From f0f299b384e2f02fdb8f10c85f84f53a00a13702 Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Tue, 4 Jan 2022 19:32:44 +0530 Subject: [PATCH] Code Organization --- stardew-access/ModEntry.cs | 154 ++++++----- ...{DialoguePatcher.cs => DialoguePatches.cs} | 2 +- .../Patches/{MenuPatch.cs => MenuPatches.cs} | 228 +--------------- stardew-access/Patches/QuestPatches.cs | 249 ++++++++++++++++++ 4 files changed, 335 insertions(+), 298 deletions(-) rename stardew-access/Patches/{DialoguePatcher.cs => DialoguePatches.cs} (99%) rename stardew-access/Patches/{MenuPatch.cs => MenuPatches.cs} (53%) create mode 100644 stardew-access/Patches/QuestPatches.cs diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index c8e5358..41de1bc 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -57,111 +57,123 @@ namespace stardew_access #region Harmony Patches + #region Dialogue Patches harmony.Patch( - original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DialoguePatcher), nameof(DialoguePatcher.DialoguePatch)) - ); + original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.DialoguePatch)) + ); harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)), - postfix: new HarmonyMethod(typeof(DialoguePatcher), nameof(DialoguePatcher.ClearDialogueString)) + postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.ClearDialogueString)) ); harmony.Patch( original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.drawHoverText), new Type[] { typeof(SpriteBatch), typeof(string), typeof(SpriteFont), typeof(int), typeof(int), typeof(int), typeof(string), typeof(int), typeof(string[]), typeof(Item), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(float), typeof(CraftingRecipe), typeof(IList) }), - postfix: new HarmonyMethod(typeof(DialoguePatcher), nameof(DialoguePatcher.HoverTextPatch)) - ); + postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.HoverTextPatch)) + ); + #endregion + #region Title Menu Patches harmony.Patch( - original: AccessTools.Method(typeof(TitleMenu), nameof(TitleMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.TitleMenuPatch)) - ); + original: AccessTools.Method(typeof(TitleMenu), nameof(TitleMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.TitleMenuPatch)) + ); harmony.Patch( original: AccessTools.Method(typeof(LoadGameMenu.SaveFileSlot), nameof(LoadGameMenu.SaveFileSlot.Draw), new Type[] { typeof(SpriteBatch), typeof(int) }), postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.LoadGameMenuPatch)) ); - harmony.Patch( - original: AccessTools.Method(typeof(ExitPage), nameof(ExitPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ExitPagePatch)) - ); - harmony.Patch( original: AccessTools.Method(typeof(CharacterCustomization), nameof(CharacterCustomization.draw), new Type[] { typeof(SpriteBatch) }), postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.NewGameMenuPatch)) ); - harmony.Patch( - original: AccessTools.Method(typeof(LetterViewerMenu), nameof(LetterViewerMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.LetterViewerMenuPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(QuestLog), nameof(QuestLog.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.QuestLogPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(Billboard), nameof(Billboard.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.BillboardPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(ShippingMenu), nameof(ShippingMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.ShippingMenuPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(OptionsPage), nameof(OptionsPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.OptionsPagePatch)) - ); - harmony.Patch( original: AccessTools.Method(typeof(CoopMenu), nameof(CoopMenu.update), new Type[] { typeof(GameTime) }), postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.CoopMenuPatch)) - ); + ); + #endregion + + #region Game Menu Patches + harmony.Patch( + original: AccessTools.Method(typeof(OptionsPage), nameof(OptionsPage.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.OptionsPagePatch)) + ); harmony.Patch( - original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(ChatManuPatches), nameof(ChatManuPatches.ChatBoxPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(LevelUpMenu), nameof(LevelUpMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.LevelUpMenuPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(ConfirmationDialog), nameof(ConfirmationDialog.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.ConfirmationDialogPatch)) - ); - - harmony.Patch( - original: AccessTools.Constructor(typeof(NamingMenu), new Type[] { typeof(NamingMenu.doneNamingBehavior), typeof(string), typeof(string) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.NamingMenuPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(MineElevatorMenu), nameof(MineElevatorMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.MineElevatorMenuPatch)) - ); - - harmony.Patch( - original: AccessTools.Method(typeof(LanguageSelectionMenu), nameof(LanguageSelectionMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.LanguageSelectionMenuPatch)) + original: AccessTools.Method(typeof(ExitPage), nameof(ExitPage.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ExitPagePatch)) ); harmony.Patch( original: AccessTools.Method(typeof(CraftingPage), nameof(CraftingPage.draw), new Type[] { typeof(SpriteBatch) }), postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.CraftingPagePatch)) + ); + #endregion + + #region Menu Patches + harmony.Patch( + original: AccessTools.Method(typeof(LetterViewerMenu), nameof(LetterViewerMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LetterViewerMenuPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(ShippingMenu), nameof(ShippingMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ShippingMenuPatch)) ); harmony.Patch( - original: AccessTools.Method(typeof(SpecialOrdersBoard), nameof(SpecialOrdersBoard.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.SpecialOrdersBoardPatch)) + original: AccessTools.Method(typeof(LevelUpMenu), nameof(LevelUpMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LevelUpMenuPatch)) ); + harmony.Patch( + original: AccessTools.Method(typeof(ConfirmationDialog), nameof(ConfirmationDialog.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ConfirmationDialogPatch)) + ); + + harmony.Patch( + original: AccessTools.Constructor(typeof(NamingMenu), new Type[] { typeof(NamingMenu.doneNamingBehavior), typeof(string), typeof(string) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.NamingMenuPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(MineElevatorMenu), nameof(MineElevatorMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.MineElevatorMenuPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(LanguageSelectionMenu), nameof(LanguageSelectionMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LanguageSelectionMenuPatch)) + ); + #endregion + + #region Quest Patches + harmony.Patch( + original: AccessTools.Method(typeof(SpecialOrdersBoard), nameof(SpecialOrdersBoard.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.SpecialOrdersBoardPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(QuestLog), nameof(QuestLog.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.QuestLogPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(Billboard), nameof(Billboard.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.BillboardPatch)) + ); + #endregion + + #region Chat Menu Patches + harmony.Patch( + original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), + postfix: new HarmonyMethod(typeof(ChatManuPatches), nameof(ChatManuPatches.ChatBoxPatch)) + ); + #endregion + #endregion #region Custom Commands @@ -196,7 +208,9 @@ namespace stardew_access if (!Context.IsPlayerFree) return; - MenuPatch.resetGlobalVars(); + // Reset variables + MenuPatches.resetGlobalVars(); + QuestPatches.resetGlobalVars(); SlotAndLocation.narrateCurrentSlot(); diff --git a/stardew-access/Patches/DialoguePatcher.cs b/stardew-access/Patches/DialoguePatches.cs similarity index 99% rename from stardew-access/Patches/DialoguePatcher.cs rename to stardew-access/Patches/DialoguePatches.cs index 5826900..254353c 100644 --- a/stardew-access/Patches/DialoguePatcher.cs +++ b/stardew-access/Patches/DialoguePatches.cs @@ -6,7 +6,7 @@ using System.Text; namespace stardew_access.Patches { - internal class DialoguePatcher + internal class DialoguePatches { private static string currentDialogue = " "; diff --git a/stardew-access/Patches/MenuPatch.cs b/stardew-access/Patches/MenuPatches.cs similarity index 53% rename from stardew-access/Patches/MenuPatch.cs rename to stardew-access/Patches/MenuPatches.cs index 80f917f..9376e96 100644 --- a/stardew-access/Patches/MenuPatch.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -6,73 +6,11 @@ using StardewValley.Quests; namespace stardew_access.Patches { - internal class MenuPatch + internal class MenuPatches { private static string currentLetterText = " "; - private static string currentDailyQuestText = " "; private static string currentLevelUpTitle = " "; - internal static void SpecialOrdersBoardPatch(SpecialOrdersBoard __instance) - { - try - { - int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position - - if (__instance.acceptLeftQuestButton.visible && __instance.acceptLeftQuestButton.containsPoint(x, y)) - { - string toSpeak = getSpecialOrderDetails(__instance.leftOrder); - - toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - - ScreenReader.sayWithMenuChecker(toSpeak, true); - return; - } - - if (__instance.acceptRightQuestButton.visible && __instance.acceptRightQuestButton.containsPoint(x, y)) - { - string toSpeak = getSpecialOrderDetails(__instance.rightOrder); - - toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - - ScreenReader.sayWithMenuChecker(toSpeak, true); - return; - } - } - catch (Exception e) - { - MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); - } - } - - private static string getSpecialOrderDetails(SpecialOrder order) - { - int daysLeft = order.GetDaysLeft(); - string description = order.GetDescription(); - string objectiveDescription = ""; - string name = order.GetName(); - int moneyReward = order.GetMoneyReward(); - - // Get each objectives - for (int i = 0; i < order.GetObjectiveDescriptions().Count; i++) - { - objectiveDescription += order.GetObjectiveDescriptions()[i] + ", \n"; - } - - string toReturn = $"{name}\n\tDescription:{description}\n\tObjectives: {objectiveDescription}"; - - if (order.IsTimedQuest()) - { - toReturn = $"{toReturn}\n\tTime: {daysLeft} days"; - } - - if (order.HasMoneyReward()) - { - toReturn = $"{toReturn}\n\tReward: {moneyReward}g"; - } - - return toReturn; - } - internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) { try @@ -258,169 +196,6 @@ namespace stardew_access.Patches } } - internal static void BillboardPatch(Billboard __instance, bool ___dailyQuestBoard) - { - try - { - if (!___dailyQuestBoard) - { - #region Callender - for (int i = 0; i < __instance.calendarDays.Count; i++) - { - if (__instance.calendarDays[i].containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) - { - string toSpeak = $"Day {i + 1}"; - - if (__instance.calendarDays[i].name.Length > 0) - { - toSpeak += $", {__instance.calendarDays[i].name}"; - } - if (__instance.calendarDays[i].hoverText.Length > 0) - { - toSpeak += $", {__instance.calendarDays[i].hoverText}"; - } - - if (Game1.dayOfMonth == i + 1) - toSpeak += $", Current"; - - ScreenReader.sayWithChecker(toSpeak, true); - } - } - #endregion - } - else - { - #region Daily Quest Board - if (Game1.questOfTheDay == null || Game1.questOfTheDay.currentObjective == null || Game1.questOfTheDay.currentObjective.Length == 0) - { - // No quests - string toSpeak = "No quests for today!"; - if (currentDailyQuestText != toSpeak) - { - currentDailyQuestText = toSpeak; - ScreenReader.say(toSpeak, true); - } - } - else - { - SpriteFont font = ((LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko) ? Game1.smallFont : Game1.dialogueFont); - string description = Game1.parseText(Game1.questOfTheDay.questDescription, font, 640); - string toSpeak = description; - - if (currentDailyQuestText != toSpeak) - { - currentDailyQuestText = toSpeak; - - // Snap to accept quest button - if (__instance.acceptQuestButton.visible) - { - toSpeak += "\t\n Left click to accept quest."; - __instance.acceptQuestButton.snapMouseCursorToCenter(); - } - - ScreenReader.say(toSpeak, true); - } - } - #endregion - } - } - catch (Exception e) - { - MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); - } - } - - internal static void QuestLogPatch(QuestLog __instance, int ___questPage, List> ___pages, int ___currentPage, IQuest ____shownQuest, List ____objectiveText) - { - try - { - bool snapMouseToRewardBox = false; - - if (___questPage == -1) - { - #region Quest Lists - for (int i = 0; i < __instance.questLogButtons.Count; i++) - { - if (___pages.Count() > 0 && ___pages[___currentPage].Count() > i) - { - string name = ___pages[___currentPage][i].GetName(); - int daysLeft = ___pages[___currentPage][i].GetDaysLeft(); - string toSpeak = $"{name} quest"; - - if (daysLeft > 0 && ___pages[___currentPage][i].ShouldDisplayAsComplete()) - toSpeak += $"\t\n {daysLeft} days left"; - - toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; - if (__instance.questLogButtons[i].containsPoint(Game1.getOldMouseX(), Game1.getOldMouseY())) - { - ScreenReader.sayWithChecker(toSpeak, true); - } - } - } - #endregion - } - else - { - #region Individual quest - string description = Game1.parseText(____shownQuest.GetDescription(), Game1.dialogueFont, __instance.width - 128); - string title = ____shownQuest.GetName(); - string toSpeak = " "; - if (____shownQuest.ShouldDisplayAsComplete()) - { - #region Quest completed menu - - toSpeak = $"Quest: {title} Completed!"; - - if (__instance.HasReward()) - { - snapMouseToRewardBox = true; - if (__instance.HasMoneyReward()) - { - toSpeak += $"you recieved {____shownQuest.GetMoneyReward()}g"; - } - - toSpeak += "... left click to collect reward"; - } - - #endregion - } - else - { - #region Quest in-complete menu - toSpeak = $"Title: {title}. \t\n Description: {description}"; - - for (int j = 0; j < ____objectiveText.Count; j++) - { - if (____shownQuest != null) - { - _ = ____shownQuest is SpecialOrder; - } - string parsed_text = Game1.parseText(____objectiveText[j], width: __instance.width - 192, whichFont: Game1.dialogueFont); - - toSpeak += $"\t\nOrder {j + 1}: {parsed_text} \t\n"; - } - - int daysLeft = ____shownQuest.GetDaysLeft(); - - if (daysLeft > 0) - toSpeak += $"\t\n{daysLeft} days left."; - #endregion - } - - // Move mouse to reward button - if (snapMouseToRewardBox) - __instance.rewardBox.snapMouseCursorToCenter(); - - ScreenReader.sayWithChecker(toSpeak, true); - #endregion - } - } - catch (Exception e) - { - MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); - } - } - internal static void LetterViewerMenuPatch(LetterViewerMenu __instance) { try @@ -486,7 +261,6 @@ namespace stardew_access.Patches internal static void resetGlobalVars() { currentLetterText = " "; - currentDailyQuestText = " "; currentLevelUpTitle = " "; } } diff --git a/stardew-access/Patches/QuestPatches.cs b/stardew-access/Patches/QuestPatches.cs new file mode 100644 index 0000000..16b8ae3 --- /dev/null +++ b/stardew-access/Patches/QuestPatches.cs @@ -0,0 +1,249 @@ +using Microsoft.Xna.Framework.Graphics; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Menus; +using StardewValley.Quests; + +namespace stardew_access.Patches +{ + internal class QuestPatches + { + private static string currentDailyQuestText = " "; + + #region For Special Orders Board + internal static void SpecialOrdersBoardPatch(SpecialOrdersBoard __instance) + { + try + { + int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position + + if (__instance.acceptLeftQuestButton.visible && __instance.acceptLeftQuestButton.containsPoint(x, y)) + { + string toSpeak = getSpecialOrderDetails(__instance.leftOrder); + + toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; + + ScreenReader.sayWithMenuChecker(toSpeak, true); + return; + } + + if (__instance.acceptRightQuestButton.visible && __instance.acceptRightQuestButton.containsPoint(x, y)) + { + string toSpeak = getSpecialOrderDetails(__instance.rightOrder); + + toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; + + ScreenReader.sayWithMenuChecker(toSpeak, true); + return; + } + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + + private static string getSpecialOrderDetails(SpecialOrder order) + { + int daysLeft = order.GetDaysLeft(); + string description = order.GetDescription(); + string objectiveDescription = ""; + string name = order.GetName(); + int moneyReward = order.GetMoneyReward(); + + // Get each objectives + for (int i = 0; i < order.GetObjectiveDescriptions().Count; i++) + { + objectiveDescription += order.GetObjectiveDescriptions()[i] + ", \n"; + } + + string toReturn = $"{name}\n\tDescription:{description}\n\tObjectives: {objectiveDescription}"; + + if (order.IsTimedQuest()) + { + toReturn = $"{toReturn}\n\tTime: {daysLeft} days"; + } + + if (order.HasMoneyReward()) + { + toReturn = $"{toReturn}\n\tReward: {moneyReward}g"; + } + + return toReturn; + } + #endregion + + #region For Normal Billboard in the town + internal static void BillboardPatch(Billboard __instance, bool ___dailyQuestBoard) + { + try + { + if (!___dailyQuestBoard) + { + #region Callender + for (int i = 0; i < __instance.calendarDays.Count; i++) + { + if (__instance.calendarDays[i].containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) + { + string toSpeak = $"Day {i + 1}"; + + if (__instance.calendarDays[i].name.Length > 0) + { + toSpeak += $", {__instance.calendarDays[i].name}"; + } + if (__instance.calendarDays[i].hoverText.Length > 0) + { + toSpeak += $", {__instance.calendarDays[i].hoverText}"; + } + + if (Game1.dayOfMonth == i + 1) + toSpeak += $", Current"; + + ScreenReader.sayWithChecker(toSpeak, true); + } + } + #endregion + } + else + { + #region Daily Quest Board + if (Game1.questOfTheDay == null || Game1.questOfTheDay.currentObjective == null || Game1.questOfTheDay.currentObjective.Length == 0) + { + // No quests + string toSpeak = "No quests for today!"; + if (currentDailyQuestText != toSpeak) + { + currentDailyQuestText = toSpeak; + ScreenReader.say(toSpeak, true); + } + } + else + { + SpriteFont font = ((LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko) ? Game1.smallFont : Game1.dialogueFont); + string description = Game1.parseText(Game1.questOfTheDay.questDescription, font, 640); + string toSpeak = description; + + if (currentDailyQuestText != toSpeak) + { + currentDailyQuestText = toSpeak; + + // Snap to accept quest button + if (__instance.acceptQuestButton.visible) + { + toSpeak += "\t\n Left click to accept quest."; + __instance.acceptQuestButton.snapMouseCursorToCenter(); + } + + ScreenReader.say(toSpeak, true); + } + } + #endregion + } + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + #endregion + + #region Journal Menu + internal static void QuestLogPatch(QuestLog __instance, int ___questPage, List> ___pages, int ___currentPage, IQuest ____shownQuest, List ____objectiveText) + { + try + { + bool snapMouseToRewardBox = false; + + if (___questPage == -1) + { + #region Quest Lists + for (int i = 0; i < __instance.questLogButtons.Count; i++) + { + if (___pages.Count() > 0 && ___pages[___currentPage].Count() > i) + { + string name = ___pages[___currentPage][i].GetName(); + int daysLeft = ___pages[___currentPage][i].GetDaysLeft(); + string toSpeak = $"{name} quest"; + + if (daysLeft > 0 && ___pages[___currentPage][i].ShouldDisplayAsComplete()) + toSpeak += $"\t\n {daysLeft} days left"; + + toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; + if (__instance.questLogButtons[i].containsPoint(Game1.getOldMouseX(), Game1.getOldMouseY())) + { + ScreenReader.sayWithChecker(toSpeak, true); + } + } + } + #endregion + } + else + { + #region Individual quest + string description = Game1.parseText(____shownQuest.GetDescription(), Game1.dialogueFont, __instance.width - 128); + string title = ____shownQuest.GetName(); + string toSpeak = " "; + if (____shownQuest.ShouldDisplayAsComplete()) + { + #region Quest completed menu + + toSpeak = $"Quest: {title} Completed!"; + + if (__instance.HasReward()) + { + snapMouseToRewardBox = true; + if (__instance.HasMoneyReward()) + { + toSpeak += $"you recieved {____shownQuest.GetMoneyReward()}g"; + } + + toSpeak += "... left click to collect reward"; + } + + #endregion + } + else + { + #region Quest in-complete menu + toSpeak = $"Title: {title}. \t\n Description: {description}"; + + for (int j = 0; j < ____objectiveText.Count; j++) + { + if (____shownQuest != null) + { + _ = ____shownQuest is SpecialOrder; + } + string parsed_text = Game1.parseText(____objectiveText[j], width: __instance.width - 192, whichFont: Game1.dialogueFont); + + toSpeak += $"\t\nOrder {j + 1}: {parsed_text} \t\n"; + } + + int daysLeft = ____shownQuest.GetDaysLeft(); + + if (daysLeft > 0) + toSpeak += $"\t\n{daysLeft} days left."; + #endregion + } + + // Move mouse to reward button + if (snapMouseToRewardBox) + __instance.rewardBox.snapMouseCursorToCenter(); + + ScreenReader.sayWithChecker(toSpeak, true); + #endregion + } + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + #endregion + + + internal static void resetGlobalVars() + { + currentDailyQuestText = " "; + } + } +}