diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index b6cf1e3..f894686 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -189,7 +189,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ItemListMenu), nameof(ItemListMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ItemListMenuPatch)) + postfix: new HarmonyMethod(typeof(ItemListMenuPatch), nameof(ItemListMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index f935345..35ffe98 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -296,7 +296,7 @@ namespace stardew_access.Patches } else if (menu is ItemListMenu) { - MenuPatches.itemListMenuQuery = " "; + ItemListMenuPatch.Cleanup(); } else if (menu is FieldOfficeMenu) { diff --git a/stardew-access/Patches/ItemListMenuPatch.cs b/stardew-access/Patches/ItemListMenuPatch.cs new file mode 100644 index 0000000..e94a206 --- /dev/null +++ b/stardew-access/Patches/ItemListMenuPatch.cs @@ -0,0 +1,55 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ItemListMenuPatch + { + private static string itemListMenuQuery = ""; + + internal static void DrawPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = "", currentList = ""; + + for (int i = ___currentTab * __instance.itemsPerCategoryPage; i < ___currentTab * __instance.itemsPerCategoryPage + __instance.itemsPerCategoryPage; i++) + { + if (i == 0) currentList = ___title; + if (___itemsToList.Count <= i) continue; + + if (___itemsToList[i] == null) + { + currentList = $"{currentList}, \n" + Game1.content.LoadString("Strings\\UI:ItemList_ItemsLostValue", ___totalValueOfItems); + continue; + } + + currentList = $"{currentList}, \n {___itemsToList[i].Stack} {___itemsToList[i].DisplayName}"; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = $"Page {___currentTab + 1} of {((int)___itemsToList.Count / __instance.itemsPerCategoryPage) + 1} \n {currentList} \n ok button"; + else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next page button"; + else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + toSpeak = "Previous page button"; + + if (itemListMenuQuery != toSpeak) + { + itemListMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + itemListMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 46acc3f..20ca4c4 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -15,52 +15,8 @@ namespace stardew_access.Patches internal static string tailoringMenuQuery = " "; internal static string pondQueryMenuQuery = " "; internal static string forgeMenuQuery = " "; - internal static string itemListMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " ", currentList = " "; - - for (int i = ___currentTab * __instance.itemsPerCategoryPage; i < ___currentTab * __instance.itemsPerCategoryPage + __instance.itemsPerCategoryPage; i++) - { - if (i == 0) - currentList = ___title; - - if (___itemsToList.Count > i) - { - if (___itemsToList[i] == null) - { - currentList = $"{currentList}, \n" + Game1.content.LoadString("Strings\\UI:ItemList_ItemsLostValue", ___totalValueOfItems); - continue; - } - - currentList = $"{currentList}, \n {___itemsToList[i].Stack} {___itemsToList[i].DisplayName}"; - } - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = $"Page {___currentTab + 1} of {((int)___itemsToList.Count / __instance.itemsPerCategoryPage) + 1} \n {currentList} \n ok button"; - else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next page button"; - else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - toSpeak = "Previous page button"; - - if (itemListMenuQuery != toSpeak) - { - itemListMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ForgeMenuPatch(ForgeMenu __instance) { try @@ -570,7 +526,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - } }