The raisesectortonearest and lowersectortonearest now work with visual slope handles

This commit is contained in:
biwa 2020-03-19 16:16:08 +01:00
parent 7b0adadbfb
commit f5baa09684
2 changed files with 395 additions and 307 deletions

View file

@ -2405,6 +2405,46 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd
[BeginAction("raisesectortonearest")]
public void RaiseSectorToNearest()
{
List<VisualSidedefSlope> selectedhandles = GetSelectedSlopeHandles();
if (selectedhandles.Count > 0)
{
if (selectedhandles.Count > 1)
{
General.Interface.DisplayStatus(StatusType.Warning, "Can only raise to nearest when one visual slope handle is selected");
return;
}
int startheight = (int)selectedhandles[0].GetCenterPoint().z;
int targetheight = int.MaxValue;
foreach (KeyValuePair<Sector, List<VisualSlope>> kvp in allslopehandles)
{
foreach (VisualSidedefSlope handle in kvp.Value)
{
if (handle != selectedhandles[0] && handle.Sidedef.Line == selectedhandles[0].Sidedef.Line)
{
int z = (int)handle.GetCenterPoint().z;
if (z > startheight && z < targetheight)
targetheight = z;
}
}
}
if (targetheight != int.MaxValue)
{
PreAction(UndoGroup.SectorHeightChange);
selectedhandles[0].OnChangeTargetHeight(targetheight - startheight);
PostAction();
}
else
{
General.Interface.DisplayStatus(StatusType.Warning, "Can't raise: already at the highest level");
}
}
else
{
Dictionary<Sector, VisualFloor> floors = new Dictionary<Sector, VisualFloor>();
Dictionary<Sector, VisualCeiling> ceilings = new Dictionary<Sector, VisualCeiling>();
@ -2601,10 +2641,51 @@ namespace CodeImp.DoomBuilder.BuilderModes
PostAction();
}
}
//mxd
[BeginAction("lowersectortonearest")]
public void LowerSectorToNearest()
{
List<VisualSidedefSlope> selectedhandles = GetSelectedSlopeHandles();
if (selectedhandles.Count > 0)
{
if (selectedhandles.Count > 1)
{
General.Interface.DisplayStatus(StatusType.Warning, "Can only lower to nearest when one visual slope handle is selected");
return;
}
int startheight = (int)selectedhandles[0].GetCenterPoint().z;
int targetheight = int.MinValue;
foreach (KeyValuePair<Sector, List<VisualSlope>> kvp in allslopehandles)
{
foreach (VisualSidedefSlope handle in kvp.Value)
{
if (handle != selectedhandles[0] && handle.Sidedef.Line == selectedhandles[0].Sidedef.Line)
{
int z = (int)handle.GetCenterPoint().z;
if (z < startheight && z > targetheight)
targetheight = z;
}
}
}
if (targetheight != int.MinValue)
{
PreAction(UndoGroup.SectorHeightChange);
selectedhandles[0].OnChangeTargetHeight(-(startheight - targetheight));
PostAction();
}
else
{
General.Interface.DisplayStatus(StatusType.Warning, "Can't lower: already at the lowest level");
}
}
else
{
Dictionary<Sector, VisualFloor> floors = new Dictionary<Sector, VisualFloor>();
Dictionary<Sector, VisualCeiling> ceilings = new Dictionary<Sector, VisualCeiling>();
@ -2798,6 +2879,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
PostAction();
}
}
//mxd
[BeginAction("matchbrightness")]

View file

@ -60,6 +60,12 @@ namespace CodeImp.DoomBuilder.VisualModes
#region ================== Methods
public Vector3D GetCenterPoint()
{
Vector2D p = sidedef.Line.GetCenterPoint();
return new Vector3D(p, level.plane.GetZ(p));
}
public override void Update()
{
plane = new Plane(level.plane.Normal, level.plane.Offset - 0.1f);