diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index f2dd7ff..a77c76e 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -16,12 +16,12 @@ namespace stardew_access #region Dialogue Patches harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.DialoguePatch)) + postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.RecieveLeftClickPatch)) + postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.RecieveLeftClickPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/DialogueBoxPatch.cs b/stardew-access/Patches/DialogueBoxPatch.cs index 5f036e7..bc471d6 100644 --- a/stardew-access/Patches/DialogueBoxPatch.cs +++ b/stardew-access/Patches/DialogueBoxPatch.cs @@ -1,17 +1,14 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; +using StardewValley; using StardewValley.Menus; namespace stardew_access.Patches { - internal class DialoguePatches + internal class DialogueBoxPatch { private static string currentDialogue = ""; - private static string previousSpeakerName = ""; private static bool isDialogueAppearingFirstTime = true; - internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) + internal static void DrawPatch(DialogueBox __instance) { try { diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 8e92817..765efbd 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -283,7 +283,7 @@ namespace stardew_access.Patches } else if (menu is DialogueBox) { - DialoguePatches.Cleanup(); + DialogueBoxPatch.Cleanup(); } else if (menu is JojaCDMenu) { diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 8da8b11..5f5e16b 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -25,88 +25,15 @@ namespace stardew_access.Patches __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); } - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) - { - string toSpeak = "Up Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) - { - string toSpeak = "Down Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion + if (narrateHoveredButton(__instance, x, y)) return; - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) { shopMenuQueryKey = ""; return; } - #endregion - #region Narrate hovered selling item - if (__instance.hoveredItem != null) - { - string name = __instance.hoveredItem.DisplayName; - string price = $"Buy Price: {__instance.hoverPrice} g"; - string description = __instance.hoveredItem.getDescription(); - string requirements = ""; - - #region Narrate required items for item - int itemIndex = -1, itemAmount = 5; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) - itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) - itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; - - if (itemIndex != -1) - { - string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; - - if (itemAmount != -1) - requirements = $"Required: {itemAmount} {itemName}"; - else - requirements = $"Required: {itemName}"; - } - #endregion - - string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion + narrateHoveredSellingItem(__instance); } catch (Exception e) { @@ -114,6 +41,75 @@ namespace stardew_access.Patches } } + private static bool narrateHoveredButton(ShopMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) + { + toSpeak = "Up Arrow Button"; + } + else if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) + { + toSpeak = "Down Arrow Button"; + } + else + { + return false; + } + + if (shopMenuQueryKey == toSpeak) return true; + + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + + private static void narrateHoveredSellingItem(ShopMenu __instance) + { + if (__instance.hoveredItem == null) return; + + string name = __instance.hoveredItem.DisplayName; + string price = $"Buy Price: {__instance.hoverPrice} g"; + string description = __instance.hoveredItem.getDescription(); + string requirements = ""; + + #region get required items for item + int itemIndex = -1, itemAmount = 5; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) + itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) + itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; + + if (itemIndex != -1) + { + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + requirements = $"Required: {itemAmount} {itemName}"; + else + requirements = $"Required: {itemName}"; + } + #endregion + + string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; + if (shopMenuQueryKey == toSpeak) return; + + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + internal static void Cleanup() { shopMenuQueryKey = "";