From 8d11cc6266a83ef0ad21ab6f4ccf335fa29058d2 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:40:01 +0530 Subject: [PATCH] Moved exit page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 40 ---------------- .../Patches/GameMenuPatches/ExitPagePatch.cs | 48 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 885a78a..395fe61 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -75,7 +75,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ExitPage), nameof(ExitPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ExitPagePatch)) + postfix: new HarmonyMethod(typeof(ExitPagePatch), nameof(ExitPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index ae93dc8..d12998b 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -4,13 +4,9 @@ using StardewValley.Objects; namespace stardew_access.Patches { - // Menus in the game menu i.e., the menu which opens when we press `e` internal class GameMenuPatches { - internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string exitPageQueryKey = ""; - internal static string profilePageQuery = ""; internal static void GameMenuPatch(GameMenu __instance) { @@ -42,41 +38,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - - internal static void ExitPagePatch(ExitPage __instance) - { - try - { - if (__instance.exitToTitle.visible && - __instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = "Exit to Title Button"; - if (exitPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.exitToDesktop.visible && - __instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = "Exit to Desktop Button"; - if (exitPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } } } diff --git a/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs b/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs new file mode 100644 index 0000000..81431f7 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs @@ -0,0 +1,48 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ExitPagePatch + { + internal static string exitPageQueryKey = ""; + + internal static void DrawPatch(ExitPage __instance) + { + try + { + if (__instance.exitToTitle.visible && + __instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string toSpeak = "Exit to Title Button"; + if (exitPageQueryKey != toSpeak) + { + exitPageQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.exitToDesktop.visible && + __instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string toSpeak = "Exit to Desktop Button"; + if (exitPageQueryKey != toSpeak) + { + exitPageQueryKey = 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() + { + exitPageQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 644f9c0..04e6715 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -34,7 +34,7 @@ namespace stardew_access.Patches else if (menu is GameMenu) { GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.exitPageQueryKey = ""; + ExitPagePatch.Cleanup(); OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); InventoryPagePatch.Cleanup();