Added page up/down to cycle through chats

master
shoaib11120 2021-12-29 19:43:32 +05:30
parent b9c29f1fed
commit aa0f36cad1
1 changed files with 62 additions and 9 deletions

View File

@ -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 = " ";
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)
{
@ -35,6 +58,36 @@ namespace stardew_access.Patches
}
}
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 CoopMenuPatch(CoopMenu __instance, CoopMenu.Tab ___currentTab)
{