stardew-access/stardew-access/Patches/GameMenuPatches.cs

83 lines
3.0 KiB
C#

using StardewValley;
using StardewValley.Menus;
using StardewValley.Objects;
namespace stardew_access.Patches
{
// Menus in the game menu i.e., the menu which opens when we press `e`
internal class GameMenuPatches
{
internal static string hoveredItemQueryKey = "";
internal static string gameMenuQueryKey = "";
internal static string exitPageQueryKey = "";
internal static string profilePageQuery = "";
internal static void GameMenuPatch(GameMenu __instance)
{
try
{
// Continue if only in the Inventory Page or Crafting Page
if (__instance.currentTab != 0 && __instance.currentTab != 4 && __instance.currentTab != 6 && __instance.currentTab != 7)
return;
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
for (int i = 0; i < __instance.tabs.Count; i++)
{
if (__instance.tabs[i].containsPoint(x, y))
{
string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab";
if (gameMenuQueryKey != toSpeak)
{
MainClass.DebugLog("here");
gameMenuQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
}
return;
}
}
}
catch (Exception e)
{
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
}
internal static void ExitPagePatch(ExitPage __instance)
{
try
{
if (__instance.exitToTitle.visible &&
__instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
{
string toSpeak = "Exit to Title Button";
if (exitPageQueryKey != toSpeak)
{
gameMenuQueryKey = "";
exitPageQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
}
return;
}
if (__instance.exitToDesktop.visible &&
__instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
{
string toSpeak = "Exit to Desktop Button";
if (exitPageQueryKey != toSpeak)
{
gameMenuQueryKey = "";
exitPageQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
}
return;
}
}
catch (Exception e)
{
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
}
}
}