diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs index e08beec..4b99ad6 100644 --- a/stardew-access/Patches/GeodeMenuPatch.cs +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -5,7 +5,7 @@ namespace stardew_access.Patches { internal class GeodeMenuPatch { - internal static string geodeMenuQueryKey = ""; + private static string geodeMenuQueryKey = ""; internal static void DrawPatch(GeodeMenu __instance) { @@ -13,77 +13,11 @@ namespace stardew_access.Patches { 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; + if (narrateRecievedTreasure(__instance)) return; + if (narrateHoveredButton(__instance, x, y)) return; - 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) { @@ -91,6 +25,60 @@ namespace stardew_access.Patches } } + private static bool narrateRecievedTreasure(GeodeMenu __instance) + { + // Narrates the treasure recieved on breaking the geode + if (__instance.geodeTreasure == null) return false; + + 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 true; + } + + private static bool narrateHoveredButton(GeodeMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) + { + toSpeak = "Place geode here"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop item here"; + isDropItemButton = true; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash can"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok button"; + } + else + { + return false; + } + + if (geodeMenuQueryKey == toSpeak) return true; + + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + internal static void Cleanup() { geodeMenuQueryKey = ""; diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 49c552f..63278ca 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -309,6 +309,10 @@ namespace stardew_access.Patches { MenuPatches.pondQueryMenuQuery = " "; } + else if (menu is GeodeMenu) + { + GeodeMenuPatch.Cleanup(); + } InventoryUtils.Cleanup(); TextBoxPatch.activeTextBoxes = "";