From 12bd0bea80f0f24cbfe582cc8a4f7a6a34b70b53 Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Thu, 6 Jan 2022 18:52:23 +0530 Subject: [PATCH] Making geode menu accessible --- stardew-access/ModEntry.cs | 25 +++--- stardew-access/Patches/DialoguePatches.cs | 3 + stardew-access/Patches/GameMenuPatches.cs | 100 ++++++++++++++++++++++ stardew-access/Patches/MenuPatches.cs | 15 ++++ 4 files changed, 133 insertions(+), 10 deletions(-) diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 7472730..de19899 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -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; diff --git a/stardew-access/Patches/DialoguePatches.cs b/stardew-access/Patches/DialoguePatches.cs index fc7edf6..15caf98 100644 --- a/stardew-access/Patches/DialoguePatches.cs +++ b/stardew-access/Patches/DialoguePatches.cs @@ -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 diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index d5cb2a9..08b55ee 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -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 diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 6bbb0a8..7ca6822 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -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 = " ";