mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
created DebugSubmenus and moved most prop placer stuff out of DebugMenu.cs, also made a tab bar for submenus and added styling
This commit is contained in:
parent
b31e1bbcd7
commit
489fac98e7
@ -1,4 +1,4 @@
|
||||
using NewHorizons.Utility;
|
||||
using NewHorizons.Utility;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@ -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<string> favoriteProps = new HashSet<string>();
|
||||
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<string, PlanetConfig> loadedConfigFiles = new Dictionary<string, PlanetConfig>();
|
||||
private bool saveButtonUnlocked = false;
|
||||
private Vector2 recentModListScrollPosition = Vector2.zero;
|
||||
|
||||
// submenus
|
||||
private List<DebugSubmenu> 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<DebugPropPlacer>();
|
||||
_drc = this.GetRequiredComponent<DebugRaycaster>();
|
||||
LoadFavoriteProps();
|
||||
|
||||
submenus = new List<DebugSubmenu>()
|
||||
{
|
||||
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<string>();
|
||||
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<DebugPropPlacer>();
|
||||
_drc = this.GetRequiredComponent<DebugRaycaster>();
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
NewHorizons/Utility/DebugUtilities/DebugMenuDummySubmenu.cs
Normal file
24
NewHorizons/Utility/DebugUtilities/DebugMenuDummySubmenu.cs
Normal file
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
91
NewHorizons/Utility/DebugUtilities/DebugMenuPropPlacer.cs
Normal file
91
NewHorizons/Utility/DebugUtilities/DebugMenuPropPlacer.cs
Normal file
@ -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<string> favoriteProps = new HashSet<string>();
|
||||
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<string>();
|
||||
PlayerPrefs.SetString(favoritePropsPlayerPrefKey, string.Join(separatorCharacter + "", favoritePropsArray));
|
||||
}
|
||||
|
||||
if (GUILayout.Button(propName))
|
||||
{
|
||||
menu._dpp.SetCurrentObject(propPath);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
NewHorizons/Utility/DebugUtilities/DebugSubmenu.cs
Normal file
16
NewHorizons/Utility/DebugUtilities/DebugSubmenu.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user