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;
|
2007-06-24 22:53:41 +00:00
|
|
|
using CodeImp.DoomBuilder.Controls;
|
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;
|
2007-06-13 19:39:38 +00:00
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Interface
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
private const string STATUS_READY_TEXT = "Ready.";
|
2007-10-10 15:54:42 +00:00
|
|
|
private const int MAX_RECENT_FILES = 8;
|
|
|
|
private const int MAX_RECENT_FILES_PIXELS = 250;
|
2007-06-14 14:44:18 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
#region ================== Delegates
|
|
|
|
|
|
|
|
private delegate void CallUpdateStatusIcon();
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
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-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
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
// Recent files
|
|
|
|
private ToolStripMenuItem[] recentitems;
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
// Edit modes
|
|
|
|
private List<ToolStripItem> editmodeitems;
|
|
|
|
|
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; } }
|
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; } }
|
|
|
|
|
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>();
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
UpdateToolsMenu();
|
2008-01-02 21:49:43 +00:00
|
|
|
UpdateEditModeItems();
|
2007-10-14 21:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generic event that invokes the tagged action
|
|
|
|
private void InvokeTaggedAction(object sender, EventArgs e)
|
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
string asmname;
|
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
this.Update();
|
2008-01-02 21:49:43 +00:00
|
|
|
asmname = General.ThisAssembly.GetName().Name.ToLowerInvariant();
|
2008-04-27 12:07:26 +00:00
|
|
|
General.Actions[asmname + "_" + (sender as ToolStripItem).Tag.ToString()].Begin();
|
2007-10-26 19:06:59 +00:00
|
|
|
this.Update();
|
2007-10-14 21:31:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Window
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
// Resume any exclusive mouse input
|
|
|
|
ResumeExclusiveMouseInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window loses focus
|
|
|
|
private void MainForm_Deactivate(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Release all pressed keys
|
|
|
|
General.Actions.ReleaseAllKeys();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
General.WriteLogLine("Closing main interface window...");
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Stop exclusive mode, if any is active
|
|
|
|
StopExclusiveMouseInput();
|
|
|
|
SetProcessorState(false);
|
|
|
|
|
2007-10-04 18:16:05 +00:00
|
|
|
// Unbind methods
|
2008-04-27 12:07:26 +00:00
|
|
|
General.Actions.UnbindMethods(this);
|
2007-06-14 15:35:37 +00:00
|
|
|
|
|
|
|
// Determine window state to save
|
2007-06-24 18:56:43 +00:00
|
|
|
if(this.WindowState != FormWindowState.Minimized)
|
|
|
|
windowstate = (int)this.WindowState;
|
|
|
|
else
|
|
|
|
windowstate = (int)FormWindowState.Normal;
|
2007-06-14 15:35:37 +00:00
|
|
|
|
2007-10-10 15:54:42 +00:00
|
|
|
// Save window settings
|
2007-06-14 15:35:37 +00:00
|
|
|
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);
|
|
|
|
|
2007-10-10 15:54:42 +00:00
|
|
|
// Save recent files
|
|
|
|
SaveRecentFiles();
|
|
|
|
|
2007-06-14 15:35:37 +00:00
|
|
|
// Terminate the program
|
2007-10-04 18:52:21 +00:00
|
|
|
General.Terminate(true);
|
2007-06-13 19:39:38 +00:00
|
|
|
}
|
2007-06-14 14:44:18 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Statusbar
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-14 18:11:03 +00:00
|
|
|
// This returns the current status text
|
2008-01-02 21:49:43 +00:00
|
|
|
internal string GetCurrentSatus()
|
2007-10-14 18:11:03 +00:00
|
|
|
{
|
|
|
|
return statuslabel.Text;
|
|
|
|
}
|
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
// This changes status text
|
|
|
|
public void DisplayStatus(string status)
|
|
|
|
{
|
|
|
|
// Update status description
|
|
|
|
if(statuslabel.Text != status)
|
|
|
|
statuslabel.Text = status;
|
|
|
|
|
2007-10-26 19:06:59 +00:00
|
|
|
// Update icon as well
|
|
|
|
UpdateStatusIcon();
|
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
// Refresh if needed
|
|
|
|
statusbar.Invalidate();
|
|
|
|
this.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This changes status text to Ready
|
|
|
|
public void DisplayReady()
|
|
|
|
{
|
|
|
|
// Display ready status description
|
|
|
|
DisplayStatus(STATUS_READY_TEXT);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
// From another thread?
|
|
|
|
if(statusbar.InvokeRequired)
|
|
|
|
{
|
|
|
|
// Call to form thread
|
|
|
|
CallUpdateStatusIcon call = new CallUpdateStatusIcon(UpdateStatusIcon);
|
|
|
|
this.Invoke(call);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ready status?
|
|
|
|
if(statuslabel.Text == STATUS_READY_TEXT)
|
|
|
|
{
|
|
|
|
// Map open?
|
|
|
|
if((General.Map != null) && (General.Map.Data != null))
|
|
|
|
{
|
|
|
|
// Check if loading in the background
|
|
|
|
if(General.Map.Data.IsLoading)
|
|
|
|
{
|
|
|
|
// Display semi-ready icon
|
|
|
|
statuslabel.Image = CodeImp.DoomBuilder.Properties.Resources.Status1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Display ready icon
|
|
|
|
statuslabel.Image = CodeImp.DoomBuilder.Properties.Resources.Status0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Display ready icon
|
|
|
|
statuslabel.Image = CodeImp.DoomBuilder.Properties.Resources.Status0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Display busy icon
|
|
|
|
statuslabel.Image = CodeImp.DoomBuilder.Properties.Resources.Status2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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?
|
2007-10-20 01:04:47 +00:00
|
|
|
if(General.Map.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
|
2007-10-20 01:04:47 +00:00
|
|
|
(General.Map.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?
|
2007-10-20 01:04:47 +00:00
|
|
|
if(General.Map.Mode is ClassicMode)
|
|
|
|
(General.Map.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?
|
|
|
|
if(General.Map.Mode is ClassicMode)
|
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
ShowGridSetup();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This shows the grid setup dialog
|
2008-04-27 12:07:26 +00:00
|
|
|
[BeginAction("gridsetup")]
|
2008-01-02 21:49:43 +00:00
|
|
|
internal void ShowGridSetup()
|
2007-11-10 19:24:52 +00:00
|
|
|
{
|
|
|
|
// Only when a map is open
|
|
|
|
if(General.Map == null) return;
|
|
|
|
|
|
|
|
// Show preferences dialog
|
|
|
|
GridSetupForm gridform = new GridSetupForm();
|
|
|
|
if(gridform.ShowDialog(this) == DialogResult.OK)
|
|
|
|
{
|
|
|
|
// Redraw display
|
|
|
|
RedrawDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
|
|
|
gridform.Dispose();
|
|
|
|
}
|
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
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
#region ================== Toolbar
|
|
|
|
|
|
|
|
// This enables or disables all editing mode items
|
|
|
|
private void UpdateEditModeItems()
|
|
|
|
{
|
|
|
|
// Enable/disable all items
|
|
|
|
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
|
|
|
|
internal void RemoveSpecificEditModeButtons()
|
|
|
|
{
|
|
|
|
bool removed;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Go for all items
|
|
|
|
removed = false;
|
|
|
|
foreach(ToolStripItem i in editmodeitems)
|
|
|
|
{
|
|
|
|
// Only remove the button if it is for a config-specific editing mode
|
|
|
|
if((i.Tag as EditModeInfo).ConfigSpecific)
|
|
|
|
{
|
|
|
|
// Remove it and restart
|
|
|
|
editmodeitems.Remove(i);
|
|
|
|
toolbar.Items.Remove(i);
|
|
|
|
menuedit.DropDownItems.Remove(i);
|
|
|
|
removed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(removed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This adds an editing mode button to the toolbar and edit menu
|
|
|
|
internal void AddEditModeButton(EditModeInfo modeinfo)
|
|
|
|
{
|
|
|
|
ToolStripItem item;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
item.Enabled = (General.Map != null);
|
|
|
|
toolbar.Items.Insert(index, item);
|
|
|
|
editmodeitems.Add(item);
|
|
|
|
|
|
|
|
// Create menu item
|
|
|
|
index = menuedit.DropDownItems.IndexOf(itemeditmodesseperator);
|
|
|
|
item = new ToolStripMenuItem(modeinfo.ButtonDesc, modeinfo.ButtonImage, new EventHandler(EditModeButtonHandler));
|
|
|
|
item.Tag = modeinfo;
|
|
|
|
item.Enabled = (General.Map != null);
|
|
|
|
menuedit.DropDownItems.Insert(index, item);
|
|
|
|
editmodeitems.Add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This handles edit mode button clicks
|
|
|
|
private void EditModeButtonHandler(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
EditModeInfo modeinfo;
|
|
|
|
|
|
|
|
this.Update();
|
|
|
|
modeinfo = (EditModeInfo)((sender as ToolStripItem).Tag);
|
2008-04-27 12:07:26 +00:00
|
|
|
General.Actions[modeinfo.SwitchAction.GetFullActionName(modeinfo.Plugin.Assembly)].Begin();
|
2008-01-02 21:49:43 +00:00
|
|
|
this.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
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();
|
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
|
|
|
|
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-04-12 12:45:57 +00:00
|
|
|
if((General.Map != null) && (General.Map.Mode != null))
|
|
|
|
{
|
|
|
|
General.Map.Mode.RedrawDisplay();
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if(General.Map.Mode != null)
|
|
|
|
{
|
|
|
|
if(!displayresized) General.Map.Mode.RefreshDisplay();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e.Graphics.Clear(Color.FromArgb(General.Colors.Background.ToInt()));
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
2007-06-15 18:30:55 +00:00
|
|
|
// Mouse click
|
2008-04-20 23:22:16 +00:00
|
|
|
private void display_MouseClick(object sender, MouseEventArgs e) { if((General.Map != null) && (General.Map.Mode != null)) General.Map.Mode.MouseClick(e); }
|
2007-06-15 18:30:55 +00:00
|
|
|
|
|
|
|
// Mouse doubleclick
|
2008-04-20 23:22:16 +00:00
|
|
|
private void display_MouseDoubleClick(object sender, MouseEventArgs e) { if((General.Map != null) && (General.Map.Mode != null)) General.Map.Mode.MouseDoubleClick(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;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
General.Actions.KeyPressed(key);
|
|
|
|
|
|
|
|
// Invoke on editing mode
|
|
|
|
if((General.Map != null) && (General.Map.Mode != null)) General.Map.Mode.MouseDown(e);
|
|
|
|
}
|
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-04-20 23:22:16 +00:00
|
|
|
if((General.Map != null) && (mouseinput == null) && (General.Map.Mode != null)) General.Map.Mode.MouseEnter(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-04-20 23:22:16 +00:00
|
|
|
if((General.Map != null) && (mouseinput == null) && (General.Map.Mode != null)) General.Map.Mode.MouseLeave(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-04-20 23:22:16 +00:00
|
|
|
if((General.Map != null) && (mouseinput == null) && (General.Map.Mode != null)) General.Map.Mode.MouseMove(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;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
General.Actions.KeyReleased(key);
|
|
|
|
|
|
|
|
// Invoke on editing mode
|
|
|
|
if((General.Map != null) && (General.Map.Mode != null)) General.Map.Mode.MouseUp(e);
|
|
|
|
}
|
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
|
|
|
// This checks if a given action is active
|
|
|
|
public bool CheckActionActive(Assembly assembly, string actionname)
|
|
|
|
{
|
|
|
|
if(assembly == null)
|
|
|
|
return General.Actions.CheckActionActive(General.ThisAssembly, actionname);
|
|
|
|
else
|
|
|
|
return General.Actions.CheckActionActive(assembly, actionname);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
Cursor.Show();
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
// 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-04-27 12:07:26 +00:00
|
|
|
General.Actions.KeyPressed((int)SpecialKeys.MScrollUp);
|
|
|
|
General.Actions.KeyReleased((int)SpecialKeys.MScrollUp);
|
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-04-27 12:07:26 +00:00
|
|
|
General.Actions.KeyPressed((int)SpecialKeys.MScrollDown);
|
|
|
|
General.Actions.KeyReleased((int)SpecialKeys.MScrollDown);
|
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
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
// Invoke any actions associated with this key
|
2008-04-27 12:07:26 +00:00
|
|
|
General.Actions.UpdateModifiers(mod);
|
|
|
|
General.Actions.KeyPressed((int)e.KeyData);
|
2007-11-14 22:53:48 +00:00
|
|
|
|
|
|
|
// Invoke on editing mode
|
2008-04-20 23:22:16 +00:00
|
|
|
if((General.Map != null) && (General.Map.Mode != null)) General.Map.Mode.KeyDown(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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Invoke any actions associated with this key
|
|
|
|
General.Actions.UpdateModifiers(mod);
|
|
|
|
General.Actions.KeyReleased((int)e.KeyData);
|
2007-11-14 22:53:48 +00:00
|
|
|
|
|
|
|
// Invoke on editing mode
|
2008-04-20 23:22:16 +00:00
|
|
|
if((General.Map != null) && (General.Map.Mode != null)) General.Map.Mode.KeyUp(e);
|
2007-06-26 08:03:36 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 19:28:03 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-15 10:18:03 +00:00
|
|
|
#region ================== Menus
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ToolStripMenuItem menuitem;
|
|
|
|
string actionname;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
menuitem = (item as ToolStripMenuItem);
|
|
|
|
|
|
|
|
// Tag set for this item?
|
|
|
|
if(menuitem.Tag != null)
|
|
|
|
{
|
|
|
|
// Get the action name
|
|
|
|
actionname = menuitem.Tag.ToString();
|
|
|
|
|
|
|
|
// Action with this name available?
|
|
|
|
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
|
|
|
|
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);
|
2007-10-14 15:44:55 +00:00
|
|
|
|
|
|
|
// Toolbar icons
|
|
|
|
buttonnewmap.Enabled = itemnewmap.Enabled;
|
|
|
|
buttonopenmap.Enabled = itemopenmap.Enabled;
|
|
|
|
buttonsavemap.Enabled = itemsavemap.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);
|
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);
|
2007-11-12 22:43:01 +00:00
|
|
|
|
|
|
|
// Determine undo description
|
|
|
|
if(itemundo.Enabled)
|
|
|
|
itemundo.Text = "Undo " + General.Map.UndoRedo.NextUndo.description;
|
|
|
|
else
|
|
|
|
itemundo.Text = "Undo";
|
|
|
|
|
|
|
|
// Determine redo description
|
|
|
|
if(itemredo.Enabled)
|
|
|
|
itemredo.Text = "Redo " + General.Map.UndoRedo.NextRedo.description;
|
|
|
|
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);
|
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;
|
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;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
#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);
|
|
|
|
|
|
|
|
// Toolbar icons
|
|
|
|
}
|
|
|
|
|
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()
|
2007-09-27 22:55:03 +00:00
|
|
|
{
|
|
|
|
// Show configuration dialog
|
|
|
|
ConfigForm cfgform = new ConfigForm();
|
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();
|
|
|
|
|
|
|
|
// Reload resources if a map is open
|
|
|
|
if(General.Map != null) General.Map.ReloadResources();
|
2007-10-20 12:34:27 +00:00
|
|
|
|
|
|
|
// Redraw display
|
|
|
|
RedrawDisplay();
|
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();
|
2007-10-21 22:41:46 +00:00
|
|
|
|
2008-02-24 21:52:18 +00:00
|
|
|
// Map opened?
|
|
|
|
if(General.Map != null)
|
|
|
|
{
|
|
|
|
// Setup and reload stuff
|
|
|
|
General.Map.Graphics.SetupSettings();
|
|
|
|
General.Map.Map.UpdateConfiguration();
|
|
|
|
General.Map.ReloadResources();
|
|
|
|
}
|
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
|
|
|
}
|
2007-10-09 20:47:08 +00:00
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
#endregion
|
2007-10-24 17:25:03 +00:00
|
|
|
|
|
|
|
#region ================== Info Panels
|
|
|
|
|
|
|
|
// This hides all info panels
|
|
|
|
public void HideInfo()
|
|
|
|
{
|
|
|
|
// Hide them all
|
|
|
|
if(linedefinfo.Visible) linedefinfo.Hide();
|
|
|
|
if(vertexinfo.Visible) vertexinfo.Hide();
|
|
|
|
if(sectorinfo.Visible) sectorinfo.Hide();
|
|
|
|
if(thinginfo.Visible) thinginfo.Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show linedef info
|
|
|
|
public void ShowLinedefInfo(Linedef l) { linedefinfo.ShowInfo(l); }
|
|
|
|
|
|
|
|
// Show vertex info
|
|
|
|
public void ShowVertexInfo(Vertex v) { vertexinfo.ShowInfo(v); }
|
|
|
|
|
|
|
|
// Show sector info
|
|
|
|
public void ShowSectorInfo(Sector s) { sectorinfo.ShowInfo(s); }
|
|
|
|
|
|
|
|
// Show thing info
|
|
|
|
public void ShowThingInfo(Thing t) { thinginfo.ShowInfo(t); }
|
|
|
|
|
|
|
|
#endregion
|
2008-01-02 21:49:43 +00:00
|
|
|
|
|
|
|
#region ================== Dialogs
|
|
|
|
|
|
|
|
// This shows the dialog to edit lines
|
|
|
|
public void ShowEditLinedefs(ICollection<Linedef> lines)
|
|
|
|
{
|
|
|
|
// Show line edit dialog
|
|
|
|
LinedefEditForm f = new LinedefEditForm();
|
|
|
|
f.Setup(lines);
|
|
|
|
f.ShowDialog(this);
|
|
|
|
f.Dispose();
|
|
|
|
}
|
|
|
|
|
2008-02-21 06:47:43 +00:00
|
|
|
// This shows the dialog to edit sectors
|
|
|
|
public void ShowEditSectors(ICollection<Sector> sectors)
|
|
|
|
{
|
|
|
|
// Show line edit dialog
|
|
|
|
SectorEditForm f = new SectorEditForm();
|
|
|
|
f.Setup(sectors);
|
|
|
|
f.ShowDialog(this);
|
|
|
|
f.Dispose();
|
|
|
|
}
|
|
|
|
|
2008-01-02 21:49:43 +00:00
|
|
|
#endregion
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
#region ================== Processor
|
|
|
|
|
|
|
|
// This toggles the processor
|
|
|
|
public void SetProcessorState(bool on)
|
|
|
|
{
|
|
|
|
processor.Enabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Processor event
|
|
|
|
private void processor_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Vector2D deltamouse;
|
|
|
|
|
|
|
|
// In exclusive mouse mode?
|
|
|
|
if(mouseinput != null)
|
|
|
|
{
|
|
|
|
// Process mouse input
|
|
|
|
deltamouse = mouseinput.Process();
|
|
|
|
if((General.Map != null) && (General.Map.Mode != null))
|
|
|
|
General.Map.Mode.MouseInput(deltamouse);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process signal
|
|
|
|
if((General.Map != null) && (General.Map.Mode != null))
|
|
|
|
General.Map.Mode.Process();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-06-13 19:39:38 +00:00
|
|
|
}
|
|
|
|
}
|