1
0
mirror of synced 2024-12-13 00:01:13 +01:00
Switch-Toolbox/Switch_Toolbox_Library/GUI.cs
KillzXGaming 5081e39414 More format additions and fixes.
Fixed MKAGPDX models a bit so they aren't all missing mesh data. Skinned ones are still buggy!
 BMD wip support using SuperBMDLib.
 Adjusted gui loading a little bit.
2019-07-11 17:22:59 -04:00

157 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GL_EditorFramework.GL_Core;
using System.Windows.Forms;
using GL_EditorFramework.StandardCameras;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using Switch_Toolbox.Library.Forms;
using GL_EditorFramework.Interfaces;
using GL_EditorFramework.EditorDrawables;
namespace Switch_Toolbox.Library
{
public class LibraryGUI
{
public static Viewport GetActiveViewport()
{
var viewport = GetActiveContent();
if (viewport != null && viewport is IViewportContainer)
{
return (((IViewportContainer)viewport).GetViewport());
}
if (Runtime.MainForm.ActiveMdiChild is IViewportContainer)
{
return ((IViewportContainer)Runtime.MainForm.ActiveMdiChild).GetViewport();
}
if (viewport != null && viewport is Viewport)
{
return ((Viewport)viewport);
}
return null;
}
public static AnimationPanel GetAnimationPanel()
{
var editor = GetActiveContent();
if (editor != null && editor is IViewportContainer)
{
return (((IViewportContainer)editor).GetAnimationPanel());
}
return null;
}
public static void UpdateViewport()
{
Viewport viewport = GetActiveViewport();
if (viewport != null)
viewport.UpdateViewport();
}
public static Form GetActiveForm()
{
return Runtime.MainForm.ActiveMdiChild;
}
public static void CreateMdiWindow(STForm form, bool Show = true)
{
var mainform = Application.OpenForms[0];
((IMdiContainer)mainform).AddChildContainer(form);
}
public static ObjectEditor GetObjectEditor()
{
if (Runtime.MainForm.ActiveMdiChild is ObjectEditor)
{
return (ObjectEditor)Runtime.MainForm.ActiveMdiChild;
}
return null;
}
public static void LoadViewportEditor(Control control)
{
control.Dock = DockStyle.Fill;
var activeContent = GetActiveContent(typeof(ViewportDivider));
if (activeContent == null)
{
activeContent = new ViewportDivider();
activeContent.Dock = DockStyle.Fill;
LoadEditor(activeContent);
}
if (control is Viewport)
{
((ViewportDivider)activeContent).viewportPanel.Controls.Clear();
((ViewportDivider)activeContent).viewportPanel.Controls.Add(control);
}
else
{
((ViewportDivider)activeContent).editorPanel.Controls.Clear();
((ViewportDivider)activeContent).editorPanel.Controls.Add(control);
}
}
public static void LoadEditor(Control control)
{
if (Runtime.MainForm.ActiveMdiChild is ObjectEditor)
{
((ObjectEditor)Runtime.MainForm.ActiveMdiChild).LoadEditor(control);
}
}
public static UserControl GetActiveContent(Type type = null)
{
if (Runtime.MainForm.ActiveMdiChild == null)
return null;
if (Runtime.MainForm.ActiveMdiChild is ObjectEditor)
{
foreach (var ctrl in ((ObjectEditor)Runtime.MainForm.ActiveMdiChild).GetEditors())
{
if (type == null) {
return (UserControl)ctrl;
}
if (ctrl.GetType() == type) {
return (UserControl)ctrl;
}
}
}
else
{
foreach (var ctrl in Runtime.MainForm.ActiveMdiChild.Controls)
{
if (type == null && type == typeof(UserControl))
{
return (UserControl)ctrl;
}
else if (ctrl.GetType() == type)
{
return (UserControl)ctrl;
}
else
{
Console.WriteLine(ctrl);
foreach (var inter in ctrl.GetType().GetInterfaces())
{
Console.WriteLine(inter);
if (inter.IsGenericType && inter.GetGenericTypeDefinition() == type)
{
return (UserControl)ctrl;
}
}
}
}
}
return null;
}
public static void LoadViewport(Viewport viewport)
{
}
}
}