Merge branch 'absolutez' into 'master'

Implement absolutez flag for things & support flip flag

See merge request STJr/UltimateZoneBuilder!9
This commit is contained in:
sphere 2023-06-10 17:29:58 +00:00
commit ec72f56992
7 changed files with 88 additions and 45 deletions

View file

@ -126,6 +126,7 @@ sectorflagscategories
thingflags_udmf
{
flip = "Flip";
absolutez = "Absolute Z height";
}
// Thing flags UDMF translation table
@ -137,6 +138,7 @@ thingflagstranslation
2 = "flip";
4 = "special";
8 = "ambush";
16 = "absolutez";
}
// DEFAULT SECTOR BRIGHTNESS LEVELS

View file

@ -87,14 +87,14 @@ namespace CodeImp.DoomBuilder.Controls
// Determine z info to show
t.DetermineSector();
string zinfo;
if(ti.AbsoluteZ || t.Sector == null)
if(ti.AbsoluteZ || t.AbsoluteZ || t.Sector == null)
{
zinfo = t.Position.z.ToString(CultureInfo.InvariantCulture) + " (abs.)"; //mxd
}
else
{
// Hangs from ceiling?
if(ti.Hangs)
// Hangs from ceiling? / Is flipped?
if(t.IsFlipped)
zinfo = t.Position.z + " (" + Math.Round(Sector.GetCeilingPlane(t.Sector).GetZ(t.Position) - t.Position.z - ti.Height, General.Map.FormatInterface.VertexDecimals).ToString(CultureInfo.InvariantCulture) + ")"; //mxd
else
zinfo = t.Position.z + " (" + Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position) + t.Position.z, General.Map.FormatInterface.VertexDecimals).ToString(CultureInfo.InvariantCulture) + ")"; //mxd

View file

