stardew-access/stardew-access/Patches/MenuPatches.cs

266 lines
11 KiB
C#
Raw Normal View History

using StardewModdingAPI;
using StardewValley;
using StardewValley.Menus;
namespace stardew_access.Patches
{
2022-01-04 14:02:44 +00:00
internal class MenuPatches
{
private static string currentLetterText = " ";
2021-12-30 13:39:05 +00:00
private static string currentLevelUpTitle = " ";
2021-12-28 15:13:07 +00:00
internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance)
{
try
{
int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position
if(__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y))
{
ScreenReader.sayWithMenuChecker($"Next Page Button", true);
return;
}
if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y))
{
ScreenReader.sayWithMenuChecker($"Previous Page Button", true);
return;
}
for(int i=0; i<__instance.languages.Count; i++)
{
if(__instance.languages[i].containsPoint(x, y))
{
ScreenReader.sayWithMenuChecker($"{__instance.languageList[i]} Button", true);
break;
}
}
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
internal static void MineElevatorMenuPatch(List<ClickableComponent> ___elevators)
{
try
{
int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position
for (int i=0; i<___elevators.Count; i++)
{
if(___elevators[i].containsPoint(x, y))
{
ScreenReader.sayWithMenuChecker($"{___elevators[i].name} level", true);
break;
}
}
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
2021-12-31 15:15:52 +00:00
internal static void NamingMenuPatch(NamingMenu __instance, string title, TextBox ___textBox)
{
try
{
__instance.textBoxCC.snapMouseCursor();
___textBox.SelectMe();
string toSpeak = $"{title}";
ScreenReader.sayWithChecker(toSpeak, true);
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
internal static void ConfirmationDialogPatch(ConfirmationDialog __instance, string ___message)
{
try
{
int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y;
2021-12-30 14:53:10 +00:00
ScreenReader.sayWithMenuChecker(___message, true);
if(__instance.okButton.containsPoint(x, y))
{
ScreenReader.sayWithMenuChecker("Ok Button", false);
} else if (__instance.cancelButton.containsPoint(x, y))
{
ScreenReader.sayWithMenuChecker("Cancel Button", false);
}
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
2021-12-30 13:39:05 +00:00
internal static void LevelUpMenuPatch(LevelUpMenu __instance, List<int> ___professionsToChoose, List<string> ___leftProfessionDescription, List<string> ___rightProfessionDescription, List<string> ___extraInfoForLevel, List<CraftingRecipe> ___newCraftingRecipes, string ___title)
{
try
{
int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y;
string leftProfession = " ", rightProfession = " ", extraInfo = " ", newCraftingRecipe = " ", toSpeak = " ";
if (!__instance.informationUp)
{
return;
}
if (__instance.isProfessionChooser)
{
if (___professionsToChoose.Count() == 0)
{
return;
}
for (int j = 0; j < ___leftProfessionDescription.Count; j++)
{
leftProfession += ___leftProfessionDescription[j] + ", ";
}
for (int i = 0; i < ___rightProfessionDescription.Count; i++)
{
rightProfession += ___rightProfessionDescription[i] + ", ";
}
if (__instance.leftProfession.containsPoint(x, y))
toSpeak = $"Selected: {leftProfession} Left click to choose.";
if (__instance.rightProfession.containsPoint(x, y))
toSpeak = $"Selected: {rightProfession} Left click to choose.";
}
else
{
foreach (string s2 in ___extraInfoForLevel)
{
extraInfo += s2 + ", ";
}
foreach (CraftingRecipe s in ___newCraftingRecipes)
{
string cookingOrCrafting = Game1.content.LoadString("Strings\\UI:LearnedRecipe_" + (s.isCookingRecipe ? "cooking" : "crafting"));
string message = Game1.content.LoadString("Strings\\UI:LevelUp_NewRecipe", cookingOrCrafting, s.DisplayName);
newCraftingRecipe += $"{message}, ";
}
if (__instance.okButton.containsPoint(x, y))
{
toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close.";
}
}
if (toSpeak != " ")
ScreenReader.sayWithMenuChecker(toSpeak, true);
else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.")
{
ScreenReader.sayWithMenuChecker($"{___title}. Select a new profession.", true);
currentLevelUpTitle = $"{___title}. Select a new profession.";
}
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
2021-12-27 14:39:45 +00:00
internal static void ShippingMenuPatch(ShippingMenu __instance, List<int> ___categoryTotals)
{
2021-12-28 15:13:07 +00:00
try
2021-12-27 14:39:45 +00:00
{
2021-12-28 15:13:07 +00:00
if (__instance.currentPage == -1)
2021-12-27 14:39:45 +00:00
{
2021-12-28 15:13:07 +00:00
int total = ___categoryTotals[5];
string toSpeak;
if (__instance.okButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
2021-12-27 14:39:45 +00:00
{
2021-12-28 15:13:07 +00:00
toSpeak = $"{total}g in total. Press left mouse button to save.";
2021-12-27 14:39:45 +00:00
ScreenReader.sayWithChecker(toSpeak, true);
}
2021-12-28 15:13:07 +00:00
for (int i = 0; i < __instance.categories.Count; i++)
{
if (__instance.categories[i].containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
{
toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g.";
ScreenReader.sayWithChecker(toSpeak, true);
}
}
2021-12-27 14:39:45 +00:00
}
}
2021-12-28 15:13:07 +00:00
catch (Exception e)
{
2021-12-28 15:14:59 +00:00
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
2021-12-28 15:13:07 +00:00
}
2021-12-27 14:39:45 +00:00
}
internal static void LetterViewerMenuPatch(LetterViewerMenu __instance)
{
try
{
if (!__instance.IsActive())
return;
#region Texts in the letter
string title = __instance.mailTitle;
string message = __instance.mailMessage[__instance.page];
string toSpeak = $"{title} \t\n\t {message}.";
if (__instance.ShouldShowInteractable())
{
if (__instance.moneyIncluded > 0)
{
string moneyText = Game1.content.LoadString("Strings\\UI:LetterViewer_MoneyIncluded", __instance.moneyIncluded);
toSpeak += $"\t\n\t ,Included money: {moneyText}";
}
else if (__instance.learnedRecipe != null && __instance.learnedRecipe.Length > 0)
{
string recipeText = Game1.content.LoadString("Strings\\UI:LetterViewer_LearnedRecipe", __instance.cookingOrCrafting);
toSpeak += $"\t\n\t ,Learned Recipe: {recipeText}";
}
}
if (currentLetterText != toSpeak)
{
currentLetterText = toSpeak;
2021-12-14 13:43:34 +00:00
// snap mouse to accept quest button
if (__instance.acceptQuestButton.visible)
{
toSpeak += "\t\n Left click to accept quest.";
__instance.acceptQuestButton.snapMouseCursorToCenter();
}
ScreenReader.say(toSpeak, false);
}
#endregion
#region Narrate items given in the mail
if (__instance.ShouldShowInteractable())
{
foreach (ClickableComponent c in __instance.itemsToGrab)
{
string name = c.name;
string label = c.label;
if (c.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y))
ScreenReader.sayWithChecker($"Grab: {name} \t\n {label}", false);
}
}
#endregion
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
internal static void resetGlobalVars()
{
currentLetterText = " ";
2021-12-30 13:39:05 +00:00
currentLevelUpTitle = " ";
}
}
}