From 5cf6327552bc4a664280b19f76bd4df79c011e60 Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Thu, 30 Dec 2021 19:09:05 +0530 Subject: [PATCH] Level up menu is accessible --- stardew-access/ModEntry.cs | 5 ++ stardew-access/Patches/DialoguePatcher.cs | 1 - stardew-access/Patches/MenuPatch.cs | 68 +++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 4ae7097..11c2c08 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -127,6 +127,11 @@ namespace stardew_access postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.ChatBoxPatch)) ); + harmony.Patch( + original: AccessTools.Method(typeof(LevelUpMenu), nameof(LevelUpMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.LevelUpMenuPatch)) + ); + #endregion #region Custom Commands diff --git a/stardew-access/Patches/DialoguePatcher.cs b/stardew-access/Patches/DialoguePatcher.cs index 6733fae..ffdd83e 100644 --- a/stardew-access/Patches/DialoguePatcher.cs +++ b/stardew-access/Patches/DialoguePatcher.cs @@ -199,7 +199,6 @@ namespace stardew_access.Patches #endregion #region Narrate toSpeak - // To prevent it from getting conflicted by two hover texts at the same time, two seperate methods are used. // For example, sometimes `Welcome to Pierre's` and the items in seeds shop get conflicted causing it to speak infinitely. if(Context.IsPlayerFree) diff --git a/stardew-access/Patches/MenuPatch.cs b/stardew-access/Patches/MenuPatch.cs index 0b3426c..1539efe 100644 --- a/stardew-access/Patches/MenuPatch.cs +++ b/stardew-access/Patches/MenuPatch.cs @@ -14,6 +14,7 @@ namespace stardew_access.Patches private static bool isRunning = false, isChatRunning = false; private static string currentLetterText = " "; private static string currentDailyQuestText = " "; + private static string currentLevelUpTitle = " "; internal static void ChatBoxPatch(ChatBox __instance, List ___messages) { @@ -179,6 +180,72 @@ namespace stardew_access.Patches } } + internal static void LevelUpMenuPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title) + { + try + { + int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; + 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)) + toSpeak = $"Selected: {leftProfession} Left click to choose."; + + if (__instance.rightProfession.containsPoint(x, y)) + 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)) + { + toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close."; + } + } + + if (toSpeak != " ") + ScreenReader.sayWithMenuChecker(toSpeak, true); + else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") + { + ScreenReader.sayWithMenuChecker($"{___title}. Select a new profession.", true); + currentLevelUpTitle = $"{___title}. Select a new profession."; + } + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + internal static void ShippingMenuPatch(ShippingMenu __instance, List ___categoryTotals) { try @@ -640,6 +707,7 @@ namespace stardew_access.Patches { currentLetterText = " "; currentDailyQuestText = " "; + currentLevelUpTitle = " "; } } }