Allow changing sector texture offsets, if the sector has tagless flat alignment.

This commit is contained in:
sphere 2021-06-05 01:36:37 +02:00
parent 738fcfe2c3
commit cde434af8c
3 changed files with 143 additions and 19 deletions

View file

@ -446,7 +446,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd
protected void ClearFields(IEnumerable<string> keys, string undodescription, string resultdescription)
{
if(!General.Map.UDMF) return;
if(!General.Map.UDMF && !General.Map.SRB2) return;
mode.CreateUndo(undodescription);
mode.SetActionResult(resultdescription);
@ -902,7 +902,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(horizontal == 0 && vertical == 0) return; //mxd
//mxd
if(!General.Map.UDMF)
if(!General.Map.UDMF && !General.Map.SRB2)
{
General.Interface.DisplayStatus(StatusType.Warning, "Floor/ceiling texture offsets cannot be changed in this map format!");
return;
@ -912,7 +912,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
undoticket = mode.CreateUndo("Change texture offsets");
//mxd
if(doSurfaceAngleCorrection)
if(General.Map.UDMF && doSurfaceAngleCorrection)
{
Point p = new Point(horizontal, vertical);
float angle = Angle2D.RadToDeg(General.Map.VisualCamera.AngleXY);

View file

@ -237,6 +237,47 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd
Sector s = GetControlSector();
s.Fields.BeforeFieldsChange();
if (General.Map.SRB2)
{
Linedef alignment = null;
foreach (Sidedef side in s.Sidedefs)
if (side.Line.IsFlatAlignment && side.Line.Tag == 0 && side.Sector == s) alignment = side.Line;
if (alignment == null)
{
mode.SetActionResult("Sector has no flat alignment line!");
return;
}
else
{
if (alignment.IsFlagSet("4096"))
alignment.SetFlag("4096", false);
if (!alignment.IsFlagSet("8192"))
alignment.SetFlag("8192", true);
alignment.Front.OffsetX += xy.X;
alignment.Front.OffsetY += xy.Y;
float rotation = General.ClampAngle(90f - alignment.Angle * Angle2D.PIDEG);
float rotationrad = rotation / Angle2D.PIDEG;
float rx = (float)Math.Cos(rotationrad) * alignment.Front.OffsetX - (float)Math.Sin(rotationrad) * -alignment.Front.OffsetY;
float ry = (float)Math.Sin(rotationrad) * alignment.Front.OffsetX + (float)Math.Cos(rotationrad) * -alignment.Front.OffsetY;
if (s.Fields.ContainsKey("xpanningceiling")) s.Fields["xpanningceiling"] = new UniValue(UniversalType.Float, rx);
else s.Fields.Add("xpanningceiling", new UniValue(UniversalType.Float, rx));
if (s.Fields.ContainsKey("ypanningceiling")) s.Fields["ypanningceiling"] = new UniValue(UniversalType.Float, -ry);
else s.Fields.Add("ypanningceiling", new UniValue(UniversalType.Float, -ry));
if (s.Fields.ContainsKey("rotationfloor")) s.Fields["rotationfloor"] = new UniValue(UniversalType.Float, rotation);
else s.Fields.Add("rotationfloor", new UniValue(UniversalType.Float, rotation));
if (s.Fields.ContainsKey("rotationceiling")) s.Fields["rotationceiling"] = new UniValue(UniversalType.Float, rotation);
else s.Fields.Add("rotationceiling", new UniValue(UniversalType.Float, rotation));
s.UpdateNeeded = true;
mode.SetActionResult("Changed ceiling texture offsets to " + alignment.Front.OffsetX + ", " + alignment.Front.OffsetY + ".");
}
}
else
{
float nx = (s.Fields.GetValue("xpanningceiling", 0.0f) + xy.X) % (Texture.ScaledWidth / s.Fields.GetValue("xscaleceiling", 1.0f));
float ny = (s.Fields.GetValue("ypanningceiling", 0.0f) + xy.Y) % (Texture.ScaledHeight / s.Fields.GetValue("yscaleceiling", 1.0f));
s.Fields["xpanningceiling"] = new UniValue(UniversalType.Float, nx);
@ -245,6 +286,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
mode.SetActionResult("Changed ceiling texture offsets to " + nx + ", " + ny + ".");
}
}
//mxd. Texture scale change
protected override void ChangeTextureScale(int incrementX, int incrementY)
@ -288,6 +330,27 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd
public override void OnResetTextureOffset()
{
if (General.Map.SRB2)
{
Sector s = GetControlSector();
foreach (Sidedef side in s.Sidedefs)
if (side.Line.IsFlatAlignment && side.Line.Tag == 0 && side.Sector == s && side.Line.IsFlagSet("8192"))
{
float rotation = General.ClampAngle(90f - side.Angle * Angle2D.PIDEG);
if (s.Fields.ContainsKey("rotationfloor")) s.Fields["rotationfloor"] = new UniValue(UniversalType.Float, rotation);
else s.Fields.Add("rotationfloor", new UniValue(UniversalType.Float, rotation));
if (s.Fields.ContainsKey("rotationceiling")) s.Fields["rotationceiling"] = new UniValue(UniversalType.Float, rotation);
else s.Fields.Add("rotationceiling", new UniValue(UniversalType.Float, rotation));
side.Line.Front.OffsetX = side.Line.Front.OffsetY = 0;
ClearFields(new[] { "xpanningfloor", "ypanningfloor", "xpanningceiling", "ypanningceiling" },
"Reset texture offsets", "Texture offsets reset.");
return;
}
}
else
ClearFields(new[] { "xpanningceiling", "ypanningceiling" }, "Reset texture offsets", "Texture offsets reset.");
}

View file

@ -225,6 +225,45 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd
Sector s = GetControlSector();
s.Fields.BeforeFieldsChange();
if (General.Map.SRB2)
{
Linedef alignment = null;
foreach (Sidedef side in s.Sidedefs)
if (side.Line.IsFlatAlignment && side.Line.Tag == 0 && side.Sector == s) alignment = side.Line;
if (alignment == null)
{
mode.SetActionResult("Sector has no flat alignment line!");
return;
}
else
{
if (alignment.IsFlagSet("2048"))
alignment.SetFlag("2048", false);
if (!alignment.IsFlagSet("8192"))
alignment.SetFlag("8192", true);
alignment.Front.OffsetX += xy.X;
alignment.Front.OffsetY += xy.Y;
float rotation = General.ClampAngle(90f - alignment.Angle * Angle2D.PIDEG);
float rotationrad = rotation / Angle2D.PIDEG;
float rx = (float)Math.Cos(rotationrad) * alignment.Front.OffsetX - (float)Math.Sin(rotationrad) * -alignment.Front.OffsetY;
float ry = (float)Math.Sin(rotationrad) * alignment.Front.OffsetX + (float)Math.Cos(rotationrad) * -alignment.Front.OffsetY;
if (s.Fields.ContainsKey("xpanningfloor")) s.Fields["xpanningfloor"] = new UniValue(UniversalType.Float, rx);
else s.Fields.Add("xpanningfloor", new UniValue(UniversalType.Float, rx));
if (s.Fields.ContainsKey("ypanningfloor")) s.Fields["ypanningfloor"] = new UniValue(UniversalType.Float, -ry);
else s.Fields.Add("ypanningfloor", new UniValue(UniversalType.Float, -ry));
if (s.Fields.ContainsKey("rotationfloor")) s.Fields["rotationfloor"] = new UniValue(UniversalType.Float, rotation);
else s.Fields.Add("rotationfloor", new UniValue(UniversalType.Float, rotation));
s.UpdateNeeded = true;
mode.SetActionResult("Changed floor texture offsets to " + alignment.Front.OffsetX + ", " + alignment.Front.OffsetY + ".");
}
}
else
{
float nx = (s.Fields.GetValue("xpanningfloor", 0.0f) + xy.X) % (Texture.ScaledWidth / s.Fields.GetValue("xscalefloor", 1.0f));
float ny = (s.Fields.GetValue("ypanningfloor", 0.0f) + xy.Y) % (Texture.ScaledHeight / s.Fields.GetValue("yscalefloor", 1.0f));
s.Fields["xpanningfloor"] = new UniValue(UniversalType.Float, nx);
@ -233,6 +272,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
mode.SetActionResult("Changed floor texture offsets to " + nx + ", " + ny + ".");
}
}
//mxd. Texture scale change
protected override void ChangeTextureScale(int incrementX, int incrementY)
@ -276,6 +316,27 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd
public override void OnResetTextureOffset()
{
if (General.Map.SRB2)
{
Sector s = GetControlSector();
foreach (Sidedef side in s.Sidedefs)
if (side.Line.IsFlatAlignment && side.Line.Tag == 0 && side.Sector == s && side.Line.IsFlagSet("8192"))
{
float rotation = General.ClampAngle(90f - side.Angle * Angle2D.PIDEG);
if (s.Fields.ContainsKey("rotationfloor")) s.Fields["rotationfloor"] = new UniValue(UniversalType.Float, rotation);
else s.Fields.Add("rotationfloor", new UniValue(UniversalType.Float, rotation));
if (s.Fields.ContainsKey("rotationceiling")) s.Fields["rotationceiling"] = new UniValue(UniversalType.Float, rotation);
else s.Fields.Add("rotationceiling", new UniValue(UniversalType.Float, rotation));
side.Line.Front.OffsetX = side.Line.Front.OffsetY = 0;
ClearFields(new[] { "xpanningfloor", "ypanningfloor", "xpanningceiling", "ypanningceiling" },
"Reset texture offsets", "Texture offsets reset.");
return;
}
}
else
ClearFields(new[] { "xpanningfloor", "ypanningfloor" }, "Reset texture offsets", "Texture offsets reset.");
}