Merged master into duplicate-3d-floors branch

Added some error handling to duplicating 3D floors
This commit is contained in:
biwa 2020-06-13 17:00:12 +02:00
commit 57b184a9e6
5 changed files with 153 additions and 118 deletions

View file

@ -605,10 +605,13 @@ namespace CodeImp.DoomBuilder.Editing
// Call UndoBegin event
if(General.Editing.Mode.OnUndoBegin())
{
// Cancel volatile mode, if any
// This returns false when mode was not volatile
if(!General.Editing.CancelVolatileMode())
{
// biwa. Previously being in a volatile mode simply switch back the the previous
// stable mode without actually performing the undo. This causes problems when the
// volatile mode create undo snapshots. EditSelectionMode does this, and removing
// it's undo snapshot only works because the mode's OnCancel is called twice.
// Maybe the logic of CancelVolatileMode is just wrong.
General.Editing.CancelVolatileMode();
geometrychanged = false;
populationchanged = false;
General.Map.Map.ClearAllMarks(false);
@ -722,7 +725,6 @@ namespace CodeImp.DoomBuilder.Editing
}
}
}
}
Cursor.Current = oldcursor;
}

View file

@ -30,6 +30,19 @@ using CodeImp.DoomBuilder.Map;
namespace CodeImp.DoomBuilder.ThreeDFloorMode
{
[Serializable]
public class NoSpaceInCSAException : Exception
{
public NoSpaceInCSAException()
{ }
public NoSpaceInCSAException(string message) : base(message)
{ }
public NoSpaceInCSAException(string message, Exception innerException) : base(message, innerException)
{ }
}
public class ControlSectorArea
{
@ -318,7 +331,7 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
}
}
throw new Exception("Not enough space for control sector relocation");
throw new NoSpaceInCSAException("Not enough space for control sector relocation");
}
public List<DrawnVertex> GetNewControlSectorVertices()
@ -354,7 +367,7 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
}
}
throw new Exception("No space left for control sectors");
throw new NoSpaceInCSAException("No space left for control sectors");
}
public bool Inside(float x, float y)

View file

@ -61,6 +61,8 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
{
#region ================== Constants
private const string duplicateundodescription = "Duplicate 3D floor control sectors before pasting";
#endregion
#region ================== Variables
@ -87,6 +89,7 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
ControlSectorArea.Highlight csahighlight = ControlSectorArea.Highlight.None;
bool dragging = false;
bool withdrawduplicateundo;
bool paintselectpressed;
@ -108,10 +111,19 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
{
threedfloors = BuilderPlug.GetThreeDFloors(General.Map.Map.Sectors.ToList());
if(General.Editing.Mode is EditSelectionMode && ((EditSelectionMode)General.Editing.Mode).Cancelled)
{
withdrawduplicateundo = false;
// If we're coming from EditSelectionMode, and that modes was cancelled check if the last undo was to create
// duplicated 3D floors. If that's the case we want to withdraw that undo, too. Don't do it here, though, as the other
// mode is still active, do it in OnEngage instead
if (General.Editing.Mode is EditSelectionMode &&
((EditSelectionMode)General.Editing.Mode).Cancelled &&
General.Map.UndoRedo.NextUndo != null &&
General.Map.UndoRedo.NextUndo.Description == duplicateundodescription)
{
withdrawduplicateundo = true;
}
}
// Disposer
@ -674,6 +686,10 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
UpdateLabels();
updateOverlaySurfaces();
UpdateOverlay();
// Withdraw the undo that was created when
if (withdrawduplicateundo)
General.Map.UndoRedo.WithdrawUndo();
}
void ViewSelectionNumbers_Click(object sender, EventArgs e)
@ -1516,9 +1532,12 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
tagblacklist.Add(tag);
if (duplicatethreedfloors.Count == 0)
{
General.Interface.DisplayStatus(StatusType.Warning, "Selected geometry doesn't contain 3D floors");
return;
}
General.Map.UndoRedo.CreateUndo("Duplicate 3D floor control sectors before pasting");
General.Map.UndoRedo.CreateUndo(duplicateundodescription);
// Create a new control sector for each 3D floor that needs to be duplicated. Force it to generate
// a new tag, and store the old (current) and new tag
@ -1527,13 +1546,14 @@ namespace CodeImp.DoomBuilder.ThreeDFloorMode
int newtag;
int oldtag = tdf.UDMFTag;
if(tdf.CreateGeometry(new List<int>(), true, out newtag))
try
{
tdf.CreateGeometry(new List<int>(), true, out newtag);
tagreplacements[oldtag] = newtag;
}
else
catch(NoSpaceInCSAException e)
{
General.Interface.DisplayStatus(StatusType.Warning, "Could not create 3D floor control sector geometry");
General.Interface.DisplayStatus(StatusType.Warning, string.Format("Could not create 3D floor control sector geometry: {0}", e.Message));
General.Map.UndoRedo.WithdrawUndo();
return;
}

View file

@ -360,12 +360,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
case GridLockMode.VERTICAL:
slicesH = horizontalslices;
slicesV = height / General.Map.Grid.GridSize;
slicesV = Math.Abs(height / General.Map.Grid.GridSize);
break;
case GridLockMode.BOTH:
slicesH = width / General.Map.Grid.GridSize;
slicesV = height / General.Map.Grid.GridSize;
slicesH = Math.Abs(width / General.Map.Grid.GridSize);
slicesV = Math.Abs(height / General.Map.Grid.GridSize);
break;
}

View file

@ -1444,7 +1444,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Cancel mode
public override void OnCancel()
{
// Make sure the following code is only run once
// Only allow the following code to be run once
if (cancelled)
return;