diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 1948818..ef00a10 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -90,7 +90,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ItemGrabMenu), nameof(ItemGrabMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ItemGrabMenuPatch)) + postfix: new HarmonyMethod(typeof(ItemGrabMenuPatch), nameof(ItemGrabMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index bdca60c..e84f888 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -10,7 +10,6 @@ namespace stardew_access.Patches internal static string hoveredItemQueryKey = ""; internal static string geodeMenuQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string itemGrabMenuQueryKey = ""; internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; @@ -201,6 +200,7 @@ namespace stardew_access.Patches string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab"; if (gameMenuQueryKey != toSpeak) { + MainClass.DebugLog("here"); gameMenuQueryKey = toSpeak; MainClass.ScreenReader.Say(toSpeak, true); } @@ -298,267 +298,6 @@ namespace stardew_access.Patches } } - internal static void ItemGrabMenuPatch(ItemGrabMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) - { - __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); - __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); - } - - #region Narrate buttons in the menu - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - gameMenuQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) - { - string toSpeak = "Add to existing stacks button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) - { - string toSpeak = "Special Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) - { - - string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - // FIXME - /*if (__instance.discreteColorPickerCC.Count > 0) { - for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) - { - if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) - { - MainClass.monitor.Log(i.ToString(), LogLevel.Debug); - string toSpeak = getChestColorName(i); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - ScreenReader.say(toSpeak, true); - Game1.playSound("sa_drop_item"); - } - return; - } - } - }*/ - #endregion - - #region Narrate the last shipped item if in the shipping bin - if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) - { - Item lastShippedItem = Game1.getFarm().lastItemShipped; - string name = lastShippedItem.DisplayName; - int count = lastShippedItem.Stack; - - string toSpeak = $"Last Shipped: {count} {name}"; - - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - itemGrabMenuQueryKey = ""; - return; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - itemGrabMenuQueryKey = ""; - return; - } - - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - // TODO Add color names - private static string getChestColorName(int i) - { - string toReturn = ""; - switch (i) - { - case 0: - toReturn = "Default chest color"; - break; - case 1: - toReturn = "Default chest color"; - break; - case 2: - toReturn = "Default chest color"; - break; - case 3: - toReturn = "Default chest color"; - break; - case 4: - toReturn = "Default chest color"; - break; - case 5: - toReturn = "Default chest color"; - break; - case 6: - toReturn = "Default chest color"; - break; - case 7: - toReturn = "Default chest color"; - break; - case 8: - toReturn = "Default chest color"; - break; - case 9: - toReturn = "Default chest color"; - break; - case 10: - toReturn = "Default chest color"; - break; - case 11: - toReturn = "Default chest color"; - break; - case 12: - toReturn = "Default chest color"; - break; - case 13: - toReturn = "Default chest color"; - break; - case 14: - toReturn = "Default chest color"; - break; - case 15: - toReturn = "Default chest color"; - break; - case 16: - toReturn = "Default chest color"; - break; - case 17: - toReturn = "Default chest color"; - break; - case 18: - toReturn = "Default chest color"; - break; - case 19: - toReturn = "Default chest color"; - break; - case 20: - toReturn = "Default chest color"; - break; - } - return toReturn; - } internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) { @@ -838,9 +577,9 @@ namespace stardew_access.Patches if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) { string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) + if (inventoryPageQueryKey != toSpeak) { - itemGrabMenuQueryKey = toSpeak; + inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; MainClass.ScreenReader.Say(toSpeak, true); @@ -851,9 +590,9 @@ namespace stardew_access.Patches { string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) + if (inventoryPageQueryKey != toSpeak) { - itemGrabMenuQueryKey = toSpeak; + inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; MainClass.ScreenReader.Say(toSpeak, true); diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 67c91a1..9866068 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -55,7 +55,7 @@ namespace stardew_access.Patches } else if (menu is ItemGrabMenu) { - GameMenuPatches.itemGrabMenuQueryKey = ""; + ItemGrabMenuPatch.Cleanup(); } else if (menu is GeodeMenu) { diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs new file mode 100644 index 0000000..664d810 --- /dev/null +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -0,0 +1,266 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ItemGrabMenuPatch + { + internal static string itemGrabMenuQueryKey = ""; + internal static string hoveredItemQueryKey = ""; + + internal static void DrawPatch(ItemGrabMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) + { + __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); + __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); + } + + #region Narrate buttons in the menu + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Ok Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash Can"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + string toSpeak = "Organize Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) + { + string toSpeak = "Add to existing stacks button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) + { + string toSpeak = "Special Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) + { + + string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + + string toSpeak = "Community Center Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + + // FIXME + /*if (__instance.discreteColorPickerCC.Count > 0) { + for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) + { + if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) + { + MainClass.monitor.Log(i.ToString(), LogLevel.Debug); + string toSpeak = getChestColorName(i); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + ScreenReader.say(toSpeak, true); + Game1.playSound("sa_drop_item"); + } + return; + } + } + }*/ + #endregion + + #region Narrate the last shipped item if in the shipping bin + if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) + { + Item lastShippedItem = Game1.getFarm().lastItemShipped; + string name = lastShippedItem.DisplayName; + int count = lastShippedItem.Stack; + + string toSpeak = $"Last Shipped: {count} {name}"; + + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + { + itemGrabMenuQueryKey = ""; + return; + } + + if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) + { + itemGrabMenuQueryKey = ""; + return; + } + + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + // TODO Add color names + private static string getChestColorName(int i) + { + string toReturn = ""; + switch (i) + { + case 0: + toReturn = "Default chest color"; + break; + case 1: + toReturn = "Default chest color"; + break; + case 2: + toReturn = "Default chest color"; + break; + case 3: + toReturn = "Default chest color"; + break; + case 4: + toReturn = "Default chest color"; + break; + case 5: + toReturn = "Default chest color"; + break; + case 6: + toReturn = "Default chest color"; + break; + case 7: + toReturn = "Default chest color"; + break; + case 8: + toReturn = "Default chest color"; + break; + case 9: + toReturn = "Default chest color"; + break; + case 10: + toReturn = "Default chest color"; + break; + case 11: + toReturn = "Default chest color"; + break; + case 12: + toReturn = "Default chest color"; + break; + case 13: + toReturn = "Default chest color"; + break; + case 14: + toReturn = "Default chest color"; + break; + case 15: + toReturn = "Default chest color"; + break; + case 16: + toReturn = "Default chest color"; + break; + case 17: + toReturn = "Default chest color"; + break; + case 18: + toReturn = "Default chest color"; + break; + case 19: + toReturn = "Default chest color"; + break; + case 20: + toReturn = "Default chest color"; + break; + } + return toReturn; + } + + internal static void Cleanup() { + hoveredItemQueryKey = ""; + itemGrabMenuQueryKey = ""; + } + } +}