diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 3ca34b7..dfa26fb 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -84,7 +84,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ExitPage), nameof(ExitPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.ExitPagePatch)) + postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ExitPagePatch)) ); harmony.Patch( @@ -114,7 +114,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(OptionsPage), nameof(OptionsPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.OptionsPagePatch)) + postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.OptionsPagePatch)) ); harmony.Patch( @@ -152,6 +152,11 @@ namespace stardew_access postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.LanguageSelectionMenuPatch)) ); + harmony.Patch( + original: AccessTools.Method(typeof(CraftingPage), nameof(CraftingPage.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.CraftingPagePatch)) + ); + #endregion #region Custom Commands diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs new file mode 100644 index 0000000..10724fd --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -0,0 +1,116 @@ + +using StardewModdingAPI; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class GameMenuPatches + { + internal static void CraftingPagePatch(CraftingPage __instance) + { + try + { + int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position + + if(__instance.upButton != null && __instance.upButton.containsPoint(x, y)) + { + ScreenReader.sayWithMenuChecker("Previous Recipe List", true); + return; + } + + if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) + { + ScreenReader.sayWithMenuChecker("Next Recipe List", true); + return; + } + + if(__instance.trashCan.containsPoint(x, y)) + { + ScreenReader.sayWithMenuChecker("Trash Can", true); + return; + } + + if(__instance.dropItemInvisibleButton.containsPoint(x, y)) + { + ScreenReader.sayWithMenuChecker("Drop Item", true); + return; + } + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + + internal static void OptionsPagePatch(OptionsPage __instance) + { + try + { + int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); + int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; + for (int i = 0; i < __instance.optionSlots.Count; i++) + { + if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) + { + OptionsElement optionsElement = __instance.options[currentItemIndex + i]; + string toSpeak = optionsElement.label; + + if (optionsElement is OptionsButton) + toSpeak = $" {toSpeak} Button"; + else if (optionsElement is OptionsCheckbox) + toSpeak = ((optionsElement as OptionsCheckbox).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; + else if (optionsElement is OptionsDropDown) + toSpeak = $"{toSpeak} Dropdown, option {(optionsElement as OptionsDropDown).dropDownDisplayOptions[(optionsElement as OptionsDropDown).selectedOption]} selected"; + else if (optionsElement is OptionsSlider) + toSpeak = $"{(optionsElement as OptionsSlider).value}% {toSpeak} Slider"; + else if (optionsElement is OptionsPlusMinus) + toSpeak = $"{(optionsElement as OptionsPlusMinus).displayOptions[(optionsElement as OptionsPlusMinus).selected]} selected of {toSpeak}"; + else if (optionsElement is OptionsInputListener) + { + string buttons = ""; + (optionsElement as OptionsInputListener).buttonNames.ForEach(name => { buttons += $", {name}"; }); + toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; + } + else + { + if (toSpeak.Contains(":")) + toSpeak = toSpeak.Replace(":", ""); + + toSpeak = $"{toSpeak} Options:"; + } + + ScreenReader.sayWithChecker(toSpeak, true); + break; + } + } + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + + internal static void ExitPagePatch(ExitPage __instance) + { + try + { + if (__instance.exitToTitle.visible && + __instance.exitToTitle.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) + { + ScreenReader.sayWithChecker("Exit to Title Button", true); + } + if (__instance.exitToDesktop.visible && + __instance.exitToDesktop.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) + { + ScreenReader.sayWithChecker("Exit to Desktop Button", true); + } + } + catch (Exception e) + { + + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + } +} diff --git a/stardew-access/Patches/MenuPatch.cs b/stardew-access/Patches/MenuPatch.cs index e971ce8..7db822d 100644 --- a/stardew-access/Patches/MenuPatch.cs +++ b/stardew-access/Patches/MenuPatch.cs @@ -102,54 +102,6 @@ namespace stardew_access.Patches } } - internal static void OptionsPagePatch(OptionsPage __instance) - { - try - { - int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); - int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; - for (int i = 0; i < __instance.optionSlots.Count; i++) - { - if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) - { - OptionsElement optionsElement = __instance.options[currentItemIndex + i]; - string toSpeak = optionsElement.label; - - if (optionsElement is OptionsButton) - toSpeak = $" {toSpeak} Button"; - else if (optionsElement is OptionsCheckbox) - toSpeak = ((optionsElement as OptionsCheckbox).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; - else if (optionsElement is OptionsDropDown) - toSpeak = $"{toSpeak} Dropdown, option {(optionsElement as OptionsDropDown).dropDownDisplayOptions[(optionsElement as OptionsDropDown).selectedOption]} selected"; - else if (optionsElement is OptionsSlider) - toSpeak = $"{(optionsElement as OptionsSlider).value}% {toSpeak} Slider"; - else if (optionsElement is OptionsPlusMinus) - toSpeak = $"{(optionsElement as OptionsPlusMinus).displayOptions[(optionsElement as OptionsPlusMinus).selected]} selected of {toSpeak}"; - else if (optionsElement is OptionsInputListener) - { - string buttons = ""; - (optionsElement as OptionsInputListener).buttonNames.ForEach(name => { buttons += $", {name}"; }); - toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; - } - else - { - if (toSpeak.Contains(":")) - toSpeak = toSpeak.Replace(":", ""); - - toSpeak = $"{toSpeak} Options:"; - } - - ScreenReader.sayWithChecker(toSpeak, true); - break; - } - } - } - catch (Exception e) - { - MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); - } - } - internal static void LevelUpMenuPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title) { try @@ -470,28 +422,6 @@ namespace stardew_access.Patches } } - internal static void ExitPagePatch(ExitPage __instance) - { - try - { - if (__instance.exitToTitle.visible && - __instance.exitToTitle.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) - { - ScreenReader.sayWithChecker("Exit to Title Button", true); - } - if (__instance.exitToDesktop.visible && - __instance.exitToDesktop.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) - { - ScreenReader.sayWithChecker("Exit to Desktop Button", true); - } - } - catch (Exception e) - { - - MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); - } - } - internal static void resetGlobalVars() { currentLetterText = " ";