2007-06-14 23:31:57 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
2007-09-24 19:54:47 +00:00
|
|
|
using System.Globalization;
|
2007-06-13 19:39:38 +00:00
|
|
|
using System.Windows.Forms;
|
2008-05-29 11:34:01 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
2007-07-07 09:40:34 +00:00
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2007-09-23 22:01:21 +00:00
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
2007-09-24 19:54:47 +00:00
|
|
|
using CodeImp.DoomBuilder.Editing;
|
2007-10-10 15:54:42 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.IO;
|
2007-10-24 17:25:03 +00:00
|
|
|
using CodeImp.DoomBuilder.Map;
|
2008-04-27 12:07:26 +00:00
|
|
|
using System.Reflection;
|
|
|
|
using CodeImp.DoomBuilder.Plugins;
|
2008-05-29 11:54:45 +00:00
|
|
|
using CodeImp.DoomBuilder.Controls;
|
2008-09-07 17:55:20 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
2008-09-07 21:28:20 +00:00
|
|
|
using CodeImp.DoomBuilder.Properties;
|
2008-09-10 08:43:20 +00:00
|
|
|
using CodeImp.DoomBuilder.Config;
|
2008-10-15 11:46:43 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2008-11-18 13:05:04 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Runtime.InteropServices;
|
2007-06-13 19:39:38 +00:00
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
|
|
|
|
2008-05-29 11:54:45 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Windows
|
2007-06-13 19:39:38 +00:00
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
public partial class MainForm : DelayedForm, IMainForm
|
2007-06-13 19:39:38 +00:00
|
|
|
{
|
2007-06-14 14:44:18 +00:00
|
|
|
#region ================== Constants
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2007-10-10 15:54:42 +00:00
|
|
|
private const int MAX_RECENT_FILES = 8;
|
|
|
|
private const int MAX_RECENT_FILES_PIXELS = 250;
|
2009-01-04 13:19:18 +00:00
|
|
|
private const int EXPANDED_INFO_HEIGHT = 106;
|
|
|
|
private const int COLLAPSED_INFO_HEIGHT = 20;
|
2008-09-07 21:28:20 +00:00
|
|
|
|
2009-02-26 14:16:18 +00:00
|
|
|
// Status bar
|
|
|
|
private const string STATUS_READY_TEXT = "Ready.";
|
|
|
|
private const string STATUS_LOADING_TEXT = "Loading resources...";
|
|
|
|
private const int WARNING_FLASH_COUNT = 10;
|
|
|
|
private const int WARNING_FLASH_INTERVAL = 100;
|
2009-02-26 23:27:46 +00:00
|
|
|
private const int WARNING_RESET_DELAY = 4000;
|
|
|
|
private const int INFO_RESET_DELAY = 4000;
|
2009-02-27 19:02:21 +00:00
|
|
|
private const int ACTION_FLASH_COUNT = 3;
|
|
|
|
private const int ACTION_FLASH_INTERVAL = 50;
|
2009-02-26 23:27:46 +00:00
|
|
|
private const int ACTION_RESET_DELAY = 4000;
|
2009-02-26 14:16:18 +00:00
|
|
|
|
|
|
|
private readonly Image[,] STATUS_IMAGES = new Image[2, 4]
|
2008-09-24 14:53:42 +00:00
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
// Normal versions
|
|
|
|
{
|
|
|
|
Properties.Resources.Status0, Properties.Resources.Status1,
|
|
|
|
Properties.Resources.Status2, Properties.Resources.Warning
|
|
|
|
},
|
|
|
|
|
|
|
|
// Flashing versions
|
|
|
|
{
|
|
|
|
Properties.Resources.Status10, Properties.Resources.Status11,
|
|
|
|
Properties.Resources.Status12, Properties.Resources.WarningOff
|
|
|
|
}
|
|
|
|
};
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2008-11-18 13:05:04 +00:00
|
|
|
// Message pump
|
|
|
|
public enum ThreadMessages : int
|
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
// Sent by the background threat to update the status
|
|
|
|
UpdateStatus = General.WM_USER + 1,
|
2008-11-18 13:05:04 +00:00
|
|
|
|
|
|
|
// This is sent by the background thread when images are loaded
|
|
|
|
// but only when first loaded or when dimensions were changed
|
|
|
|
ImageDataLoaded = General.WM_USER + 2
|
|
|
|
}
|
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
#region ================== Delegates
|
|
|
|
|
|
|
|
private delegate void CallUpdateStatusIcon();
|
2008-10-15 11:46:43 +00:00
|
|
|
private delegate void CallImageDataLoaded(ImageData img);
|
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Position/size
|
|
|
|
private Point lastposition;
|
|
|
|
private Size lastsize;
|
2007-06-24 18:56:43 +00:00
|
|
|
private bool displayresized = true;
|
2009-01-07 10:44:38 +00:00
|
|
|
private bool windowactive;
|
2007-06-24 18:56:43 +00:00
|
|
|
|
2007-06-16 19:53:51 +00:00
|
|
|
// Mouse in display
|
|
|
|
private bool mouseinside;
|
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// Input
|
|
|
|
private bool shift, ctrl, alt;
|
2008-12-17 19:35:00 +00:00
|
|
|
private MouseButtons mousebuttons;
|
2008-01-05 18:11:29 +00:00
|
|
|
private MouseInput mouseinput;
|
|
|
|
private Rectangle originalclip;
|
2008-05-08 16:39:14 +00:00
|
|
|
private bool mouseexclusive;
|
|
|
|
private int mouseexclusivebreaklevel;
|
2007-06-26 08:03:36 +00:00
|
|
|
|
2008-09-10 08:43:20 +00:00
|
|
|
// Skills
|
2009-01-04 15:06:51 +00:00
|
|
|
private ToolStripItem[] skills;
|
2008-09-10 08:43:20 +00:00
|
|
|
|
2009-01-04 13:19:18 +00:00
|
|
|
// Last info on panels
|
|
|
|
private object lastinfoobject;
|
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// Recent files
|
|
|
|
private ToolStripMenuItem[] recentitems;
|
|
|
|
|
2008-11-17 00:41:52 +00:00
|
|
|
// View modes
|
|
|
|
private ToolStripButton[] viewmodesbuttons;
|
|
|
|
private ToolStripMenuItem[] viewmodesitems;
|
2008-10-15 11:46:43 +00:00
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Edit modes
|
|
|
|
private List<ToolStripItem> editmodeitems;
|
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
// Toolbar
|
|
|
|
private EventHandler buttonvisiblechangedhandler;
|
2008-05-26 20:06:15 +00:00
|
|
|
private bool updatingfilters;
|
2008-05-26 12:14:48 +00:00
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Statusbar
|
2009-02-26 14:16:18 +00:00
|
|
|
private StatusInfo status;
|
|
|
|
private int statusflashcount;
|
|
|
|
private bool statusflashicon;
|
2008-09-07 21:28:20 +00:00
|
|
|
|
2008-11-18 13:05:04 +00:00
|
|
|
// Properties
|
|
|
|
private IntPtr windowptr;
|
|
|
|
|
2008-11-27 06:53:38 +00:00
|
|
|
// Processing
|
2009-02-22 22:57:21 +00:00
|
|
|
private int processingcount;
|
2008-11-27 06:53:38 +00:00
|
|
|
private double lastupdatetime;
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
#endregion
|
2007-06-15 10:18:03 +00:00
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2007-11-13 09:06:15 +00:00
|
|
|
public bool ShiftState { get { return shift; } }
|
|
|
|
public bool CtrlState { get { return ctrl; } }
|
|
|
|
public bool AltState { get { return alt; } }
|
2008-12-17 19:35:00 +00:00
|
|
|
public MouseButtons MouseButtons { get { return mousebuttons; } }
|
2007-06-16 19:53:51 +00:00
|
|
|
public bool MouseInDisplay { get { return mouseinside; } }
|
2008-01-02 21:49:43 +00:00
|
|
|
internal RenderTargetControl Display { get { return display; } }
|
2007-12-01 01:32:56 +00:00
|
|
|
public bool SnapToGrid { get { return buttonsnaptogrid.Checked; } }
|
2007-12-08 15:18:14 +00:00
|
|
|
public bool AutoMerge { get { return buttonautomerge.Checked; } }
|
2008-05-08 16:39:14 +00:00
|
|
|
public bool MouseExclusive { get { return mouseexclusive; } }
|
2008-11-18 13:05:04 +00:00
|
|
|
new public IntPtr Handle { get { return windowptr; } }
|
2009-01-04 13:19:18 +00:00
|
|
|
public bool IsInfoPanelExpanded { get { return (panelinfo.Height == EXPANDED_INFO_HEIGHT); } }
|
2009-01-07 10:44:38 +00:00
|
|
|
public bool IsActiveWindow { get { return windowactive; } }
|
2009-02-26 14:16:18 +00:00
|
|
|
public StatusInfo Status { get { return status; } }
|
2008-05-08 16:39:14 +00:00
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
// Constructor
|
2008-01-02 21:49:43 +00:00
|
|
|
internal MainForm()
|
2007-06-13 19:39:38 +00:00
|
|
|
{
|
|
|
|
// Setup controls
|
|
|
|
InitializeComponent();
|
2008-01-02 21:49:43 +00:00
|
|
|
editmodeitems = new List<ToolStripItem>();
|
2008-11-18 13:05:04 +00:00
|
|
|
|
|
|
|
// Fetch pointer
|
|
|
|
windowptr = base.Handle;
|
|
|
|
|
2008-11-17 00:41:52 +00:00
|
|
|
// Make array for view modes
|
|
|
|
viewmodesbuttons = new ToolStripButton[Renderer2D.NUM_VIEW_MODES];
|
|
|
|
viewmodesbuttons[(int)ViewMode.Normal] = buttonviewnormal;
|
|
|
|
viewmodesbuttons[(int)ViewMode.Brightness] = buttonviewbrightness;
|
|
|
|
viewmodesbuttons[(int)ViewMode.FloorTextures] = buttonviewfloors;
|
|
|
|
viewmodesbuttons[(int)ViewMode.CeilingTextures] = buttonviewceilings;
|
|
|
|
viewmodesitems = new ToolStripMenuItem[Renderer2D.NUM_VIEW_MODES];
|
|
|
|
viewmodesitems[(int)ViewMode.Normal] = itemviewnormal;
|
|
|
|
viewmodesitems[(int)ViewMode.Brightness] = itemviewbrightness;
|
|
|
|
viewmodesitems[(int)ViewMode.FloorTextures] = itemviewfloors;
|
|
|
|
viewmodesitems[(int)ViewMode.CeilingTextures] = itemviewceilings;
|
2008-01-02 21:49:43 +00:00
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Visual Studio IDE doesn't let me set these in the designer :(
|
2007-09-24 19:54:47 +00:00
|
|
|
buttonzoom.Font = menufile.Font;
|
2007-11-10 19:24:52 +00:00
|
|
|
buttonzoom.DropDownDirection = ToolStripDropDownDirection.AboveLeft;
|
|
|
|
buttongrid.Font = menufile.Font;
|
|
|
|
buttongrid.DropDownDirection = ToolStripDropDownDirection.AboveLeft;
|
2007-09-24 19:54:47 +00:00
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
// Event handlers
|
|
|
|
buttonvisiblechangedhandler = new EventHandler(ToolbarButtonVisibleChanged);
|
|
|
|
|
2007-09-29 15:43:59 +00:00
|
|
|
// Bind any methods
|
2008-04-27 12:07:26 +00:00
|
|
|
General.Actions.BindMethods(this);
|
2007-09-29 15:43:59 +00:00
|
|
|
|
2007-06-24 22:53:41 +00:00
|
|
|
// Apply shortcut keys
|
|
|
|
ApplyShortcutKeys();
|
|
|
|
|
2007-10-10 15:54:42 +00:00
|
|
|
// Make recent items list
|
|
|
|
CreateRecentFiles();
|
|
|
|
|
2007-10-16 21:15:27 +00:00
|
|
|
// Show splash
|
|
|
|
ShowSplashDisplay();
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
|
2007-10-14 21:31:45 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== General
|
|
|
|
|
2008-10-15 11:46:43 +00:00
|
|
|
// Editing mode changed!
|
|
|
|
internal void EditModeChanged()
|
|
|
|
{
|
|
|
|
// Check appropriate button on interface
|
|
|
|
// And show the mode name
|
2008-11-27 11:59:17 +00:00
|
|
|
if(General.Editing.Mode != null)
|
2008-10-15 11:46:43 +00:00
|
|
|
{
|
2008-11-27 11:59:17 +00:00
|
|
|
General.MainWindow.CheckEditModeButton(General.Editing.Mode.EditModeButtonName);
|
|
|
|
General.MainWindow.DisplayModeName(General.Editing.Mode.Attributes.DisplayName);
|
2008-10-15 11:46:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
General.MainWindow.CheckEditModeButton("");
|
|
|
|
General.MainWindow.DisplayModeName("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// View mode only matters in classic editing modes
|
2008-11-17 00:41:52 +00:00
|
|
|
for(int i = 0; i < Renderer2D.NUM_VIEW_MODES; i++)
|
|
|
|
{
|
2008-11-27 11:59:17 +00:00
|
|
|
viewmodesitems[i].Enabled = (General.Editing.Mode is ClassicMode);
|
|
|
|
viewmodesbuttons[i].Enabled = (General.Editing.Mode is ClassicMode);
|
2008-11-17 00:41:52 +00:00
|
|
|
}
|
2008-10-15 11:46:43 +00:00
|
|
|
}
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// This makes a beep sound
|
|
|
|
public void MessageBeep(MessageBeepType type)
|
|
|
|
{
|
|
|
|
General.MessageBeep(type);
|
|
|
|
}
|
|
|
|
|
2007-10-14 21:31:45 +00:00
|
|
|
// This updates all menus for the current status
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void UpdateInterface()
|
2007-10-14 21:31:45 +00:00
|
|
|
{
|
|
|
|
// Map opened?
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Show map name and filename in caption
|
|
|
|
this.Text = General.Map.FileTitle + " (" + General.Map.Options.CurrentName + ") - " + Application.ProductName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Show normal caption
|
|
|
|
this.Text = Application.ProductName;
|
|
|
|
}
|
2008-09-10 08:43:20 +00:00
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// Update the status bar
|
|
|
|
UpdateStatusbar();
|
|
|
|
|
2007-10-14 21:31:45 +00:00
|
|
|
// Update menus and toolbar icons
|
|
|
|
UpdateFileMenu();
|
|
|
|
UpdateEditMenu();
|
2008-11-17 00:41:52 +00:00
|
|
|
UpdateViewMenu();
|
2008-09-24 15:14:29 +00:00
|
|
|
UpdateModeMenu();
|
2008-12-31 16:43:23 +00:00
|
|
|
UpdatePrefabsMenu();
|
2007-10-14 21:31:45 +00:00
|
|
|
UpdateToolsMenu();
|
2008-09-26 05:53:34 +00:00
|
|
|
UpdateToolbar();
|
2008-09-10 08:43:20 +00:00
|
|
|
UpdateSkills();
|
2007-10-14 21:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generic event that invokes the tagged action
|
2008-05-15 12:36:55 +00:00
|
|
|
public void InvokeTaggedAction(object sender, EventArgs e)
|
2007-10-14 21:31:45 +00:00
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
string asmname;
|
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
this.Update();
|
2009-01-04 13:19:18 +00:00
|
|
|
|
|
|
|
if(sender is ToolStripItem)
|
|
|
|
General.Actions.InvokeAction((sender as ToolStripItem).Tag.ToString());
|
2009-01-14 23:12:52 +00:00
|
|
|
else if(sender is Control)
|
|
|
|
General.Actions.InvokeAction((sender as Control).Tag.ToString());
|
2009-01-04 13:19:18 +00:00
|
|
|
else
|
|
|
|
General.Fail("InvokeTaggedAction used on an unexpected control.");
|
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
this.Update();
|
2007-10-14 21:31:45 +00:00
|
|
|
}
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
#endregion
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
#region ================== Window
|
2008-09-07 17:55:20 +00:00
|
|
|
|
2008-12-08 06:29:30 +00:00
|
|
|
// This sets the focus on the display for correct key input
|
|
|
|
public bool FocusDisplay()
|
|
|
|
{
|
|
|
|
return display.Focus();
|
|
|
|
}
|
|
|
|
|
2008-09-07 17:55:20 +00:00
|
|
|
// Window is first shown
|
|
|
|
private void MainForm_Shown(object sender, EventArgs e)
|
2008-10-13 17:47:08 +00:00
|
|
|
{
|
|
|
|
// Perform auto mapo loading action when the window is not delayed
|
|
|
|
if(!General.DelayMainWindow) PerformAutoMapLoading();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto map loading that must be done when the window is first shown after loading
|
|
|
|
// but also before the window is shown when the -delaywindow parameter is given
|
|
|
|
internal void PerformAutoMapLoading()
|
2008-09-07 17:55:20 +00:00
|
|
|
{
|
|
|
|
// Check if the command line arguments tell us to load something
|
|
|
|
if(General.AutoLoadFile != null)
|
|
|
|
{
|
|
|
|
bool showdialog = false;
|
|
|
|
MapOptions options = new MapOptions();
|
|
|
|
Configuration mapsettings;
|
|
|
|
|
|
|
|
// Any of the options already given?
|
|
|
|
if(General.AutoLoadMap != null)
|
|
|
|
{
|
|
|
|
// Try to find existing options in the settings file
|
|
|
|
string dbsfile = General.AutoLoadFile.Substring(0, General.AutoLoadFile.Length - 4) + ".dbs";
|
|
|
|
if(File.Exists(dbsfile))
|
|
|
|
try { mapsettings = new Configuration(dbsfile, true); }
|
|
|
|
catch(Exception) { mapsettings = new Configuration(true); }
|
|
|
|
else
|
|
|
|
mapsettings = new Configuration(true);
|
|
|
|
|
|
|
|
// Set map name and other options
|
|
|
|
options = new MapOptions(mapsettings, General.AutoLoadMap);
|
|
|
|
|
|
|
|
// Set configuration file (constructor already does this, but we want this info from the cmd args if possible)
|
|
|
|
options.ConfigFile = General.AutoLoadConfig;
|
|
|
|
if(options.ConfigFile == null) options.ConfigFile = mapsettings.ReadSetting("gameconfig", "");
|
|
|
|
if(options.ConfigFile.Trim().Length == 0) showdialog = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No options given
|
|
|
|
showdialog = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show open map dialog?
|
|
|
|
if(showdialog)
|
|
|
|
{
|
|
|
|
// Show open dialog
|
|
|
|
General.OpenMapFile(General.AutoLoadFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Open with options
|
|
|
|
General.OpenMapFileWithOptions(General.AutoLoadFile, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-14 15:35:37 +00:00
|
|
|
|
|
|
|
// Window is loaded
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Position window from configuration settings
|
|
|
|
this.SuspendLayout();
|
|
|
|
this.Location = new Point(General.Settings.ReadSetting("mainwindow.positionx", this.Location.X),
|
|
|
|
General.Settings.ReadSetting("mainwindow.positiony", this.Location.Y));
|
|
|
|
this.Size = new Size(General.Settings.ReadSetting("mainwindow.sizewidth", this.Size.Width),
|
|
|
|
General.Settings.ReadSetting("mainwindow.sizeheight", this.Size.Height));
|
|
|
|
this.WindowState = (FormWindowState)General.Settings.ReadSetting("mainwindow.windowstate", (int)FormWindowState.Maximized);
|
|
|
|
this.ResumeLayout(true);
|
|
|
|
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
2008-05-08 16:39:14 +00:00
|
|
|
|
|
|
|
// Window receives focus
|
|
|
|
private void MainForm_Activated(object sender, EventArgs e)
|
|
|
|
{
|
2009-01-07 10:44:38 +00:00
|
|
|
windowactive = true;
|
|
|
|
|
2008-05-08 16:39:14 +00:00
|
|
|
// Resume any exclusive mouse input
|
|
|
|
ResumeExclusiveMouseInput();
|
2008-12-06 00:28:49 +00:00
|
|
|
display.Focus();
|
2008-05-08 16:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Window loses focus
|
|
|
|
private void MainForm_Deactivate(object sender, EventArgs e)
|
|
|
|
{
|
2009-01-07 10:44:38 +00:00
|
|
|
windowactive = false;
|
|
|
|
|
2008-05-08 16:39:14 +00:00
|
|
|
// Release all pressed keys
|
|
|
|
General.Actions.ReleaseAllKeys();
|
2008-12-17 19:35:00 +00:00
|
|
|
mousebuttons = MouseButtons.None;
|
2008-05-08 16:39:14 +00:00
|
|
|
|
|
|
|
// Stop exclusive mouse input
|
|
|
|
BreakExclusiveMouseInput();
|
|
|
|
}
|
2007-06-14 15:35:37 +00:00
|
|
|
|
|
|
|
// Window is moved
|
|
|
|
private void MainForm_Move(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// Window resizes
|
|
|
|
private void MainForm_Resize(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Resizing
|
|
|
|
//this.SuspendLayout();
|
|
|
|
//resized = true;
|
|
|
|
}
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
// Window was resized
|
|
|
|
private void MainForm_ResizeEnd(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Normal windowstate?
|
|
|
|
if(this.WindowState == FormWindowState.Normal)
|
|
|
|
{
|
|
|
|
// Keep last position and size
|
|
|
|
lastposition = this.Location;
|
|
|
|
lastsize = this.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window is being closed
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
{
|
|
|
|
int windowstate;
|
2007-10-04 18:16:05 +00:00
|
|
|
|
2008-05-11 00:42:34 +00:00
|
|
|
if(e.CloseReason != CloseReason.ApplicationExitCall)
|
|
|
|
{
|
2008-05-19 21:33:07 +00:00
|
|
|
// Close the map
|
|
|
|
if(General.CloseMap())
|
|
|
|
{
|
|
|
|
General.WriteLogLine("Closing main interface window...");
|
2008-09-07 21:28:20 +00:00
|
|
|
|
2009-02-26 14:16:18 +00:00
|
|
|
// Stop timers
|
|
|
|
statusflasher.Stop();
|
|
|
|
statusresetter.Stop();
|
2008-05-19 21:33:07 +00:00
|
|
|
|
|
|
|
// Stop exclusive mode, if any is active
|
|
|
|
StopExclusiveMouseInput();
|
2009-02-22 22:57:21 +00:00
|
|
|
StopProcessing();
|
2008-05-19 21:33:07 +00:00
|
|
|
|
|
|
|
// Unbind methods
|
|
|
|
General.Actions.UnbindMethods(this);
|
|
|
|
|
|
|
|
// Determine window state to save
|
|
|
|
if(this.WindowState != FormWindowState.Minimized)
|
|
|
|
windowstate = (int)this.WindowState;
|
|
|
|
else
|
|
|
|
windowstate = (int)FormWindowState.Normal;
|
|
|
|
|
|
|
|
// Save window settings
|
|
|
|
General.Settings.WriteSetting("mainwindow.positionx", lastposition.X);
|
|
|
|
General.Settings.WriteSetting("mainwindow.positiony", lastposition.Y);
|
|
|
|
General.Settings.WriteSetting("mainwindow.sizewidth", lastsize.Width);
|
|
|
|
General.Settings.WriteSetting("mainwindow.sizeheight", lastsize.Height);
|
|
|
|
General.Settings.WriteSetting("mainwindow.windowstate", windowstate);
|
|
|
|
|
|
|
|
// Save recent files
|
|
|
|
SaveRecentFiles();
|
|
|
|
|
|
|
|
// Terminate the program
|
|
|
|
General.Terminate(true);
|
|
|
|
}
|
2008-05-11 00:42:34 +00:00
|
|
|
else
|
2008-05-19 21:33:07 +00:00
|
|
|
{
|
|
|
|
// Cancel the close
|
|
|
|
e.Cancel = true;
|
|
|
|
}
|
2008-05-11 00:42:34 +00:00
|
|
|
}
|
2007-06-13 19:39:38 +00:00
|
|
|
}
|
2007-06-14 14:44:18 +00:00
|
|
|
|
|
|
|
#endregion
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
#region ================== Statusbar
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2007-11-10 19:24:52 +00:00
|
|
|
// This updates the status bar
|
|
|
|
private void UpdateStatusbar()
|
|
|
|
{
|
|
|
|
// Map open?
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Enable items
|
|
|
|
xposlabel.Enabled = true;
|
|
|
|
yposlabel.Enabled = true;
|
|
|
|
poscommalabel.Enabled = true;
|
|
|
|
zoomlabel.Enabled = true;
|
|
|
|
buttonzoom.Enabled = true;
|
|
|
|
gridlabel.Enabled = true;
|
|
|
|
buttongrid.Enabled = true;
|
2008-09-22 18:27:50 +00:00
|
|
|
configlabel.Text = General.Map.Config.Name;
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Disable items
|
|
|
|
xposlabel.Text = "--";
|
|
|
|
yposlabel.Text = "--";
|
|
|
|
xposlabel.Enabled = false;
|
|
|
|
yposlabel.Enabled = false;
|
|
|
|
poscommalabel.Enabled = false;
|
|
|
|
zoomlabel.Enabled = false;
|
|
|
|
buttonzoom.Enabled = false;
|
|
|
|
gridlabel.Enabled = false;
|
|
|
|
buttongrid.Enabled = false;
|
2008-09-22 18:27:50 +00:00
|
|
|
configlabel.Text = "";
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
2008-09-24 14:53:42 +00:00
|
|
|
|
|
|
|
UpdateStatusIcon();
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2009-02-26 14:16:18 +00:00
|
|
|
// This flashes the status icon
|
|
|
|
private void statusflasher_Tick(object sender, EventArgs e)
|
2008-09-07 21:28:20 +00:00
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
statusflashicon = !statusflashicon;
|
|
|
|
UpdateStatusIcon();
|
|
|
|
statusflashcount--;
|
|
|
|
if(statusflashcount == 0) statusflasher.Stop();
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2009-02-26 14:16:18 +00:00
|
|
|
// This resets the status to ready
|
|
|
|
private void statusresetter_Tick(object sender, EventArgs e)
|
2008-09-07 21:28:20 +00:00
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
DisplayReady();
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2009-02-26 14:16:18 +00:00
|
|
|
// This changes status text
|
|
|
|
public void DisplayStatus(StatusType type, string message) { DisplayStatus(new StatusInfo(type, message)); }
|
|
|
|
public void DisplayStatus(StatusInfo newstatus)
|
2008-09-07 21:28:20 +00:00
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
// Stop timers
|
2009-02-27 19:02:21 +00:00
|
|
|
if(!newstatus.displayed)
|
|
|
|
{
|
|
|
|
statusresetter.Stop();
|
|
|
|
statusflasher.Stop();
|
|
|
|
statusflashicon = false;
|
|
|
|
}
|
2009-02-26 14:16:18 +00:00
|
|
|
|
|
|
|
// Determine what to do specifically for this status type
|
|
|
|
switch(newstatus.type)
|
2008-09-07 21:28:20 +00:00
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
// When no particular information is to be displayed.
|
|
|
|
// The messages displayed depends on running background processes.
|
|
|
|
case StatusType.Ready:
|
|
|
|
if((General.Map != null) && (General.Map.Data != null) && General.Map.Data.IsLoading)
|
|
|
|
newstatus.message = STATUS_LOADING_TEXT;
|
2008-09-24 14:53:42 +00:00
|
|
|
else
|
2009-02-26 14:16:18 +00:00
|
|
|
newstatus.message = STATUS_READY_TEXT;
|
|
|
|
break;
|
2009-02-26 23:27:46 +00:00
|
|
|
|
|
|
|
// Shows information without flashing the icon.
|
|
|
|
case StatusType.Info:
|
2009-02-27 19:02:21 +00:00
|
|
|
if(!newstatus.displayed)
|
|
|
|
{
|
|
|
|
statusresetter.Interval = INFO_RESET_DELAY;
|
|
|
|
statusresetter.Start();
|
|
|
|
}
|
2009-02-26 23:27:46 +00:00
|
|
|
break;
|
2009-02-26 14:16:18 +00:00
|
|
|
|
|
|
|
// Shows action information and flashes up the status icon once.
|
|
|
|
case StatusType.Action:
|
2009-02-27 19:02:21 +00:00
|
|
|
if(!newstatus.displayed)
|
|
|
|
{
|
|
|
|
statusflashicon = true;
|
|
|
|
statusflasher.Interval = ACTION_FLASH_INTERVAL;
|
|
|
|
statusflashcount = ACTION_FLASH_COUNT;
|
|
|
|
statusflasher.Start();
|
|
|
|
statusresetter.Interval = ACTION_RESET_DELAY;
|
|
|
|
statusresetter.Start();
|
|
|
|
}
|
2009-02-26 14:16:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Shows a warning, makes a warning sound and flashes a warning icon.
|
|
|
|
case StatusType.Warning:
|
2009-02-27 19:02:21 +00:00
|
|
|
if(!newstatus.displayed)
|
|
|
|
{
|
|
|
|
MessageBeep(MessageBeepType.Warning);
|
|
|
|
statusflasher.Interval = WARNING_FLASH_INTERVAL;
|
|
|
|
statusflashcount = WARNING_FLASH_COUNT;
|
|
|
|
statusflasher.Start();
|
|
|
|
statusresetter.Interval = WARNING_RESET_DELAY;
|
|
|
|
statusresetter.Start();
|
|
|
|
}
|
2009-02-26 14:16:18 +00:00
|
|
|
break;
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
2009-02-26 14:16:18 +00:00
|
|
|
|
|
|
|
// Update status description
|
|
|
|
status = newstatus;
|
2009-02-27 19:02:21 +00:00
|
|
|
status.displayed = true;
|
2009-02-26 14:16:18 +00:00
|
|
|
if(statuslabel.Text != status.message)
|
|
|
|
statuslabel.Text = status.message;
|
|
|
|
|
|
|
|
// Update icon as well
|
|
|
|
UpdateStatusIcon();
|
|
|
|
|
|
|
|
// Refresh
|
|
|
|
statusbar.Invalidate();
|
|
|
|
this.Update();
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
// This changes status text to Ready
|
|
|
|
public void DisplayReady()
|
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
DisplayStatus(StatusType.Ready, null);
|
2007-06-14 14:44:18 +00:00
|
|
|
}
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
// This updates the status icon
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void UpdateStatusIcon()
|
2007-10-26 19:06:59 +00:00
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
int statusicon = 0;
|
|
|
|
int statusflashindex = statusflashicon ? 1 : 0;
|
|
|
|
|
|
|
|
// Loading icon?
|
|
|
|
if((General.Map != null) && (General.Map.Data != null) && General.Map.Data.IsLoading)
|
|
|
|
statusicon = 1;
|
|
|
|
|
|
|
|
// Status type
|
|
|
|
switch(status.type)
|
2007-10-26 19:06:59 +00:00
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
case StatusType.Ready:
|
|
|
|
case StatusType.Info:
|
|
|
|
case StatusType.Action:
|
|
|
|
statuslabel.Image = STATUS_IMAGES[statusflashindex, statusicon];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case StatusType.Busy:
|
|
|
|
statuslabel.Image = STATUS_IMAGES[statusflashindex, 2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case StatusType.Warning:
|
|
|
|
statuslabel.Image = STATUS_IMAGES[statusflashindex, 3];
|
|
|
|
break;
|
2007-10-26 19:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-24 14:53:42 +00:00
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// This changes coordinates display
|
2008-01-05 18:11:29 +00:00
|
|
|
public void UpdateCoordinates(Vector2D coords)
|
2007-07-07 09:40:34 +00:00
|
|
|
{
|
|
|
|
// X position
|
|
|
|
if(float.IsNaN(coords.x))
|
|
|
|
xposlabel.Text = "--";
|
|
|
|
else
|
|
|
|
xposlabel.Text = coords.x.ToString("####0");
|
|
|
|
|
|
|
|
// Y position
|
|
|
|
if(float.IsNaN(coords.y))
|
|
|
|
yposlabel.Text = "--";
|
|
|
|
else
|
|
|
|
yposlabel.Text = coords.y.ToString("####0");
|
|
|
|
|
|
|
|
// Update status bar
|
2007-10-20 19:50:03 +00:00
|
|
|
//statusbar.Update();
|
2007-07-07 09:40:34 +00:00
|
|
|
}
|
2007-09-24 19:54:47 +00:00
|
|
|
|
|
|
|
// This changes zoom display
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void UpdateZoom(float scale)
|
2007-09-24 19:54:47 +00:00
|
|
|
{
|
|
|
|
// Update scale label
|
|
|
|
if(float.IsNaN(scale))
|
|
|
|
zoomlabel.Text = "--";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scale *= 100;
|
|
|
|
zoomlabel.Text = scale.ToString("##0") + "%";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update status bar
|
2007-10-20 19:50:03 +00:00
|
|
|
//statusbar.Update();
|
2007-09-24 19:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Zoom to a specified level
|
|
|
|
private void itemzoomto_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int zoom;
|
|
|
|
|
|
|
|
if(General.Map == null) return;
|
|
|
|
|
|
|
|
// In classic mode?
|
2008-11-27 11:59:17 +00:00
|
|
|
if(General.Editing.Mode is ClassicMode)
|
2007-09-24 19:54:47 +00:00
|
|
|
{
|
|
|
|
// Requested from menu?
|
|
|
|
if(sender is ToolStripMenuItem)
|
|
|
|
{
|
|
|
|
// Get integral zoom level
|
|
|
|
zoom = int.Parse((sender as ToolStripMenuItem).Tag.ToString(), CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
// Zoom now
|
2008-11-27 11:59:17 +00:00
|
|
|
(General.Editing.Mode as ClassicMode).SetZoom((float)zoom / 100f);
|
2007-09-24 19:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zoom to fit in screen
|
|
|
|
private void itemzoomfittoscreen_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if(General.Map == null) return;
|
|
|
|
|
|
|
|
// In classic mode?
|
2008-11-27 11:59:17 +00:00
|
|
|
if(General.Editing.Mode is ClassicMode)
|
|
|
|
(General.Editing.Mode as ClassicMode).CenterInScreen();
|
2007-09-24 19:54:47 +00:00
|
|
|
}
|
2007-11-10 19:24:52 +00:00
|
|
|
|
|
|
|
// This changes grid display
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void UpdateGrid(int gridsize)
|
2007-11-10 19:24:52 +00:00
|
|
|
{
|
|
|
|
// Update grid label
|
|
|
|
if(gridsize == 0)
|
|
|
|
gridlabel.Text = "--";
|
|
|
|
else
|
|
|
|
gridlabel.Text = gridsize.ToString("###0") + " mp";
|
|
|
|
|
|
|
|
// Update status bar
|
|
|
|
//statusbar.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set grid to a specified size
|
|
|
|
private void itemgridsize_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if(General.Map == null) return;
|
|
|
|
|
|
|
|
// In classic mode?
|
2008-11-27 11:59:17 +00:00
|
|
|
if(General.Editing.Mode is ClassicMode)
|
2007-11-10 19:24:52 +00:00
|
|
|
{
|
|
|
|
// Requested from menu?
|
|
|
|
if(sender is ToolStripMenuItem)
|
|
|
|
{
|
|
|
|
// Get integral zoom level
|
|
|
|
size = int.Parse((sender as ToolStripMenuItem).Tag.ToString(), CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
// Change grid size
|
|
|
|
General.Map.Grid.SetGridSize(size);
|
|
|
|
|
|
|
|
// Redraw display
|
|
|
|
RedrawDisplay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show grid setup
|
|
|
|
private void itemgridcustom_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if(General.Map == null) return;
|
|
|
|
|
2008-06-10 08:35:14 +00:00
|
|
|
General.Map.Grid.ShowGridSetup();
|
2007-11-10 19:24:52 +00:00
|
|
|
}
|
2007-07-07 09:40:34 +00:00
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
#endregion
|
2007-06-14 23:31:57 +00:00
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
#region ================== Display
|
|
|
|
|
|
|
|
// This shows the splash screen on display
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ShowSplashDisplay()
|
2007-06-15 10:18:03 +00:00
|
|
|
{
|
|
|
|
// Change display to show splash logo
|
2007-10-16 21:15:27 +00:00
|
|
|
display.SetSplashLogoDisplay();
|
2008-05-16 21:48:23 +00:00
|
|
|
display.Cursor = Cursors.Default;
|
2007-06-15 18:30:55 +00:00
|
|
|
this.Update();
|
2007-06-15 10:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This clears the display
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ClearDisplay()
|
2007-06-15 10:18:03 +00:00
|
|
|
{
|
|
|
|
// Clear the display
|
2007-10-16 21:15:27 +00:00
|
|
|
display.SetManualRendering();
|
2007-06-15 18:30:55 +00:00
|
|
|
this.Update();
|
2007-06-15 10:18:03 +00:00
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
2008-05-16 21:48:23 +00:00
|
|
|
// This sets the display cursor
|
|
|
|
public void SetCursor(Cursor cursor)
|
|
|
|
{
|
|
|
|
// Only when a map is open
|
|
|
|
if(General.Map != null) display.Cursor = cursor;
|
|
|
|
}
|
|
|
|
|
2007-10-05 10:00:15 +00:00
|
|
|
// This redraws the display on the next paint event
|
|
|
|
public void RedrawDisplay()
|
2007-06-15 22:38:42 +00:00
|
|
|
{
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (General.Editing.Mode != null))
|
2008-04-12 12:45:57 +00:00
|
|
|
{
|
2008-11-27 11:59:17 +00:00
|
|
|
General.Editing.Mode.OnRedrawDisplay();
|
2008-04-12 12:45:57 +00:00
|
|
|
}
|
2008-04-20 23:22:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
display.Invalidate();
|
|
|
|
}
|
2007-06-15 22:38:42 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 14:27:46 +00:00
|
|
|
// This event is called when a repaint is needed
|
|
|
|
private void display_Paint(object sender, PaintEventArgs e)
|
|
|
|
{
|
2008-04-20 23:22:16 +00:00
|
|
|
if(General.Map != null)
|
|
|
|
{
|
2008-11-27 11:59:17 +00:00
|
|
|
if(General.Editing.Mode != null)
|
2008-04-20 23:22:16 +00:00
|
|
|
{
|
2008-11-27 11:59:17 +00:00
|
|
|
if(!displayresized) General.Editing.Mode.OnPresentDisplay();
|
2008-04-20 23:22:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-17 23:32:13 +00:00
|
|
|
if(General.Colors != null)
|
|
|
|
e.Graphics.Clear(Color.FromArgb(General.Colors.Background.ToInt()));
|
|
|
|
else
|
|
|
|
e.Graphics.Clear(SystemColors.AppWorkspace);
|
2008-04-20 23:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-19 14:27:46 +00:00
|
|
|
}
|
|
|
|
|
2007-06-15 22:38:42 +00:00
|
|
|
// Redraw requested
|
|
|
|
private void redrawtimer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Disable timer (only redraw once)
|
|
|
|
redrawtimer.Enabled = false;
|
2007-06-24 18:56:43 +00:00
|
|
|
|
|
|
|
// Resume control layouts
|
2007-10-06 17:25:59 +00:00
|
|
|
//if(displayresized) General.LockWindowUpdate(IntPtr.Zero);
|
2007-09-23 22:01:21 +00:00
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// Map opened?
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Display was resized?
|
|
|
|
if(displayresized)
|
|
|
|
{
|
|
|
|
// Reset graphics to match changes
|
|
|
|
General.Map.Graphics.Reset();
|
|
|
|
}
|
2007-09-23 22:01:21 +00:00
|
|
|
|
2009-01-04 13:19:18 +00:00
|
|
|
// This is a dirty trick to give the display a new mousemove event with correct arguments
|
|
|
|
if(mouseinside)
|
|
|
|
{
|
|
|
|
Point mousepos = Cursor.Position;
|
|
|
|
Cursor.Position = new Point(mousepos.X + 1, mousepos.Y + 1);
|
|
|
|
Cursor.Position = mousepos;
|
|
|
|
}
|
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// Redraw now
|
2007-10-05 10:00:15 +00:00
|
|
|
RedrawDisplay();
|
2007-06-24 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display resize is done
|
|
|
|
displayresized = false;
|
2007-06-15 22:38:42 +00:00
|
|
|
}
|
2007-06-16 19:53:51 +00:00
|
|
|
|
|
|
|
// Display size changes
|
|
|
|
private void display_Resize(object sender, EventArgs e)
|
|
|
|
{
|
2007-06-24 18:56:43 +00:00
|
|
|
// Resizing
|
2007-10-06 17:25:59 +00:00
|
|
|
//if(!displayresized) General.LockWindowUpdate(display.Handle);
|
2007-06-24 18:56:43 +00:00
|
|
|
displayresized = true;
|
2007-06-16 19:53:51 +00:00
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// Request redraw
|
|
|
|
if(!redrawtimer.Enabled) redrawtimer.Enabled = true;
|
2007-06-16 19:53:51 +00:00
|
|
|
}
|
2007-06-15 22:38:42 +00:00
|
|
|
|
2008-05-23 06:00:37 +00:00
|
|
|
// This requests a delayed redraw
|
|
|
|
public void DelayedRedraw()
|
|
|
|
{
|
|
|
|
// Request redraw
|
|
|
|
if(!redrawtimer.Enabled) redrawtimer.Enabled = true;
|
|
|
|
}
|
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
// Mouse click
|
2008-12-17 19:35:00 +00:00
|
|
|
private void display_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseClick(e);
|
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse doubleclick
|
2008-12-17 19:35:00 +00:00
|
|
|
private void display_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseDoubleClick(e);
|
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse down
|
2008-04-27 12:07:26 +00:00
|
|
|
private void display_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
int key = 0;
|
2009-03-01 21:20:52 +00:00
|
|
|
|
2008-12-24 14:21:54 +00:00
|
|
|
int mod = 0;
|
|
|
|
if(alt) mod |= (int)Keys.Alt;
|
|
|
|
if(shift) mod |= (int)Keys.Shift;
|
|
|
|
if(ctrl) mod |= (int)Keys.Control;
|
|
|
|
|
2008-12-17 19:35:00 +00:00
|
|
|
// Apply button
|
|
|
|
mousebuttons |= e.Button;
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Create key
|
|
|
|
switch(e.Button)
|
|
|
|
{
|
|
|
|
case MouseButtons.Left: key = (int)Keys.LButton; break;
|
|
|
|
case MouseButtons.Middle: key = (int)Keys.MButton; break;
|
|
|
|
case MouseButtons.Right: key = (int)Keys.RButton; break;
|
|
|
|
case MouseButtons.XButton1: key = (int)Keys.XButton1; break;
|
|
|
|
case MouseButtons.XButton2: key = (int)Keys.XButton2; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invoke any actions associated with this key
|
2008-12-24 14:21:54 +00:00
|
|
|
General.Actions.KeyPressed(key | mod);
|
2008-04-27 12:07:26 +00:00
|
|
|
|
|
|
|
// Invoke on editing mode
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseDown(e);
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse enters
|
2007-06-16 19:53:51 +00:00
|
|
|
private void display_MouseEnter(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
mouseinside = true;
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (mouseinput == null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseEnter(e);
|
2007-06-16 19:53:51 +00:00
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse leaves
|
2007-06-16 19:53:51 +00:00
|
|
|
private void display_MouseLeave(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
mouseinside = false;
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (mouseinput == null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseLeave(e);
|
2007-06-16 19:53:51 +00:00
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse moves
|
2008-01-05 18:11:29 +00:00
|
|
|
private void display_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
{
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (mouseinput == null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseMove(e);
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse up
|
2008-04-27 12:07:26 +00:00
|
|
|
private void display_MouseUp(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
int key = 0;
|
2008-12-24 14:21:54 +00:00
|
|
|
|
|
|
|
int mod = 0;
|
|
|
|
if(alt) mod |= (int)Keys.Alt;
|
|
|
|
if(shift) mod |= (int)Keys.Shift;
|
|
|
|
if(ctrl) mod |= (int)Keys.Control;
|
|
|
|
|
2008-12-17 19:35:00 +00:00
|
|
|
// Apply button
|
|
|
|
mousebuttons &= ~e.Button;
|
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Create key
|
|
|
|
switch(e.Button)
|
|
|
|
{
|
|
|
|
case MouseButtons.Left: key = (int)Keys.LButton; break;
|
|
|
|
case MouseButtons.Middle: key = (int)Keys.MButton; break;
|
|
|
|
case MouseButtons.Right: key = (int)Keys.RButton; break;
|
|
|
|
case MouseButtons.XButton1: key = (int)Keys.XButton1; break;
|
|
|
|
case MouseButtons.XButton2: key = (int)Keys.XButton2; break;
|
|
|
|
}
|
2008-12-24 14:21:54 +00:00
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
// Invoke any actions associated with this key
|
2008-12-24 14:21:54 +00:00
|
|
|
General.Actions.KeyReleased(key | mod);
|
2008-04-27 12:07:26 +00:00
|
|
|
|
|
|
|
// Invoke on editing mode
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnMouseUp(e);
|
2008-04-27 12:07:26 +00:00
|
|
|
}
|
2007-06-15 10:18:03 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
#region ================== Input
|
2008-04-27 12:07:26 +00:00
|
|
|
|
2008-05-08 16:39:14 +00:00
|
|
|
// This is a tool to lock the mouse in exclusive mode
|
|
|
|
private void StartMouseExclusive()
|
2008-01-05 18:11:29 +00:00
|
|
|
{
|
2008-05-08 16:39:14 +00:00
|
|
|
// Not already locked?
|
2008-01-05 18:11:29 +00:00
|
|
|
if(mouseinput == null)
|
|
|
|
{
|
|
|
|
// Start special input device
|
|
|
|
mouseinput = new MouseInput(this);
|
|
|
|
|
|
|
|
// Lock and hide the mouse in window
|
|
|
|
originalclip = Cursor.Clip;
|
|
|
|
Cursor.Clip = display.RectangleToScreen(display.ClientRectangle);
|
|
|
|
Cursor.Hide();
|
|
|
|
}
|
|
|
|
}
|
2008-05-08 16:39:14 +00:00
|
|
|
|
|
|
|
// This is a tool to unlock the mouse
|
|
|
|
private void StopMouseExclusive()
|
2008-01-05 18:11:29 +00:00
|
|
|
{
|
2008-05-08 16:39:14 +00:00
|
|
|
// Locked?
|
2008-01-05 18:11:29 +00:00
|
|
|
if(mouseinput != null)
|
|
|
|
{
|
|
|
|
// Stop special input device
|
|
|
|
mouseinput.Dispose();
|
|
|
|
mouseinput = null;
|
|
|
|
|
|
|
|
// Release and show the mouse
|
|
|
|
Cursor.Clip = originalclip;
|
2008-12-05 15:38:50 +00:00
|
|
|
Cursor.Position = display.PointToScreen(new Point(display.ClientSize.Width / 2, display.ClientSize.Height / 2));
|
2008-01-05 18:11:29 +00:00
|
|
|
Cursor.Show();
|
|
|
|
}
|
|
|
|
}
|
2008-12-05 15:38:50 +00:00
|
|
|
|
2008-05-08 16:39:14 +00:00
|
|
|
// This requests exclusive mouse input
|
|
|
|
public void StartExclusiveMouseInput()
|
|
|
|
{
|
|
|
|
// Only when not already in exclusive mode
|
|
|
|
if(!mouseexclusive)
|
|
|
|
{
|
|
|
|
General.WriteLogLine("Starting exclusive mouse input mode...");
|
|
|
|
|
|
|
|
// Start special input device
|
|
|
|
StartMouseExclusive();
|
|
|
|
mouseexclusive = true;
|
|
|
|
mouseexclusivebreaklevel = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This stops exclusive mouse input
|
|
|
|
public void StopExclusiveMouseInput()
|
|
|
|
{
|
|
|
|
// Only when in exclusive mode
|
|
|
|
if(mouseexclusive)
|
|
|
|
{
|
|
|
|
General.WriteLogLine("Stopping exclusive mouse input mode...");
|
|
|
|
|
|
|
|
// Stop special input device
|
|
|
|
StopMouseExclusive();
|
|
|
|
mouseexclusive = false;
|
|
|
|
mouseexclusivebreaklevel = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This temporarely breaks exclusive mode and counts the break level
|
|
|
|
public void BreakExclusiveMouseInput()
|
|
|
|
{
|
|
|
|
// Only when in exclusive mode
|
|
|
|
if(mouseexclusive)
|
|
|
|
{
|
|
|
|
// Stop special input device
|
|
|
|
StopMouseExclusive();
|
|
|
|
|
|
|
|
// Count the break level
|
|
|
|
mouseexclusivebreaklevel++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This resumes exclusive mode from a break when all breaks have been called to resume
|
|
|
|
public void ResumeExclusiveMouseInput()
|
|
|
|
{
|
|
|
|
// Only when in exclusive mode
|
|
|
|
if(mouseexclusive && (mouseexclusivebreaklevel > 0))
|
|
|
|
{
|
|
|
|
// Decrease break level
|
|
|
|
mouseexclusivebreaklevel--;
|
|
|
|
|
|
|
|
// All break levels resumed? Then lock the mouse again.
|
|
|
|
if(mouseexclusivebreaklevel == 0)
|
|
|
|
StartMouseExclusive();
|
|
|
|
}
|
|
|
|
}
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// When the mouse wheel is changed
|
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
{
|
2008-12-24 14:21:54 +00:00
|
|
|
int mod = 0;
|
|
|
|
if(alt) mod |= (int)Keys.Alt;
|
|
|
|
if(shift) mod |= (int)Keys.Shift;
|
|
|
|
if(ctrl) mod |= (int)Keys.Control;
|
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// Scrollwheel up?
|
|
|
|
if(e.Delta > 0)
|
|
|
|
{
|
|
|
|
// Invoke actions for scrollwheel
|
2007-11-15 23:38:09 +00:00
|
|
|
//for(int i = 0; i < e.Delta; i += 120)
|
2008-12-24 14:21:54 +00:00
|
|
|
General.Actions.KeyPressed((int)SpecialKeys.MScrollUp | mod);
|
|
|
|
General.Actions.KeyReleased((int)SpecialKeys.MScrollUp | mod);
|
2007-06-26 08:03:36 +00:00
|
|
|
}
|
|
|
|
// Scrollwheel down?
|
|
|
|
else if(e.Delta < 0)
|
|
|
|
{
|
|
|
|
// Invoke actions for scrollwheel
|
2007-11-15 23:38:09 +00:00
|
|
|
//for(int i = 0; i > e.Delta; i -= 120)
|
2008-12-24 14:21:54 +00:00
|
|
|
General.Actions.KeyPressed((int)SpecialKeys.MScrollDown | mod);
|
|
|
|
General.Actions.KeyReleased((int)SpecialKeys.MScrollDown | mod);
|
2007-06-26 08:03:36 +00:00
|
|
|
}
|
2007-09-23 22:01:21 +00:00
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// Let the base know
|
|
|
|
base.OnMouseWheel(e);
|
|
|
|
}
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
// When a key is pressed
|
|
|
|
private void MainForm_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
2008-04-27 12:07:26 +00:00
|
|
|
int mod = 0;
|
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// Keep key modifiers
|
|
|
|
alt = e.Alt;
|
|
|
|
shift = e.Shift;
|
|
|
|
ctrl = e.Control;
|
2008-04-27 12:07:26 +00:00
|
|
|
if(alt) mod |= (int)Keys.Alt;
|
|
|
|
if(shift) mod |= (int)Keys.Shift;
|
|
|
|
if(ctrl) mod |= (int)Keys.Control;
|
2007-06-26 08:03:36 +00:00
|
|
|
|
2009-01-16 10:20:19 +00:00
|
|
|
// Don't process any keys when they are meant for the things filter drop down box
|
|
|
|
if(!thingfilters.DroppedDown)
|
|
|
|
{
|
|
|
|
// Invoke any actions associated with this key
|
|
|
|
General.Actions.UpdateModifiers(mod);
|
|
|
|
General.Actions.KeyPressed((int)e.KeyData);
|
|
|
|
|
|
|
|
// Invoke on editing mode
|
|
|
|
if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnKeyDown(e);
|
|
|
|
}
|
2007-06-25 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// When a key is released
|
|
|
|
private void MainForm_KeyUp(object sender, KeyEventArgs e)
|
|
|
|
{
|
2008-04-27 12:07:26 +00:00
|
|
|
int mod = 0;
|
2009-01-16 10:20:19 +00:00
|
|
|
|
2007-06-26 08:03:36 +00:00
|
|
|
// Keep key modifiers
|
|
|
|
alt = e.Alt;
|
|
|
|
shift = e.Shift;
|
|
|
|
ctrl = e.Control;
|
2008-04-27 12:07:26 +00:00
|
|
|
if(alt) mod |= (int)Keys.Alt;
|
|
|
|
if(shift) mod |= (int)Keys.Shift;
|
|
|
|
if(ctrl) mod |= (int)Keys.Control;
|
2009-01-16 10:20:19 +00:00
|
|
|
|
|
|
|
// Don't process any keys when they are meant for the things filter drop down box
|
|
|
|
if(!thingfilters.DroppedDown)
|
|
|
|
{
|
|
|
|
// Invoke any actions associated with this key
|
|
|
|
General.Actions.UpdateModifiers(mod);
|
|
|
|
General.Actions.KeyReleased((int)e.KeyData);
|
|
|
|
|
|
|
|
// Invoke on editing mode
|
|
|
|
if((General.Map != null) && (General.Editing.Mode != null)) General.Editing.Mode.OnKeyUp(e);
|
|
|
|
}
|
2007-06-26 08:03:36 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
#endregion
|
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
#region ================== Toolbar
|
2008-09-10 08:43:20 +00:00
|
|
|
|
|
|
|
// This updates the skills list
|
|
|
|
private void UpdateSkills()
|
|
|
|
{
|
|
|
|
// Clear list
|
|
|
|
buttontest.DropDownItems.Clear();
|
|
|
|
|
|
|
|
// Map loaded?
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Make the new skills list
|
2009-01-04 15:06:51 +00:00
|
|
|
skills = new ToolStripItem[(General.Map.Config.Skills.Count * 2) + 1];
|
|
|
|
int addindex = 0;
|
|
|
|
|
|
|
|
// Positive skills are with monsters
|
|
|
|
for(int i = 0; i < General.Map.Config.Skills.Count; i++)
|
|
|
|
{
|
|
|
|
ToolStripMenuItem menuitem = new ToolStripMenuItem(General.Map.Config.Skills[i].ToString());
|
|
|
|
menuitem.Image = Properties.Resources.Monster2;
|
|
|
|
menuitem.Click += new EventHandler(TestSkill_Click);
|
|
|
|
menuitem.Tag = General.Map.Config.Skills[i].Index;
|
|
|
|
menuitem.Checked = (General.Settings.TestMonsters && (General.Map.ConfigSettings.TestSkill == General.Map.Config.Skills[i].Index));
|
|
|
|
skills[addindex++] = menuitem;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add seperator
|
|
|
|
skills[addindex] = new ToolStripSeparator();
|
|
|
|
skills[addindex].Padding = new Padding(0, 3, 0, 3);
|
|
|
|
addindex++;
|
|
|
|
|
|
|
|
// Negative skills are without monsters
|
2008-09-10 08:43:20 +00:00
|
|
|
for(int i = 0; i < General.Map.Config.Skills.Count; i++)
|
|
|
|
{
|
2009-01-04 15:06:51 +00:00
|
|
|
ToolStripMenuItem menuitem = new ToolStripMenuItem(General.Map.Config.Skills[i].ToString());
|
|
|
|
menuitem.Image = Properties.Resources.Monster3;
|
|
|
|
menuitem.Click += new EventHandler(TestSkill_Click);
|
|
|
|
menuitem.Tag = -General.Map.Config.Skills[i].Index;
|
|
|
|
menuitem.Checked = (!General.Settings.TestMonsters && (General.Map.ConfigSettings.TestSkill == General.Map.Config.Skills[i].Index));
|
|
|
|
skills[addindex++] = menuitem;
|
2008-09-10 08:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add to list
|
|
|
|
buttontest.DropDownItems.AddRange(skills);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Event handler for testing at a specific skill
|
|
|
|
private void TestSkill_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int skill = (int)((sender as ToolStripMenuItem).Tag);
|
2009-01-04 15:06:51 +00:00
|
|
|
General.Settings.TestMonsters = (skill > 0);
|
|
|
|
General.Map.ConfigSettings.TestSkill = Math.Abs(skill);
|
|
|
|
General.Map.Launcher.TestAtSkill(Math.Abs(skill));
|
|
|
|
UpdateSkills();
|
2008-09-26 05:53:34 +00:00
|
|
|
}
|
2008-09-10 08:43:20 +00:00
|
|
|
|
2008-05-26 20:06:15 +00:00
|
|
|
// This loses focus
|
|
|
|
private void LoseFocus(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Lose focus!
|
|
|
|
this.ActiveControl = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Things filter selected
|
|
|
|
private void thingfilters_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Only possible when a map is open
|
|
|
|
if((General.Map != null) && !updatingfilters)
|
|
|
|
{
|
|
|
|
// Change filter
|
|
|
|
General.Map.ChangeThingFilter(thingfilters.SelectedItem as ThingsFilter);
|
|
|
|
}
|
2009-01-16 10:20:19 +00:00
|
|
|
|
2008-05-26 20:06:15 +00:00
|
|
|
// Lose focus
|
2009-01-16 10:20:19 +00:00
|
|
|
if(!thingfilters.DroppedDown) LoseFocus(sender, e);
|
2008-05-26 20:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This updates the things filter on the toolbar
|
|
|
|
internal void UpdateThingsFilters()
|
|
|
|
{
|
|
|
|
// Only possible to list filters when a map is open
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
ThingsFilter oldfilter = null;
|
|
|
|
if(thingfilters.SelectedIndex > -1)
|
|
|
|
oldfilter = thingfilters.SelectedItem as ThingsFilter;
|
|
|
|
|
|
|
|
updatingfilters = true;
|
|
|
|
|
|
|
|
// Clear the list
|
|
|
|
thingfilters.Items.Clear();
|
|
|
|
|
|
|
|
// Add null filter
|
|
|
|
if(General.Map.ThingsFilter is NullThingsFilter)
|
|
|
|
thingfilters.Items.Add(General.Map.ThingsFilter);
|
|
|
|
else
|
|
|
|
thingfilters.Items.Add(new NullThingsFilter());
|
|
|
|
|
|
|
|
// Add all filters
|
|
|
|
foreach(ThingsFilter f in General.Map.ConfigSettings.ThingsFilters)
|
|
|
|
thingfilters.Items.Add(f);
|
|
|
|
|
|
|
|
// Select current filter
|
|
|
|
foreach(ThingsFilter f in thingfilters.Items)
|
|
|
|
if(f == General.Map.ThingsFilter) thingfilters.SelectedItem = f;
|
|
|
|
|
|
|
|
updatingfilters = false;
|
|
|
|
|
|
|
|
// No filter selected?
|
|
|
|
if(thingfilters.SelectedIndex == -1)
|
|
|
|
{
|
|
|
|
// Select the first and update
|
|
|
|
thingfilters.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
// Another filter got selected?
|
|
|
|
else if(oldfilter != (thingfilters.SelectedItem as ThingsFilter))
|
|
|
|
{
|
|
|
|
// Update!
|
|
|
|
thingfilters_SelectedIndexChanged(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Clear the list
|
|
|
|
thingfilters.Items.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
// This adds a button to the toolbar
|
|
|
|
public void AddButton(ToolStripItem button)
|
|
|
|
{
|
|
|
|
// Find the plugin that called this method
|
|
|
|
Plugin plugin = General.Plugins.FindPluginByAssembly(Assembly.GetCallingAssembly());
|
|
|
|
|
|
|
|
// Fix tags to full action names
|
|
|
|
ToolStripItemCollection items = new ToolStripItemCollection(toolbar, new ToolStripItem[0]);
|
|
|
|
items.Add(button);
|
|
|
|
RenameTagsToFullActions(items, plugin);
|
|
|
|
|
|
|
|
// Bind visible changed event
|
|
|
|
if(!(button is ToolStripSeparator)) button.VisibleChanged += buttonvisiblechangedhandler;
|
|
|
|
|
|
|
|
// Insert the button at the end of the toolbar
|
|
|
|
toolbar.Items.Add(button);
|
2009-01-27 15:44:45 +00:00
|
|
|
UpdateSeparators();
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Removes a button
|
|
|
|
public void RemoveButton(ToolStripItem button)
|
|
|
|
{
|
|
|
|
// Unbind visible changed event
|
|
|
|
if(!(button is ToolStripSeparator)) button.VisibleChanged -= buttonvisiblechangedhandler;
|
|
|
|
|
|
|
|
// Remove button
|
|
|
|
toolbar.Items.Remove(button);
|
2009-01-27 15:44:45 +00:00
|
|
|
UpdateSeparators();
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This handle visibility changes in the toolbar buttons
|
|
|
|
private void ToolbarButtonVisibleChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Update the seeprators
|
2009-01-27 15:44:45 +00:00
|
|
|
UpdateSeparators();
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
|
|
|
|
2009-01-27 15:44:45 +00:00
|
|
|
// This hides redundant seperators and shows single seperators
|
|
|
|
internal void UpdateSeparators()
|
|
|
|
{
|
|
|
|
UpdateToolStripSeparators(toolbar.Items, false);
|
|
|
|
UpdateToolStripSeparators(menumode.DropDownItems, true);
|
|
|
|
}
|
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
// This updates the seperators
|
|
|
|
// Hides redundant seperators and shows single seperators
|
2009-01-27 15:44:45 +00:00
|
|
|
private void UpdateToolStripSeparators(ToolStripItemCollection items, bool defaultvisible)
|
2008-05-26 12:14:48 +00:00
|
|
|
{
|
|
|
|
ToolStripItem pvi = null;
|
2009-01-27 15:44:45 +00:00
|
|
|
foreach(ToolStripItem i in items)
|
2008-05-26 12:14:48 +00:00
|
|
|
{
|
2009-01-27 15:44:45 +00:00
|
|
|
bool separatorvisible = false;
|
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
// This is a seperator?
|
|
|
|
if(i is ToolStripSeparator)
|
|
|
|
{
|
|
|
|
// Make visible when previous item was not a seperator
|
2009-01-27 15:44:45 +00:00
|
|
|
separatorvisible = !(pvi is ToolStripSeparator) && (pvi != null);
|
|
|
|
i.Visible = separatorvisible;
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
2009-01-27 15:44:45 +00:00
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
// Keep as previous visible item
|
2009-01-27 15:44:45 +00:00
|
|
|
if(i.Visible || separatorvisible || (defaultvisible && !(i is ToolStripSeparator))) pvi = i;
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
2009-01-27 15:44:45 +00:00
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
// Hide last item if it is a seperator
|
|
|
|
if(pvi is ToolStripSeparator) pvi.Visible = false;
|
|
|
|
}
|
|
|
|
|
2008-09-26 05:53:34 +00:00
|
|
|
// This enables or disables all editing mode items and toolbar buttons
|
|
|
|
private void UpdateToolbar()
|
2008-05-26 12:14:48 +00:00
|
|
|
{
|
2008-09-26 05:53:34 +00:00
|
|
|
// Enable/disable all edit mode items
|
2008-05-26 12:14:48 +00:00
|
|
|
foreach(ToolStripItem i in editmodeitems) i.Enabled = (General.Map != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This checks one of the edit mode items (and unchecks all others)
|
|
|
|
internal void CheckEditModeButton(string modeclassname)
|
|
|
|
{
|
|
|
|
// Go for all items
|
|
|
|
foreach(ToolStripItem i in editmodeitems)
|
|
|
|
{
|
|
|
|
// Check what type it is
|
|
|
|
if(i is ToolStripMenuItem)
|
|
|
|
{
|
|
|
|
// Check if mode type matches with given name
|
|
|
|
(i as ToolStripMenuItem).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
|
|
|
|
}
|
|
|
|
else if(i is ToolStripButton)
|
|
|
|
{
|
|
|
|
// Check if mode type matches with given name
|
|
|
|
(i as ToolStripButton).Checked = ((i.Tag as EditModeInfo).Type.Name == modeclassname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This removes the config-specific editing mode buttons
|
2008-11-27 10:33:09 +00:00
|
|
|
internal void RemoveEditModeButtons()
|
2008-05-26 12:14:48 +00:00
|
|
|
{
|
2008-11-27 10:33:09 +00:00
|
|
|
// Go for all items
|
|
|
|
foreach(ToolStripItem i in editmodeitems)
|
2008-05-26 12:14:48 +00:00
|
|
|
{
|
2008-11-27 10:33:09 +00:00
|
|
|
// Remove it and restart
|
|
|
|
toolbar.Items.Remove(i);
|
|
|
|
menumode.DropDownItems.Remove(i);
|
2009-01-27 15:44:45 +00:00
|
|
|
i.Dispose();
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
2008-11-27 10:33:09 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
editmodeitems.Clear();
|
2009-01-27 15:44:45 +00:00
|
|
|
UpdateSeparators();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This adds an editing mode seperator on the toolbar and menu
|
|
|
|
internal void AddEditModeSeperator()
|
|
|
|
{
|
|
|
|
ToolStripSeparator item;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
// Create a button
|
|
|
|
index = toolbar.Items.IndexOf(buttoneditmodesseperator);
|
|
|
|
item = new ToolStripSeparator();
|
|
|
|
item.Margin = new Padding(6, 0, 6, 0);
|
|
|
|
toolbar.Items.Insert(index, item);
|
|
|
|
editmodeitems.Add(item);
|
|
|
|
|
|
|
|
// Create menu item
|
|
|
|
index = menumode.DropDownItems.Count;
|
|
|
|
item = new ToolStripSeparator();
|
|
|
|
item.Margin = new Padding(0, 3, 0, 3);
|
|
|
|
menumode.DropDownItems.Insert(index, item);
|
|
|
|
editmodeitems.Add(item);
|
|
|
|
|
|
|
|
UpdateSeparators();
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This adds an editing mode button to the toolbar and edit menu
|
|
|
|
internal void AddEditModeButton(EditModeInfo modeinfo)
|
|
|
|
{
|
|
|
|
ToolStripItem item;
|
|
|
|
int index;
|
2009-01-15 21:25:29 +00:00
|
|
|
|
|
|
|
string controlname = modeinfo.ButtonDesc.Replace("&", "&&");
|
2008-05-26 12:14:48 +00:00
|
|
|
|
|
|
|
// Create a button
|
|
|
|
index = toolbar.Items.IndexOf(buttoneditmodesseperator);
|
|
|
|
item = new ToolStripButton(modeinfo.ButtonDesc, modeinfo.ButtonImage, new EventHandler(EditModeButtonHandler));
|
|
|
|
item.DisplayStyle = ToolStripItemDisplayStyle.Image;
|
|
|
|
item.Tag = modeinfo;
|
|
|
|
toolbar.Items.Insert(index, item);
|
|
|
|
editmodeitems.Add(item);
|
|
|
|
|
|
|
|
// Create menu item
|
2008-09-24 15:14:29 +00:00
|
|
|
index = menumode.DropDownItems.Count;
|
2009-01-15 21:25:29 +00:00
|
|
|
item = new ToolStripMenuItem(controlname, modeinfo.ButtonImage, new EventHandler(EditModeButtonHandler));
|
2008-05-26 12:14:48 +00:00
|
|
|
item.Tag = modeinfo;
|
2008-09-24 15:14:29 +00:00
|
|
|
menumode.DropDownItems.Insert(index, item);
|
2008-05-26 12:14:48 +00:00
|
|
|
editmodeitems.Add(item);
|
2009-01-27 15:44:45 +00:00
|
|
|
item.Visible = true;
|
|
|
|
|
2008-09-24 16:44:53 +00:00
|
|
|
ApplyShortcutKeys(menumode.DropDownItems);
|
2009-01-27 15:44:45 +00:00
|
|
|
UpdateSeparators();
|
2008-05-26 12:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This handles edit mode button clicks
|
|
|
|
private void EditModeButtonHandler(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
EditModeInfo modeinfo;
|
|
|
|
|
|
|
|
this.Update();
|
|
|
|
modeinfo = (EditModeInfo)((sender as ToolStripItem).Tag);
|
2008-12-10 22:58:58 +00:00
|
|
|
General.Actions.InvokeAction(modeinfo.SwitchAction.GetFullActionName(modeinfo.Plugin.Assembly));
|
2008-05-26 12:14:48 +00:00
|
|
|
this.Update();
|
|
|
|
}
|
2008-10-15 11:46:43 +00:00
|
|
|
|
2008-05-26 12:14:48 +00:00
|
|
|
#endregion
|
2008-10-15 11:46:43 +00:00
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
#region ================== Menus
|
|
|
|
|
2008-05-14 21:48:36 +00:00
|
|
|
// This adds a menu to the menus bar
|
|
|
|
public void AddMenu(ToolStripMenuItem menu)
|
|
|
|
{
|
2008-05-16 20:00:49 +00:00
|
|
|
// Find the plugin that called this method
|
|
|
|
Plugin plugin = General.Plugins.FindPluginByAssembly(Assembly.GetCallingAssembly());
|
|
|
|
|
|
|
|
// Fix tags to full action names
|
|
|
|
RenameTagsToFullActions(menu.DropDownItems, plugin);
|
|
|
|
|
2008-05-14 21:48:36 +00:00
|
|
|
// Insert the menu before the Tools menu
|
|
|
|
menumain.Items.Insert(menumain.Items.IndexOf(menutools), menu);
|
2008-05-15 12:36:55 +00:00
|
|
|
ApplyShortcutKeys(menu.DropDownItems);
|
2008-05-14 21:48:36 +00:00
|
|
|
}
|
2008-05-16 20:00:49 +00:00
|
|
|
|
|
|
|
// Removes a menu
|
2008-05-14 21:48:36 +00:00
|
|
|
public void RemoveMenu(ToolStripMenuItem menu)
|
|
|
|
{
|
|
|
|
menumain.Items.Remove(menu);
|
|
|
|
}
|
|
|
|
|
2007-06-24 22:53:41 +00:00
|
|
|
// Public method to apply shortcut keys
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ApplyShortcutKeys()
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
|
|
|
// Apply shortcut keys to menus
|
|
|
|
ApplyShortcutKeys(menumain.Items);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This sets the shortcut keys on menu items
|
|
|
|
private void ApplyShortcutKeys(ToolStripItemCollection items)
|
|
|
|
{
|
|
|
|
// Go for all controls to find menu items
|
|
|
|
foreach(ToolStripItem item in items)
|
|
|
|
{
|
|
|
|
// This is a menu item?
|
|
|
|
if(item is ToolStripMenuItem)
|
|
|
|
{
|
|
|
|
// Get the item in proper type
|
2008-05-16 20:00:49 +00:00
|
|
|
ToolStripMenuItem menuitem = (item as ToolStripMenuItem);
|
2007-06-24 22:53:41 +00:00
|
|
|
|
|
|
|
// Tag set for this item?
|
2008-09-24 16:44:53 +00:00
|
|
|
if(menuitem.Tag is string)
|
2007-06-24 22:53:41 +00:00
|
|
|
{
|
2008-09-24 16:44:53 +00:00
|
|
|
// Action with this name available?
|
2008-05-16 20:00:49 +00:00
|
|
|
string actionname = menuitem.Tag.ToString();
|
2008-09-24 16:44:53 +00:00
|
|
|
if(General.Actions.Exists(actionname))
|
|
|
|
{
|
|
|
|
// Put the action shortcut key on the menu item
|
|
|
|
menuitem.ShortcutKeyDisplayString = Action.GetShortcutKeyDesc(General.Actions[actionname].ShortcutKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Edit mode info set for this item?
|
|
|
|
else if(menuitem.Tag is EditModeInfo)
|
|
|
|
{
|
2007-06-24 22:53:41 +00:00
|
|
|
// Action with this name available?
|
2008-09-24 16:44:53 +00:00
|
|
|
EditModeInfo modeinfo = (menuitem.Tag as EditModeInfo);
|
|
|
|
string actionname = modeinfo.SwitchAction.GetFullActionName(modeinfo.Plugin.Assembly);
|
2007-06-24 22:53:41 +00:00
|
|
|
if(General.Actions.Exists(actionname))
|
|
|
|
{
|
|
|
|
// Put the action shortcut key on the menu item
|
2007-06-25 06:55:30 +00:00
|
|
|
menuitem.ShortcutKeyDisplayString = Action.GetShortcutKeyDesc(General.Actions[actionname].ShortcutKey);
|
2007-06-24 22:53:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively apply shortcut keys to child menu items as well
|
|
|
|
ApplyShortcutKeys(menuitem.DropDownItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-10 15:54:42 +00:00
|
|
|
|
2008-05-16 20:00:49 +00:00
|
|
|
// This fixes short action names to fully qualified
|
|
|
|
// action names on menu item tags
|
|
|
|
private void RenameTagsToFullActions(ToolStripItemCollection items, Plugin plugin)
|
|
|
|
{
|
|
|
|
// Go for all controls to find menu items
|
|
|
|
foreach(ToolStripItem item in items)
|
|
|
|
{
|
2008-10-08 12:56:12 +00:00
|
|
|
// Tag set for this item?
|
|
|
|
if((item.Tag != null) && (item.Tag is string))
|
2008-05-16 20:00:49 +00:00
|
|
|
{
|
2008-10-08 12:56:12 +00:00
|
|
|
// Get the action name
|
|
|
|
string actionname = item.Tag.ToString();
|
2008-05-16 20:00:49 +00:00
|
|
|
|
2008-10-08 12:56:12 +00:00
|
|
|
// Check if the tag doe not already begin with the assembly name
|
|
|
|
if(!(item.Tag as string).StartsWith(plugin.Name + "_", StringComparison.InvariantCultureIgnoreCase))
|
2008-05-16 20:00:49 +00:00
|
|
|
{
|
2008-10-08 12:56:12 +00:00
|
|
|
// Change the tag to a fully qualified action name
|
|
|
|
item.Tag = plugin.Name.ToLowerInvariant() + "_" + (item.Tag as string);
|
2008-05-16 20:00:49 +00:00
|
|
|
}
|
2008-10-08 12:56:12 +00:00
|
|
|
}
|
2008-05-16 20:00:49 +00:00
|
|
|
|
2008-10-08 12:56:12 +00:00
|
|
|
// This is a menu item?
|
|
|
|
if(item is ToolStripMenuItem)
|
|
|
|
{
|
|
|
|
// Get the item in proper type
|
|
|
|
ToolStripMenuItem menuitem = (item as ToolStripMenuItem);
|
|
|
|
|
2008-05-16 20:00:49 +00:00
|
|
|
// Recursively perform operation on child menu items
|
|
|
|
RenameTagsToFullActions(menuitem.DropDownItems, plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#region ================== File Menu
|
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
// This sets up the file menu
|
|
|
|
private void UpdateFileMenu()
|
|
|
|
{
|
|
|
|
// Enable/disable items
|
|
|
|
itemclosemap.Enabled = (General.Map != null);
|
|
|
|
itemsavemap.Enabled = (General.Map != null);
|
|
|
|
itemsavemapas.Enabled = (General.Map != null);
|
|
|
|
itemsavemapinto.Enabled = (General.Map != null);
|
2008-05-23 06:00:37 +00:00
|
|
|
itemtestmap.Enabled = (General.Map != null);
|
2007-10-14 15:44:55 +00:00
|
|
|
|
|
|
|
// Toolbar icons
|
|
|
|
buttonnewmap.Enabled = itemnewmap.Enabled;
|
|
|
|
buttonopenmap.Enabled = itemopenmap.Enabled;
|
|
|
|
buttonsavemap.Enabled = itemsavemap.Enabled;
|
2008-05-23 06:00:37 +00:00
|
|
|
buttontest.Enabled = itemtestmap.Enabled;
|
2007-06-15 10:18:03 +00:00
|
|
|
}
|
|
|
|
|
2007-10-10 15:54:42 +00:00
|
|
|
// This sets the recent files from configuration
|
|
|
|
private void CreateRecentFiles()
|
|
|
|
{
|
|
|
|
int insertindex;
|
|
|
|
bool anyitems = false;
|
|
|
|
string filename;
|
|
|
|
|
|
|
|
// Where to insert
|
|
|
|
insertindex = menufile.DropDownItems.IndexOf(itemnorecent);
|
|
|
|
|
|
|
|
// Create all items
|
|
|
|
recentitems = new ToolStripMenuItem[MAX_RECENT_FILES];
|
|
|
|
for(int i = 0; i < MAX_RECENT_FILES; i++)
|
|
|
|
{
|
|
|
|
// Create item
|
|
|
|
recentitems[i] = new ToolStripMenuItem("");
|
|
|
|
recentitems[i].Tag = "";
|
|
|
|
recentitems[i].Click += new EventHandler(recentitem_Click);
|
|
|
|
menufile.DropDownItems.Insert(insertindex + i, recentitems[i]);
|
|
|
|
|
|
|
|
// Get configuration setting
|
|
|
|
filename = General.Settings.ReadSetting("recentfiles.file" + i, "");
|
|
|
|
if(filename != "")
|
|
|
|
{
|
|
|
|
// Set up item
|
|
|
|
recentitems[i].Text = GetDisplayFilename(filename);
|
|
|
|
recentitems[i].Tag = filename;
|
|
|
|
recentitems[i].Visible = true;
|
|
|
|
anyitems = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Hide item
|
|
|
|
recentitems[i].Visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide the no recent item when there are items
|
|
|
|
itemnorecent.Visible = !anyitems;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This saves the recent files list
|
|
|
|
private void SaveRecentFiles()
|
|
|
|
{
|
|
|
|
// Go for all items
|
|
|
|
for(int i = 0; i < MAX_RECENT_FILES; i++)
|
|
|
|
{
|
|
|
|
// Recent file set?
|
|
|
|
if(recentitems[i].Text != "")
|
|
|
|
{
|
|
|
|
// Save to configuration
|
|
|
|
General.Settings.WriteSetting("recentfiles.file" + i, recentitems[i].Tag.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This adds a recent file to the list
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void AddRecentFile(string filename)
|
2007-10-10 15:54:42 +00:00
|
|
|
{
|
|
|
|
int movedownto = MAX_RECENT_FILES - 1;
|
|
|
|
|
|
|
|
// Check if this file is already in the list
|
|
|
|
for(int i = 0; i < MAX_RECENT_FILES; i++)
|
|
|
|
{
|
|
|
|
// File same as this item?
|
|
|
|
if(string.Compare(filename, recentitems[i].Tag.ToString(), true) == 0)
|
|
|
|
{
|
|
|
|
// Move down to here so that this item will disappear
|
|
|
|
movedownto = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go for all items, except the last one, backwards
|
|
|
|
for(int i = movedownto - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
// Move recent file down the list
|
|
|
|
recentitems[i + 1].Text = recentitems[i].Text;
|
|
|
|
recentitems[i + 1].Tag = recentitems[i].Tag.ToString();
|
|
|
|
recentitems[i + 1].Visible = (recentitems[i + 1].Text != "");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add new file at the top
|
|
|
|
recentitems[0].Text = GetDisplayFilename(filename);
|
|
|
|
recentitems[0].Tag = filename;
|
|
|
|
recentitems[0].Visible = true;
|
2007-10-15 07:50:28 +00:00
|
|
|
|
|
|
|
// Hide the no recent item
|
|
|
|
itemnorecent.Visible = false;
|
2007-10-10 15:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the trimmed file/path string
|
|
|
|
private string GetDisplayFilename(string filename)
|
|
|
|
{
|
|
|
|
string newname;
|
|
|
|
|
|
|
|
// String doesnt fit?
|
|
|
|
if(GetStringWidth(filename) > MAX_RECENT_FILES_PIXELS)
|
|
|
|
{
|
|
|
|
// Start chopping off characters
|
|
|
|
for(int i = filename.Length - 6; i >= 0; i--)
|
|
|
|
{
|
|
|
|
// Does it fit now?
|
|
|
|
newname = filename.Substring(0, 3) + "..." + filename.Substring(filename.Length - i, i);
|
|
|
|
if(GetStringWidth(newname) <= MAX_RECENT_FILES_PIXELS) return newname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cant find anything that fits (most unlikely!)
|
|
|
|
return "wtf?!";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The whole string fits
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the width of a string
|
|
|
|
private float GetStringWidth(string str)
|
|
|
|
{
|
|
|
|
Graphics g = Graphics.FromHwndInternal(this.Handle);
|
|
|
|
SizeF strsize = g.MeasureString(str, this.Font);
|
|
|
|
return strsize.Width;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit clicked
|
|
|
|
private void itemexit_Click(object sender, EventArgs e) { this.Close(); }
|
|
|
|
|
|
|
|
// Recent item clicked
|
2007-10-14 21:31:45 +00:00
|
|
|
private void recentitem_Click(object sender, EventArgs e)
|
2007-10-10 15:54:42 +00:00
|
|
|
{
|
|
|
|
// Get the item that was clicked
|
|
|
|
ToolStripItem item = (sender as ToolStripItem);
|
|
|
|
|
|
|
|
// Open this file
|
2007-10-14 21:31:45 +00:00
|
|
|
General.OpenMapFile(item.Tag.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Edit Menu
|
|
|
|
|
|
|
|
// This sets up the edit menu
|
|
|
|
private void UpdateEditMenu()
|
|
|
|
{
|
|
|
|
// No edit menu when no map open
|
2007-10-20 19:50:03 +00:00
|
|
|
//menuedit.Visible = (General.Map != null);
|
2007-10-14 21:31:45 +00:00
|
|
|
|
|
|
|
// Enable/disable items
|
2007-12-08 15:18:14 +00:00
|
|
|
itemundo.Enabled = (General.Map != null) && (General.Map.UndoRedo.NextUndo != null);
|
|
|
|
itemredo.Enabled = (General.Map != null) && (General.Map.UndoRedo.NextRedo != null);
|
2008-11-27 13:42:18 +00:00
|
|
|
itemcut.Enabled = (General.Map != null) && (General.Editing.Mode != null) && General.Editing.Mode.Attributes.AllowCopyPaste;
|
|
|
|
itemcopy.Enabled = (General.Map != null) && (General.Editing.Mode != null) && General.Editing.Mode.Attributes.AllowCopyPaste;
|
|
|
|
itempaste.Enabled = (General.Map != null) && (General.Editing.Mode != null) && General.Editing.Mode.Attributes.AllowCopyPaste;
|
2007-10-20 19:50:03 +00:00
|
|
|
itemmapoptions.Enabled = (General.Map != null);
|
2007-12-01 01:32:56 +00:00
|
|
|
itemsnaptogrid.Enabled = (General.Map != null);
|
2007-12-08 15:18:14 +00:00
|
|
|
itemautomerge.Enabled = (General.Map != null);
|
2008-06-10 08:35:14 +00:00
|
|
|
itemgridsetup.Enabled = (General.Map != null);
|
|
|
|
itemgridinc.Enabled = (General.Map != null);
|
|
|
|
itemgriddec.Enabled = (General.Map != null);
|
2007-11-12 22:43:01 +00:00
|
|
|
|
|
|
|
// Determine undo description
|
|
|
|
if(itemundo.Enabled)
|
2008-12-24 18:27:13 +00:00
|
|
|
itemundo.Text = "Undo " + General.Map.UndoRedo.NextUndo.Description;
|
2007-11-12 22:43:01 +00:00
|
|
|
else
|
|
|
|
itemundo.Text = "Undo";
|
|
|
|
|
|
|
|
// Determine redo description
|
|
|
|
if(itemredo.Enabled)
|
2008-12-24 18:27:13 +00:00
|
|
|
itemredo.Text = "Redo " + General.Map.UndoRedo.NextRedo.Description;
|
2007-11-12 22:43:01 +00:00
|
|
|
else
|
|
|
|
itemredo.Text = "Redo";
|
2007-10-14 21:31:45 +00:00
|
|
|
|
|
|
|
// Toolbar icons
|
|
|
|
buttonmapoptions.Enabled = (General.Map != null);
|
2007-11-12 22:43:01 +00:00
|
|
|
buttonundo.Enabled = itemundo.Enabled;
|
|
|
|
buttonredo.Enabled = itemredo.Enabled;
|
|
|
|
buttonundo.ToolTipText = itemundo.Text;
|
|
|
|
buttonredo.ToolTipText = itemredo.Text;
|
2007-12-01 01:32:56 +00:00
|
|
|
buttonsnaptogrid.Enabled = (General.Map != null);
|
2007-12-08 15:18:14 +00:00
|
|
|
buttonautomerge.Enabled = (General.Map != null);
|
2008-09-16 07:35:57 +00:00
|
|
|
buttoncut.Enabled = itemcut.Enabled;
|
|
|
|
buttoncopy.Enabled = itemcopy.Enabled;
|
|
|
|
buttonpaste.Enabled = itempaste.Enabled;
|
2007-12-01 01:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Action to toggle snap to grid
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("togglesnap")]
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ToggleSnapToGrid()
|
2007-12-01 01:32:56 +00:00
|
|
|
{
|
|
|
|
buttonsnaptogrid.Checked = !buttonsnaptogrid.Checked;
|
|
|
|
itemsnaptogrid.Checked = buttonsnaptogrid.Checked;
|
2009-02-27 15:38:13 +00:00
|
|
|
string onoff = buttonsnaptogrid.Checked ? "ON" : "OFF";
|
|
|
|
DisplayStatus(StatusType.Action, "Snap to grid is now " + onoff + " by default.");
|
2007-10-10 15:54:42 +00:00
|
|
|
}
|
2007-12-08 15:18:14 +00:00
|
|
|
|
|
|
|
// Action to toggle auto merge
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("toggleautomerge")]
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ToggleAutoMerge()
|
2007-12-08 15:18:14 +00:00
|
|
|
{
|
|
|
|
buttonautomerge.Checked = !buttonautomerge.Checked;
|
|
|
|
itemautomerge.Checked = buttonautomerge.Checked;
|
2009-02-27 15:38:13 +00:00
|
|
|
string onoff = buttonautomerge.Checked ? "ON" : "OFF";
|
|
|
|
DisplayStatus(StatusType.Action, "Snap to geometry is now " + onoff + " by default.");
|
2007-12-08 15:18:14 +00:00
|
|
|
}
|
2007-10-10 15:54:42 +00:00
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
2007-06-15 22:38:42 +00:00
|
|
|
|
2008-11-17 00:41:52 +00:00
|
|
|
#region ================== View Menu
|
|
|
|
|
|
|
|
// This sets up the modes menu
|
|
|
|
private void UpdateViewMenu()
|
|
|
|
{
|
2008-11-18 13:05:04 +00:00
|
|
|
// Menu items
|
|
|
|
itemthingsfilter.Enabled = (General.Map != null);
|
|
|
|
itemscripteditor.Enabled = (General.Map != null);
|
|
|
|
|
2008-11-17 00:41:52 +00:00
|
|
|
// View mode items
|
|
|
|
for(int i = 0; i < Renderer2D.NUM_VIEW_MODES; i++)
|
|
|
|
{
|
|
|
|
// NOTE: We only disable them when no map is loaded, because they may
|
|
|
|
// need to be disabled for non-classic modes
|
|
|
|
if(General.Map == null)
|
|
|
|
{
|
|
|
|
viewmodesbuttons[i].Enabled = false;
|
|
|
|
viewmodesbuttons[i].Checked = false;
|
|
|
|
viewmodesitems[i].Enabled = false;
|
|
|
|
viewmodesitems[i].Checked = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check the correct item
|
|
|
|
viewmodesbuttons[i].Checked = (i == (int)General.Map.CRenderer2D.ViewMode);
|
|
|
|
viewmodesitems[i].Checked = (i == (int)General.Map.CRenderer2D.ViewMode);
|
|
|
|
}
|
|
|
|
}
|
2008-11-18 13:05:04 +00:00
|
|
|
|
|
|
|
// Toolbar icons
|
|
|
|
thingfilters.Enabled = (General.Map != null);
|
|
|
|
buttonthingsfilter.Enabled = (General.Map != null);
|
|
|
|
buttonscripteditor.Enabled = (General.Map != null);
|
|
|
|
UpdateThingsFilters();
|
2008-11-17 00:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-09-24 15:14:29 +00:00
|
|
|
#region ================== Mode Menu
|
|
|
|
|
|
|
|
// This sets up the modes menu
|
|
|
|
private void UpdateModeMenu()
|
|
|
|
{
|
2009-01-27 15:44:45 +00:00
|
|
|
menumode.Visible = (General.Map != null);
|
2008-09-24 15:14:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-06-15 22:38:42 +00:00
|
|
|
#region ================== Help Menu
|
|
|
|
|
|
|
|
// About clicked
|
|
|
|
private void itemhelpabout_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
AboutForm aboutform;
|
|
|
|
|
|
|
|
// Show about dialog
|
|
|
|
aboutform = new AboutForm();
|
|
|
|
aboutform.ShowDialog(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-09-27 22:55:03 +00:00
|
|
|
|
2008-12-31 16:43:23 +00:00
|
|
|
#region ================== Prefabs Menu
|
|
|
|
|
|
|
|
// This sets up the prefabs menu
|
|
|
|
private void UpdatePrefabsMenu()
|
|
|
|
{
|
|
|
|
// Enable/disable items
|
|
|
|
itemcreateprefab.Enabled = (General.Map != null);
|
|
|
|
iteminsertprefabfile.Enabled = (General.Map != null);
|
|
|
|
iteminsertpreviousprefab.Enabled = (General.Map != null) && General.Map.CopyPaste.IsPreviousPrefabAvailable;
|
|
|
|
|
|
|
|
// Toolbar icons
|
|
|
|
buttoninsertprefabfile.Enabled = (General.Map != null);
|
|
|
|
buttoninsertpreviousprefab.Enabled = (General.Map != null) && General.Map.CopyPaste.IsPreviousPrefabAvailable;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
#region ================== Tools Menu
|
|
|
|
|
2007-10-14 21:31:45 +00:00
|
|
|
// This sets up the tools menu
|
|
|
|
private void UpdateToolsMenu()
|
|
|
|
{
|
|
|
|
// Enable/disable items
|
|
|
|
itemreloadresources.Enabled = (General.Map != null);
|
|
|
|
}
|
|
|
|
|
2009-02-26 16:03:43 +00:00
|
|
|
// Errors and Warnings
|
|
|
|
[BeginAction("showerrors")]
|
|
|
|
internal void ShowErrors()
|
|
|
|
{
|
2009-02-26 23:27:46 +00:00
|
|
|
ErrorsForm errform = new ErrorsForm();
|
|
|
|
errform.ShowDialog(this);
|
|
|
|
errform.Dispose();
|
2009-02-26 16:03:43 +00:00
|
|
|
}
|
|
|
|
|
2007-10-09 20:47:08 +00:00
|
|
|
// Game Configuration action
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("configuration")]
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ShowConfiguration()
|
2008-05-23 06:00:37 +00:00
|
|
|
{
|
|
|
|
// Show configuration dialog
|
|
|
|
ShowConfigurationPage(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This shows the configuration on a specific page
|
|
|
|
internal void ShowConfigurationPage(int pageindex)
|
2007-09-27 22:55:03 +00:00
|
|
|
{
|
|
|
|
// Show configuration dialog
|
|
|
|
ConfigForm cfgform = new ConfigForm();
|
2008-05-23 06:00:37 +00:00
|
|
|
if(pageindex > -1) cfgform.ShowTab(pageindex);
|
2007-09-30 19:37:57 +00:00
|
|
|
if(cfgform.ShowDialog(this) == DialogResult.OK)
|
2007-10-09 20:47:08 +00:00
|
|
|
{
|
2007-10-14 21:31:45 +00:00
|
|
|
// Update interface
|
|
|
|
UpdateInterface();
|
2008-05-15 09:43:19 +00:00
|
|
|
|
|
|
|
// Let the plugins know
|
|
|
|
General.Plugins.ProgramReconfigure();
|
2008-05-23 06:00:37 +00:00
|
|
|
|
2007-10-14 21:31:45 +00:00
|
|
|
// Reload resources if a map is open
|
2008-12-10 22:58:58 +00:00
|
|
|
if(General.Map != null) General.Actions.InvokeAction("builder_reloadresources");
|
2008-05-23 06:00:37 +00:00
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
// Redraw display
|
|
|
|
RedrawDisplay();
|
2007-10-09 20:47:08 +00:00
|
|
|
}
|
2008-05-23 06:00:37 +00:00
|
|
|
|
2007-10-09 20:47:08 +00:00
|
|
|
// Done
|
|
|
|
cfgform.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preferences action
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("preferences")]
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ShowPreferences()
|
2007-10-09 20:47:08 +00:00
|
|
|
{
|
|
|
|
// Show preferences dialog
|
|
|
|
PreferencesForm prefform = new PreferencesForm();
|
|
|
|
if(prefform.ShowDialog(this) == DialogResult.OK)
|
2007-09-30 19:37:57 +00:00
|
|
|
{
|
|
|
|
// Update shortcut keys in menus
|
|
|
|
ApplyShortcutKeys();
|
2008-05-15 09:43:19 +00:00
|
|
|
|
2008-09-26 15:15:56 +00:00
|
|
|
// Generate new color correction table
|
|
|
|
General.Colors.CreateCorrectionTable();
|
|
|
|
|
2008-05-15 09:43:19 +00:00
|
|
|
// Let the plugins know
|
|
|
|
General.Plugins.ProgramReconfigure();
|
2007-10-21 22:41:46 +00:00
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
// Map opened?
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
2008-12-10 22:58:58 +00:00
|
|
|
// Reload resources!
|
2008-11-18 14:20:49 +00:00
|
|
|
if(General.Map.ScriptEditor != null) General.Map.ScriptEditor.Editor.RefreshSettings();
|
2008-02-24 21:52:18 +00:00
|
|
|
General.Map.Graphics.SetupSettings();
|
2008-11-30 02:17:19 +00:00
|
|
|
General.Map.UpdateConfiguration();
|
2008-12-10 22:58:58 +00:00
|
|
|
General.Actions.InvokeAction("builder_reloadresources");
|
2008-02-24 21:52:18 +00:00
|
|
|
}
|
2007-10-21 12:58:56 +00:00
|
|
|
|
2007-10-20 12:34:27 +00:00
|
|
|
// Redraw display
|
|
|
|
RedrawDisplay();
|
2007-09-30 19:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
2007-10-09 20:47:08 +00:00
|
|
|
prefform.Dispose();
|
2007-09-27 22:55:03 +00:00
|
|
|
}
|
2008-11-10 16:11:44 +00:00
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
#endregion
|
2007-10-24 17:25:03 +00:00
|
|
|
|
|
|
|
#region ================== Info Panels
|
|
|
|
|
2009-01-04 13:19:18 +00:00
|
|
|
// This toggles the panel expanded / collapsed
|
|
|
|
[BeginAction("toggleinfopanel")]
|
|
|
|
internal void ToggleInfoPanel()
|
|
|
|
{
|
|
|
|
if(IsInfoPanelExpanded)
|
|
|
|
{
|
|
|
|
panelinfo.Height = COLLAPSED_INFO_HEIGHT;
|
|
|
|
buttontoggleinfo.Text = "5"; // Arrow up
|
|
|
|
if(linedefinfo.Visible) linedefinfo.Hide();
|
|
|
|
if(vertexinfo.Visible) vertexinfo.Hide();
|
|
|
|
if(sectorinfo.Visible) sectorinfo.Hide();
|
|
|
|
if(thinginfo.Visible) thinginfo.Hide();
|
|
|
|
modename.Visible = false;
|
|
|
|
labelcollapsedinfo.Visible = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
panelinfo.Height = EXPANDED_INFO_HEIGHT;
|
|
|
|
buttontoggleinfo.Text = "6"; // Arrow down
|
|
|
|
labelcollapsedinfo.Visible = false;
|
|
|
|
if(lastinfoobject is Vertex) ShowVertexInfo(lastinfoobject as Vertex);
|
|
|
|
else if(lastinfoobject is Linedef) ShowLinedefInfo(lastinfoobject as Linedef);
|
|
|
|
else if(lastinfoobject is Sector) ShowSectorInfo(lastinfoobject as Sector);
|
|
|
|
else if(lastinfoobject is Thing) ShowThingInfo(lastinfoobject as Thing);
|
|
|
|
else HideInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
FocusDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse released on info panel toggle button
|
|
|
|
private void buttontoggleinfo_MouseUp(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
FocusDisplay();
|
|
|
|
}
|
|
|
|
|
2008-06-11 05:02:48 +00:00
|
|
|
// This displays the current mode name
|
|
|
|
internal void DisplayModeName(string name)
|
|
|
|
{
|
2009-01-04 13:19:18 +00:00
|
|
|
if(lastinfoobject == null)
|
|
|
|
{
|
|
|
|
labelcollapsedinfo.Text = name;
|
|
|
|
labelcollapsedinfo.Refresh();
|
|
|
|
}
|
2008-06-11 05:02:48 +00:00
|
|
|
modename.Text = name;
|
|
|
|
modename.Refresh();
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:25:03 +00:00
|
|
|
// This hides all info panels
|
|
|
|
public void HideInfo()
|
|
|
|
{
|
|
|
|
// Hide them all
|
2009-01-04 13:19:18 +00:00
|
|
|
lastinfoobject = null;
|
2007-10-24 17:25:03 +00:00
|
|
|
if(linedefinfo.Visible) linedefinfo.Hide();
|
|
|
|
if(vertexinfo.Visible) vertexinfo.Hide();
|
|
|
|
if(sectorinfo.Visible) sectorinfo.Hide();
|
|
|
|
if(thinginfo.Visible) thinginfo.Hide();
|
2009-01-04 13:19:18 +00:00
|
|
|
labelcollapsedinfo.Text = modename.Text;
|
|
|
|
labelcollapsedinfo.Refresh();
|
|
|
|
modename.Visible = ((General.Map != null) && IsInfoPanelExpanded);
|
2008-06-11 05:02:48 +00:00
|
|
|
modename.Refresh();
|
2007-10-24 17:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 12:37:31 +00:00
|
|
|
// This refreshes info
|
|
|
|
public void RefreshInfo()
|
|
|
|
{
|
|
|
|
if(lastinfoobject is Vertex) ShowVertexInfo(lastinfoobject as Vertex);
|
|
|
|
else if(lastinfoobject is Linedef) ShowLinedefInfo(lastinfoobject as Linedef);
|
|
|
|
else if(lastinfoobject is Sector) ShowSectorInfo(lastinfoobject as Sector);
|
|
|
|
else if(lastinfoobject is Thing) ShowThingInfo(lastinfoobject as Thing);
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:25:03 +00:00
|
|
|
// Show linedef info
|
2008-06-11 05:02:48 +00:00
|
|
|
public void ShowLinedefInfo(Linedef l)
|
|
|
|
{
|
2009-01-04 13:19:18 +00:00
|
|
|
lastinfoobject = l;
|
2008-06-11 05:02:48 +00:00
|
|
|
modename.Visible = false;
|
2009-01-04 12:27:06 +00:00
|
|
|
if(vertexinfo.Visible) vertexinfo.Hide();
|
|
|
|
if(sectorinfo.Visible) sectorinfo.Hide();
|
|
|
|
if(thinginfo.Visible) thinginfo.Hide();
|
2009-01-04 13:19:18 +00:00
|
|
|
if(IsInfoPanelExpanded) linedefinfo.ShowInfo(l);
|
|
|
|
|
|
|
|
// Show info on collapsed label
|
|
|
|
if(General.Map.Config.LinedefActions.ContainsKey(l.Action))
|
|
|
|
{
|
|
|
|
LinedefActionInfo act = General.Map.Config.LinedefActions[l.Action];
|
|
|
|
labelcollapsedinfo.Text = act.ToString();
|
|
|
|
}
|
|
|
|
else if(l.Action == 0)
|
|
|
|
labelcollapsedinfo.Text = l.Action.ToString() + " - None";
|
|
|
|
else
|
|
|
|
labelcollapsedinfo.Text = l.Action.ToString() + " - Unknown";
|
|
|
|
|
|
|
|
labelcollapsedinfo.Refresh();
|
2008-06-11 05:02:48 +00:00
|
|
|
}
|
2007-10-24 17:25:03 +00:00
|
|
|
|
|
|
|
// Show vertex info
|
2008-06-11 05:02:48 +00:00
|
|
|
public void ShowVertexInfo(Vertex v)
|
|
|
|
{
|
2009-01-04 13:19:18 +00:00
|
|
|
lastinfoobject = v;
|
2008-06-11 05:02:48 +00:00
|
|
|
modename.Visible = false;
|
2009-01-04 12:27:06 +00:00
|
|
|
if(linedefinfo.Visible) linedefinfo.Hide();
|
|
|
|
if(sectorinfo.Visible) sectorinfo.Hide();
|
|
|
|
if(thinginfo.Visible) thinginfo.Hide();
|
2009-01-04 13:19:18 +00:00
|
|
|
if(IsInfoPanelExpanded) vertexinfo.ShowInfo(v);
|
|
|
|
|
|
|
|
// Show info on collapsed label
|
|
|
|
labelcollapsedinfo.Text = v.Position.x.ToString("0.##") + ", " + v.Position.y.ToString("0.##");
|
|
|
|
labelcollapsedinfo.Refresh();
|
2008-06-11 05:02:48 +00:00
|
|
|
}
|
2007-10-24 17:25:03 +00:00
|
|
|
|
|
|
|
// Show sector info
|
2008-06-11 05:02:48 +00:00
|
|
|
public void ShowSectorInfo(Sector s)
|
|
|
|
{
|
2009-01-04 13:19:18 +00:00
|
|
|
lastinfoobject = s;
|
2008-06-11 05:02:48 +00:00
|
|
|
modename.Visible = false;
|
2009-01-04 12:27:06 +00:00
|
|
|
if(linedefinfo.Visible) linedefinfo.Hide();
|
|
|
|
if(vertexinfo.Visible) vertexinfo.Hide();
|
|
|
|
if(thinginfo.Visible) thinginfo.Hide();
|
2009-01-04 13:19:18 +00:00
|
|
|
if(IsInfoPanelExpanded) sectorinfo.ShowInfo(s);
|
|
|
|
|
|
|
|
// Show info on collapsed label
|
|
|
|
if(General.Map.Config.SectorEffects.ContainsKey(s.Effect))
|
|
|
|
labelcollapsedinfo.Text = General.Map.Config.SectorEffects[s.Effect].ToString();
|
|
|
|
else if(s.Effect == 0)
|
|
|
|
labelcollapsedinfo.Text = s.Effect.ToString() + " - Normal";
|
|
|
|
else
|
|
|
|
labelcollapsedinfo.Text = s.Effect.ToString() + " - Unknown";
|
|
|
|
|
|
|
|
labelcollapsedinfo.Refresh();
|
2008-06-11 05:02:48 +00:00
|
|
|
}
|
2007-10-24 17:25:03 +00:00
|
|
|
|
|
|
|
// Show thing info
|
2008-06-11 05:02:48 +00:00
|
|
|
public void ShowThingInfo(Thing t)
|
|
|
|
{
|
2009-01-04 13:19:18 +00:00
|
|
|
lastinfoobject = t;
|
2008-06-11 05:02:48 +00:00
|
|
|
modename.Visible = false;
|
2009-01-04 12:27:06 +00:00
|
|
|
if(linedefinfo.Visible) linedefinfo.Hide();
|
|
|
|
if(vertexinfo.Visible) vertexinfo.Hide();
|
|
|
|
if(sectorinfo.Visible) sectorinfo.Hide();
|
2009-01-04 13:19:18 +00:00
|
|
|
if(IsInfoPanelExpanded) thinginfo.ShowInfo(t);
|
|
|
|
|
|
|
|
// Show info on collapsed label
|
2009-01-21 16:18:30 +00:00
|
|
|
ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
|
2009-01-04 13:19:18 +00:00
|
|
|
labelcollapsedinfo.Text = t.Type + " - " + ti.Title;
|
|
|
|
labelcollapsedinfo.Refresh();
|
2008-06-11 05:02:48 +00:00
|
|
|
}
|
2007-10-24 17:25:03 +00:00
|
|
|
|
|
|
|
#endregion
|
2008-01-02 21:49:43 +00:00
|
|
|
|
|
|
|
#region ================== Dialogs
|
|
|
|
|
2008-10-17 09:39:07 +00:00
|
|
|
// This browses for a texture
|
|
|
|
// Returns the new texture name or the same texture name when cancelled
|
|
|
|
public string BrowseTexture(IWin32Window owner, string initialvalue)
|
|
|
|
{
|
|
|
|
return TextureBrowserForm.Browse(owner, initialvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This browses for a flat
|
|
|
|
// Returns the new flat name or the same flat name when cancelled
|
|
|
|
public string BrowseFlat(IWin32Window owner, string initialvalue)
|
|
|
|
{
|
|
|
|
return FlatBrowserForm.Browse(owner, initialvalue);
|
|
|
|
}
|
|
|
|
|
2008-09-01 12:14:35 +00:00
|
|
|
// This browses the lindef types
|
|
|
|
// Returns the new action or the same action when cancelled
|
|
|
|
public int BrowseLinedefActions(IWin32Window owner, int initialvalue)
|
|
|
|
{
|
|
|
|
return ActionBrowserForm.BrowseAction(owner, initialvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This browses sector effects
|
|
|
|
// Returns the new effect or the same effect when cancelled
|
|
|
|
public int BrowseSectorEffect(IWin32Window owner, int initialvalue)
|
|
|
|
{
|
|
|
|
return EffectBrowserForm.BrowseEffect(owner, initialvalue);
|
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// This shows the dialog to edit lines
|
2008-06-11 05:02:48 +00:00
|
|
|
public DialogResult ShowEditLinedefs(ICollection<Linedef> lines)
|
2008-01-02 21:49:43 +00:00
|
|
|
{
|
2008-06-11 05:02:48 +00:00
|
|
|
DialogResult result;
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Show line edit dialog
|
|
|
|
LinedefEditForm f = new LinedefEditForm();
|
|
|
|
f.Setup(lines);
|
2008-06-11 05:02:48 +00:00
|
|
|
result = f.ShowDialog(this);
|
2008-01-02 21:49:43 +00:00
|
|
|
f.Dispose();
|
2008-06-11 05:02:48 +00:00
|
|
|
|
|
|
|
return result;
|
2008-01-02 21:49:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 06:47:43 +00:00
|
|
|
// This shows the dialog to edit sectors
|
2008-06-11 05:02:48 +00:00
|
|
|
public DialogResult ShowEditSectors(ICollection<Sector> sectors)
|
2008-02-21 06:47:43 +00:00
|
|
|
{
|
2008-06-11 05:02:48 +00:00
|
|
|
DialogResult result;
|
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
// Show sector edit dialog
|
2008-02-21 06:47:43 +00:00
|
|
|
SectorEditForm f = new SectorEditForm();
|
|
|
|
f.Setup(sectors);
|
2008-06-11 05:02:48 +00:00
|
|
|
result = f.ShowDialog(this);
|
2008-02-21 06:47:43 +00:00
|
|
|
f.Dispose();
|
2008-06-11 05:02:48 +00:00
|
|
|
|
|
|
|
return result;
|
2008-02-21 06:47:43 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
// This shows the dialog to edit things
|
2008-06-11 05:02:48 +00:00
|
|
|
public DialogResult ShowEditThings(ICollection<Thing> things)
|
2008-05-17 17:43:57 +00:00
|
|
|
{
|
2008-06-11 05:02:48 +00:00
|
|
|
DialogResult result;
|
|
|
|
|
2008-05-17 17:43:57 +00:00
|
|
|
// Show thing edit dialog
|
|
|
|
ThingEditForm f = new ThingEditForm();
|
|
|
|
f.Setup(things);
|
2008-06-11 05:02:48 +00:00
|
|
|
result = f.ShowDialog(this);
|
2008-05-17 17:43:57 +00:00
|
|
|
f.Dispose();
|
2008-06-11 05:02:48 +00:00
|
|
|
|
|
|
|
return result;
|
2008-05-17 17:43:57 +00:00
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
#endregion
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2008-11-18 13:05:04 +00:00
|
|
|
#region ================== Message Pump
|
|
|
|
|
|
|
|
// This handles messages
|
|
|
|
protected override unsafe void WndProc(ref Message m)
|
|
|
|
{
|
|
|
|
// Notify message?
|
|
|
|
switch(m.Msg)
|
|
|
|
{
|
2009-02-26 14:16:18 +00:00
|
|
|
case (int)ThreadMessages.UpdateStatus:
|
|
|
|
DisplayStatus(status);
|
2008-11-18 13:05:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case (int)ThreadMessages.ImageDataLoaded:
|
|
|
|
string imagename = Marshal.PtrToStringAuto(m.WParam);
|
|
|
|
Marshal.FreeCoTaskMem(m.WParam);
|
2009-01-03 22:18:59 +00:00
|
|
|
if((General.Map != null) && (General.Map.Data != null))
|
2008-11-18 13:05:04 +00:00
|
|
|
{
|
|
|
|
ImageData img = General.Map.Data.GetFlatImage(imagename);
|
|
|
|
if(img != null) ImageDataLoaded(img);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-01 21:20:52 +00:00
|
|
|
|
|
|
|
case General.WM_SYSCOMMAND:
|
|
|
|
// We don't want to open a menu when ALT is pressed
|
|
|
|
if(m.WParam.ToInt32() != General.SC_KEYMENU)
|
|
|
|
{
|
|
|
|
base.WndProc(ref m);
|
|
|
|
}
|
|
|
|
break;
|
2008-11-18 13:05:04 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// Let the base handle the message
|
|
|
|
base.WndProc(ref m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-10-15 11:46:43 +00:00
|
|
|
#region ================== Processing
|
2008-11-18 13:05:04 +00:00
|
|
|
|
2008-10-15 11:46:43 +00:00
|
|
|
// This is called from the background thread when images are loaded
|
|
|
|
// but only when first loaded or when dimensions were changed
|
|
|
|
internal void ImageDataLoaded(ImageData img)
|
|
|
|
{
|
2008-11-18 13:05:04 +00:00
|
|
|
// Image is used in the map?
|
|
|
|
if((img != null) && img.UsedInMap && !img.IsDisposed)
|
2008-10-15 11:46:43 +00:00
|
|
|
{
|
2008-11-18 13:05:04 +00:00
|
|
|
// Go for all setors
|
|
|
|
bool updated = false;
|
|
|
|
foreach(Sector s in General.Map.Map.Sectors)
|
2008-10-15 11:46:43 +00:00
|
|
|
{
|
2008-11-18 13:05:04 +00:00
|
|
|
// Update floor buffer if needed
|
|
|
|
if(s.LongFloorTexture == img.LongName)
|
2008-10-15 11:46:43 +00:00
|
|
|
{
|
2008-11-18 13:05:04 +00:00
|
|
|
s.UpdateFloorSurface();
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update ceiling buffer if needed
|
|
|
|
if(s.LongCeilTexture == img.LongName)
|
|
|
|
{
|
|
|
|
s.UpdateCeilingSurface();
|
|
|
|
updated = true;
|
2008-10-15 11:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-18 13:05:04 +00:00
|
|
|
|
|
|
|
// If we made updates, redraw the screen
|
|
|
|
if(updated) DelayedRedraw();
|
2008-10-15 11:46:43 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2009-02-22 22:57:21 +00:00
|
|
|
public void EnableProcessing()
|
2008-01-05 18:11:29 +00:00
|
|
|
{
|
2009-02-22 22:57:21 +00:00
|
|
|
// Increase count
|
|
|
|
processingcount++;
|
|
|
|
|
|
|
|
// If not already enabled, enable processing now
|
|
|
|
if(!processor.Enabled)
|
|
|
|
{
|
|
|
|
processor.Enabled = true;
|
|
|
|
lastupdatetime = General.Clock.GetCurrentTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisableProcessing()
|
|
|
|
{
|
|
|
|
// Increase count
|
|
|
|
processingcount--;
|
|
|
|
if(processingcount < 0) processingcount = 0;
|
|
|
|
|
|
|
|
// Turn off
|
|
|
|
if(processor.Enabled && (processingcount == 0))
|
|
|
|
processor.Enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void StopProcessing()
|
|
|
|
{
|
|
|
|
// Turn off
|
|
|
|
processingcount = 0;
|
|
|
|
processor.Enabled = false;
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Processor event
|
|
|
|
private void processor_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Vector2D deltamouse;
|
2008-11-27 06:53:38 +00:00
|
|
|
double curtime = General.Clock.GetCurrentTime();
|
|
|
|
double deltatime = curtime - lastupdatetime;
|
|
|
|
lastupdatetime = curtime;
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
// In exclusive mouse mode?
|
|
|
|
if(mouseinput != null)
|
|
|
|
{
|
|
|
|
// Process mouse input
|
|
|
|
deltamouse = mouseinput.Process();
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (General.Editing.Mode != null))
|
|
|
|
General.Editing.Mode.OnMouseInput(deltamouse);
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process signal
|
2008-11-27 11:59:17 +00:00
|
|
|
if((General.Map != null) && (General.Editing.Mode != null))
|
|
|
|
General.Editing.Mode.OnProcess(deltatime);
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-06-13 19:39:38 +00:00
|
|
|
}
|
|
|
|
}
|