mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-27 06:02:11 +00:00
better way to cancel editing mode
This commit is contained in:
parent
0fd6efb82f
commit
ab28c9d66b
4 changed files with 49 additions and 51 deletions
|
@ -110,12 +110,14 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Events
|
#region ================== Events
|
||||||
|
|
||||||
// When the editing mode changes
|
// When the editing mode changes
|
||||||
public override void OnModeChange(EditMode oldmode, EditMode newmode)
|
public override bool OnModeChange(EditMode oldmode, EditMode newmode)
|
||||||
{
|
{
|
||||||
// Show the correct menu for the new mode
|
// Show the correct menu for the new mode
|
||||||
menusform.ShowEditingModeMenu(newmode);
|
menusform.ShowEditingModeMenu(newmode);
|
||||||
|
|
||||||
|
return base.OnModeChange(oldmode, newmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -65,7 +65,6 @@ namespace CodeImp.DoomBuilder
|
||||||
private string filetitle;
|
private string filetitle;
|
||||||
private string filepathname;
|
private string filepathname;
|
||||||
private string temppath;
|
private string temppath;
|
||||||
private bool cancelmodechange;
|
|
||||||
|
|
||||||
// Main objects
|
// Main objects
|
||||||
private MapSet map;
|
private MapSet map;
|
||||||
|
@ -98,7 +97,6 @@ namespace CodeImp.DoomBuilder
|
||||||
public string FilePathName { get { return filepathname; } }
|
public string FilePathName { get { return filepathname; } }
|
||||||
public string FileTitle { get { return filetitle; } }
|
public string FileTitle { get { return filetitle; } }
|
||||||
public string TempPath { get { return temppath; } }
|
public string TempPath { get { return temppath; } }
|
||||||
public bool CancelModeChange { get { return cancelmodechange; } set { cancelmodechange |= value; } }
|
|
||||||
internal MapOptions Options { get { return options; } }
|
internal MapOptions Options { get { return options; } }
|
||||||
public MapSet Map { get { return map; } }
|
public MapSet Map { get { return map; } }
|
||||||
public EditMode Mode { get { return mode; } }
|
public EditMode Mode { get { return mode; } }
|
||||||
|
@ -865,10 +863,10 @@ namespace CodeImp.DoomBuilder
|
||||||
// - Engage of new mode is called
|
// - Engage of new mode is called
|
||||||
// - Dispose of old mode is called
|
// - Dispose of old mode is called
|
||||||
//
|
//
|
||||||
public void ChangeMode(EditMode nextmode)
|
// Returns false when cancelled
|
||||||
|
public bool ChangeMode(EditMode nextmode)
|
||||||
{
|
{
|
||||||
EditMode oldmode = mode;
|
EditMode oldmode = mode;
|
||||||
cancelmodechange = false;
|
|
||||||
|
|
||||||
// Log info
|
// Log info
|
||||||
if(newmode != null)
|
if(newmode != null)
|
||||||
|
@ -889,56 +887,50 @@ namespace CodeImp.DoomBuilder
|
||||||
prevstablemode = null;
|
prevstablemode = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let the plugins know beforehand
|
// Let the plugins know beforehand and check if not cancelled
|
||||||
General.Plugins.ModeChanges(oldmode, newmode);
|
if(General.Plugins.ModeChanges(oldmode, newmode))
|
||||||
|
|
||||||
// Change cancelled?
|
|
||||||
if(cancelmodechange)
|
|
||||||
{
|
{
|
||||||
General.WriteLogLine("Edit mode change cancelled.");
|
// Disenagage old mode
|
||||||
return;
|
if(oldmode != null) oldmode.OnDisengage();
|
||||||
}
|
|
||||||
|
|
||||||
// Disenagage old mode
|
|
||||||
if(oldmode != null) oldmode.OnDisengage();
|
|
||||||
|
|
||||||
// Change cancelled?
|
// Reset cursor
|
||||||
if(cancelmodechange)
|
General.Interface.SetCursor(Cursors.Default);
|
||||||
{
|
|
||||||
General.WriteLogLine("Edit mode change cancelled.");
|
// Apply new mode
|
||||||
return;
|
mode = newmode;
|
||||||
}
|
|
||||||
|
// Engage new mode
|
||||||
|
if(newmode != null) newmode.OnEngage();
|
||||||
|
|
||||||
// Reset cursor
|
// Check appropriate button on interface
|
||||||
General.Interface.SetCursor(Cursors.Default);
|
// And show the mode name
|
||||||
|
if(mode != null)
|
||||||
// Apply new mode
|
{
|
||||||
mode = newmode;
|
General.MainWindow.CheckEditModeButton(mode.EditModeButtonName);
|
||||||
|
General.MainWindow.DisplayModeName(mode.Attributes.DisplayName);
|
||||||
// Engage new mode
|
}
|
||||||
if(newmode != null) newmode.OnEngage();
|
else
|
||||||
|
{
|
||||||
|
General.MainWindow.CheckEditModeButton("");
|
||||||
|
General.MainWindow.DisplayModeName("");
|
||||||
|
}
|
||||||
|
|
||||||
// Check appropriate button on interface
|
// Dispose old mode
|
||||||
// And show the mode name
|
if(oldmode != null) oldmode.Dispose();
|
||||||
if(mode != null)
|
|
||||||
{
|
// Done switching
|
||||||
General.MainWindow.CheckEditModeButton(mode.EditModeButtonName);
|
newmode = null;
|
||||||
General.MainWindow.DisplayModeName(mode.Attributes.DisplayName);
|
|
||||||
|
// Redraw the display
|
||||||
|
General.MainWindow.RedrawDisplay();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
General.MainWindow.CheckEditModeButton("");
|
// Cancelled
|
||||||
General.MainWindow.DisplayModeName("");
|
General.WriteLogLine("Edit mode change cancelled.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispose old mode
|
|
||||||
if(oldmode != null) oldmode.Dispose();
|
|
||||||
|
|
||||||
// Done switching
|
|
||||||
newmode = null;
|
|
||||||
|
|
||||||
// Redraw the display
|
|
||||||
General.MainWindow.RedrawDisplay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This changes mode by class name and optionally with arguments
|
// This changes mode by class name and optionally with arguments
|
||||||
|
|
|
@ -115,11 +115,13 @@ namespace CodeImp.DoomBuilder.Plugins
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called by the Doom Builder core when the editing mode changes.
|
/// This is called by the Doom Builder core when the editing mode changes.
|
||||||
|
/// Return false to abort the mode change.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="oldmode">The previous editing mode</param>
|
/// <param name="oldmode">The previous editing mode</param>
|
||||||
/// <param name="newmode">The new editing mode</param>
|
/// <param name="newmode">The new editing mode</param>
|
||||||
public virtual void OnModeChange(EditMode oldmode, EditMode newmode)
|
public virtual bool OnModeChange(EditMode oldmode, EditMode newmode)
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -208,9 +208,11 @@ namespace CodeImp.DoomBuilder.Plugins
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ModeChanges(EditMode oldmode, EditMode newmode)
|
public bool ModeChanges(EditMode oldmode, EditMode newmode)
|
||||||
{
|
{
|
||||||
foreach(Plugin p in plugins) p.Plug.OnModeChange(oldmode, newmode);
|
bool result = true;
|
||||||
|
foreach(Plugin p in plugins) result &= p.Plug.OnModeChange(oldmode, newmode);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue