From b8fce68bec27a74a2f0eff61a180b3030043d666 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:24:08 +0530 Subject: [PATCH] Moved more menus to their own class --- stardew-access/HarmonyPatches.cs | 10 +- .../Patches/ConfirmationDialogMenuPatch.cs | 32 +++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/LevelUpMenuPatch.cs | 109 +++++++++ stardew-access/Patches/MenuPatches.cs | 226 ------------------ stardew-access/Patches/NamingMenuPatch.cs | 42 ++++ stardew-access/Patches/ShippingMenuPatch.cs | 46 ++++ .../Patches/TitleTextInputMenuPatch.cs | 27 +++ 8 files changed, 262 insertions(+), 232 deletions(-) create mode 100644 stardew-access/Patches/ConfirmationDialogMenuPatch.cs create mode 100644 stardew-access/Patches/LevelUpMenuPatch.cs delete mode 100644 stardew-access/Patches/MenuPatches.cs create mode 100644 stardew-access/Patches/NamingMenuPatch.cs create mode 100644 stardew-access/Patches/ShippingMenuPatch.cs create mode 100644 stardew-access/Patches/TitleTextInputMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 35db304..5171631 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -134,27 +134,27 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ShippingMenu), nameof(ShippingMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ShippingMenuPatch)) + postfix: new HarmonyMethod(typeof(ShippingMenuPatch), nameof(ShippingMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(LevelUpMenu), nameof(LevelUpMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LevelUpMenuPatch)) + postfix: new HarmonyMethod(typeof(LevelUpMenuPatch), nameof(LevelUpMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(ConfirmationDialog), nameof(ConfirmationDialog.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ConfirmationDialogPatch)) + postfix: new HarmonyMethod(typeof(ConfirmationDialogMenuPatch), nameof(ConfirmationDialogMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(TitleTextInputMenu), nameof(TitleTextInputMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.TitleTextInputMenuPatch)) + postfix: new HarmonyMethod(typeof(TitleTextInputMenuPatch), nameof(TitleTextInputMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(NamingMenu), nameof(NamingMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.NamingMenuPatch)) + postfix: new HarmonyMethod(typeof(NamingMenuPatch), nameof(NamingMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/ConfirmationDialogMenuPatch.cs b/stardew-access/Patches/ConfirmationDialogMenuPatch.cs new file mode 100644 index 0000000..ffde9ec --- /dev/null +++ b/stardew-access/Patches/ConfirmationDialogMenuPatch.cs @@ -0,0 +1,32 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ConfirmationDialogMenuPatch + { + internal static void DrawPatch(ConfirmationDialog __instance, string ___message) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string toSpeak = ___message; + + if (__instance.okButton.containsPoint(x, y)) + { + toSpeak += "\n\tOk Button"; + } + else if (__instance.cancelButton.containsPoint(x, y)) + { + toSpeak += "\n\tCancel Button"; + } + + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 6668365..7069fb5 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -231,7 +231,7 @@ namespace stardew_access.Patches } else if (menu is LevelUpMenu) { - MenuPatches.currentLevelUpTitle = " "; + LevelUpMenuPatch.Cleanup(); } else if (menu is Billboard) { diff --git a/stardew-access/Patches/LevelUpMenuPatch.cs b/stardew-access/Patches/LevelUpMenuPatch.cs new file mode 100644 index 0000000..cb4535b --- /dev/null +++ b/stardew-access/Patches/LevelUpMenuPatch.cs @@ -0,0 +1,109 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class LevelUpMenuPatch + { + private static string currentLevelUpTitle = ""; + + internal static void DrawPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title, bool ___isActive, bool ___isProfessionChooser) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string leftProfession = "", rightProfession = "", extraInfo = "", newCraftingRecipe = "", toSpeak = ""; + + if (!__instance.informationUp) + return; + + if (__instance.isProfessionChooser) + { + if (___professionsToChoose.Count() == 0) return; + + for (int j = 0; j < ___leftProfessionDescription.Count; j++) + { + leftProfession += ___leftProfessionDescription[j] + ", "; + } + for (int i = 0; i < ___rightProfessionDescription.Count; i++) + { + rightProfession += ___rightProfessionDescription[i] + ", "; + } + + if (__instance.leftProfession.containsPoint(x, y)) + { + if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) + { + Game1.player.professions.Add(___professionsToChoose[0]); + __instance.getImmediateProfessionPerk(___professionsToChoose[0]); + ___isActive = false; + __instance.informationUp = false; + ___isProfessionChooser = false; + __instance.RemoveLevelFromLevelList(); + __instance.exitThisMenu(); + return; + } + + toSpeak = $"Selected: {leftProfession} Left click to choose."; + } + + if (__instance.rightProfession.containsPoint(x, y)) + { + if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) + { + Game1.player.professions.Add(___professionsToChoose[1]); + __instance.getImmediateProfessionPerk(___professionsToChoose[1]); + ___isActive = false; + __instance.informationUp = false; + ___isProfessionChooser = false; + __instance.RemoveLevelFromLevelList(); + __instance.exitThisMenu(); + return; + } + + toSpeak = $"Selected: {rightProfession} Left click to choose."; + } + } + else + { + foreach (string s2 in ___extraInfoForLevel) + { + extraInfo += s2 + ", "; + } + foreach (CraftingRecipe s in ___newCraftingRecipes) + { + string cookingOrCrafting = Game1.content.LoadString("Strings\\UI:LearnedRecipe_" + (s.isCookingRecipe ? "cooking" : "crafting")); + string message = Game1.content.LoadString("Strings\\UI:LevelUp_NewRecipe", cookingOrCrafting, s.DisplayName); + + newCraftingRecipe += $"{message}, "; + } + } + + if (__instance.okButton.containsPoint(x, y)) + { + if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) + __instance.okButtonClicked(); + + toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close."; + } + + if (toSpeak != "") + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") + { + MainClass.ScreenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true); + currentLevelUpTitle = $"{___title}. Select a new profession."; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + currentLevelUpTitle = ""; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs deleted file mode 100644 index 6e343cd..0000000 --- a/stardew-access/Patches/MenuPatches.cs +++ /dev/null @@ -1,226 +0,0 @@ -using Microsoft.Xna.Framework; -using stardew_access.Features; -using StardewModdingAPI; -using StardewValley; -using StardewValley.Buildings; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class MenuPatches - { - internal static string currentLevelUpTitle = " "; - internal static bool firstTimeInNamingMenu = true; - internal static int prevSlotIndex = -999; - - - - - internal static void TitleTextInputMenuPatch(TitleTextInputMenu __instance) - { - try - { - string toSpeak = ""; - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.pasteButton != null && __instance.pasteButton.containsPoint(x, y)) - toSpeak = $"Paste button"; - - if (toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void NamingMenuPatch(NamingMenu __instance, TextBox ___textBox, string ___title) - { - try - { - if (firstTimeInNamingMenu) - { - firstTimeInNamingMenu = false; - ___textBox.Selected = false; - } - - if (TextBoxPatch.isAnyTextBoxActive) return; - - string toSpeak = ""; - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box - - if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = $"{___title} text box"; - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - toSpeak = $"Done naming button"; - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - toSpeak = $"Random button"; - - if (toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void ConfirmationDialogPatch(ConfirmationDialog __instance, string ___message) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - string toSpeak = ___message; - - if (__instance.okButton.containsPoint(x, y)) - { - toSpeak += "\n\tOk Button"; - } - else if (__instance.cancelButton.containsPoint(x, y)) - { - toSpeak += "\n\tCancel Button"; - } - - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void LevelUpMenuPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title, bool ___isActive, bool ___isProfessionChooser) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - string leftProfession = " ", rightProfession = " ", extraInfo = " ", newCraftingRecipe = " ", toSpeak = " "; - - if (!__instance.informationUp) - { - return; - } - if (__instance.isProfessionChooser) - { - if (___professionsToChoose.Count() == 0) - { - return; - } - for (int j = 0; j < ___leftProfessionDescription.Count; j++) - { - leftProfession += ___leftProfessionDescription[j] + ", "; - } - for (int i = 0; i < ___rightProfessionDescription.Count; i++) - { - rightProfession += ___rightProfessionDescription[i] + ", "; - } - - if (__instance.leftProfession.containsPoint(x, y)) - { - if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) - { - Game1.player.professions.Add(___professionsToChoose[0]); - __instance.getImmediateProfessionPerk(___professionsToChoose[0]); - ___isActive = false; - __instance.informationUp = false; - ___isProfessionChooser = false; - __instance.RemoveLevelFromLevelList(); - __instance.exitThisMenu(); - return; - } - - toSpeak = $"Selected: {leftProfession} Left click to choose."; - } - - if (__instance.rightProfession.containsPoint(x, y)) - { - if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) - { - Game1.player.professions.Add(___professionsToChoose[1]); - __instance.getImmediateProfessionPerk(___professionsToChoose[1]); - ___isActive = false; - __instance.informationUp = false; - ___isProfessionChooser = false; - __instance.RemoveLevelFromLevelList(); - __instance.exitThisMenu(); - return; - } - - toSpeak = $"Selected: {rightProfession} Left click to choose."; - } - } - else - { - foreach (string s2 in ___extraInfoForLevel) - { - extraInfo += s2 + ", "; - } - foreach (CraftingRecipe s in ___newCraftingRecipes) - { - string cookingOrCrafting = Game1.content.LoadString("Strings\\UI:LearnedRecipe_" + (s.isCookingRecipe ? "cooking" : "crafting")); - string message = Game1.content.LoadString("Strings\\UI:LevelUp_NewRecipe", cookingOrCrafting, s.DisplayName); - - newCraftingRecipe += $"{message}, "; - } - } - - if (__instance.okButton.containsPoint(x, y)) - { - if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) - __instance.okButtonClicked(); - - toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close."; - } - - if (toSpeak != " ") - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") - { - MainClass.ScreenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true); - currentLevelUpTitle = $"{___title}. Select a new profession."; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void ShippingMenuPatch(ShippingMenu __instance, List ___categoryTotals) - { - try - { - - if (__instance.currentPage == -1) - { - int total = ___categoryTotals[5]; - string toSpeak; - if (__instance.okButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - // Perform Left Click - if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) - { - Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); - } - toSpeak = $"{total}g in total. Press left mouse button to save."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - for (int i = 0; i < __instance.categories.Count; i++) - { - if (__instance.categories[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - } -} diff --git a/stardew-access/Patches/NamingMenuPatch.cs b/stardew-access/Patches/NamingMenuPatch.cs new file mode 100644 index 0000000..06e8f0e --- /dev/null +++ b/stardew-access/Patches/NamingMenuPatch.cs @@ -0,0 +1,42 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class NamingMenuPatch + { + internal static bool firstTimeInNamingMenu = true; + + internal static void DrawPatch(NamingMenu __instance, TextBox ___textBox, string ___title) + { + try + { + if (firstTimeInNamingMenu) + { + firstTimeInNamingMenu = false; + ___textBox.Selected = false; + } + + if (TextBoxPatch.isAnyTextBoxActive) return; + + string toSpeak = ""; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box + + if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = $"{___title} text box"; + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + toSpeak = $"Done naming button"; + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + toSpeak = $"Random button"; + + if (toSpeak != "") + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/ShippingMenuPatch.cs b/stardew-access/Patches/ShippingMenuPatch.cs new file mode 100644 index 0000000..692d9ee --- /dev/null +++ b/stardew-access/Patches/ShippingMenuPatch.cs @@ -0,0 +1,46 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ShippingMenuPatch + { + internal static int prevSlotIndex = -999; + + internal static void DrawPatch(ShippingMenu __instance, List ___categoryTotals) + { + try + { + + if (__instance.currentPage == -1) + { + int total = ___categoryTotals[5]; + string toSpeak; + if (__instance.okButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + // Perform Left Click + if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) + { + Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); + } + toSpeak = $"{total}g in total. Press left mouse button to save."; + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + + for (int i = 0; i < __instance.categories.Count; i++) + { + if (__instance.categories[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/TitleTextInputMenuPatch.cs b/stardew-access/Patches/TitleTextInputMenuPatch.cs new file mode 100644 index 0000000..2ed19ac --- /dev/null +++ b/stardew-access/Patches/TitleTextInputMenuPatch.cs @@ -0,0 +1,27 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TitleTextInputMenuPatch + { + internal static void DrawPatch(TitleTextInputMenu __instance) + { + try + { + string toSpeak = ""; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (__instance.pasteButton != null && __instance.pasteButton.containsPoint(x, y)) + toSpeak = $"Paste button"; + + if (toSpeak != "") + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +}