diff --git a/File_Format_Library/FileFormats/Layout/CAFE/Header.cs b/File_Format_Library/FileFormats/Layout/CAFE/Header.cs index b5c3ee5d..2597e476 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/Header.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/Header.cs @@ -450,8 +450,16 @@ namespace LayoutBXLYT.Cafe public void Write(FileWriter writer) { + RecalculateMaterialReferences(); + 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.WriteSignature(Magic); if (!IsBigEndian) diff --git a/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs b/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs index c8982567..fa7dd9cc 100644 --- a/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs @@ -479,6 +479,8 @@ namespace LayoutBXLYT public void Write(FileWriter writer) { + RecalculateMaterialReferences(); + Version = VersionMajor << 24 | VersionMinor << 16 | VersionMicro << 8 | VersionMicro2; writer.SetByteOrder(true); diff --git a/File_Format_Library/FileFormats/Layout/Common.cs b/File_Format_Library/FileFormats/Layout/Common.cs index 6e5917e8..0045066e 100644 --- a/File_Format_Library/FileFormats/Layout/Common.cs +++ b/File_Format_Library/FileFormats/Layout/Common.cs @@ -2285,6 +2285,24 @@ namespace LayoutBXLYT return new BxlytMaterial(); } + public void RecalculateMaterialReferences() + { + List 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) { foreach (var mat in Materials)