Skip to content

Commit

Permalink
UIList, BandList
Browse files Browse the repository at this point in the history
  • Loading branch information
ihatecompvir committed Jan 12, 2025
1 parent c577b58 commit bb73816
Show file tree
Hide file tree
Showing 5 changed files with 465 additions and 1 deletion.
180 changes: 180 additions & 0 deletions MiloLib/Assets/Band/UI/BandList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using MiloLib.Assets.UI;
using MiloLib.Classes;
using MiloLib.Utils;

namespace MiloLib.Assets.Band.UI
{
[Name("BandList"), Description("Band specific UIList")]
public class BandList : UIList
{
public class HighlightObjects
{
[Name("Target Object"), Description("The object to attach to the highlight")]
public Symbol targetObject = new(0, "");
[Name("X Offset"), Description("x offset from list position")]
public float xOffset;
[Name("Y Offset"), Description("y offset from list position")]
public float yOffset;
[Name("Z Offset"), Description("z offset from list position")]
public float zOffset;

public HighlightObjects Read(EndianReader reader)
{
targetObject = Symbol.Read(reader);
xOffset = reader.ReadFloat();
yOffset = reader.ReadFloat();
zOffset = reader.ReadFloat();
return this;
}

public void Write(EndianWriter writer)
{
Symbol.Write(writer, targetObject);
writer.WriteFloat(xOffset);
writer.WriteFloat(yOffset);
writer.WriteFloat(zOffset);
}
}
private ushort altRevision;
private ushort revision;

[Name("Focus Anim"), Description("Animation to play on a selected entry to transition into and out of focus")]
public Symbol focusAnim = new(0, "");
[Name("Pulse Anim"), Description("Animation to play on a selected entry after focus is played - focus anim must exist")]
public Symbol pulseAnim = new(0, "");

[Name("Reveal Anim"), Description("animation to play on each entry when list is revealed")]
public Symbol revealAnim = new(0, "");
[Name("Conceal Anim"), Description("animation to play on each entry when list is concealed")]
public Symbol concealAnim = new(0, "");
[Name("Reveal Sound"), Description("sound to play on each entry when list is revealed")]
public Symbol revealSound = new(0, "");
[Name("Conceal Sound"), Description("sound to play on each entry when list is concealed")]
public Symbol concealSound = new(0, "");

[Name("Reveal Sound Delay"), Description("delay for sound to play on each entry when list is revealed")]
public float revealSoundDelay;
[Name("Conceal Sound Delay"), Description("delay for sound to play on each entry when list is concealed")]
public float concealSoundDelay;
[Name("Reveal Start Delay"), Description("delay before playing reveal animation")]
public float revealStartDelay;
[Name("Reveal Entry Delay"), Description("delay between list entries playing reveal animation")]
public float revealEntryDelay;
[Name("Reveal Scale"), Description("amount to scale reveal animation")]
public float revealScale;
[Name("Conceal Start Delay"), Description("delay before playing conceal animation")]
public float concealStartDelay;
[Name("Conceal Entry Delay"), Description("delay between list entries playing conceal animation")]
public float concealEntryDelay;
[Name("Conceal Scale"), Description("amount to scale conceal animation")]
public float concealScale;
[Name("Auto Reveal"), Description("Whether or not to start revealed")]
public bool autoReveal;

private uint highlightObjectsCount;
public List<HighlightObjects> highlightObjects = new();

public BandList Read(EndianReader reader, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry entry)
{
uint combinedRevision = reader.ReadUInt32();
if (BitConverter.IsLittleEndian) (revision, altRevision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF));
else (altRevision, revision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF));

base.Read(reader, false, parent, entry);

if (revision >= 0x12)
{
focusAnim = Symbol.Read(reader);
pulseAnim = Symbol.Read(reader);
}

if (revision >= 0x13)
{
revealAnim = Symbol.Read(reader);
revealStartDelay = reader.ReadFloat();
revealEntryDelay = reader.ReadFloat();
concealAnim = Symbol.Read(reader);
concealStartDelay = reader.ReadFloat();
concealEntryDelay = reader.ReadFloat();
}
if (revision >= 0x14)
{
revealScale = reader.ReadFloat();
concealScale = reader.ReadFloat();
autoReveal = reader.ReadBoolean();
}

if (revision >= 0x15)
{
revealSound = Symbol.Read(reader);
concealSound = Symbol.Read(reader);
revealSoundDelay = reader.ReadFloat();
concealSoundDelay = reader.ReadFloat();
}
if (revision >= 0x16)
{
highlightObjectsCount = reader.ReadUInt32();
for (int i = 0; i < highlightObjectsCount; i++)
{
highlightObjects.Add(new HighlightObjects().Read(reader));
}
}

if (standalone)
if ((reader.Endianness == Endian.BigEndian ? 0xADDEADDE : 0xDEADDEAD) != reader.ReadUInt32()) throw new Exception("Got to end of standalone asset but didn't find the expected end bytes, read likely did not succeed");

return this;
}

