BXLYT : Recalculate material indices automatically on save.

This commit is contained in:
KillzXGaming 2020-09-20 14:05:28 -04:00
parent 3126bef310
commit e39e6f7d03
3 changed files with 28 additions and 0 deletions

View file

@ -450,8 +450,16 @@ namespace LayoutBXLYT.Cafe
public void Write(FileWriter writer) public void Write(FileWriter writer)
{ {
RecalculateMaterialReferences();
Version = VersionMajor << 24 | VersionMinor << 16 | VersionMicro << 8 | VersionMicro2; Version = VersionMajor << 24 | VersionMinor << 16 | VersionMicro << 8 | VersionMicro2;
foreach (var pane in PaneLookup.Values)
{
if (pane is PIC1)
((PIC1)pane).MaterialIndex = (ushort)MaterialList.Materials.IndexOf(((PIC1)pane).Material);
}
writer.SetByteOrder(true); writer.SetByteOrder(true);
writer.WriteSignature(Magic); writer.WriteSignature(Magic);
if (!IsBigEndian) if (!IsBigEndian)

View file

@ -479,6 +479,8 @@ namespace LayoutBXLYT
public void Write(FileWriter writer) public void Write(FileWriter writer)
{ {
RecalculateMaterialReferences();
Version = VersionMajor << 24 | VersionMinor << 16 | VersionMicro << 8 | VersionMicro2; Version = VersionMajor << 24 | VersionMinor << 16 | VersionMicro << 8 | VersionMicro2;
writer.SetByteOrder(true); writer.SetByteOrder(true);

View file

@ -2285,6 +2285,24 @@ namespace LayoutBXLYT
return new BxlytMaterial(); return new BxlytMaterial();
} }
public void RecalculateMaterialReferences()
{
List<BxlytMaterial> materials = Materials;
foreach (var pane in PaneLookup.Values)
{
if (pane is IPicturePane)
((IPicturePane)pane).MaterialIndex = (ushort)materials.IndexOf(((IPicturePane)pane).Material);
if (pane is IWindowPane)
{
((IWindowPane)pane).Content.MaterialIndex = (ushort)materials.IndexOf(((IWindowPane)pane).Content.Material);
foreach (var window in ((IWindowPane)pane).WindowFrames)
window.MaterialIndex = (ushort)materials.IndexOf(window.Material);
}
if (pane is ITextPane)
((ITextPane)pane).MaterialIndex = (ushort)materials.IndexOf(((ITextPane)pane).Material);
}
}
public void RemoveTextureReferences(string texture) public void RemoveTextureReferences(string texture)
{ {
foreach (var mat in Materials) foreach (var mat in Materials)