@ -2164,7 +2164,7 @@ namespace CodeImp.DoomBuilder.Geometry
ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
int absz = GetThingAbsoluteZ(t, ti);
int height = ti.Height == 0 ? 1 : (int)ti.Height;
Rectangle thing = new Rectangle(0, ti.Hangs ? absz - height : absz, 1, height);
Rectangle thing = new Rectangle(0, t.IsFlipped ? absz - height : absz, 1, height);
if(front.FloorHeight < back.FloorHeight)
{
@ -2213,9 +2213,9 @@ namespace CodeImp.DoomBuilder.Geometry
if(initialSector != t.Sector && General.Map.FormatInterface.HasThingHeight)
{
ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
if(ti.AbsoluteZ) return;
if(ti.AbsoluteZ || t.AbsoluteZ) return;
if(ti.Hangs && initialSector.CeilHeight != t.Sector.CeilHeight)
if(t.IsFlipped && initialSector.CeilHeight != t.Sector.CeilHeight)
{
t.Move(t.Position.x, t.Position.y, t.Position.z - (initialSector.CeilHeight - t.Sector.CeilHeight));
return;
@ -2229,12 +2229,12 @@ namespace CodeImp.DoomBuilder.Geometry
public static int GetThingAbsoluteZ(Thing t, ThingTypeInfo ti)
{
// Determine z info
if(ti.AbsoluteZ) return (int)t.Position.z;
if(ti.AbsoluteZ || t.AbsoluteZ) return (int)t.Position.z;
if(t.Sector != null)
{
// Hangs from ceiling?
if(ti.Hangs) return (int)(t.Sector.CeilHeight - t.Position.z - ti.Height);
// Hangs from ceiling? / is flipped?
if(t.IsFlipped) return (int)(t.Sector.CeilHeight - t.Position.z - ti.Height);
return (int)(t.Sector.FloorHeight + t.Position.z);
}

View file

@ -124,13 +124,23 @@ namespace CodeImp.DoomBuilder.Map
public bool IsDirectional { get { return directional; } } //mxd
public bool Highlighted { get { return highlighted; } set { highlighted = value; } } //mxd
internal int LastProcessed { get { return lastProcessed; } set { lastProcessed = value; } }
public bool Flip { get { return General.Map.UDMF && IsFlagSet("flip"); } }
public bool AbsoluteZ { get { return General.Map.UDMF && IsFlagSet("absolutez"); } }
public bool IsFlipped
{
get
{
ThingTypeInfo ti = General.Map.Data.GetThingInfo(Type);
return ti.Hangs ^ Flip;
}
}
#endregion
#endregion
#region ================== Constructor / Disposer
#region ================== Constructor / Disposer
// Constructor
internal Thing(MapSet map, int listindex, bool recordundo = true)
// Constructor
internal Thing(MapSet map, int listindex, bool recordundo = true)
{
// Initialize
this.elementtype = MapElementType.THING; //mxd

View file

@ -173,14 +173,15 @@ namespace CodeImp.DoomBuilder.Windows
// Coordination
angle.Text = ft.AngleDoom.ToString();
cbAbsoluteHeight.Checked = useabsoluteheight; //mxd
cbAbsoluteHeight.Checked = useabsoluteheight || ft.AbsoluteZ; //mxd
cbAbsoluteHeight.Enabled = !ft.AbsoluteZ;
//mxd
ft.DetermineSector();
double floorheight = (ft.Sector != null ? Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position) : 0);
posX.Text = (ft.Position.x).ToString();
posY.Text = (ft.Position.y).ToString();
posZ.Text = (useabsoluteheight ? (Math.Round(ft.Position.z + floorheight, General.Map.FormatInterface.VertexDecimals)).ToString() : (ft.Position.z).ToString());
posZ.Text = ((useabsoluteheight && !ft.AbsoluteZ) ? (Math.Round(ft.Position.z + floorheight, General.Map.FormatInterface.VertexDecimals)).ToString() : (ft.Position.z).ToString());
posX.ButtonStep = General.Map.Grid.GridSize;
posY.ButtonStep = General.Map.Grid.GridSize;
posZ.ButtonStep = General.Map.Grid.GridSize;
@ -249,7 +250,7 @@ namespace CodeImp.DoomBuilder.Windows
//mxd. Position
if((t.Position.x).ToString() != posX.Text) posX.Text = "";
if((t.Position.y).ToString() != posY.Text) posY.Text = "";
if(useabsoluteheight && t.Sector != null)
if(useabsoluteheight && !t.AbsoluteZ && t.Sector != null)
{
if((Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position) + t.Position.z, General.Map.FormatInterface.VertexDecimals)).ToString() != posZ.Text)
posZ.Text = "";
@ -547,13 +548,13 @@ namespace CodeImp.DoomBuilder.Windows
//update label text
Thing ft = General.GetByIndex(things, 0);
double z = ft.Position.z;
if(useabsoluteheight && ft.Sector != null) z += Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position);
if(useabsoluteheight && !ft.AbsoluteZ && ft.Sector != null) z += Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position);
posZ.Text = Math.Round(z, General.Map.FormatInterface.VertexDecimals).ToString();
foreach(Thing t in things)
{
z = t.Position.z;
if(useabsoluteheight && t.Sector != null) z += Sector.GetFloorPlane(t.Sector).GetZ(t.Position);
if(useabsoluteheight && !ft.AbsoluteZ && t.Sector != null) z += Sector.GetFloorPlane(t.Sector).GetZ(t.Position);
string ztext = Math.Round(z, General.Map.FormatInterface.VertexDecimals).ToString();
if(posZ.Text != ztext)
{
@ -656,7 +657,7 @@ namespace CodeImp.DoomBuilder.Windows
foreach(Thing t in things)
{
double z = posZ.GetResultFloat(thingprops[i++].Z);
if(useabsoluteheight && !posZ.CheckIsRelative() && t.Sector != null)
if(useabsoluteheight && !t.AbsoluteZ && !posZ.CheckIsRelative() && t.Sector != null)
z -= Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position.x, t.Position.y), General.Map.FormatInterface.VertexDecimals);
t.Move(new Vector3D(t.Position.x, t.Position.y, z));
}
@ -839,6 +840,31 @@ namespace CodeImp.DoomBuilder.Windows
return;
}
preventchanges = true;
// Update Z height, in case AbsoluteZ flag changed
Thing ft = General.GetByIndex(things, 0);
double z = ft.Position.z;
if (useabsoluteheight && !ft.AbsoluteZ && ft.Sector != null) z += Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position);
posZ.Text = Math.Round(z, General.Map.FormatInterface.VertexDecimals).ToString();
foreach (Thing t in things)
{
z = t.Position.z;
if (useabsoluteheight && !ft.AbsoluteZ && t.Sector != null) z += Sector.GetFloorPlane(t.Sector).GetZ(t.Position);
string ztext = Math.Round(z, General.Map.FormatInterface.VertexDecimals).ToString();
if (posZ.Text != ztext)
{
posZ.Text = "";
break;
}
}
cbAbsoluteHeight.Checked = useabsoluteheight || ft.AbsoluteZ; //mxd
cbAbsoluteHeight.Enabled = !ft.AbsoluteZ;
preventchanges = false;
// Everything is OK
missingflags.Visible = false;
settingsgroup.ForeColor = SystemColors.ControlText;
@ -873,6 +899,5 @@ namespace CodeImp.DoomBuilder.Windows
{
}
}
}

