diff --git a/File_Format_Library/FileFormats/HyruleWarriors/HWBinGzResource.cs b/File_Format_Library/FileFormats/HyruleWarriors/HWBinGzResource.cs index 53e6ab02..66479c57 100644 --- a/File_Format_Library/FileFormats/HyruleWarriors/HWBinGzResource.cs +++ b/File_Format_Library/FileFormats/HyruleWarriors/HWBinGzResource.cs @@ -109,7 +109,6 @@ namespace FirstPlugin public void Load(Stream stream) { stream = CheckCompression(stream); - stream.ExportToFile(FilePath + ".dec"); using (var reader = new FileReader(stream)) { diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs index 49bd520e..2b038d3f 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs @@ -73,7 +73,7 @@ namespace LayoutBXLYT.Cafe #region Text Converter Interface public TextFileType TextFileType => TextFileType.Xml; - public bool CanConvertBack => false; + public bool CanConvertBack => true; public string ConvertToString() { @@ -95,6 +95,8 @@ namespace LayoutBXLYT.Cafe public void ConvertFromString(string text) { + header = FLYT.FromXml(text); + header.FileInfo = this; } #endregion @@ -228,19 +230,24 @@ namespace LayoutBXLYT.Cafe public class Header : BxlytHeader, IDisposable { private const string Magic = "FLYT"; - private ushort ByteOrderMark; private ushort HeaderSize; + [Browsable(false)] public LYT1 LayoutInfo { get; set; } + [Browsable(false)] public TXL1 TextureList { get; set; } + [Browsable(false)] public MAT1 MaterialList { get; set; } + [Browsable(false)] public FNL1 FontList { get; set; } + [Browsable(false)] public CNT1 Container { get; set; } //As of now this should be empty but just for future proofing private List UnknownSections = new List(); + [Browsable(false)] public int TotalPaneCount() { int panes = GetPanes().Count; @@ -248,16 +255,19 @@ namespace LayoutBXLYT.Cafe return panes + grpPanes; } + [Browsable(false)] public override List Textures { get { return TextureList.Textures; } } + [Browsable(false)] public override Dictionary GetTextures { get { return ((BFLYT)FileInfo).GetTextures(); } } + [Browsable(false)] public List GetPanes() { List panes = new List(); @@ -265,6 +275,7 @@ namespace LayoutBXLYT.Cafe return panes; } + [Browsable(false)] public List GetGroupPanes() { List panes = new List(); @@ -286,7 +297,7 @@ namespace LayoutBXLYT.Cafe GetGroupChildren(panes, (GRP1)pane); } - public void Read(FileReader reader, BFLYT bflyt) + public Header() { LayoutInfo = new LYT1(); TextureList = new TXL1(); @@ -295,6 +306,20 @@ namespace LayoutBXLYT.Cafe RootPane = new PAN1(); RootGroup = new GRP1(); + VersionMajor = 8; + VersionMinor = 0; + VersionMicro = 0; + VersionMicro2 = 0; + } + + public void Read(FileReader reader, BFLYT bflyt) + { + LayoutInfo = new LYT1(); + TextureList = new TXL1(); + MaterialList = new MAT1(); + FontList = new FNL1(); + RootPane = new PAN1(); + RootGroup = new GRP1(); FileInfo = bflyt; reader.SetByteOrder(true); @@ -303,6 +328,7 @@ namespace LayoutBXLYT.Cafe reader.CheckByteOrderMark(ByteOrderMark); HeaderSize = reader.ReadUInt16(); Version = reader.ReadUInt32(); + SetVersionInfo(); uint FileSize = reader.ReadUInt32(); ushort sectionCount = reader.ReadUInt16(); reader.ReadUInt16(); //Padding @@ -1331,7 +1357,9 @@ namespace LayoutBXLYT.Cafe private BFLYT.Header ParentLayout; - public PIC1() : base() { + public PIC1(BFLYT.Header header) : base() { + ParentLayout = header; + ColorTopLeft = STColor8.White; ColorTopRight = STColor8.White; ColorBottomLeft = STColor8.White; @@ -1474,7 +1502,23 @@ namespace LayoutBXLYT.Cafe public PAN1() : base() { + Alpha = 255; + PaneMagFlags = 0; + Name = ""; + Translate = new Vector3F(0,0,0); + Rotate = new Vector3F(0,0,0); + Scale = new Vector2F(1,1); + Width = 0; + Height = 0; + UserDataInfo = ""; + UserData = new UserData(); + originX = OriginX.Center; + originY = OriginY.Center; + ParentOriginX = OriginX.Center; + ParentOriginY = OriginY.Center; + InfluenceAlpha = false; + Visible = true; } public PAN1(FileReader reader) : base() @@ -1637,6 +1681,9 @@ namespace LayoutBXLYT.Cafe ParentLayout = header; Name = reader.ReadString(0x1C).Replace("\0", string.Empty); + Name = Name.Replace("\x01", string.Empty); + Name = Name.Replace("\x04", string.Empty); + if (header.VersionMajor >= 8) { flags = reader.ReadUInt32(); diff --git a/File_Format_Library/FileFormats/Layout/Common.cs b/File_Format_Library/FileFormats/Layout/Common.cs index ad0e2be2..b0a39d59 100644 --- a/File_Format_Library/FileFormats/Layout/Common.cs +++ b/File_Format_Library/FileFormats/Layout/Common.cs @@ -235,55 +235,63 @@ namespace LayoutBXLYT public class BxlytHeader : IDisposable { + [Browsable(false)] public string FileName { get { return FileInfo.FileName; } } + [DisplayName("Use Big Endian"), CategoryAttribute("File Settings")] public bool IsBigEndian { get; set; } + [Browsable(false)] internal IFileFormat FileInfo; + [Browsable(false)] public BasePane RootPane { get; set; } + [Browsable(false)] public BasePane RootGroup { get; set; } + [Browsable(false)] public virtual Dictionary GetTextures { get; } + [Browsable(false)] public virtual List Textures { get; } + [Browsable(false)] internal uint Version; + [DisplayName("Version"), CategoryAttribute("File Settings")] public string VersionFull { get { - var major = Version >> 24; - var minor = Version >> 16 & 0xFF; - var micro = Version >> 8 & 0xFF; - var micro2 = Version & 0xFF; - return $"{major} {minor} {micro} {micro2}"; + return $"{VersionMajor},{VersionMinor},{VersionMicro},{VersionMicro2}"; } } - public uint VersionMajor + + [RefreshProperties(RefreshProperties.All)] + public uint VersionMajor { get; set; } + [RefreshProperties(RefreshProperties.All)] + public uint VersionMinor { get; set; } + [RefreshProperties(RefreshProperties.All)] + public uint VersionMicro { get; set; } + [RefreshProperties(RefreshProperties.All)] + public uint VersionMicro2 { get; set; } + + internal void SetVersionInfo() { - get { return Version >> 24; } + VersionMajor = Version >> 24; + VersionMinor = Version >> 16 & 0xFF; + VersionMicro = Version >> 8 & 0xFF; + VersionMicro2 = Version & 0xFF; } - public uint VersionMinor + internal uint SaveVersion() { - get { return Version >> 16 & 0xFF; } - } - - public uint VersionMicro - { - get { return Version >> 8 & 0xFF; } - } - - public uint VersionMicro2 - { - get { return Version & 0xFF; } + return VersionMajor << 24 | VersionMinor << 16 | VersionMicro << 8 | VersionMicro2; } public void Dispose() diff --git a/File_Format_Library/GUI/BFLYT/LayoutEditor.cs b/File_Format_Library/GUI/BFLYT/LayoutEditor.cs index c84ffab8..8bc6d704 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutEditor.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutEditor.cs @@ -147,11 +147,15 @@ namespace LayoutBXLYT { if (e is TreeViewEventArgs) { var node = ((TreeViewEventArgs)e).Node; - var pane = (BasePane)node.Tag; - LayoutProperties.LoadProperties(pane, OnProperyChanged); - - ActiveViewport.SelectedPanes.Add(pane); + if (node.Tag is BasePane) + { + var pane = node.Tag as BasePane; + LayoutProperties.LoadProperties(pane, OnProperyChanged); + ActiveViewport.SelectedPanes.Add(pane); + } + else + LayoutProperties.LoadProperties(node.Tag, OnProperyChanged); } } if (ActiveViewport != null) @@ -428,6 +432,7 @@ namespace LayoutBXLYT if (TextConverter == null) TextConverter = new LayoutTextDocked(); TextConverter.Text = "Text Converter"; + TextConverter.TextCompiled += OnTextCompiled; TextConverter.LoadLayout((BFLYT)ActiveLayout.FileInfo); if (ActiveViewport != null) TextConverter.Show(ActiveViewport.Pane, DockAlignment.Bottom, 0.4); @@ -444,6 +449,16 @@ namespace LayoutBXLYT } } + private void OnTextCompiled(object sender, EventArgs e) + { + var layout = TextConverter.GetLayout(); + ActiveLayout = layout.header; + ReloadEditors(layout.header); + + if (ActiveViewport != null) + ActiveViewport.ResetLayout(ActiveLayout); + } + private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (ActiveLayout != null && ActiveLayout.FileInfo.CanSave) diff --git a/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs b/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs index ca833434..9b02485a 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs @@ -47,6 +47,8 @@ namespace LayoutBXLYT treeView1.BeginUpdate(); treeView1.Nodes.Clear(); + treeView1.Nodes.Add(new TreeNode("File Settings") {Tag = bxlyt }); + CreateQuickAccess(bxlyt); LoadPane(bxlyt.RootGroup); LoadPane(bxlyt.RootPane); diff --git a/File_Format_Library/GUI/BFLYT/LayoutProperties.cs b/File_Format_Library/GUI/BFLYT/LayoutProperties.cs index 1c5b5a46..1c8efc3b 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutProperties.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutProperties.cs @@ -35,6 +35,11 @@ namespace LayoutBXLYT stPropertyGrid1.UpdateProperties(); } + public void LoadProperties(object prop, Action propChanged) + { + LoadPropertyTab("Properties", prop, propChanged); + } + public void LoadProperties(BasePane prop, Action propChanged) { LoadPropertyTab("Pane", prop, propChanged); diff --git a/File_Format_Library/GUI/BFLYT/LayoutTextDocked.Designer.cs b/File_Format_Library/GUI/BFLYT/LayoutTextDocked.Designer.cs index 7ac0d9e0..881ff77e 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutTextDocked.Designer.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutTextDocked.Designer.cs @@ -28,8 +28,16 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.SuspendLayout(); + // + // LayoutTextDocked + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(320, 292); + this.Name = "LayoutTextDocked"; + this.ResumeLayout(false); + } #endregion diff --git a/File_Format_Library/GUI/BFLYT/LayoutTextDocked.cs b/File_Format_Library/GUI/BFLYT/LayoutTextDocked.cs index 0e8ac117..7261d2f5 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutTextDocked.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutTextDocked.cs @@ -14,6 +14,8 @@ namespace LayoutBXLYT { public partial class LayoutTextDocked : LayoutDocked { + public EventHandler TextCompiled; + TextEditor editor; public LayoutTextDocked() { @@ -22,6 +24,13 @@ namespace LayoutBXLYT editor = new TextEditor(); editor.Dock = DockStyle.Fill; Controls.Add(editor); + + TextCompiled += CompileLayout; + } + + public BFLYT GetLayout() + { + return activeLayout; } public void Reset() @@ -29,9 +38,24 @@ namespace LayoutBXLYT editor.FillEditor(""); } + private BFLYT activeLayout; public void LoadLayout(BFLYT bflyt) { + activeLayout = bflyt; + editor.AddContextMenu("Convert to BFLYT", TextCompiled); editor.FillEditor(bflyt.ConvertToString()); } + + private void CompileLayout(object sender, EventArgs e) + { + try + { + activeLayout.ConvertFromString(editor.GetText()); + } + catch (Exception ex) + { + STErrorDialog.Show("Failed to convert BFLYT! ", "Text Converter", ex.ToString()); + } + } } } diff --git a/File_Format_Library/GUI/BFLYT/LayoutTextDocked.resx b/File_Format_Library/GUI/BFLYT/LayoutTextDocked.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/File_Format_Library/GUI/BFLYT/LayoutTextDocked.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/File_Format_Library/GUI/BFLYT/LayoutViewer.cs b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs index 1c6f9305..f1a085c3 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutViewer.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs @@ -34,6 +34,12 @@ namespace LayoutBXLYT private Dictionary Textures; + public void ResetLayout(BxlytHeader bxlyt) + { + LayoutFile = bxlyt; + UpdateViewport(); + } + public LayoutViewer(BxlytHeader bxlyt, Dictionary textures) { InitializeComponent();