2019-08-01 23:47:35 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2019-08-29 21:45:32 +02:00
|
|
|
|
using Toolbox.Library.Forms;
|
|
|
|
|
using WeifenLuo.WinFormsUI.Docking;
|
|
|
|
|
using WeifenLuo.WinFormsUI.ThemeVS2015;
|
|
|
|
|
using Toolbox.Library.IO;
|
|
|
|
|
using Toolbox.Library;
|
2019-08-30 00:05:44 +02:00
|
|
|
|
using FirstPlugin;
|
2019-08-01 23:47:35 +02:00
|
|
|
|
|
2019-08-29 22:33:23 +02:00
|
|
|
|
namespace LayoutBXLYT
|
2019-08-01 23:47:35 +02:00
|
|
|
|
{
|
2019-08-29 21:45:32 +02:00
|
|
|
|
public partial class LayoutEditor : Form
|
2019-08-01 23:47:35 +02:00
|
|
|
|
{
|
2019-08-29 23:17:24 +02:00
|
|
|
|
public List<BxlytHeader> LayoutFiles = new List<BxlytHeader>();
|
2019-08-27 22:38:06 +02:00
|
|
|
|
|
2019-08-29 23:17:24 +02:00
|
|
|
|
private BxlytHeader ActiveLayout;
|
2019-08-28 03:14:37 +02:00
|
|
|
|
|
2019-08-27 22:38:06 +02:00
|
|
|
|
public enum DockLayout
|
|
|
|
|
{
|
|
|
|
|
Default,
|
|
|
|
|
Animation,
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 21:45:32 +02:00
|
|
|
|
public EventHandler ObjectSelected;
|
|
|
|
|
public EventHandler ObjectChanged;
|
|
|
|
|
|
2019-08-01 23:47:35 +02:00
|
|
|
|
public LayoutEditor()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-08-29 21:45:32 +02:00
|
|
|
|
|
|
|
|
|
var theme = new VS2015DarkTheme();
|
|
|
|
|
this.dockPanel1.Theme = theme;
|
|
|
|
|
this.dockPanel1.BackColor = FormThemes.BaseTheme.FormBackColor;
|
|
|
|
|
this.BackColor = FormThemes.BaseTheme.FormBackColor;
|
|
|
|
|
|
|
|
|
|
viewportBackColorCB.Items.Add("Back Color : Default");
|
|
|
|
|
viewportBackColorCB.Items.Add("Back Color : Custom");
|
|
|
|
|
viewportBackColorCB.SelectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
ObjectSelected += OnObjectSelected;
|
|
|
|
|
ObjectChanged += OnObjectChanged;
|
2019-08-01 23:47:35 +02:00
|
|
|
|
}
|
2019-08-27 22:38:06 +02:00
|
|
|
|
|
2019-08-29 21:45:32 +02:00
|
|
|
|
private List<LayoutViewer> Viewports = new List<LayoutViewer>();
|
|
|
|
|
private LayoutViewer ActiveViewport;
|
2019-08-29 23:17:24 +02:00
|
|
|
|
private LayoutHierarchy LayoutHierarchy;
|
2019-08-30 00:05:44 +02:00
|
|
|
|
private LayoutTextureList LayoutTextureList;
|
2019-08-30 01:01:47 +02:00
|
|
|
|
private LayoutProperties LayoutProperties;
|
2019-08-29 21:45:32 +02:00
|
|
|
|
|
2019-08-28 03:14:37 +02:00
|
|
|
|
private bool isLoaded = false;
|
2019-08-27 22:38:06 +02:00
|
|
|
|
public void LoadBflyt(BFLYT.Header header, string fileName)
|
|
|
|
|
{
|
2019-08-29 21:45:32 +02:00
|
|
|
|
LayoutFiles.Add(header);
|
|
|
|
|
ActiveLayout = header;
|
2019-08-28 03:14:37 +02:00
|
|
|
|
|
2019-08-29 21:45:32 +02:00
|
|
|
|
LayoutViewer Viewport = new LayoutViewer(header);
|
|
|
|
|
Viewport.Dock = DockStyle.Fill;
|
2019-08-30 01:01:47 +02:00
|
|
|
|
Viewport.Show(dockPanel1, DockState.Document);
|
|
|
|
|
Viewport.DockHandler.AllowEndUserDocking = false;
|
2019-08-29 21:45:32 +02:00
|
|
|
|
Viewports.Add(Viewport);
|
|
|
|
|
ActiveViewport = Viewport;
|
|
|
|
|
|
|
|
|
|
if (!isLoaded)
|
|
|
|
|
InitializeDockPanels();
|
2019-08-28 03:14:37 +02:00
|
|
|
|
|
|
|
|
|
isLoaded = true;
|
2019-08-27 22:38:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 21:45:32 +02:00
|
|
|
|
private void InitializeDockPanels()
|
|
|
|
|
{
|
|
|
|
|
ShowTextureList();
|
|
|
|
|
ShowPaneHierarchy();
|
|
|
|
|
ShowPropertiesPanel();
|
|
|
|
|
UpdateBackColor();
|
2019-08-29 23:17:24 +02:00
|
|
|
|
}
|
2019-08-29 21:45:32 +02:00
|
|
|
|
|
2019-08-30 01:01:47 +02:00
|
|
|
|
private void ResetEditors()
|
|
|
|
|
{
|
|
|
|
|
if (LayoutHierarchy != null)
|
|
|
|
|
LayoutHierarchy.Reset();
|
|
|
|
|
if (LayoutTextureList != null)
|
|
|
|
|
LayoutTextureList.Reset();
|
|
|
|
|
if (LayoutProperties != null)
|
|
|
|
|
LayoutProperties.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 23:17:24 +02:00
|
|
|
|
private void ReloadEditors(BxlytHeader activeLayout)
|
|
|
|
|
{
|
2019-08-30 01:01:47 +02:00
|
|
|
|
if (!isLoaded) return;
|
|
|
|
|
|
|
|
|
|
if (LayoutProperties != null)
|
|
|
|
|
LayoutProperties.Reset();
|
2019-08-29 23:17:24 +02:00
|
|
|
|
if (LayoutHierarchy != null)
|
|
|
|
|
LayoutHierarchy.LoadLayout(activeLayout, ObjectSelected);
|
2019-08-30 00:05:44 +02:00
|
|
|
|
if (LayoutTextureList != null)
|
|
|
|
|
LayoutTextureList.LoadTextures(activeLayout);
|
2019-08-29 21:45:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnObjectChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnProperyChanged()
|
|
|
|
|
{
|
|
|
|
|
if (ActiveViewport != null)
|
|
|
|
|
ActiveViewport.UpdateViewport();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isChecked = false;
|
|
|
|
|
private void OnObjectSelected(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (isChecked) return;
|
|
|
|
|
|
|
|
|
|
ActiveViewport.SelectedPanes.Clear();
|
|
|
|
|
|
2019-08-30 01:01:47 +02:00
|
|
|
|
if (LayoutProperties != null && (string)sender == "Select")
|
2019-08-29 21:45:32 +02:00
|
|
|
|
{
|
|
|
|
|
if (e is TreeViewEventArgs) {
|
|
|
|
|
var node = ((TreeViewEventArgs)e).Node;
|
2019-08-29 22:33:23 +02:00
|
|
|
|
var pane = (BasePane)node.Tag;
|
2019-08-29 21:45:32 +02:00
|
|
|
|
|
2019-08-30 01:01:47 +02:00
|
|
|
|
LayoutProperties.LoadProperties(pane, OnProperyChanged);
|
2019-08-29 21:45:32 +02:00
|
|
|
|
|
|
|
|
|
ActiveViewport.SelectedPanes.Add(pane);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ActiveViewport != null)
|
|
|
|
|
{
|
|
|
|
|
if (e is TreeViewEventArgs && (string)sender == "Checked" && !isChecked) {
|
|
|
|
|
isChecked = true;
|
|
|
|
|
var node = ((TreeViewEventArgs)e).Node;
|
|
|
|
|
ToggleChildern(node, node.Checked);
|
|
|
|
|
isChecked = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActiveViewport.UpdateViewport();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToggleChildern(TreeNode node, bool isChecked)
|
|
|
|
|
{
|
2019-08-29 22:33:23 +02:00
|
|
|
|
if (node.Tag is BasePane)
|
|
|
|
|
((BasePane)node.Tag).DisplayInEditor = isChecked;
|
2019-08-29 21:45:32 +02:00
|
|
|
|
|
|
|
|
|
node.Checked = isChecked;
|
|
|
|
|
foreach (TreeNode child in node.Nodes)
|
|
|
|
|
ToggleChildern(child, isChecked);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 22:38:06 +02:00
|
|
|
|
public void LoadBflan()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitalizeEditors()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-08-28 03:14:37 +02:00
|
|
|
|
|
|
|
|
|
private void LayoutEditor_ParentChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.ParentForm == null) return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 21:45:32 +02:00
|
|
|
|
private void textureListToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
|
|
|
ShowTextureList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowPropertiesPanel()
|
|
|
|
|
{
|
2019-08-30 01:01:47 +02:00
|
|
|
|
LayoutProperties = new LayoutProperties();
|
|
|
|
|
LayoutProperties.Text = "Properties";
|
|
|
|
|
LayoutProperties.Show(dockPanel1, DockState.DockRight);
|
2019-08-29 21:45:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowPaneHierarchy()
|
|
|
|
|
{
|
2019-08-29 23:17:24 +02:00
|
|
|
|
LayoutHierarchy = new LayoutHierarchy();
|
2019-08-30 01:01:47 +02:00
|
|
|
|
LayoutHierarchy.Text = "Hierarchy";
|
2019-08-29 23:17:24 +02:00
|
|
|
|
LayoutHierarchy.LoadLayout(ActiveLayout, ObjectSelected);
|
2019-08-30 01:01:47 +02:00
|
|
|
|
LayoutHierarchy.Show(dockPanel1, DockState.DockLeft);
|
2019-08-29 21:45:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowTextureList()
|
2019-08-28 03:14:37 +02:00
|
|
|
|
{
|
2019-08-30 00:05:44 +02:00
|
|
|
|
LayoutTextureList = new LayoutTextureList();
|
2019-08-30 01:01:47 +02:00
|
|
|
|
LayoutTextureList.Text = "Texture List";
|
2019-08-30 00:05:44 +02:00
|
|
|
|
LayoutTextureList.LoadTextures(ActiveLayout);
|
2019-08-30 01:01:47 +02:00
|
|
|
|
LayoutTextureList.Show(dockPanel1, DockState.DockRight);
|
2019-08-29 21:45:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stComboBox1_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2019-08-28 03:14:37 +02:00
|
|
|
|
|
2019-08-29 21:45:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isBGUpdating = false;
|
|
|
|
|
private void viewportBackColorCB_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (ActiveViewport == null || isBGUpdating) return;
|
|
|
|
|
UpdateBackColor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBackColor()
|
|
|
|
|
{
|
|
|
|
|
if (viewportBackColorCB.SelectedIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
ActiveViewport.UpdateBackgroundColor(Color.FromArgb(130, 130, 130));
|
|
|
|
|
backColorDisplay.BackColor = Color.FromArgb(130, 130, 130);
|
|
|
|
|
}
|
2019-08-28 03:14:37 +02:00
|
|
|
|
else
|
2019-08-29 21:45:32 +02:00
|
|
|
|
{
|
|
|
|
|
ColorDialog dlg = new ColorDialog();
|
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
ActiveViewport.UpdateBackgroundColor(dlg.Color);
|
|
|
|
|
backColorDisplay.BackColor = dlg.Color;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
viewportBackColorCB.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void backColorDisplay_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
isBGUpdating = true;
|
|
|
|
|
|
|
|
|
|
ColorDialog dlg = new ColorDialog();
|
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
ActiveViewport.UpdateBackgroundColor(dlg.Color);
|
|
|
|
|
backColorDisplay.BackColor = dlg.Color;
|
|
|
|
|
|
|
|
|
|
if (viewportBackColorCB.SelectedIndex == 0)
|
|
|
|
|
viewportBackColorCB.SelectedIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isBGUpdating = false;
|
2019-08-28 03:14:37 +02:00
|
|
|
|
}
|
2019-08-29 23:17:24 +02:00
|
|
|
|
|
|
|
|
|
private void dockPanel1_ActiveDocumentChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-08-30 01:21:47 +02:00
|
|
|
|
var dockContent = dockPanel1.ActiveDocument as LayoutViewer;
|
|
|
|
|
if (dockContent != null)
|
2019-08-29 23:17:24 +02:00
|
|
|
|
{
|
2019-08-30 01:21:47 +02:00
|
|
|
|
var file = (dockContent).LayoutFile;
|
|
|
|
|
ReloadEditors(file);
|
2019-08-29 23:17:24 +02:00
|
|
|
|
|
2019-08-30 01:21:47 +02:00
|
|
|
|
dockContent.UpdateViewport();
|
2019-08-29 23:17:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-30 00:05:44 +02:00
|
|
|
|
|
|
|
|
|
private void LayoutEditor_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
|
|
|
|
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
|
|
foreach (string filename in files)
|
|
|
|
|
OpenFile(filename);
|
|
|
|
|
|
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenFile(string fileName)
|
|
|
|
|
{
|
|
|
|
|
//Todo if an image is dropped, we should make a picture pane if a viewer is active
|
|
|
|
|
|
|
|
|
|
var file = STFileLoader.OpenFileFormat(fileName);
|
|
|
|
|
if (file == null) return;
|
|
|
|
|
|
|
|
|
|
if (file is BFLYT)
|
|
|
|
|
LoadBflyt(((BFLYT)file).header, file.FileName);
|
|
|
|
|
else if (file is IArchiveFile)
|
2019-08-30 01:21:47 +02:00
|
|
|
|
{
|
|
|
|
|
var layouts = SearchLayoutFiles((IArchiveFile)file);
|
|
|
|
|
if (layouts.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
var form = new FileSelector();
|
|
|
|
|
form.LoadLayoutFiles(layouts);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
foreach (var index in form.SelectedIndices())
|
|
|
|
|
{
|
|
|
|
|
LoadBflyt(layouts[index].header, file.FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (layouts.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
LoadBflyt(layouts[0].header, file.FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-30 00:05:44 +02:00
|
|
|
|
else if (file is BFLAN)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (file is BNTX)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 01:21:47 +02:00
|
|
|
|
private List<BFLYT> SearchLayoutFiles(IArchiveFile archiveFile)
|
2019-08-30 00:05:44 +02:00
|
|
|
|
{
|
2019-08-30 01:21:47 +02:00
|
|
|
|
List<BFLYT> layouts = new List<BFLYT>();
|
|
|
|
|
|
2019-08-30 00:05:44 +02:00
|
|
|
|
foreach (var file in archiveFile.Files)
|
|
|
|
|
{
|
2019-08-30 01:01:47 +02:00
|
|
|
|
var fileFormat = STFileLoader.OpenFileFormat(file.FileName,
|
|
|
|
|
new Type[] { typeof(BFLYT), typeof(SARC) }, file.FileData);
|
|
|
|
|
|
|
|
|
|
if (fileFormat is BFLYT)
|
2019-08-30 00:05:44 +02:00
|
|
|
|
{
|
|
|
|
|
fileFormat.IFileInfo.ArchiveParent = archiveFile;
|
2019-08-30 01:21:47 +02:00
|
|
|
|
layouts.Add((BFLYT)fileFormat);
|
2019-08-30 00:05:44 +02:00
|
|
|
|
}
|
|
|
|
|
else if (Utils.GetExtension(file.FileName) == ".bntx")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (Utils.GetExtension(file.FileName) == ".bflim")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-08-30 01:01:47 +02:00
|
|
|
|
else if (fileFormat is SARC)
|
2019-08-30 00:05:44 +02:00
|
|
|
|
{
|
|
|
|
|
fileFormat.IFileInfo.ArchiveParent = archiveFile;
|
|
|
|
|
|
|
|
|
|
if (fileFormat is IArchiveFile)
|
2019-08-30 01:21:47 +02:00
|
|
|
|
return SearchLayoutFiles((IArchiveFile)fileFormat);
|
2019-08-30 00:05:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-30 01:21:47 +02:00
|
|
|
|
|
|
|
|
|
return layouts;
|
2019-08-30 00:05:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LayoutEditor_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
|
e.Effect = DragDropEffects.All;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
String[] strGetFormats = e.Data.GetFormats();
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-30 01:01:47 +02:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-01 23:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|