From fa5c741b763a0243c3cf95b476f91d7e5901136c Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Tue, 20 Sep 2022 23:52:41 +0200 Subject: [PATCH] Fixed a regression where editing map elements did not preserve the selection order, but used the index order instead. Fixes #791 --- .../ClassicModes/DragLinedefsMode.cs | 2 +- .../ClassicModes/DragSectorsMode.cs | 2 +- .../ClassicModes/DragThingsMode.cs | 2 +- .../ClassicModes/DragVerticesMode.cs | 2 +- .../BuilderModes/ClassicModes/LinedefsMode.cs | 23 ++++++++-------- .../BuilderModes/ClassicModes/SectorsMode.cs | 25 +++++++++-------- .../BuilderModes/ClassicModes/ThingsMode.cs | 27 +++++++++---------- .../BuilderModes/ClassicModes/VerticesMode.cs | 20 +++++++------- 8 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs index 56d972bf..56d4ee24 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DragLinedefsMode.cs @@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Disposer // Constructor to start dragging immediately - public DragLinedefsMode(Vector2D dragstartmappos, List lines) + public DragLinedefsMode(Vector2D dragstartmappos, ICollection lines) { // Mark what we are dragging General.Map.Map.ClearAllMarks(false); diff --git a/Source/Plugins/BuilderModes/ClassicModes/DragSectorsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DragSectorsMode.cs index 73b90d78..67e3126b 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/DragSectorsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DragSectorsMode.cs @@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Disposer // Constructor to start dragging immediately - public DragSectorsMode(Vector2D dragstartmappos, List sectors) + public DragSectorsMode(Vector2D dragstartmappos, ICollection sectors) { // Mark what we are dragging General.Map.Map.ClearAllMarks(false); diff --git a/Source/Plugins/BuilderModes/ClassicModes/DragThingsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DragThingsMode.cs index 25cc237c..6d160141 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/DragThingsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DragThingsMode.cs @@ -114,7 +114,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Disposer // Constructor to start dragging immediately - public DragThingsMode(EditMode basemode, Vector2D dragstartmappos, List things, bool makeundo) + public DragThingsMode(EditMode basemode, Vector2D dragstartmappos, ICollection things, bool makeundo) { // Initialize this.dragstartmappos = dragstartmappos; diff --git a/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs index 422650a5..a550f1ac 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DragVerticesMode.cs @@ -59,7 +59,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Disposer // Constructor to start dragging immediately - public DragVerticesMode(Vector2D dragstartmappos, List vertices) + public DragVerticesMode(Vector2D dragstartmappos, ICollection vertices) { // Mark what we are dragging General.Map.Map.ClearAllMarks(false); diff --git a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs index 14bbba56..744f9af9 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs @@ -71,6 +71,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Stores sizes of the text for text labels so that they only have to be computed once private Dictionary textlabelsizecache; + // Linedefs that will be edited + ICollection editlines; + #endregion #region ================== Properties @@ -777,21 +780,20 @@ namespace CodeImp.DoomBuilder.BuilderModes // Edit pressed in this mode editpressed = true; - // We use the marks to determine what to edit/drag, so clear it first - General.Map.Map.ClearMarkedLinedefs(false); - // Highlighted item not selected? if(!highlighted.Selected) { // Make this the only selection General.Map.Map.ClearSelectedLinedefs(); - highlighted.Marked = true; + + editlines = new List { highlighted }; + UpdateSelectionInfo(); //mxd General.Interface.RedrawDisplay(); } else { - General.Map.Map.MarkSelectedLinedefs(true, true); + editlines = General.Map.Map.GetSelectedLinedefs(true); } // Update display @@ -828,10 +830,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Edit pressed in this mode? if(editpressed) { - // Anything selected? - ICollection editlines = General.Map.Map.GetMarkedLinedefs(true); - - if(editlines.Count > 0) + if(editlines?.Count > 0) { if(General.Interface.IsActiveWindow) { @@ -1063,19 +1062,19 @@ namespace CodeImp.DoomBuilder.BuilderModes // Anything highlighted? if((highlighted != null) && !highlighted.IsDisposed) { - List draglines = new List(); + ICollection draglines; // Highlighted item not selected? if(!highlighted.Selected) { // Select only this linedef for dragging General.Map.Map.ClearSelectedLinedefs(); - draglines.Add(highlighted); + draglines = new List { highlighted }; } else { // Add all selected linedefs to the linedefs we want to drag - draglines.AddRange(General.Map.Map.GetSelectedLinedefs(true)); + draglines = General.Map.Map.GetSelectedLinedefs(true); } // Start dragging the selection diff --git a/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs index c47ff7a9..2d063fd6 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs @@ -83,6 +83,9 @@ namespace CodeImp.DoomBuilder.BuilderModes private ConcurrentDictionary determinedsectorthings; + // Sectors that will be edited + private ICollection editsectors; + #endregion #region ================== Properties @@ -1056,24 +1059,23 @@ namespace CodeImp.DoomBuilder.BuilderModes // Edit pressed in this mode editpressed = true; - // We use the marks to determine what to edit/drag, so clear it first - General.Map.Map.ClearMarkedSectors(false); - // Highlighted item not selected? if (!highlighted.Selected) { // Make this the only selection General.Map.Map.ClearSelectedSectors(); General.Map.Map.ClearSelectedLinedefs(); - highlighted.Marked = true; + + editsectors = new List { highlighted }; + UpdateSelectedLabels(); //mxd UpdateOverlaySurfaces(); //mxd UpdateSelectionInfo(); //mxd General.Interface.RedrawDisplay(); } - else + else // Highlight is selected, so take all selected sectors { - General.Map.Map.MarkSelectedSectors(true, true); + editsectors = General.Map.Map.GetSelectedSectors(true); } // Update display @@ -1108,10 +1110,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Edit pressed in this mode? if(editpressed) { - // Anything selected? - ICollection editsectors = General.Map.Map.GetMarkedSectors(true); - - if(editsectors.Count > 0) + if(editsectors?.Count > 0) { if(General.Interface.IsActiveWindow) { @@ -1315,19 +1314,19 @@ namespace CodeImp.DoomBuilder.BuilderModes // Anything highlighted? if((highlighted != null) && !highlighted.IsDisposed) { - List dragsectors = new List(); + ICollection dragsectors; // Highlighted item not selected? if (!highlighted.Selected) { // Select only this sector for dragging General.Map.Map.ClearSelectedSectors(); - dragsectors.Add(highlighted); + dragsectors = new List { highlighted }; UpdateOverlaySurfaces(); //mxd } else { - dragsectors.AddRange(General.Map.Map.GetSelectedSectors(true)); + dragsectors = General.Map.Map.GetSelectedSectors(true); } // Start dragging the selection diff --git a/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs index bad36e87..cbd92183 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs @@ -76,6 +76,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Stores sizes of the text for text labels so that they only have to be computed once private Dictionary textlabelsizecache; + // Things that will be edited + private ICollection editthings; + #endregion #region ================== Properties @@ -483,22 +486,21 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Edit pressed in this mode editpressed = true; - - // We use the marks to determine what do edit/drag, so clear it first - General.Map.Map.ClearMarkedThings(false); // Highlighted item not selected? if(!highlighted.Selected) { // Make this the only selection General.Map.Map.ClearSelectedThings(); - highlighted.Marked = true; + + editthings = new List { highlighted }; + UpdateSelectionInfo(); //mxd General.Interface.RedrawDisplay(); } else { - General.Map.Map.MarkSelectedThings(true, true); + editthings = General.Map.Map.GetSelectedThings(true); } // Update display @@ -528,7 +530,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { General.Map.Map.ClearSelectedThings(); General.Map.Map.ClearMarkedThings(false); - t.Marked = true; + editthings = new List { t }; Highlight(t); General.Interface.RedrawDisplay(); } @@ -543,10 +545,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Edit pressed in this mode? if(editpressed) { - // Anything selected? - ICollection editthings = General.Map.Map.GetMarkedThings(true); - - if(editthings.Count > 0) + if(editthings?.Count > 0) { if(General.Interface.IsActiveWindow) { @@ -743,19 +742,19 @@ namespace CodeImp.DoomBuilder.BuilderModes // Anything highlighted? if((highlighted != null) && !highlighted.IsDisposed) { - List dragthings = new List(); + ICollection dragthings; // Highlighted item not selected? if(!highlighted.Selected) { // Select only this thing for dragging General.Map.Map.ClearSelectedThings(); - dragthings.Add(highlighted); + dragthings = new List { highlighted }; } else { // Add all selected things to the things we want to drag - dragthings.AddRange(General.Map.Map.GetSelectedThings(true)); + dragthings = General.Map.Map.GetSelectedThings(true); } // Start dragging the selection @@ -765,7 +764,7 @@ namespace CodeImp.DoomBuilder.BuilderModes bool thingscloned = false; if(General.Interface.ShiftState) { - List clonedthings = new List(dragthings.Count); + ICollection clonedthings = new List(dragthings.Count); if(dragthings.Count > 0) { // Make undo diff --git a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs index d206cd46..a17bdd20 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs @@ -59,6 +59,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // The blockmap makes is used to make finding lines faster BlockMap blockmap; + // Vertices that will be edited + ICollection editvertices; + #endregion #region ================== Properties @@ -294,13 +297,15 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Make this the only selection General.Map.Map.ClearSelectedVertices(); - highlighted.Marked = true; + + editvertices = new List { highlighted }; + UpdateSelectionInfo(); //mxd General.Interface.RedrawDisplay(); } else { - General.Map.Map.MarkSelectedVertices(true, true); + editvertices = General.Map.Map.GetSelectedVertices(true); } // Update display @@ -400,10 +405,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Edit pressed in this mode? if(editpressed) { - // Anything selected? - ICollection editvertices = General.Map.Map.GetMarkedVertices(true); - - if(editvertices.Count > 0) + if(editvertices?.Count > 0) { if(General.Interface.IsActiveWindow) { @@ -635,19 +637,19 @@ namespace CodeImp.DoomBuilder.BuilderModes // Anything highlighted? if((highlighted != null) && !highlighted.IsDisposed) { - List dragvertices = new List(); + ICollection dragvertices; // Highlighted item not selected? if(!highlighted.Selected) { // Select only this vertex for dragging General.Map.Map.ClearSelectedVertices(); - dragvertices.Add(highlighted); + dragvertices = new List { highlighted }; } else { // Add all selected vertices to the vertices we want to drag - dragvertices.AddRange(General.Map.Map.GetSelectedVertices(true)); + dragvertices = General.Map.Map.GetSelectedVertices(true); } // Start dragging the selection