From 6730fcceff5a6b2d44608a75a8fc891e7ceac4b3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:29:51 +0530 Subject: [PATCH] Moved geode menu patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 86 ---------------- stardew-access/Patches/GeodeMenuPatch.cs | 99 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 101 insertions(+), 88 deletions(-) create mode 100644 stardew-access/Patches/GeodeMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index ef00a10..d0fe365 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -95,7 +95,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(GeodeMenu), nameof(GeodeMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.GeodeMenuPatch)) + postfix: new HarmonyMethod(typeof(GeodeMenuPatch), nameof(GeodeMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index e84f888..d7c3891 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -8,7 +8,6 @@ namespace stardew_access.Patches internal class GameMenuPatches { internal static string hoveredItemQueryKey = ""; - internal static string geodeMenuQueryKey = ""; internal static string gameMenuQueryKey = ""; internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; @@ -214,91 +213,6 @@ namespace stardew_access.Patches } } - internal static void GeodeMenuPatch(GeodeMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - #region Narrate the treasure recieved on breaking the geode - if (__instance.geodeTreasure != null) - { - string name = __instance.geodeTreasure.DisplayName; - int stack = __instance.geodeTreasure.Stack; - - string toSpeak = $"Recieved {stack} {name}"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered buttons in the menu - if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) - { - string toSpeak = "Place geode here"; - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop item here"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash can"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok button"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - geodeMenuQueryKey = ""; - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) { try diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs new file mode 100644 index 0000000..e08beec --- /dev/null +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -0,0 +1,99 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class GeodeMenuPatch + { + internal static string geodeMenuQueryKey = ""; + + internal static void DrawPatch(GeodeMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + #region Narrate the treasure recieved on breaking the geode + if (__instance.geodeTreasure != null) + { + string name = __instance.geodeTreasure.DisplayName; + int stack = __instance.geodeTreasure.Stack; + + string toSpeak = $"Recieved {stack} {name}"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered buttons in the menu + if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) + { + string toSpeak = "Place geode here"; + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop item here"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash can"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Ok button"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + geodeMenuQueryKey = ""; + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + geodeMenuQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 9866068..b1be281 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -59,7 +59,7 @@ namespace stardew_access.Patches } else if (menu is GeodeMenu) { - GameMenuPatches.geodeMenuQueryKey = ""; + GeodeMenuPatch.Cleanup(); } else if (menu is CarpenterMenu) {