diff --git a/src/UI/CSConsole/ConsoleController.cs b/src/UI/CSConsole/ConsoleController.cs index 2bfb9a0..6e284a8 100644 --- a/src/UI/CSConsole/ConsoleController.cs +++ b/src/UI/CSConsole/ConsoleController.cs @@ -64,7 +64,7 @@ The following helper methods are available: private static HashSet usingDirectives; private static StringBuilder evaluatorOutput; - public static CSConsolePanel Panel => UIManager.CSharpConsole; + public static CSConsolePanel Panel => UIManager.GetPanel(UIManager.Panels.CSConsole); public static InputFieldRef Input => Panel.Input; public static int LastCaretPosition { get; private set; } diff --git a/src/UI/CSConsole/LexerBuilder.cs b/src/UI/CSConsole/LexerBuilder.cs index 727e998..b4443f0 100644 --- a/src/UI/CSConsole/LexerBuilder.cs +++ b/src/UI/CSConsole/LexerBuilder.cs @@ -299,6 +299,7 @@ namespace UnityExplorer.UI.CSConsole // lower the indent level by one as we would not have accounted for this closing symbol indent--; + // go back from the caret to the start of the line, calculate how much indent we need to adjust. while (CurrentIndex > 0) { CurrentIndex--; diff --git a/src/UI/CacheObject/CacheConfigEntry.cs b/src/UI/CacheObject/CacheConfigEntry.cs new file mode 100644 index 0000000..4060d4c --- /dev/null +++ b/src/UI/CacheObject/CacheConfigEntry.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityExplorer.Core.Config; +using UnityExplorer.UI.CacheObject.Views; + +namespace UnityExplorer.UI.CacheObject +{ + public class CacheConfigEntry : CacheObjectBase + { + public CacheConfigEntry(IConfigElement configElement) + { + this.RefConfigElement = configElement; + + this.NameLabelText = $"{configElement.Name}" + + $"\r\n{configElement.Description}"; + + this.FallbackType = configElement.ElementType; + + configElement.OnValueChangedNotify += UpdateValueFromSource; + } + + public IConfigElement RefConfigElement; + + public override bool ShouldAutoEvaluate => true; + public override bool HasArguments => false; + public override bool CanWrite => true; + + public void UpdateValueFromSource() + { + if (RefConfigElement.BoxedValue.Equals(this.Value)) + return; + + SetValueFromSource(RefConfigElement.BoxedValue); + } + + public override void TrySetUserValue(object value) + { + this.Value = value; + RefConfigElement.BoxedValue = value; + } + + protected override bool SetCellEvaluateState(CacheObjectCell cell) => false; + } +} diff --git a/src/UI/CacheObject/CacheObjectBase.cs b/src/UI/CacheObject/CacheObjectBase.cs index fd1d526..75620fa 100644 --- a/src/UI/CacheObject/CacheObjectBase.cs +++ b/src/UI/CacheObject/CacheObjectBase.cs @@ -349,7 +349,8 @@ namespace UnityExplorer.UI.CacheObject cell.ApplyButton.Component.gameObject.SetActive(args.applyActive); // Inspect button only if last value not null. - cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull); + if (cell.InspectButton != null) + cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull); // allow IValue for null strings though cell.SubContentButton.Component.gameObject.SetActive(args.subContentButtonActive && (!LastValueWasNull || State == ValueState.String)); diff --git a/src/UI/CacheObject/Views/CacheConfigCell.cs b/src/UI/CacheObject/Views/CacheConfigCell.cs new file mode 100644 index 0000000..cf1c30e --- /dev/null +++ b/src/UI/CacheObject/Views/CacheConfigCell.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; +using UnityEngine.UI; + +namespace UnityExplorer.UI.CacheObject.Views +{ + public class ConfigEntryCell : CacheObjectCell + { + public override GameObject CreateContent(GameObject parent) + { + // Main layout + + UIRoot = UIFactory.CreateUIObject(this.GetType().Name, parent, new Vector2(100, 30)); + Rect = UIRoot.GetComponent(); + UIFactory.SetLayoutGroup(UIRoot, false, false, true, true, 4, 4, 4, 4, 4, childAlignment: TextAnchor.UpperLeft); + UIFactory.SetLayoutElement(UIRoot, minWidth: 100, flexibleWidth: 9999, minHeight: 30, flexibleHeight: 600); + UIRoot.AddComponent().verticalFit = ContentSizeFitter.FitMode.PreferredSize; + + // Left label + + NameLabel = UIFactory.CreateLabel(UIRoot, "NameLabel", "", TextAnchor.MiddleLeft); + NameLabel.horizontalOverflow = HorizontalWrapMode.Wrap; + UIFactory.SetLayoutElement(NameLabel.gameObject, minHeight: 25, flexibleWidth: 9999, flexibleHeight: 300); + NameLayout = NameLabel.GetComponent(); + + // horizontal group + + var horiGroup = UIFactory.CreateUIObject("RightHoriGroup", UIRoot); + UIFactory.SetLayoutGroup(horiGroup, false, false, true, true, 4, childAlignment: TextAnchor.UpperLeft); + UIFactory.SetLayoutElement(horiGroup, minHeight: 25, minWidth: 200, flexibleWidth: 9999, flexibleHeight: 800); + + SubContentButton = UIFactory.CreateButton(horiGroup, "SubContentButton", "▲", subInactiveColor); + UIFactory.SetLayoutElement(SubContentButton.Component.gameObject, minWidth: 25, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0); + SubContentButton.OnClick += SubContentClicked; + + // Type label + + TypeLabel = UIFactory.CreateLabel(horiGroup, "TypeLabel", "", TextAnchor.MiddleLeft); + TypeLabel.horizontalOverflow = HorizontalWrapMode.Wrap; + UIFactory.SetLayoutElement(TypeLabel.gameObject, minHeight: 25, flexibleHeight: 150, minWidth: 60, flexibleWidth: 0); + + // Bool and number value interaction + + var toggleObj = UIFactory.CreateToggle(horiGroup, "Toggle", out Toggle, out ToggleText); + UIFactory.SetLayoutElement(toggleObj, minWidth: 70, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0); + ToggleText.color = SignatureHighlighter.KeywordBlue; + Toggle.onValueChanged.AddListener(ToggleClicked); + + InputField = UIFactory.CreateInputField(horiGroup, "InputField", "..."); + UIFactory.SetLayoutElement(InputField.UIRoot, minWidth: 150, flexibleWidth: 0, minHeight: 25, flexibleHeight: 0); + + // Apply + + ApplyButton = UIFactory.CreateButton(horiGroup, "ApplyButton", "Apply", new Color(0.15f, 0.19f, 0.15f)); + UIFactory.SetLayoutElement(ApplyButton.Component.gameObject, minWidth: 70, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0); + ApplyButton.OnClick += ApplyClicked; + + // Main value label + + ValueLabel = UIFactory.CreateLabel(horiGroup, "ValueLabel", "Value goes here", TextAnchor.MiddleLeft); + ValueLabel.horizontalOverflow = HorizontalWrapMode.Wrap; + UIFactory.SetLayoutElement(ValueLabel.gameObject, minHeight: 25, flexibleHeight: 150, flexibleWidth: 9999); + + // Subcontent + + SubContentHolder = UIFactory.CreateUIObject("SubContent", UIRoot); + UIFactory.SetLayoutElement(SubContentHolder.gameObject, minHeight: 30, flexibleHeight: 600, minWidth: 100, flexibleWidth: 9999); + UIFactory.SetLayoutGroup(SubContentHolder, true, true, true, true, 2, childAlignment: TextAnchor.UpperLeft); + //SubContentHolder.AddComponent().verticalFit = ContentSizeFitter.FitMode.MinSize; + SubContentHolder.SetActive(false); + + // Bottom separator + var separator = UIFactory.CreateUIObject("BottomSeperator", UIRoot); + UIFactory.SetLayoutElement(separator, minHeight: 1, flexibleHeight: 0, flexibleWidth: 9999); + separator.AddComponent().color = Color.black; + + return UIRoot; + } + + protected override void ConstructEvaluateHolder(GameObject parent) { } + } +} diff --git a/src/UI/CacheObject/Views/CacheObjectCell.cs b/src/UI/CacheObject/Views/CacheObjectCell.cs index 7adc597..afb029c 100644 --- a/src/UI/CacheObject/Views/CacheObjectCell.cs +++ b/src/UI/CacheObject/Views/CacheObjectCell.cs @@ -78,8 +78,8 @@ namespace UnityExplorer.UI.CacheObject.Views this.Occupant.OnCellSubContentToggle(); } - private readonly Color subInactiveColor = new Color(0.23f, 0.23f, 0.23f); - private readonly Color subActiveColor = new Color(0.23f, 0.33f, 0.23f); + public readonly Color subInactiveColor = new Color(0.23f, 0.23f, 0.23f); + public readonly Color subActiveColor = new Color(0.23f, 0.33f, 0.23f); public void RefreshSubcontentButton() { @@ -113,9 +113,9 @@ namespace UnityExplorer.UI.CacheObject.Views UIFactory.SetLayoutGroup(horiRow, false, false, true, true, 5, 2, childAlignment: TextAnchor.UpperLeft); horiRow.AddComponent().verticalFit = ContentSizeFitter.FitMode.PreferredSize; - // Left member label + // Left name label - NameLabel = UIFactory.CreateLabel(horiRow, "MemberLabel", "", TextAnchor.MiddleLeft); + NameLabel = UIFactory.CreateLabel(horiRow, "NameLabel", "", TextAnchor.MiddleLeft); NameLabel.horizontalOverflow = HorizontalWrapMode.Wrap; UIFactory.SetLayoutElement(NameLabel.gameObject, minHeight: 25, minWidth: 20, flexibleHeight: 300, flexibleWidth: 0); NameLayout = NameLabel.GetComponent(); diff --git a/src/UI/IValues/InteractiveDictionary.cs b/src/UI/IValues/InteractiveDictionary.cs index dff20a2..e91dcad 100644 --- a/src/UI/IValues/InteractiveDictionary.cs +++ b/src/UI/IValues/InteractiveDictionary.cs @@ -13,7 +13,7 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.IValues { - public class InteractiveDictionary : InteractiveValue, IPoolDataSource, ICacheObjectController + public class InteractiveDictionary : InteractiveValue, ICellPoolDataSource, ICacheObjectController { CacheObjectBase ICacheObjectController.ParentCacheObject => this.CurrentOwner; object ICacheObjectController.Target => this.CurrentOwner.Value; diff --git a/src/UI/IValues/InteractiveList.cs b/src/UI/IValues/InteractiveList.cs index 19a823b..7e6c514 100644 --- a/src/UI/IValues/InteractiveList.cs +++ b/src/UI/IValues/InteractiveList.cs @@ -13,7 +13,7 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.IValues { - public class InteractiveList : InteractiveValue, IPoolDataSource, ICacheObjectController + public class InteractiveList : InteractiveValue, ICellPoolDataSource, ICacheObjectController { CacheObjectBase ICacheObjectController.ParentCacheObject => this.CurrentOwner; object ICacheObjectController.Target => this.CurrentOwner.Value; diff --git a/src/UI/Inspectors/ReflectionInspector.cs b/src/UI/Inspectors/ReflectionInspector.cs index fccd3c5..b77a1b0 100644 --- a/src/UI/Inspectors/ReflectionInspector.cs +++ b/src/UI/Inspectors/ReflectionInspector.cs @@ -18,7 +18,7 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Inspectors { - public class ReflectionInspector : InspectorBase, IPoolDataSource, ICacheObjectController + public class ReflectionInspector : InspectorBase, ICellPoolDataSource, ICacheObjectController { public CacheObjectBase ParentCacheObject { get; set; } public Type TargetType { get; private set; } @@ -95,7 +95,7 @@ namespace UnityExplorer.UI.Inspectors autoUpdateToggle.isOn = false; AutoUpdateWanted = false; - ObjectRef = null; + UnityObjectRef = null; ComponentRef = null; TextureRef = null; CleanupTextureViewer(); @@ -193,6 +193,17 @@ namespace UnityExplorer.UI.Inspectors } } + public void UpdateClicked() + { + UpdateDisplayedMembers(); + + if (this.UnityObjectRef) + { + nameInput.Text = UnityObjectRef.name; + instanceIdInput.Text = UnityObjectRef.GetInstanceID().ToString(); + } + } + // Filtering public void SetFilter(string filter) => SetFilter(filter, FlagsFilter); @@ -378,7 +389,7 @@ namespace UnityExplorer.UI.Inspectors var updateButton = UIFactory.CreateButton(rowObj, "UpdateButton", "Update displayed values", new Color(0.22f, 0.28f, 0.22f)); UIFactory.SetLayoutElement(updateButton.Component.gameObject, minHeight: 25, minWidth: 175, flexibleWidth: 0); - updateButton.OnClick += UpdateDisplayedMembers; + updateButton.OnClick += UpdateClicked; var toggleObj = UIFactory.CreateToggle(rowObj, "AutoUpdateToggle", out autoUpdateToggle, out Text toggleText); //GameObject.DestroyImmediate(toggleText); @@ -455,7 +466,7 @@ namespace UnityExplorer.UI.Inspectors // Unity object helpers - private UnityEngine.Object ObjectRef; + private UnityEngine.Object UnityObjectRef; private Component ComponentRef; private Texture2D TextureRef; private bool TextureViewerWanted; @@ -475,11 +486,11 @@ namespace UnityExplorer.UI.Inspectors return; } - ObjectRef = (UnityEngine.Object)Target.TryCast(typeof(UnityEngine.Object)); + UnityObjectRef = (UnityEngine.Object)Target.TryCast(typeof(UnityEngine.Object)); unityObjectRow.SetActive(true); - nameInput.Text = ObjectRef.name; - instanceIdInput.Text = ObjectRef.GetInstanceID().ToString(); + nameInput.Text = UnityObjectRef.name; + instanceIdInput.Text = UnityObjectRef.GetInstanceID().ToString(); if (typeof(Component).IsAssignableFrom(TargetType)) { @@ -515,7 +526,7 @@ namespace UnityExplorer.UI.Inspectors { // disable TextureViewerWanted = false; - textureViewer.gameObject.SetActive(false); + textureViewer.SetActive(false); mainContentHolder.SetActive(true); textureButton.ButtonText.text = "View Texture"; } @@ -529,7 +540,7 @@ namespace UnityExplorer.UI.Inspectors // enable TextureViewerWanted = true; - textureViewer.gameObject.SetActive(true); + textureViewer.SetActive(true); mainContentHolder.gameObject.SetActive(false); textureButton.ButtonText.text = "Hide Texture"; } diff --git a/src/UI/Panels/CSConsolePanel.cs b/src/UI/Panels/CSConsolePanel.cs index f57bbab..787ecbb 100644 --- a/src/UI/Panels/CSConsolePanel.cs +++ b/src/UI/Panels/CSConsolePanel.cs @@ -54,7 +54,7 @@ namespace UnityExplorer.UI.Panels ConfigManager.CSConsoleData.Value = this.ToSaveData(); } - public override string GetSaveData() => ConfigManager.CSConsoleData.Value; + public override string GetSaveDataFromConfigManager() => ConfigManager.CSConsoleData.Value; // UI Construction diff --git a/src/UI/Panels/ConsoleLogPanel.cs b/src/UI/Panels/ConsoleLogPanel.cs index dc9e167..7bc22e8 100644 --- a/src/UI/Panels/ConsoleLogPanel.cs +++ b/src/UI/Panels/ConsoleLogPanel.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using UnityEngine; +using UnityExplorer.Core.Config; namespace UnityExplorer.UI.Panels { @@ -13,24 +15,27 @@ namespace UnityExplorer.UI.Panels public override int MinWidth => 300; public override int MinHeight => 75; - public override void ConstructPanelContent() + public override string GetSaveDataFromConfigManager() { - throw new NotImplementedException(); + return ConfigManager.ConsoleLogData.Value; } public override void DoSaveToConfigElement() { - throw new NotImplementedException(); - } - - public override string GetSaveData() - { - throw new NotImplementedException(); + ConfigManager.ConsoleLogData.Value = this.ToSaveData(); } protected internal override void DoSetDefaultPosAndAnchors() { - throw new NotImplementedException(); + mainPanelRect.localPosition = Vector2.zero; + mainPanelRect.pivot = new Vector2(0f, 1f); + mainPanelRect.anchorMin = new Vector2(0.5f, 0.1f); + mainPanelRect.anchorMax = new Vector2(0.9f, 0.25f); + } + + public override void ConstructPanelContent() + { + } } } diff --git a/src/UI/Panels/InspectorPanel.cs b/src/UI/Panels/InspectorPanel.cs index 513ea64..befdc97 100644 --- a/src/UI/Panels/InspectorPanel.cs +++ b/src/UI/Panels/InspectorPanel.cs @@ -42,7 +42,7 @@ namespace UnityExplorer.UI.Panels InspectorManager.OnPanelResized(panel.rect.width); } - public override string GetSaveData() => ConfigManager.InspectorData.Value; + public override string GetSaveDataFromConfigManager() => ConfigManager.InspectorData.Value; //public override void LoadSaveData() //{ diff --git a/src/UI/Panels/ObjectExplorerPanel.cs b/src/UI/Panels/ObjectExplorerPanel.cs index 1e8a343..9d32e89 100644 --- a/src/UI/Panels/ObjectExplorerPanel.cs +++ b/src/UI/Panels/ObjectExplorerPanel.cs @@ -63,7 +63,7 @@ namespace UnityExplorer.UI.Panels ObjectSearch.Update(); } - public override string GetSaveData() => ConfigManager.ObjectExplorerData.Value; + public override string GetSaveDataFromConfigManager() => ConfigManager.ObjectExplorerData.Value; public override void DoSaveToConfigElement() { diff --git a/src/UI/Panels/OptionsPanel.cs b/src/UI/Panels/OptionsPanel.cs index aff3f95..3c32acf 100644 --- a/src/UI/Panels/OptionsPanel.cs +++ b/src/UI/Panels/OptionsPanel.cs @@ -2,35 +2,97 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using UnityEngine; +using UnityEngine.UI; +using UnityExplorer.Core.Config; +using UnityExplorer.UI.CacheObject; +using UnityExplorer.UI.CacheObject.Views; +using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Panels { - public class OptionsPanel : UIPanel + public class OptionsPanel : UIPanel, ICacheObjectController, ICellPoolDataSource { public override string Name => "Options"; public override UIManager.Panels PanelType => UIManager.Panels.Options; - public override int MinWidth => 400; + public override int MinWidth => 550; public override int MinHeight => 200; - public override void ConstructPanelContent() + public override bool ShouldSaveActiveState => false; + public override bool ShowByDefault => false; + + // Entry holders + private readonly List configEntries = new List(); + + // ICacheObjectController + public CacheObjectBase ParentCacheObject => null; + public object Target => null; + public Type TargetType => null; + public bool CanWrite => true; + + // ICellPoolDataSource + public int ItemCount => configEntries.Count; + + public OptionsPanel() { - throw new NotImplementedException(); + foreach (var entry in ConfigManager.ConfigElements) + { + var cache = new CacheConfigEntry(entry.Value); + cache.Owner = this; + configEntries.Add(cache); + } + } + + public void OnCellBorrowed(ConfigEntryCell cell) + { + } + + public void SetCell(ConfigEntryCell cell, int index) + { + CacheObjectControllerHelper.SetCell(cell, index, this.configEntries, null); + } + + // Panel save data + + public override string GetSaveDataFromConfigManager() + { + return ConfigManager.OptionsPanelData.Value; } public override void DoSaveToConfigElement() { - throw new NotImplementedException(); - } - - public override string GetSaveData() - { - throw new NotImplementedException(); + ConfigManager.OptionsPanelData.Value = this.ToSaveData(); } protected internal override void DoSetDefaultPosAndAnchors() { - throw new NotImplementedException(); + mainPanelRect.localPosition = Vector2.zero; + mainPanelRect.pivot = new Vector2(0.5f, 1f); + mainPanelRect.anchorMin = new Vector2(0.5f, 0.1f); + mainPanelRect.anchorMax = new Vector2(0.5f, 0.85f); + mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 550f); + } + + // UI Construction + + public override void ConstructPanelContent() + { + // Save button + + var saveBtn = UIFactory.CreateButton(this.content, "Save", "Save Options", new Color(0.25f, 0.3f, 0.25f)); + UIFactory.SetLayoutElement(saveBtn.Component.gameObject, flexibleWidth: 9999, minHeight: 30, flexibleHeight: 0); + saveBtn.OnClick += ConfigManager.Handler.SaveConfig; + + // Config entries + + var scrollPool = UIFactory.CreateScrollPool(this.content, "ConfigEntries", out GameObject scrollObj, + out GameObject scrollContent); + + scrollPool.Initialize(this); + + foreach (var config in configEntries) + config.UpdateValueFromSource(); } } } diff --git a/src/UI/Panels/UIPanel.cs b/src/UI/Panels/UIPanel.cs index 95fd4e5..3b2091c 100644 --- a/src/UI/Panels/UIPanel.cs +++ b/src/UI/Panels/UIPanel.cs @@ -220,7 +220,7 @@ namespace UnityExplorer.UI.Panels // apply panel save data or revert to default try { - ApplySaveData(GetSaveData()); + ApplySaveData(GetSaveDataFromConfigManager()); } catch (Exception ex) { @@ -252,7 +252,7 @@ namespace UnityExplorer.UI.Panels DoSaveToConfigElement(); } - public abstract string GetSaveData(); + public abstract string GetSaveDataFromConfigManager(); public bool ApplyingSaveData { get; set; } diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index cc4186b..0a5510b 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -39,14 +39,7 @@ namespace UnityExplorer.UI // panels internal static GameObject PanelHolder { get; private set; } - - public static ObjectExplorerPanel Explorer { get; private set; } - public static InspectorPanel Inspector { get; private set; } - public static CSConsolePanel CSharpConsole { get; private set; } - public static OptionsPanel Options { get; private set; } - public static ConsoleLogPanel ConsoleLog { get; private set; } - - public static AutoCompleteModal AutoCompleter { get; private set; } + private static readonly Dictionary UIPanels = new Dictionary(); // assets internal static Font ConsoleFont { get; private set; } @@ -62,24 +55,6 @@ namespace UnityExplorer.UI public const int MAX_INPUTFIELD_CHARS = 16000; public const int MAX_TEXT_VERTS = 65000; - public static UIPanel GetPanel(Panels panel) - { - switch (panel) - { - case Panels.ObjectExplorer: - return Explorer; - case Panels.Inspector: - return Inspector; - case Panels.AutoCompleter: - return AutoCompleter; - case Panels.CSConsole: - return CSharpConsole; - default: - throw new NotImplementedException($"TODO GetPanel: {panel}"); - } - } - - // main menu toggle public static bool ShowMenu { get => s_showMenu; @@ -95,34 +70,16 @@ namespace UnityExplorer.UI } public static bool s_showMenu = true; - public static void Update() + // Panels + + public static UIPanel GetPanel(Panels panel) { - if (!CanvasRoot || Initializing) - return; + return UIPanels[panel]; + } - //if (InspectUnderMouse.Inspecting) - //{ - // InspectUnderMouse.UpdateInspect(); - // return; - //} - - if (InputManager.GetKeyDown(ConfigManager.Main_Menu_Toggle.Value)) - ShowMenu = !ShowMenu; - - if (!ShowMenu) - return; - - gcLabel.text = "GC : " + (GC.GetTotalMemory(false) / 1024 / 1024) + "MB"; - - if (InputManager.GetKeyDown(ConfigManager.Force_Unlock_Keybind.Value)) - CursorUnlocker.Unlock = !CursorUnlocker.Unlock; - - if (EventSystem.current != EventSys) - CursorUnlocker.SetEventSystem(); - - UIPanel.UpdateFocus(); - PanelDragger.UpdateInstances(); - UIBehaviourModel.UpdateInstances(); + public static T GetPanel(Panels panel) where T : UIPanel + { + return (T)UIPanels[panel]; } public static void TogglePanel(Panels panel) @@ -153,6 +110,38 @@ namespace UnityExplorer.UI SetPanelActive(panel, value); } + // Main UI Update loop + + public static void Update() + { + if (!CanvasRoot || Initializing) + return; + + //if (InspectUnderMouse.Inspecting) + //{ + // InspectUnderMouse.UpdateInspect(); + // return; + //} + + if (InputManager.GetKeyDown(ConfigManager.Main_Menu_Toggle.Value)) + ShowMenu = !ShowMenu; + + if (!ShowMenu) + return; + + if (InputManager.GetKeyDown(ConfigManager.Force_Unlock_Toggle.Value)) + CursorUnlocker.Unlock = !CursorUnlocker.Unlock; + + if (EventSystem.current != EventSys) + CursorUnlocker.SetEventSystem(); + + UIPanel.UpdateFocus(); + PanelDragger.UpdateInstances(); + UIBehaviourModel.UpdateInstances(); + } + + // Initialization and UI Construction + internal static void InitUI() { LoadBundle(); @@ -161,33 +150,28 @@ namespace UnityExplorer.UI CreateRootCanvas(); + // Global UI Pool Holder PoolHolder = new GameObject("PoolHolder"); PoolHolder.transform.parent = CanvasRoot.transform; PoolHolder.SetActive(false); CreateTopNavBar(); + // TODO (or probably just do this when showing it for first time) //InspectUnderMouse.ConstructUI(); - AutoCompleter = new AutoCompleteModal(); - AutoCompleter.ConstructUI(); + UIPanels.Add(Panels.AutoCompleter, new AutoCompleteModal()); + UIPanels.Add(Panels.ObjectExplorer, new ObjectExplorerPanel()); + UIPanels.Add(Panels.Inspector, new InspectorPanel()); + UIPanels.Add(Panels.CSConsole, new CSConsolePanel()); + UIPanels.Add(Panels.Options, new OptionsPanel()); + UIPanels.Add(Panels.ConsoleLog, new ConsoleLogPanel()); - Explorer = new ObjectExplorerPanel(); - Explorer.ConstructUI(); + foreach (var panel in UIPanels.Values) + panel.ConstructUI(); - Inspector = new InspectorPanel(); - Inspector.ConstructUI(); - - CSharpConsole = new CSConsolePanel(); - CSharpConsole.ConstructUI(); ConsoleController.Init(); - Options = new OptionsPanel(); - Options.ConstructUI(); - - ConsoleLog = new ConsoleLogPanel(); - ConsoleLog.ConstructUI(); - ShowMenu = !ConfigManager.Hide_On_Startup.Value; ExplorerCore.Log("UI initialized."); @@ -228,12 +212,6 @@ namespace UnityExplorer.UI PanelHolder.transform.SetAsFirstSibling(); } - //// temp - //private static float lastTimeSpeed; - //private static bool pausing; - - private static Text gcLabel; - private static void CreateTopNavBar() { var navbarPanel = UIFactory.CreateUIObject("MainNavbar", CanvasRoot); @@ -243,7 +221,7 @@ namespace UnityExplorer.UI NavBarRect.pivot = new Vector2(0.5f, 1f); NavBarRect.anchorMin = new Vector2(0.5f, 1f); NavBarRect.anchorMax = new Vector2(0.5f, 1f); - NavBarRect.sizeDelta = new Vector2(900f, 35f); + NavBarRect.sizeDelta = new Vector2(1000f, 35f); // UnityExplorer title @@ -251,32 +229,6 @@ namespace UnityExplorer.UI var title = UIFactory.CreateLabel(navbarPanel, "Title", titleTxt, TextAnchor.MiddleLeft, default, true, 18); UIFactory.SetLayoutElement(title.gameObject, minWidth: 240, flexibleWidth: 0); - // temp debug - - gcLabel = UIFactory.CreateLabel(navbarPanel, "GCLabel", "GC: ", TextAnchor.MiddleLeft); - UIFactory.SetLayoutElement(gcLabel.gameObject, minWidth: 150, minHeight: 25, flexibleWidth: 0); - - // TODO something nicer for this, maybe a 'Tools' dropout below the main navbar with a few helpers like this. - - //var btn = UIFactory.CreateButton(navbarPanel, "Button", "pause", new Color(0.2f, 0.2f, 0.2f)); - //UIFactory.SetLayoutElement(btn.Button.gameObject, minWidth: 30, flexibleWidth: 0, minHeight: 25); - //btn.OnClick += () => - //{ - // if (!pausing) - // { - // lastTimeSpeed = Time.timeScale; - // Time.timeScale = 0; - // pausing = true; - // btn.ButtonText.text = "resume"; - // } - // else - // { - // Time.timeScale = lastTimeSpeed; - // pausing = false; - // btn.ButtonText.text = "pause"; - // } - //}; - // Navbar NavbarButtonHolder = UIFactory.CreateUIObject("NavButtonHolder", navbarPanel); diff --git a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs index 7c3e0ec..439bad1 100644 --- a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs +++ b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs @@ -18,7 +18,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete public class AutoCompleteModal : UIPanel { - public static AutoCompleteModal Instance => UIManager.AutoCompleter; + public static AutoCompleteModal Instance => UIManager.GetPanel(UIManager.Panels.AutoCompleter); public override string Name => "AutoCompleter"; public override UIManager.Panels PanelType => UIManager.Panels.AutoCompleter; @@ -201,6 +201,6 @@ namespace UnityExplorer.UI.Widgets.AutoComplete // not savable } - public override string GetSaveData() => null; + public override string GetSaveDataFromConfigManager() => null; } } diff --git a/src/UI/Widgets/ButtonList/ButtonListSource.cs b/src/UI/Widgets/ButtonList/ButtonListSource.cs index 71bbe08..c11e04b 100644 --- a/src/UI/Widgets/ButtonList/ButtonListSource.cs +++ b/src/UI/Widgets/ButtonList/ButtonListSource.cs @@ -10,7 +10,7 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Widgets { - public class ButtonListSource : IPoolDataSource + public class ButtonListSource : ICellPoolDataSource { internal ScrollPool ScrollPool; diff --git a/src/UI/Widgets/ScrollPool/IPoolDataSource.cs b/src/UI/Widgets/ScrollPool/ICellPoolDataSource.cs similarity index 85% rename from src/UI/Widgets/ScrollPool/IPoolDataSource.cs rename to src/UI/Widgets/ScrollPool/ICellPoolDataSource.cs index f456a77..dbf5272 100644 --- a/src/UI/Widgets/ScrollPool/IPoolDataSource.cs +++ b/src/UI/Widgets/ScrollPool/ICellPoolDataSource.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace UnityExplorer.UI.Widgets { - public interface IPoolDataSource where T : ICell + public interface ICellPoolDataSource where T : ICell { int ItemCount { get; } diff --git a/src/UI/Widgets/ScrollPool/ScrollPool.cs b/src/UI/Widgets/ScrollPool/ScrollPool.cs index ed69dc7..bcd5365 100644 --- a/src/UI/Widgets/ScrollPool/ScrollPool.cs +++ b/src/UI/Widgets/ScrollPool/ScrollPool.cs @@ -27,7 +27,7 @@ namespace UnityExplorer.UI.Widgets this.ScrollRect = scrollRect; } - public IPoolDataSource DataSource { get; set; } + public ICellPoolDataSource DataSource { get; set; } public readonly List CellPool = new List(); @@ -143,7 +143,7 @@ namespace UnityExplorer.UI.Widgets //private bool Initialized; /// Should be called only once, when the scroll pool is created. - public void Initialize(IPoolDataSource dataSource, Action onHeightChangedListener = null) + public void Initialize(ICellPoolDataSource dataSource, Action onHeightChangedListener = null) { this.DataSource = dataSource; HeightCache = new DataHeightCache(this); diff --git a/src/UI/Widgets/TransformTree/TransformTree.cs b/src/UI/Widgets/TransformTree/TransformTree.cs index 62c3e96..fea5677 100644 --- a/src/UI/Widgets/TransformTree/TransformTree.cs +++ b/src/UI/Widgets/TransformTree/TransformTree.cs @@ -11,7 +11,7 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Widgets { - public class TransformTree : IPoolDataSource + public class TransformTree : ICellPoolDataSource { public Func> GetRootEntriesMethod; diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index 8b6123c..a46d055 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -216,6 +216,8 @@ + + @@ -319,7 +321,7 @@ - +