View file

@ -354,8 +354,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
Vector3D pos = thing.Thing.Position;
double thingheight = thing.Thing.Height;
bool absolute = thing.Info.AbsoluteZ;
bool hangs = thing.Info.Hangs;
bool absolute = thing.Info.AbsoluteZ || thing.Thing.AbsoluteZ;
bool hangs = thing.Thing.IsFlipped;
if(absolute && hangs)
{
@ -450,8 +450,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
{
Vector3D pos = thing.Thing.Position;
double thingheight = thing.Thing.Height;
bool absolute = thing.Info.AbsoluteZ;
bool hangs = thing.Info.Hangs;
bool absolute = thing.Info.AbsoluteZ || thing.Thing.AbsoluteZ; ;
bool hangs = thing.Thing.IsFlipped;
if(absolute && hangs)
{
@ -576,15 +576,15 @@ namespace CodeImp.DoomBuilder.BuilderModes
ThingTypeInfo info = General.Map.Data.GetThingInfoEx(t.Type);
if(info != null)
{
if(info.AbsoluteZ && info.Hangs) return t.Position.z; // Not sure what to do here...
if(info.AbsoluteZ)
if(info.AbsoluteZ && t.IsFlipped) return t.Position.z; // Not sure what to do here...
if(info.AbsoluteZ || t.AbsoluteZ)
{
// Transform to floor-aligned position
SectorData nsd = mode.GetSectorData(t.Sector);
return t.Position.z - nsd.Floor.plane.GetZ(t.Position) + t.Height;
}
if(info.Hangs)
if(t.IsFlipped)
{
// Transform to floor-aligned position. Align top of target thing to the bottom of the hanging thing
SectorData nsd = mode.GetSectorData(t.Sector);

View file

@ -216,7 +216,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(!info.Bright)
{
Vector3D thingpos = new Vector3D(Thing.Position.x, Thing.Position.y, Thing.Position.z + sd.Floor.plane.GetZ(Thing.Position));
double thingz = Thing.IsFlipped ? sd.Ceiling.plane.GetZ(Thing.Position) - Thing.Position.z - Thing.Height : Thing.Position.z + sd.Floor.plane.GetZ(Thing.Position);
Vector3D thingpos = new Vector3D(Thing.Position.x, Thing.Position.y, thingz);
SectorLevel level = sd.GetLevelAboveOrAt(thingpos);
//mxd. Let's use point on floor plane instead of Thing.Sector.FloorHeight;
@ -290,7 +291,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
//TECH: even Bright Thing frames are affected by custom fade...
else
{
Vector3D thingpos = new Vector3D(Thing.Position.x, Thing.Position.y, Thing.Position.z + sd.Floor.plane.GetZ(Thing.Position));
double thingz = Thing.IsFlipped ? sd.Ceiling.plane.GetZ(Thing.Position) - Thing.Position.z - Thing.Height : Thing.Position.z + sd.Floor.plane.GetZ(Thing.Position);
Vector3D thingpos = new Vector3D(Thing.Position.x, Thing.Position.y, thingz);
SectorLevel level = sd.GetLevelAboveOrAt(thingpos);
if(level != null && level.sector.FogMode > SectorFogMode.CLASSIC)
@ -342,35 +344,37 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd. Sprite mirroring
float ul = (info.SpriteFrame[i].Mirror ? 1f : 0f);
float ur = (info.SpriteFrame[i].Mirror ? 0f : 1f);
float vb = (Thing.Flip ? 1f : 0f);
float vt = (Thing.Flip ? 0f : 1f);
if(sizeless) //mxd
{
float hh = height / 2;
verts[0] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)(offsets.y - hh), sectorcolor, ul, 1.0f);
verts[1] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)(hh + offsets.y), sectorcolor, ul, 0.0f);
verts[2] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)(hh + offsets.y), sectorcolor, ur, 0.0f);
verts[0] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)(offsets.y - hh), sectorcolor, ul, vt);
verts[1] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)(hh + offsets.y), sectorcolor, ul, vb);
verts[2] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)(hh + offsets.y), sectorcolor, ur, vb);
verts[3] = verts[0];
verts[4] = verts[2];
verts[5] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)(offsets.y - hh), sectorcolor, ur, 1.0f);
verts[5] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)(offsets.y - hh), sectorcolor, ur, vt);
}
else if (info.CenterHitbox)
{
float hh = height / 2;
verts[0] = new WorldVertex((float)(-radius + offsets.x), 0.0f, -hh, sectorcolor, 0.0f, 1.0f);
verts[1] = new WorldVertex((float)(-radius + offsets.x), 0.0f, hh, sectorcolor, 0.0f, 0.0f);
verts[2] = new WorldVertex((float)(+radius + offsets.x), 0.0f, hh, sectorcolor, 1.0f, 0.0f);
verts[0] = new WorldVertex((float)(-radius + offsets.x), 0.0f, -hh, sectorcolor, 0.0f, vt);
verts[1] = new WorldVertex((float)(-radius + offsets.x), 0.0f, hh, sectorcolor, 0.0f, vb);
verts[2] = new WorldVertex((float)(+radius + offsets.x), 0.0f, hh, sectorcolor, 1.0f, vb);
verts[3] = verts[0];
verts[4] = verts[2];
verts[5] = new WorldVertex((float)(+radius + offsets.x), 0.0f, -hh, sectorcolor, 1.0f, 1.0f);
verts[5] = new WorldVertex((float)(+radius + offsets.x), 0.0f, -hh, sectorcolor, 1.0f, vt);
}
else
{
verts[0] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)offsets.y, sectorcolor, ul, 1.0f);
verts[1] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)(height + offsets.y), sectorcolor, ul, 0.0f);
verts[2] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)(height + offsets.y), sectorcolor, ur, 0.0f);
verts[0] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)offsets.y, sectorcolor, ul, vt);
verts[1] = new WorldVertex((float)(-radius + offsets.x), 0.0f, (float)(height + offsets.y), sectorcolor, ul, vb);
verts[2] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)(height + offsets.y), sectorcolor, ur, vb);
verts[3] = verts[0];
verts[4] = verts[2];
verts[5] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)offsets.y, sectorcolor, ur, 1.0f);
verts[5] = new WorldVertex((float)(+radius + offsets.x), 0.0f, (float)offsets.y, sectorcolor, ur, vt);
}
allverts[i] = verts;
}
@ -434,12 +438,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
pos.z = (Thing.Args[0] == 0) ? sd.Floor.sector.FloorHeight + Thing.Position.z : Thing.Position.z;
}
}
else if(info.AbsoluteZ)
else if(info.AbsoluteZ || Thing.AbsoluteZ)
{
// Absolute Z position
pos.z = Thing.Position.z;
}
else if(info.Hangs)
else if(Thing.IsFlipped) // info.Hangs
{
// Hang from ceiling
if(Thing.Sector != null)
@ -478,6 +482,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
//if (info.ZOffset != 0) pos.z += Thing.IsFlipped ? -info.ZOffset : info.ZOffset;
// Apply settings
SetPosition(pos);
SetCageColor(Thing.Color);
@ -817,7 +823,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
if((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket))
undoticket = mode.CreateUndo("Change thing height");
Thing.Move(Thing.Position + new Vector3D(0.0f, 0.0f, (info.Hangs ? -amount : amount)));
Thing.Move(Thing.Position + new Vector3D(0.0f, 0.0f, (Thing.IsFlipped ? -amount : amount)));
mode.SetActionResult("Changed thing height to " + Thing.Position.z + ".");