1
0
mirror of synced 2025-01-19 09:17:30 +01:00

Tons more bflyt progress

This commit is contained in:
KillzXGaming 2019-08-29 19:01:47 -04:00
parent 1e4b18844f
commit 7724a056f5
8 changed files with 129 additions and 51 deletions

View File

@ -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<string, STGenericTexture> GetTextures
{
get { return FileInfo.GetTextures(); }
get { return ((BFLYT)FileInfo).GetTextures(); }
}
public void Read(FileReader reader, BFLYT bflyt)
{
LayoutInfo = new LYT1();

View File

@ -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

View File

@ -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;
}
}

View File

@ -48,15 +48,11 @@ namespace LayoutBXLYT
ObjectChanged += OnObjectChanged;
}
private DockContent TextureListDock;
private DockContent PaneTreeDock;
private DockContent ColorDock;
private DockContent PropertiesDock;
private List<LayoutViewer> Viewports = new List<LayoutViewer>();
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);
}
}
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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)

View File

@ -15,7 +15,7 @@ using Toolbox.Library.IO;
namespace LayoutBXLYT
{
public partial class LayoutViewer : UserControl
public partial class LayoutViewer : LayoutDocked
{
public List<BasePane> SelectedPanes = new List<BasePane>();
@ -37,10 +37,22 @@ namespace LayoutBXLYT
{
InitializeComponent();
LayoutFile = bflyt;
Text = bflyt.FileName;
Textures = new Dictionary<string, STGenericTexture>();
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()