From da907bea7814549456cc60ec4df9c47c59555d28 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Thu, 23 Jun 2022 08:53:48 -0400 Subject: [PATCH] separated props into three separate dropdowns --- .../Utility/DebugMenu/DebugMenuPropPlacer.cs | 119 ++++++++++++------ .../Utility/DebugUtilities/DebugPropPlacer.cs | 4 +- 2 files changed, 80 insertions(+), 43 deletions(-) diff --git a/NewHorizons/Utility/DebugMenu/DebugMenuPropPlacer.cs b/NewHorizons/Utility/DebugMenu/DebugMenuPropPlacer.cs index d98fd8ba..db5b8589 100644 --- a/NewHorizons/Utility/DebugMenu/DebugMenuPropPlacer.cs +++ b/NewHorizons/Utility/DebugMenu/DebugMenuPropPlacer.cs @@ -12,14 +12,23 @@ namespace NewHorizons.Utility.DebugMenu { class DebugMenuPropPlacer : DebugSubmenu { - private Vector2 recentPropsScrollPosition = Vector2.zero; private HashSet favoriteProps = new HashSet(); + private List favoritePropsList = new List(); + private List propsLoadedFromConfig = new List(); 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 DebugPropPlacer _dpp; internal DebugRaycaster _drc; + // menu params + private Vector2 favoritePropsScrollPosition = Vector2.zero; + private bool favoritePropsCollapsed = false; + private Vector2 recentPropsScrollPosition = Vector2.zero; + private bool recentPropsCollapsed = false; + private Vector2 configPropsScrollPosition = Vector2.zero; + private bool configPropsCollapsed = true; + internal override string SubmenuName() { return "Prop Placer"; @@ -55,7 +64,7 @@ namespace NewHorizons.Utility.DebugMenu internal override void LoadConfigFile(DebugMenu menu, PlanetConfig config) { - _dpp.FindAndRegisterPropsFromConfig(config); + _dpp.FindAndRegisterPropsFromConfig(config, propsLoadedFromConfig); } private void LoadFavoriteProps() @@ -67,9 +76,11 @@ namespace NewHorizons.Utility.DebugMenu var favoritePropPaths = favoritePropsPlayerPref.Split(separatorCharacter); foreach (string favoriteProp in favoritePropPaths) { - DebugPropPlacer.RecentlyPlacedProps.Add(favoriteProp); + // DebugPropPlacer.RecentlyPlacedProps.Add(favoriteProp); this.favoriteProps.Add(favoriteProp); } + + favoritePropsList = favoriteProps.ToList(); } internal override void OnGUI(DebugMenu menu) @@ -81,45 +92,71 @@ namespace NewHorizons.Utility.DebugMenu _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(menu.EditorMenuSize.x), GUILayout.Height(500)); - 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(); - + + var favoriteMenu = PropsList(menu, favoritePropsList, favoritePropsCollapsed, favoritePropsScrollPosition, "Favorite Props"); + favoritePropsCollapsed = favoriteMenu.collapsed; + favoritePropsScrollPosition = favoriteMenu.scroll; GUILayout.Space(5); + + var recentMenu = PropsList(menu, DebugPropPlacer.RecentlyPlacedProps, recentPropsCollapsed, recentPropsScrollPosition, "Recently Placed Props"); + recentPropsCollapsed= recentMenu.collapsed; + recentPropsScrollPosition = recentMenu.scroll; + GUILayout.Space(5); + + var configMenu = PropsList(menu, propsLoadedFromConfig, configPropsCollapsed, configPropsScrollPosition, "Props Loaded From Configs"); + configPropsCollapsed = configMenu.collapsed; + configPropsScrollPosition = configMenu.scroll; + GUILayout.Space(5); + + + } + + private struct PropsListReturn { public bool collapsed; public Vector2 scroll; } + private PropsListReturn PropsList(DebugMenu menu, IEnumerable props, bool collapsed, Vector2 scroll, string title) + { + GUILayout.BeginVertical(menu._editorMenuStyle); + + var arrow = collapsed ? " > " : " v "; + if (GUILayout.Button(arrow + title, menu._submenuStyle)) collapsed = !collapsed; + if (collapsed) return new PropsListReturn() { collapsed=collapsed, scroll=scroll }; + + scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(menu.EditorMenuSize.x), GUILayout.Height(500)); + foreach (string propPath in props) + { + 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, GUILayout.ExpandWidth(true))) + { + _dpp.SetCurrentObject(propPath); + } + + GUILayout.EndHorizontal(); + } + GUILayout.EndScrollView(); + GUILayout.EndVertical(); + + return new PropsListReturn() { collapsed=collapsed, scroll=scroll }; } internal override void PreSave(DebugMenu menu) diff --git a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs index 29563f47..42633aac 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs @@ -153,7 +153,7 @@ namespace NewHorizons.Utility.DebugUtilities return astroObjectName; } - public void FindAndRegisterPropsFromConfig(PlanetConfig config) + public void FindAndRegisterPropsFromConfig(PlanetConfig config, List pathsList = null) { if (config.starSystem != Main.Instance.CurrentStarSystem) return; @@ -180,7 +180,7 @@ namespace NewHorizons.Utility.DebugUtilities // selectable list of placed props if (detail.assetBundle == null && !RecentlyPlacedProps.Contains(data.detailInfo.path)) { - RecentlyPlacedProps.Add(data.detailInfo.path); + if (pathsList != null) pathsList.Add(data.detailInfo.path); } } }