Moved options page patch
parent
7c1e600790
commit
820d714594
|
@ -70,7 +70,7 @@ namespace stardew_access
|
|||
|
||||
harmony.Patch(
|
||||
original: AccessTools.Method(typeof(OptionsPage), nameof(OptionsPage.draw), new Type[] { typeof(SpriteBatch) }),
|
||||
postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.OptionsPagePatch))
|
||||
postfix: new HarmonyMethod(typeof(OptionsPagePatch), nameof(OptionsPagePatch.DrawPatch))
|
||||
);
|
||||
|
||||
harmony.Patch(
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace stardew_access.Patches
|
|||
internal static string hoveredItemQueryKey = "";
|
||||
internal static string gameMenuQueryKey = "";
|
||||
internal static string exitPageQueryKey = "";
|
||||
internal static string optionsPageQueryKey = "";
|
||||
internal static string profilePageQuery = "";
|
||||
|
||||
internal static void GameMenuPatch(GameMenu __instance)
|
||||
|
@ -45,59 +44,6 @@ namespace stardew_access.Patches
|
|||
}
|
||||
|
||||
|
||||
internal static void OptionsPagePatch(OptionsPage __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex));
|
||||
int x = Game1.getMouseX(true), y = Game1.getMouseY(true);
|
||||
for (int i = 0; i < __instance.optionSlots.Count; i++)
|
||||
{
|
||||
if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y))
|
||||
{
|
||||
OptionsElement optionsElement = __instance.options[currentItemIndex + i];
|
||||
string toSpeak = optionsElement.label;
|
||||
|
||||
if (optionsElement is OptionsButton)
|
||||
toSpeak = $" {toSpeak} Button";
|
||||
else if (optionsElement is OptionsCheckbox)
|
||||
toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox";
|
||||
else if (optionsElement is OptionsDropDown)
|
||||
toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected";
|
||||
else if (optionsElement is OptionsSlider)
|
||||
toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider";
|
||||
else if (optionsElement is OptionsPlusMinus)
|
||||
toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}";
|
||||
else if (optionsElement is OptionsInputListener)
|
||||
{
|
||||
string buttons = "";
|
||||
((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; });
|
||||
toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (toSpeak.Contains(":"))
|
||||
toSpeak = toSpeak.Replace(":", "");
|
||||
|
||||
toSpeak = $"{toSpeak} Options:";
|
||||
}
|
||||
|
||||
if (optionsPageQueryKey != toSpeak)
|
||||
{
|
||||
gameMenuQueryKey = "";
|
||||
optionsPageQueryKey = 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
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
using StardewValley;
|
||||
using StardewValley.Menus;
|
||||
|
||||
namespace stardew_access.Patches
|
||||
{
|
||||
internal class OptionsPagePatch
|
||||
{
|
||||
internal static string optionsPageQueryKey = "";
|
||||
|
||||
internal static void DrawPatch(OptionsPage __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex));
|
||||
int x = Game1.getMouseX(true), y = Game1.getMouseY(true);
|
||||
for (int i = 0; i < __instance.optionSlots.Count; i++)
|
||||
{
|
||||
if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y))
|
||||
{
|
||||
OptionsElement optionsElement = __instance.options[currentItemIndex + i];
|
||||
string toSpeak = optionsElement.label;
|
||||
|
||||
if (optionsElement is OptionsButton)
|
||||
toSpeak = $" {toSpeak} Button";
|
||||
else if (optionsElement is OptionsCheckbox)
|
||||
toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox";
|
||||
else if (optionsElement is OptionsDropDown)
|
||||
toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected";
|
||||
else if (optionsElement is OptionsSlider)
|
||||
toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider";
|
||||
else if (optionsElement is OptionsPlusMinus)
|
||||
toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}";
|
||||
else if (optionsElement is OptionsInputListener)
|
||||
{
|
||||
string buttons = "";
|
||||
((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; });
|
||||
toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (toSpeak.Contains(":"))
|
||||
toSpeak = toSpeak.Replace(":", "");
|
||||
|
||||
toSpeak = $"{toSpeak} Options:";
|
||||
}
|
||||
|
||||
if (optionsPageQueryKey != toSpeak)
|
||||
{
|
||||
optionsPageQueryKey = 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 Cleanup()
|
||||
{
|
||||
optionsPageQueryKey = "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ namespace stardew_access.Patches
|
|||
{
|
||||
GameMenuPatches.gameMenuQueryKey = "";
|
||||
GameMenuPatches.exitPageQueryKey = "";
|
||||
GameMenuPatches.optionsPageQueryKey = "";
|
||||
OptionsPagePatch.Cleanup();
|
||||
SocialPagePatch.Cleanup();
|
||||
InventoryPagePatch.Cleanup();
|
||||
CraftingPagePatch.Cleanup();
|
||||
|
|
Loading…
Reference in New Issue