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

This commit is contained in:
biwa 2020-04-11 10:42:41 +02:00
parent 12b3906470
commit 138c96bb13
5 changed files with 76 additions and 28 deletions

View file

@ -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;

View file

@ -2656,6 +2656,11 @@ namespace CodeImp.DoomBuilder
return snappedCount;
}
public void GridVisibilityChanged()
{
renderer2d.GridVisibilityChanged();
}
#endregion
}
}

View file

@ -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()

View file

@ -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)
{

View file

@ -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<Vertex> selected, Linedef ld1, Linedef ld2, Vertex v)
{
Vertex v1 = (ld1.Start == v) ? ld1.End : ld1.Start;