From 32d354f23c8e617b99ad21576572c376adfc1da8 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Sat, 19 Mar 2022 15:23:18 +0530 Subject: [PATCH] Fixing museum menu --- stardew-access/HarmonyPatches.cs | 11 +++ stardew-access/ModEntry.cs | 4 - stardew-access/Patches/MenuPatches.cs | 114 ++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 4 deletions(-) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 2a4f5c0..7a9440a 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -1,6 +1,7 @@ using HarmonyLib; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; using stardew_access.Patches; using StardewValley; using StardewValley.Menus; @@ -137,6 +138,16 @@ namespace stardew_access original: AccessTools.Method(typeof(LanguageSelectionMenu), nameof(LanguageSelectionMenu.draw), new Type[] { typeof(SpriteBatch) }), postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LanguageSelectionMenuPatch)) ); + + harmony.Patch( + original: AccessTools.Method(typeof(MuseumMenu), nameof(MuseumMenu.receiveKeyPress), new Type[] { typeof(Keys) }), + prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.MuseumMenuKeyPressPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(MuseumMenu), nameof(MuseumMenu.draw), new Type[] { typeof(SpriteBatch) }), + postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.MuseumMenuPatch)) + ); #endregion #region Quest Patches diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index bda0a42..5558305 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -205,17 +205,13 @@ namespace stardew_access // Manual read tile at looking tile if (Equals(e.Button, SButton.J) && !isLeftAltPressed) { - readTile = false; ReadTile.run(manuallyTriggered: true); - Task.Delay(1000).ContinueWith(t => { readTile = true; }); } // Manual read tile at player's position if (Equals(e.Button, SButton.J) && isLeftAltPressed) { - readTile = false; ReadTile.run(manuallyTriggered: true, playersPosition: true); - Task.Delay(1000).ContinueWith(t => { readTile = true; }); } /*if (Equals(e.Button, SButton.B)) diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 8312e82..fb3d267 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -1,4 +1,5 @@ using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; using stardew_access.Features; using StardewModdingAPI; using StardewValley; @@ -9,8 +10,121 @@ namespace stardew_access.Patches internal class MenuPatches { private static string currentLetterText = " "; + private static string hoveredItemQueryKey = " "; private static string currentLevelUpTitle = " "; public static Vector2? prevTile = null; + private static bool isMoving = false; + + internal static bool MuseumMenuKeyPressPatch() + { + try + { + if (isMoving) + return false; + + if (!isMoving) + { + isMoving = true; + Task.Delay(200).ContinueWith(_ => { isMoving = false; }); + } + + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + + return true; + } + + internal static void MuseumMenuPatch(MuseumMenu __instance, bool ___holdingMuseumPiece) + { + try + { + int x = Game1.getMouseX(), y = Game1.getMouseY(); // Mouse x and y position + + if (___holdingMuseumPiece) + { + // Museum Inventory + } + else + { + // Player Inventory + narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y) + { + #region Narrate hovered item + for (int i = 0; i < inventory.Count; i++) + { + if (inventory[i].containsPoint(x, y)) + { + string toSpeak = ""; + if ((i + 1) <= actualInventory.Count) + { + if (actualInventory[i] != null) + { + string name = actualInventory[i].DisplayName; + int stack = actualInventory[i].Stack; + string quality = ""; + + #region Add quality of item + if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).quality > 0) + { + int qualityIndex = ((StardewValley.Object)actualInventory[i]).quality; + if (qualityIndex == 1) + { + quality = "Silver quality"; + } + else if (qualityIndex == 2 || qualityIndex == 3) + { + quality = "Gold quality"; + } + else if (qualityIndex >= 4) + { + quality = "Iridium quality"; + } + } + #endregion + + if (inventoryMenu.highlightMethod(inventoryMenu.actualInventory[i])) + name = $"Donatable {name}"; + + if (stack > 1) + toSpeak = $"{stack} {name} {quality}"; + else + toSpeak = $"{name} {quality}"; + } + else + { + // For empty slot + toSpeak = "Empty Slot"; + } + } + else + { + // For empty slot + toSpeak = "Empty Slot"; + } + + if (hoveredItemQueryKey != $"{toSpeak}:{i}") + { + hoveredItemQueryKey = $"{toSpeak}:{i}"; + MainClass.GetScreenReader().Say(toSpeak, true); + } + return true; + } + } + #endregion + return false; + } internal static bool PlaySoundPatch(string cueName) {