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

83 lines
3.0 KiB
C#
Raw Normal View History

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