From 8866e4f9504586ff7e0a1a1caa4b950f2aca093c Mon Sep 17 00:00:00 2001
From: shoaib11120 <shoaib.khan20@outlook.com>
Date: Mon, 3 Jan 2022 19:25:10 +0530
Subject: [PATCH] Separated chat menu patch

---
 stardew-access/ModEntry.cs                |  2 +-
 stardew-access/Patches/ChatManuPatches.cs | 85 +++++++++++++++++++++++
 stardew-access/Patches/MenuPatch.cs       | 75 +-------------------
 3 files changed, 87 insertions(+), 75 deletions(-)
 create mode 100644 stardew-access/Patches/ChatManuPatches.cs

diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs
index 5384e25..49baf31 100644
--- a/stardew-access/ModEntry.cs
+++ b/stardew-access/ModEntry.cs
@@ -124,7 +124,7 @@ namespace stardew_access
 
             harmony.Patch(
                 original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }),
-                postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.ChatBoxPatch))
+                postfix: new HarmonyMethod(typeof(MenuPatch), nameof(ChatManuPatches.ChatBoxPatch))
             );
 
             harmony.Patch(
diff --git a/stardew-access/Patches/ChatManuPatches.cs b/stardew-access/Patches/ChatManuPatches.cs
new file mode 100644
index 0000000..764709c
--- /dev/null
+++ b/stardew-access/Patches/ChatManuPatches.cs
@@ -0,0 +1,85 @@
+using StardewModdingAPI;
+using StardewValley;
+using StardewValley.Menus;
+
+namespace stardew_access.Patches
+{
+    internal class ChatManuPatches
+    {
+        private static int currentChatMessageIndex = 0;
+        private static bool isChatRunning = false;
+
+        internal static void ChatBoxPatch(ChatBox __instance, List<ChatMessage> ___messages)
+        {
+            try
+            {
+                string toSpeak = " ";
+
+                if (__instance.chatBox.Selected)
+                {
+                    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)
+            {
+                MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
+            }
+        }
+
+        private static async Task CycleThroughChatMessages(bool increase, List<ChatMessage> ___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;
+        }
+    }
+}
diff --git a/stardew-access/Patches/MenuPatch.cs b/stardew-access/Patches/MenuPatch.cs
index 767227c..70fe20d 100644
--- a/stardew-access/Patches/MenuPatch.cs
+++ b/stardew-access/Patches/MenuPatch.cs
@@ -10,8 +10,6 @@ namespace stardew_access.Patches
 {
     internal class MenuPatch
     {
-        private static int currentChatMessageIndex = 0;
-        private static bool isChatRunning = false;
         private static string currentLetterText = " ";
         private static string currentDailyQuestText = " ";
         private static string currentLevelUpTitle = " ";
@@ -53,78 +51,7 @@ namespace stardew_access.Patches
             }
         }
 
-        internal static void ChatBoxPatch(ChatBox __instance, List<ChatMessage> ___messages)
-        {
-            try
-            {
-                string toSpeak = " ";
-
-                if (__instance.chatBox.Selected)
-                {
-                    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)
-            {
-                MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
-            }
-        }
-
-        private static async Task CycleThroughChatMessages(bool increase, List<ChatMessage> ___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 OptionsPagePatch(OptionsPage __instance)
         {