From 138c96bb13f7c814c1b4bb21f3b059abfc258234 Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Sat, 11 Apr 2020 10:42:41 +0200 Subject: [PATCH] Moved smart grid transform into Linedefs Mode and Vertices Mode, so it also works when simply highlighting a linedef or vertex. When doing smart grid transform on a linedef it'll also use the vertex closest to the mouse cursor as the origin instead of always the start vertex --- Source/Core/Editing/GridSetup.cs | 4 +-- Source/Core/General/MapManager.cs | 5 +++ Source/Core/Windows/MainForm.cs | 25 ------------- .../BuilderModes/ClassicModes/LinedefsMode.cs | 35 +++++++++++++++++++ .../BuilderModes/ClassicModes/VerticesMode.cs | 35 ++++++++++++++++++- 5 files changed, 76 insertions(+), 28 deletions(-) diff --git a/Source/Core/Editing/GridSetup.cs b/Source/Core/Editing/GridSetup.cs index d8116905..4da46086 100755 --- a/Source/Core/Editing/GridSetup.cs +++ b/Source/Core/Editing/GridSetup.cs @@ -177,13 +177,13 @@ namespace CodeImp.DoomBuilder.Editing } // Set the rotation angle of the grid - internal void SetGridRotation(float angle) + public void SetGridRotation(float angle) { gridrotate = angle; } // Set the origin of the grid - internal void SetGridOrigin(float x, float y) + public void SetGridOrigin(float x, float y) { gridoriginx = x; gridoriginy = y; diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs index f5d1df49..bb480b20 100755 --- a/Source/Core/General/MapManager.cs +++ b/Source/Core/General/MapManager.cs @@ -2656,6 +2656,11 @@ namespace CodeImp.DoomBuilder return snappedCount; } + public void GridVisibilityChanged() + { + renderer2d.GridVisibilityChanged(); + } + #endregion } } \ No newline at end of file diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 58f21975..a9856c71 100755 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -2963,31 +2963,6 @@ namespace CodeImp.DoomBuilder.Windows General.Interface.RedrawDisplay(); } - [BeginAction("smartgridtransform")] - protected void SmartGridTransform() - { - if((General.Map.Map.SelectedVerticessCount >= 1 && General.Map.Map.SelectedLinedefsCount >= 1) || General.Map.Map.SelectedVerticessCount > 1 || General.Map.Map.SelectedLinedefsCount > 1) - { - General.Interface.DisplayStatus(StatusType.Warning, "Either nothing or either exactly one vertex or linedef must be selected"); - General.Interface.MessageBeep(MessageBeepType.Warning); - return; - } - - if(General.Map.Map.SelectedVerticessCount == 1) - { - SetGridOriginToVertex(); - return; - } - - if(General.Map.Map.SelectedLinedefsCount == 1) - { - AlignGridToLinedef(); - return; - } - - ResetGrid(); - } - //mxd [BeginAction("toggledynamicgrid")] protected void ToggleDynamicGrid() diff --git a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs index 5606628e..4361e33f 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs @@ -1853,6 +1853,41 @@ namespace CodeImp.DoomBuilder.BuilderModes } } + [BeginAction("smartgridtransform", BaseAction = true)] + protected void SmartGridTransform() + { + if (General.Map.Map.SelectedLinedefsCount > 1) + { + General.Interface.DisplayStatus(StatusType.Warning, "Either nothing or exactly one linedef must be selected"); + General.Interface.MessageBeep(MessageBeepType.Warning); + return; + } + + Linedef linedef = null; + + if (General.Map.Map.SelectedLinedefsCount == 1) + linedef = General.Map.Map.GetSelectedLinedefs(true).First(); + else if (highlighted != null) + linedef = highlighted; + + if (linedef != null) + { + // Get the vertex that's closest to the mouse cursor + Vertex vertex = (new Vertex[] { linedef.Start, linedef.End }).OrderBy(v => Vector2D.Distance(v.Position, mousemappos)).First(); + General.Map.Grid.SetGridRotation(linedef.Angle); + General.Map.Grid.SetGridOrigin(vertex.Position.x, vertex.Position.y); + General.Map.GridVisibilityChanged(); + General.Interface.RedrawDisplay(); + } + else + { + General.Map.Grid.SetGridRotation(0.0f); + General.Map.Grid.SetGridOrigin(0, 0); + General.Map.GridVisibilityChanged(); + General.Interface.RedrawDisplay(); + } + } + //mxd. gradientbrightness utility private static bool SidedefHasVisibleParts(Sidedef side) { diff --git a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs index 89a9c89f..ebb4b10f 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; using CodeImp.DoomBuilder.BuilderModes.Interface; using CodeImp.DoomBuilder.Windows; @@ -1099,11 +1100,43 @@ namespace CodeImp.DoomBuilder.BuilderModes if(form.Setup(this)) form.ShowDialog(General.Interface); } + [BeginAction("smartgridtransform", BaseAction = true)] + protected void SmartGridTransform() + { + if (General.Map.Map.SelectedVerticessCount > 1) + { + General.Interface.DisplayStatus(StatusType.Warning, "Either nothing or exactly one vertex must be selected"); + General.Interface.MessageBeep(MessageBeepType.Warning); + return; + } + + Vertex vertex = null; + + if (General.Map.Map.SelectedVerticessCount == 1) + vertex = General.Map.Map.GetSelectedVertices(true).First(); + else if (highlighted != null) + vertex = highlighted; + + if (vertex != null) + { + General.Map.Grid.SetGridOrigin(vertex.Position.x, vertex.Position.y); + General.Map.GridVisibilityChanged(); + General.Interface.RedrawDisplay(); + } + else + { + General.Map.Grid.SetGridRotation(0.0f); + General.Map.Grid.SetGridOrigin(0, 0); + General.Map.GridVisibilityChanged(); + General.Interface.RedrawDisplay(); + } + } + #endregion #region ================== Action assist (mxd) - //mxd + //mxd private static void MergeLines(ICollection selected, Linedef ld1, Linedef ld2, Vertex v) { Vertex v1 = (ld1.Start == v) ? ld1.End : ld1.Start;