2022-01-22 20:20:44 +11:00
|
|
|
|
using System.Collections.Generic;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
using UnityEngine;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
using UnityEngine.UI;
|
2022-01-17 19:42:05 +11:00
|
|
|
|
using UnityExplorer.Config;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.CSConsole;
|
|
|
|
|
using UnityExplorer.Inspectors;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
using UnityExplorer.UI.Panels;
|
2022-05-10 01:44:08 +10:00
|
|
|
|
using UnityExplorer.UI.Widgets;
|
2021-04-23 21:50:58 +10:00
|
|
|
|
using UnityExplorer.UI.Widgets.AutoComplete;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib;
|
|
|
|
|
using UniverseLib.Input;
|
|
|
|
|
using UniverseLib.UI;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.UI.Models;
|
2022-04-14 01:25:59 +10:00
|
|
|
|
using UniverseLib.UI.Panels;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.UI.Widgets.ScrollView;
|
|
|
|
|
using UniverseLib.Utility;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
|
2020-11-03 20:59:13 +11:00
|
|
|
|
namespace UnityExplorer.UI
|
2020-10-23 01:50:33 +11:00
|
|
|
|
{
|
|
|
|
|
public static class UIManager
|
|
|
|
|
{
|
2021-04-23 21:50:58 +10:00
|
|
|
|
public enum Panels
|
|
|
|
|
{
|
|
|
|
|
ObjectExplorer,
|
|
|
|
|
Inspector,
|
|
|
|
|
CSConsole,
|
|
|
|
|
Options,
|
|
|
|
|
ConsoleLog,
|
2021-05-15 06:23:13 +10:00
|
|
|
|
AutoCompleter,
|
2021-09-06 17:10:01 +10:00
|
|
|
|
UIInspectorResults,
|
2021-09-06 23:04:40 +10:00
|
|
|
|
HookManager,
|
2022-04-18 21:39:17 +10:00
|
|
|
|
Clipboard,
|
|
|
|
|
Freecam
|
2021-04-23 21:50:58 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 21:45:09 +10:00
|
|
|
|
public enum VerticalAnchor
|
|
|
|
|
{
|
|
|
|
|
Top,
|
|
|
|
|
Bottom
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static VerticalAnchor NavbarAnchor = VerticalAnchor.Top;
|
|
|
|
|
|
2021-12-02 18:35:46 +11:00
|
|
|
|
public static bool Initializing { get; internal set; } = true;
|
|
|
|
|
|
2022-01-22 20:20:44 +11:00
|
|
|
|
internal static UIBase UiBase { get; private set; }
|
|
|
|
|
public static GameObject UIRoot => UiBase?.RootObject;
|
|
|
|
|
public static RectTransform UIRootRect { get; private set; }
|
|
|
|
|
public static Canvas UICanvas { get; private set; }
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2022-04-14 01:25:59 +10:00
|
|
|
|
internal static readonly Dictionary<Panels, UEPanel> UIPanels = new();
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-03 21:02:01 +10:00
|
|
|
|
public static RectTransform NavBarRect;
|
2021-05-28 16:39:42 +10:00
|
|
|
|
public static GameObject NavbarTabButtonHolder;
|
2022-01-18 20:19:20 +11:00
|
|
|
|
private static readonly Vector2 NAVBAR_DIMENSIONS = new(1020f, 35f);
|
2021-05-03 21:02:01 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static ButtonRef closeBtn;
|
2022-05-10 01:44:08 +10:00
|
|
|
|
private static TimeScaleWidget timeScaleWidget;
|
2021-05-28 16:39:42 +10:00
|
|
|
|
|
2022-01-18 20:19:20 +11:00
|
|
|
|
private static int lastScreenWidth;
|
|
|
|
|
private static int lastScreenHeight;
|
|
|
|
|
|
2021-03-11 17:57:58 +11:00
|
|
|
|
public static bool ShowMenu
|
|
|
|
|
{
|
2022-01-22 20:20:44 +11:00
|
|
|
|
get => UiBase != null && UiBase.Enabled;
|
2021-04-15 20:18:03 +10:00
|
|
|
|
set
|
2021-03-11 17:57:58 +11:00
|
|
|
|
{
|
2022-01-22 20:20:44 +11:00
|
|
|
|
if (UiBase == null || !UIRoot || UiBase.Enabled == value)
|
2021-03-30 19:50:04 +11:00
|
|
|
|
return;
|
|
|
|
|
|
2021-12-02 18:35:46 +11:00
|
|
|
|
UniversalUI.SetUIActive(ExplorerCore.GUID, value);
|
2022-03-04 00:20:04 +11:00
|
|
|
|
UniversalUI.SetUIActive(MouseInspector.UIBaseGUID, value);
|
2021-03-11 17:57:58 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// Initialization
|
|
|
|
|
|
|
|
|
|
internal static void InitUI()
|
|
|
|
|
{
|
2022-04-14 01:25:59 +10:00
|
|
|
|
UiBase = UniversalUI.RegisterUI<ExplorerUIBase>(ExplorerCore.GUID, Update);
|
2021-05-28 16:39:42 +10:00
|
|
|
|
|
2022-01-22 20:20:44 +11:00
|
|
|
|
UIRootRect = UIRoot.GetComponent<RectTransform>();
|
|
|
|
|
UICanvas = UIRoot.GetComponent<Canvas>();
|
2021-05-28 16:39:42 +10:00
|
|
|
|
|
2022-01-22 20:20:44 +11:00
|
|
|
|
DisplayManager.Init();
|
|
|
|
|
|
2022-03-23 18:04:27 +11:00
|
|
|
|
Display display = DisplayManager.ActiveDisplay;
|
2022-01-22 20:20:44 +11:00
|
|
|
|
lastScreenWidth = display.renderingWidth;
|
|
|
|
|
lastScreenHeight = display.renderingHeight;
|
2022-01-18 20:19:20 +11:00
|
|
|
|
|
2022-01-17 21:00:55 +11:00
|
|
|
|
// Create UI.
|
2021-05-28 16:39:42 +10:00
|
|
|
|
CreateTopNavBar();
|
2022-01-17 21:00:55 +11:00
|
|
|
|
// This could be automated with Assembly.GetTypes(),
|
|
|
|
|
// but the order is important and I'd have to write something to handle the order.
|
2022-04-14 01:25:59 +10:00
|
|
|
|
UIPanels.Add(Panels.AutoCompleter, new AutoCompleteModal(UiBase));
|
|
|
|
|
UIPanels.Add(Panels.ObjectExplorer, new ObjectExplorerPanel(UiBase));
|
|
|
|
|
UIPanels.Add(Panels.Inspector, new InspectorPanel(UiBase));
|
|
|
|
|
UIPanels.Add(Panels.CSConsole, new CSConsolePanel(UiBase));
|
|
|
|
|
UIPanels.Add(Panels.HookManager, new HookManagerPanel(UiBase));
|
2022-04-18 21:39:17 +10:00
|
|
|
|
UIPanels.Add(Panels.Freecam, new FreeCamPanel(UiBase));
|
2022-04-14 01:25:59 +10:00
|
|
|
|
UIPanels.Add(Panels.Clipboard, new ClipboardPanel(UiBase));
|
|
|
|
|
UIPanels.Add(Panels.ConsoleLog, new LogPanel(UiBase));
|
|
|
|
|
UIPanels.Add(Panels.Options, new OptionsPanel(UiBase));
|
|
|
|
|
UIPanels.Add(Panels.UIInspectorResults, new MouseInspectorResultsPanel(UiBase));
|
2022-04-18 21:39:17 +10:00
|
|
|
|
|
|
|
|
|
MouseInspector.inspectorUIBase = UniversalUI.RegisterUI(MouseInspector.UIBaseGUID, null);
|
|
|
|
|
new MouseInspector(MouseInspector.inspectorUIBase);
|
2021-05-28 16:39:42 +10:00
|
|
|
|
|
2022-01-17 19:42:05 +11:00
|
|
|
|
// Call some initialize methods
|
2022-01-18 20:19:20 +11:00
|
|
|
|
Notification.Init();
|
2021-05-28 16:39:42 +10:00
|
|
|
|
ConsoleController.Init();
|
|
|
|
|
|
2022-01-17 19:42:05 +11:00
|
|
|
|
// Failsafe fix, in some games all dropdowns displayed values are blank on startup for some reason.
|
2022-04-12 05:20:35 +10:00
|
|
|
|
foreach (Dropdown dropdown in UIRoot.GetComponentsInChildren<Dropdown>(true))
|
2021-07-11 18:11:14 +10:00
|
|
|
|
dropdown.RefreshShownValue();
|
2021-12-02 18:35:46 +11:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
Initializing = false;
|
2022-04-25 19:37:29 +10:00
|
|
|
|
|
|
|
|
|
if (ConfigManager.Hide_On_Startup.Value)
|
|
|
|
|
ShowMenu = false;
|
2021-05-28 16:39:42 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Main UI Update loop
|
|
|
|
|
|
|
|
|
|
public static void Update()
|
|
|
|
|
{
|
2021-12-02 18:35:46 +11:00
|
|
|
|
if (!UIRoot)
|
2021-05-28 16:39:42 +10:00
|
|
|
|
return;
|
|
|
|
|
|
2022-03-04 00:20:04 +11:00
|
|
|
|
// If we are doing a Mouse Inspect, we don't need to update anything else.
|
|
|
|
|
if (MouseInspector.Instance.TryUpdate())
|
2021-05-28 16:39:42 +10:00
|
|
|
|
return;
|
|
|
|
|
|
2022-01-18 20:19:20 +11:00
|
|
|
|
// Update Notification modal
|
|
|
|
|
Notification.Update();
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// Check forceUnlockMouse toggle
|
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Force_Unlock_Toggle.Value))
|
2021-12-02 18:35:46 +11:00
|
|
|
|
UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = !UniverseLib.Config.ConfigManager.Force_Unlock_Mouse;
|
2021-05-28 16:39:42 +10:00
|
|
|
|
|
2021-05-28 18:48:55 +10:00
|
|
|
|
// update the timescale value
|
2022-05-10 01:44:08 +10:00
|
|
|
|
timeScaleWidget.Update();
|
2021-05-28 18:48:55 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// check screen dimension change
|
2022-04-12 05:20:35 +10:00
|
|
|
|
Display display = DisplayManager.ActiveDisplay;
|
2022-01-22 20:20:44 +11:00
|
|
|
|
if (display.renderingWidth != lastScreenWidth || display.renderingHeight != lastScreenHeight)
|
2021-05-28 16:39:42 +10:00
|
|
|
|
OnScreenDimensionsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 23:03:30 +10:00
|
|
|
|
// Panels
|
2021-03-11 17:57:58 +11:00
|
|
|
|
|
2022-04-14 01:25:59 +10:00
|
|
|
|
public static UEPanel GetPanel(Panels panel) => UIPanels[panel];
|
2020-10-23 01:50:33 +11:00
|
|
|
|
|
2022-04-14 01:25:59 +10:00
|
|
|
|
public static T GetPanel<T>(Panels panel) where T : UEPanel => (T)UIPanels[panel];
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
2021-04-24 04:03:33 +10:00
|
|
|
|
public static void TogglePanel(Panels panel)
|
|
|
|
|
{
|
2022-04-14 01:25:59 +10:00
|
|
|
|
UEPanel uiPanel = GetPanel(panel);
|
2021-04-24 04:03:33 +10:00
|
|
|
|
SetPanelActive(panel, !uiPanel.Enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-13 02:21:25 +11:00
|
|
|
|
public static void SetPanelActive(Panels panelType, bool active)
|
2021-04-24 04:03:33 +10:00
|
|
|
|
{
|
2022-04-14 01:25:59 +10:00
|
|
|
|
GetPanel(panelType).SetActive(active);
|
2021-04-28 23:58:13 +10:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 01:25:59 +10:00
|
|
|
|
public static void SetPanelActive(UEPanel panel, bool active)
|
2021-04-28 23:58:13 +10:00
|
|
|
|
{
|
|
|
|
|
panel.SetActive(active);
|
|
|
|
|
}
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// navbar
|
2021-05-18 19:55:27 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
public static void SetNavBarAnchor()
|
2021-05-13 23:03:30 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
switch (NavbarAnchor)
|
2021-05-15 06:23:13 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
case VerticalAnchor.Top:
|
|
|
|
|
NavBarRect.anchorMin = new Vector2(0.5f, 1f);
|
|
|
|
|
NavBarRect.anchorMax = new Vector2(0.5f, 1f);
|
|
|
|
|
NavBarRect.anchoredPosition = new Vector2(NavBarRect.anchoredPosition.x, 0);
|
2022-01-18 20:19:20 +11:00
|
|
|
|
NavBarRect.sizeDelta = NAVBAR_DIMENSIONS;
|
2021-05-28 16:39:42 +10:00
|
|
|
|
break;
|
2021-05-13 23:03:30 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
case VerticalAnchor.Bottom:
|
|
|
|
|
NavBarRect.anchorMin = new Vector2(0.5f, 0f);
|
|
|
|
|
NavBarRect.anchorMax = new Vector2(0.5f, 0f);
|
|
|
|
|
NavBarRect.anchoredPosition = new Vector2(NavBarRect.anchoredPosition.x, 35);
|
2022-01-18 20:19:20 +11:00
|
|
|
|
NavBarRect.sizeDelta = NAVBAR_DIMENSIONS;
|
2021-05-28 16:39:42 +10:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-13 23:03:30 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// listeners
|
2021-05-13 23:03:30 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void OnScreenDimensionsChanged()
|
|
|
|
|
{
|
2022-04-12 05:20:35 +10:00
|
|
|
|
Display display = DisplayManager.ActiveDisplay;
|
2022-01-22 20:20:44 +11:00
|
|
|
|
lastScreenWidth = display.renderingWidth;
|
|
|
|
|
lastScreenHeight = display.renderingHeight;
|
2021-05-18 19:55:27 +10:00
|
|
|
|
|
2022-04-14 01:25:59 +10:00
|
|
|
|
foreach (KeyValuePair<Panels, UEPanel> panel in UIPanels)
|
2021-05-18 19:55:27 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
panel.Value.EnsureValidSize();
|
2022-04-14 01:25:59 +10:00
|
|
|
|
panel.Value.EnsureValidPosition();
|
2021-05-28 16:39:42 +10:00
|
|
|
|
panel.Value.Dragger.OnEndResize();
|
2021-05-18 19:55:27 +10:00
|
|
|
|
}
|
2021-05-13 23:03:30 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void OnCloseButtonClicked()
|
2021-04-24 04:03:33 +10:00
|
|
|
|
{
|
2021-05-28 16:39:42 +10:00
|
|
|
|
ShowMenu = false;
|
|
|
|
|
}
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
private static void Master_Toggle_OnValueChanged(KeyCode val)
|
|
|
|
|
{
|
|
|
|
|
closeBtn.ButtonText.text = val.ToString();
|
|
|
|
|
}
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2022-05-10 01:44:08 +10:00
|
|
|
|
|
2021-04-24 04:03:33 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// UI Construction
|
|
|
|
|
|
2021-04-28 23:58:13 +10:00
|
|
|
|
private static void CreateTopNavBar()
|
2021-04-23 21:50:58 +10:00
|
|
|
|
{
|
2022-04-12 05:20:35 +10:00
|
|
|
|
GameObject navbarPanel = UIFactory.CreateUIObject("MainNavbar", UIRoot);
|
2021-05-28 16:39:42 +10:00
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(navbarPanel, false, false, true, true, 5, 4, 4, 4, 4, TextAnchor.MiddleCenter);
|
2021-04-28 23:58:13 +10:00
|
|
|
|
navbarPanel.AddComponent<Image>().color = new Color(0.1f, 0.1f, 0.1f);
|
2021-05-03 21:02:01 +10:00
|
|
|
|
NavBarRect = navbarPanel.GetComponent<RectTransform>();
|
|
|
|
|
NavBarRect.pivot = new Vector2(0.5f, 1f);
|
2021-05-16 21:45:09 +10:00
|
|
|
|
|
|
|
|
|
NavbarAnchor = ConfigManager.Main_Navbar_Anchor.Value;
|
|
|
|
|
SetNavBarAnchor();
|
2021-06-05 19:36:09 +10:00
|
|
|
|
ConfigManager.Main_Navbar_Anchor.OnValueChanged += (VerticalAnchor val) =>
|
2021-05-16 21:45:09 +10:00
|
|
|
|
{
|
|
|
|
|
NavbarAnchor = val;
|
|
|
|
|
SetNavBarAnchor();
|
|
|
|
|
};
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-04-28 23:58:13 +10:00
|
|
|
|
// UnityExplorer title
|
|
|
|
|
|
2022-04-18 21:39:17 +10:00
|
|
|
|
string titleTxt = $"UE <i><color=grey>{ExplorerCore.VERSION}</color></i>";
|
|
|
|
|
Text title = UIFactory.CreateLabel(navbarPanel, "Title", titleTxt, TextAnchor.MiddleCenter, default, true, 14);
|
|
|
|
|
UIFactory.SetLayoutElement(title.gameObject, minWidth: 75, flexibleWidth: 0);
|
2021-05-03 21:02:01 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
// panel tabs
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
NavbarTabButtonHolder = UIFactory.CreateUIObject("NavTabButtonHolder", navbarPanel);
|
|
|
|
|
UIFactory.SetLayoutElement(NavbarTabButtonHolder, minHeight: 25, flexibleHeight: 999, flexibleWidth: 999);
|
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(NavbarTabButtonHolder, false, true, true, true, 4, 2, 2, 2, 2);
|
|
|
|
|
|
2022-05-10 01:44:08 +10:00
|
|
|
|
// Time scale widget
|
|
|
|
|
timeScaleWidget = new(navbarPanel);
|
2022-01-17 19:42:05 +11:00
|
|
|
|
|
2022-05-10 01:44:08 +10:00
|
|
|
|
//spacer
|
|
|
|
|
GameObject spacer = UIFactory.CreateUIObject("Spacer", navbarPanel);
|
|
|
|
|
UIFactory.SetLayoutElement(spacer, minWidth: 15);
|
2021-05-15 06:23:13 +10:00
|
|
|
|
|
2021-04-28 23:58:13 +10:00
|
|
|
|
// Hide menu button
|
2021-04-23 21:50:58 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
closeBtn = UIFactory.CreateButton(navbarPanel, "CloseButton", ConfigManager.Master_Toggle.Value.ToString());
|
2022-05-10 01:44:08 +10:00
|
|
|
|
UIFactory.SetLayoutElement(closeBtn.Component.gameObject, minHeight: 25, minWidth: 60, flexibleWidth: 0);
|
2022-01-31 21:24:01 +11:00
|
|
|
|
RuntimeHelper.SetColorBlock(closeBtn.Component, new Color(0.63f, 0.32f, 0.31f),
|
2021-04-23 21:50:58 +10:00
|
|
|
|
new Color(0.81f, 0.25f, 0.2f), new Color(0.6f, 0.18f, 0.16f));
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-28 16:39:42 +10:00
|
|
|
|
ConfigManager.Master_Toggle.OnValueChanged += Master_Toggle_OnValueChanged;
|
|
|
|
|
closeBtn.OnClick += OnCloseButtonClicked;
|
2020-10-23 01:50:33 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|