From aa0f36cad1c860ba4c21371f050964d0f46fe707 Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Wed, 29 Dec 2021 19:43:32 +0530 Subject: [PATCH] Added page up/down to cycle through chats --- stardew-access/Patches/MenuPatch.cs | 71 +++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/stardew-access/Patches/MenuPatch.cs b/stardew-access/Patches/MenuPatch.cs index 1b9d19d..0b3426c 100644 --- a/stardew-access/Patches/MenuPatch.cs +++ b/stardew-access/Patches/MenuPatch.cs @@ -10,8 +10,8 @@ namespace stardew_access.Patches { internal class MenuPatch { - private static int saveGameIndex = -1; - private static bool isRunning = false; + private static int saveGameIndex = -1, currentChatMessageIndex = 0; + private static bool isRunning = false, isChatRunning = false; private static string currentLetterText = " "; private static string currentDailyQuestText = " "; @@ -19,15 +19,38 @@ namespace stardew_access.Patches { try { - if (___messages.Count - 1 < 0) - return; + string toSpeak = " "; - string toSpeak = ""; - ___messages[___messages.Count - 1].message.ForEach(message => + if (__instance.chatBox.Selected) { - toSpeak += $"{message.message}, "; - }); - ScreenReader.sayWithChatChecker(toSpeak, false); + bool isPrevArrowPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.PageUp); + bool isNextArrowPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.PageDown); + + if (___messages.Count > 0) + { + #region To narrate previous and next chat messages + if (isNextArrowPressed && !isChatRunning) + { + _ = CycleThroughChatMessages(true, ___messages); + } + else if (isPrevArrowPressed && !isChatRunning) + { + _ = CycleThroughChatMessages(false, ___messages); + } + #endregion + } + } + else if (___messages.Count > 0) + { + #region To narrate latest chat message + ___messages[___messages.Count - 1].message.ForEach(message => + { + toSpeak += $"{message.message}, "; + }); + if (toSpeak != " ") + ScreenReader.sayWithChatChecker(toSpeak, false); + #endregion + } } catch (Exception e) { @@ -35,6 +58,36 @@ namespace stardew_access.Patches } } + private static async Task CycleThroughChatMessages(bool increase, List ___messages) + { + isChatRunning = true; + await Task.Delay(200); + string toSpeak = " "; + if (increase) + { + ++currentChatMessageIndex; + if (currentChatMessageIndex > ___messages.Count - 1) + { + currentChatMessageIndex = ___messages.Count - 1; + } + } + else + { + --currentChatMessageIndex; + if (currentChatMessageIndex < 0) + { + currentChatMessageIndex = 0; + } + } + ___messages[currentChatMessageIndex].message.ForEach(message => + { + toSpeak += $"{message.message}, "; + }); + + ScreenReader.say(toSpeak, true); + isChatRunning = false; + } + internal static void CoopMenuPatch(CoopMenu __instance, CoopMenu.Tab ___currentTab) {