public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false, parent, entry);

if (revision >= 0x12)
{
Symbol.Write(writer, focusAnim);
Symbol.Write(writer, pulseAnim);
}

if (revision >= 0x13)
{
Symbol.Write(writer, revealAnim);
writer.WriteFloat(revealStartDelay);
writer.WriteFloat(revealEntryDelay);
Symbol.Write(writer, concealAnim);
writer.WriteFloat(concealStartDelay);
writer.WriteFloat(concealEntryDelay);
}

if (revision >= 0x14)
{
writer.WriteFloat(revealScale);
writer.WriteFloat(concealScale);
writer.WriteBoolean(autoReveal);
}

if (revision >= 0x15)
{
Symbol.Write(writer, revealSound);
Symbol.Write(writer, concealSound);
writer.WriteFloat(revealSoundDelay);
writer.WriteFloat(concealSoundDelay);
}

if (revision >= 0x16)
{
writer.WriteUInt32((uint)highlightObjects.Count);
foreach (var highlightObject in highlightObjects)
{
highlightObject.Write(writer);
}
}

if (standalone)
writer.WriteBlock(new byte[4] { 0xAD, 0xDE, 0xAD, 0xDE });
}

}
}
21 changes: 21 additions & 0 deletions MiloLib/Assets/DirectoryMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,10 @@ public void ReadEntry(EndianReader reader, DirectoryMeta.Entry entry)
Debug.WriteLine("Reading entry BandLabel " + entry.name.value);
entry.obj = new BandLabel().Read(reader, true, this, entry);
break;
case "BandList":
Debug.WriteLine("Reading entry BandList " + entry.name.value);
entry.obj = new BandList().Read(reader, true, this, entry);
break;
case "BandPlacer":
Debug.WriteLine("Reading entry BandPlacer " + entry.name.value);
entry.obj = new BandPlacer().Read(reader, true, this, entry);
Expand Down Expand Up @@ -1060,6 +1064,14 @@ public void ReadEntry(EndianReader reader, DirectoryMeta.Entry entry)
Debug.WriteLine("Reading entry UIGuide " + entry.name.value);
entry.obj = new UIGuide().Read(reader, true, this, entry);
break;
case "UILabel":
Debug.WriteLine("Reading entry UILabel " + entry.name.value);
entry.obj = new UILabel().Read(reader, true, this, entry);
break;
case "UIList":
Debug.WriteLine("Reading entry UIList " + entry.name.value);
entry.obj = new UIList().Read(reader, true, this, entry);
break;
case "Wind":
Debug.WriteLine("Reading entry Wind " + entry.name.value);
entry.obj = new RndWind().Read(reader, true, this, entry);
Expand Down Expand Up @@ -1322,6 +1334,9 @@ public void WriteEntry(EndianWriter writer, DirectoryMeta.Entry entry)
case "BandLabel":
((BandLabel)entry.obj).Write(writer, true, this, entry);
break;
case "BandList":
((BandList)entry.obj).Write(writer, true, this, entry);
break;
case "BandPlacer":
((BandPlacer)entry.obj).Write(writer, true, this, entry);
break;
Expand Down Expand Up @@ -1454,6 +1469,12 @@ public void WriteEntry(EndianWriter writer, DirectoryMeta.Entry entry)
case "UIGuide":
((UIGuide)entry.obj).Write(writer, true, this, entry);
break;
case "UILabel":
((UILabel)entry.obj).Write(writer, true, this, entry);
break;
case "UIList":
((UIList)entry.obj).Write(writer, true, this, entry);
break;
case "Wind":
((RndWind)entry.obj).Write(writer, true, this, entry);
break;
Expand Down
2 changes: 2 additions & 0 deletions MiloLib/Assets/Rnd/RndMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public void Write(EndianWriter writer, uint meshVersion)
}
}

// TODO:
// these read and write vertex functions are genuinely horrible. need to refactor these in the future so converting between Mesh versions can be done more reliably
public void ReadVertices(EndianReader reader, uint meshVersion, bool isNextGen, uint compressionType)
{
vertices = new();
Expand Down
4 changes: 3 additions & 1 deletion MiloLib/Assets/UI/UIComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class UIComponent : Object
public RndTrans trans = new();
public RndDrawable draw = new();

[Name("Nav Right"), Description("Object to navigate to when the right button is pressed"), MinVersion(1)]
public Symbol navRight = new(0, "");
[Name("Nav Down"), Description("Object to navigate to when the down button is pressed"), MinVersion(1)]
public Symbol navDown = new(0, "");
[Name("Resource Name"), Description("path to resource file for this component")]
[Name("Resource Name"), Description("path to resource file for this component"), MinVersion(2)]
public Symbol resourceName = new(0, "");


Expand Down
Loading

0 comments on commit bb73816

Please sign in to comment.