Add screen prompts for debug mode (#352)

This commit is contained in:
Nick 2022-09-10 13:32:56 -04:00 committed by GitHub
commit 073892c008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 5 deletions

View File

@ -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": {

View File

@ -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<DebugRaycaster>();
_placePrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_PLACE_TEXT", TranslationHandler.TextType.UI) + " <CMD>", 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);
}
}
}

View File

@ -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<DebugRaycaster>();
currentObject = DEFAULT_OBJECT;
_placePrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_PLACE", TranslationHandler.TextType.UI) + " <CMD>", ImageUtilities.GetButtonSprite(KeyCode.G));
_undoPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_UNDO", TranslationHandler.TextType.UI) + " <CMD>", ImageUtilities.GetButtonSprite(KeyCode.Minus));
_redoPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_REDO", TranslationHandler.TextType.UI) + " <CMD>", 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;

View File

@ -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<OWRigidbody>();
_raycastPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_RAYCAST", TranslationHandler.TextType.UI) + " <CMD>", 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;
@ -36,6 +46,11 @@ namespace NewHorizons.Utility.DebugUtilities
}
public void UpdatePromptVisibility()
{
_raycastPrompt.SetVisibility(!OWTime.IsPaused() && Main.Debug);
}
internal void PrintRaycast()
{

View File

@ -352,6 +352,15 @@ namespace NewHorizons.Utility
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
{