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
|
@ -112,10 +112,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
|
|||
#region ================== Events
|
||||
|
||||
// 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
|
||||
menusform.ShowEditingModeMenu(newmode);
|
||||
|
||||
return base.OnModeChange(oldmode, newmode);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -65,7 +65,6 @@ namespace CodeImp.DoomBuilder
|
|||
private string filetitle;
|
||||
private string filepathname;
|
||||
private string temppath;
|
||||
private bool cancelmodechange;
|
||||
|
||||
// Main objects
|
||||
private MapSet map;
|
||||
|
@ -98,7 +97,6 @@ namespace CodeImp.DoomBuilder
|
|||
public string FilePathName { get { return filepathname; } }
|
||||
public string FileTitle { get { return filetitle; } }
|
||||
public string TempPath { get { return temppath; } }
|
||||
public bool CancelModeChange { get { return cancelmodechange; } set { cancelmodechange |= value; } }
|
||||
internal MapOptions Options { get { return options; } }
|
||||
public MapSet Map { get { return map; } }
|
||||
public EditMode Mode { get { return mode; } }
|
||||
|
@ -865,10 +863,10 @@ namespace CodeImp.DoomBuilder
|
|||
// - Engage of new 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;
|
||||
cancelmodechange = false;
|
||||
|
||||
// Log info
|
||||
if(newmode != null)
|
||||
|
@ -889,26 +887,12 @@ namespace CodeImp.DoomBuilder
|
|||
prevstablemode = null;
|
||||
}
|
||||
|
||||
// Let the plugins know beforehand
|
||||
General.Plugins.ModeChanges(oldmode, newmode);
|
||||
|
||||
// Change cancelled?
|
||||
if(cancelmodechange)
|
||||
// Let the plugins know beforehand and check if not cancelled
|
||||
if(General.Plugins.ModeChanges(oldmode, newmode))
|
||||
{
|
||||
General.WriteLogLine("Edit mode change cancelled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Disenagage old mode
|
||||
if(oldmode != null) oldmode.OnDisengage();
|
||||
|
||||
// Change cancelled?
|
||||
if(cancelmodechange)
|
||||
{
|
||||
General.WriteLogLine("Edit mode change cancelled.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset cursor
|
||||
General.Interface.SetCursor(Cursors.Default);
|
||||
|
||||
|
@ -939,6 +923,14 @@ namespace CodeImp.DoomBuilder
|
|||
|
||||
// Redraw the display
|
||||
General.MainWindow.RedrawDisplay();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cancelled
|
||||
General.WriteLogLine("Edit mode change cancelled.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// This changes mode by class name and optionally with arguments
|
||||
|
|
|
@ -115,11 +115,13 @@ namespace CodeImp.DoomBuilder.Plugins
|
|||
|
||||
/// <summary>
|
||||
/// This is called by the Doom Builder core when the editing mode changes.
|
||||
/// Return false to abort the mode change.
|
||||
/// </summary>
|
||||
/// <param name="oldmode">The previous 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>
|
||||
|
|
|
@ -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