diff --git a/Source/BuilderModes/ClassicModes/CurveLinedefsMode.cs b/Source/BuilderModes/ClassicModes/CurveLinedefsMode.cs index f73cbcd7..96e464af 100644 --- a/Source/BuilderModes/ClassicModes/CurveLinedefsMode.cs +++ b/Source/BuilderModes/ClassicModes/CurveLinedefsMode.cs @@ -110,7 +110,7 @@ namespace CodeImp.DoomBuilder.BuilderModes base.OnEngage(); // Show toolbox window - BuilderPlug.Me.CurveLinedefsForm.Show((Form)General.Interface, this); + BuilderPlug.Me.CurveLinedefsForm.Show((Form)General.Interface); } // Disenagaging @@ -123,7 +123,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } // This applies the curves and returns to the base mode - public void Apply() + public override void OnAccept() { // Create undo General.Map.UndoRedo.CreateUndo("Curve linedefs", UndoGroup.None, 0); diff --git a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs index 83f38427..7fd5d6ef 100644 --- a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs +++ b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs @@ -135,8 +135,8 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Map.ChangeMode(basemode); } - // Disenagaging - public override void OnDisengage() + // Accepted + public override void OnAccept() { List newverts = new List(); List intersectverts = new List(); @@ -145,21 +145,18 @@ namespace CodeImp.DoomBuilder.BuilderModes List insidesides = new List(); List mergeverts = new List(); List nonmergeverts = new List(General.Map.Map.Vertices); - MapSet map = General.Map.Map; - base.OnDisengage(); - Cursor.Current = Cursors.AppStarting; General.Settings.FindDefaultDrawSettings(); - - // When not cancelled and points have been drawn - if(!cancelled && (points.Count > 0)) + + // When points have been drawn + if(points.Count > 0) { // Make undo for the draw General.Map.UndoRedo.CreateUndo("line draw", UndoGroup.None, 0); - + /***************************************************\ STEP 1: Create the new geometry \***************************************************/ @@ -167,7 +164,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Make first vertex Vertex v1 = map.CreateVertex(points[0].pos); v1.Marked = true; - + // Keep references newverts.Add(v1); if(points[0].stitch) mergeverts.Add(v1); else nonmergeverts.Add(v1); @@ -178,7 +175,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Create vertex for point Vertex v2 = map.CreateVertex(points[i].pos); v2.Marked = true; - + // Keep references newverts.Add(v2); if(points[i].stitch) mergeverts.Add(v2); else nonmergeverts.Add(v2); @@ -190,7 +187,7 @@ namespace CodeImp.DoomBuilder.BuilderModes ld.ApplySidedFlags(); ld.UpdateCache(); newlines.Add(ld); - + // Should we split this line to merge with intersecting lines? if(points[i - 1].stitch && points[i].stitch) { @@ -228,7 +225,7 @@ namespace CodeImp.DoomBuilder.BuilderModes newverts.Add(splitvertex); mergeverts.Add(splitvertex); // <-- add to merge? intersectverts.Add(splitvertex); - + // The Split method ties the end of the original line to the given // vertex and starts a new line at the given vertex, so continue // splitting with the new line, because the intersections are sorted @@ -238,14 +235,14 @@ namespace CodeImp.DoomBuilder.BuilderModes newlines.Add(splitline); } } - + // Next v1 = v2; } // Join merge vertices so that overlapping vertices in the draw become one. MapSet.JoinVertices(mergeverts, mergeverts, false, MapSet.STITCH_DISTANCE); - + // We prefer a closed polygon, because then we can determine the interior properly // Check if the two ends of the polygon are closed bool drawingclosed = false; @@ -266,7 +263,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if((l1 != null) && (l2 != null)) { List shortestpath = null; - + // Same line? if(l1 == l2) { @@ -286,11 +283,11 @@ namespace CodeImp.DoomBuilder.BuilderModes paths.Add(SectorTools.FindClosestPath(l2, true, l1, false, true)); paths.Add(SectorTools.FindClosestPath(l2, false, l1, true, true)); paths.Add(SectorTools.FindClosestPath(l2, false, l1, false, true)); - + foreach(List p in paths) if((p != null) && ((shortestpath == null) || (p.Count < shortestpath.Count))) shortestpath = p; } - + // Found a path? if(shortestpath != null) { @@ -300,12 +297,12 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Get the next position Vector2D v2pos = shortestpath[i].Front ? shortestpath[i].Line.Start.Position : shortestpath[i].Line.End.Position; - + // Make the new vertex Vertex v2 = map.CreateVertex(v2pos); v2.Marked = true; mergeverts.Add(v2); - + // Make the line Linedef ld = map.CreateLinedef(v1, v2); ld.Marked = true; @@ -336,13 +333,13 @@ namespace CodeImp.DoomBuilder.BuilderModes } } } - + // Merge intersetion vertices with the new lines. This completes the // self intersections for which splits were made above. map.Update(true, false); MapSet.SplitLinesByVertices(newlines, intersectverts, MapSet.STITCH_DISTANCE, null); MapSet.SplitLinesByVertices(newlines, mergeverts, MapSet.STITCH_DISTANCE, null); - + /***************************************************\ STEP 2: Merge the new geometry \***************************************************/ @@ -362,7 +359,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Make polygon LinedefTracePath tracepath = new LinedefTracePath(pathlines); Polygon pathpoly = tracepath.MakePolygon(); - + // Check if the front of the line is outside the polygon if(!pathpoly.Intersect(ld.GetSidePoint(true))) { @@ -394,17 +391,17 @@ namespace CodeImp.DoomBuilder.BuilderModes // Mark only the vertices that should be merged map.ClearMarkedVertices(false); foreach(Vertex v in mergeverts) v.Marked = true; - + // Before this point, the new geometry is not linked with the existing geometry. // Now perform standard geometry stitching to merge the new geometry with the rest // of the map. The marked vertices indicate the new geometry. map.StitchGeometry(); map.Update(true, false); - + // Find our new lines again, because they have been merged with the other geometry // but their Marked property is copied where they have joined. newlines = map.GetMarkedLinedefs(true); - + /***************************************************\ STEP 3: Join and create new sectors \***************************************************/ @@ -417,7 +414,7 @@ namespace CodeImp.DoomBuilder.BuilderModes for(int i = 0; i < newlines.Count; i++) { Linedef ld = newlines[i]; - + // Front not marked as done? if(!frontsdone[i]) { @@ -427,13 +424,13 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Make the new sector Sector newsector = SectorTools.MakeSector(sectorlines); - + // Go for all sidedefs in this new sector foreach(Sidedef sd in newsector.Sidedefs) { // Keep list of sides inside created sectors insidesides.Add(sd); - + // Side matches with a side of our new lines? int lineindex = newlines.IndexOf(sd.Line); if(lineindex > -1) @@ -471,7 +468,7 @@ namespace CodeImp.DoomBuilder.BuilderModes break; } } - + // Join? if(joinsidedef != null) { @@ -510,10 +507,10 @@ namespace CodeImp.DoomBuilder.BuilderModes { sd.RemoveUnneededTextures(true); } - + // Snap to map format accuracy General.Map.Map.SnapAllToAccuracy(); - + // Update cached values map.Update(); @@ -523,6 +520,11 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done Cursor.Current = Cursors.Default; + + // Return to original mode + Type t = basemode.GetType(); + basemode = (EditMode)Activator.CreateInstance(t); + General.Map.ChangeMode(basemode); } // This checks if the view offset/zoom changed and updates the check @@ -781,8 +783,8 @@ namespace CodeImp.DoomBuilder.BuilderModes [BeginAction("finishdraw")] public void FinishDraw() { - // Just return to base mode, Disengage will be called automatically. - General.Map.ChangeMode(basemode); + // Accept the changes + General.Map.AcceptMode(); } // When a key is released diff --git a/Source/BuilderModes/ClassicModes/LinedefsMode.cs b/Source/BuilderModes/ClassicModes/LinedefsMode.cs index c6c9b58e..6b907352 100644 --- a/Source/BuilderModes/ClassicModes/LinedefsMode.cs +++ b/Source/BuilderModes/ClassicModes/LinedefsMode.cs @@ -53,7 +53,10 @@ namespace CodeImp.DoomBuilder.BuilderModes // Highlighted item private Linedef highlighted; - + + // Interface + private bool editpressed; + #endregion #region ================== Properties @@ -256,6 +259,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Item highlighted? if((highlighted != null) && !highlighted.IsDisposed) { + // Edit pressed in this mode + editpressed = true; + // Highlighted item not selected? if(!highlighted.Selected) { @@ -283,20 +289,25 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done editing protected override void OnEndEdit() { - // Anything selected? - ICollection selected = General.Map.Map.GetSelectedLinedefs(true); - if(selected.Count > 0) + // Edit pressed in this mode? + if(editpressed) { - // Show line edit dialog - General.Interface.ShowEditLinedefs(selected); + // Anything selected? + ICollection selected = General.Map.Map.GetSelectedLinedefs(true); + if(selected.Count > 0) + { + // Show line edit dialog + General.Interface.ShowEditLinedefs(selected); - // When a single line was selected, deselect it now - if(selected.Count == 1) General.Map.Map.ClearSelectedLinedefs(); + // When a single line was selected, deselect it now + if(selected.Count == 1) General.Map.Map.ClearSelectedLinedefs(); - // Update entire display - General.Interface.RedrawDisplay(); + // Update entire display + General.Interface.RedrawDisplay(); + } } + editpressed = false; base.OnEndEdit(); } diff --git a/Source/BuilderModes/ClassicModes/SectorsMode.cs b/Source/BuilderModes/ClassicModes/SectorsMode.cs index add6921a..6eb77550 100644 --- a/Source/BuilderModes/ClassicModes/SectorsMode.cs +++ b/Source/BuilderModes/ClassicModes/SectorsMode.cs @@ -53,6 +53,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Highlighted item private Sector highlighted; + // Interface + private bool editpressed; + // The methods GetSelected* and MarkSelected* on the MapSet do not // retain the order in which items were selected. // This list keeps in order while sectors are selected/deselected. @@ -319,6 +322,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Item highlighted? if((highlighted != null) && !highlighted.IsDisposed) { + // Edit pressed in this mode + editpressed = true; + // Highlighted item not selected? if(!highlighted.Selected) { @@ -345,24 +351,29 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done editing protected override void OnEndEdit() { - // Anything selected? - ICollection selected = General.Map.Map.GetSelectedSectors(true); - if(selected.Count > 0) + // Edit pressed in this mode? + if(editpressed) { - // Show sector edit dialog - General.Interface.ShowEditSectors(selected); - - // When a single sector was selected, deselect it now - if(selected.Count == 1) + // Anything selected? + ICollection selected = General.Map.Map.GetSelectedSectors(true); + if(selected.Count > 0) { - General.Map.Map.ClearSelectedSectors(); - General.Map.Map.ClearSelectedLinedefs(); - } + // Show sector edit dialog + General.Interface.ShowEditSectors(selected); - // Update entire display - General.Interface.RedrawDisplay(); + // When a single sector was selected, deselect it now + if(selected.Count == 1) + { + General.Map.Map.ClearSelectedSectors(); + General.Map.Map.ClearSelectedLinedefs(); + } + + // Update entire display + General.Interface.RedrawDisplay(); + } } + editpressed = false; base.OnEndEdit(); } diff --git a/Source/BuilderModes/ClassicModes/ThingsMode.cs b/Source/BuilderModes/ClassicModes/ThingsMode.cs index 6c77bca6..e3331e20 100644 --- a/Source/BuilderModes/ClassicModes/ThingsMode.cs +++ b/Source/BuilderModes/ClassicModes/ThingsMode.cs @@ -53,6 +53,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Highlighted item private Thing highlighted; + // Interface + private bool editpressed; + #endregion #region ================== Properties @@ -227,6 +230,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Item highlighted? if((highlighted != null) && !highlighted.IsDisposed) { + // Edit pressed in this mode + editpressed = true; + // Highlighted item not selected? if(!highlighted.Selected) { @@ -252,20 +258,25 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done editing protected override void OnEndEdit() { - // Anything selected? - ICollection selected = General.Map.Map.GetSelectedThings(true); - if(selected.Count > 0) + // Edit pressed in this mode? + if(editpressed) { - // Show thing edit dialog - // TODO + // Anything selected? + ICollection selected = General.Map.Map.GetSelectedThings(true); + if(selected.Count > 0) + { + // Show thing edit dialog + // TODO - // When a single thing was selected, deselect it now - if(selected.Count == 1) General.Map.Map.ClearSelectedThings(); + // When a single thing was selected, deselect it now + if(selected.Count == 1) General.Map.Map.ClearSelectedThings(); - // Update entire display - General.Interface.RedrawDisplay(); + // Update entire display + General.Interface.RedrawDisplay(); + } } + editpressed = false; base.OnEndEdit(); } diff --git a/Source/BuilderModes/ClassicModes/VerticesMode.cs b/Source/BuilderModes/ClassicModes/VerticesMode.cs index ebba99a3..e193f7e3 100644 --- a/Source/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/BuilderModes/ClassicModes/VerticesMode.cs @@ -53,6 +53,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Highlighted item protected Vertex highlighted; + // Interface + private bool editpressed; + #endregion #region ================== Properties @@ -238,12 +241,16 @@ namespace CodeImp.DoomBuilder.BuilderModes // Start editing protected override void OnEdit() { + // Edit pressed in this mode + editpressed = true; + base.OnEdit(); } // Done editing protected override void OnEndEdit() { + editpressed = false; base.OnEndEdit(); } diff --git a/Source/BuilderModes/Interface/CurveLinedefsForm.cs b/Source/BuilderModes/Interface/CurveLinedefsForm.cs index d5b124d9..340acd87 100644 --- a/Source/BuilderModes/Interface/CurveLinedefsForm.cs +++ b/Source/BuilderModes/Interface/CurveLinedefsForm.cs @@ -40,8 +40,6 @@ namespace CodeImp.DoomBuilder.BuilderModes { #region ================== Variables - private CurveLinedefsMode mode; - #endregion #region ================== Properties @@ -80,11 +78,8 @@ namespace CodeImp.DoomBuilder.BuilderModes } // This shows the window - public void Show(Form owner, CurveLinedefsMode mode) + public void Show(Form owner) { - // Keep reference to mode - this.mode = mode; - // First time showing? //if((this.Location.X == 0) && (this.Location.Y == 0)) { @@ -183,7 +178,7 @@ namespace CodeImp.DoomBuilder.BuilderModes private void apply_Click(object sender, EventArgs e) { // Apply now - mode.Apply(); + General.Map.AcceptMode(); } #endregion diff --git a/Source/Editing/EditMode.cs b/Source/Editing/EditMode.cs index ea6ed0ab..a090ac72 100644 --- a/Source/Editing/EditMode.cs +++ b/Source/Editing/EditMode.cs @@ -162,6 +162,8 @@ namespace CodeImp.DoomBuilder.Editing // This forces the mode to cancel and return to the "parent" mode public virtual void OnCancel() { } + + public virtual void OnAccept() { } // Interface events public virtual void OnMouseClick(MouseEventArgs e) { } diff --git a/Source/General/MapManager.cs b/Source/General/MapManager.cs index 6ce82b01..68af9656 100644 --- a/Source/General/MapManager.cs +++ b/Source/General/MapManager.cs @@ -832,7 +832,17 @@ namespace CodeImp.DoomBuilder // Let the mode know mode.OnCancel(); } - + + /// + /// This accepts the changes in the current mode. + /// + [BeginAction("acceptmode")] + public void AcceptMode() + { + // Let the mode know + mode.OnAccept(); + } + // // This changes the editing mode. // Order in which events occur for the old and new modes: diff --git a/Source/Resources/Actions.cfg b/Source/Resources/Actions.cfg index 7b6d3c11..60ec0ccd 100644 --- a/Source/Resources/Actions.cfg +++ b/Source/Resources/Actions.cfg @@ -126,6 +126,15 @@ cancelmode allowscroll = true; } +acceptmode +{ + title = "Edit: Accept Action"; + description = "Accepts the changes in the current action and switches back to normal editing mode."; + allowkeys = true; + allowmouse = true; + allowscroll = true; +} + classicselect { title = "2D: Select";