diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 6cc7464..885a78a 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -70,7 +70,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(OptionsPage), nameof(OptionsPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.OptionsPagePatch)) + postfix: new HarmonyMethod(typeof(OptionsPagePatch), nameof(OptionsPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 84c7300..ae93dc8 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 gameMenuQueryKey = ""; internal static string exitPageQueryKey = ""; - internal static string optionsPageQueryKey = ""; internal static string profilePageQuery = ""; internal static void GameMenuPatch(GameMenu __instance) @@ -45,59 +44,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.getMouseX(true), y = Game1.getMouseY(true); - 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 = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; - else if (optionsElement is OptionsDropDown) - toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; - else if (optionsElement is OptionsSlider) - toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; - else if (optionsElement is OptionsPlusMinus) - toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; - else if (optionsElement is OptionsInputListener) - { - string buttons = ""; - ((OptionsInputListener)optionsElement).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:"; - } - - if (optionsPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - optionsPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ExitPagePatch(ExitPage __instance) { try diff --git a/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs new file mode 100644 index 0000000..a05d478 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs @@ -0,0 +1,67 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class OptionsPagePatch + { + internal static string optionsPageQueryKey = ""; + + internal static void DrawPatch(OptionsPage __instance) + { + try + { + int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + 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 = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; + else if (optionsElement is OptionsDropDown) + toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; + else if (optionsElement is OptionsSlider) + toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; + else if (optionsElement is OptionsPlusMinus) + toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; + else if (optionsElement is OptionsInputListener) + { + string buttons = ""; + ((OptionsInputListener)optionsElement).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:"; + } + + if (optionsPageQueryKey != toSpeak) + { + optionsPageQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + optionsPageQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 5e85c02..644f9c0 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -35,7 +35,7 @@ namespace stardew_access.Patches { GameMenuPatches.gameMenuQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; - GameMenuPatches.optionsPageQueryKey = ""; + OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); InventoryPagePatch.Cleanup(); CraftingPagePatch.Cleanup();