diff --git a/NewHorizons/Assets/translations/english.json b/NewHorizons/Assets/translations/english.json index 82cb193e..b6fa95be 100644 --- a/NewHorizons/Assets/translations/english.json +++ b/NewHorizons/Assets/translations/english.json @@ -16,7 +16,12 @@ "RICH_PRESENCE_EXPLORING": "Exploring {0}.", "RICH_PRESENCE_WARPING": "Warping to {0}.", "OUTDATED_VERSION_WARNING": "WARNING\n\nNew Horizons only works on version {0} or higher. You're on version {1}.\n\nPlease update your game or uninstall NH.", - "JSON_FAILED_TO_LOAD": "Invalid file(s): {0}" + "JSON_FAILED_TO_LOAD": "Invalid file(s): {0}", + "DEBUG_RAYCAST": "Raycast", + "DEBUG_PLACE": "Place Object", + "DEBUG_PLACE_TEXT": "Place Nomai Text", + "DEBUG_UNDO": "Undo", + "DEBUG_REDO": "Redo" }, "AchievementTranslations": { "NH_EATEN_OUTSIDE_BRAMBLE": { diff --git a/NewHorizons/Utility/DebugUtilities/DebugNomaiTextPlacer.cs b/NewHorizons/Utility/DebugUtilities/DebugNomaiTextPlacer.cs index d26815e8..13bf0523 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugNomaiTextPlacer.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugNomaiTextPlacer.cs @@ -1,3 +1,4 @@ +using NewHorizons.Handlers; using System; using System.Collections.Generic; using System.Linq; @@ -15,13 +16,24 @@ namespace NewHorizons.Utility.DebugUtilities private DebugRaycaster _rc; + private ScreenPrompt _placePrompt; + private void Awake() { _rc = this.GetComponent(); + + _placePrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_PLACE_TEXT", TranslationHandler.TextType.UI) + " ", ImageUtilities.GetButtonSprite(KeyCode.G)); + Locator.GetPromptManager().AddScreenPrompt(_placePrompt, PromptPosition.UpperRight, false); } - void Update() + private void OnDestroy() { + Locator.GetPromptManager()?.RemoveScreenPrompt(_placePrompt, PromptPosition.UpperRight); + } + + private void Update() + { + UpdatePromptVisibility(); if (!Main.Debug) return; if (!active) return; @@ -31,5 +43,10 @@ namespace NewHorizons.Utility.DebugUtilities if (onRaycast != null) onRaycast.Invoke(data); } } + + public void UpdatePromptVisibility() + { + _placePrompt.SetVisibility(!OWTime.IsPaused() && Main.Debug && active); + } } } diff --git a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs index c3bb644c..70e85fcc 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs @@ -1,6 +1,7 @@ using NewHorizons.Builder.Props; using NewHorizons.External.Configs; using NewHorizons.External.Modules; +using NewHorizons.Handlers; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -39,14 +40,36 @@ namespace NewHorizons.Utility.DebugUtilities public GameObject mostRecentlyPlacedPropGO { get { return props.Count() <= 0 ? null : props[props.Count() - 1].gameObject; } } public string mostRecentlyPlacedPropPath { get { return props.Count() <= 0 ? "" : props[props.Count() - 1].detailInfo.path; } } + private ScreenPrompt _placePrompt; + private ScreenPrompt _undoPrompt; + private ScreenPrompt _redoPrompt; + private void Awake() { _rc = this.GetRequiredComponent(); currentObject = DEFAULT_OBJECT; + + _placePrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_PLACE", TranslationHandler.TextType.UI) + " ", ImageUtilities.GetButtonSprite(KeyCode.G)); + _undoPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_UNDO", TranslationHandler.TextType.UI) + " ", ImageUtilities.GetButtonSprite(KeyCode.Minus)); + _redoPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_REDO", TranslationHandler.TextType.UI) + " ", ImageUtilities.GetButtonSprite(KeyCode.Equals)); + + Locator.GetPromptManager().AddScreenPrompt(_placePrompt, PromptPosition.UpperRight, false); + Locator.GetPromptManager().AddScreenPrompt(_undoPrompt, PromptPosition.UpperRight, false); + Locator.GetPromptManager().AddScreenPrompt(_redoPrompt, PromptPosition.UpperRight, false); + } + + private void OnDestroy() + { + var promptManager = Locator.GetPromptManager(); + if (promptManager == null) return; + promptManager.RemoveScreenPrompt(_placePrompt, PromptPosition.UpperRight); + promptManager.RemoveScreenPrompt(_undoPrompt, PromptPosition.UpperRight); + promptManager.RemoveScreenPrompt(_redoPrompt, PromptPosition.UpperRight); } private void Update() { + UpdatePromptVisibility(); if (!Main.Debug) return; if (!active) return; @@ -66,6 +89,14 @@ namespace NewHorizons.Utility.DebugUtilities } } + public void UpdatePromptVisibility() + { + var visible = !OWTime.IsPaused() && Main.Debug && active; + _placePrompt.SetVisibility(visible); + _undoPrompt.SetVisibility(visible && props.Count > 0); + _redoPrompt.SetVisibility(visible && deletedProps.Count > 0); + } + public void SetCurrentObject(string s) { currentObject = s; diff --git a/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs b/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs index b01e68e5..16f502e8 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components.Orbital; +using NewHorizons.Handlers; using UnityEngine; using UnityEngine.InputSystem; @@ -17,15 +17,25 @@ namespace NewHorizons.Utility.DebugUtilities private GameObject _planeDownRightSphere; private GameObject _planeDownLeftSphere; + private ScreenPrompt _raycastPrompt; private void Awake() { _rb = this.GetRequiredComponent(); + + _raycastPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_RAYCAST", TranslationHandler.TextType.UI) + " ", ImageUtilities.GetButtonSprite(KeyCode.P)); + + Locator.GetPromptManager().AddScreenPrompt(_raycastPrompt, PromptPosition.UpperRight, false); } + private void OnDestroy() + { + Locator.GetPromptManager()?.RemoveScreenPrompt(_raycastPrompt, PromptPosition.UpperRight); + } private void Update() { + UpdatePromptVisibility(); if (!Main.Debug) return; if (Keyboard.current == null) return; @@ -35,7 +45,12 @@ namespace NewHorizons.Utility.DebugUtilities } } - + + public void UpdatePromptVisibility() + { + _raycastPrompt.SetVisibility(!OWTime.IsPaused() && Main.Debug); + } + internal void PrintRaycast() { diff --git a/NewHorizons/Utility/ImageUtilities.cs b/NewHorizons/Utility/ImageUtilities.cs index 37bc267b..e875341f 100644 --- a/NewHorizons/Utility/ImageUtilities.cs +++ b/NewHorizons/Utility/ImageUtilities.cs @@ -351,7 +351,16 @@ namespace NewHorizons.Utility newTexture.Apply(); return newTexture; } - + + public static Sprite GetButtonSprite(JoystickButton button) => GetButtonSprite(ButtonPromptLibrary.SharedInstance.GetButtonTexture(button)); + public static Sprite GetButtonSprite(KeyCode key) => GetButtonSprite(ButtonPromptLibrary.SharedInstance.GetButtonTexture(key)); + private static Sprite GetButtonSprite(Texture2D texture) + { + var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100, 0, SpriteMeshType.FullRect, Vector4.zero, false); + sprite.name = texture.name; + return sprite; + } + // Modified from https://stackoverflow.com/a/69141085/9643841 public class AsyncImageLoader : MonoBehaviour {