diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 5e84c6b..d576d60 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -179,7 +179,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(PondQueryMenu), nameof(PondQueryMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.PondQueryMenuPatch)) + postfix: new HarmonyMethod(typeof(PondQueryMenuPatch), nameof(PondQueryMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 6f8f121..993c4f3 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -308,7 +308,7 @@ namespace stardew_access.Patches } else if (menu is PondQueryMenu) { - MenuPatches.pondQueryMenuQuery = " "; + PondQueryMenuPatch.Cleanup(); } else if (menu is GeodeMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 9a1b2d4..0cca006 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -11,65 +11,9 @@ namespace stardew_access.Patches { internal static string currentLevelUpTitle = " "; internal static bool firstTimeInNamingMenu = true; - internal static bool isNarratingPondInfo = false; internal static string tailoringMenuQuery = " "; - internal static string pondQueryMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void PondQueryMenuPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - string toSpeak = " ", extra = ""; - - if (___confirmingEmpty) - { - if (__instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm button"; - else if (__instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel button"; - } - else - { - if (isPrimaryInfoKeyPressed && !isNarratingPondInfo) - { - string pond_name_text = Game1.content.LoadString("Strings\\UI:PondQuery_Name", ____fishItem.DisplayName); - string population_text = Game1.content.LoadString("Strings\\UI:PondQuery_Population", string.Concat(____pond.FishCount), ____pond.maxOccupants.Value); - bool has_unresolved_needs = ____pond.neededItem.Value != null && ____pond.HasUnresolvedNeeds() && !____pond.hasCompletedRequest.Value; - string bring_text = ""; - - if (has_unresolved_needs && ____pond.neededItem.Value != null) - bring_text = Game1.content.LoadString("Strings\\UI:PondQuery_StatusRequest_Bring") + $": {____pond.neededItemCount} {____pond.neededItem.Value.DisplayName}"; - - extra = $"{pond_name_text} {population_text} {bring_text} Status: {____statusText}"; - pondQueryMenuQuery = " "; - - isNarratingPondInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingPondInfo = false; }); - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "Ok button"; - else if (__instance.changeNettingButton != null && __instance.changeNettingButton.containsPoint(x, y)) - toSpeak = "Change netting button"; - else if (__instance.emptyButton != null && __instance.emptyButton.containsPoint(x, y)) - toSpeak = "Empty pond button"; - } - - if (pondQueryMenuQuery != toSpeak) - { - pondQueryMenuQuery = toSpeak; - MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void TailoringMenuPatch(TailoringMenu __instance) { try diff --git a/stardew-access/Patches/PondQuerMenuPatch.cs b/stardew-access/Patches/PondQuerMenuPatch.cs new file mode 100644 index 0000000..a370fc1 --- /dev/null +++ b/stardew-access/Patches/PondQuerMenuPatch.cs @@ -0,0 +1,72 @@ +using StardewValley; +using StardewValley.Buildings; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class PondQueryMenuPatch + { + private static string pondQueryMenuQuery = ""; + private static bool isNarratingPondInfo = false; + + internal static void DrawPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + string toSpeak = "", extra = ""; + + if (___confirmingEmpty) + { + if (__instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm button"; + else if (__instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel button"; + } + else + { + if (isPrimaryInfoKeyPressed && !isNarratingPondInfo) + { + string pond_name_text = Game1.content.LoadString("Strings\\UI:PondQuery_Name", ____fishItem.DisplayName); + string population_text = Game1.content.LoadString("Strings\\UI:PondQuery_Population", string.Concat(____pond.FishCount), ____pond.maxOccupants.Value); + bool has_unresolved_needs = ____pond.neededItem.Value != null && ____pond.HasUnresolvedNeeds() && !____pond.hasCompletedRequest.Value; + string bring_text = ""; + + if (has_unresolved_needs && ____pond.neededItem.Value != null) + bring_text = Game1.content.LoadString("Strings\\UI:PondQuery_StatusRequest_Bring") + $": {____pond.neededItemCount} {____pond.neededItem.Value.DisplayName}"; + + extra = $"{pond_name_text} {population_text} {bring_text} Status: {____statusText}"; + pondQueryMenuQuery = ""; + + isNarratingPondInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingPondInfo = false; }); + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "Ok button"; + else if (__instance.changeNettingButton != null && __instance.changeNettingButton.containsPoint(x, y)) + toSpeak = "Change netting button"; + else if (__instance.emptyButton != null && __instance.emptyButton.containsPoint(x, y)) + toSpeak = "Empty pond button"; + } + + if (pondQueryMenuQuery != toSpeak) + { + pondQueryMenuQuery = toSpeak; + MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + pondQueryMenuQuery = ""; + isNarratingPondInfo = false; + } + } +}