From b0c1d9e17368b2d126d518d09afa9340f100d700 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:00:31 +0530 Subject: [PATCH] Moved tailoring menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 89 -------------- stardew-access/Patches/TailoringMenuPatch.cs | 115 ++++++++++++++++++ 4 files changed, 117 insertions(+), 91 deletions(-) create mode 100644 stardew-access/Patches/TailoringMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index d576d60..fc08646 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -174,7 +174,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(TailoringMenu), nameof(TailoringMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.TailoringMenuPatch)) + postfix: new HarmonyMethod(typeof(TailoringMenuPatch), nameof(TailoringMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 993c4f3..6668365 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -288,7 +288,7 @@ namespace stardew_access.Patches } else if (menu is TailoringMenu) { - MenuPatches.tailoringMenuQuery = " "; + TailoringMenuPatch.Cleanup(); } else if (menu is ForgeMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 0cca006..420073d 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -11,97 +11,8 @@ namespace stardew_access.Patches { internal static string currentLevelUpTitle = " "; internal static bool firstTimeInNamingMenu = true; - internal static string tailoringMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void TailoringMenuPatch(TailoringMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " "; - - if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) - { - if (__instance.leftIngredientSpot.item == null) - { - toSpeak = "Input cloth here"; - } - else - { - Item item = __instance.leftIngredientSpot.item; - toSpeak = $"Cloth slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) - { - if (__instance.rightIngredientSpot.item == null) - { - toSpeak = "Input ingredient here"; - } - else - { - Item item = __instance.rightIngredientSpot.item; - toSpeak = $"Ingredient slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) - { - toSpeak = "Star tailoring button"; - } - else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - toSpeak = "Trashcan"; - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "drop item"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) - { - toSpeak = "Hat Slot"; - - if (Game1.player.hat.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.hat.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) - { - toSpeak = "Shirt Slot"; - - if (Game1.player.shirtItem.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.shirtItem.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[2].containsPoint(x, y)) - { - toSpeak = "Pants Slot"; - - if (Game1.player.pantsItem.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}"; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - - if (tailoringMenuQuery != toSpeak) - { - tailoringMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - Game1.playSound("drop_item"); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ChooseFromListMenuPatch(ChooseFromListMenu __instance, List ___options, int ___index, bool ___isJukebox) { try diff --git a/stardew-access/Patches/TailoringMenuPatch.cs b/stardew-access/Patches/TailoringMenuPatch.cs new file mode 100644 index 0000000..3718730 --- /dev/null +++ b/stardew-access/Patches/TailoringMenuPatch.cs @@ -0,0 +1,115 @@ +using stardew_access.Features; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TailoringMenuPatch + { + internal static string tailoringMenuQuery = ""; + + internal static void DrawPatch(TailoringMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; + + + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static bool narrateHoveredButton(TailoringMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) + { + if (__instance.leftIngredientSpot.item == null) + { + toSpeak = "Input cloth here"; + } + else + { + Item item = __instance.leftIngredientSpot.item; + toSpeak = $"Cloth slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) + { + if (__instance.rightIngredientSpot.item == null) + { + toSpeak = "Input ingredient here"; + } + else + { + Item item = __instance.rightIngredientSpot.item; + toSpeak = $"Ingredient slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) + { + toSpeak = "Star tailoring button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trashcan"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "drop item"; + isDropItemButton = true; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) + { + toSpeak = "Hat Slot"; + + if (Game1.player.hat.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.hat.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) + { + toSpeak = "Shirt Slot"; + + if (Game1.player.shirtItem.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.shirtItem.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[2].containsPoint(x, y)) + { + toSpeak = "Pants Slot"; + + if (Game1.player.pantsItem.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}"; + } + else { + return false; + } + + if (tailoringMenuQuery != toSpeak) + { + tailoringMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + internal static void Cleanup() + { + tailoringMenuQuery = ""; + } + } +}