More progress

This commit is contained in:
Sinai
2021-05-05 21:27:09 +10:00
parent 961ff80c6d
commit e4ff86259b
42 changed files with 1159 additions and 730 deletions

View File

@ -15,6 +15,8 @@ namespace UnityExplorer.UI.Panels
{
public override string Name => "C# Console";
public override UIManager.Panels PanelType => UIManager.Panels.CSConsole;
public override int MinWidth => 400;
public override int MinHeight => 300;
public static CSConsolePanel Instance { get; private set; }
@ -95,25 +97,18 @@ namespace UnityExplorer.UI.Panels
ConfigManager.CSConsoleData.Value = this.ToSaveData();
}
public override void LoadSaveData()
{
this.ApplySaveData(ConfigManager.CSConsoleData.Value);
}
public override string GetSaveData() => ConfigManager.CSConsoleData.Value;
public override void SetDefaultPosAndAnchors()
// UI Construction
protected internal override void DoSetDefaultPosAndAnchors()
{
mainPanelRect.localPosition = Vector2.zero;
mainPanelRect.pivot = new Vector2(0f, 1f);
mainPanelRect.anchorMin = new Vector2(0.5f, 0);
mainPanelRect.anchorMax = new Vector2(0.5f, 1);
mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 100); // bottom
mainPanelRect.offsetMax = new Vector2(mainPanelRect.offsetMax.x, -50); // top
mainPanelRect.sizeDelta = new Vector2(700f, mainPanelRect.sizeDelta.y);
mainPanelRect.anchoredPosition = new Vector2(-150, 0);
mainPanelRect.anchorMin = new Vector2(0.4f, 0.1f);
mainPanelRect.anchorMax = new Vector2(0.9f, 0.85f);
}
// UI Construction
public override void ConstructPanelContent()
{
//Content = UIFactory.CreateVerticalGroup(MainMenu.Instance.PageViewport, "CSharpConsole", true, true, true, true);

View File

@ -6,11 +6,7 @@ using System.Text;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Core.Config;
using UnityExplorer.Core.Runtime;
using UnityExplorer.UI.Inspectors;
using UnityExplorer.UI.Models;
using UnityExplorer.UI.Utility;
using UnityExplorer.UI.Widgets;
namespace UnityExplorer.UI.Panels
{
@ -23,6 +19,8 @@ namespace UnityExplorer.UI.Panels
public override string Name => "Inspector";
public override UIManager.Panels PanelType => UIManager.Panels.Inspector;
public override bool ShouldSaveActiveState => false;
public override int MinWidth => 550;
public override int MinHeight => 350;
public GameObject NavbarHolder;
public GameObject ContentHolder;
@ -40,41 +38,40 @@ namespace UnityExplorer.UI.Panels
{
base.OnFinishResize(panel);
InspectorManager.PanelWidth = this.mainPanelRect.rect.width;
InspectorManager.OnPanelResized(panel.rect.width);
}
public override void LoadSaveData()
{
ApplySaveData(ConfigManager.InspectorData.Value);
public override string GetSaveData() => ConfigManager.InspectorData.Value;
InspectorManager.PanelWidth = this.mainPanelRect.rect.width;
}
//public override void LoadSaveData()
//{
// ApplySaveData(ConfigManager.InspectorData.Value);
//
// InspectorManager.PanelWidth = this.mainPanelRect.rect.width;
//}
public override void DoSaveToConfigElement()
{
ConfigManager.InspectorData.Value = this.ToSaveData();
}
public override void SetDefaultPosAndAnchors()
protected internal override void DoSetDefaultPosAndAnchors()
{
mainPanelRect.localPosition = Vector2.zero;
mainPanelRect.pivot = new Vector2(0f, 1f);
mainPanelRect.anchorMin = new Vector2(0.1f, 0.15f);
mainPanelRect.anchorMax = new Vector2(0.1f, 0.95f);
mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 100); // bottom
mainPanelRect.offsetMax = new Vector2(mainPanelRect.offsetMax.x, -50); // top
mainPanelRect.sizeDelta = new Vector2(700f, mainPanelRect.sizeDelta.y);
mainPanelRect.anchoredPosition = new Vector2(-150, 0);
mainPanelRect.anchorMin = new Vector2(0.35f, 0.175f);
mainPanelRect.anchorMax = new Vector2(0.8f, 0.925f);
}
public override void ConstructPanelContent()
{
// this.UIRoot.GetComponent<Mask>().enabled = false;
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(this.content, forceHeight: true, spacing: 4, padLeft: 5, padRight: 5);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(this.content, true, true, true, true, 4, padLeft: 5, padRight: 5);
this.NavbarHolder = UIFactory.CreateGridGroup(this.content, "Navbar", new Vector2(200, 22), new Vector2(4, 4),
new Color(0.12f, 0.12f, 0.12f));
new Color(0.05f, 0.05f, 0.05f));
//UIFactory.SetLayoutElement(NavbarHolder, flexibleWidth: 9999, minHeight: 0, preferredHeight: 0, flexibleHeight: 9999);
NavbarHolder.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

View File

@ -20,6 +20,8 @@ namespace UnityExplorer.UI.Panels
{
public override string Name => "Object Explorer";
public override UIManager.Panels PanelType => UIManager.Panels.ObjectExplorer;
public override int MinWidth => 350;
public override int MinHeight => 200;
public SceneExplorer SceneExplorer;
public ObjectSearch ObjectSearch;
@ -56,18 +58,17 @@ namespace UnityExplorer.UI.Panels
{
if (SelectedTab == 0)
SceneExplorer.Update();
else
ObjectSearch.Update();
}
public override string GetSaveData() => ConfigManager.ObjectExplorerData.Value;
public override void DoSaveToConfigElement()
{
ConfigManager.ObjectExplorerData.Value = this.ToSaveData();
}
public override void LoadSaveData()
{
ApplySaveData(ConfigManager.ObjectExplorerData.Value);
}
public override string ToSaveData()
{
string ret = base.ToSaveData();
@ -95,21 +96,13 @@ namespace UnityExplorer.UI.Panels
SetTab(SelectedTab);
}
public override void SetDefaultPosAndAnchors()
protected internal override void DoSetDefaultPosAndAnchors()
{
// todo proper default size
mainPanelRect.localPosition = Vector2.zero;
mainPanelRect.pivot = new Vector2(0f, 1f);
mainPanelRect.anchorMin = new Vector2(0.1f, 0.25f);
mainPanelRect.anchorMax = new Vector2(0.25f, 0.8f);
//mainPanelRect.anchorMin = Vector3.zero;
//mainPanelRect.anchorMax = new Vector2(0, 1);
//mainPanelRect.sizeDelta = new Vector2(320f, mainPanelRect.sizeDelta.y);
//mainPanelRect.anchoredPosition = new Vector2(200, 0);
//mainPanelRect.offsetMin = new Vector2(mainPanelRect.offsetMin.x, 100); // bottom
//mainPanelRect.offsetMax = new Vector2(mainPanelRect.offsetMax.x, -50); // top
mainPanelRect.anchorMin = new Vector2(0.125f, 0.175f);
mainPanelRect.anchorMax = new Vector2(0.325f, 0.925f);
//mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 350);
}
public override void ConstructPanelContent()

View File

@ -77,7 +77,8 @@ namespace UnityExplorer.UI.Panels
// Instance
public bool AllowDragAndResize { get; set; }
public UIPanel UIPanel { get; private set; }
public bool AllowDragAndResize => UIPanel.CanDragAndResize;
public RectTransform Panel { get; set; }
public event Action<RectTransform> OnFinishResize;
@ -95,7 +96,7 @@ namespace UnityExplorer.UI.Panels
public static GameObject s_resizeCursorObj;
internal readonly Vector2 minResize = new Vector2(200, 50);
//internal readonly Vector2 minResize = new Vector2(200, 50);
private bool WasResizing { get; set; }
private ResizeTypes m_currentResizeType = ResizeTypes.NONE;
@ -109,8 +110,9 @@ namespace UnityExplorer.UI.Panels
private Rect m_totalResizeRect;
public PanelDragger(RectTransform dragArea, RectTransform panelToDrag)
public PanelDragger(RectTransform dragArea, RectTransform panelToDrag, UIPanel panel)
{
this.UIPanel = panel;
Instances.Add(this);
DragableArea = dragArea;
Panel = panelToDrag;
@ -417,12 +419,12 @@ namespace UnityExplorer.UI.Panels
Panel.anchorMin = new Vector2(anchorMin.x, anchorMin.y);
Panel.anchorMax = new Vector2(anchorMax.x, anchorMax.y);
if (Panel.rect.width < minResize.x)
if (Panel.rect.width < UIPanel.MinWidth)
{
Panel.anchorMin = new Vector2(prevMin.x, Panel.anchorMin.y);
Panel.anchorMax = new Vector2(prevMax.x, Panel.anchorMax.y);
}
if (Panel.rect.height < minResize.y)
if (Panel.rect.height < UIPanel.MinHeight)
{
Panel.anchorMin = new Vector2(Panel.anchorMin.x, prevMin.y);
Panel.anchorMax = new Vector2(Panel.anchorMax.x, prevMax.y);
@ -459,14 +461,4 @@ namespace UnityExplorer.UI.Panels
#endregion
}
// Just to allow Enum to do .HasFlag() in NET 3.5
public static class Net35FlagsEx
{
public static bool HasFlag(this Enum flags, Enum value)
{
ulong num = Convert.ToUInt64(value);
return (Convert.ToUInt64(flags) & num) == num;
}
}
}

View File

@ -75,6 +75,8 @@ namespace UnityExplorer.UI.Panels
public abstract UIManager.Panels PanelType { get; }
public abstract string Name { get; }
public abstract int MinWidth { get; }
public abstract int MinHeight { get; }
public virtual bool ShowByDefault => false;
public virtual bool ShouldSaveActiveState => true;
@ -126,6 +128,18 @@ namespace UnityExplorer.UI.Panels
base.Destroy();
}
protected internal abstract void DoSetDefaultPosAndAnchors();
public void SetTransformDefaults()
{
DoSetDefaultPosAndAnchors();
if (mainPanelRect.rect.width < MinWidth)
mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, MinWidth);
if (mainPanelRect.rect.height < MinHeight)
mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, MinHeight);
}
public void ConstructUI()
{
//this.Enabled = true;
@ -146,16 +160,16 @@ namespace UnityExplorer.UI.Panels
// create core canvas
uiRoot = UIFactory.CreatePanel(Name, out GameObject panelContent);
mainPanelRect = this.uiRoot.GetComponent<RectTransform>();
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(this.uiRoot, true, true, true, true, 0, 2, 2, 2, 2, TextAnchor.UpperLeft);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(this.uiRoot, false, false, true, true, 0, 2, 2, 2, 2, TextAnchor.UpperLeft);
int id = this.uiRoot.transform.GetInstanceID();
transformToPanelDict.Add(id, this);
content = panelContent;
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(this.content, true, true, true, true, 2, 2, 2, 2, 2, TextAnchor.UpperLeft);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(this.content, false, false, true, true, 2, 2, 2, 2, 2, TextAnchor.UpperLeft);
// always apply default pos and anchors (save data may only be partial)
SetDefaultPosAndAnchors();
SetTransformDefaults();
// Title bar
var titleGroup = UIFactory.CreateHorizontalGroup(content, "TitleBar", false, true, true, true, 2,
@ -165,11 +179,14 @@ namespace UnityExplorer.UI.Panels
// Title text
var titleTxt = UIFactory.CreateLabel(titleGroup, "TitleBar", Name, TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(titleTxt.gameObject, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999);
UIFactory.SetLayoutElement(titleTxt.gameObject, minWidth: 250, minHeight: 25, flexibleHeight: 0, flexibleWidth: 0);
// close button
var closeBtn = UIFactory.CreateButton(titleGroup, "CloseButton", "—");
var closeHolder = UIFactory.CreateUIObject("CloseHolder", titleGroup);
UIFactory.SetLayoutElement(closeHolder, minHeight: 25, flexibleHeight: 0, minWidth: 30, flexibleWidth: 9999);
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(closeHolder, false, false, true, true, 0, childAlignment: TextAnchor.MiddleRight);
var closeBtn = UIFactory.CreateButton(closeHolder, "CloseButton", "—");
UIFactory.SetLayoutElement(closeBtn.Button.gameObject, minHeight: 25, minWidth: 25, flexibleWidth: 0);
RuntimeProvider.Instance.SetColorBlock(closeBtn.Button, new Color(0.33f, 0.32f, 0.31f));
@ -184,15 +201,15 @@ namespace UnityExplorer.UI.Panels
// Panel dragger
Dragger = new PanelDragger(titleTxt.GetComponent<RectTransform>(), mainPanelRect);
Dragger = new PanelDragger(titleGroup.GetComponent<RectTransform>(), mainPanelRect, this);
Dragger.OnFinishResize += OnFinishResize;
Dragger.OnFinishDrag += OnFinishDrag;
Dragger.AllowDragAndResize = this.CanDragAndResize;
// content (abstract)
ConstructPanelContent();
UIManager.SetPanelActive(this.PanelType, true);
UIManager.SetPanelActive(this.PanelType, false);
UIManager.SetPanelActive(this.PanelType, ShowByDefault);
@ -200,15 +217,16 @@ namespace UnityExplorer.UI.Panels
// apply panel save data or revert to default
try
{
LoadSaveData();
Dragger.OnEndResize();
ApplySaveData(GetSaveData());
}
catch (Exception ex)
{
ExplorerCore.Log($"Exception loading panel save data: {ex}");
SetDefaultPosAndAnchors();
SetTransformDefaults();
}
Dragger.OnEndResize();
// simple listener for saving enabled state
this.OnToggleEnabled += (bool val) =>
{
@ -221,6 +239,8 @@ namespace UnityExplorer.UI.Panels
// SAVE DATA
public abstract void DoSaveToConfigElement();
public void SaveToConfigManager()
{
if (UIManager.Initializing)
@ -229,11 +249,7 @@ namespace UnityExplorer.UI.Panels
DoSaveToConfigElement();
}
public abstract void DoSaveToConfigElement();
public abstract void SetDefaultPosAndAnchors();
public abstract void LoadSaveData();
public abstract string GetSaveData();
public bool ApplyingSaveData { get; set; }
@ -268,7 +284,7 @@ namespace UnityExplorer.UI.Panels
catch
{
ExplorerCore.LogWarning("Invalid or corrupt panel save data! Restoring to default.");
SetDefaultPosAndAnchors();
SetTransformDefaults();
}
}
}