diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 4100597..4ae7097 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -122,6 +122,10 @@ namespace stardew_access postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.CoopMenuPatch)) ); + harmony.Patch( + original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), + postfix: new HarmonyMethod(typeof(MenuPatch), nameof(MenuPatch.ChatBoxPatch)) + ); #endregion diff --git a/stardew-access/Patches/MenuPatch.cs b/stardew-access/Patches/MenuPatch.cs index b44f6d4..1b9d19d 100644 --- a/stardew-access/Patches/MenuPatch.cs +++ b/stardew-access/Patches/MenuPatch.cs @@ -15,6 +15,26 @@ namespace stardew_access.Patches private static string currentLetterText = " "; private static string currentDailyQuestText = " "; + internal static void ChatBoxPatch(ChatBox __instance, List ___messages) + { + try + { + if (___messages.Count - 1 < 0) + return; + + string toSpeak = ""; + ___messages[___messages.Count - 1].message.ForEach(message => + { + toSpeak += $"{message.message}, "; + }); + ScreenReader.sayWithChatChecker(toSpeak, false); + } + catch (Exception e) + { + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); + } + } + internal static void CoopMenuPatch(CoopMenu __instance, CoopMenu.Tab ___currentTab) { diff --git a/stardew-access/ScreenReader.cs b/stardew-access/ScreenReader.cs index 158779e..557742d 100644 --- a/stardew-access/ScreenReader.cs +++ b/stardew-access/ScreenReader.cs @@ -6,7 +6,7 @@ namespace stardew_access internal class ScreenReader { public static IAccessibleOutput? screenReader = null; - internal static string prevText = "", prevTextTile = " "; + internal static string prevText = "", prevTextTile = " ", prevChatText = ""; public static void initializeScreenReader() { @@ -65,6 +65,18 @@ namespace stardew_access } } + public static void sayWithChatChecker(string text, bool interrupt) + { + if (screenReader == null) + return; + + if (prevChatText != text) + { + prevChatText = text; + screenReader.Speak(text, interrupt); + } + } + public static void sayWithTileQuery(string text, int x, int y, bool interrupt) { if (screenReader == null)