Making geode menu accessible

master
shoaib11120 2022-01-06 18:52:23 +05:30
parent d9b92e7203
commit 12bd0bea80
4 changed files with 133 additions and 10 deletions

View File

@ -118,15 +118,15 @@ namespace stardew_access
postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.InventoryMenuPatch))
);
/*harmony.Patch(
original: AccessTools.Method(typeof(MenuWithInventory), nameof(MenuWithInventory.draw), new Type[] { typeof(SpriteBatch) }),
postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.MenuWithInventoryPatch))
);*/
harmony.Patch(
original: AccessTools.Method(typeof(ItemGrabMenu), nameof(ItemGrabMenu.draw), new Type[] { typeof(SpriteBatch) }),
postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ItemGrabMenuPatch))
);
harmony.Patch(
original: AccessTools.Method(typeof(GeodeMenu), nameof(GeodeMenu.draw), new Type[] { typeof(SpriteBatch) }),
postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.GeodeMenuPatch))
);
#endregion
#region Menu Patches
@ -187,7 +187,14 @@ namespace stardew_access
harmony.Patch(
original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }),
postfix: new HarmonyMethod(typeof(ChatManuPatches), nameof(ChatManuPatches.ChatBoxPatch))
);
);
#endregion
#region On Menu CLose Patch
harmony.Patch(
original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)),
postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.IClickableMenuOnExitPatch))
);
#endregion
#endregion
@ -228,10 +235,8 @@ namespace stardew_access
// Get the audio file and add it to a SoundEffect.
SoundEffect sound_effect;
string filePathCombined = Path.Combine(this.Helper.DirectoryPath, "mySound.wav");
using (var stream = new System.IO.FileStream(filePathCombined, System.IO.FileMode.Open))
{
sound_effect = SoundEffect.FromStream(stream);
}*/
System.IO.FileStream stream = new System.IO.FileStream(filePathCombined, System.IO.FileMode.Open)
sound_effect = SoundEffect.FromStream(stream);*/
#endregion
helper.Events.Input.ButtonPressed += this.OnButtonPressed;

View File

@ -122,6 +122,9 @@ namespace stardew_access.Patches
if (Game1.activeClickableMenu is Billboard)
return;
if (Game1.activeClickableMenu is GeodeMenu)
return;
StringBuilder toSpeak = new StringBuilder(" ");
#region Add item count before title

View File

@ -7,6 +7,106 @@ namespace stardew_access.Patches
{
internal class GameMenuPatches
{
internal static string geodeMenuQueryKey = "";
internal static void GeodeMenuPatch(GeodeMenu __instance)
{
try
{
int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position
if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y))
{
string toSpeak = "Place geode here";
if (geodeMenuQueryKey != toSpeak)
{
geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true);
}
return;
}
if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y))
{
string toSpeak = "Drop item here";
if (geodeMenuQueryKey != toSpeak)
{
geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true);
}
return;
}
if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y))
{
string toSpeak = "Trash can";
if (geodeMenuQueryKey != toSpeak)
{
geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true);
}
return;
}
if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
{
string toSpeak = "Ok button";
if (geodeMenuQueryKey != toSpeak)
{
geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true);
}
return;
}
for (int i = 0; i < __instance.inventory.inventory.Count; i++)
{
if(__instance.inventory.inventory[i].containsPoint(x, y))
{
string toSpeak = "";
if ((i + 1) <= __instance.inventory.actualInventory.Count)
{
if (__instance.inventory.actualInventory[i] != null)
{
string name = __instance.inventory.actualInventory[i].DisplayName;
int stack = __instance.inventory.actualInventory[i].Stack;
if(stack>1)
toSpeak = $"{stack} {name}";
else
toSpeak = $"{name}";
}
else
{
// For empty slot
toSpeak = "Empty Slot";
}
}
else
{
// For empty slot
toSpeak = "Empty Slot";
}
if (geodeMenuQueryKey != $"{toSpeak}:{i}")
{
geodeMenuQueryKey = $"{toSpeak}:{i}";
ScreenReader.say(toSpeak, true);
}
return;
}
}
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
internal static void ItemGrabMenuPatch(ItemGrabMenu __instance)
{
try

View File

@ -256,6 +256,21 @@ namespace stardew_access.Patches
}
}
internal static void IClickableMenuOnExitPatch(IClickableMenu __instance)
{
try
{
if(__instance is GeodeMenu)
{
GameMenuPatches.geodeMenuQueryKey = "";
}
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
internal static void resetGlobalVars()
{
currentLetterText = " ";