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

83 lines
3.0 KiB
C#
Raw Normal View History

2022-03-29 14:27:38 +00:00
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
{
2022-01-06 16:29:27 +00:00
internal static string hoveredItemQueryKey = "";
2022-01-07 09:27:57 +00:00
internal static string gameMenuQueryKey = "";
internal static string exitPageQueryKey = "";
internal static string profilePageQuery = "";
2022-01-07 09:27:57 +00:00
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;
2022-03-21 06:42:50 +00:00
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
2022-01-07 09:27:57 +00:00
2022-02-01 07:20:40 +00:00
for (int i = 0; i < __instance.tabs.Count; i++)
2022-01-07 09:27:57 +00:00
{
2022-02-01 07:20:40 +00:00
if (__instance.tabs[i].containsPoint(x, y))
2022-01-07 09:27:57 +00:00
{
string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab";
if (gameMenuQueryKey != toSpeak)
{
2023-02-24 08:40:28 +00:00
MainClass.DebugLog("here");
2022-01-07 09:27:57 +00:00
gameMenuQueryKey = toSpeak;
2022-04-09 10:18:13 +00:00
MainClass.ScreenReader.Say(toSpeak, true);
2022-01-07 09:27:57 +00:00
}
return;
}
}
}
catch (Exception e)
{
2022-03-19 07:24:53 +00:00
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
2022-01-07 09:27:57 +00:00
}
}
2022-01-06 13:22:23 +00:00
internal static void ExitPagePatch(ExitPage __instance)
{
try
{
if (__instance.exitToTitle.visible &&
2022-03-21 06:42:50 +00:00
__instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
{
2022-01-07 09:27:57 +00:00
string toSpeak = "Exit to Title Button";
if (exitPageQueryKey != toSpeak)
{
gameMenuQueryKey = "";
exitPageQueryKey = toSpeak;
2022-04-09 10:18:13 +00:00
MainClass.ScreenReader.Say(toSpeak, true);
2022-01-07 09:27:57 +00:00
}
return;
}
if (__instance.exitToDesktop.visible &&
2022-03-21 06:42:50 +00:00
__instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true)))
{
2022-01-07 09:27:57 +00:00
string toSpeak = "Exit to Desktop Button";
if (exitPageQueryKey != toSpeak)
{
gameMenuQueryKey = "";
exitPageQueryKey = toSpeak;
2022-04-09 10:18:13 +00:00
MainClass.ScreenReader.Say(toSpeak, true);
2022-01-07 09:27:57 +00:00
}
return;
}
}
catch (Exception e)
{
2022-03-19 07:24:53 +00:00
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
}
}
}