Separated chat menu patch
parent
4c67d43bad
commit
8866e4f950
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue