mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-31 04:40:55 +00:00
Some refactoring related to visual sloping
This commit is contained in:
parent
41e1652bfc
commit
b70970ebcf
4 changed files with 25 additions and 37 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
/// </summary>
|
||||
/// <param name="starthandle">The slope handle to start from (the one we need to find a pivot handle for)</param>
|
||||
/// <returns></returns>
|
||||
public static VisualSidedefSlope GetSmartPivotHandle(VisualSidedefSlope starthandle, BaseVisualMode mode)
|
||||
public override VisualSlope GetSmartPivotHandle()
|
||||
{
|
||||
VisualSidedefSlope handle = starthandle;
|
||||
VisualSlope handle = this;
|
||||
List<VisualSidedefSlope> potentialhandles = new List<VisualSidedefSlope>();
|
||||
List<IVisualEventReceiver> 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<VisualSidedefSlope> anglediffsortedhandles = potentialhandles.OrderBy(h => Math.Abs(starthandle.NormalizedAngleDeg - h.NormalizedAngleDeg)).ToList();
|
||||
List<VisualSidedefSlope> 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)
|
||||
|
|
|
@ -168,20 +168,19 @@ namespace CodeImp.DoomBuilder.VisualModes
|
|||
/// <summary>
|
||||
/// Finds a slope handle to pivot around. It takes the vertex that's furthest away from the given handle
|
||||
/// </summary>
|
||||
/// <param name="starthandle">The slope handle to start from (the one we need to find a pivot handle for)</param>
|
||||
/// <returns></returns>
|
||||
public static VisualVertexSlope GetSmartPivotHandle(VisualVertexSlope starthandle, BaseVisualMode mode)
|
||||
public override VisualSlope GetSmartPivotHandle()
|
||||
{
|
||||
VisualVertexSlope handle = starthandle;
|
||||
VisualSlope handle = this;
|
||||
List<VisualVertexSlope> potentialhandles = new List<VisualVertexSlope>();
|
||||
List<IVisualEventReceiver> 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)
|
||||
|
|
Loading…
Reference in a new issue