From 87c61f4189927548dc656a5c251cdde902fe816a Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Fri, 13 May 2022 11:01:06 -0400 Subject: [PATCH] feat: added list of buttons to select recently placed props --- NewHorizons/Utility/DebugMenu.cs | 29 ++++++++++++++++++++++++-- NewHorizons/Utility/DebugPropPlacer.cs | 25 ++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Utility/DebugMenu.cs b/NewHorizons/Utility/DebugMenu.cs index ed04606b..08c73ae2 100644 --- a/NewHorizons/Utility/DebugMenu.cs +++ b/NewHorizons/Utility/DebugMenu.cs @@ -19,6 +19,9 @@ namespace NewHorizons.Utility DebugPropPlacer _dpp; DebugRaycaster _drc; + // menu params + private Vector2 recentPropsScrollPosition = Vector2.zero; + private void Awake() { _dpp = this.GetRequiredComponent(); @@ -47,9 +50,31 @@ namespace NewHorizons.Utility // https://docs.unity3d.com/ScriptReference/GUI.TextField.html GUILayout.BeginArea(new Rect(menuPosition.x, menuPosition.y, EditorMenuSize.x, EditorMenuSize.y), _editorMenuStyle); - _dpp.currentObject = GUILayout.TextArea(_dpp.currentObject); + + // + // DebugPropPlacer + // + GUILayout.Label("Recently placed objects"); + _dpp.SetCurrentObject(GUILayout.TextArea(_dpp.currentObject)); + + GUILayout.Space(5); - // TODO: maintain list of objects here + // 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 _dpp.RecentlyPlacedProps) + { + var propPathElements = propPath.Split('/'); + if (GUILayout.Button(propPathElements[propPathElements.Length-1])) + { + _dpp.SetCurrentObject(propPath); + } + } + GUILayout.EndScrollView(); + + + + // TODO: maintain list of recently placed objects here // TODO: field to provide name of mod to load configs from, plus button to load those into the PropPlaecr (make sure not to load more than once, once the button has been pushed, disable it) // TODO: add a warning that the button cannot be pushed more than once diff --git a/NewHorizons/Utility/DebugPropPlacer.cs b/NewHorizons/Utility/DebugPropPlacer.cs index 595fcafb..293978cb 100644 --- a/NewHorizons/Utility/DebugPropPlacer.cs +++ b/NewHorizons/Utility/DebugPropPlacer.cs @@ -24,16 +24,21 @@ namespace NewHorizons.Utility public Vector3 rotation { get { return gameObject.transform.localEulerAngles; } } } + // DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_1/Props_DreamZone_1/OtherComponentsGroup/Trees_Z1/DreamHouseIsland/Tree_DW_M_Var public static readonly string DEFAULT_OBJECT = "BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District1/Props_HangingCity_District1/OtherComponentsGroup/Props_HangingCity_Building_10/Prefab_NOM_VaseThin"; - public string currentObject = DEFAULT_OBJECT; + public string currentObject { get; private set; } + private bool hasAddedCurrentObjectToRecentsList = false; private List props = new List(); private List deletedProps = new List(); private DebugRaycaster _rc; + public List RecentlyPlacedProps = new List(); + private void Awake() { _rc = this.GetRequiredComponent(); + currentObject = DEFAULT_OBJECT; } private void Update() @@ -61,10 +66,26 @@ namespace NewHorizons.Utility } } + public void SetCurrentObject(string s) + { + currentObject = s; + hasAddedCurrentObjectToRecentsList = false; + } + internal void PlaceObject() { DebugRaycastData data = _rc.Raycast(); PlaceObject(data, this.gameObject.transform.position); + + if (!hasAddedCurrentObjectToRecentsList) + { + hasAddedCurrentObjectToRecentsList = true; + + if (!RecentlyPlacedProps.Contains(currentObject)) + { + RecentlyPlacedProps.Add(currentObject); + } + } } public void PlaceObject(DebugRaycastData data, Vector3 playerAbsolutePosition) @@ -80,7 +101,7 @@ namespace NewHorizons.Utility if (currentObject == "" || currentObject == null) { - currentObject = DEFAULT_OBJECT; + SetCurrentObject(DEFAULT_OBJECT); } GameObject prop = DetailBuilder.MakeDetail(data.hitObject, data.hitObject.GetComponentInChildren(), currentObject, data.pos, data.norm, 1, false);