UltimateZoneBuilder/Source/Editing/EditMode.cs

218 lines
6 KiB
C#
Raw Normal View History

2007-06-15 18:30:55 +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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Windows;
2007-06-15 18:30:55 +00:00
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
2007-06-15 22:38:42 +00:00
using CodeImp.DoomBuilder.Rendering;
2007-06-24 18:56:43 +00:00
using System.Diagnostics;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.Geometry;
2007-06-15 18:30:55 +00:00
#endregion
namespace CodeImp.DoomBuilder.Editing
{
/// <summary>
/// Provides basic user input interface functionality for a Doom Builder editing mode.
/// </summary>
2008-01-02 21:49:43 +00:00
public abstract class EditMode
2007-06-15 18:30:55 +00:00
{
#region ================== Constants
2007-11-07 21:14:27 +00:00
public const int DRAG_START_MOVE_PIXELS = 5;
2007-06-15 18:30:55 +00:00
#endregion
#region ================== Variables
2007-06-15 22:38:42 +00:00
// Attributes
private EditModeAttribute attributes;
2007-06-15 18:30:55 +00:00
// Disposing
protected bool isdisposed = false;
#endregion
#region ================== Properties
public bool IsDisposed { get { return isdisposed; } }
public EditModeAttribute Attributes { get { return attributes; } }
2008-01-02 21:49:43 +00:00
// Unless overriden, this returns the name of this mode
// for checking the appropriate button on the toolbar.
public virtual string EditModeButtonName { get { return GetType().Name; } }
2007-06-15 18:30:55 +00:00
#endregion
#region ================== Constructor / Disposer
/// <summary>
/// Provides basic user input interface functionality for a Doom Builder editing mode.
/// </summary>
2007-06-15 18:30:55 +00:00
public EditMode()
{
// Fetch attributes
object[] attrs = this.GetType().GetCustomAttributes(true);
foreach(object a in attrs)
{
if(a is EditModeAttribute)
{
attributes = (EditModeAttribute)a;
break;
}
}
// No attributes found?
if(attributes == null) throw new Exception("Editing mode \"" + this.GetType().Name + "\" is missing EditMode attributes!");
2007-06-15 18:30:55 +00:00
// We have no destructor
GC.SuppressFinalize(this);
}
2008-01-02 21:49:43 +00:00
// Disposer
2007-06-15 18:30:55 +00:00
public virtual void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
// Done
isdisposed = true;
}
}
#endregion
2007-06-24 18:56:43 +00:00
#region ================== Static Methods
// This creates an instance of a specific mode
public static EditMode Create(Type modetype, object[] args)
{
try
{
// Create new mode
return (EditMode)General.ThisAssembly.CreateInstance(modetype.FullName, false,
BindingFlags.Default, null, args, CultureInfo.CurrentCulture, new object[0]);
}
// Catch errors
catch(TargetInvocationException e)
{
// Throw the actual exception
Debug.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
Debug.WriteLine(e.InnerException.Source + " throws " + e.InnerException.GetType().Name + ":");
Debug.WriteLine(e.InnerException.Message);
Debug.WriteLine(e.InnerException.StackTrace);
throw e.InnerException;
}
}
#endregion
#region ================== Events
2007-06-15 18:30:55 +00:00
2007-11-10 01:58:08 +00:00
//
// Order in which events occur for the old and new modes:
//
// - Constructor of new mode is called
// - Disengage of old mode is called
// ----- Mode switches -----
// - Engage of new mode is called
// - Dispose of old mode is called
//
2007-10-20 19:50:03 +00:00
// Mode engages
public virtual void OnEngage()
2007-10-20 19:50:03 +00:00
{
// Bind any methods
General.Actions.BindMethods(this);
2007-10-20 19:50:03 +00:00
}
// Mode disengages
public virtual void OnDisengage()
2007-10-20 19:50:03 +00:00
{
// Unbind any methods
General.Actions.UnbindMethods(this);
2007-10-20 19:50:03 +00:00
}
2009-04-05 19:29:27 +00:00
// Called when the user presses F1 for Help
public virtual void OnHelp() { }
2007-11-07 21:14:27 +00:00
// This forces the mode to cancel and return to the "parent" mode
public virtual void OnCancel() { }
public virtual void OnAccept() { }
// Called before copying. Return false when copying should be cancelled.
// The edit mode should mark all vertices, lines and sectors
// that need to be copied.
public virtual bool OnCopyBegin() { return false; }
// Called when the marked geometry has been copied.
public virtual void OnCopyEnd() { }
// Called before pasting. Return false when paste should be cancelled.
public virtual bool OnPasteBegin() { return true; }
// Called after new geometry has been pasted in. The new geometry is marked.
public virtual void OnPasteEnd() { }
// Called when undo/redo is used
// Return false to cancel undo action
public virtual bool OnUndoBegin() { return true; }
public virtual bool OnRedoBegin() { return true; }
public virtual void OnUndoEnd() { }
public virtual void OnRedoEnd() { }
2007-11-07 21:14:27 +00:00
// Interface events
public virtual void OnMouseClick(MouseEventArgs e) { }
public virtual void OnMouseDoubleClick(MouseEventArgs e) { }
public virtual void OnMouseDown(MouseEventArgs e) { }
public virtual void OnMouseEnter(EventArgs e) { }
public virtual void OnMouseLeave(EventArgs e) { }
public virtual void OnMouseMove(MouseEventArgs e) { }
public virtual void OnMouseUp(MouseEventArgs e) { }
public virtual void OnKeyDown(KeyEventArgs e) { }
public virtual void OnKeyUp(KeyEventArgs e) { }
public virtual void OnMouseInput(Vector2D delta) { }
// Rendering events
public virtual void OnRedrawDisplay() { }
public virtual void OnPresentDisplay() { }
2008-04-13 11:51:09 +00:00
// Processing events
public virtual void OnProcess(double deltatime) { }
2007-06-15 18:30:55 +00:00
2008-12-10 22:58:58 +00:00
// Generic events
public virtual void OnReloadResources() { }
2008-12-24 18:27:13 +00:00
public virtual void OnMapSetChangeBegin() { }
public virtual void OnMapSetChangeEnd() { }
2008-12-10 22:58:58 +00:00
2007-06-15 18:30:55 +00:00
#endregion
}
}