Fixed a regression where editing map elements did not preserve the selection order, but used the index order instead. Fixes #791

This commit is contained in:
biwa 2022-09-20 23:52:41 +02:00
parent e7ccffa498
commit fa5c741b76
8 changed files with 51 additions and 52 deletions

View file

@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Constructor / Disposer #region ================== Constructor / Disposer
// Constructor to start dragging immediately // Constructor to start dragging immediately
public DragLinedefsMode(Vector2D dragstartmappos, List<Linedef> lines) public DragLinedefsMode(Vector2D dragstartmappos, ICollection<Linedef> lines)
{ {
// Mark what we are dragging // Mark what we are dragging
General.Map.Map.ClearAllMarks(false); General.Map.Map.ClearAllMarks(false);

View file

@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Constructor / Disposer #region ================== Constructor / Disposer
// Constructor to start dragging immediately // Constructor to start dragging immediately
public DragSectorsMode(Vector2D dragstartmappos, List<Sector> sectors) public DragSectorsMode(Vector2D dragstartmappos, ICollection<Sector> sectors)
{ {
// Mark what we are dragging // Mark what we are dragging
General.Map.Map.ClearAllMarks(false); General.Map.Map.ClearAllMarks(false);

View file

@ -114,7 +114,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Constructor / Disposer #region ================== Constructor / Disposer
// Constructor to start dragging immediately // Constructor to start dragging immediately
public DragThingsMode(EditMode basemode, Vector2D dragstartmappos, List<Thing> things, bool makeundo) public DragThingsMode(EditMode basemode, Vector2D dragstartmappos, ICollection<Thing> things, bool makeundo)
{ {
// Initialize // Initialize
this.dragstartmappos = dragstartmappos; this.dragstartmappos = dragstartmappos;

View file

@ -59,7 +59,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Constructor / Disposer #region ================== Constructor / Disposer
// Constructor to start dragging immediately // Constructor to start dragging immediately
public DragVerticesMode(Vector2D dragstartmappos, List<Vertex> vertices) public DragVerticesMode(Vector2D dragstartmappos, ICollection<Vertex> vertices)
{ {
// Mark what we are dragging // Mark what we are dragging
General.Map.Map.ClearAllMarks(false); General.Map.Map.ClearAllMarks(false);

View file

@ -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 // Stores sizes of the text for text labels so that they only have to be computed once
private Dictionary<string, float> textlabelsizecache; private Dictionary<string, float> textlabelsizecache;
// Linedefs that will be edited
ICollection<Linedef> editlines;
#endregion #endregion
#region ================== Properties #region ================== Properties
@ -777,21 +780,20 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Edit pressed in this mode // Edit pressed in this mode
editpressed = true; 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? // Highlighted item not selected?
if(!highlighted.Selected) if(!highlighted.Selected)
{ {
// Make this the only selection // Make this the only selection
General.Map.Map.ClearSelectedLinedefs(); General.Map.Map.ClearSelectedLinedefs();
highlighted.Marked = true;
editlines = new List<Linedef> { highlighted };
UpdateSelectionInfo(); //mxd UpdateSelectionInfo(); //mxd
General.Interface.RedrawDisplay(); General.Interface.RedrawDisplay();
} }
else else
{ {
General.Map.Map.MarkSelectedLinedefs(true, true); editlines = General.Map.Map.GetSelectedLinedefs(true);
} }
// Update display // Update display
@ -828,10 +830,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Edit pressed in this mode? // Edit pressed in this mode?
if(editpressed) if(editpressed)
{ {
// Anything selected? if(editlines?.Count > 0)
ICollection<Linedef> editlines = General.Map.Map.GetMarkedLinedefs(true);
if(editlines.Count > 0)
{ {
if(General.Interface.IsActiveWindow) if(General.Interface.IsActiveWindow)
{ {
@ -1063,19 +1062,19 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Anything highlighted? // Anything highlighted?
if((highlighted != null) && !highlighted.IsDisposed) if((highlighted != null) && !highlighted.IsDisposed)
{ {
List<Linedef> draglines = new List<Linedef>(); ICollection<Linedef> draglines;
// Highlighted item not selected? // Highlighted item not selected?
if(!highlighted.Selected) if(!highlighted.Selected)
{ {
// Select only this linedef for dragging // Select only this linedef for dragging
General.Map.Map.ClearSelectedLinedefs(); General.Map.Map.ClearSelectedLinedefs();
draglines.Add(highlighted); draglines = new List<Linedef> { highlighted };
} }
else else
{ {
// Add all selected linedefs to the linedefs we want to drag // 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 // Start dragging the selection

View file

@ -83,6 +83,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
private ConcurrentDictionary<Thing, bool> determinedsectorthings; private ConcurrentDictionary<Thing, bool> determinedsectorthings;
// Sectors that will be edited
private ICollection<Sector> editsectors;
#endregion #endregion
#region ================== Properties #region ================== Properties
@ -1056,24 +1059,23 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Edit pressed in this mode // Edit pressed in this mode
editpressed = true; 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? // Highlighted item not selected?
if (!highlighted.Selected) if (!highlighted.Selected)
{ {
// Make this the only selection // Make this the only selection
General.Map.Map.ClearSelectedSectors(); General.Map.Map.ClearSelectedSectors();
General.Map.Map.ClearSelectedLinedefs(); General.Map.Map.ClearSelectedLinedefs();
highlighted.Marked = true;
editsectors = new List<Sector> { highlighted };
UpdateSelectedLabels(); //mxd UpdateSelectedLabels(); //mxd
UpdateOverlaySurfaces(); //mxd UpdateOverlaySurfaces(); //mxd
UpdateSelectionInfo(); //mxd UpdateSelectionInfo(); //mxd
General.Interface.RedrawDisplay(); 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 // Update display
@ -1108,10 +1110,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Edit pressed in this mode? // Edit pressed in this mode?
if(editpressed) if(editpressed)
{ {
// Anything selected? if(editsectors?.Count > 0)
ICollection<Sector> editsectors = General.Map.Map.GetMarkedSectors(true);
if(editsectors.Count > 0)
{ {
if(General.Interface.IsActiveWindow) if(General.Interface.IsActiveWindow)
{ {
@ -1315,19 +1314,19 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Anything highlighted? // Anything highlighted?
if((highlighted != null) && !highlighted.IsDisposed) if((highlighted != null) && !highlighted.IsDisposed)
{ {
List<Sector> dragsectors = new List<Sector>(); ICollection<Sector> dragsectors;
// Highlighted item not selected? // Highlighted item not selected?
if (!highlighted.Selected) if (!highlighted.Selected)
{ {
// Select only this sector for dragging // Select only this sector for dragging
General.Map.Map.ClearSelectedSectors(); General.Map.Map.ClearSelectedSectors();
dragsectors.Add(highlighted); dragsectors = new List<Sector> { highlighted };
UpdateOverlaySurfaces(); //mxd UpdateOverlaySurfaces(); //mxd
} }
else else
{ {
dragsectors.AddRange(General.Map.Map.GetSelectedSectors(true)); dragsectors = General.Map.Map.GetSelectedSectors(true);
} }
// Start dragging the selection // Start dragging the selection

View file

@ -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 // Stores sizes of the text for text labels so that they only have to be computed once
private Dictionary<string, float> textlabelsizecache; private Dictionary<string, float> textlabelsizecache;
// Things that will be edited
private ICollection<Thing> editthings;
#endregion #endregion
#region ================== Properties #region ================== Properties
@ -484,21 +487,20 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Edit pressed in this mode // Edit pressed in this mode
editpressed = true; 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? // Highlighted item not selected?
if(!highlighted.Selected) if(!highlighted.Selected)
{ {
// Make this the only selection // Make this the only selection
General.Map.Map.ClearSelectedThings(); General.Map.Map.ClearSelectedThings();
highlighted.Marked = true;
editthings = new List<Thing> { highlighted };
UpdateSelectionInfo(); //mxd UpdateSelectionInfo(); //mxd
General.Interface.RedrawDisplay(); General.Interface.RedrawDisplay();
} }
else else
{ {
General.Map.Map.MarkSelectedThings(true, true); editthings = General.Map.Map.GetSelectedThings(true);
} }
// Update display // Update display
@ -528,7 +530,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
General.Map.Map.ClearSelectedThings(); General.Map.Map.ClearSelectedThings();
General.Map.Map.ClearMarkedThings(false); General.Map.Map.ClearMarkedThings(false);
t.Marked = true; editthings = new List<Thing> { t };
Highlight(t); Highlight(t);
General.Interface.RedrawDisplay(); General.Interface.RedrawDisplay();
} }
@ -543,10 +545,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Edit pressed in this mode? // Edit pressed in this mode?
if(editpressed) if(editpressed)
{ {
// Anything selected? if(editthings?.Count > 0)
ICollection<Thing> editthings = General.Map.Map.GetMarkedThings(true);
if(editthings.Count > 0)
{ {
if(General.Interface.IsActiveWindow) if(General.Interface.IsActiveWindow)
{ {
@ -743,19 +742,19 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Anything highlighted? // Anything highlighted?
if((highlighted != null) && !highlighted.IsDisposed) if((highlighted != null) && !highlighted.IsDisposed)
{ {
List<Thing> dragthings = new List<Thing>(); ICollection<Thing> dragthings;
// Highlighted item not selected? // Highlighted item not selected?
if(!highlighted.Selected) if(!highlighted.Selected)
{ {
// Select only this thing for dragging // Select only this thing for dragging
General.Map.Map.ClearSelectedThings(); General.Map.Map.ClearSelectedThings();
dragthings.Add(highlighted); dragthings = new List<Thing> { highlighted };
} }
else else
{ {
// Add all selected things to the things we want to drag // 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 // Start dragging the selection
@ -765,7 +764,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
bool thingscloned = false; bool thingscloned = false;
if(General.Interface.ShiftState) if(General.Interface.ShiftState)
{ {
List<Thing> clonedthings = new List<Thing>(dragthings.Count); ICollection<Thing> clonedthings = new List<Thing>(dragthings.Count);
if(dragthings.Count > 0) if(dragthings.Count > 0)
{ {
// Make undo // Make undo

View file

@ -59,6 +59,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
// The blockmap makes is used to make finding lines faster // The blockmap makes is used to make finding lines faster
BlockMap<BlockEntry> blockmap; BlockMap<BlockEntry> blockmap;
// Vertices that will be edited
ICollection<Vertex> editvertices;
#endregion #endregion
#region ================== Properties #region ================== Properties
@ -294,13 +297,15 @@ namespace CodeImp.DoomBuilder.BuilderModes
{ {
// Make this the only selection // Make this the only selection
General.Map.Map.ClearSelectedVertices(); General.Map.Map.ClearSelectedVertices();
highlighted.Marked = true;
editvertices = new List<Vertex> { highlighted };
UpdateSelectionInfo(); //mxd UpdateSelectionInfo(); //mxd
General.Interface.RedrawDisplay(); General.Interface.RedrawDisplay();
} }
else else
{ {
General.Map.Map.MarkSelectedVertices(true, true); editvertices = General.Map.Map.GetSelectedVertices(true);
} }
// Update display // Update display
@ -400,10 +405,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Edit pressed in this mode? // Edit pressed in this mode?
if(editpressed) if(editpressed)
{ {
// Anything selected? if(editvertices?.Count > 0)
ICollection<Vertex> editvertices = General.Map.Map.GetMarkedVertices(true);
if(editvertices.Count > 0)
{ {
if(General.Interface.IsActiveWindow) if(General.Interface.IsActiveWindow)
{ {
@ -635,19 +637,19 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Anything highlighted? // Anything highlighted?
if((highlighted != null) && !highlighted.IsDisposed) if((highlighted != null) && !highlighted.IsDisposed)
{ {
List<Vertex> dragvertices = new List<Vertex>(); ICollection<Vertex> dragvertices;
// Highlighted item not selected? // Highlighted item not selected?
if(!highlighted.Selected) if(!highlighted.Selected)
{ {
// Select only this vertex for dragging // Select only this vertex for dragging
General.Map.Map.ClearSelectedVertices(); General.Map.Map.ClearSelectedVertices();
dragvertices.Add(highlighted); dragvertices = new List<Vertex> { highlighted };
} }
else else
{ {
// Add all selected vertices to the vertices we want to drag // 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 // Start dragging the selection