diff --git a/Source/Core/VisualModes/VisualSlope.cs b/Source/Core/VisualModes/VisualSlope.cs index 0035141d..a4632d2a 100644 --- a/Source/Core/VisualModes/VisualSlope.cs +++ b/Source/Core/VisualModes/VisualSlope.cs @@ -109,6 +109,7 @@ namespace CodeImp.DoomBuilder.VisualModes public virtual void Update() {} public virtual Vector3D GetPivotPoint() { return new Vector3D(); } + public virtual VisualSlope GetSmartPivotHandle() { return null; } public void SetPosition(Line2D line, Plane plane) { diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index e5e65326..6e0639b2 100755 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -545,24 +545,12 @@ namespace CodeImp.DoomBuilder.BuilderModes usedslopehandles.Remove((VisualSlope)target.picked); } - if (newtarget.picked is VisualSidedefSlope) + if(newtarget.picked is VisualSlope) { - usedslopehandles.Add((VisualSidedefSlope)newtarget.picked); + usedslopehandles.Add((VisualSlope)newtarget.picked); // Get the smart pivot handle for the targeted slope handle, so that it can be drawn - VisualSlope handle = VisualSidedefSlope.GetSmartPivotHandle((VisualSidedefSlope)newtarget.picked, this); - if (handle != null) - { - handle.SmartPivot = true; - usedslopehandles.Add(handle); - } - } - else if(newtarget.picked is VisualVertexSlope) - { - usedslopehandles.Add((VisualVertexSlope)newtarget.picked); - - // Get the smart pivot handle for the targeted slope handle, so that it can be drawn - VisualSlope handle = VisualVertexSlope.GetSmartPivotHandle((VisualVertexSlope)newtarget.picked, this); + VisualSlope handle = ((VisualSlope)newtarget.picked).GetSmartPivotHandle(); if (handle != null) { handle.SmartPivot = true; @@ -839,7 +827,8 @@ namespace CodeImp.DoomBuilder.BuilderModes // No handles selected, try to slope between highlighted handle and it smart pivot if (handles.Count == 0 && HighlightedTarget is VisualSidedefSlope) { - VisualSidedefSlope handle = VisualSidedefSlope.GetSmartPivotHandle((VisualSidedefSlope)HighlightedTarget, this); + //VisualSidedefSlope handle = VisualSidedefSlope.GetSmartPivotHandle((VisualSidedefSlope)HighlightedTarget, this); + VisualSidedefSlope handle = (VisualSidedefSlope)((VisualSidedefSlope)HighlightedTarget).GetSmartPivotHandle(); if (handle == null) { General.Interface.DisplayStatus(StatusType.Warning, "Couldn't find a smart pivot handle."); @@ -857,9 +846,9 @@ namespace CodeImp.DoomBuilder.BuilderModes VisualSidedefSlope handle; if (HighlightedTarget is VisualSidedefSlope) - handle = VisualSidedefSlope.GetSmartPivotHandle((VisualSidedefSlope)HighlightedTarget, this); + handle = (VisualSidedefSlope)((VisualSidedefSlope)HighlightedTarget).GetSmartPivotHandle(); else - handle = VisualSidedefSlope.GetSmartPivotHandle(handles[0], this); + handle = (VisualSidedefSlope)(handles[0].GetSmartPivotHandle()); if (handle == null) { diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs b/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs index 00fd2d4e..739711d5 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs @@ -160,20 +160,19 @@ namespace CodeImp.DoomBuilder.VisualModes /// same angle as the start handle, and is the furthest away. If such a handle does not exist it finds one that's /// closest to those specs /// - /// The slope handle to start from (the one we need to find a pivot handle for) /// - public static VisualSidedefSlope GetSmartPivotHandle(VisualSidedefSlope starthandle, BaseVisualMode mode) + public override VisualSlope GetSmartPivotHandle() { - VisualSidedefSlope handle = starthandle; + VisualSlope handle = this; List potentialhandles = new List(); List selectedsectors = mode.GetSelectedObjects(true, false, false, false, false); if (selectedsectors.Count == 0) { // No sectors selected, so find all handles that belong to the same level - foreach (VisualSidedefSlope checkhandle in mode.SidedefSlopeHandles[starthandle.Sidedef.Sector]) + foreach (VisualSidedefSlope checkhandle in mode.SidedefSlopeHandles[sidedef.Sector]) { - if (checkhandle != starthandle && checkhandle.Level == starthandle.Level) + if (checkhandle != this && checkhandle.Level == level) potentialhandles.Add(checkhandle); } } @@ -188,7 +187,7 @@ namespace CodeImp.DoomBuilder.VisualModes foreach (Sector s in sectors) foreach (VisualSidedefSlope checkhandle in mode.SidedefSlopeHandles[s]) { - if (checkhandle != starthandle) + if (checkhandle != this) foreach (BaseVisualGeometrySector bvgs in selectedsectors) if (bvgs.Level == checkhandle.Level) potentialhandles.Add(checkhandle); @@ -196,13 +195,13 @@ namespace CodeImp.DoomBuilder.VisualModes } // Sort potential handles by their angle difference to the start handle. That means that handles with less angle difference will be at the beginning of the list - List anglediffsortedhandles = potentialhandles.OrderBy(h => Math.Abs(starthandle.NormalizedAngleDeg - h.NormalizedAngleDeg)).ToList(); + List anglediffsortedhandles = potentialhandles.OrderBy(h => Math.Abs(NormalizedAngleDeg - h.NormalizedAngleDeg)).ToList(); // Get all potential handles that have to same angle as the one that's closest to the start handle, then sort them by distance, and take the one that's furthest away if (anglediffsortedhandles.Count > 0) - handle = anglediffsortedhandles.Where(h => h.NormalizedAngleDeg == anglediffsortedhandles[0].NormalizedAngleDeg).OrderByDescending(h => Math.Abs(starthandle.Sidedef.Line.Line.GetDistanceToLine(h.sidedef.Line.GetCenterPoint(), false))).First(); + handle = anglediffsortedhandles.Where(h => h.NormalizedAngleDeg == anglediffsortedhandles[0].NormalizedAngleDeg).OrderByDescending(h => Math.Abs(sidedef.Line.Line.GetDistanceToLine(h.sidedef.Line.GetCenterPoint(), false))).First(); - if (handle == starthandle) + if (handle == this) return null; return handle; @@ -331,7 +330,7 @@ namespace CodeImp.DoomBuilder.VisualModes // User didn't set a pivot handle, try to find the smart pivot handle if(pivothandle == null) - pivothandle = GetSmartPivotHandle(this, mode); + pivothandle = GetSmartPivotHandle(); // Still no pivot handle, cancle if (pivothandle == null) diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualVertexSlope.cs b/Source/Plugins/BuilderModes/VisualModes/VisualVertexSlope.cs index a61ead3a..a82d45a1 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualVertexSlope.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualVertexSlope.cs @@ -168,20 +168,19 @@ namespace CodeImp.DoomBuilder.VisualModes /// /// Finds a slope handle to pivot around. It takes the vertex that's furthest away from the given handle /// - /// The slope handle to start from (the one we need to find a pivot handle for) /// - public static VisualVertexSlope GetSmartPivotHandle(VisualVertexSlope starthandle, BaseVisualMode mode) + public override VisualSlope GetSmartPivotHandle() { - VisualVertexSlope handle = starthandle; + VisualSlope handle = this; List potentialhandles = new List(); List selectedsectors = mode.GetSelectedObjects(true, false, false, false, false); if (selectedsectors.Count == 0) { // No sectors selected, so find all handles that belong to the same level - foreach (VisualVertexSlope checkhandle in mode.VertexSlopeHandles[starthandle.Sector]) + foreach (VisualVertexSlope checkhandle in mode.VertexSlopeHandles[sector]) { - if (checkhandle != starthandle && checkhandle.Level == starthandle.Level) + if (checkhandle != this && checkhandle.Level == level) potentialhandles.Add(checkhandle); } } @@ -196,16 +195,16 @@ namespace CodeImp.DoomBuilder.VisualModes foreach (Sector s in sectors) foreach (VisualVertexSlope checkhandle in mode.VertexSlopeHandles[s]) { - if (checkhandle != starthandle) + if (checkhandle != this) foreach (BaseVisualGeometrySector bvgs in selectedsectors) if (bvgs.Level == checkhandle.Level) potentialhandles.Add(checkhandle); } } - handle = potentialhandles.OrderByDescending(h => Vector2D.Distance(h.Vertex.Position, starthandle.vertex.Position)).First(); + handle = potentialhandles.OrderByDescending(h => Vector2D.Distance(h.Vertex.Position, vertex.Position)).First(); - if (handle == starthandle) + if (handle == this) return null; return handle; @@ -306,7 +305,7 @@ namespace CodeImp.DoomBuilder.VisualModes // User didn't set a pivot handle, try to find the smart pivot handle if (pivothandle == null) - pivothandle = GetSmartPivotHandle(this, mode); + pivothandle = GetSmartPivotHandle(); // Still no pivot handle, cancle if (pivothandle == null)