1
0
mirror of synced 2024-11-15 11:33:20 +01:00
Switch-Toolbox/File_Format_Library/GUI/BFLYT/LayoutEditor.cs

262 lines
8.0 KiB
C#
Raw Normal View History

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;
using Toolbox.Library.Forms;
using WeifenLuo.WinFormsUI.Docking;
using WeifenLuo.WinFormsUI.ThemeVS2015;
using Toolbox.Library.IO;
using Toolbox.Library;
2019-08-27 22:38:06 +02:00
namespace FirstPlugin.Forms
{
public partial class LayoutEditor : Form
{
2019-08-27 22:38:06 +02:00
public List<BFLYT.Header> LayoutFiles = new List<BFLYT.Header>();
2019-08-28 03:14:37 +02:00
private BFLYT.Header ActiveLayout;
2019-08-27 22:38:06 +02:00
public enum DockLayout
{
Default,
Animation,
}
public EventHandler ObjectSelected;
public EventHandler ObjectChanged;
public LayoutEditor()
{
InitializeComponent();
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-27 22:38:06 +02:00
private DockContent TextureListDock;
private DockContent GroupTreeDock;
private DockContent PaneTreeDock;
private DockContent ColorDock;
private DockContent PropertiesDock;
private List<LayoutViewer> Viewports = new List<LayoutViewer>();
private LayoutViewer ActiveViewport;
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)
{
LayoutFiles.Add(header);
ActiveLayout = header;
2019-08-28 03:14:37 +02:00
LayoutViewer Viewport = new LayoutViewer(header);
Viewport.Dock = DockStyle.Fill;
DockShow(Viewport, fileName, DockState.Document);
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
}
private void InitializeDockPanels()
{
ShowTextureList();
ShowPaneHierarchy();
ShowGroupsHierarchy();
ShowPropertiesPanel();
UpdateBackColor();
}
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();
if (PropertiesDock != null && (string)sender == "Select")
{
if (e is TreeViewEventArgs) {
var node = ((TreeViewEventArgs)e).Node;
var pane = (BFLYT.BasePane)node.Tag;
((LayoutProperties)PropertiesDock.Controls[0]).LoadProperties(pane, OnProperyChanged);
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)
{
if (node.Tag is BFLYT.BasePane)
((BFLYT.BasePane)node.Tag).DisplayInEditor = isChecked;
node.Checked = isChecked;
foreach (TreeNode child in node.Nodes)
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;
}
2019-08-28 03:14:37 +02:00
private DockContent CreateContent(UserControl control, string text)
{
DockContent content = new DockContent();
content.Text = text;
control.Dock = DockStyle.Fill;
content.Controls.Add(control);
return content;
}
2019-08-28 03:14:37 +02:00
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;
}
private void textureListToolStripMenuItem_Click(object sender, EventArgs e) {
ShowTextureList();
}
private void ShowGroupsHierarchy()
{
dockPanel1.GetContainerControl();
LayoutHierarchy hierarchyList = new LayoutHierarchy();
hierarchyList.LoadLayout(ActiveLayout,ObjectSelected, true);
GroupTreeDock = DockShow(hierarchyList, "Groups", DockAlignment.Top, TextureListDock, 0.5f);
}
private void ShowPropertiesPanel()
{
LayoutProperties properties = new LayoutProperties();
PropertiesDock = DockShow(properties, "Properties", DockAlignment.Top, TextureListDock, 0.5f);
}
private void ShowPaneHierarchy()
{
LayoutHierarchy hierarchyList = new LayoutHierarchy();
hierarchyList.LoadLayout(ActiveLayout, ObjectSelected);
PaneTreeDock = DockShow(hierarchyList, "Panes", DockAlignment.Top, TextureListDock, 0.5f);
}
private void ShowTextureList()
2019-08-28 03:14:37 +02:00
{
LayoutTextureList textureListForm = new LayoutTextureList();
textureListForm.LoadTextures(ActiveLayout);
TextureListDock = DockShow(textureListForm, "Texture List", DockState.DockRight);
}
private void stComboBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
2019-08-28 03:14:37 +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
{
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
}
}
}