Support "Align floor/ceiling to front side" actions in SRB2 maps

This commit is contained in:
sphere 2021-05-06 13:18:50 +02:00
parent 5133ff3040
commit 5bb6488ca0

View file

@ -211,18 +211,24 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(lines.Count == 0 && highlighted != null && !highlighted.IsDisposed) if(lines.Count == 0 && highlighted != null && !highlighted.IsDisposed)
lines.Add(highlighted); lines.Add(highlighted);
if(lines.Count == 0) if (lines.Count == 0)
{ {
General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection"); General.Interface.DisplayStatus(StatusType.Warning, "This action requires a selection!");
return;
}
if(General.Map.SRB2 && !alignToFrontSide)
{
General.Interface.DisplayStatus(StatusType.Warning, "SRB2 only supports front-side alignment.");
return; return;
} }
//Create Undo //Create Undo
string rest = (alignFloors ? "Floors" : "Ceilings") + " to " + (alignToFrontSide ? "Front" : "Back")+ " Side"; string rest = (alignFloors ? "floors" : "ceilings") + " to " + (alignToFrontSide ? "front" : "back")+ " side";
General.Map.UndoRedo.CreateUndo("Align " + rest); General.Map.UndoRedo.CreateUndo("Align " + rest);
int counter = 0; int counter = 0;
foreach(Linedef l in lines) foreach (Linedef l in lines)
{ {
Sector s = null; Sector s = null;
@ -240,6 +246,61 @@ namespace CodeImp.DoomBuilder.BuilderModes
s.Fields.BeforeFieldsChange(); s.Fields.BeforeFieldsChange();
// hack for SRB2 flat alignment
if (General.Map.SRB2)
{
bool existing = true;
// don't overwrite existing tags or actions
if (l.Tag != 0 || (!l.IsFlatAlignment && l.Action != 0))
continue;
// add flat alignment effect to new linedefs
if (!l.IsFlatAlignment)
{
l.Action = General.Map.FormatInterface.FlatAlignmentType;
existing = false;
}
if (alignFloors)
{
if (l.IsFlagSet("2048"))
l.SetFlag("2048", false); // enable floor alignment for existing lines
else if (!existing)
l.SetFlag("4096", true); // disable ceiling alignment for new lines
else
l.SetFlag("2048", true); // toggle floor alignment
s.UpdateFloorSurface();
}
else
{
if (l.IsFlagSet("4096"))
l.SetFlag("4096", false); // enable ceiling alignment for existing lines
else if (!existing)
l.SetFlag("2048", true); // disable floor alignment for new lines
else
l.SetFlag("4096", true); // toggle ceiling alignment
s.UpdateCeilingSurface();
}
if (l.IsFlagSet("2048") && l.IsFlagSet("4096")) // clear action if it does nothing
{
l.SetFlag("2048", false);
l.SetFlag("4096", false);
l.Action = 0;
}
s.UpdateNeeded = true;
s.UpdateCache();
continue;
}
if (!General.Map.UDMF && !General.Map.SRB2)
{
General.Interface.DisplayStatus(StatusType.Warning, "This action only works in UDMF or SRB2 map format.");
return;
}
float sourceAngle = (float)Math.Round(General.ClampAngle(alignToFrontSide ? -Angle2D.RadToDeg(l.Angle) + 90 : -Angle2D.RadToDeg(l.Angle) - 90), 1); float sourceAngle = (float)Math.Round(General.ClampAngle(alignToFrontSide ? -Angle2D.RadToDeg(l.Angle) + 90 : -Angle2D.RadToDeg(l.Angle) - 90), 1);
if(!alignToFrontSide) sourceAngle = General.ClampAngle(sourceAngle + 180); if(!alignToFrontSide) sourceAngle = General.ClampAngle(sourceAngle + 180);
@ -269,7 +330,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
s.UpdateCache(); s.UpdateCache();
} }
General.Interface.DisplayStatus(StatusType.Info, "Aligned " +counter + " " + rest); General.Interface.DisplayStatus(StatusType.Info, "Aligned " + counter + " " + rest + ".");
//update //update
General.Map.Map.Update(); General.Map.Map.Update();
@ -1569,7 +1630,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
[BeginAction("alignfloortofront")] [BeginAction("alignfloortofront")]
public void AlignFloorToFront() public void AlignFloorToFront()
{ {
if(!General.Map.UDMF) return;
AlignTextureToLine(true, true); AlignTextureToLine(true, true);
} }
@ -1577,7 +1637,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
[BeginAction("alignfloortoback")] [BeginAction("alignfloortoback")]
public void AlignFloorToBack() public void AlignFloorToBack()
{ {
if(!General.Map.UDMF) return;
AlignTextureToLine(true, false); AlignTextureToLine(true, false);
} }
@ -1585,7 +1644,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
[BeginAction("alignceilingtofront")] [BeginAction("alignceilingtofront")]
public void AlignCeilingToFront() public void AlignCeilingToFront()
{ {
if(!General.Map.UDMF) return;
AlignTextureToLine(false, true); AlignTextureToLine(false, true);
} }
@ -1593,7 +1651,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
[BeginAction("alignceilingtoback")] [BeginAction("alignceilingtoback")]
public void AlignCeilingToBack() public void AlignCeilingToBack()
{ {
if(!General.Map.UDMF) return;
AlignTextureToLine(false, false); AlignTextureToLine(false, false);
} }