diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index cfa32b7..2064352 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -132,6 +132,11 @@ namespace stardew_access original: AccessTools.Method(typeof(GeodeMenu), nameof(GeodeMenu.draw), new Type[] { typeof(SpriteBatch) }), postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.GeodeMenuPatch)) ); + + harmony.Patch( + original: AccessTools.Method(typeof(ShopMenu), nameof(ShopMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ShopMenuPatch)) + ); #endregion #region Menu Patches diff --git a/stardew-access/Patches/DialoguePatches.cs b/stardew-access/Patches/DialoguePatches.cs index c47fdf3..ceb1666 100644 --- a/stardew-access/Patches/DialoguePatches.cs +++ b/stardew-access/Patches/DialoguePatches.cs @@ -138,7 +138,10 @@ namespace stardew_access.Patches return; if (Game1.activeClickableMenu is ItemGrabMenu) - return; + return; + + if (Game1.activeClickableMenu is ShopMenu) + return; #endregion StringBuilder toSpeak = new StringBuilder(" "); diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 11929bd..946cf27 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -16,9 +16,97 @@ namespace stardew_access.Patches internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; + internal static string shopMenuQueryKey = ""; internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; + internal static void ShopMenuPatch(ShopMenu __instance) + { + try + { + int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position + bool isIPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.I); + bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); + + if (isLeftShiftPressed && isIPressed && __instance.inventory.inventory.Count>0) + { + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + } + else if (!isLeftShiftPressed && isIPressed && __instance.forSaleButtons.Count>0) + { + __instance.forSaleButtons[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.forSaleButtons[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 = ""; + ScreenReader.say(toSpeak, true); + Game1.playSound("sa_drop_item"); + } + return; + } + if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) + { + string toSpeak = "Up Arrow Button"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + 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 = ""; + ScreenReader.say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (narrateHoveredItemInInventory(__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 toSpeak = $"{name}, {price}, \n\t{description}"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + ScreenReader.say(toSpeak, true); + } + } + #endregion + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + internal static void GameMenuPatch(GameMenu __instance) { try @@ -141,10 +229,10 @@ namespace stardew_access.Patches bool isIPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.I); bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); - if(isLeftShiftPressed && isIPressed && __instance.inventory != null) + if(isLeftShiftPressed && isIPressed && __instance.inventory.inventory.Count > 0) { __instance.inventory.inventory[0].snapMouseCursorToCenter(); - }else if(!isLeftShiftPressed && isIPressed && __instance.ItemsToGrabMenu != null) + }else if(!isLeftShiftPressed && isIPressed && __instance.ItemsToGrabMenu.inventory.Count > 0) { __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); } @@ -242,18 +330,19 @@ namespace stardew_access.Patches bool isCPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.C); bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); - if (isLeftShiftPressed && isIPressed && __instance.inventory != null) + if (isLeftShiftPressed && isIPressed && __instance.inventory.inventory.Count > 0) { // snap to first inventory slot __instance.inventory.inventory[0].snapMouseCursorToCenter(); currentSelectedCraftingRecipe = -1; } - else if (!isLeftShiftPressed && isIPressed && __instance.inventory != null) + else if (!isLeftShiftPressed && isIPressed && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count>0) { // snap to first crafting recipe __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); currentSelectedCraftingRecipe = 0; - } else if (isCPressed && !isSelectingRecipe) + } + else if (isCPressed && !isSelectingRecipe) { _ = CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage); } @@ -436,6 +525,7 @@ namespace stardew_access.Patches { int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position + #region Narrate buttons in the menu if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) { string toSpeak = "Drop Item"; @@ -474,7 +564,8 @@ namespace stardew_access.Patches ScreenReader.say(toSpeak, true); } return; - } + } + #endregion #region Narrate equipment slots for (int i=0; i<__instance.equipmentIcons.Count; i++) @@ -672,12 +763,11 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } - internal static bool narrateHoveredItemInInventory(List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false) + internal static bool narrateHoveredItemInInventory(List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1) { #region Narrate hovered item for (int i = 0; i < inventory.Count; i++) @@ -695,6 +785,7 @@ namespace stardew_access.Patches string healthNStamine = ""; string buffs = ""; string description = ""; + string price = ""; #region Add quality of item if (actualInventory[i] is StardewValley.Object && (actualInventory[i] as StardewValley.Object).quality > 0) @@ -756,19 +847,24 @@ namespace stardew_access.Patches #endregion } + if (hoverPrice != -1) + { + price = $"Sell Price: {hoverPrice} g"; + } + if (giveExtraDetails) { if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{description}, \n{healthNStamine}, \n{buffs}"; + toSpeak = $"{stack} {name} {quality}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; else - toSpeak = $"{name} {quality}, \n{description}, \n{healthNStamine}, \n{buffs}"; + toSpeak = $"{name} {quality}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; } else { if (stack > 1) - toSpeak = $"{stack} {name} {quality}"; + toSpeak = $"{stack} {name} {quality}, \n{price}"; else - toSpeak = $"{name} {quality}"; + toSpeak = $"{name} {quality}, \n{price}"; } } else diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 78ac66f..48affc9 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -286,11 +286,16 @@ namespace stardew_access.Patches GameMenuPatches.geodeMenuQueryKey = ""; } - if(__instance is ItemGrabMenu) + if (__instance is ItemGrabMenu) { GameMenuPatches.itemGrabMenuQueryKey = ""; } + if (__instance is ShopMenu) + { + GameMenuPatches.shopMenuQueryKey = ""; + } + GameMenuPatches.hoveredItemQueryKey = ""; } catch (Exception e)