2009-04-19 18:07:22 +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 ;
2015-11-03 08:54:56 +00:00
using System.Collections.Generic ;
2009-04-19 18:07:22 +00:00
using System.Globalization ;
using System.Windows.Forms ;
using System.Reflection ;
using System.Diagnostics ;
2014-02-18 14:04:14 +00:00
using CodeImp.DoomBuilder.Actions ;
2009-04-19 18:07:22 +00:00
using CodeImp.DoomBuilder.Geometry ;
2009-07-09 14:03:47 +00:00
using CodeImp.DoomBuilder.Config ;
2015-09-04 12:44:09 +00:00
using CodeImp.DoomBuilder.Windows ;
2009-04-19 18:07:22 +00:00
#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
2014-01-23 13:36:51 +00:00
protected bool isdisposed ;
2014-01-08 09:46:57 +00:00
2009-04-19 18:07:22 +00:00
#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 ; } }
2009-05-17 14:00:36 +00:00
// Override this to provide a highlighted object, if applicable
public virtual object HighlightedObject { get { return null ; } }
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
/// <summary>
/// Provides basic user input interface functionality for a Doom Builder editing mode.
/// </summary>
2015-05-27 12:38:03 +00:00
protected EditMode ( )
2009-04-19 18:07:22 +00:00
{
// Fetch attributes
object [ ] attrs = this . GetType ( ) . GetCustomAttributes ( true ) ;
foreach ( object a in attrs )
{
2016-02-01 22:04:00 +00:00
EditModeAttribute attribute = a as EditModeAttribute ;
if ( attribute ! = null )
2009-04-19 18:07:22 +00:00
{
2016-02-01 22:04:00 +00:00
attributes = attribute ;
2009-04-19 18:07:22 +00:00
break ;
}
}
// No attributes found?
if ( attributes = = null ) throw new Exception ( "Editing mode \"" + this . GetType ( ) . Name + "\" is missing EditMode attributes!" ) ;
// 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
2015-09-04 12:44:09 +00:00
#region = = = = = = = = = = = = = = = = = = Methods
//mxd
public virtual void UpdateSelectionInfo ( )
{
2015-11-03 08:54:56 +00:00
// Collect info
List < string > info = new List < string > ( ) ;
if ( General . Map . Map . SelectedSectorsCount > 0 )
info . Add ( General . Map . Map . SelectedSectorsCount + ( General . Map . Map . SelectedSectorsCount = = 1 ? " sector" : " sectors" ) ) ;
if ( General . Map . Map . SelectedLinedefsCount > 0 )
info . Add ( General . Map . Map . SelectedLinedefsCount + ( General . Map . Map . SelectedLinedefsCount = = 1 ? " linedef" : " linedefs" ) ) ;
if ( General . Map . Map . SelectedVerticessCount > 0 )
info . Add ( General . Map . Map . SelectedVerticessCount + ( General . Map . Map . SelectedVerticessCount = = 1 ? " vertex" : " vertices" ) ) ;
if ( General . Map . Map . SelectedThingsCount > 0 )
info . Add ( General . Map . Map . SelectedThingsCount + ( General . Map . Map . SelectedThingsCount = = 1 ? " thing" : " things" ) ) ;
// Display results
string result = string . Empty ;
if ( info . Count > 0 )
{
result = string . Join ( ", " , info . ToArray ( ) ) ;
int pos = result . LastIndexOf ( "," , StringComparison . Ordinal ) ;
if ( pos ! = - 1 ) result = result . Remove ( pos , 1 ) . Insert ( pos , " and" ) ;
result + = " selected." ;
}
General . Interface . DisplayStatus ( StatusType . Selection , result ) ;
2015-09-04 12:44:09 +00:00
}
#endregion
2009-04-19 18:07:22 +00:00
#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 ) ;
2014-01-08 09:46:57 +00:00
//mxd. Show hints for this mode
2014-02-18 14:04:14 +00:00
General . Hints . ShowHints ( this . GetType ( ) , HintsManager . GENERAL ) ;
2014-12-10 21:11:56 +00:00
//mxd. Display new mode name
General . Interface . HideInfo ( ) ;
2009-04-19 18:07:22 +00:00
}
// 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 ( ) { }
2009-07-10 08:25:04 +00:00
// Called before pasting. Override this and return true to indicate that paste is allowed to contiue.
public virtual bool OnPasteBegin ( PasteOptions options ) { return false ; }
2009-04-19 18:07:22 +00:00
// Called after new geometry has been pasted in. The new geometry is marked.
2009-07-09 14:03:47 +00:00
public virtual void OnPasteEnd ( PasteOptions options ) { }
2009-04-19 18:07:22 +00:00
// Called when undo/redo is used
// Return false to cancel undo action
public virtual bool OnUndoBegin ( ) { return true ; }
public virtual bool OnRedoBegin ( ) { return true ; }
2015-11-08 20:20:46 +00:00
public virtual void OnUndoEnd ( ) { General . Map . Renderer2D . UpdateExtraFloorFlag ( ) ; } //mxd
public virtual void OnRedoEnd ( ) { General . Map . Renderer2D . UpdateExtraFloorFlag ( ) ; } //mxd
2009-04-19 18:07:22 +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 ( ) { }
// Processing events
2016-03-14 00:01:21 +00:00
public virtual void OnProcess ( long deltatime ) { }
2009-04-19 18:07:22 +00:00
// Generic events
public virtual void OnReloadResources ( ) { }
public virtual void OnMapSetChangeBegin ( ) { }
public virtual void OnMapSetChangeEnd ( ) { }
2012-06-07 01:06:37 +00:00
2013-09-11 09:47:53 +00:00
//mxd. map testing events
2014-03-23 09:08:51 +00:00
public virtual bool OnMapTestBegin ( bool testFromCurrentPosition ) { return true ; } //called before test map is launched. Returns false if map launch is impossible
public virtual void OnMapTestEnd ( bool testFromCurrentPosition ) { } //called after game engine is closed
2009-04-19 18:07:22 +00:00
#endregion
}
}