mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-23 20:32:34 +00:00
013865e27d
Reverted "Delete Item" action to the way it worked in DB2. Added "Dissolve Item" action, which works the way "Delete Item" worked in previous revisions of GZDB. Added "Auto Clear Sidedef Textures" action, "Edit" menu and toolbar button, which toggle automatic removal of sidedef textures when floor or ceiling height is changed or when geometry is drawn, copied or pasted. Draw Settings panel: upper/lower texture overrides can now be used. Draw Settings panel: added 2 sets of buttons, which allow to quickly set or clear textures in current selection. Things are now rendered behind AND on top of the grid/linedefs/vertices when they are dragged. Redesigned hints system. They are now shown in a side panel. Edit area auto-focusing is now disabled when script editor is open. Texture Browser form: no texture group was selected when opening the form in some cases. Fixed several strange/misleading text messages.
245 lines
7 KiB
C#
245 lines
7 KiB
C#
|
|
#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.Globalization;
|
|
using System.Windows.Forms;
|
|
using System.Reflection;
|
|
using System.Diagnostics;
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
#endregion
|
|
|
|
namespace CodeImp.DoomBuilder.Editing
|
|
{
|
|
/// <summary>
|
|
/// Provides basic user input interface functionality for a Doom Builder editing mode.
|
|
/// </summary>
|
|
public abstract class EditMode
|
|
{
|
|
#region ================== Constants
|
|
|
|
public const int DRAG_START_MOVE_PIXELS = 5;
|
|
|
|
#endregion
|
|
|
|
#region ================== Variables
|
|
|
|
// Attributes
|
|
private EditModeAttribute attributes;
|
|
|
|
// Disposing
|
|
protected bool isdisposed = false;
|
|
|
|
//mxd. Hints
|
|
protected string[] hints;
|
|
protected string[] multiselectionHints;
|
|
|
|
#endregion
|
|
|
|
#region ================== Properties
|
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
|
|
|
public EditModeAttribute Attributes { get { return attributes; } }
|
|
|
|
// 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; } }
|
|
|
|
// Override this to provide a highlighted object, if applicable
|
|
public virtual object HighlightedObject { get { return null; } }
|
|
|
|
#endregion
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
/// <summary>
|
|
/// Provides basic user input interface functionality for a Doom Builder editing mode.
|
|
/// </summary>
|
|
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!");
|
|
|
|
SetupHints(); //mxd
|
|
SetupMultiselectionHints(); //mxd
|
|
|
|
// We have no destructor
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
// Disposer
|
|
public virtual void Dispose()
|
|
{
|
|
// Not already disposed?
|
|
if(!isdisposed)
|
|
{
|
|
// Clean up
|
|
|
|
// Done
|
|
isdisposed = true;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#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 ================== Methods (mxd)
|
|
|
|
|
|
/// <summary>
|
|
/// Override this to setup hints for this editing mode
|
|
/// </summary>
|
|
protected virtual void SetupHints() { //mxd
|
|
hints = new[] { "Press F1 to view help about current editing mode" };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Override this to setup hints shown while multiselecting for this editing mode
|
|
/// </summary>
|
|
protected virtual void SetupMultiselectionHints() { //mxd
|
|
multiselectionHints = new[] { "Press F1 to view help about current editing mode" };
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ================== Events
|
|
|
|
//
|
|
// 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
|
|
//
|
|
|
|
// Mode engages
|
|
public virtual void OnEngage()
|
|
{
|
|
// Bind any methods
|
|
General.Actions.BindMethods(this);
|
|
|
|
//mxd. Show hints for this mode
|
|
General.Interface.ShowEditModeHints(hints);
|
|
}
|
|
|
|
// Mode disengages
|
|
public virtual void OnDisengage()
|
|
{
|
|
// Unbind any methods
|
|
General.Actions.UnbindMethods(this);
|
|
}
|
|
|
|
// Called when the user presses F1 for Help
|
|
public virtual void OnHelp() { }
|
|
|
|
// 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. Override this and return true to indicate that paste is allowed to contiue.
|
|
public virtual bool OnPasteBegin(PasteOptions options) { return false; }
|
|
|
|
// Called after new geometry has been pasted in. The new geometry is marked.
|
|
public virtual void OnPasteEnd(PasteOptions options) { }
|
|
|
|
// 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() { }
|
|
|
|
// 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() { }
|
|
|
|
// Processing events
|
|
public virtual void OnProcess(float deltatime) { }
|
|
|
|
// Generic events
|
|
public virtual void OnReloadResources() { }
|
|
public virtual void OnMapSetChangeBegin() { }
|
|
public virtual void OnMapSetChangeEnd() { }
|
|
|
|
//mxd. map testing events
|
|
public virtual bool OnMapTestBegin() { return true; } //called before test map is launched. Returns false if map launch is impossible
|
|
public virtual void OnMapTestEnd() { } //called after game engine is closed
|
|
|
|
#endregion
|
|
}
|
|
}
|