From 6b091e210dcb08bd4dd8037aa91e3ae2115fef0c Mon Sep 17 00:00:00 2001 From: nyxeka Date: Sun, 7 Jan 2024 11:58:20 -0500 Subject: [PATCH] Add a new hotkey to close the interface occasionally, if the UI toggle hotkey is more accessable, it can be accidentally pressed. This adds the option to set a close hotkey for if you happen to open the recipe browser during a boss fight or something --- RecipeBrowser.cs | 3 +++ RecipeBrowserPlayer.cs | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/RecipeBrowser.cs b/RecipeBrowser.cs index a3a0713..df5cbe2 100644 --- a/RecipeBrowser.cs +++ b/RecipeBrowser.cs @@ -37,6 +37,7 @@ internal class RecipeBrowser : Mod //internal static Dictionary translations; // reference to private field. internal static Mod itemChecklistInstance; internal ModKeybind ToggleRecipeBrowserHotKey; + internal ModKeybind CloseRecipeBrowserHotKey; internal ModKeybind QueryHoveredItemHotKey; internal ModKeybind ToggleFavoritedPanelHotKey; @@ -80,6 +81,7 @@ public override void Load() { */ ToggleRecipeBrowserHotKey = KeybindLoader.RegisterKeybind(this, "ToggleRecipeBrowser", "OemCloseBrackets"); + CloseRecipeBrowserHotKey = KeybindLoader.RegisterKeybind(this, "CloseRecipeBrowser", "Esc"); QueryHoveredItemHotKey = KeybindLoader.RegisterKeybind(this, "QueryHoveredItem", "Mouse3"); ToggleFavoritedPanelHotKey = KeybindLoader.RegisterKeybind(this, "ToggleFavoritedRecipesWindow", "F3"); /* @@ -118,6 +120,7 @@ public override void Unload() itemChecklistInstance = null; LootCache.instance = null; ToggleRecipeBrowserHotKey = null; + CloseRecipeBrowserHotKey = null; QueryHoveredItemHotKey = null; RecipeBrowserUI.instance = null; RecipeCatalogueUI.instance = null; diff --git a/RecipeBrowserPlayer.cs b/RecipeBrowserPlayer.cs index 127194c..6d70196 100644 --- a/RecipeBrowserPlayer.cs +++ b/RecipeBrowserPlayer.cs @@ -174,6 +174,18 @@ public override void ProcessTriggers(TriggersSet triggersSet) { //if (!RecipeBrowser.instance.CheatSheetLoaded) { + if (RecipeBrowser.instance.CloseRecipeBrowserHotKey.JustPressed) + { + RecipeBrowserUI.instance.ShowRecipeBrowser = false; + // Debug assistance, allows for reinitializing RecipeBrowserUI + //if (!RecipeBrowserUI.instance.ShowRecipeBrowser) + //{ + // RecipeBrowserUI.instance.RemoveAllChildren(); + // var isInitializedFieldInfo = typeof(Terraria.UI.UIElement).GetField("_isInitialized", BindingFlags.Instance | BindingFlags.NonPublic); + // isInitializedFieldInfo.SetValue(RecipeBrowserUI.instance, false); + // RecipeBrowserUI.instance.Activate(); + //} + } if (RecipeBrowser.instance.ToggleRecipeBrowserHotKey.JustPressed) { RecipeBrowserUI.instance.ShowRecipeBrowser = !RecipeBrowserUI.instance.ShowRecipeBrowser;