From 489fac98e7a544390ae2bf568854196a42b4a552 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Tue, 31 May 2022 19:27:23 -0400 Subject: [PATCH] created DebugSubmenus and moved most prop placer stuff out of DebugMenu.cs, also made a tab bar for submenus and added styling --- NewHorizons/Handlers/ShipLogHandler.cs | 2 +- .../Utility/DebugUtilities/DebugMenu.cs | 142 +++++++++--------- .../DebugUtilities/DebugMenuDummySubmenu.cs | 24 +++ .../DebugUtilities/DebugMenuPropPlacer.cs | 91 +++++++++++ .../Utility/DebugUtilities/DebugSubmenu.cs | 16 ++ 5 files changed, 201 insertions(+), 74 deletions(-) create mode 100644 NewHorizons/Utility/DebugUtilities/DebugMenuDummySubmenu.cs create mode 100644 NewHorizons/Utility/DebugUtilities/DebugMenuPropPlacer.cs create mode 100644 NewHorizons/Utility/DebugUtilities/DebugSubmenu.cs diff --git a/NewHorizons/Handlers/ShipLogHandler.cs b/NewHorizons/Handlers/ShipLogHandler.cs index 2ef80633..55f6184b 100644 --- a/NewHorizons/Handlers/ShipLogHandler.cs +++ b/NewHorizons/Handlers/ShipLogHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Utility; +using NewHorizons.Utility; using System.Collections.Generic; using System.Linq; using UnityEngine; diff --git a/NewHorizons/Utility/DebugUtilities/DebugMenu.cs b/NewHorizons/Utility/DebugUtilities/DebugMenu.cs index eac4f31d..ebcc9ca3 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugMenu.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugMenu.cs @@ -1,4 +1,4 @@ -using NewHorizons.External; +using NewHorizons.External; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; @@ -30,25 +30,27 @@ namespace NewHorizons.Utility.DebugUtilities private static IModButton pauseMenuButton; GUIStyle _editorMenuStyle; - Vector2 EditorMenuSize = new Vector2(600, 900); + GUIStyle _tabBarStyle; + GUIStyle _submenuStyle; + internal Vector2 EditorMenuSize = new Vector2(600, 900); bool menuOpen = false; static bool openMenuOnPause; static bool staticInitialized; - DebugPropPlacer _dpp; - DebugRaycaster _drc; + internal DebugPropPlacer _dpp; + internal DebugRaycaster _drc; // menu params - private Vector2 recentPropsScrollPosition = Vector2.zero; - private HashSet favoriteProps = new HashSet(); - public static readonly char separatorCharacter = '☧'; // since no chars are illegal in game object names, I picked one that's extremely unlikely to be used to be a separator - private static readonly string favoritePropsPlayerPrefKey = "FavoriteProps"; - private static IModBehaviour loadedMod = null; private Dictionary loadedConfigFiles = new Dictionary(); private bool saveButtonUnlocked = false; private Vector2 recentModListScrollPosition = Vector2.zero; + // submenus + private List submenus; + private int activeSubmenu = 0; + + private static JsonSerializerSettings jsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, @@ -60,7 +62,15 @@ namespace NewHorizons.Utility.DebugUtilities { _dpp = this.GetRequiredComponent(); _drc = this.GetRequiredComponent(); - LoadFavoriteProps(); + + submenus = new List() + { + new DebugMenuPropPlacer(), + new DebugMenuDummySubmenu() + }; + + + submenus.ForEach((submenu) => submenu.OnAwake(this)); } private void Start() @@ -107,19 +117,6 @@ namespace NewHorizons.Utility.DebugUtilities private void CloseMenu() { menuOpen = false; } - private void LoadFavoriteProps() - { - string favoritePropsPlayerPref = PlayerPrefs.GetString(favoritePropsPlayerPrefKey); - - if (favoritePropsPlayerPref == null || favoritePropsPlayerPref == "") return; - - var favoritePropPaths = favoritePropsPlayerPref.Split(separatorCharacter); - foreach (string favoriteProp in favoritePropPaths) - { - DebugPropPlacer.RecentlyPlacedProps.Add(favoriteProp); - this.favoriteProps.Add(favoriteProp); - } - } private void OnGUI() { @@ -130,53 +127,6 @@ namespace NewHorizons.Utility.DebugUtilities GUILayout.BeginArea(new Rect(menuPosition.x, menuPosition.y, EditorMenuSize.x, EditorMenuSize.y), _editorMenuStyle); - // - // DebugPropPlacer - // - GUILayout.Label("Recently placed objects"); - _dpp.SetCurrentObject(GUILayout.TextArea(_dpp.currentObject)); - - GUILayout.Space(5); - - // List of recently placed objects - GUILayout.Label("Recently placed objects"); - recentPropsScrollPosition = GUILayout.BeginScrollView(recentPropsScrollPosition, GUILayout.Width(EditorMenuSize.x), GUILayout.Height(100)); - foreach (string propPath in DebugPropPlacer.RecentlyPlacedProps) - { - GUILayout.BeginHorizontal(); - - var propPathElements = propPath[propPath.Length-1] == '/' - ? propPath.Substring(0, propPath.Length-1).Split('/') - : propPath.Split('/'); - string propName = propPathElements[propPathElements.Length - 1]; - - string favoriteButtonIcon = favoriteProps.Contains(propPath) ? "★" : "☆"; - if (GUILayout.Button(favoriteButtonIcon, GUILayout.ExpandWidth(false))) - { - if (favoriteProps.Contains(propPath)) - { - favoriteProps.Remove(propPath); - } - else - { - favoriteProps.Add(propPath); - } - - string[] favoritePropsArray = favoriteProps.ToArray(); - PlayerPrefs.SetString(favoritePropsPlayerPrefKey, string.Join(separatorCharacter + "", favoritePropsArray)); - } - - if (GUILayout.Button(propName)) - { - _dpp.SetCurrentObject(propPath); - } - - GUILayout.EndHorizontal(); - } - GUILayout.EndScrollView(); - - GUILayout.Space(5); - // continue working on existing mod GUILayout.Label("Name of your mod"); @@ -219,6 +169,33 @@ namespace NewHorizons.Utility.DebugUtilities GUILayout.EndHorizontal(); } + GUILayout.Space(5); + // todo: a line or something? + GUILayout.Space(5); + + // draw submenu stuff + if (loadedMod != null) + { + GUILayout.BeginHorizontal(_tabBarStyle); + GUILayout.Space(5); + for (int i = 0; i < submenus.Count; i++) + { + GUI.enabled = i != activeSubmenu; + var style = i == activeSubmenu ? _submenuStyle : _tabBarStyle; + if (GUILayout.Button(" "+submenus[i].SubmenuName()+" ", style, GUILayout.ExpandWidth(false))) + activeSubmenu = i; + GUI.enabled = true; + + // if (i < submenus.Count-1) GUILayout.Label("|", GUILayout.ExpandWidth(false)); + } + GUILayout.EndHorizontal(); + + GUILayout.BeginVertical(_submenuStyle); + submenus[activeSubmenu].OnGUI(this); + GUILayout.EndVertical(); + } + + GUILayout.EndArea(); } @@ -339,15 +316,34 @@ namespace NewHorizons.Utility.DebugUtilities _dpp = this.GetRequiredComponent(); _drc = this.GetRequiredComponent(); - Texture2D bgTexture = ImageUtilities.MakeSolidColorTexture((int)EditorMenuSize.x, (int)EditorMenuSize.y, Color.black); - _editorMenuStyle = new GUIStyle { normal = { - background = bgTexture + background = ImageUtilities.MakeSolidColorTexture(1, 1, Color.black) } }; + + _tabBarStyle = new GUIStyle + { + normal = + { + background = ImageUtilities.MakeSolidColorTexture(1, 1, new Color(0.3f, 0.3f, 0.3f)) + }, + fontStyle = FontStyle.Bold, + fontSize = 16 + }; + + _submenuStyle = new GUIStyle + { + normal = + { + background = ImageUtilities.MakeSolidColorTexture(1, 1, new Color(0.2f, 0.2f, 0.2f)), + textColor = Color.white + }, + fontStyle = FontStyle.Bold, + fontSize = 16 + }; } } } diff --git a/NewHorizons/Utility/DebugUtilities/DebugMenuDummySubmenu.cs b/NewHorizons/Utility/DebugUtilities/DebugMenuDummySubmenu.cs new file mode 100644 index 00000000..9ffa8d80 --- /dev/null +++ b/NewHorizons/Utility/DebugUtilities/DebugMenuDummySubmenu.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Utility.DebugUtilities +{ + class DebugMenuDummySubmenu : DebugSubmenu + { + internal override void OnAwake(DebugMenu menu) + { + } + + internal override void OnGUI(DebugMenu menu) + { + } + + internal override string SubmenuName() + { + return "Blank"; + } + } +} diff --git a/NewHorizons/Utility/DebugUtilities/DebugMenuPropPlacer.cs b/NewHorizons/Utility/DebugUtilities/DebugMenuPropPlacer.cs new file mode 100644 index 00000000..69bc5e50 --- /dev/null +++ b/NewHorizons/Utility/DebugUtilities/DebugMenuPropPlacer.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Utility.DebugUtilities +{ + class DebugMenuPropPlacer : DebugSubmenu + { + private Vector2 recentPropsScrollPosition = Vector2.zero; + private HashSet favoriteProps = new HashSet(); + public static readonly char separatorCharacter = '☧'; // since no chars are illegal in game object names, I picked one that's extremely unlikely to be used to be a separator + private static readonly string favoritePropsPlayerPrefKey = "FavoriteProps"; + + internal override string SubmenuName() + { + return "Prop Placer"; + } + + internal override void OnAwake(DebugMenu menu) + { + LoadFavoriteProps(); + } + + private void LoadFavoriteProps() + { + string favoritePropsPlayerPref = PlayerPrefs.GetString(favoritePropsPlayerPrefKey); + + if (favoritePropsPlayerPref == null || favoritePropsPlayerPref == "") return; + + var favoritePropPaths = favoritePropsPlayerPref.Split(separatorCharacter); + foreach (string favoriteProp in favoritePropPaths) + { + DebugPropPlacer.RecentlyPlacedProps.Add(favoriteProp); + this.favoriteProps.Add(favoriteProp); + } + } + + internal override void OnGUI(DebugMenu menu) + { + // + // DebugPropPlacer + // + GUILayout.Label("Recently placed objects"); + menu._dpp.SetCurrentObject(GUILayout.TextArea(menu._dpp.currentObject)); + + GUILayout.Space(5); + + // List of recently placed objects + GUILayout.Label("Recently placed objects"); + recentPropsScrollPosition = GUILayout.BeginScrollView(recentPropsScrollPosition, GUILayout.Width(menu.EditorMenuSize.x)); + foreach (string propPath in DebugPropPlacer.RecentlyPlacedProps) + { + GUILayout.BeginHorizontal(); + + var propPathElements = propPath[propPath.Length-1] == '/' + ? propPath.Substring(0, propPath.Length-1).Split('/') + : propPath.Split('/'); + string propName = propPathElements[propPathElements.Length - 1]; + + string favoriteButtonIcon = favoriteProps.Contains(propPath) ? "★" : "☆"; + if (GUILayout.Button(favoriteButtonIcon, GUILayout.ExpandWidth(false))) + { + if (favoriteProps.Contains(propPath)) + { + favoriteProps.Remove(propPath); + } + else + { + favoriteProps.Add(propPath); + } + + string[] favoritePropsArray = favoriteProps.ToArray(); + PlayerPrefs.SetString(favoritePropsPlayerPrefKey, string.Join(separatorCharacter + "", favoritePropsArray)); + } + + if (GUILayout.Button(propName)) + { + menu._dpp.SetCurrentObject(propPath); + } + + GUILayout.EndHorizontal(); + } + GUILayout.EndScrollView(); + + GUILayout.Space(5); + } + } +} diff --git a/NewHorizons/Utility/DebugUtilities/DebugSubmenu.cs b/NewHorizons/Utility/DebugUtilities/DebugSubmenu.cs new file mode 100644 index 00000000..c617161a --- /dev/null +++ b/NewHorizons/Utility/DebugUtilities/DebugSubmenu.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Utility.DebugUtilities +{ + abstract class DebugSubmenu + { + internal abstract void OnAwake(DebugMenu menu); + internal abstract void OnGUI(DebugMenu menu); + + internal abstract string SubmenuName(); + } +}