From 7724a056f57c7a4611d3f537c5908e0dbc053e1f Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Thu, 29 Aug 2019 19:01:47 -0400 Subject: [PATCH] Tons more bflyt progress --- .../FileFormats/Layout/BFLYT.cs | 7 +- .../FileFormats/Layout/Common.cs | 15 +++- .../GUI/BFLYT/LayoutEditor.Designer.cs | 21 +++++ File_Format_Library/GUI/BFLYT/LayoutEditor.cs | 90 ++++++++++--------- .../GUI/BFLYT/LayoutHierarchy.cs | 8 +- .../GUI/BFLYT/LayoutProperties.cs | 7 +- .../GUI/BFLYT/LayoutTextureList.cs | 16 +++- File_Format_Library/GUI/BFLYT/LayoutViewer.cs | 16 +++- 8 files changed, 129 insertions(+), 51 deletions(-) diff --git a/File_Format_Library/FileFormats/Layout/BFLYT.cs b/File_Format_Library/FileFormats/Layout/BFLYT.cs index 6189d642..d7e6dec3 100644 --- a/File_Format_Library/FileFormats/Layout/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/BFLYT.cs @@ -192,10 +192,8 @@ namespace LayoutBXLYT //Thanks to SwitchThemes for flags, and enums //https://github.com/FuryBaguette/SwitchLayoutEditor/tree/master/SwitchThemesCommon - public class Header : BxlytHeader + public class Header : BxlytHeader, IDisposable { - internal BFLYT FileInfo; - public string FileName { get { return FileInfo.FileName; } @@ -220,10 +218,9 @@ namespace LayoutBXLYT public override Dictionary GetTextures { - get { return FileInfo.GetTextures(); } + get { return ((BFLYT)FileInfo).GetTextures(); } } - public void Read(FileReader reader, BFLYT bflyt) { LayoutInfo = new LYT1(); diff --git a/File_Format_Library/FileFormats/Layout/Common.cs b/File_Format_Library/FileFormats/Layout/Common.cs index 18e1986e..18ee59eb 100644 --- a/File_Format_Library/FileFormats/Layout/Common.cs +++ b/File_Format_Library/FileFormats/Layout/Common.cs @@ -6,9 +6,15 @@ using System.Threading.Tasks; using Syroot.Maths; using Toolbox.Library.IO; using Toolbox.Library; +using WeifenLuo.WinFormsUI.Docking; namespace LayoutBXLYT { + public class LayoutDocked : DockContent + { + + } + public class BasePane : SectionCommon { public bool DisplayInEditor { get; set; } = true; @@ -109,8 +115,10 @@ namespace LayoutBXLYT Bottom = 2 }; - public class BxlytHeader + public class BxlytHeader : IDisposable { + internal IFileFormat FileInfo; + public BasePane RootPane { get; set; } public BasePane RootGroup { get; set; } @@ -152,6 +160,11 @@ namespace LayoutBXLYT { get { return Version & 0xFF; } } + + public void Dispose() + { + FileInfo.Unload(); + } } public class SectionCommon diff --git a/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs b/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs index ddc08f09..3e29eea4 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutEditor.Designer.cs @@ -36,9 +36,11 @@ this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.stMenuStrip1 = new Toolbox.Library.Forms.STMenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.clearWorkspaceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.textureListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.backColorDisplay)).BeginInit(); this.stToolStrip1.SuspendLayout(); this.stMenuStrip1.SuspendLayout(); @@ -109,10 +111,20 @@ // // fileToolStripMenuItem // + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.openToolStripMenuItem, + this.clearWorkspaceToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); this.fileToolStripMenuItem.Text = "File"; // + // clearWorkspaceToolStripMenuItem + // + this.clearWorkspaceToolStripMenuItem.Name = "clearWorkspaceToolStripMenuItem"; + this.clearWorkspaceToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.clearWorkspaceToolStripMenuItem.Text = "Clear Files"; + this.clearWorkspaceToolStripMenuItem.Click += new System.EventHandler(this.clearWorkspaceToolStripMenuItem_Click); + // // editToolStripMenuItem // this.editToolStripMenuItem.Name = "editToolStripMenuItem"; @@ -134,6 +146,13 @@ this.textureListToolStripMenuItem.Text = "Texture List"; this.textureListToolStripMenuItem.Click += new System.EventHandler(this.textureListToolStripMenuItem_Click); // + // openToolStripMenuItem + // + this.openToolStripMenuItem.Name = "openToolStripMenuItem"; + this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.openToolStripMenuItem.Text = "Open"; + this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); + // // LayoutEditor // this.AllowDrop = true; @@ -172,5 +191,7 @@ private Toolbox.Library.Forms.STComboBox viewportBackColorCB; private System.Windows.Forms.PictureBox backColorDisplay; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem clearWorkspaceToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; } } diff --git a/File_Format_Library/GUI/BFLYT/LayoutEditor.cs b/File_Format_Library/GUI/BFLYT/LayoutEditor.cs index 41988434..ee540f4e 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutEditor.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutEditor.cs @@ -48,15 +48,11 @@ namespace LayoutBXLYT ObjectChanged += OnObjectChanged; } - private DockContent TextureListDock; - private DockContent PaneTreeDock; - private DockContent ColorDock; - private DockContent PropertiesDock; - private List Viewports = new List(); private LayoutViewer ActiveViewport; private LayoutHierarchy LayoutHierarchy; private LayoutTextureList LayoutTextureList; + private LayoutProperties LayoutProperties; private bool isLoaded = false; public void LoadBflyt(BFLYT.Header header, string fileName) @@ -66,7 +62,8 @@ namespace LayoutBXLYT LayoutViewer Viewport = new LayoutViewer(header); Viewport.Dock = DockStyle.Fill; - DockShow(Viewport, fileName, DockState.Document); + Viewport.Show(dockPanel1, DockState.Document); + Viewport.DockHandler.AllowEndUserDocking = false; Viewports.Add(Viewport); ActiveViewport = Viewport; @@ -81,12 +78,25 @@ namespace LayoutBXLYT ShowTextureList(); ShowPaneHierarchy(); ShowPropertiesPanel(); - UpdateBackColor(); } + private void ResetEditors() + { + if (LayoutHierarchy != null) + LayoutHierarchy.Reset(); + if (LayoutTextureList != null) + LayoutTextureList.Reset(); + if (LayoutProperties != null) + LayoutProperties.Reset(); + } + private void ReloadEditors(BxlytHeader activeLayout) { + if (!isLoaded) return; + + if (LayoutProperties != null) + LayoutProperties.Reset(); if (LayoutHierarchy != null) LayoutHierarchy.LoadLayout(activeLayout, ObjectSelected); if (LayoutTextureList != null) @@ -111,13 +121,13 @@ namespace LayoutBXLYT ActiveViewport.SelectedPanes.Clear(); - if (PropertiesDock != null && (string)sender == "Select") + if (LayoutProperties != null && (string)sender == "Select") { if (e is TreeViewEventArgs) { var node = ((TreeViewEventArgs)e).Node; var pane = (BasePane)node.Tag; - ((LayoutProperties)PropertiesDock.Controls[0]).LoadProperties(pane, OnProperyChanged); + LayoutProperties.LoadProperties(pane, OnProperyChanged); ActiveViewport.SelectedPanes.Add(pane); } @@ -145,29 +155,6 @@ namespace LayoutBXLYT ToggleChildern(child, isChecked); } - private DockContent DockShow(UserControl control, string text, DockAlignment dockState, DockContent dockSide = null, float Alignment = 0) - { - DockContent content = CreateContent(control, text); - content.Show(dockSide.Pane, dockState, Alignment); - return content; - } - - private DockContent DockShow(UserControl control, string text, DockState dockState) - { - DockContent content = CreateContent(control, text); - content.Show(dockPanel1, dockState); - return content; - } - - private DockContent CreateContent(UserControl control, string text) - { - DockContent content = new DockContent(); - content.Text = text; - control.Dock = DockStyle.Fill; - content.Controls.Add(control); - return content; - } - public void LoadBflan() { @@ -189,22 +176,25 @@ namespace LayoutBXLYT private void ShowPropertiesPanel() { - LayoutProperties properties = new LayoutProperties(); - PropertiesDock = DockShow(properties, "Properties", DockAlignment.Top, TextureListDock, 0.5f); + LayoutProperties = new LayoutProperties(); + LayoutProperties.Text = "Properties"; + LayoutProperties.Show(dockPanel1, DockState.DockRight); } private void ShowPaneHierarchy() { LayoutHierarchy = new LayoutHierarchy(); + LayoutHierarchy.Text = "Hierarchy"; LayoutHierarchy.LoadLayout(ActiveLayout, ObjectSelected); - PaneTreeDock = DockShow(LayoutHierarchy, "Panes", DockAlignment.Top, TextureListDock, 0.5f); + LayoutHierarchy.Show(dockPanel1, DockState.DockLeft); } private void ShowTextureList() { LayoutTextureList = new LayoutTextureList(); + LayoutTextureList.Text = "Texture List"; LayoutTextureList.LoadTextures(ActiveLayout); - TextureListDock = DockShow(LayoutTextureList, "Texture List", DockState.DockRight); + LayoutTextureList.Show(dockPanel1, DockState.DockRight); } private void stComboBox1_MouseDoubleClick(object sender, MouseEventArgs e) @@ -308,9 +298,11 @@ namespace LayoutBXLYT { foreach (var file in archiveFile.Files) { - if (Utils.GetExtension(file.FileName) == ".bflyt") + var fileFormat = STFileLoader.OpenFileFormat(file.FileName, + new Type[] { typeof(BFLYT), typeof(SARC) }, file.FileData); + + if (fileFormat is BFLYT) { - var fileFormat = file.OpenFile(); fileFormat.IFileInfo.ArchiveParent = archiveFile; if (fileFormat is BFLYT) @@ -324,9 +316,8 @@ namespace LayoutBXLYT { } - else if (Utils.GetExtension(file.FileName) == ".lyarc") + else if (fileFormat is SARC) { - var fileFormat = file.OpenFile(); fileFormat.IFileInfo.ArchiveParent = archiveFile; if (fileFormat is IArchiveFile) @@ -345,5 +336,24 @@ namespace LayoutBXLYT e.Effect = DragDropEffects.None; } } + + private void clearWorkspaceToolStripMenuItem_Click(object sender, EventArgs e) + { + for (int i = 0; i < dockPanel1.DocumentsCount; i++) + dockPanel1.Documents.ElementAt(i).DockHandler.DockPanel = null; + + ResetEditors(); + } + + private void openToolStripMenuItem_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + if (ofd.ShowDialog() == DialogResult.OK) + { + foreach (string filename in ofd.FileNames) + OpenFile(filename); + } + } } } diff --git a/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs b/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs index 3ced5d30..f2fdfe82 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutHierarchy.cs @@ -12,7 +12,7 @@ using Toolbox.Library.Forms; namespace LayoutBXLYT { - public partial class LayoutHierarchy : UserControl + public partial class LayoutHierarchy : LayoutDocked { public LayoutHierarchy() { @@ -47,6 +47,12 @@ namespace LayoutBXLYT isLoaded = true; } + public void Reset() + { + treeView1.Nodes.Clear(); + isLoaded = false; + } + private void LoadPane(BasePane pane, TreeNode parent = null) { PaneTreeWrapper paneNode = new PaneTreeWrapper(); diff --git a/File_Format_Library/GUI/BFLYT/LayoutProperties.cs b/File_Format_Library/GUI/BFLYT/LayoutProperties.cs index e6e50d5e..5350c4d4 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutProperties.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutProperties.cs @@ -11,7 +11,7 @@ using Toolbox.Library.Forms; namespace LayoutBXLYT { - public partial class LayoutProperties : UserControl + public partial class LayoutProperties : LayoutDocked { public LayoutProperties() { @@ -20,6 +20,11 @@ namespace LayoutBXLYT stTabControl1.myBackColor = FormThemes.BaseTheme.FormBackColor; } + public void Reset() + { + stTabControl1.Controls.Clear(); + } + public void LoadProperties(BasePane prop, Action propChanged) { stTabControl1.Controls.Clear(); diff --git a/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs b/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs index 661bb08e..f8938f21 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutTextureList.cs @@ -15,7 +15,7 @@ using WeifenLuo.WinFormsUI.Docking; namespace LayoutBXLYT { - public partial class LayoutTextureList : UserControl + public partial class LayoutTextureList : LayoutDocked { ImageList imgList = new ImageList(); public LayoutTextureList() @@ -37,6 +37,20 @@ namespace LayoutBXLYT }; } + public void Reset() + { + if (Thread != null && Thread.IsAlive) + Thread.Abort(); + + for (int i = 0; i < imgList.Images.Count; i++) + imgList.Images[i].Dispose(); + + imgList.Images.Clear(); + listViewCustom1.Items.Clear(); + + isLoaded = false; + } + private bool isLoaded = false; private Thread Thread; public void LoadTextures(BxlytHeader header) diff --git a/File_Format_Library/GUI/BFLYT/LayoutViewer.cs b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs index 2f86bcfd..e9db05c8 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutViewer.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs @@ -15,7 +15,7 @@ using Toolbox.Library.IO; namespace LayoutBXLYT { - public partial class LayoutViewer : UserControl + public partial class LayoutViewer : LayoutDocked { public List SelectedPanes = new List(); @@ -37,10 +37,22 @@ namespace LayoutBXLYT { InitializeComponent(); LayoutFile = bflyt; + Text = bflyt.FileName; Textures = new Dictionary(); if (bflyt.TextureList.Textures.Count > 0) - Textures = bflyt.FileInfo.GetTextures(); + Textures = ((BFLYT)bflyt.FileInfo).GetTextures(); + } + + protected override void OnFormClosing(FormClosingEventArgs e) + { + var result = MessageBox.Show("Are you sure you want to close this file? You will lose any unsaved progress!", "Layout Editor", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (result != DialogResult.Yes) + e.Cancel = true; + else + LayoutFile.Dispose(); + + base.OnFormClosing(e); } public void UpdateViewport()