From 6d3962ea4d56002c529ee331c711068f9bba2925 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 23 Feb 2023 21:41:05 +0530 Subject: [PATCH 01/40] Refactored code BuildingNAnimalMenuPatches.cs --- stardew-access/CustomCommands.cs | 39 +- stardew-access/Features/BuildingOperations.cs | 366 +++++++++ stardew-access/HarmonyPatches.cs | 6 +- stardew-access/ModEntry.cs | 8 +- .../Patches/AnimalQueryMenuPatch.cs | 78 ++ .../Patches/BuildingNAnimalMenuPatches.cs | 705 ------------------ stardew-access/Patches/CarpenterMenuPach.cs | 195 +++++ stardew-access/Patches/IClickableMenuPatch.cs | 25 +- .../Patches/PurchaseAnimalsMenuPatch.cs | 101 +++ 9 files changed, 782 insertions(+), 741 deletions(-) create mode 100644 stardew-access/Features/BuildingOperations.cs create mode 100644 stardew-access/Patches/AnimalQueryMenuPatch.cs delete mode 100644 stardew-access/Patches/BuildingNAnimalMenuPatches.cs create mode 100644 stardew-access/Patches/CarpenterMenuPach.cs create mode 100644 stardew-access/Patches/PurchaseAnimalsMenuPatch.cs diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index 557d7bf..8d10fc2 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -1,4 +1,5 @@ using Microsoft.Xna.Framework; +using stardew_access.Features; using stardew_access.Patches; using StardewModdingAPI; using StardewValley; @@ -327,18 +328,18 @@ namespace stardew_access return; } - BuildingNAnimalMenuPatches.marked[index] = new Vector2((int)Game1.player.getTileX(), (int)Game1.player.getTileY()); + BuildingOperations.marked[index] = new Vector2((int)Game1.player.getTileX(), (int)Game1.player.getTileY()); MainClass.InfoLog($"Location {(int)Game1.player.getTileX()}x {(int)Game1.player.getTileY()}y added at {index} index."); }); helper.ConsoleCommands.Add("marklist", "List all marked positions.", (string commmand, string[] args) => { string toPrint = ""; - for (int i = 0; i < BuildingNAnimalMenuPatches.marked.Length; i++) + for (int i = 0; i < BuildingOperations.marked.Length; i++) { - if (BuildingNAnimalMenuPatches.marked[i] != Vector2.Zero) + if (BuildingOperations.marked[i] != Vector2.Zero) { - toPrint = $"{toPrint}\n Index {i}: {BuildingNAnimalMenuPatches.marked[i].X}x {BuildingNAnimalMenuPatches.marked[i].Y}y"; + toPrint = $"{toPrint}\n Index {i}: {BuildingOperations.marked[i].X}x {BuildingOperations.marked[i].Y}y"; } } @@ -355,7 +356,7 @@ namespace stardew_access helper.ConsoleCommands.Add("buildsel", "Select the building index which you want to upgrade/demolish/paint", (string commmand, string[] args) => { - if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu && Game1.activeClickableMenu is not AnimalQueryMenu) || !BuildingNAnimalMenuPatches.isOnFarm) + if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu && Game1.activeClickableMenu is not AnimalQueryMenu) || !CarpenterMenuPatch.isOnFarm) { MainClass.InfoLog($"Cannot select building."); return; @@ -380,12 +381,12 @@ namespace stardew_access string? positionIndexInString = args.ElementAtOrDefault(1); int positionIndex = 0; - if (BuildingNAnimalMenuPatches.isMoving) + if (CarpenterMenuPatch.isMoving) { - if (BuildingNAnimalMenuPatches.isConstructing || BuildingNAnimalMenuPatches.isMoving) + if (CarpenterMenuPatch.isConstructing || CarpenterMenuPatch.isMoving) { - if (BuildingNAnimalMenuPatches.availableBuildings[index] == null) + if (BuildingOperations.availableBuildings[index] == null) { MainClass.InfoLog($"No building found with index {index}. Use buildlist."); return; @@ -406,9 +407,9 @@ namespace stardew_access } } } - else if (BuildingNAnimalMenuPatches.isConstructing && !BuildingNAnimalMenuPatches.isUpgrading) + else if (CarpenterMenuPatch.isConstructing && !CarpenterMenuPatch.isUpgrading) { - if (BuildingNAnimalMenuPatches.marked[index] == Vector2.Zero) + if (BuildingOperations.marked[index] == Vector2.Zero) { MainClass.InfoLog($"No marked position found at {index} index."); return; @@ -416,7 +417,7 @@ namespace stardew_access } else { - if (BuildingNAnimalMenuPatches.availableBuildings[index] == null) + if (BuildingOperations.availableBuildings[index] == null) { MainClass.InfoLog($"No building found with index {index}. Use buildlist."); return; @@ -427,19 +428,19 @@ namespace stardew_access if (Game1.activeClickableMenu is PurchaseAnimalsMenu) { - BuildingNAnimalMenuPatches.PurchaseAnimal(BuildingNAnimalMenuPatches.availableBuildings[index]); + BuildingOperations.PurchaseAnimal(BuildingOperations.availableBuildings[index]); } else if (Game1.activeClickableMenu is AnimalQueryMenu) { - BuildingNAnimalMenuPatches.MoveAnimal(BuildingNAnimalMenuPatches.availableBuildings[index]); + BuildingOperations.MoveAnimal(BuildingOperations.availableBuildings[index]); } else { - if (BuildingNAnimalMenuPatches.isConstructing && !BuildingNAnimalMenuPatches.isUpgrading) { response = BuildingNAnimalMenuPatches.Contstruct(BuildingNAnimalMenuPatches.marked[index]); } - else if (BuildingNAnimalMenuPatches.isMoving) { response = BuildingNAnimalMenuPatches.Move(BuildingNAnimalMenuPatches.availableBuildings[index], BuildingNAnimalMenuPatches.marked[positionIndex]); } - else if (BuildingNAnimalMenuPatches.isDemolishing) { response = BuildingNAnimalMenuPatches.Demolish(BuildingNAnimalMenuPatches.availableBuildings[index]); } - else if (BuildingNAnimalMenuPatches.isUpgrading) { response = BuildingNAnimalMenuPatches.Upgrade(BuildingNAnimalMenuPatches.availableBuildings[index]); } - else if (BuildingNAnimalMenuPatches.isPainting) { response = BuildingNAnimalMenuPatches.Paint(BuildingNAnimalMenuPatches.availableBuildings[index]); } + if (CarpenterMenuPatch.isConstructing && !CarpenterMenuPatch.isUpgrading) { response = BuildingOperations.Contstruct(BuildingOperations.marked[index]); } + else if (CarpenterMenuPatch.isMoving) { response = BuildingOperations.Move(BuildingOperations.availableBuildings[index], BuildingOperations.marked[positionIndex]); } + else if (CarpenterMenuPatch.isDemolishing) { response = BuildingOperations.Demolish(BuildingOperations.availableBuildings[index]); } + else if (CarpenterMenuPatch.isUpgrading) { response = BuildingOperations.Upgrade(BuildingOperations.availableBuildings[index]); } + else if (CarpenterMenuPatch.isPainting) { response = BuildingOperations.Paint(BuildingOperations.availableBuildings[index]); } } if (response != null) @@ -517,7 +518,7 @@ namespace stardew_access string? name = buildings[i].nameOfIndoorsWithoutUnique; name = (name == "null") ? buildings[i].buildingType.Value : name; - BuildingNAnimalMenuPatches.availableBuildings[buildingIndex] = buildings[i]; + BuildingOperations.availableBuildings[buildingIndex] = buildings[i]; toPrint = $"{toPrint}\nIndex {buildingIndex}: {name}: At {buildings[i].tileX}x and {buildings[i].tileY}y"; ++buildingIndex; } diff --git a/stardew-access/Features/BuildingOperations.cs b/stardew-access/Features/BuildingOperations.cs new file mode 100644 index 0000000..f970ba3 --- /dev/null +++ b/stardew-access/Features/BuildingOperations.cs @@ -0,0 +1,366 @@ +using Microsoft.Xna.Framework; +using stardew_access.Patches; +using StardewValley; +using StardewValley.Buildings; +using StardewValley.Locations; +using StardewValley.Objects; + +namespace stardew_access.Features +{ + internal class BuildingOperations + { + internal static Building?[] availableBuildings = new Building[100]; + internal static Vector2[] marked = new Vector2[10]; + + public static string? Demolish(Building? toDemolish) + { + if (toDemolish == null) + return null; + + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::654) + Farm farm = (Farm)Game1.getLocationFromName("Farm"); + Action buildingLockFailed = delegate + { + if (CarpenterMenuPatch.isDemolishing) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); + } + }; + Action continueDemolish = delegate + { + if (CarpenterMenuPatch.isDemolishing && toDemolish != null && farm.buildings.Contains(toDemolish)) + { + if ((int)toDemolish.daysOfConstructionLeft.Value > 0 || (int)toDemolish.daysUntilUpgrade.Value > 0) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_DuringConstruction"); + } + else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is AnimalHouse && ((AnimalHouse)toDemolish.indoors.Value).animalsThatLiveHere.Count > 0) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_AnimalsHere"); + } + else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value.farmers.Any()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); + } + else + { + if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin) + { + foreach (Farmer current in Game1.getAllFarmers()) + { + if (current.currentLocation != null && current.currentLocation.Name == ((Cabin)toDemolish.indoors.Value).GetCellarName()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); + return; + } + } + } + if (toDemolish.indoors.Value is Cabin && ((Cabin)toDemolish.indoors.Value).farmhand.Value.isActive()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_FarmhandOnline"); + } + else + { + toDemolish.BeforeDemolish(); + Chest? chest = null; + if (toDemolish.indoors.Value is Cabin) + { + List list = ((Cabin)toDemolish.indoors.Value).demolish(); + if (list.Count > 0) + { + chest = new Chest(playerChest: true); + chest.fixLidFrame(); + chest.items.Set(list); + } + } + if (farm.destroyStructure(toDemolish)) + { + _ = (int)toDemolish.tileY.Value; + _ = (int)toDemolish.tilesHigh.Value; + Game1.flashAlpha = 1f; + toDemolish.showDestroyedAnimation(Game1.getFarm()); + Game1.playSound("explosion"); + Utility.spreadAnimalsAround(toDemolish, farm); + if (CarpenterMenuPatch.carpenterMenu != null) + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenu, 1500); + // freeze = true; + if (chest != null) + { + farm.objects[new Vector2((int)toDemolish.tileX.Value + (int)toDemolish.tilesWide.Value / 2, (int)toDemolish.tileY.Value + (int)toDemolish.tilesHigh.Value / 2)] = chest; + } + } + } + } + } + }; + if (toDemolish != null) + { + if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin && !Game1.IsMasterGame) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); + toDemolish = null; + return response; + } + if (CarpenterMenuPatch.carpenterMenu != null && !CarpenterMenuPatch.carpenterMenu.CanDemolishThis(toDemolish)) + { + toDemolish = null; + return response; + } + if (CarpenterMenuPatch.carpenterMenu != null && !Game1.IsMasterGame && !CarpenterMenuPatch.carpenterMenu.hasPermissionsToDemolish(toDemolish)) + { + toDemolish = null; + return response; + } + } + if (toDemolish != null && toDemolish.indoors.Value is Cabin) + { + Cabin cabin = (Cabin)toDemolish.indoors.Value; + if (cabin.farmhand.Value != null && (bool)cabin.farmhand.Value.isCustomized.Value) + { + Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\UI:Carpenter_DemolishCabinConfirm", cabin.farmhand.Value.Name), Game1.currentLocation.createYesNoResponses(), delegate (Farmer f, string answer) + { + if (answer == "Yes") + { + Game1.activeClickableMenu = CarpenterMenuPatch.carpenterMenu; + Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); + } + else + { + if (CarpenterMenuPatch.carpenterMenu != null) + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenu, 1000); + } + }); + return response; + } + } + if (toDemolish != null) + { + Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); + } + + return response; + } + + public static string? Contstruct(Vector2 position) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::874) + Game1.player.team.buildLock.RequestLock(delegate + { + if (CarpenterMenuPatch.isOnFarm && Game1.locationRequest == null) + { + if (tryToBuild(position)) + { + if (CarpenterMenuPatch.carpenterMenu != null) + { + CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.consumeResources(); + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 2000); + } + // freeze = true; + } + else + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantBuild"); + } + } + Game1.player.team.buildLock.ReleaseLock(); + }); + + return response; + } + + public static bool tryToBuild(Vector2 position) + { + if (CarpenterMenuPatch.carpenterMenu == null) + return false; + return ((Farm)Game1.getLocationFromName("Farm")).buildStructure(CarpenterMenuPatch.carpenterMenu.CurrentBlueprint, position, Game1.player, CarpenterMenuPatch.isMagicalConstruction); + } + + public static string? Upgrade(Building? toUpgrade) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::775) + if (CarpenterMenuPatch.carpenterMenu != null && toUpgrade != null && CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.name != null && toUpgrade.buildingType.Equals(CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.nameOfBuildingToUpgrade)) + { + CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.consumeResources(); + toUpgrade.daysUntilUpgrade.Value = 2; + toUpgrade.showUpgradeAnimation(Game1.getFarm()); + Game1.playSound("axe"); + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 1500); + // freeze = true; + // Game1.multiplayer.globalChatInfoMessage("BuildingBuild", Game1.player.Name, Utility.AOrAn(carpenterMenu.CurrentBlueprint.displayName), carpenterMenu.CurrentBlueprint.displayName, Game1.player.farmName.Value); + } + else if (toUpgrade != null) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantUpgrade_BuildingType"); + } + return response; + } + + public static string? Paint(Building? toPaint) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::793) + Farm farm_location = Game1.getFarm(); + if (toPaint != null) + { + if (!toPaint.CanBePainted()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); + return response; + } + if (CarpenterMenuPatch.carpenterMenu != null && !CarpenterMenuPatch.carpenterMenu.HasPermissionsToPaint(toPaint)) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); + return response; + } + toPaint.color.Value = Color.White; + + if (CarpenterMenuPatch.carpenterMenu != null) + CarpenterMenuPatch.carpenterMenu.SetChildMenu(new StardewValley.Menus.BuildingPaintMenu(toPaint)); + } + /* TODO Add painting of farm house + else if (farm_location.GetHouseRect().Contains(Utility.Vector2ToPoint(new Vector2(toPaint.tileX, toPaint.tileY)))) + { + if (!carpenterMenu.CanPaintHouse()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); + } + else if (!carpenterMenu.HasPermissionsToPaint(null)) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); + } + else + { + carpenterMenu.SetChildMenu(new BuildingPaintMenu("House", () => (farm_location.paintedHouseTexture != null) ? farm_location.paintedHouseTexture : Farm.houseTextures, farm_location.houseSource.Value, farm_location.housePaintColor.Value)); + } + }*/ + return response; + } + + public static string? Move(Building? buildingToMove, Vector2 position) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::829) + if (buildingToMove != null) + { + string? name = buildingToMove.nameOfIndoorsWithoutUnique; + name = (name == "null") ? buildingToMove.buildingType.Value : name; + + if ((int)buildingToMove.daysOfConstructionLeft.Value > 0) + { + buildingToMove = null; + return "Building under construction, cannot move"; + } + if (CarpenterMenuPatch.carpenterMenu != null && !CarpenterMenuPatch.carpenterMenu.hasPermissionsToMove(buildingToMove)) + { + buildingToMove = null; + return "You don't have permission to move this building"; + } + Game1.playSound("axchop"); + + if (((Farm)Game1.getLocationFromName("Farm")).buildStructure(buildingToMove, position, Game1.player)) + { + if (buildingToMove is ShippingBin) + { + ((ShippingBin)buildingToMove).initLid(); + } + if (buildingToMove is GreenhouseBuilding) + { + Game1.getFarm().greenhouseMoved.Value = true; + } + buildingToMove.performActionOnBuildingPlacement(); + buildingToMove = null; + Game1.playSound("axchop"); + DelayedAction.playSoundAfterDelay("dirtyHit", 50); + DelayedAction.playSoundAfterDelay("dirtyHit", 150); + + response = $"{buildingToMove} moved to {position.X}x {position.Y}y"; + } + else + { + Game1.playSound("cancel"); + response = $"Cannot move building to {position.X}x {position.Y}y"; + } + + } + + return response; + } + + public static void PurchaseAnimal(Building? selection) + { + if (selection == null) + return; + + if (PurchaseAnimalsMenuPatch.purchaseAnimalsMenu == null) + return; + + int x = (selection.tileX.Value * Game1.tileSize) - Game1.viewport.X; + int y = (selection.tileY.Value * Game1.tileSize) - Game1.viewport.Y; + + if (PurchaseAnimalsMenuPatch.animalBeingPurchased != null && !selection.buildingType.Value.Contains(PurchaseAnimalsMenuPatch.animalBeingPurchased.buildingTypeILiveIn.Value)) + { + string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11326", PurchaseAnimalsMenuPatch.animalBeingPurchased.displayType); + MainClass.ScreenReader.Say(warn, true); + return; + } + + if (((AnimalHouse)selection.indoors.Value).isFull()) + { + string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11321"); + MainClass.ScreenReader.Say(warn, true); + return; + } + + PurchaseAnimalsMenuPatch.purchaseAnimalsMenu.receiveLeftClick(x, y); + } + + public static void MoveAnimal(Building? selection) + { + if (selection == null) + return; + + if (AnimalQueryMenuPatch.animalQueryMenu == null) + return; + + if (AnimalQueryMenuPatch.animalBeingMoved == null) + return; + + // The following code is taken from the game's source code [AnimalQueryMenu.cs::receiveLeftClick] + if (selection.buildingType.Value.Contains(AnimalQueryMenuPatch.animalBeingMoved.buildingTypeILiveIn.Value)) + { + if (((AnimalHouse)selection.indoors.Value).isFull()) + { + string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_BuildingFull"); + MainClass.ScreenReader.Say(warn, true); + return; + } + if (selection.Equals(AnimalQueryMenuPatch.animalBeingMoved.home)) + { + string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_AlreadyHome"); + MainClass.ScreenReader.Say(warn, true); + return; + } + ((AnimalHouse)AnimalQueryMenuPatch.animalBeingMoved.home.indoors.Value).animalsThatLiveHere.Remove(AnimalQueryMenuPatch.animalBeingMoved.myID.Value); + if (((AnimalHouse)AnimalQueryMenuPatch.animalBeingMoved.home.indoors.Value).animals.ContainsKey(AnimalQueryMenuPatch.animalBeingMoved.myID.Value)) + { + ((AnimalHouse)selection.indoors.Value).animals.Add(AnimalQueryMenuPatch.animalBeingMoved.myID.Value, AnimalQueryMenuPatch.animalBeingMoved); + ((AnimalHouse)AnimalQueryMenuPatch.animalBeingMoved.home.indoors.Value).animals.Remove(AnimalQueryMenuPatch.animalBeingMoved.myID.Value); + } + AnimalQueryMenuPatch.animalBeingMoved.home = selection; + AnimalQueryMenuPatch.animalBeingMoved.homeLocation.Value = new Vector2((int)selection.tileX.Value, (int)selection.tileY.Value); + ((AnimalHouse)selection.indoors.Value).animalsThatLiveHere.Add(AnimalQueryMenuPatch.animalBeingMoved.myID.Value); + AnimalQueryMenuPatch.animalBeingMoved.makeSound(); + Game1.globalFadeToBlack(AnimalQueryMenuPatch.animalQueryMenu.finishedPlacingAnimal); + } + else + { + string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_CantLiveThere"); + MainClass.ScreenReader.Say(warn, true); + } + return; + } + } +} diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index bf570f2..72475db 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -237,17 +237,17 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.draw), new Type[] { typeof(SpriteBatch) }), - prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.CarpenterMenuPatch)) + prefix: new HarmonyMethod(typeof(CarpenterMenuPatch), nameof(CarpenterMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(PurchaseAnimalsMenu), nameof(PurchaseAnimalsMenu.draw), new Type[] { typeof(SpriteBatch) }), - prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.PurchaseAnimalsMenuPatch)) + prefix: new HarmonyMethod(typeof(PurchaseAnimalsMenuPatch), nameof(PurchaseAnimalsMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(AnimalQueryMenu), nameof(AnimalQueryMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.AnimalQueryMenuPatch)) + postfix: new HarmonyMethod(typeof(AnimalQueryMenuPatch), nameof(AnimalQueryMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index def28d6..1830c50 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -128,14 +128,14 @@ namespace stardew_access HarmonyPatches.Initialize(harmony); //Initialize marked locations - for (int i = 0; i < BuildingNAnimalMenuPatches.marked.Length; i++) + for (int i = 0; i < BuildingOperations.marked.Length; i++) { - BuildingNAnimalMenuPatches.marked[i] = Vector2.Zero; + BuildingOperations.marked[i] = Vector2.Zero; } - for (int i = 0; i < BuildingNAnimalMenuPatches.availableBuildings.Length; i++) + for (int i = 0; i < BuildingOperations.availableBuildings.Length; i++) { - BuildingNAnimalMenuPatches.availableBuildings[i] = null; + BuildingOperations.availableBuildings[i] = null; } #endregion diff --git a/stardew-access/Patches/AnimalQueryMenuPatch.cs b/stardew-access/Patches/AnimalQueryMenuPatch.cs new file mode 100644 index 0000000..232d573 --- /dev/null +++ b/stardew-access/Patches/AnimalQueryMenuPatch.cs @@ -0,0 +1,78 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class AnimalQueryMenuPatch + { + internal static bool isNarratingAnimalInfo = false; + internal static string animalQueryMenuQuery = ""; + internal static AnimalQueryMenu? animalQueryMenu; + internal static FarmAnimal? animalBeingMoved = null; + internal static bool isOnFarm = false; + + internal static void DrawPatch(AnimalQueryMenu __instance, bool ___confirmingSell, FarmAnimal ___animal, TextBox ___textBox, string ___parentName, bool ___movingAnimal) + { + try + { + if (TextBoxPatch.isAnyTextBoxActive) return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details + string toSpeak = " ", details = " "; + + isOnFarm = ___movingAnimal; + animalQueryMenu = __instance; + animalBeingMoved = ___animal; + + if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) + { + string name = ___animal.displayName; + string type = ___animal.displayType; + int age = (___animal.GetDaysOwned() + 1) / 28 + 1; + string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); + string parent = ""; + if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) + { + ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); + } + if (___parentName != null) + { + parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); + } + + details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; + animalQueryMenuQuery = ""; + + isNarratingAnimalInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "OK button"; + else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) + toSpeak = $"Sell for {___animal.getSellPrice()}g button"; + else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm selling animal"; + else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel selling animal"; + else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) + toSpeak = "Change home building button"; + else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) + toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = "Animal name text box"; + + if (animalQueryMenuQuery != toSpeak) + { + animalQueryMenuQuery = toSpeak; + MainClass.ScreenReader.Say($"{details} {toSpeak}", true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"An error occured in AnimalQueryMenuPatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs deleted file mode 100644 index 352011f..0000000 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ /dev/null @@ -1,705 +0,0 @@ -using Microsoft.Xna.Framework; -using StardewValley; -using StardewValley.Buildings; -using StardewValley.Locations; -using StardewValley.Menus; -using StardewValley.Objects; - -namespace stardew_access.Patches -{ - internal class BuildingNAnimalMenuPatches - { - internal static Vector2[] marked = new Vector2[10]; - internal static Building?[] availableBuildings = new Building[100]; - internal static CarpenterMenu? carpenterMenu = null; - internal static bool isNarratingAnimalInfo = false; - internal static string animalQueryMenuQuery = " "; - internal static string carpenterMenuQuery = "", purchaseAnimalMenuQuery = ""; - internal static bool isSayingBlueprintInfo = false; - internal static string prevBlueprintInfo = ""; - internal static bool isOnFarm = false, isUpgrading = false, isDemolishing = false, isPainting = false, isConstructing = false, isMoving = false, isMagicalConstruction = false; - internal static bool firstTimeInNamingMenu = true; - internal static PurchaseAnimalsMenu? purchaseAnimalsMenu; - internal static AnimalQueryMenu? animalQueryMenu; - private static FarmAnimal? animalBeingPurchasedOrMoved = null; - - internal static void AnimalQueryMenuPatch(AnimalQueryMenu __instance, bool ___confirmingSell, FarmAnimal ___animal, TextBox ___textBox, string ___parentName, bool ___movingAnimal) - { - try - { - if (TextBoxPatch.isAnyTextBoxActive) return; - - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details - string toSpeak = " ", details = " "; - - isOnFarm = ___movingAnimal; - animalQueryMenu = __instance; - animalBeingPurchasedOrMoved = ___animal; - - if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) - { - string name = ___animal.displayName; - string type = ___animal.displayType; - int age = (___animal.GetDaysOwned() + 1) / 28 + 1; - string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); - string parent = ""; - if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) - { - ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); - } - if (___parentName != null) - { - parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); - } - - details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; - animalQueryMenuQuery = " "; - - isNarratingAnimalInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "OK button"; - else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) - toSpeak = $"Sell for {___animal.getSellPrice()}g button"; - else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm selling animal"; - else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel selling animal"; - else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) - toSpeak = "Change home building button"; - else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) - toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = "Animal name text box"; - - if (animalQueryMenuQuery != toSpeak) - { - animalQueryMenuQuery = toSpeak; - MainClass.ScreenReader.Say($"{details} {toSpeak}", true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void PurchaseAnimalsMenuPatch(PurchaseAnimalsMenu __instance, bool ___onFarm, bool ___namingAnimal, TextBox ___textBox, FarmAnimal ___animalBeingPurchased) - { - try - { - if (TextBoxPatch.isAnyTextBoxActive) return; - - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - purchaseAnimalsMenu = __instance; - isOnFarm = ___onFarm; - animalBeingPurchasedOrMoved = ___animalBeingPurchased; - - if (___onFarm && ___namingAnimal) - { - string toSpeak = ""; - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "Cancel Button"; - } - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - { - toSpeak = "OK Button"; - } - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - { - toSpeak = "Random Name Button"; - } - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - { - toSpeak = "Name Text Box"; - // string? value = ___textBox.Text; - // if (value != "" && value != null && value != "null") - // toSpeak = $"{toSpeak}, Value: {value}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = toSpeak; - - if (firstTimeInNamingMenu) - { - toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; - firstTimeInNamingMenu = false; - } - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else if (___onFarm && !___namingAnimal) - { - firstTimeInNamingMenu = true; - } - else if (!___onFarm && !___namingAnimal) - { - firstTimeInNamingMenu = true; - if (__instance.hovered != null) - { - string toSpeak = ""; - if (((StardewValley.Object)__instance.hovered.item).Type != null) - { - toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; - } - else - { - string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); - int price = __instance.hovered.item.salePrice(); - string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); - - toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = 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 CarpenterMenuPatch( - CarpenterMenu __instance, bool ___onFarm, List ___ingredients, int ___price, - List ___blueprints, int ___currentBlueprintIndex, bool ___upgrading, bool ___demolishing, bool ___moving, - bool ___painting, bool ___magicalConstruction) - { - try - { - isOnFarm = ___onFarm; - carpenterMenu = __instance; - isMagicalConstruction = ___magicalConstruction; - if (!___onFarm) - { - isUpgrading = false; - isDemolishing = false; - isPainting = false; - isMoving = false; - isConstructing = false; - - #region The blueprint menu - BluePrint currentBluprint = __instance.CurrentBlueprint; - if (currentBluprint == null) - return; - - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - string ingredients = ""; - string name = currentBluprint.displayName; - string upgradeName = currentBluprint.nameOfBuildingToUpgrade; - string description = currentBluprint.description; - string price = $"{___price}g"; - string blueprintInfo; - int width = currentBluprint.tilesWidth; - int height = currentBluprint.tilesHeight; - - #region Get ingredients - for (int i = 0; i < ___ingredients.Count; i++) - { - string itemName = ___ingredients[i].DisplayName; - int itemStack = ___ingredients[i].Stack; - string itemQuality = ""; - - int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; - if (qualityValue == 1) - { - itemQuality = "Silver quality"; - } - else if (qualityValue == 2 || qualityValue == 3) - { - itemQuality = "Gold quality"; - } - else if (qualityValue >= 4) - { - itemQuality = "Iridium quality"; - } - - ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; - } - #endregion - - blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; - - if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo) - { - SayBlueprintInfo(blueprintInfo); - } - else if (prevBlueprintInfo != blueprintInfo) - { - prevBlueprintInfo = blueprintInfo; - SayBlueprintInfo(blueprintInfo); - } - else - { - if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - { - string toSpeak = "Previous Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - { - string toSpeak = "Next Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) - { - string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) - { - string toSpeak = "Move Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) - { - string toSpeak = "Paint Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) - { - string toSpeak = "Cancel Button"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - #endregion - } - else - { - if (___demolishing) - isDemolishing = true; - else if (___upgrading) - isUpgrading = true; - else if (___painting) - isPainting = true; - else if (___moving) - isMoving = true; - else - isConstructing = true; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static async void SayBlueprintInfo(string info) - { - isSayingBlueprintInfo = true; - MainClass.ScreenReader.Say(info, true); - await Task.Delay(300); - isSayingBlueprintInfo = false; - } - - public static string? Demolish(Building? toDemolish) - { - if (toDemolish == null) - return null; - - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::654) - Farm farm = (Farm)Game1.getLocationFromName("Farm"); - Action buildingLockFailed = delegate - { - if (isDemolishing) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); - } - }; - Action continueDemolish = delegate - { - if (isDemolishing && toDemolish != null && farm.buildings.Contains(toDemolish)) - { - if ((int)toDemolish.daysOfConstructionLeft.Value > 0 || (int)toDemolish.daysUntilUpgrade.Value > 0) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_DuringConstruction"); - } - else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is AnimalHouse && ((AnimalHouse)toDemolish.indoors.Value).animalsThatLiveHere.Count > 0) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_AnimalsHere"); - } - else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value.farmers.Any()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); - } - else - { - if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin) - { - foreach (Farmer current in Game1.getAllFarmers()) - { - if (current.currentLocation != null && current.currentLocation.Name == ((Cabin)toDemolish.indoors.Value).GetCellarName()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); - return; - } - } - } - if (toDemolish.indoors.Value is Cabin && ((Cabin)toDemolish.indoors.Value).farmhand.Value.isActive()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_FarmhandOnline"); - } - else - { - toDemolish.BeforeDemolish(); - Chest? chest = null; - if (toDemolish.indoors.Value is Cabin) - { - List list = ((Cabin)toDemolish.indoors.Value).demolish(); - if (list.Count > 0) - { - chest = new Chest(playerChest: true); - chest.fixLidFrame(); - chest.items.Set(list); - } - } - if (farm.destroyStructure(toDemolish)) - { - _ = (int)toDemolish.tileY.Value; - _ = (int)toDemolish.tilesHigh.Value; - Game1.flashAlpha = 1f; - toDemolish.showDestroyedAnimation(Game1.getFarm()); - Game1.playSound("explosion"); - Utility.spreadAnimalsAround(toDemolish, farm); - if (carpenterMenu != null) - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1500); - // freeze = true; - if (chest != null) - { - farm.objects[new Vector2((int)toDemolish.tileX.Value + (int)toDemolish.tilesWide.Value / 2, (int)toDemolish.tileY.Value + (int)toDemolish.tilesHigh.Value / 2)] = chest; - } - } - } - } - } - }; - if (toDemolish != null) - { - if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin && !Game1.IsMasterGame) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); - toDemolish = null; - return response; - } - if (carpenterMenu != null && !carpenterMenu.CanDemolishThis(toDemolish)) - { - toDemolish = null; - return response; - } - if (carpenterMenu != null && !Game1.IsMasterGame && !carpenterMenu.hasPermissionsToDemolish(toDemolish)) - { - toDemolish = null; - return response; - } - } - if (toDemolish != null && toDemolish.indoors.Value is Cabin) - { - Cabin cabin = (Cabin)toDemolish.indoors.Value; - if (cabin.farmhand.Value != null && (bool)cabin.farmhand.Value.isCustomized.Value) - { - Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\UI:Carpenter_DemolishCabinConfirm", cabin.farmhand.Value.Name), Game1.currentLocation.createYesNoResponses(), delegate (Farmer f, string answer) - { - if (answer == "Yes") - { - Game1.activeClickableMenu = carpenterMenu; - Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); - } - else - { - if (carpenterMenu != null) - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1000); - } - }); - return response; - } - } - if (toDemolish != null) - { - Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); - } - - return response; - } - - public static string? Contstruct(Vector2 position) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::874) - Game1.player.team.buildLock.RequestLock(delegate - { - if (isOnFarm && Game1.locationRequest == null) - { - if (tryToBuild(position)) - { - if (carpenterMenu != null) - { - carpenterMenu.CurrentBlueprint.consumeResources(); - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 2000); - } - // freeze = true; - } - else - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantBuild"); - } - } - Game1.player.team.buildLock.ReleaseLock(); - }); - - return response; - } - - public static bool tryToBuild(Vector2 position) - { - if (carpenterMenu == null) - return false; - return ((Farm)Game1.getLocationFromName("Farm")).buildStructure(carpenterMenu.CurrentBlueprint, position, Game1.player, isMagicalConstruction); - } - - public static string? Upgrade(Building? toUpgrade) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::775) - if (carpenterMenu != null && toUpgrade != null && carpenterMenu.CurrentBlueprint.name != null && toUpgrade.buildingType.Equals(carpenterMenu.CurrentBlueprint.nameOfBuildingToUpgrade)) - { - carpenterMenu.CurrentBlueprint.consumeResources(); - toUpgrade.daysUntilUpgrade.Value = 2; - toUpgrade.showUpgradeAnimation(Game1.getFarm()); - Game1.playSound("axe"); - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 1500); - // freeze = true; - // Game1.multiplayer.globalChatInfoMessage("BuildingBuild", Game1.player.Name, Utility.AOrAn(carpenterMenu.CurrentBlueprint.displayName), carpenterMenu.CurrentBlueprint.displayName, Game1.player.farmName.Value); - } - else if (toUpgrade != null) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantUpgrade_BuildingType"); - } - return response; - } - - public static string? Paint(Building? toPaint) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::793) - Farm farm_location = Game1.getFarm(); - if (toPaint != null) - { - if (!toPaint.CanBePainted()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); - return response; - } - if (carpenterMenu != null && !carpenterMenu.HasPermissionsToPaint(toPaint)) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); - return response; - } - toPaint.color.Value = Color.White; - - if (carpenterMenu != null) - carpenterMenu.SetChildMenu(new BuildingPaintMenu(toPaint)); - } - /* TODO Add painting of farm house - else if (farm_location.GetHouseRect().Contains(Utility.Vector2ToPoint(new Vector2(toPaint.tileX, toPaint.tileY)))) - { - if (!carpenterMenu.CanPaintHouse()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); - } - else if (!carpenterMenu.HasPermissionsToPaint(null)) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); - } - else - { - carpenterMenu.SetChildMenu(new BuildingPaintMenu("House", () => (farm_location.paintedHouseTexture != null) ? farm_location.paintedHouseTexture : Farm.houseTextures, farm_location.houseSource.Value, farm_location.housePaintColor.Value)); - } - }*/ - return response; - } - - public static string? Move(Building? buildingToMove, Vector2 position) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::829) - if (buildingToMove != null) - { - string? name = buildingToMove.nameOfIndoorsWithoutUnique; - name = (name == "null") ? buildingToMove.buildingType.Value : name; - - if ((int)buildingToMove.daysOfConstructionLeft.Value > 0) - { - buildingToMove = null; - return "Building under construction, cannot move"; - } - if (carpenterMenu != null && !carpenterMenu.hasPermissionsToMove(buildingToMove)) - { - buildingToMove = null; - return "You don't have permission to move this building"; - } - Game1.playSound("axchop"); - - if (((Farm)Game1.getLocationFromName("Farm")).buildStructure(buildingToMove, position, Game1.player)) - { - if (buildingToMove is ShippingBin) - { - ((ShippingBin)buildingToMove).initLid(); - } - if (buildingToMove is GreenhouseBuilding) - { - Game1.getFarm().greenhouseMoved.Value = true; - } - buildingToMove.performActionOnBuildingPlacement(); - buildingToMove = null; - Game1.playSound("axchop"); - DelayedAction.playSoundAfterDelay("dirtyHit", 50); - DelayedAction.playSoundAfterDelay("dirtyHit", 150); - - response = $"{buildingToMove} moved to {position.X}x {position.Y}y"; - } - else - { - Game1.playSound("cancel"); - response = $"Cannot move building to {position.X}x {position.Y}y"; - } - - } - - return response; - } - - public static void PurchaseAnimal(Building? selection) - { - if (selection == null) - return; - - if (purchaseAnimalsMenu == null) - return; - - int x = (selection.tileX.Value * Game1.tileSize) - Game1.viewport.X; - int y = (selection.tileY.Value * Game1.tileSize) - Game1.viewport.Y; - - if (animalBeingPurchasedOrMoved != null && !selection.buildingType.Value.Contains(animalBeingPurchasedOrMoved.buildingTypeILiveIn.Value)) - { - string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11326", animalBeingPurchasedOrMoved.displayType); - MainClass.ScreenReader.Say(warn, true); - return; - } - - if (((AnimalHouse)selection.indoors.Value).isFull()) - { - string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11321"); - MainClass.ScreenReader.Say(warn, true); - return; - } - - purchaseAnimalsMenu.receiveLeftClick(x, y); - } - - public static void MoveAnimal(Building? selection) - { - if (selection == null) - return; - - if (animalQueryMenu == null) - return; - - if (animalBeingPurchasedOrMoved == null) - return; - - // The following code is taken from the game's source code [AnimalQueryMenu.cs::receiveLeftClick] - if (selection.buildingType.Value.Contains(animalBeingPurchasedOrMoved.buildingTypeILiveIn.Value)) - { - if (((AnimalHouse)selection.indoors.Value).isFull()) - { - string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_BuildingFull"); - MainClass.ScreenReader.Say(warn, true); - return; - } - if (selection.Equals(animalBeingPurchasedOrMoved.home)) - { - string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_AlreadyHome"); - MainClass.ScreenReader.Say(warn, true); - return; - } - ((AnimalHouse)animalBeingPurchasedOrMoved.home.indoors.Value).animalsThatLiveHere.Remove(animalBeingPurchasedOrMoved.myID.Value); - if (((AnimalHouse)animalBeingPurchasedOrMoved.home.indoors.Value).animals.ContainsKey(animalBeingPurchasedOrMoved.myID.Value)) - { - ((AnimalHouse)selection.indoors.Value).animals.Add(animalBeingPurchasedOrMoved.myID.Value, animalBeingPurchasedOrMoved); - ((AnimalHouse)animalBeingPurchasedOrMoved.home.indoors.Value).animals.Remove(animalBeingPurchasedOrMoved.myID.Value); - } - animalBeingPurchasedOrMoved.home = selection; - animalBeingPurchasedOrMoved.homeLocation.Value = new Vector2((int)selection.tileX.Value, (int)selection.tileY.Value); - ((AnimalHouse)selection.indoors.Value).animalsThatLiveHere.Add(animalBeingPurchasedOrMoved.myID.Value); - animalBeingPurchasedOrMoved.makeSound(); - Game1.globalFadeToBlack(animalQueryMenu.finishedPlacingAnimal); - } - else - { - string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_CantLiveThere"); - MainClass.ScreenReader.Say(warn, true); - } - return; - } - } -} diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPach.cs new file mode 100644 index 0000000..3745452 --- /dev/null +++ b/stardew-access/Patches/CarpenterMenuPach.cs @@ -0,0 +1,195 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class CarpenterMenuPatch + { + internal static CarpenterMenu? carpenterMenu = null; + internal static string carpenterMenuQuery = ""; + internal static bool isSayingBlueprintInfo = false; + internal static string prevBlueprintInfo = ""; + internal static bool isOnFarm = false, isUpgrading = false, isDemolishing = false, isPainting = false, isConstructing = false, isMoving = false, isMagicalConstruction = false; + + internal static void DrawPatch( + CarpenterMenu __instance, bool ___onFarm, List ___ingredients, int ___price, + List ___blueprints, int ___currentBlueprintIndex, bool ___upgrading, bool ___demolishing, bool ___moving, + bool ___painting, bool ___magicalConstruction) + { + try + { + isOnFarm = ___onFarm; + carpenterMenu = __instance; + isMagicalConstruction = ___magicalConstruction; + if (!___onFarm) + { + isUpgrading = false; + isDemolishing = false; + isPainting = false; + isMoving = false; + isConstructing = false; + + #region The blueprint menu + BluePrint currentBluprint = __instance.CurrentBlueprint; + if (currentBluprint == null) + return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + string ingredients = ""; + string name = currentBluprint.displayName; + string upgradeName = currentBluprint.nameOfBuildingToUpgrade; + string description = currentBluprint.description; + string price = $"{___price}g"; + string blueprintInfo; + int width = currentBluprint.tilesWidth; + int height = currentBluprint.tilesHeight; + + #region Get ingredients + for (int i = 0; i < ___ingredients.Count; i++) + { + string itemName = ___ingredients[i].DisplayName; + int itemStack = ___ingredients[i].Stack; + string itemQuality = ""; + + int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; + if (qualityValue == 1) + { + itemQuality = "Silver quality"; + } + else if (qualityValue == 2 || qualityValue == 3) + { + itemQuality = "Gold quality"; + } + else if (qualityValue >= 4) + { + itemQuality = "Iridium quality"; + } + + ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; + } + #endregion + + blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; + + if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo) + { + SayBlueprintInfo(blueprintInfo); + } + else if (prevBlueprintInfo != blueprintInfo) + { + prevBlueprintInfo = blueprintInfo; + SayBlueprintInfo(blueprintInfo); + } + else + { + if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + { + string toSpeak = "Previous Blueprint"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + { + string toSpeak = "Next Blueprint"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) + { + string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) + { + string toSpeak = "Move Building"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) + { + string toSpeak = "Paint Building"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) + { + string toSpeak = "Cancel Button"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + #endregion + } + else + { + if (___demolishing) + isDemolishing = true; + else if (___upgrading) + isUpgrading = true; + else if (___painting) + isPainting = true; + else if (___moving) + isMoving = true; + else + isConstructing = true; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static async void SayBlueprintInfo(string info) + { + isSayingBlueprintInfo = true; + MainClass.ScreenReader.Say(info, true); + await Task.Delay(300); + isSayingBlueprintInfo = false; + } + + + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 1a3992a..ae98f9d 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -63,19 +63,24 @@ namespace stardew_access.Patches } else if (menu is CarpenterMenu) { - BuildingNAnimalMenuPatches.carpenterMenuQuery = ""; - BuildingNAnimalMenuPatches.isUpgrading = false; - BuildingNAnimalMenuPatches.isDemolishing = false; - BuildingNAnimalMenuPatches.isPainting = false; - BuildingNAnimalMenuPatches.isMoving = false; - BuildingNAnimalMenuPatches.isConstructing = false; - BuildingNAnimalMenuPatches.carpenterMenu = null; + CarpenterMenuPatch.carpenterMenuQuery = ""; + CarpenterMenuPatch.isUpgrading = false; + CarpenterMenuPatch.isDemolishing = false; + CarpenterMenuPatch.isPainting = false; + CarpenterMenuPatch.isMoving = false; + CarpenterMenuPatch.isConstructing = false; + CarpenterMenuPatch.carpenterMenu = null; } else if (menu is PurchaseAnimalsMenu) { - BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = ""; - BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true; - BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null; + PurchaseAnimalsMenuPatch.purchaseAnimalMenuQuery = ""; + PurchaseAnimalsMenuPatch.firstTimeInNamingMenu = true; + PurchaseAnimalsMenuPatch.purchaseAnimalsMenu = null; + } + else if (menu is AnimalQueryMenu) + { + AnimalQueryMenuPatch.animalQueryMenuQuery = ""; + AnimalQueryMenuPatch.animalQueryMenu = null; } else if (menu is DialogueBox) { diff --git a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs new file mode 100644 index 0000000..0828c06 --- /dev/null +++ b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs @@ -0,0 +1,101 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class PurchaseAnimalsMenuPatch + { + internal static FarmAnimal? animalBeingPurchased = null; + internal static bool isOnFarm = false; + internal static string purchaseAnimalMenuQuery = ""; + internal static PurchaseAnimalsMenu? purchaseAnimalsMenu; + internal static bool firstTimeInNamingMenu = true; + + internal static void DrawPatch(PurchaseAnimalsMenu __instance, bool ___onFarm, bool ___namingAnimal, TextBox ___textBox, FarmAnimal ___animalBeingPurchased) + { + try + { + if (TextBoxPatch.isAnyTextBoxActive) return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + purchaseAnimalsMenu = __instance; + isOnFarm = ___onFarm; + animalBeingPurchased = ___animalBeingPurchased; + + if (___onFarm && ___namingAnimal) + { + string toSpeak = ""; + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Cancel Button"; + } + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + { + toSpeak = "OK Button"; + } + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + { + toSpeak = "Random Name Button"; + } + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + { + toSpeak = "Name Text Box"; + // string? value = ___textBox.Text; + // if (value != "" && value != null && value != "null") + // toSpeak = $"{toSpeak}, Value: {value}"; + } + + if (purchaseAnimalMenuQuery != toSpeak) + { + purchaseAnimalMenuQuery = toSpeak; + + if (firstTimeInNamingMenu) + { + toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; + firstTimeInNamingMenu = false; + } + + MainClass.ScreenReader.Say(toSpeak, true); + } + } + else if (___onFarm && !___namingAnimal) + { + firstTimeInNamingMenu = true; + } + else if (!___onFarm && !___namingAnimal) + { + firstTimeInNamingMenu = true; + if (__instance.hovered != null) + { + string toSpeak = ""; + if (((StardewValley.Object)__instance.hovered.item).Type != null) + { + toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; + } + else + { + string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); + int price = __instance.hovered.item.salePrice(); + string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); + + toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; + } + + if (purchaseAnimalMenuQuery != toSpeak) + { + purchaseAnimalMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + + } +} From 4a39bf94ead74f66229d737855bf0d680bfadb37 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 13:49:50 +0530 Subject: [PATCH 02/40] Moved shop menu patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 107 --------------- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ShopMenuPatch.cs | 123 ++++++++++++++++++ 4 files changed, 125 insertions(+), 109 deletions(-) create mode 100644 stardew-access/Patches/ShopMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 72475db..1948818 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -100,7 +100,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ShopMenu), nameof(ShopMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ShopMenuPatch)) + postfix: new HarmonyMethod(typeof(ShopMenuPatch), nameof(ShopMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index f5d0ea2..bdca60c 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -15,7 +15,6 @@ namespace stardew_access.Patches internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; - internal static string shopMenuQueryKey = ""; internal static string socialPageQuery = ""; internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; @@ -185,112 +184,6 @@ namespace stardew_access.Patches } } - internal static void ShopMenuPatch(ShopMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) - { - __instance.forSaleButtons[0].snapMouseCursorToCenter(); - __instance.setCurrentlySnappedComponentTo(__instance.forSaleButtons[0].myID); - } - - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) - { - string toSpeak = "Up Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) - { - string toSpeak = "Down Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) - { - shopMenuQueryKey = ""; - return; - } - #endregion - - #region Narrate hovered selling item - if (__instance.hoveredItem != null) - { - string name = __instance.hoveredItem.DisplayName; - string price = $"Buy Price: {__instance.hoverPrice} g"; - string description = __instance.hoveredItem.getDescription(); - string requirements = ""; - - #region Narrate required items for item - int itemIndex = -1, itemAmount = 5; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) - itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) - itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; - - if (itemIndex != -1) - { - string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; - - if (itemAmount != -1) - requirements = $"Required: {itemAmount} {itemName}"; - else - requirements = $"Required: {itemName}"; - } - #endregion - - string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void GameMenuPatch(GameMenu __instance) { try diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index ae98f9d..67c91a1 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -51,7 +51,7 @@ namespace stardew_access.Patches } else if (menu is ShopMenu) { - GameMenuPatches.shopMenuQueryKey = ""; + ShopMenuPatch.Cleanup(); } else if (menu is ItemGrabMenu) { diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs new file mode 100644 index 0000000..4f565a9 --- /dev/null +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -0,0 +1,123 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ShopMenuPatch + { + internal static string shopMenuQueryKey = ""; + internal static string hoveredItemQueryKey = ""; + + internal static void DrawPatch(ShopMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) + { + __instance.forSaleButtons[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.forSaleButtons[0].myID); + } + + #region Narrate buttons in the menu + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) + { + string toSpeak = "Up Arrow Button"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) + { + string toSpeak = "Down Arrow Button"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) + { + shopMenuQueryKey = ""; + return; + } + #endregion + + #region Narrate hovered selling item + if (__instance.hoveredItem != null) + { + string name = __instance.hoveredItem.DisplayName; + string price = $"Buy Price: {__instance.hoverPrice} g"; + string description = __instance.hoveredItem.getDescription(); + string requirements = ""; + + #region Narrate required items for item + int itemIndex = -1, itemAmount = 5; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) + itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) + itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; + + if (itemIndex != -1) + { + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + requirements = $"Required: {itemAmount} {itemName}"; + else + requirements = $"Required: {itemName}"; + } + #endregion + + string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + shopMenuQueryKey = ""; + hoveredItemQueryKey = ""; + } + } +} From 7d505d2dd74f7a3f5c36fb42e142f8655839475f Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:10:28 +0530 Subject: [PATCH 03/40] Moved item grab menu patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 271 +----------------- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ItemGrabMenuPatch.cs | 266 +++++++++++++++++ 4 files changed, 273 insertions(+), 268 deletions(-) create mode 100644 stardew-access/Patches/ItemGrabMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 1948818..ef00a10 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -90,7 +90,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ItemGrabMenu), nameof(ItemGrabMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ItemGrabMenuPatch)) + postfix: new HarmonyMethod(typeof(ItemGrabMenuPatch), nameof(ItemGrabMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index bdca60c..e84f888 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -10,7 +10,6 @@ namespace stardew_access.Patches internal static string hoveredItemQueryKey = ""; internal static string geodeMenuQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string itemGrabMenuQueryKey = ""; internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; @@ -201,6 +200,7 @@ namespace stardew_access.Patches string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab"; if (gameMenuQueryKey != toSpeak) { + MainClass.DebugLog("here"); gameMenuQueryKey = toSpeak; MainClass.ScreenReader.Say(toSpeak, true); } @@ -298,267 +298,6 @@ namespace stardew_access.Patches } } - internal static void ItemGrabMenuPatch(ItemGrabMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) - { - __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); - __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); - } - - #region Narrate buttons in the menu - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - gameMenuQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) - { - string toSpeak = "Add to existing stacks button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) - { - string toSpeak = "Special Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) - { - - string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - // FIXME - /*if (__instance.discreteColorPickerCC.Count > 0) { - for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) - { - if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) - { - MainClass.monitor.Log(i.ToString(), LogLevel.Debug); - string toSpeak = getChestColorName(i); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - ScreenReader.say(toSpeak, true); - Game1.playSound("sa_drop_item"); - } - return; - } - } - }*/ - #endregion - - #region Narrate the last shipped item if in the shipping bin - if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) - { - Item lastShippedItem = Game1.getFarm().lastItemShipped; - string name = lastShippedItem.DisplayName; - int count = lastShippedItem.Stack; - - string toSpeak = $"Last Shipped: {count} {name}"; - - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - itemGrabMenuQueryKey = ""; - return; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - itemGrabMenuQueryKey = ""; - return; - } - - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - // TODO Add color names - private static string getChestColorName(int i) - { - string toReturn = ""; - switch (i) - { - case 0: - toReturn = "Default chest color"; - break; - case 1: - toReturn = "Default chest color"; - break; - case 2: - toReturn = "Default chest color"; - break; - case 3: - toReturn = "Default chest color"; - break; - case 4: - toReturn = "Default chest color"; - break; - case 5: - toReturn = "Default chest color"; - break; - case 6: - toReturn = "Default chest color"; - break; - case 7: - toReturn = "Default chest color"; - break; - case 8: - toReturn = "Default chest color"; - break; - case 9: - toReturn = "Default chest color"; - break; - case 10: - toReturn = "Default chest color"; - break; - case 11: - toReturn = "Default chest color"; - break; - case 12: - toReturn = "Default chest color"; - break; - case 13: - toReturn = "Default chest color"; - break; - case 14: - toReturn = "Default chest color"; - break; - case 15: - toReturn = "Default chest color"; - break; - case 16: - toReturn = "Default chest color"; - break; - case 17: - toReturn = "Default chest color"; - break; - case 18: - toReturn = "Default chest color"; - break; - case 19: - toReturn = "Default chest color"; - break; - case 20: - toReturn = "Default chest color"; - break; - } - return toReturn; - } internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) { @@ -838,9 +577,9 @@ namespace stardew_access.Patches if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) { string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) + if (inventoryPageQueryKey != toSpeak) { - itemGrabMenuQueryKey = toSpeak; + inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; MainClass.ScreenReader.Say(toSpeak, true); @@ -851,9 +590,9 @@ namespace stardew_access.Patches { string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) + if (inventoryPageQueryKey != toSpeak) { - itemGrabMenuQueryKey = toSpeak; + inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; MainClass.ScreenReader.Say(toSpeak, true); diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 67c91a1..9866068 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -55,7 +55,7 @@ namespace stardew_access.Patches } else if (menu is ItemGrabMenu) { - GameMenuPatches.itemGrabMenuQueryKey = ""; + ItemGrabMenuPatch.Cleanup(); } else if (menu is GeodeMenu) { diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs new file mode 100644 index 0000000..664d810 --- /dev/null +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -0,0 +1,266 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ItemGrabMenuPatch + { + internal static string itemGrabMenuQueryKey = ""; + internal static string hoveredItemQueryKey = ""; + + internal static void DrawPatch(ItemGrabMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) + { + __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); + __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); + } + + #region Narrate buttons in the menu + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Ok Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash Can"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + string toSpeak = "Organize Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) + { + string toSpeak = "Add to existing stacks button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) + { + string toSpeak = "Special Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) + { + + string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + + string toSpeak = "Community Center Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + + // FIXME + /*if (__instance.discreteColorPickerCC.Count > 0) { + for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) + { + if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) + { + MainClass.monitor.Log(i.ToString(), LogLevel.Debug); + string toSpeak = getChestColorName(i); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + ScreenReader.say(toSpeak, true); + Game1.playSound("sa_drop_item"); + } + return; + } + } + }*/ + #endregion + + #region Narrate the last shipped item if in the shipping bin + if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) + { + Item lastShippedItem = Game1.getFarm().lastItemShipped; + string name = lastShippedItem.DisplayName; + int count = lastShippedItem.Stack; + + string toSpeak = $"Last Shipped: {count} {name}"; + + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + { + itemGrabMenuQueryKey = ""; + return; + } + + if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) + { + itemGrabMenuQueryKey = ""; + return; + } + + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + // TODO Add color names + private static string getChestColorName(int i) + { + string toReturn = ""; + switch (i) + { + case 0: + toReturn = "Default chest color"; + break; + case 1: + toReturn = "Default chest color"; + break; + case 2: + toReturn = "Default chest color"; + break; + case 3: + toReturn = "Default chest color"; + break; + case 4: + toReturn = "Default chest color"; + break; + case 5: + toReturn = "Default chest color"; + break; + case 6: + toReturn = "Default chest color"; + break; + case 7: + toReturn = "Default chest color"; + break; + case 8: + toReturn = "Default chest color"; + break; + case 9: + toReturn = "Default chest color"; + break; + case 10: + toReturn = "Default chest color"; + break; + case 11: + toReturn = "Default chest color"; + break; + case 12: + toReturn = "Default chest color"; + break; + case 13: + toReturn = "Default chest color"; + break; + case 14: + toReturn = "Default chest color"; + break; + case 15: + toReturn = "Default chest color"; + break; + case 16: + toReturn = "Default chest color"; + break; + case 17: + toReturn = "Default chest color"; + break; + case 18: + toReturn = "Default chest color"; + break; + case 19: + toReturn = "Default chest color"; + break; + case 20: + toReturn = "Default chest color"; + break; + } + return toReturn; + } + + internal static void Cleanup() { + hoveredItemQueryKey = ""; + itemGrabMenuQueryKey = ""; + } + } +} From 6730fcceff5a6b2d44608a75a8fc891e7ceac4b3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:29:51 +0530 Subject: [PATCH 04/40] Moved geode menu patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 86 ---------------- stardew-access/Patches/GeodeMenuPatch.cs | 99 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 101 insertions(+), 88 deletions(-) create mode 100644 stardew-access/Patches/GeodeMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index ef00a10..d0fe365 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -95,7 +95,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(GeodeMenu), nameof(GeodeMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.GeodeMenuPatch)) + postfix: new HarmonyMethod(typeof(GeodeMenuPatch), nameof(GeodeMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index e84f888..d7c3891 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -8,7 +8,6 @@ namespace stardew_access.Patches internal class GameMenuPatches { internal static string hoveredItemQueryKey = ""; - internal static string geodeMenuQueryKey = ""; internal static string gameMenuQueryKey = ""; internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; @@ -214,91 +213,6 @@ namespace stardew_access.Patches } } - internal static void GeodeMenuPatch(GeodeMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - #region Narrate the treasure recieved on breaking the geode - if (__instance.geodeTreasure != null) - { - string name = __instance.geodeTreasure.DisplayName; - int stack = __instance.geodeTreasure.Stack; - - string toSpeak = $"Recieved {stack} {name}"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered buttons in the menu - if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) - { - string toSpeak = "Place geode here"; - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop item here"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash can"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok button"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - geodeMenuQueryKey = ""; - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) { try diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs new file mode 100644 index 0000000..e08beec --- /dev/null +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -0,0 +1,99 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class GeodeMenuPatch + { + internal static string geodeMenuQueryKey = ""; + + internal static void DrawPatch(GeodeMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + #region Narrate the treasure recieved on breaking the geode + if (__instance.geodeTreasure != null) + { + string name = __instance.geodeTreasure.DisplayName; + int stack = __instance.geodeTreasure.Stack; + + string toSpeak = $"Recieved {stack} {name}"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered buttons in the menu + if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) + { + string toSpeak = "Place geode here"; + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop item here"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash can"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Ok button"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + geodeMenuQueryKey = ""; + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + geodeMenuQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 9866068..b1be281 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -59,7 +59,7 @@ namespace stardew_access.Patches } else if (menu is GeodeMenu) { - GameMenuPatches.geodeMenuQueryKey = ""; + GeodeMenuPatch.Cleanup(); } else if (menu is CarpenterMenu) { From 2a5baa6770f8e0f980d5cf2e8d60c23573291ceb Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:33:03 +0530 Subject: [PATCH 05/40] Moved collections page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 15 ------------- .../GameMenuPatches/CollectionsPagePatch.cs | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index d0fe365..509109a 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -110,7 +110,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CollectionsPage), nameof(CollectionsPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.CollectionsPagePatch)) + postfix: new HarmonyMethod(typeof(CollectionsPagePatch), nameof(CollectionsPagePatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index d7c3891..0f7b6fb 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -18,21 +18,6 @@ namespace stardew_access.Patches internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; - internal static void CollectionsPagePatch(CollectionsPage __instance) - { - try - { - int x = Game1.getMousePosition().X, y = Game1.getMousePosition().Y; - if (__instance.letterviewerSubMenu != null) - { - DialoguePatches.NarrateLetterContent(__instance.letterviewerSubMenu); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } internal static void SocialPagePatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) { diff --git a/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs new file mode 100644 index 0000000..a708930 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs @@ -0,0 +1,21 @@ +namespace stardew_access.Patches +{ + internal class CollectionsPagePatch + { + internal static void DrawPatch(StardewValley.Menus.CollectionsPage __instance) + { + try + { + int x = StardewValley.Game1.getMousePosition().X, y = StardewValley.Game1.getMousePosition().Y; + if (__instance.letterviewerSubMenu != null) + { + DialoguePatches.NarrateLetterContent(__instance.letterviewerSubMenu); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 9d7c2c36ec18b1e2727147acb7fd81869221671a Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:37:21 +0530 Subject: [PATCH 06/40] Moved social page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 150 ---------------- .../GameMenuPatches/SocialPagePatch.cs | 163 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 165 insertions(+), 152 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 509109a..f2db5c8 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -105,7 +105,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(SocialPage), nameof(SocialPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.SocialPagePatch)) + postfix: new HarmonyMethod(typeof(SocialPagePatch), nameof(SocialPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 0f7b6fb..2afb84b 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -13,160 +13,10 @@ namespace stardew_access.Patches internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; - internal static string socialPageQuery = ""; internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; - - internal static void SocialPagePatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - for (int i = ___slotPosition; i < ___slotPosition + 5; i++) - { - if (i < ___sprites.Count) - { - if (__instance.names[i] is string) - { - #region For NPCs - if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string name = $"{__instance.names[i] as string}"; - int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); - bool datable = SocialPage.isDatable(name); - Friendship friendship = __instance.getFriendship(name); - int giftsThisWeek = friendship.GiftsThisWeek; - bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); - bool spouse = friendship.IsMarried(); - bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); - ___kidsNames.Add("Robin"); - ___kidsNames.Add("Pierre"); - ___kidsNames.Add("Caroline"); - ___kidsNames.Add("Jodi"); - ___kidsNames.Add("Kent"); - ___kidsNames.Add("George"); - ___kidsNames.Add("Evelyn"); - ___kidsNames.Add("Demetrius"); - - - - string toSpeak = $"{name}"; - - if (!hasTalked) - { - toSpeak = $"{toSpeak}, not talked yet"; - } - - - if (datable | housemate) - { - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (housemate) - { - text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); - } - else if (spouse) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (__instance.isMarriedToAnyone(name)) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (__instance.getFriendship(name).IsDivorced()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{toSpeak}, {text2}"; - } - if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) - { - toSpeak = $"{toSpeak}, married"; - } - if (spouse) - { - toSpeak = $"{toSpeak}, spouse"; - } - else if (friendship.IsDating()) - { - toSpeak = $"{toSpeak}, dating"; - } - - toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; - - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - } - else if (__instance.names[i] is long) - { - #region For Farmers - - long farmerID = (long)__instance.names[i]; - Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); - if (farmer != null) - { - int gender = (!farmer.IsMale) ? 1 : 0; - ClickableTextureComponent clickableTextureComponent = ___sprites[i]; - if (clickableTextureComponent.containsPoint(x, y)) - { - Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); - bool spouse = friendship.IsMarried(); - string toSpeak = ""; - - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (spouse) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (farmer.isMarried() && !farmer.hasRoommate()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (friendship.IsDivorced()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{farmer.displayName}, {text2}"; - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - - #endregion - } - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void GameMenuPatch(GameMenu __instance) { try diff --git a/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs new file mode 100644 index 0000000..3c03245 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs @@ -0,0 +1,163 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class SocialPagePatch + { + internal static string socialPageQuery = ""; + + internal static void DrawPatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + for (int i = ___slotPosition; i < ___slotPosition + 5; i++) + { + if (i < ___sprites.Count) + { + if (__instance.names[i] is string) + { + #region For NPCs + if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string name = $"{__instance.names[i] as string}"; + int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); + bool datable = SocialPage.isDatable(name); + Friendship friendship = __instance.getFriendship(name); + int giftsThisWeek = friendship.GiftsThisWeek; + bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); + bool spouse = friendship.IsMarried(); + bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); + ___kidsNames.Add("Robin"); + ___kidsNames.Add("Pierre"); + ___kidsNames.Add("Caroline"); + ___kidsNames.Add("Jodi"); + ___kidsNames.Add("Kent"); + ___kidsNames.Add("George"); + ___kidsNames.Add("Evelyn"); + ___kidsNames.Add("Demetrius"); + + + + string toSpeak = $"{name}"; + + if (!hasTalked) + { + toSpeak = $"{toSpeak}, not talked yet"; + } + + + if (datable | housemate) + { + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (housemate) + { + text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); + } + else if (spouse) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (__instance.isMarriedToAnyone(name)) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (__instance.getFriendship(name).IsDivorced()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{toSpeak}, {text2}"; + } + if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) + { + toSpeak = $"{toSpeak}, married"; + } + if (spouse) + { + toSpeak = $"{toSpeak}, spouse"; + } + else if (friendship.IsDating()) + { + toSpeak = $"{toSpeak}, dating"; + } + + toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; + + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + } + else if (__instance.names[i] is long) + { + #region For Farmers + + long farmerID = (long)__instance.names[i]; + Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); + if (farmer != null) + { + int gender = (!farmer.IsMale) ? 1 : 0; + ClickableTextureComponent clickableTextureComponent = ___sprites[i]; + if (clickableTextureComponent.containsPoint(x, y)) + { + Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); + bool spouse = friendship.IsMarried(); + string toSpeak = ""; + + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (spouse) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (farmer.isMarried() && !farmer.hasRoommate()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (friendship.IsDivorced()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{farmer.displayName}, {text2}"; + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + + #endregion + } + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + socialPageQuery = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index b1be281..e925565 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -38,7 +38,7 @@ namespace stardew_access.Patches GameMenuPatches.inventoryPageQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; GameMenuPatches.optionsPageQueryKey = ""; - GameMenuPatches.socialPageQuery = ""; + SocialPagePatch.Cleanup(); GameMenuPatches.currentSelectedCraftingRecipe = -1; GameMenuPatches.isSelectingRecipe = false; } From f851806947a303d006619384630748a74ce0ff8c Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:43:19 +0530 Subject: [PATCH 07/40] Moved crafting page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 234 ---------------- .../GameMenuPatches/CraftingPagePatch.cs | 250 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 4 +- 4 files changed, 252 insertions(+), 238 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index f2db5c8..25f5091 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -80,7 +80,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CraftingPage), nameof(CraftingPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.CraftingPagePatch)) + postfix: new HarmonyMethod(typeof(CraftingPagePatch), nameof(CraftingPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 2afb84b..027802d 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -9,13 +9,10 @@ namespace stardew_access.Patches { internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; internal static string profilePageQuery = ""; - internal static int currentSelectedCraftingRecipe = -1; - internal static bool isSelectingRecipe = false; internal static void GameMenuPatch(GameMenu __instance) { @@ -48,237 +45,6 @@ namespace stardew_access.Patches } } - internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - // snap to first inventory slot - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = -1; - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) - { - // snap to first crafting recipe - __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); - __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = 0; - } - else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) - { - isSelectingRecipe = true; - CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); - Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); - } - - #region Narrate buttons in the menu - if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) - { - string toSpeak = "Previous Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) - { - string toSpeak = "Next Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - #endregion - - #region Narrate hovered recipe - if (___hoverRecipe != null) - { - string name = ___hoverRecipe.DisplayName; - int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; - string description = ""; - string ingredients = ""; - string buffs = ""; - string craftable = ""; - - description = $"Description:\n{___hoverRecipe.description}"; - craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; - - #region Crafting ingredients - ingredients = "Ingredients:\n"; - for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) - { - int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; - int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; - string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); - - ingredients += $" ,{recipeCount} {recipeName}"; - } - #endregion - - #region Health & stamina and buff items (effects like +1 walking speed) - Item producesItem = ___hoverRecipe.createItem(); - if (producesItem is StardewValley.Object producesItemObject) - { - if (producesItemObject.Edibility != -300) - { - int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); - buffs += $"{stamina_recovery} Energy"; - if (stamina_recovery >= 0) - { - int health_recovery = producesItemObject.healthRecoveredOnConsumption(); - buffs += $"\n{health_recovery} Health"; - } - } - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; - string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) - ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) - : null; - - if (buffIconsToDisplay != null) - { - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - buffs += $"{buffName}\n"; - } - catch (Exception) { } - } - - buffs = $"Buffs and boosts:\n {buffs}"; - } - } - #endregion - - - string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; - - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - else - { - var isRecipeInFocus = false; - foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) - { - if (item.Key.containsPoint(x, y)) - { - isRecipeInFocus = true; - break; - } - } - - if (isRecipeInFocus) - { - string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; - - if (craftingPageQueryKey != query) - { - craftingPageQueryKey = query; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say("unknown recipe", true); - } - return; - } - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - { - gameMenuQueryKey = ""; - craftingPageQueryKey = ""; - return; - } - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static void CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) - { - currentSelectedCraftingRecipe++; - if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count) - currentSelectedCraftingRecipe = 0; - - __instance.setCurrentlySnappedComponentTo(pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.myID); - pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter(); - - // Skip if recipe is not unlocked/unknown - if (pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.hoverText.Equals("ghosted")) - CycleThroughRecipies(pagesOfCraftingRecipes, ___currentCraftingPage, __instance); - } - - // This method is used to get the inventory items to check if the player has enough ingredients for a recipe - // Taken from CraftingPage.cs -> 169 line - internal static IList? getContainerContents(List materialContainers) - { - if (materialContainers == null) - { - return null; - } - List items = new List(); - for (int i = 0; i < materialContainers.Count; i++) - { - items.AddRange(materialContainers[i].items); - } - return items; - } - internal static void InventoryPagePatch(InventoryPage __instance) { try diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs new file mode 100644 index 0000000..51db2e5 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -0,0 +1,250 @@ +using StardewValley; +using StardewValley.Menus; +using StardewValley.Objects; + +namespace stardew_access.Patches +{ + internal class CraftingPagePatch + { + internal static string hoveredItemQueryKey = ""; + internal static string craftingPageQueryKey = ""; + internal static int currentSelectedCraftingRecipe = -1; + internal static bool isSelectingRecipe = false; + + internal static void DrawPatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + // snap to first inventory slot + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = -1; + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) + { + // snap to first crafting recipe + __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); + __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = 0; + } + else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) + { + isSelectingRecipe = true; + CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); + } + + #region Narrate buttons in the menu + if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) + { + string toSpeak = "Previous Recipe List"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) + { + string toSpeak = "Next Recipe List"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash Can"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + #endregion + + #region Narrate hovered recipe + if (___hoverRecipe != null) + { + string name = ___hoverRecipe.DisplayName; + int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; + string description = ""; + string ingredients = ""; + string buffs = ""; + string craftable = ""; + + description = $"Description:\n{___hoverRecipe.description}"; + craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; + + #region Crafting ingredients + ingredients = "Ingredients:\n"; + for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) + { + int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; + int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; + string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); + + ingredients += $" ,{recipeCount} {recipeName}"; + } + #endregion + + #region Health & stamina and buff items (effects like +1 walking speed) + Item producesItem = ___hoverRecipe.createItem(); + if (producesItem is StardewValley.Object producesItemObject) + { + if (producesItemObject.Edibility != -300) + { + int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); + buffs += $"{stamina_recovery} Energy"; + if (stamina_recovery >= 0) + { + int health_recovery = producesItemObject.healthRecoveredOnConsumption(); + buffs += $"\n{health_recovery} Health"; + } + } + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; + string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) + ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay != null) + { + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + buffs += $"{buffName}\n"; + } + catch (Exception) { } + } + + buffs = $"Buffs and boosts:\n {buffs}"; + } + } + #endregion + + + string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; + + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + else + { + var isRecipeInFocus = false; + foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) + { + if (item.Key.containsPoint(x, y)) + { + isRecipeInFocus = true; + break; + } + } + + if (isRecipeInFocus) + { + string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; + + if (craftingPageQueryKey != query) + { + craftingPageQueryKey = query; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say("unknown recipe", true); + } + return; + } + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + { + craftingPageQueryKey = ""; + return; + } + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) + { + currentSelectedCraftingRecipe++; + if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count) + currentSelectedCraftingRecipe = 0; + + __instance.setCurrentlySnappedComponentTo(pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.myID); + pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter(); + + // Skip if recipe is not unlocked/unknown + if (pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.hoverText.Equals("ghosted")) + CycleThroughRecipies(pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + } + + // This method is used to get the inventory items to check if the player has enough ingredients for a recipe + // Taken from CraftingPage.cs -> 169 line + internal static IList? getContainerContents(List materialContainers) + { + if (materialContainers == null) + { + return null; + } + List items = new List(); + for (int i = 0; i < materialContainers.Count; i++) + { + items.AddRange(materialContainers[i].items); + } + return items; + } + + internal static void Cleanup() + { + hoveredItemQueryKey = ""; + craftingPageQueryKey = ""; + currentSelectedCraftingRecipe = -1; + isSelectingRecipe = false; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index e925565..7a5efea 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -34,13 +34,11 @@ namespace stardew_access.Patches else if (menu is GameMenu) { GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.craftingPageQueryKey = ""; GameMenuPatches.inventoryPageQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; GameMenuPatches.optionsPageQueryKey = ""; SocialPagePatch.Cleanup(); - GameMenuPatches.currentSelectedCraftingRecipe = -1; - GameMenuPatches.isSelectingRecipe = false; + CraftingPagePatch.Cleanup(); } else if (menu is JunimoNoteMenu) { From 7c1e600790082154c505cb7191928ddf791fdff7 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:33:14 +0530 Subject: [PATCH 08/40] Moved inventory page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 207 ----------------- .../GameMenuPatches/InventoryPagePatch.cs | 217 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 219 insertions(+), 209 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 25f5091..6cc7464 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -85,7 +85,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(InventoryPage), nameof(InventoryPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.InventoryPagePatch)) + postfix: new HarmonyMethod(typeof(InventoryPagePatch), nameof(InventoryPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 027802d..84c7300 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -9,7 +9,6 @@ namespace stardew_access.Patches { internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; internal static string profilePageQuery = ""; @@ -45,212 +44,6 @@ namespace stardew_access.Patches } } - internal static void InventoryPagePatch(InventoryPage __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Inventory Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - - #region Narrate equipment slots - for (int i = 0; i < __instance.equipmentIcons.Count; i++) - { - if (__instance.equipmentIcons[i].containsPoint(x, y)) - { - string toSpeak = ""; - - #region Get name and description of the item - switch (__instance.equipmentIcons[i].name) - { - case "Hat": - { - if (Game1.player.hat.Value != null) - { - toSpeak = $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}"; - } - else - { - toSpeak = "Hat slot"; - } - } - break; - case "Left Ring": - { - if (Game1.player.leftRing.Value != null) - { - toSpeak = $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}"; - } - else - { - toSpeak = "Left Ring slot"; - } - } - break; - case "Right Ring": - { - if (Game1.player.rightRing.Value != null) - { - toSpeak = $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}"; - } - else - { - toSpeak = "Right ring slot"; - } - } - break; - case "Boots": - { - if (Game1.player.boots.Value != null) - { - toSpeak = $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}"; - } - else - { - toSpeak = "Boots slot"; - } - } - break; - case "Shirt": - { - if (Game1.player.shirtItem.Value != null) - { - toSpeak = $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}"; - } - else - { - toSpeak = "Shirt slot"; - } - } - break; - case "Pants": - { - if (Game1.player.pantsItem.Value != null) - { - toSpeak = $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}"; - } - else - { - toSpeak = "Pants slot"; - } - } - break; - } - #endregion - - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - inventoryPageQueryKey = ""; - } - #endregion - - if (MainClass.Config.MoneyKey.JustPressed()) - { - string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); - string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); - string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); - int festivalScore = Game1.player.festivalScore; - int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; - int qiGems = Game1.player.QiGems; - int qiCoins = Game1.player.clubCoins; - - string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; - - if (festivalScore > 0) - toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; - - if (walnut > 0) - toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; - - if (qiGems > 0) - toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; - - if (qiCoins > 0) - toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } internal static void OptionsPagePatch(OptionsPage __instance) { diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs new file mode 100644 index 0000000..bfc367b --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -0,0 +1,217 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class InventoryPagePatch + { + internal static string inventoryPageQueryKey = ""; + internal static string hoveredItemQueryKey = ""; + + internal static void DrawPatch(InventoryPage __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + #region Narrate buttons in the menu + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + } + + if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + string toSpeak = "Organize Inventory Button"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash Can"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + string toSpeak = "Organize Button"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + + string toSpeak = "Community Center Button"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + #endregion + + #region Narrate equipment slots + for (int i = 0; i < __instance.equipmentIcons.Count; i++) + { + if (__instance.equipmentIcons[i].containsPoint(x, y)) + { + string toSpeak = ""; + + #region Get name and description of the item + switch (__instance.equipmentIcons[i].name) + { + case "Hat": + { + if (Game1.player.hat.Value != null) + { + toSpeak = $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}"; + } + else + { + toSpeak = "Hat slot"; + } + } + break; + case "Left Ring": + { + if (Game1.player.leftRing.Value != null) + { + toSpeak = $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}"; + } + else + { + toSpeak = "Left Ring slot"; + } + } + break; + case "Right Ring": + { + if (Game1.player.rightRing.Value != null) + { + toSpeak = $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}"; + } + else + { + toSpeak = "Right ring slot"; + } + } + break; + case "Boots": + { + if (Game1.player.boots.Value != null) + { + toSpeak = $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}"; + } + else + { + toSpeak = "Boots slot"; + } + } + break; + case "Shirt": + { + if (Game1.player.shirtItem.Value != null) + { + toSpeak = $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}"; + } + else + { + toSpeak = "Shirt slot"; + } + } + break; + case "Pants": + { + if (Game1.player.pantsItem.Value != null) + { + toSpeak = $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}"; + } + else + { + toSpeak = "Pants slot"; + } + } + break; + } + #endregion + + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + { + inventoryPageQueryKey = ""; + } + #endregion + + if (MainClass.Config.MoneyKey.JustPressed()) + { + string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); + string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); + string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); + int festivalScore = Game1.player.festivalScore; + int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; + int qiGems = Game1.player.QiGems; + int qiCoins = Game1.player.clubCoins; + + string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; + + if (festivalScore > 0) + toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; + + if (walnut > 0) + toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; + + if (qiGems > 0) + toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; + + if (qiCoins > 0) + toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; + + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + inventoryPageQueryKey = ""; + hoveredItemQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 7a5efea..5e85c02 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -34,10 +34,10 @@ namespace stardew_access.Patches else if (menu is GameMenu) { GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.inventoryPageQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; GameMenuPatches.optionsPageQueryKey = ""; SocialPagePatch.Cleanup(); + InventoryPagePatch.Cleanup(); CraftingPagePatch.Cleanup(); } else if (menu is JunimoNoteMenu) From 820d714594eed1fc8db04605c734f065802afdd3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:35:58 +0530 Subject: [PATCH 09/40] Moved options page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 54 --------------- .../GameMenuPatches/OptionsPagePatch.cs | 67 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 69 insertions(+), 56 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 6cc7464..885a78a 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -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( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 84c7300..ae93dc8 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -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 diff --git a/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs new file mode 100644 index 0000000..a05d478 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs @@ -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 = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 5e85c02..644f9c0 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -35,7 +35,7 @@ namespace stardew_access.Patches { GameMenuPatches.gameMenuQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; - GameMenuPatches.optionsPageQueryKey = ""; + OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); InventoryPagePatch.Cleanup(); CraftingPagePatch.Cleanup(); From 8d11cc6266a83ef0ad21ab6f4ccf335fa29058d2 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:40:01 +0530 Subject: [PATCH 10/40] Moved exit page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 40 ---------------- .../Patches/GameMenuPatches/ExitPagePatch.cs | 48 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 885a78a..395fe61 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -75,7 +75,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ExitPage), nameof(ExitPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ExitPagePatch)) + postfix: new HarmonyMethod(typeof(ExitPagePatch), nameof(ExitPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index ae93dc8..d12998b 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -4,13 +4,9 @@ using StardewValley.Objects; namespace stardew_access.Patches { - // Menus in the game menu i.e., the menu which opens when we press `e` internal class GameMenuPatches { - internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string exitPageQueryKey = ""; - internal static string profilePageQuery = ""; internal static void GameMenuPatch(GameMenu __instance) { @@ -42,41 +38,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - - internal static void ExitPagePatch(ExitPage __instance) - { - try - { - if (__instance.exitToTitle.visible && - __instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = "Exit to Title Button"; - if (exitPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.exitToDesktop.visible && - __instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = "Exit to Desktop Button"; - if (exitPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } } } diff --git a/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs b/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs new file mode 100644 index 0000000..81431f7 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs @@ -0,0 +1,48 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ExitPagePatch + { + internal static string exitPageQueryKey = ""; + + internal static void DrawPatch(ExitPage __instance) + { + try + { + if (__instance.exitToTitle.visible && + __instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string toSpeak = "Exit to Title Button"; + if (exitPageQueryKey != toSpeak) + { + exitPageQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.exitToDesktop.visible && + __instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string toSpeak = "Exit to Desktop Button"; + if (exitPageQueryKey != toSpeak) + { + exitPageQueryKey = 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() + { + exitPageQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 644f9c0..04e6715 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -34,7 +34,7 @@ namespace stardew_access.Patches else if (menu is GameMenu) { GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.exitPageQueryKey = ""; + ExitPagePatch.Cleanup(); OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); InventoryPagePatch.Cleanup(); From 911c93a555126dedbda5dffc78d14cd59d4467c6 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:45:01 +0530 Subject: [PATCH 11/40] Moved game menu patch --- stardew-access/HarmonyPatches.cs | 2 +- .../GameMenuPatch.cs} | 10 +++++++--- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) rename stardew-access/Patches/{GameMenuPatches.cs => GameMenuPatches/GameMenuPatch.cs} (87%) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 395fe61..a993c81 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -65,7 +65,7 @@ namespace stardew_access #region Game Menu Patches harmony.Patch( original: AccessTools.Method(typeof(GameMenu), nameof(GameMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.GameMenuPatch)) + postfix: new HarmonyMethod(typeof(GameMenuPatch), nameof(GameMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs similarity index 87% rename from stardew-access/Patches/GameMenuPatches.cs rename to stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs index d12998b..f8918bf 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs @@ -1,14 +1,13 @@ using StardewValley; using StardewValley.Menus; -using StardewValley.Objects; namespace stardew_access.Patches { - internal class GameMenuPatches + internal class GameMenuPatch { internal static string gameMenuQueryKey = ""; - internal static void GameMenuPatch(GameMenu __instance) + internal static void DrawPatch(GameMenu __instance) { try { @@ -38,5 +37,10 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } + + internal static void Cleanup() + { + gameMenuQueryKey = ""; + } } } diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 04e6715..3260a80 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -33,7 +33,7 @@ namespace stardew_access.Patches } else if (menu is GameMenu) { - GameMenuPatches.gameMenuQueryKey = ""; + GameMenuPatch.Cleanup(); ExitPagePatch.Cleanup(); OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); From 15380e5b764f763eeed4d1468b049faccc1c97ec Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 20:44:54 +0530 Subject: [PATCH 12/40] Improved game menu patch code - Added active suffix if the hovered tab button matches the current tab --- .../Patches/GameMenuPatches/GameMenuPatch.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs index f8918bf..0255dbb 100644 --- a/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs +++ b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs @@ -11,26 +11,28 @@ namespace stardew_access.Patches { try { - // Continue if only in the Inventory Page or Crafting Page - if (__instance.currentTab != 0 && __instance.currentTab != 4 && __instance.currentTab != 6 && __instance.currentTab != 7) + // Skip if in map page + if (__instance.currentTab == 3) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position for (int i = 0; i < __instance.tabs.Count; i++) { - if (__instance.tabs[i].containsPoint(x, y)) + if (!__instance.tabs[i].containsPoint(x, y)) + continue; + + string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab" + ((i == __instance.currentTab) ? " Active" : ""); + if (gameMenuQueryKey != toSpeak) { - string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab"; - if (gameMenuQueryKey != toSpeak) - { - MainClass.DebugLog("here"); - gameMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; + gameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); } + return; } + + // If not hovering on any tab button + Cleanup(); } catch (Exception e) { From 0fa90e4c74f3d63fe37b32f84eb588295031d885 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 20:45:35 +0530 Subject: [PATCH 13/40] Improved and organised code in InventoryPagePatch.cs --- .../GameMenuPatches/InventoryPagePatch.cs | 291 +++++++----------- stardew-access/Patches/IClickableMenuPatch.cs | 3 +- stardew-access/Patches/InventoryUtils.cs | 6 + 3 files changed, 122 insertions(+), 178 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs index bfc367b..8dc26b3 100644 --- a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -14,202 +14,141 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + if (narrateHoveredButton(__instance, x, y)) { - string toSpeak = "Drop Item"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } + return; } - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + if (narrateHoveredEquipmentSlot(__instance, x, y)) { - string toSpeak = "Organize Inventory Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } + return; } - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - - #region Narrate equipment slots - for (int i = 0; i < __instance.equipmentIcons.Count; i++) - { - if (__instance.equipmentIcons[i].containsPoint(x, y)) - { - string toSpeak = ""; - - #region Get name and description of the item - switch (__instance.equipmentIcons[i].name) - { - case "Hat": - { - if (Game1.player.hat.Value != null) - { - toSpeak = $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}"; - } - else - { - toSpeak = "Hat slot"; - } - } - break; - case "Left Ring": - { - if (Game1.player.leftRing.Value != null) - { - toSpeak = $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}"; - } - else - { - toSpeak = "Left Ring slot"; - } - } - break; - case "Right Ring": - { - if (Game1.player.rightRing.Value != null) - { - toSpeak = $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}"; - } - else - { - toSpeak = "Right ring slot"; - } - } - break; - case "Boots": - { - if (Game1.player.boots.Value != null) - { - toSpeak = $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}"; - } - else - { - toSpeak = "Boots slot"; - } - } - break; - case "Shirt": - { - if (Game1.player.shirtItem.Value != null) - { - toSpeak = $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}"; - } - else - { - toSpeak = "Shirt slot"; - } - } - break; - case "Pants": - { - if (Game1.player.pantsItem.Value != null) - { - toSpeak = $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}"; - } - else - { - toSpeak = "Pants slot"; - } - } - break; - } - #endregion - - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { inventoryPageQueryKey = ""; + return; } - #endregion - if (MainClass.Config.MoneyKey.JustPressed()) - { - string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); - string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); - string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); - int festivalScore = Game1.player.festivalScore; - int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; - int qiGems = Game1.player.QiGems; - int qiCoins = Game1.player.clubCoins; + handleKeyBinds(); - string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; - - if (festivalScore > 0) - toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; - - if (walnut > 0) - toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; - - if (qiGems > 0) - toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; - - if (qiCoins > 0) - toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; - - MainClass.ScreenReader.Say(toSpeak, true); - } + // If no slot or button is hovered + Cleanup(); } catch (Exception e) { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + MainClass.ErrorLog($"An error occured in InventoryPagePatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}"); } } + private static void handleKeyBinds() + { + if (!MainClass.Config.MoneyKey.JustPressed()) + return; + + string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); + string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); + string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); + int festivalScore = Game1.player.festivalScore; + int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; + int qiGems = Game1.player.QiGems; + int qiCoins = Game1.player.clubCoins; + + string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; + + if (festivalScore > 0) + toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; + + if (walnut > 0) + toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; + + if (qiGems > 0) + toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; + + if (qiCoins > 0) + toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; + + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static bool narrateHoveredButton(InventoryPage __instance, int x, int y) + { + string? toSpeak = null; + bool isDropItemButton = false; + + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + toSpeak = "Organize Inventory Button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash Can"; + } + else if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + toSpeak = "Organize Button"; + } + else if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + toSpeak = "Community Center Button"; + } + else + { + return false; + } + + if (toSpeak != null && inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + private static bool narrateHoveredEquipmentSlot(InventoryPage __instance, int mouseX, int mouseY) + { + for (int i = 0; i < __instance.equipmentIcons.Count; i++) + { + if (!__instance.equipmentIcons[i].containsPoint(mouseX, mouseY)) + continue; + + string toSpeak = getNameAndDescriptionOfItem(__instance.equipmentIcons[i].name); + + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + + return true; + } + + return false; + } + + private static string getNameAndDescriptionOfItem(string slotName) => slotName switch + { + "Hat" => (Game1.player.hat.Value != null) ? $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}" : "Hat slot", + "Left Ring" => (Game1.player.leftRing.Value != null) ? $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}" : "Left Ring slot", + "Right Ring" => (Game1.player.rightRing.Value != null) ? $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}" : "Right ring slot", + "Boots" => (Game1.player.boots.Value != null) ? $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}" : "Boots slot", + "Shirt" => (Game1.player.shirtItem.Value != null) ? $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}" : "Shirt slot", + "Pants" => (Game1.player.pantsItem.Value != null) ? $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}" : "Pants slot", + _ => "unkown slot" + }; + internal static void Cleanup() { + InventoryUtils.Cleanup(); inventoryPageQueryKey = ""; hoveredItemQueryKey = ""; } diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 3260a80..24a6184 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -118,8 +118,7 @@ namespace stardew_access.Patches MenuPatches.pondQueryMenuQuery = " "; } - InventoryUtils.hoveredItemQueryKey = ""; - InventoryUtils.prevSlotIndex = -999; + InventoryUtils.Cleanup(); TextBoxPatch.activeTextBoxes = ""; } } diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs index 5903f92..f4a7602 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Patches/InventoryUtils.cs @@ -202,5 +202,11 @@ namespace stardew_access.Patches if (MainClass.Config.DisableInventoryVerbosity) return ""; return " not usable here"; } + + internal static void Cleanup() + { + hoveredItemQueryKey = ""; + prevSlotIndex = -999; + } } } From 774454ce0e0fcfccd8aad3370b396d1aa90221c7 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 3 Mar 2023 21:03:37 +0530 Subject: [PATCH 14/40] Refactored code CraftingPagePatch.cs --- .../GameMenuPatches/CraftingPagePatch.cs | 344 +++++++++--------- 1 file changed, 172 insertions(+), 172 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index 51db2e5..8599840 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -17,191 +17,23 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + if (narrateMenuButtons(__instance, x, y)) { - // snap to first inventory slot - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = -1; - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) - { - // snap to first crafting recipe - __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); - __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = 0; - } - else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) - { - isSelectingRecipe = true; - CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); - Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); - } - - #region Narrate buttons in the menu - if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) - { - string toSpeak = "Previous Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } return; } - if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) + if (narrateHoveredRecipe(__instance, ___currentCraftingPage, ___hoverRecipe, x, y)) { - string toSpeak = "Next Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } return; } - if (__instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - #endregion - - #region Narrate hovered recipe - if (___hoverRecipe != null) - { - string name = ___hoverRecipe.DisplayName; - int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; - string description = ""; - string ingredients = ""; - string buffs = ""; - string craftable = ""; - - description = $"Description:\n{___hoverRecipe.description}"; - craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; - - #region Crafting ingredients - ingredients = "Ingredients:\n"; - for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) - { - int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; - int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; - string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); - - ingredients += $" ,{recipeCount} {recipeName}"; - } - #endregion - - #region Health & stamina and buff items (effects like +1 walking speed) - Item producesItem = ___hoverRecipe.createItem(); - if (producesItem is StardewValley.Object producesItemObject) - { - if (producesItemObject.Edibility != -300) - { - int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); - buffs += $"{stamina_recovery} Energy"; - if (stamina_recovery >= 0) - { - int health_recovery = producesItemObject.healthRecoveredOnConsumption(); - buffs += $"\n{health_recovery} Health"; - } - } - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; - string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) - ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) - : null; - - if (buffIconsToDisplay != null) - { - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - buffs += $"{buffName}\n"; - } - catch (Exception) { } - } - - buffs = $"Buffs and boosts:\n {buffs}"; - } - } - #endregion - - - string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; - - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - else - { - var isRecipeInFocus = false; - foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) - { - if (item.Key.containsPoint(x, y)) - { - isRecipeInFocus = true; - break; - } - } - - if (isRecipeInFocus) - { - string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; - - if (craftingPageQueryKey != query) - { - craftingPageQueryKey = query; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say("unknown recipe", true); - } - return; - } - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) { craftingPageQueryKey = ""; return; } - #endregion + + handleKeyBinds(__instance, ___currentCraftingPage); } catch (Exception e) { @@ -209,6 +41,174 @@ namespace stardew_access.Patches } } + private static void handleKeyBinds(CraftingPage __instance, int ___currentCraftingPage) + { + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + // snap to first inventory slot + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = -1; + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) + { + // snap to first crafting recipe + __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); + __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = 0; + } + else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) + { + isSelectingRecipe = true; + CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); + } + } + + private static bool narrateMenuButtons(CraftingPage __instance, int x, int y) + { + string? toSpeak = null; + bool isDropItemButton = false; + + if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) + { + toSpeak = "Previous Recipe List"; + } + else if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) + { + toSpeak = "Next Recipe List"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash Can"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else + { + return false; + } + + if (toSpeak != null && craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + private static bool narrateHoveredRecipe(CraftingPage __instance, int ___currentCraftingPage, CraftingRecipe ___hoverRecipe, int x, int y) + { + if (___hoverRecipe == null) + { + var isRecipeInFocus = false; + foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) + { + if (!item.Key.containsPoint(x, y)) + continue; + + isRecipeInFocus = true; + break; + } + + if (!isRecipeInFocus) + return false; + + string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; + + if (craftingPageQueryKey != query) + { + craftingPageQueryKey = query; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say("unknown recipe", true); + } + return true; + } + + string name = ___hoverRecipe.DisplayName; + int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; + string description = ""; + string ingredients = ""; + string buffs = ""; + string craftable = ""; + + description = $"Description:\n{___hoverRecipe.description}"; + craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; + + #region Crafting ingredients + ingredients = "Ingredients:\n"; + for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) + { + int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; + int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; + string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); + + ingredients += $" ,{recipeCount} {recipeName}"; + } + #endregion + + #region Health & stamina and buff items (effects like +1 walking speed) + Item producesItem = ___hoverRecipe.createItem(); + if (producesItem is StardewValley.Object producesItemObject) + { + if (producesItemObject.Edibility != -300) + { + int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); + buffs += $"{stamina_recovery} Energy"; + if (stamina_recovery >= 0) + { + int health_recovery = producesItemObject.healthRecoveredOnConsumption(); + buffs += $"\n{health_recovery} Health"; + } + } + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; + string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) + ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay != null) + { + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + buffs += $"{buffName}\n"; + } + catch (Exception) { } + } + + buffs = $"Buffs and boosts:\n {buffs}"; + } + } + #endregion + + + string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; + + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + + return true; + } + private static void CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) { currentSelectedCraftingRecipe++; From b22af63b975eff558603572149bf1b5e0945c0d7 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 11:29:23 +0530 Subject: [PATCH 15/40] Improved and organised code in SocialPagePatch.cs --- .../GameMenuPatches/OptionsPagePatch.cs | 68 ++--- .../GameMenuPatches/SocialPagePatch.cs | 265 +++++++++--------- 2 files changed, 168 insertions(+), 165 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs index a05d478..f4d9879 100644 --- a/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs @@ -15,42 +15,42 @@ namespace stardew_access.Patches 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)) + 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)) + continue; + + 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) { - 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; + 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) diff --git a/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs index 3c03245..81b2ad0 100644 --- a/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs @@ -14,138 +14,16 @@ namespace stardew_access.Patches int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position for (int i = ___slotPosition; i < ___slotPosition + 5; i++) { - if (i < ___sprites.Count) + if (i >= ___sprites.Count) + continue; + + if (__instance.names[i] is string && narrateNPCDetails(__instance, i, ___kidsNames, x, y)) { - if (__instance.names[i] is string) - { - #region For NPCs - if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string name = $"{__instance.names[i] as string}"; - int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); - bool datable = SocialPage.isDatable(name); - Friendship friendship = __instance.getFriendship(name); - int giftsThisWeek = friendship.GiftsThisWeek; - bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); - bool spouse = friendship.IsMarried(); - bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); - ___kidsNames.Add("Robin"); - ___kidsNames.Add("Pierre"); - ___kidsNames.Add("Caroline"); - ___kidsNames.Add("Jodi"); - ___kidsNames.Add("Kent"); - ___kidsNames.Add("George"); - ___kidsNames.Add("Evelyn"); - ___kidsNames.Add("Demetrius"); - - - - string toSpeak = $"{name}"; - - if (!hasTalked) - { - toSpeak = $"{toSpeak}, not talked yet"; - } - - - if (datable | housemate) - { - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (housemate) - { - text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); - } - else if (spouse) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (__instance.isMarriedToAnyone(name)) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (__instance.getFriendship(name).IsDivorced()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{toSpeak}, {text2}"; - } - if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) - { - toSpeak = $"{toSpeak}, married"; - } - if (spouse) - { - toSpeak = $"{toSpeak}, spouse"; - } - else if (friendship.IsDating()) - { - toSpeak = $"{toSpeak}, dating"; - } - - toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; - - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - } - else if (__instance.names[i] is long) - { - #region For Farmers - - long farmerID = (long)__instance.names[i]; - Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); - if (farmer != null) - { - int gender = (!farmer.IsMale) ? 1 : 0; - ClickableTextureComponent clickableTextureComponent = ___sprites[i]; - if (clickableTextureComponent.containsPoint(x, y)) - { - Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); - bool spouse = friendship.IsMarried(); - string toSpeak = ""; - - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (spouse) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (farmer.isMarried() && !farmer.hasRoommate()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (friendship.IsDivorced()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{farmer.displayName}, {text2}"; - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - - #endregion - } + return; + } + else if (__instance.names[i] is long && narrateFarmerDetails(__instance, i, ___sprites, x, y)) + { + return; } } } @@ -155,6 +33,131 @@ namespace stardew_access.Patches } } + private static bool narrateNPCDetails(SocialPage __instance, int i, List ___kidsNames, int x, int y) + { + if (!__instance.characterSlots[i].bounds.Contains(x, y)) + return false; + + string name = $"{__instance.names[i] as string}"; + int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); + bool datable = SocialPage.isDatable(name); + Friendship friendship = __instance.getFriendship(name); + int giftsThisWeek = friendship.GiftsThisWeek; + bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); + bool spouse = friendship.IsMarried(); + bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); + ___kidsNames.Add("Robin"); + ___kidsNames.Add("Pierre"); + ___kidsNames.Add("Caroline"); + ___kidsNames.Add("Jodi"); + ___kidsNames.Add("Kent"); + ___kidsNames.Add("George"); + ___kidsNames.Add("Evelyn"); + ___kidsNames.Add("Demetrius"); + + string toSpeak = $"{name}"; + + if (!hasTalked) + { + toSpeak = $"{toSpeak}, not talked yet"; + } + + + if (datable | housemate) + { + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (housemate) + { + text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); + } + else if (spouse) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (__instance.isMarriedToAnyone(name)) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (__instance.getFriendship(name).IsDivorced()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{toSpeak}, {text2}"; + } + + if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) + { + toSpeak = $"{toSpeak}, married"; + } + + if (spouse) + { + toSpeak = $"{toSpeak}, spouse"; + } + else if (friendship.IsDating()) + { + toSpeak = $"{toSpeak}, dating"; + } + + toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + + private static bool narrateFarmerDetails(SocialPage __instance, int i, List ___sprites, int x, int y) + { + long farmerID = (long)__instance.names[i]; + Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); + if (farmer == null) + return false; + + int gender = (!farmer.IsMale) ? 1 : 0; + ClickableTextureComponent clickableTextureComponent = ___sprites[i]; + if (!clickableTextureComponent.containsPoint(x, y)) + return false; + + Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); + bool spouse = friendship.IsMarried(); + string toSpeak = ""; + + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (spouse) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (farmer.isMarried() && !farmer.hasRoommate()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (friendship.IsDivorced()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{farmer.displayName}, {text2}"; + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + internal static void Cleanup() { socialPageQuery = ""; From 403a97b63323dc193914d6c4d6fdc9b925654f83 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 12:03:08 +0530 Subject: [PATCH 16/40] Improved and organised code in AnimalQueryMenuPatch.cs --- .../Patches/AnimalQueryMenuPatch.cs | 103 ++++++++++-------- stardew-access/Patches/IClickableMenuPatch.cs | 3 +- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/stardew-access/Patches/AnimalQueryMenuPatch.cs b/stardew-access/Patches/AnimalQueryMenuPatch.cs index 232d573..334e580 100644 --- a/stardew-access/Patches/AnimalQueryMenuPatch.cs +++ b/stardew-access/Patches/AnimalQueryMenuPatch.cs @@ -18,61 +18,76 @@ namespace stardew_access.Patches if (TextBoxPatch.isAnyTextBoxActive) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details - string toSpeak = " ", details = " "; isOnFarm = ___movingAnimal; animalQueryMenu = __instance; animalBeingMoved = ___animal; - if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) - { - string name = ___animal.displayName; - string type = ___animal.displayType; - int age = (___animal.GetDaysOwned() + 1) / 28 + 1; - string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); - string parent = ""; - if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) - { - ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); - } - if (___parentName != null) - { - parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); - } + narrateAnimalDetailsOnKeyPress(___animal, ___parentName); - details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; - animalQueryMenuQuery = ""; - - isNarratingAnimalInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "OK button"; - else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) - toSpeak = $"Sell for {___animal.getSellPrice()}g button"; - else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm selling animal"; - else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel selling animal"; - else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) - toSpeak = "Change home building button"; - else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) - toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = "Animal name text box"; - - if (animalQueryMenuQuery != toSpeak) - { - animalQueryMenuQuery = toSpeak; - MainClass.ScreenReader.Say($"{details} {toSpeak}", true); - } + narrateHoveredButton(__instance, ___animal, ___confirmingSell, x, y); } catch (System.Exception e) { MainClass.ErrorLog($"An error occured in AnimalQueryMenuPatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}"); } } + + private static void narrateAnimalDetailsOnKeyPress(FarmAnimal ___animal, string ___parentName) + { + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + if (!isPrimaryInfoKeyPressed | isNarratingAnimalInfo) + return; + + string name = ___animal.displayName; + string type = ___animal.displayType; + int age = (___animal.GetDaysOwned() + 1) / 28 + 1; + string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); + string parent = ""; + if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) + { + ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); + } + if (___parentName != null) + { + parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); + } + + isNarratingAnimalInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); // Adds delay + + MainClass.ScreenReader.Say($"Name: {name} Type: {type} \n\t Age: {ageText} {parent}", true); + } + + private static void narrateHoveredButton(AnimalQueryMenu __instance, FarmAnimal ___animal, bool ___confirmingSell, int x, int y) + { + string toSpeak = ""; + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "OK button"; + else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) + toSpeak = $"Sell for {___animal.getSellPrice()}g button"; + else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm selling animal"; + else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel selling animal"; + else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) + toSpeak = "Change home building button"; + else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) + toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = "Animal name text box"; + + if (animalQueryMenuQuery != toSpeak) + { + animalQueryMenuQuery = toSpeak; + MainClass.ScreenReader.Say($"{toSpeak}", true); + } + } + + internal static void Cleanup() + { + AnimalQueryMenuPatch.animalQueryMenuQuery = ""; + AnimalQueryMenuPatch.animalQueryMenu = null; + } } } diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 24a6184..da31c47 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -77,8 +77,7 @@ namespace stardew_access.Patches } else if (menu is AnimalQueryMenu) { - AnimalQueryMenuPatch.animalQueryMenuQuery = ""; - AnimalQueryMenuPatch.animalQueryMenu = null; + AnimalQueryMenuPatch.Cleanup(); } else if (menu is DialogueBox) { From b0ef71cd4a3aa95801f86d8148cddfdd59f06366 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 12:16:39 +0530 Subject: [PATCH 17/40] bug fix --- stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs | 4 ++-- stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index 8599840..f9c5180 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -17,6 +17,8 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + handleKeyBinds(__instance, ___currentCraftingPage); + if (narrateMenuButtons(__instance, x, y)) { return; @@ -32,8 +34,6 @@ namespace stardew_access.Patches craftingPageQueryKey = ""; return; } - - handleKeyBinds(__instance, ___currentCraftingPage); } catch (Exception e) { diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs index 8dc26b3..dc05fd3 100644 --- a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -14,6 +14,8 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + handleKeyBinds(); + if (narrateHoveredButton(__instance, x, y)) { return; @@ -30,8 +32,6 @@ namespace stardew_access.Patches return; } - handleKeyBinds(); - // If no slot or button is hovered Cleanup(); } From baede5796585ef28dae7eb25c3e2a541c08259bf Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 19:44:58 +0530 Subject: [PATCH 18/40] Improved and organised code in bundle menu patches --- stardew-access/HarmonyPatches.cs | 4 +- stardew-access/Patches/BundleMenuPatches.cs | 360 ------------------ .../BundleMenuPatches/JojaCDMenuPatch.cs | 70 ++++ .../BundleMenuPatches/JunimoNoteMenuPatch.cs | 297 +++++++++++++++ stardew-access/Patches/ChatMenuPatches.cs | 3 +- stardew-access/Patches/IClickableMenuPatch.cs | 7 +- 6 files changed, 373 insertions(+), 368 deletions(-) delete mode 100644 stardew-access/Patches/BundleMenuPatches.cs create mode 100644 stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs create mode 100644 stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index a993c81..e22dbc4 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -117,12 +117,12 @@ namespace stardew_access #region Bundle Menu Patches harmony.Patch( original: AccessTools.Method(typeof(JunimoNoteMenu), nameof(JunimoNoteMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(BundleMenuPatches), nameof(BundleMenuPatches.JunimoNoteMenuPatch)) + postfix: new HarmonyMethod(typeof(JunimoNoteMenuPatch), nameof(JunimoNoteMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(JojaCDMenu), nameof(JojaCDMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(BundleMenuPatches), nameof(BundleMenuPatches.JojaCDMenuPatch)) + postfix: new HarmonyMethod(typeof(JojaCDMenuPatch), nameof(JojaCDMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/BundleMenuPatches.cs b/stardew-access/Patches/BundleMenuPatches.cs deleted file mode 100644 index fc3dc6c..0000000 --- a/stardew-access/Patches/BundleMenuPatches.cs +++ /dev/null @@ -1,360 +0,0 @@ -using StardewValley; -using StardewValley.Locations; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class BundleMenuPatches - { - internal static string junimoNoteMenuQuery = ""; - internal static string currentJunimoArea = ""; - internal static string jojaCDMenuQuery = ""; - internal static bool isUsingCustomButtons = false; - internal static int currentIngredientListItem = -1, currentIngredientInputSlot = -1, currentInventorySlot = -1; - - #region Joja Mart Bundle/Quests - internal static void JojaCDMenuPatch(JojaCDMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = ""; - - for (int i = 0; i < __instance.checkboxes.Count; i++) - { - ClickableComponent c = __instance.checkboxes[i]; - if (!c.containsPoint(x, y)) - continue; - - if (c.name.Equals("complete")) - { - toSpeak = $"Completed {getNameFromIndex(i)}"; - } - else - { - toSpeak = $"{getNameFromIndex(i)} Cost: {__instance.getPriceFromButtonNumber(i)}g Description: {__instance.getDescriptionFromButtonNumber(i)}"; - } - - break; - } - - if (jojaCDMenuQuery != toSpeak) - { - jojaCDMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static string getNameFromIndex(int i) - { - string name = i switch - { - 0 => "Bus", - 1 => "Minecarts", - 2 => "Bridge", - 3 => "Greenhouse", - 4 => "Panning", - _ => "", - }; - - if (name != "") - return $"{name} Project"; - else - return "unkown"; - } - #endregion - - #region Community Center Bundles - internal static void JunimoNoteMenuPatch(JunimoNoteMenu __instance, bool ___specificBundlePage, int ___whichArea, Bundle ___currentPageBundle) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (!___specificBundlePage) - { - currentIngredientListItem = -1; - isUsingCustomButtons = false; - - string areaName = __instance.scrambledText ? CommunityCenter.getAreaEnglishDisplayNameFromNumber(___whichArea) : CommunityCenter.getAreaDisplayNameFromNumber(___whichArea); - string reward = __instance.getRewardNameForArea(___whichArea); - - if (__instance.scrambledText) - { - string toSpeak = "Scrambled Text"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (currentJunimoArea != areaName) - { - currentJunimoArea = areaName; - MainClass.ScreenReader.Say($"Area {areaName}, {reward}", true); - return; - } - - for (int i = 0; i < __instance.bundles.Count; i++) - { - if (__instance.bundles[i].containsPoint(x, y)) - { - string toSpeak = $"{__instance.bundles[i].name} bundle"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - if (__instance.presentButton != null && __instance.presentButton.containsPoint(x, y)) - { - string toSpeak = "Present Button"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.fromGameMenu) - { - if (__instance.areaNextButton.visible && __instance.areaNextButton.containsPoint(x, y)) - { - string toSpeak = "Next Area Button"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.areaBackButton.visible && __instance.areaBackButton.containsPoint(x, y)) - { - string toSpeak = "Previous Area Button"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - } - else - { - bool isIPressed = MainClass.Config.BundleMenuIngredientsKey.JustPressed(); // For the ingredients - bool isCPressed = MainClass.Config.BundleMenuInventoryItemsKey.JustPressed(); // For the items in inventory - bool isPPressed = MainClass.Config.BundleMenuPurchaseButtonKey.JustPressed(); // For the Purchase Button - bool isVPressed = MainClass.Config.BundleMenuIngredientsInputSlotKey.JustPressed(); // For the ingredient input slots - bool isBackPressed = MainClass.Config.BundleMenuBackButtonKey.JustPressed(); // For the back button - bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); - - if (isIPressed && !isUsingCustomButtons) - { - isUsingCustomButtons = true; - JunimoNoteCustomButtons(__instance, ___currentPageBundle, 0, isLeftShiftPressed); - Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); - } - else if (isVPressed && !isUsingCustomButtons) - { - isUsingCustomButtons = true; - JunimoNoteCustomButtons(__instance, ___currentPageBundle, 1, isLeftShiftPressed); - Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); - } - else if (isCPressed && !isUsingCustomButtons) - { - isUsingCustomButtons = true; - JunimoNoteCustomButtons(__instance, ___currentPageBundle, 2, isLeftShiftPressed); - Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); - } - else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y)) - { - __instance.backButton.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say("Back Button", true); - } - else if (isPPressed && __instance.purchaseButton != null && !__instance.purchaseButton.containsPoint(x, y)) - { - __instance.purchaseButton.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say("Purchase Button", true); - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static void JunimoNoteCustomButtons(JunimoNoteMenu __instance, Bundle ___currentPageBundle, int signal, bool isLeftShiftPressed = false) - { - try - { - - switch (signal) - { - case 0: // For ingredient list - { - if (___currentPageBundle.ingredients.Count >= 0) - { - currentIngredientListItem = currentIngredientListItem + (isLeftShiftPressed ? -1 : 1); - if (currentIngredientListItem >= ___currentPageBundle.ingredients.Count) - if (isLeftShiftPressed) - currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; - else - currentIngredientListItem = 0; - - if (currentIngredientListItem < 0) - if (isLeftShiftPressed) - currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; - else - currentIngredientListItem = 0; - - ClickableTextureComponent c = __instance.ingredientList[currentIngredientListItem]; - BundleIngredientDescription ingredient = ___currentPageBundle.ingredients[currentIngredientListItem]; - - Item item = new StardewValley.Object(ingredient.index, ingredient.stack, isRecipe: false, -1, ingredient.quality); - bool completed = false; - if (___currentPageBundle != null && ___currentPageBundle.ingredients != null && currentIngredientListItem < ___currentPageBundle.ingredients.Count && ___currentPageBundle.ingredients[currentIngredientListItem].completed) - { - completed = true; - } - - string toSpeak = item.DisplayName; - - if (!completed) - { - int quality = ingredient.quality; - if (quality == 1) - { - toSpeak = $"Silver quality {toSpeak}"; - } - else if (quality == 2 || quality == 3) - { - toSpeak = $"Gold quality {toSpeak}"; - } - else if (quality >= 4) - { - toSpeak = $"Iridium quality {toSpeak}"; - } - - toSpeak = $"{ingredient.stack} {toSpeak}"; - } - - if (completed) - toSpeak = $"Completed {toSpeak}"; - - c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); - } - } - break; - case 1: // For input slot list - { - if (__instance.ingredientSlots.Count >= 0) - { - currentIngredientInputSlot = currentIngredientInputSlot + (isLeftShiftPressed ? -1 : 1); - if (currentIngredientInputSlot >= __instance.ingredientSlots.Count) - if (isLeftShiftPressed) - currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; - else - currentIngredientInputSlot = 0; - - if (currentIngredientInputSlot < 0) - if (isLeftShiftPressed) - currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; - else - currentIngredientInputSlot = 0; - - ClickableTextureComponent c = __instance.ingredientSlots[currentIngredientInputSlot]; - Item item = c.item; - string toSpeak; - - if (item == null) - { - toSpeak = $"Input Slot {currentIngredientInputSlot + 1}"; - } - else - { - toSpeak = item.DisplayName; - } - - c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); - } - } - break; - case 2: // For inventory slots - { - if (__instance.inventory != null && __instance.inventory.actualInventory.Count >= 0) - { - int prevSlotIndex = currentInventorySlot; - currentInventorySlot = currentInventorySlot + (isLeftShiftPressed ? -1 : 1); - if (currentInventorySlot >= __instance.inventory.actualInventory.Count) - if (isLeftShiftPressed) - currentInventorySlot = __instance.inventory.actualInventory.Count - 1; - else - currentInventorySlot = 0; - - if (currentInventorySlot < 0) - if (isLeftShiftPressed) - currentInventorySlot = __instance.inventory.actualInventory.Count - 1; - else - currentInventorySlot = 0; - - Item item = __instance.inventory.actualInventory[currentInventorySlot]; - ClickableComponent c = __instance.inventory.inventory[currentInventorySlot]; - string toSpeak; - if (item != null) - { - toSpeak = item.DisplayName; - - if ((item as StardewValley.Object) != null) - { - int quality = ((StardewValley.Object)item).Quality; - if (quality == 1) - { - toSpeak = $"Silver quality {toSpeak}"; - } - else if (quality == 2 || quality == 3) - { - toSpeak = $"Gold quality {toSpeak}"; - } - else if (quality >= 4) - { - toSpeak = $"Iridium quality {toSpeak}"; - } - } - toSpeak = $"{item.Stack} {toSpeak}"; - - if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[currentInventorySlot])) - { - toSpeak = $"{toSpeak} not usable here"; - } - } - else - { - toSpeak = "Empty Slot"; - } - c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); - } - } - break; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - #endregion - } -} \ No newline at end of file diff --git a/stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs b/stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs new file mode 100644 index 0000000..2a8e1b6 --- /dev/null +++ b/stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs @@ -0,0 +1,70 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class JojaCDMenuPatch + { + internal static string jojaCDMenuQuery = ""; + + internal static void DrawPatch(JojaCDMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = ""; + + for (int i = 0; i < __instance.checkboxes.Count; i++) + { + ClickableComponent c = __instance.checkboxes[i]; + if (!c.containsPoint(x, y)) + continue; + + if (c.name.Equals("complete")) + { + toSpeak = $"Completed {getNameFromIndex(i)}"; + } + else + { + toSpeak = $"{getNameFromIndex(i)} Cost: {__instance.getPriceFromButtonNumber(i)}g Description: {__instance.getDescriptionFromButtonNumber(i)}"; + } + + break; + } + + if (jojaCDMenuQuery != toSpeak) + { + jojaCDMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static string getNameFromIndex(int i) + { + string name = i switch + { + 0 => "Bus", + 1 => "Minecarts", + 2 => "Bridge", + 3 => "Greenhouse", + 4 => "Panning", + _ => "", + }; + + if (name != "") + return $"{name} Project"; + else + return "unkown"; + } + + internal static void Cleanup() + { + jojaCDMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs b/stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs new file mode 100644 index 0000000..96d89c5 --- /dev/null +++ b/stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs @@ -0,0 +1,297 @@ +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class JunimoNoteMenuPatch + { + internal static string junimoNoteMenuQuery = ""; + internal static string currentJunimoArea = ""; + internal static bool isUsingCustomKeyBinds = false; + internal static int currentIngredientListItem = -1, currentIngredientInputSlot = -1, currentInventorySlot = -1; + + internal static void DrawPatch(JunimoNoteMenu __instance, bool ___specificBundlePage, int ___whichArea, Bundle ___currentPageBundle) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (narrateJunimoArea(__instance, ___specificBundlePage, ___whichArea, x, y)) + { + return; + } + + narrateBundlePage(__instance, ___specificBundlePage, ___currentPageBundle, x, y); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static bool narrateJunimoArea(JunimoNoteMenu __instance, bool ___specificBundlePage, int ___whichArea, int x, int y) + { + if (___specificBundlePage) + return false; + + currentIngredientListItem = -1; + isUsingCustomKeyBinds = false; + + string areaName = __instance.scrambledText ? CommunityCenter.getAreaEnglishDisplayNameFromNumber(___whichArea) : CommunityCenter.getAreaDisplayNameFromNumber(___whichArea); + string reward = __instance.getRewardNameForArea(___whichArea); + + if (__instance.scrambledText) + { + string scrambledText = "Scrambled Text"; + if (junimoNoteMenuQuery != scrambledText) + { + junimoNoteMenuQuery = scrambledText; + MainClass.ScreenReader.Say(scrambledText, true); + } + return true; + } + + if (currentJunimoArea != areaName) + { + currentJunimoArea = areaName; + MainClass.ScreenReader.Say($"Area {areaName}, {reward}", true); + return true; + } + + string toSpeak = ""; + if (__instance.presentButton != null && __instance.presentButton.containsPoint(x, y)) + { + toSpeak = "Present Button"; + } + else if (__instance.fromGameMenu && __instance.areaNextButton.visible && __instance.areaNextButton.containsPoint(x, y)) + { + toSpeak = "Next Area Button"; + } + else if (__instance.fromGameMenu && __instance.areaBackButton.visible && __instance.areaBackButton.containsPoint(x, y)) + { + toSpeak = "Previous Area Button"; + } + else + { + for (int i = 0; i < __instance.bundles.Count; i++) + { + if (!__instance.bundles[i].containsPoint(x, y)) + continue; + + toSpeak = $"{__instance.bundles[i].name} bundle"; + break; + } + } + + if (junimoNoteMenuQuery != toSpeak) + { + junimoNoteMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + return true; + } + + return false; + } + + private static void narrateBundlePage(JunimoNoteMenu __instance, bool ___specificBundlePage, Bundle ___currentPageBundle, int x, int y) + { + if (!___specificBundlePage) + return; + + bool isIPressed = MainClass.Config.BundleMenuIngredientsKey.JustPressed(); // For the ingredients + bool isCPressed = MainClass.Config.BundleMenuInventoryItemsKey.JustPressed(); // For the items in inventory + bool isPPressed = MainClass.Config.BundleMenuPurchaseButtonKey.JustPressed(); // For the Purchase Button + bool isVPressed = MainClass.Config.BundleMenuIngredientsInputSlotKey.JustPressed(); // For the ingredient input slots + bool isBackPressed = MainClass.Config.BundleMenuBackButtonKey.JustPressed(); // For the back button + bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); + + if (isIPressed && !isUsingCustomKeyBinds) + { + isUsingCustomKeyBinds = true; + cycleThroughIngredientList(__instance, ___currentPageBundle, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomKeyBinds = false; }); + } + else if (isVPressed && !isUsingCustomKeyBinds) + { + isUsingCustomKeyBinds = true; + cycleThroughInputSlots(__instance, ___currentPageBundle, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomKeyBinds = false; }); + } + else if (isCPressed && !isUsingCustomKeyBinds) + { + isUsingCustomKeyBinds = true; + cycleThroughInventorySlots(__instance, ___currentPageBundle, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomKeyBinds = false; }); + } + else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y)) + { + __instance.backButton.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say("Back Button", true); + } + else if (isPPressed && __instance.purchaseButton != null && !__instance.purchaseButton.containsPoint(x, y)) + { + __instance.purchaseButton.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say("Purchase Button", true); + } + return; + } + + private static void cycleThroughIngredientList(JunimoNoteMenu __instance, Bundle ___currentPageBundle, bool isLeftShiftPressed = false) + { + if (___currentPageBundle.ingredients.Count < 0) + return; + + currentIngredientListItem = currentIngredientListItem + (isLeftShiftPressed ? -1 : 1); + if (currentIngredientListItem >= ___currentPageBundle.ingredients.Count) + if (isLeftShiftPressed) + currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; + else + currentIngredientListItem = 0; + + if (currentIngredientListItem < 0) + if (isLeftShiftPressed) + currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; + else + currentIngredientListItem = 0; + + ClickableTextureComponent c = __instance.ingredientList[currentIngredientListItem]; + BundleIngredientDescription ingredient = ___currentPageBundle.ingredients[currentIngredientListItem]; + + Item item = new StardewValley.Object(ingredient.index, ingredient.stack, isRecipe: false, -1, ingredient.quality); + bool completed = false; + if (___currentPageBundle != null && ___currentPageBundle.ingredients != null && currentIngredientListItem < ___currentPageBundle.ingredients.Count && ___currentPageBundle.ingredients[currentIngredientListItem].completed) + { + completed = true; + } + + string toSpeak = item.DisplayName; + + if (completed) + { + toSpeak = $"Completed {toSpeak}"; + } + else + { + int quality = ingredient.quality; + if (quality == 1) + { + toSpeak = $"Silver quality {toSpeak}"; + } + else if (quality == 2 || quality == 3) + { + toSpeak = $"Gold quality {toSpeak}"; + } + else if (quality >= 4) + { + toSpeak = $"Iridium quality {toSpeak}"; + } + + toSpeak = $"{ingredient.stack} {toSpeak}"; + } + + c.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void cycleThroughInputSlots(JunimoNoteMenu __instance, Bundle ___currentPageBundle, bool isLeftShiftPressed = false) + { + if (__instance.ingredientSlots.Count < 0) + return; + + currentIngredientInputSlot = currentIngredientInputSlot + (isLeftShiftPressed ? -1 : 1); + if (currentIngredientInputSlot >= __instance.ingredientSlots.Count) + if (isLeftShiftPressed) + currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; + else + currentIngredientInputSlot = 0; + + if (currentIngredientInputSlot < 0) + if (isLeftShiftPressed) + currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; + else + currentIngredientInputSlot = 0; + + ClickableTextureComponent c = __instance.ingredientSlots[currentIngredientInputSlot]; + Item item = c.item; + string toSpeak; + + if (item == null) + { + toSpeak = $"Input Slot {currentIngredientInputSlot + 1}"; + } + else + { + toSpeak = item.DisplayName; + } + + c.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void cycleThroughInventorySlots(JunimoNoteMenu __instance, Bundle ___currentPageBundle, bool isLeftShiftPressed = false) + { + if (__instance.inventory == null || __instance.inventory.actualInventory.Count < 0) + return; + + int prevSlotIndex = currentInventorySlot; + currentInventorySlot = currentInventorySlot + (isLeftShiftPressed ? -1 : 1); + if (currentInventorySlot >= __instance.inventory.actualInventory.Count) + if (isLeftShiftPressed) + currentInventorySlot = __instance.inventory.actualInventory.Count - 1; + else + currentInventorySlot = 0; + + if (currentInventorySlot < 0) + if (isLeftShiftPressed) + currentInventorySlot = __instance.inventory.actualInventory.Count - 1; + else + currentInventorySlot = 0; + + Item item = __instance.inventory.actualInventory[currentInventorySlot]; + ClickableComponent c = __instance.inventory.inventory[currentInventorySlot]; + string toSpeak; + if (item != null) + { + toSpeak = item.DisplayName; + + if ((item as StardewValley.Object) != null) + { + int quality = ((StardewValley.Object)item).Quality; + if (quality == 1) + { + toSpeak = $"Silver quality {toSpeak}"; + } + else if (quality == 2 || quality == 3) + { + toSpeak = $"Gold quality {toSpeak}"; + } + else if (quality >= 4) + { + toSpeak = $"Iridium quality {toSpeak}"; + } + } + toSpeak = $"{item.Stack} {toSpeak}"; + + if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[currentInventorySlot])) + { + toSpeak = $"{toSpeak} not usable here"; + } + } + else + { + toSpeak = "Empty Slot"; + } + c.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + JunimoNoteMenuPatch.currentIngredientListItem = -1; + JunimoNoteMenuPatch.currentIngredientInputSlot = -1; + JunimoNoteMenuPatch.currentInventorySlot = -1; + JunimoNoteMenuPatch.junimoNoteMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatches.cs index 9d3272d..6155a70 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatches.cs @@ -1,4 +1,5 @@ -using StardewValley.Menus; +using StardewValley; +using StardewValley.Menus; namespace stardew_access.Patches { diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index da31c47..5478bb5 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -42,10 +42,7 @@ namespace stardew_access.Patches } else if (menu is JunimoNoteMenu) { - BundleMenuPatches.currentIngredientListItem = -1; - BundleMenuPatches.currentIngredientInputSlot = -1; - BundleMenuPatches.currentInventorySlot = -1; - BundleMenuPatches.junimoNoteMenuQuery = ""; + JunimoNoteMenuPatch.Cleanup(); } else if (menu is ShopMenu) { @@ -86,7 +83,7 @@ namespace stardew_access.Patches } else if (menu is JojaCDMenu) { - BundleMenuPatches.jojaCDMenuQuery = ""; + JojaCDMenuPatch.Cleanup(); } else if (menu is QuestLog) { From 6141447c13538e059d91da325a8ce9f8e8d8c2ac Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 22:45:00 +0530 Subject: [PATCH 19/40] Improved and organised code in carpenter menu patch --- stardew-access/Patches/CarpenterMenuPach.cs | 206 +++++++++----------- 1 file changed, 87 insertions(+), 119 deletions(-) diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPach.cs index 3745452..856d817 100644 --- a/stardew-access/Patches/CarpenterMenuPach.cs +++ b/stardew-access/Patches/CarpenterMenuPach.cs @@ -29,138 +29,27 @@ namespace stardew_access.Patches isMoving = false; isConstructing = false; - #region The blueprint menu - BluePrint currentBluprint = __instance.CurrentBlueprint; - if (currentBluprint == null) + BluePrint currentBlueprint = __instance.CurrentBlueprint; + if (currentBlueprint == null) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - string ingredients = ""; - string name = currentBluprint.displayName; - string upgradeName = currentBluprint.nameOfBuildingToUpgrade; - string description = currentBluprint.description; - string price = $"{___price}g"; - string blueprintInfo; - int width = currentBluprint.tilesWidth; - int height = currentBluprint.tilesHeight; - - #region Get ingredients - for (int i = 0; i < ___ingredients.Count; i++) - { - string itemName = ___ingredients[i].DisplayName; - int itemStack = ___ingredients[i].Stack; - string itemQuality = ""; - - int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; - if (qualityValue == 1) - { - itemQuality = "Silver quality"; - } - else if (qualityValue == 2 || qualityValue == 3) - { - itemQuality = "Gold quality"; - } - else if (qualityValue >= 4) - { - itemQuality = "Iridium quality"; - } - - ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; - } - #endregion - - blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; + string blueprintInfo = getCurrentBlueprintInfo(currentBlueprint, ___price, ___ingredients); if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo) { - SayBlueprintInfo(blueprintInfo); + SpeakAndWait(blueprintInfo); } else if (prevBlueprintInfo != blueprintInfo) { prevBlueprintInfo = blueprintInfo; - SayBlueprintInfo(blueprintInfo); + SpeakAndWait(blueprintInfo); } else { - if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - { - string toSpeak = "Previous Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - { - string toSpeak = "Next Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) - { - string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) - { - string toSpeak = "Move Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) - { - string toSpeak = "Paint Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) - { - string toSpeak = "Cancel Button"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } + narrateHoveredButton(__instance, ___blueprints, ___currentBlueprintIndex, x, y); } - #endregion } else { @@ -182,14 +71,93 @@ namespace stardew_access.Patches } } - private static async void SayBlueprintInfo(string info) + private static string getCurrentBlueprintInfo(BluePrint currentBlueprint, int ___price, List ___ingredients) + { + string ingredients = ""; + string name = currentBlueprint.displayName; + string upgradeName = currentBlueprint.nameOfBuildingToUpgrade; + string description = currentBlueprint.description; + string price = $"{___price}g"; + int width = currentBlueprint.tilesWidth; + int height = currentBlueprint.tilesHeight; + + #region Get ingredients + for (int i = 0; i < ___ingredients.Count; i++) + { + string itemName = ___ingredients[i].DisplayName; + int itemStack = ___ingredients[i].Stack; + string itemQuality = ""; + + int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; + if (qualityValue == 1) + { + itemQuality = "Silver quality"; + } + else if (qualityValue == 2 || qualityValue == 3) + { + itemQuality = "Gold quality"; + } + else if (qualityValue >= 4) + { + itemQuality = "Iridium quality"; + } + + ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; + } + #endregion + + return $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; + } + + private static async void SpeakAndWait(string toSpeak) { isSayingBlueprintInfo = true; - MainClass.ScreenReader.Say(info, true); + MainClass.ScreenReader.Say(toSpeak, true); await Task.Delay(300); isSayingBlueprintInfo = false; } + private static void narrateHoveredButton(CarpenterMenu __instance, List ___blueprints, int ___currentBlueprintIndex, int x, int y) + { + string toSpeak = ""; + if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + { + toSpeak = "Previous Blueprint"; + } + else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + { + toSpeak = "Next Blueprint"; + } + else if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) + { + toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); + } + else if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) + { + toSpeak = "Move Building"; + } + else if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) + { + toSpeak = "Paint Building"; + } + else if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) + { + toSpeak = "Cancel Button"; + } + else + { + return; + } + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } } } From 9096ce59b900ea460bcb482038000abae2f8187b Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 22:57:15 +0530 Subject: [PATCH 20/40] bug fix in snapping mouse to primary and secondary inventory slots --- .../Patches/GameMenuPatches/CraftingPagePatch.cs | 16 ++++++++-------- stardew-access/Patches/ItemGrabMenuPatch.cs | 12 ++++++------ stardew-access/Patches/ShopMenuPatch.cs | 12 ++++++------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index f9c5180..59e6140 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -43,20 +43,20 @@ namespace stardew_access.Patches private static void handleKeyBinds(CraftingPage __instance, int ___currentCraftingPage) { - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - // snap to first inventory slot - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = -1; - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) + if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) { // snap to first crafting recipe __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); currentSelectedCraftingRecipe = 0; } + else if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + // snap to first inventory slot + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = -1; + } else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) { isSelectingRecipe = true; diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs index 664d810..1948491 100644 --- a/stardew-access/Patches/ItemGrabMenuPatch.cs +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -14,16 +14,16 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) + if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) { __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); } + else if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + } #region Narrate buttons in the menu if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 4f565a9..8da8b11 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -14,16 +14,16 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) + if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) { __instance.forSaleButtons[0].snapMouseCursorToCenter(); __instance.setCurrentlySnappedComponentTo(__instance.forSaleButtons[0].myID); } + else if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + } #region Narrate buttons in the menu if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) From 2ba41822c92e9a5048b0b276d3c4eb8de514091f Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 23:34:07 +0530 Subject: [PATCH 21/40] Improved and organised code in title menu patches --- stardew-access/HarmonyPatches.cs | 8 +- stardew-access/Patches/IClickableMenuPatch.cs | 18 +- stardew-access/Patches/TitleMenuPatches.cs | 238 ------------------ .../AdvancedGameOptionsPatch.cs | 85 +++++++ .../CharacterCustomizationMenuPatches.cs | 2 +- .../Patches/TitleMenuPatches/CoopMenuPatch.cs | 59 +++++ .../TitleMenuPatches/LoadGameMenuPatch.cs | 86 +++++++ .../TitleMenuPatches/TitleMenuPatches.cs | 81 ++++++ 8 files changed, 333 insertions(+), 244 deletions(-) delete mode 100644 stardew-access/Patches/TitleMenuPatches.cs create mode 100644 stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs rename stardew-access/Patches/{ => TitleMenuPatches}/CharacterCustomizationMenuPatches.cs (99%) create mode 100644 stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs create mode 100644 stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs create mode 100644 stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index e22dbc4..c5c26cf 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -38,12 +38,12 @@ namespace stardew_access #region Title Menu Patches harmony.Patch( original: AccessTools.Method(typeof(TitleMenu), nameof(TitleMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.TitleMenuPatch)) + postfix: new HarmonyMethod(typeof(TitleMenuPatch), nameof(TitleMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(LoadGameMenu.SaveFileSlot), nameof(LoadGameMenu.SaveFileSlot.Draw), new Type[] { typeof(SpriteBatch), typeof(int) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.LoadGameMenuPatch)) + postfix: new HarmonyMethod(typeof(LoadGameMenuPatch), nameof(LoadGameMenuPatch.DrawPatch)) ); harmony.Patch( @@ -53,12 +53,12 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CoopMenu), nameof(CoopMenu.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.CoopMenuPatch)) + postfix: new HarmonyMethod(typeof(CoopMenuPatch), nameof(CoopMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(AdvancedGameOptions), nameof(AdvancedGameOptions.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.AdvancedGameOptionsPatch)) + postfix: new HarmonyMethod(typeof(AdvancedGameOptionsPatch), nameof(AdvancedGameOptionsPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 5478bb5..b0a6c8c 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -19,7 +19,23 @@ namespace stardew_access.Patches internal static void Cleanup(IClickableMenu menu) { - if (menu is LetterViewerMenu) + if (menu is TitleMenu) + { + TitleMenuPatch.Cleanup(); + } + else if (menu is CoopMenu) + { + CoopMenuPatch.Cleanup(); + } + else if (menu is LoadGameMenu) + { + LoadGameMenuPatch.Cleanup(); + } + else if (menu is AdvancedGameOptions) + { + AdvancedGameOptionsPatch.Cleanup(); + } + else if (menu is LetterViewerMenu) { DialoguePatches.currentLetterText = " "; } diff --git a/stardew-access/Patches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches.cs deleted file mode 100644 index af8cba3..0000000 --- a/stardew-access/Patches/TitleMenuPatches.cs +++ /dev/null @@ -1,238 +0,0 @@ -using StardewValley; -using StardewValley.Menus; -using static StardewValley.Menus.LoadGameMenu; - -namespace stardew_access.Patches -{ - internal class TitleMenuPatches - { - public static string advancedGameOptionsQueryKey = " "; - - internal static void AdvancedGameOptionsPatch(AdvancedGameOptions __instance) - { - try - { - int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "OK Button"; - if (advancedGameOptionsQueryKey != toSpeak) - { - advancedGameOptionsQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - 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 (optionsElement is OptionsTextEntry) - { - toSpeak = $"Seed text box"; - } - else - { - if (toSpeak.Contains(":")) - toSpeak = toSpeak.Replace(":", ""); - - toSpeak = $"{toSpeak} Options:"; - } - - if (advancedGameOptionsQueryKey != toSpeak) - { - advancedGameOptionsQueryKey = 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 CoopMenuPatch(CoopMenu __instance, CoopMenu.Tab ___currentTab) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - string toSpeak = " "; - - #region Join/Host Button (Important! This should be checked before checking other buttons) - if (__instance.slotButtons[0].containsPoint(x, y)) - { - if (___currentTab == CoopMenu.Tab.JOIN_TAB) - toSpeak = "Join lan game"; - if (___currentTab == CoopMenu.Tab.HOST_TAB) - toSpeak = "Host new farm"; - } - #endregion - - #region Other Buttons - if (__instance.joinTab.containsPoint(x, y)) - { - toSpeak = "Join Tab Button"; - } - else if (__instance.hostTab.containsPoint(x, y)) - { - toSpeak = "Host Tab Button"; - } - else if (__instance.refreshButton.containsPoint(x, y)) - { - toSpeak = "Refresh Button"; - } - #endregion - - if (toSpeak != " ") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void TitleMenuPatch(TitleMenu __instance, bool ___isTransitioningButtons) - { - try - { - if (___isTransitioningButtons) - return; - - string toSpeak = ""; - - __instance.buttons.ForEach(component => - { - if (component.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string name = component.name; - string label = component.label; - toSpeak = $"{name} {label} Button"; - } - }); - - if (__instance.muteMusicButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "Mute Music Button"; - } - - if (__instance.aboutButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "About Button"; - } - - if (__instance.languageButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "Language Button"; - } - - if (__instance.windowedButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "Fullscreen: " + ((Game1.isFullscreen) ? "enabled" : "disabled"); - } - - if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string text = "Back Button"; - MainClass.ScreenReader.SayWithChecker(text, true); - } - - // Fix for back button not working using keyboard - if (TitleMenu.subMenu is CharacterCustomization && ((CharacterCustomization)TitleMenu.subMenu).backButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - // Perform Left Click - if (MainClass.Config.LeftClickMainKey.JustPressed()) - { - __instance.backButtonPressed(); - } - } - - if (TitleMenu.subMenu == null && toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void LoadGameMenuPatch(SaveFileSlot __instance, LoadGameMenu ___menu, int i) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - if (___menu.slotButtons[i].containsPoint(x, y)) - { - if (__instance.Farmer != null) - { - #region Farms - if (___menu.deleteButtons.Count > 0 && ___menu.deleteButtons[i].containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithChecker($"Delete {__instance.Farmer.farmName.Value} Farm", true); - return; - } - - if (___menu.deleteConfirmationScreen) - { - // Used diff. functions to narrate to prevent it from speaking the message again on selecting another button. - string message = "Really delete farm?"; - - MainClass.ScreenReader.SayWithChecker(message, true); - if (___menu.okDeleteButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker("Ok Button", false); - } - else if (___menu.cancelDeleteButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker("Cancel Button", false); - } - return; - } - - String farmerName = __instance.Farmer.displayName; - String farmName = __instance.Farmer.farmName.Value; - String money = __instance.Farmer.Money.ToString(); - String hoursPlayed = Utility.getHoursMinutesStringFromMilliseconds(__instance.Farmer.millisecondsPlayed); - string dateStringForSaveGame = ((!__instance.Farmer.dayOfMonthForSaveGame.HasValue || - !__instance.Farmer.seasonForSaveGame.HasValue || - !__instance.Farmer.yearForSaveGame.HasValue) ? __instance.Farmer.dateStringForSaveGame : Utility.getDateStringFor(__instance.Farmer.dayOfMonthForSaveGame.Value, __instance.Farmer.seasonForSaveGame.Value, __instance.Farmer.yearForSaveGame.Value)); - - string toSpeak = $"{farmName} Farm Selected, \t\n Farmer: {farmerName}, \t\nMoney: {money}, \t\nHours Played: {hoursPlayed}, \t\nDate: {dateStringForSaveGame}"; - - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - #endregion - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - } -} diff --git a/stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs b/stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs new file mode 100644 index 0000000..606ab1c --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs @@ -0,0 +1,85 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class AdvancedGameOptionsPatch + { + public static string advancedGameOptionsQueryKey = " "; + + internal static void DrawPatch(AdvancedGameOptions __instance) + { + try + { + int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "OK Button"; + if (advancedGameOptionsQueryKey != toSpeak) + { + advancedGameOptionsQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + 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)) + continue; + + 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 (optionsElement is OptionsTextEntry) + { + toSpeak = $"Seed text box"; + } + else + { + if (toSpeak.Contains(":")) + toSpeak = toSpeak.Replace(":", ""); + + toSpeak = $"{toSpeak} Options:"; + } + + if (advancedGameOptionsQueryKey != toSpeak) + { + advancedGameOptionsQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in advanced game menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + advancedGameOptionsQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches/CharacterCustomizationMenuPatches.cs similarity index 99% rename from stardew-access/Patches/CharacterCustomizationMenuPatches.cs rename to stardew-access/Patches/TitleMenuPatches/CharacterCustomizationMenuPatches.cs index fa3e13f..005456d 100644 --- a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs +++ b/stardew-access/Patches/TitleMenuPatches/CharacterCustomizationMenuPatches.cs @@ -119,7 +119,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + MainClass.ErrorLog($"An error occured in character customization menu patch:\n{e.Message}\n{e.StackTrace}"); } } diff --git a/stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs b/stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs new file mode 100644 index 0000000..3f4eb6a --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs @@ -0,0 +1,59 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class CoopMenuPatch + { + private static string coopMenuQueryKey = ""; + + internal static void DrawPatch(CoopMenu __instance, CoopMenu.Tab ___currentTab) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string toSpeak = ""; + + #region Join/Host Button (Important! This should be checked before checking other buttons) + if (__instance.slotButtons[0].containsPoint(x, y)) + { + if (___currentTab == CoopMenu.Tab.JOIN_TAB) + toSpeak = "Join lan game"; + if (___currentTab == CoopMenu.Tab.HOST_TAB) + toSpeak = "Host new farm"; + } + #endregion + + #region Other Buttons + if (__instance.joinTab.containsPoint(x, y)) + { + toSpeak = "Join Tab Button"; + } + else if (__instance.hostTab.containsPoint(x, y)) + { + toSpeak = "Host Tab Button"; + } + else if (__instance.refreshButton.containsPoint(x, y)) + { + toSpeak = "Refresh Button"; + } + #endregion + + if (coopMenuQueryKey != toSpeak) + { + coopMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in co-op menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + coopMenuQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs b/stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs new file mode 100644 index 0000000..df16a22 --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs @@ -0,0 +1,86 @@ +using StardewValley; +using StardewValley.Menus; +using static StardewValley.Menus.LoadGameMenu; + +namespace stardew_access.Patches +{ + internal class LoadGameMenuPatch + { + private static string loadGameMenuQueryKey = ""; + private static bool firstTimeInMenu = true; + + internal static void DrawPatch(SaveFileSlot __instance, LoadGameMenu ___menu, int i) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string toSpeak = ""; + + if (!___menu.slotButtons[i].containsPoint(x, y)) return; + if (__instance.Farmer == null) return; + + if (___menu.deleteButtons.Count > 0 && ___menu.deleteButtons[i].containsPoint(x, y)) + { + toSpeak = $"Delete {__instance.Farmer.farmName.Value} Farm"; + if (loadGameMenuQueryKey != toSpeak) + { + loadGameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (___menu.deleteConfirmationScreen) + { + if (firstTimeInMenu) + { + firstTimeInMenu = false; + toSpeak = "Really delete farm?"; + } + + if (___menu.okDeleteButton.containsPoint(x, y)) + { + toSpeak = $"{toSpeak} Ok button"; + } + else if (___menu.cancelDeleteButton.containsPoint(x, y)) + { + toSpeak = $"{toSpeak} Cancel button"; + } + + if (loadGameMenuQueryKey != toSpeak) + { + loadGameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + String farmerName = __instance.Farmer.displayName; + String farmName = __instance.Farmer.farmName.Value; + String money = __instance.Farmer.Money.ToString(); + String hoursPlayed = Utility.getHoursMinutesStringFromMilliseconds(__instance.Farmer.millisecondsPlayed); + string dateStringForSaveGame = ((!__instance.Farmer.dayOfMonthForSaveGame.HasValue || + !__instance.Farmer.seasonForSaveGame.HasValue || + !__instance.Farmer.yearForSaveGame.HasValue) ? __instance.Farmer.dateStringForSaveGame : Utility.getDateStringFor(__instance.Farmer.dayOfMonthForSaveGame.Value, __instance.Farmer.seasonForSaveGame.Value, __instance.Farmer.yearForSaveGame.Value)); + + toSpeak = $"{farmName} Farm Selected, \t\n Farmer: {farmerName}, \t\nMoney: {money}, \t\nHours Played: {hoursPlayed}, \t\nDate: {dateStringForSaveGame}"; + + if (loadGameMenuQueryKey != toSpeak) + { + loadGameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in load game menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + loadGameMenuQueryKey = ""; + firstTimeInMenu = true; + } + } +} diff --git a/stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs new file mode 100644 index 0000000..7dbf06f --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs @@ -0,0 +1,81 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TitleMenuPatch + { + private static string titleMenuQueryKey = ""; + + internal static void DrawPatch(TitleMenu __instance, bool ___isTransitioningButtons) + { + try + { + if (___isTransitioningButtons) + return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = ""; + + if (__instance.muteMusicButton.containsPoint(x, y)) + { + toSpeak = "Mute Music Button"; + } + else if (__instance.aboutButton.containsPoint(x, y)) + { + toSpeak = "About Button"; + } + else if (__instance.languageButton.containsPoint(x, y)) + { + toSpeak = "Language Button"; + } + else if (__instance.windowedButton.containsPoint(x, y)) + { + toSpeak = "Fullscreen: " + ((Game1.isFullscreen) ? "enabled" : "disabled"); + } + else if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(x, y)) + { + string text = "Back Button"; + MainClass.ScreenReader.SayWithChecker(text, true); + } + else + { + __instance.buttons.ForEach(component => + { + if (!component.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + return; + + string name = component.name; + string label = component.label; + toSpeak = $"{name} {label} Button"; + }); + } + + // Fix for back button not working using keyboard + if (TitleMenu.subMenu is CharacterCustomization && ((CharacterCustomization)TitleMenu.subMenu).backButton.containsPoint(x, y)) + { + // Perform Left Click + if (MainClass.Config.LeftClickMainKey.JustPressed()) + { + __instance.backButtonPressed(); + } + } + + if (TitleMenu.subMenu == null && titleMenuQueryKey!=toSpeak) + { + titleMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in title menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + titleMenuQueryKey = ""; + } + } +} From 8523026ed055dd6d67e925c5b0cb0a2d4598edcb Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:06:46 +0530 Subject: [PATCH 22/40] Improved and organised code for dialogue box patch Moved letter viewer menu patch to its own class moved npc patch to its own clas moved draw hover text patch to IClickableMenuPatch.cs --- stardew-access/HarmonyPatches.cs | 8 +- stardew-access/Patches/DialogueBoxPatch.cs | 131 ++++++ stardew-access/Patches/DialoguePatches.cs | 427 ------------------ .../GameMenuPatches/CollectionsPagePatch.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 194 +++++++- .../Patches/LetterViewerMenuPatch.cs | 95 ++++ stardew-access/Patches/MiniGamesPatches.cs | 4 +- stardew-access/Patches/NPCPatch.cs | 22 + 8 files changed, 446 insertions(+), 437 deletions(-) create mode 100644 stardew-access/Patches/DialogueBoxPatch.cs delete mode 100644 stardew-access/Patches/DialoguePatches.cs create mode 100644 stardew-access/Patches/LetterViewerMenuPatch.cs create mode 100644 stardew-access/Patches/NPCPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index c5c26cf..f2dd7ff 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -21,17 +21,17 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.ClearDialogueString)) + postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.RecieveLeftClickPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.drawHoverText), new Type[] { typeof(SpriteBatch), typeof(string), typeof(SpriteFont), typeof(int), typeof(int), typeof(int), typeof(string), typeof(int), typeof(string[]), typeof(Item), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(float), typeof(CraftingRecipe), typeof(IList) }), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.HoverTextPatch)) + postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.DrawHoverTextPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(NPC), nameof(NPC.drawAboveAlwaysFrontLayer)), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.drawAboveAlwaysFrontLayerPatch)) + postfix: new HarmonyMethod(typeof(NPCPatch), nameof(NPCPatch.DrawAboveAlwaysFrontLayerPatch)) ); #endregion @@ -129,7 +129,7 @@ namespace stardew_access #region Menu Patches harmony.Patch( original: AccessTools.Method(typeof(LetterViewerMenu), nameof(LetterViewerMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.LetterViewerMenuPatch)) + postfix: new HarmonyMethod(typeof(LetterViwerMenuPatch), nameof(LetterViwerMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/DialogueBoxPatch.cs b/stardew-access/Patches/DialogueBoxPatch.cs new file mode 100644 index 0000000..5f036e7 --- /dev/null +++ b/stardew-access/Patches/DialogueBoxPatch.cs @@ -0,0 +1,131 @@ +using Microsoft.Xna.Framework.Graphics; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class DialoguePatches + { + private static string currentDialogue = ""; + private static string previousSpeakerName = ""; + private static bool isDialogueAppearingFirstTime = true; + + internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) + { + try + { + if (__instance.transitioning) return; + + if (narrateCharacterDialogue(__instance)) return; + if (narrateQuestionDialogue(__instance)) return; + narrateBasicDialogue(__instance.getCurrentString()); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); + } + } + + internal static void RecieveLeftClickPatch() + { + // CLears the currentDialogue string on closing dialog + Cleanup(); + } + + private static bool narrateCharacterDialogue(DialogueBox __instance) + { + if (__instance.characterDialogue == null) return false; + + // For Normal Character dialogues + Dialogue dialogue = __instance.characterDialogue; + string speakerName = dialogue.speaker.displayName; + string dialogueText = ""; + string responseText = ""; + bool hasResponses = dialogue.isCurrentDialogueAQuestion(); + + dialogueText = $"{speakerName} said {__instance.getCurrentString()}"; + + if (hasResponses) + { + responseText = getCurrentResponseText(__instance); + + CheckAndSpeak(isDialogueAppearingFirstTime ? $"{dialogueText} \n\t {responseText}" : responseText, responseText); + if (isDialogueAppearingFirstTime) isDialogueAppearingFirstTime = false; + } + else + { + CheckAndSpeak(dialogueText); + } + + return true; + } + + private static bool narrateQuestionDialogue(DialogueBox __instance) + { + if (!__instance.isQuestion) return false; + + // For Dialogues with responses/answers like the dialogue when we click on tv + string questionText = ""; + string responseText = ""; + bool hasResponses = false; + + if (__instance.responses.Count > 0) hasResponses = true; + if (!hasResponses) return false; + + questionText = __instance.getCurrentString(); + + responseText = getCurrentResponseText(__instance); + + CheckAndSpeak(isDialogueAppearingFirstTime ? $"{questionText} \n\t {responseText}" : responseText, responseText); + if (isDialogueAppearingFirstTime) isDialogueAppearingFirstTime = false; + + return true; + } + + private static void narrateBasicDialogue(string dialogue) + { + // Basic dialogues like `No mails in the mail box` + if (Game1.activeClickableMenu is not DialogueBox) return; + CheckAndSpeak(dialogue); + } + + private static string getCurrentResponseText(DialogueBox __instance) + { + List responses = __instance.responses; + if (__instance.selectedResponse >= 0 && __instance.selectedResponse < responses.Count) + { + return $"{__instance.selectedResponse + 1}: {responses[__instance.selectedResponse].responseText}"; + } + else + { + // When the dialogue is not finished writing then the selectedResponse is <0 and this results + // in the first response not being detcted, so this sets the first response option to be the default + // if the current dialogue is a question or has responses + return $"1: {responses[0].responseText}"; + } + } + + private static void CheckAndSpeak(string toSpeak) + { + if (currentDialogue == toSpeak) return; + currentDialogue = toSpeak; + + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void CheckAndSpeak(string toSpeak, string checkQuery) + { + if (currentDialogue == checkQuery) return; + currentDialogue = checkQuery; + + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + currentDialogue = ""; + isDialogueAppearingFirstTime = true; + } + } +} diff --git a/stardew-access/Patches/DialoguePatches.cs b/stardew-access/Patches/DialoguePatches.cs deleted file mode 100644 index e131952..0000000 --- a/stardew-access/Patches/DialoguePatches.cs +++ /dev/null @@ -1,427 +0,0 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class DialoguePatches - { - internal static string currentLetterText = " "; - internal static string currentDialogue = " "; - internal static bool isDialogueAppearingFirstTime = true; - - internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) - { - try - { - if (__instance.transitioning) - return; - - if (__instance.characterDialogue != null) - { - // For Normal Character dialogues - Dialogue dialogue = __instance.characterDialogue; - string speakerName = dialogue.speaker.displayName; - List responses = __instance.responses; - string toSpeak = " "; - string dialogueText = ""; - string response = ""; - bool hasResponses = dialogue.isCurrentDialogueAQuestion(); - - dialogueText = $"{speakerName} said {__instance.getCurrentString()}"; - - if (hasResponses) - { - if (__instance.selectedResponse >= 0 && __instance.selectedResponse < responses.Count) - response = $"{__instance.selectedResponse + 1}: {responses[__instance.selectedResponse].responseText}"; - else - // When the dialogue is not finished writing then the selectedResponse is <0 and this results - // in the first response not being detcted, so this sets the first response option to be the default - // if the current dialogue is a question or has responses - response = $"1: {responses[0].responseText}"; - } - - if (hasResponses) - { - if (currentDialogue != response) - { - currentDialogue = response; - - if (isDialogueAppearingFirstTime) - { - toSpeak = $"{dialogueText} \n\t {response}"; - isDialogueAppearingFirstTime = false; - } - else - toSpeak = response; - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - if (currentDialogue != dialogueText) - { - currentDialogue = dialogueText; - MainClass.ScreenReader.Say(dialogueText, true); - } - } - } - else if (__instance.isQuestion) - { - // For Dialogues with responses/answers like the dialogue when we click on tv - string toSpeak = ""; - string dialogueText = ""; - string response = ""; - bool hasResponses = false; - - if (__instance.responses.Count > 0) - hasResponses = true; - - dialogueText = __instance.getCurrentString(); - - if (hasResponses) - if (__instance.selectedResponse >= 0 && __instance.selectedResponse < __instance.responses.Count) - response = $"{__instance.selectedResponse + 1}: {__instance.responses[__instance.selectedResponse].responseText}"; - else - // When the dialogue is not finished writing then the selectedResponse is <0 and this results - // in the first response not being detcted, so this sets the first response option to be the default - // if the current dialogue is a question or has responses - response = $"1: {__instance.responses[0].responseText}"; - - - if (hasResponses) - { - if (currentDialogue != response) - { - currentDialogue = response; - - if (isDialogueAppearingFirstTime) - { - toSpeak = $"{dialogueText} \n\t {response}"; - isDialogueAppearingFirstTime = false; - } - else - toSpeak = response; - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - if (currentDialogue != dialogueText) - { - currentDialogue = dialogueText; - MainClass.ScreenReader.Say(dialogueText, true); - } - } - } - else if (Game1.activeClickableMenu is DialogueBox) - { - // Basic dialogues like `No mails in the mail box` - if (currentDialogue != __instance.getCurrentString()) - { - currentDialogue = __instance.getCurrentString(); - MainClass.ScreenReader.Say(__instance.getCurrentString(), true); - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); - } - - } - - internal static void ClearDialogueString() - { - // CLears the currentDialogue string on closing dialog - currentDialogue = " "; - isDialogueAppearingFirstTime = true; - } - - internal static void HoverTextPatch(string? text, int moneyAmountToDisplayAtBottom = -1, string? boldTitleText = null, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, string[]? buffIconsToDisplay = null, Item? hoveredItem = null, CraftingRecipe? craftingIngredients = null) - { - try - { - #region Skip narrating hover text for certain menus - if (Game1.activeClickableMenu is TitleMenu && !(((TitleMenu)Game1.activeClickableMenu).GetChildMenu() is CharacterCustomization)) - return; - else if (Game1.activeClickableMenu is LetterViewerMenu || Game1.activeClickableMenu is QuestLog) - return; - else if (Game1.activeClickableMenu is Billboard) - return; - else if (Game1.activeClickableMenu is GeodeMenu) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is InventoryPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is CraftingPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is OptionsPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is ExitPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is SocialPage) - return; - else if (Game1.activeClickableMenu is ItemGrabMenu) - return; - else if (Game1.activeClickableMenu is ShopMenu) - return; - else if (Game1.activeClickableMenu is ConfirmationDialog) - return; - else if (Game1.activeClickableMenu is JunimoNoteMenu) - return; - else if (Game1.activeClickableMenu is CarpenterMenu) - return; - else if (Game1.activeClickableMenu is PurchaseAnimalsMenu) - return; - else if (Game1.activeClickableMenu is CraftingPage) - return; - else if (Game1.activeClickableMenu is AnimalQueryMenu) - return; - else if (Game1.activeClickableMenu is ConfirmationDialog) - return; - else if (Game1.activeClickableMenu is ReadyCheckDialog) - return; - else if (Game1.activeClickableMenu is JojaCDMenu) - return; - else if (Game1.activeClickableMenu is TailoringMenu) - return; - else if (Game1.activeClickableMenu is PondQueryMenu) - return; - else if (Game1.activeClickableMenu is ForgeMenu) - return; - else if (Game1.activeClickableMenu is ItemListMenu) - return; - else if (Game1.activeClickableMenu is FieldOfficeMenu) - return; - else if (Game1.activeClickableMenu is MuseumMenu) - return; - #endregion - - string toSpeak = " "; - - #region Add item count before title - if (hoveredItem != null && hoveredItem.HasBeenInInventory) - { - int count = hoveredItem.Stack; - if (count > 1) - toSpeak = $"{toSpeak} {count} "; - } - #endregion - - #region Add title if any - if (boldTitleText != null) - toSpeak = $"{toSpeak} {boldTitleText}\n"; - #endregion - - #region Add quality of item - if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Quality > 0) - { - int quality = ((StardewValley.Object)hoveredItem).Quality; - if (quality == 1) - { - toSpeak = $"{toSpeak} Silver quality"; - } - else if (quality == 2 || quality == 3) - { - toSpeak = $"{toSpeak} Gold quality"; - } - else if (quality >= 4) - { - toSpeak = $"{toSpeak} Iridium quality"; - } - } - #endregion - - #region Narrate hovered required ingredients - if (extraItemToShowIndex != -1) - { - string itemName = Game1.objectInformation[extraItemToShowIndex].Split('/')[0]; - - if (extraItemToShowAmount != -1) - toSpeak = $"{toSpeak} Required: {extraItemToShowAmount} {itemName}"; - else - toSpeak = $"{toSpeak} Required: {itemName}"; - } - #endregion - - #region Add money - if (moneyAmountToDisplayAtBottom != -1) - toSpeak = $"{toSpeak} \nCost: {moneyAmountToDisplayAtBottom}g\n"; - #endregion - - #region Add the base text - if (text == "???") - toSpeak = "unknown"; - else - toSpeak = $"{toSpeak} {text}"; - #endregion - - #region Add crafting ingredients - if (craftingIngredients != null) - { - toSpeak = $"{toSpeak} \n{craftingIngredients.description}"; - toSpeak = $"{toSpeak} \nIngredients\n"; - - craftingIngredients.recipeList.ToList().ForEach(recipe => - { - int count = recipe.Value; - int item = recipe.Key; - string name = craftingIngredients.getNameFromIndex(item); - - toSpeak = $"{toSpeak} ,{count} {name}"; - }); - } - #endregion - - #region Add health & stamina - if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Edibility != -300) - { - int stamina_recovery = ((StardewValley.Object)hoveredItem).staminaRecoveredOnConsumption(); - toSpeak = $"{toSpeak} {stamina_recovery} Energy\n"; - if (stamina_recovery >= 0) - { - int health_recovery = ((StardewValley.Object)hoveredItem).healthRecoveredOnConsumption(); - toSpeak = $"{toSpeak} {health_recovery} Health"; - } - } - #endregion - - #region Add buff items (effects like +1 walking speed) - if (buffIconsToDisplay != null) - { - for (int i = 0; i < buffIconsToDisplay.Length; i++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[i]) > 0) ? "+" : "") + buffIconsToDisplay[i] + " "; - if (i <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + i, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - toSpeak = $"{toSpeak} {buffName}\n"; - } - catch (Exception) { } - } - } - #endregion - - #region Narrate toSpeak - // To prevent it from getting conflicted by two hover texts at the same time, two seperate methods are used. - // For example, sometimes `Welcome to Pierre's` and the items in seeds shop get conflicted causing it to speak infinitely. - - if (toSpeak.ToString() != " ") - { - if (Context.IsPlayerFree) - MainClass.ScreenReader.SayWithChecker(toSpeak.ToString(), true); // Normal Checker - else - MainClass.ScreenReader.SayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker - } - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); - } - } - - internal static void LetterViewerMenuPatch(LetterViewerMenu __instance) - { - try - { - if (!__instance.IsActive()) - return; - - NarrateLetterContent(__instance); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void NarrateLetterContent(LetterViewerMenu __instance) - { - int x = Game1.getMousePosition().X, y = Game1.getMousePosition().Y; - #region Texts in the letter - string message = __instance.mailMessage[__instance.page]; - - string toSpeak = $"{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; - - // snap mouse to accept quest button - if (__instance.acceptQuestButton != null && __instance.questID != -1) - { - toSpeak += "\t\n Left click to accept quest."; - __instance.acceptQuestButton.snapMouseCursorToCenter(); - } - if (__instance.mailMessage.Count > 1) - toSpeak = $"Page {__instance.page + 1} of {__instance.mailMessage.Count}:\n\t{toSpeak}"; - - MainClass.ScreenReader.Say(toSpeak, true); - } - #endregion - - #region Narrate items given in the mail - if (__instance.ShouldShowInteractable()) - { - foreach (ClickableComponent c in __instance.itemsToGrab) - { - if (c.item == null) - continue; - - string name = c.item.DisplayName; - - if (c.containsPoint(x, y)) - MainClass.ScreenReader.SayWithChecker($"Left click to collect {name}", false); - } - } - #endregion - - #region Narrate buttons - if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) - MainClass.ScreenReader.SayWithChecker($"Previous page button", false); - - if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) - MainClass.ScreenReader.SayWithChecker($"Next page button", false); - - #endregion - } - - internal static void drawAboveAlwaysFrontLayerPatch(NPC __instance, string ___textAboveHead, int ___textAboveHeadTimer) - { - try - { - if (___textAboveHeadTimer > 2900 && ___textAboveHead != null) - { - MainClass.ScreenReader.SayWithChecker($"{__instance.displayName} says {___textAboveHead}", true); - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Error in patch:NPCShowTextAboveHeadPatch \n{e.Message}\n{e.StackTrace}"); - } - } - } -} diff --git a/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs index a708930..fdbaee4 100644 --- a/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs @@ -9,7 +9,7 @@ namespace stardew_access.Patches int x = StardewValley.Game1.getMousePosition().X, y = StardewValley.Game1.getMousePosition().Y; if (__instance.letterviewerSubMenu != null) { - DialoguePatches.NarrateLetterContent(__instance.letterviewerSubMenu); + LetterViwerMenuPatch.narrateLetterContent(__instance.letterviewerSubMenu); } } catch (System.Exception e) diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index b0a6c8c..8e92817 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -1,3 +1,4 @@ +using StardewValley; using StardewValley.Menus; namespace stardew_access.Patches @@ -5,6 +6,194 @@ namespace stardew_access.Patches // These patches are global, i.e. work on every menus internal class IClickableMenuPatch { + internal static void DrawHoverTextPatch(string? text, int moneyAmountToDisplayAtBottom = -1, string? boldTitleText = null, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, string[]? buffIconsToDisplay = null, Item? hoveredItem = null, CraftingRecipe? craftingIngredients = null) + { + try + { + #region Skip narrating hover text for certain menus + if (Game1.activeClickableMenu is TitleMenu && !(((TitleMenu)Game1.activeClickableMenu).GetChildMenu() is CharacterCustomization)) + return; + else if (Game1.activeClickableMenu is LetterViewerMenu || Game1.activeClickableMenu is QuestLog) + return; + else if (Game1.activeClickableMenu is Billboard) + return; + else if (Game1.activeClickableMenu is GeodeMenu) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is InventoryPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is CraftingPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is OptionsPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is ExitPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is SocialPage) + return; + else if (Game1.activeClickableMenu is ItemGrabMenu) + return; + else if (Game1.activeClickableMenu is ShopMenu) + return; + else if (Game1.activeClickableMenu is ConfirmationDialog) + return; + else if (Game1.activeClickableMenu is JunimoNoteMenu) + return; + else if (Game1.activeClickableMenu is CarpenterMenu) + return; + else if (Game1.activeClickableMenu is PurchaseAnimalsMenu) + return; + else if (Game1.activeClickableMenu is CraftingPage) + return; + else if (Game1.activeClickableMenu is AnimalQueryMenu) + return; + else if (Game1.activeClickableMenu is ConfirmationDialog) + return; + else if (Game1.activeClickableMenu is ReadyCheckDialog) + return; + else if (Game1.activeClickableMenu is JojaCDMenu) + return; + else if (Game1.activeClickableMenu is TailoringMenu) + return; + else if (Game1.activeClickableMenu is PondQueryMenu) + return; + else if (Game1.activeClickableMenu is ForgeMenu) + return; + else if (Game1.activeClickableMenu is ItemListMenu) + return; + else if (Game1.activeClickableMenu is FieldOfficeMenu) + return; + else if (Game1.activeClickableMenu is MuseumMenu) + return; + #endregion + + string toSpeak = " "; + + #region Add item count before title + if (hoveredItem != null && hoveredItem.HasBeenInInventory) + { + int count = hoveredItem.Stack; + if (count > 1) + toSpeak = $"{toSpeak} {count} "; + } + #endregion + + #region Add title if any + if (boldTitleText != null) + toSpeak = $"{toSpeak} {boldTitleText}\n"; + #endregion + + #region Add quality of item + if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Quality > 0) + { + int quality = ((StardewValley.Object)hoveredItem).Quality; + if (quality == 1) + { + toSpeak = $"{toSpeak} Silver quality"; + } + else if (quality == 2 || quality == 3) + { + toSpeak = $"{toSpeak} Gold quality"; + } + else if (quality >= 4) + { + toSpeak = $"{toSpeak} Iridium quality"; + } + } + #endregion + + #region Narrate hovered required ingredients + if (extraItemToShowIndex != -1) + { + string itemName = Game1.objectInformation[extraItemToShowIndex].Split('/')[0]; + + if (extraItemToShowAmount != -1) + toSpeak = $"{toSpeak} Required: {extraItemToShowAmount} {itemName}"; + else + toSpeak = $"{toSpeak} Required: {itemName}"; + } + #endregion + + #region Add money + if (moneyAmountToDisplayAtBottom != -1) + toSpeak = $"{toSpeak} \nCost: {moneyAmountToDisplayAtBottom}g\n"; + #endregion + + #region Add the base text + if (text == "???") + toSpeak = "unknown"; + else + toSpeak = $"{toSpeak} {text}"; + #endregion + + #region Add crafting ingredients + if (craftingIngredients != null) + { + toSpeak = $"{toSpeak} \n{craftingIngredients.description}"; + toSpeak = $"{toSpeak} \nIngredients\n"; + + craftingIngredients.recipeList.ToList().ForEach(recipe => + { + int count = recipe.Value; + int item = recipe.Key; + string name = craftingIngredients.getNameFromIndex(item); + + toSpeak = $"{toSpeak} ,{count} {name}"; + }); + } + #endregion + + #region Add health & stamina + if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Edibility != -300) + { + int stamina_recovery = ((StardewValley.Object)hoveredItem).staminaRecoveredOnConsumption(); + toSpeak = $"{toSpeak} {stamina_recovery} Energy\n"; + if (stamina_recovery >= 0) + { + int health_recovery = ((StardewValley.Object)hoveredItem).healthRecoveredOnConsumption(); + toSpeak = $"{toSpeak} {health_recovery} Health"; + } + } + #endregion + + #region Add buff items (effects like +1 walking speed) + if (buffIconsToDisplay != null) + { + for (int i = 0; i < buffIconsToDisplay.Length; i++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[i]) > 0) ? "+" : "") + buffIconsToDisplay[i] + " "; + if (i <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + i, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + toSpeak = $"{toSpeak} {buffName}\n"; + } + catch (Exception) { } + } + } + #endregion + + #region Narrate toSpeak + // To prevent it from getting conflicted by two hover texts at the same time, two seperate methods are used. + // For example, sometimes `Welcome to Pierre's` and the items in seeds shop get conflicted causing it to speak infinitely. + + if (toSpeak.ToString() != " ") + { + if (StardewModdingAPI.Context.IsPlayerFree) + MainClass.ScreenReader.SayWithChecker(toSpeak.ToString(), true); // Normal Checker + else + MainClass.ScreenReader.SayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker + } + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); + } + } + internal static void ExitThisMenuPatch(IClickableMenu __instance) { try @@ -37,7 +226,7 @@ namespace stardew_access.Patches } else if (menu is LetterViewerMenu) { - DialoguePatches.currentLetterText = " "; + LetterViwerMenuPatch.Cleanup(); } else if (menu is LevelUpMenu) { @@ -94,8 +283,7 @@ namespace stardew_access.Patches } else if (menu is DialogueBox) { - DialoguePatches.isDialogueAppearingFirstTime = true; - DialoguePatches.currentDialogue = " "; + DialoguePatches.Cleanup(); } else if (menu is JojaCDMenu) { diff --git a/stardew-access/Patches/LetterViewerMenuPatch.cs b/stardew-access/Patches/LetterViewerMenuPatch.cs new file mode 100644 index 0000000..de7eabb --- /dev/null +++ b/stardew-access/Patches/LetterViewerMenuPatch.cs @@ -0,0 +1,95 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class LetterViwerMenuPatch + { + private static string currentLetterText = ""; + + internal static void DrawPatch(LetterViewerMenu __instance) + { + try + { + if (!__instance.IsActive()) + return; + + narrateLetterContent(__instance); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void narrateLetterContent(LetterViewerMenu __instance) + { + int x = Game1.getMousePosition().X, y = Game1.getMousePosition().Y; + #region Texts in the letter + string message = __instance.mailMessage[__instance.page]; + + string toSpeak = $"{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; + + // snap mouse to accept quest button + if (__instance.acceptQuestButton != null && __instance.questID != -1) + { + toSpeak += "\t\n Left click to accept quest."; + __instance.acceptQuestButton.snapMouseCursorToCenter(); + } + if (__instance.mailMessage.Count > 1) + toSpeak = $"Page {__instance.page + 1} of {__instance.mailMessage.Count}:\n\t{toSpeak}"; + + MainClass.ScreenReader.Say(toSpeak, true); + } + #endregion + + #region Narrate items given in the mail + if (__instance.ShouldShowInteractable()) + { + foreach (ClickableComponent c in __instance.itemsToGrab) + { + if (c.item == null) + continue; + + string name = c.item.DisplayName; + + if (c.containsPoint(x, y)) + MainClass.ScreenReader.SayWithChecker($"Left click to collect {name}", false); + } + } + #endregion + + #region Narrate buttons + if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) + MainClass.ScreenReader.SayWithChecker($"Previous page button", false); + + if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) + MainClass.ScreenReader.SayWithChecker($"Next page button", false); + + #endregion + } + + internal static void Cleanup() + { + currentLetterText = ""; + } + } +} diff --git a/stardew-access/Patches/MiniGamesPatches.cs b/stardew-access/Patches/MiniGamesPatches.cs index 8addd64..07480bf 100644 --- a/stardew-access/Patches/MiniGamesPatches.cs +++ b/stardew-access/Patches/MiniGamesPatches.cs @@ -49,7 +49,7 @@ namespace stardew_access.Patches if (___letterView != null) { - DialoguePatches.NarrateLetterContent(___letterView); + LetterViwerMenuPatch.narrateLetterContent(___letterView); } if (MainClass.ModHelper == null) @@ -117,4 +117,4 @@ namespace stardew_access.Patches return new Rectangle((int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.viewport, 1294, 730).X + (286 - ___parallaxPan) * 4, (int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.viewport, 1294, 730).Y + 218 + Math.Max(0, Math.Min(60, (___grandpaSpeechTimer - 5000) / 8)), 524, 344); } } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/NPCPatch.cs b/stardew-access/Patches/NPCPatch.cs new file mode 100644 index 0000000..41f9306 --- /dev/null +++ b/stardew-access/Patches/NPCPatch.cs @@ -0,0 +1,22 @@ +using StardewValley; + +namespace stardew_access.Patches +{ + internal class NPCPatch + { + internal static void DrawAboveAlwaysFrontLayerPatch(NPC __instance, string ___textAboveHead, int ___textAboveHeadTimer) + { + try + { + if (___textAboveHeadTimer > 2900 && ___textAboveHead != null) + { + MainClass.ScreenReader.SayWithChecker($"{__instance.displayName} says {___textAboveHead}", true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Error in patch:NPCShowTextAboveHeadPatch \n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 80963c4dc629cb89a03ca082900a517803525002 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:21:50 +0530 Subject: [PATCH 23/40] Improved and organised code in shop menu patch --- stardew-access/HarmonyPatches.cs | 4 +- stardew-access/Patches/DialogueBoxPatch.cs | 9 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ShopMenuPatch.cs | 146 +++++++++--------- 4 files changed, 77 insertions(+), 84 deletions(-) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index f2dd7ff..a77c76e 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -16,12 +16,12 @@ namespace stardew_access #region Dialogue Patches harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.DialoguePatch)) + postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.RecieveLeftClickPatch)) + postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.RecieveLeftClickPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/DialogueBoxPatch.cs b/stardew-access/Patches/DialogueBoxPatch.cs index 5f036e7..bc471d6 100644 --- a/stardew-access/Patches/DialogueBoxPatch.cs +++ b/stardew-access/Patches/DialogueBoxPatch.cs @@ -1,17 +1,14 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; +using StardewValley; using StardewValley.Menus; namespace stardew_access.Patches { - internal class DialoguePatches + internal class DialogueBoxPatch { private static string currentDialogue = ""; - private static string previousSpeakerName = ""; private static bool isDialogueAppearingFirstTime = true; - internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) + internal static void DrawPatch(DialogueBox __instance) { try { diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 8e92817..765efbd 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -283,7 +283,7 @@ namespace stardew_access.Patches } else if (menu is DialogueBox) { - DialoguePatches.Cleanup(); + DialogueBoxPatch.Cleanup(); } else if (menu is JojaCDMenu) { diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 8da8b11..5f5e16b 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -25,88 +25,15 @@ namespace stardew_access.Patches __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); } - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) - { - string toSpeak = "Up Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) - { - string toSpeak = "Down Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion + if (narrateHoveredButton(__instance, x, y)) return; - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) { shopMenuQueryKey = ""; return; } - #endregion - #region Narrate hovered selling item - if (__instance.hoveredItem != null) - { - string name = __instance.hoveredItem.DisplayName; - string price = $"Buy Price: {__instance.hoverPrice} g"; - string description = __instance.hoveredItem.getDescription(); - string requirements = ""; - - #region Narrate required items for item - int itemIndex = -1, itemAmount = 5; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) - itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) - itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; - - if (itemIndex != -1) - { - string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; - - if (itemAmount != -1) - requirements = $"Required: {itemAmount} {itemName}"; - else - requirements = $"Required: {itemName}"; - } - #endregion - - string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion + narrateHoveredSellingItem(__instance); } catch (Exception e) { @@ -114,6 +41,75 @@ namespace stardew_access.Patches } } + private static bool narrateHoveredButton(ShopMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) + { + toSpeak = "Up Arrow Button"; + } + else if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) + { + toSpeak = "Down Arrow Button"; + } + else + { + return false; + } + + if (shopMenuQueryKey == toSpeak) return true; + + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + + private static void narrateHoveredSellingItem(ShopMenu __instance) + { + if (__instance.hoveredItem == null) return; + + string name = __instance.hoveredItem.DisplayName; + string price = $"Buy Price: {__instance.hoverPrice} g"; + string description = __instance.hoveredItem.getDescription(); + string requirements = ""; + + #region get required items for item + int itemIndex = -1, itemAmount = 5; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) + itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) + itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; + + if (itemIndex != -1) + { + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + requirements = $"Required: {itemAmount} {itemName}"; + else + requirements = $"Required: {itemName}"; + } + #endregion + + string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; + if (shopMenuQueryKey == toSpeak) return; + + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + internal static void Cleanup() { shopMenuQueryKey = ""; From 6822bd48404166c96a7aff8abcc981a6ba651180 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:29:19 +0530 Subject: [PATCH 24/40] Organised code for purchase animal menu patch --- stardew-access/Patches/IClickableMenuPatch.cs | 4 +- .../Patches/PurchaseAnimalsMenuPatch.cs | 124 ++++++++++-------- 2 files changed, 69 insertions(+), 59 deletions(-) diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 765efbd..36bb1cc 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -273,9 +273,7 @@ namespace stardew_access.Patches } else if (menu is PurchaseAnimalsMenu) { - PurchaseAnimalsMenuPatch.purchaseAnimalMenuQuery = ""; - PurchaseAnimalsMenuPatch.firstTimeInNamingMenu = true; - PurchaseAnimalsMenuPatch.purchaseAnimalsMenu = null; + PurchaseAnimalsMenuPatch.Cleanup(); } else if (menu is AnimalQueryMenu) { diff --git a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs index 0828c06..8ff6dff 100644 --- a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs +++ b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs @@ -24,39 +24,7 @@ namespace stardew_access.Patches if (___onFarm && ___namingAnimal) { - string toSpeak = ""; - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "Cancel Button"; - } - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - { - toSpeak = "OK Button"; - } - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - { - toSpeak = "Random Name Button"; - } - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - { - toSpeak = "Name Text Box"; - // string? value = ___textBox.Text; - // if (value != "" && value != null && value != "null") - // toSpeak = $"{toSpeak}, Value: {value}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = toSpeak; - - if (firstTimeInNamingMenu) - { - toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; - firstTimeInNamingMenu = false; - } - - MainClass.ScreenReader.Say(toSpeak, true); - } + narrateNamingMenu(__instance, x, y); } else if (___onFarm && !___namingAnimal) { @@ -65,29 +33,7 @@ namespace stardew_access.Patches else if (!___onFarm && !___namingAnimal) { firstTimeInNamingMenu = true; - if (__instance.hovered != null) - { - string toSpeak = ""; - if (((StardewValley.Object)__instance.hovered.item).Type != null) - { - toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; - } - else - { - string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); - int price = __instance.hovered.item.salePrice(); - string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); - - toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } + narratePurchasingMenu(__instance); } } catch (Exception e) @@ -96,6 +42,72 @@ namespace stardew_access.Patches } } + private static void narrateNamingMenu(PurchaseAnimalsMenu __instance, int x, int y) + { + string toSpeak = ""; + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Cancel Button"; + } + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + { + toSpeak = "OK Button"; + } + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + { + toSpeak = "Random Name Button"; + } + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + { + toSpeak = "Name Text Box"; + // string? value = ___textBox.Text; + // if (value != "" && value != null && value != "null") + // toSpeak = $"{toSpeak}, Value: {value}"; + } + if (purchaseAnimalMenuQuery == toSpeak) return; + + purchaseAnimalMenuQuery = toSpeak; + + if (firstTimeInNamingMenu) + { + toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; + firstTimeInNamingMenu = false; + } + + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void narratePurchasingMenu(PurchaseAnimalsMenu __instance) + { + if (__instance.hovered == null) + return; + + string toSpeak = ""; + if (((StardewValley.Object)__instance.hovered.item).Type != null) + { + toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; + } + else + { + string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); + int price = __instance.hovered.item.salePrice(); + string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); + + toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; + } + + if (purchaseAnimalMenuQuery == toSpeak) return; + + purchaseAnimalMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + purchaseAnimalMenuQuery = ""; + firstTimeInNamingMenu = true; + purchaseAnimalsMenu = null; + } } } From 5195313a5b86974b6505b54ffcaa7abebddcf9e1 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:44:07 +0530 Subject: [PATCH 25/40] Organised code for item grab menu patch --- stardew-access/Patches/ItemGrabMenuPatch.cs | 235 +++++++++----------- stardew-access/Patches/ShopMenuPatch.cs | 1 + 2 files changed, 100 insertions(+), 136 deletions(-) diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs index 1948491..cf2428e 100644 --- a/stardew-access/Patches/ItemGrabMenuPatch.cs +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -25,146 +25,17 @@ namespace stardew_access.Patches __instance.inventory.inventory[0].snapMouseCursorToCenter(); } - #region Narrate buttons in the menu - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + if (narrateHoveredButton(__instance, x, y)) { - string toSpeak = "Ok Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } + InventoryUtils.Cleanup(); return; } - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + if (narrateLastShippedItem(__instance, x, y)) { - string toSpeak = "Trash Can"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } + InventoryUtils.Cleanup(); return; } - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) - { - string toSpeak = "Add to existing stacks button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) - { - string toSpeak = "Special Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) - { - - string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - // FIXME - /*if (__instance.discreteColorPickerCC.Count > 0) { - for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) - { - if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) - { - MainClass.monitor.Log(i.ToString(), LogLevel.Debug); - string toSpeak = getChestColorName(i); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - ScreenReader.say(toSpeak, true); - Game1.playSound("sa_drop_item"); - } - return; - } - } - }*/ - #endregion - - #region Narrate the last shipped item if in the shipping bin - if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) - { - Item lastShippedItem = Game1.getFarm().lastItemShipped; - string name = lastShippedItem.DisplayName; - int count = lastShippedItem.Stack; - - string toSpeak = $"Last Shipped: {count} {name}"; - - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { itemGrabMenuQueryKey = ""; @@ -176,8 +47,6 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = ""; return; } - - #endregion } catch (Exception e) { @@ -185,6 +54,99 @@ namespace stardew_access.Patches } } + private static bool narrateHoveredButton(ItemGrabMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok Button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash Can"; + } + else if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + toSpeak = "Organize Button"; + } + else if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) + { + toSpeak = "Add to existing stacks button"; + } + else if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) + { + toSpeak = "Special Button"; + } + else if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) + { + toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); + } + else if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + toSpeak = "Community Center Button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else + { + return false; + } + + // FIXME + /*if (__instance.discreteColorPickerCC.Count > 0) { + for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) + { + if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) + { + MainClass.monitor.Log(i.ToString(), LogLevel.Debug); + string toSpeak = getChestColorName(i); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + ScreenReader.say(toSpeak, true); + Game1.playSound("sa_drop_item"); + } + return; + } + } + }*/ + + if (itemGrabMenuQueryKey == toSpeak) return true; + + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + + private static bool narrateLastShippedItem(ItemGrabMenu __instance, int x, int y) + { + if (!__instance.shippingBin || Game1.getFarm().lastItemShipped == null || !__instance.lastShippedHolder.containsPoint(x, y)) + return false; + + Item lastShippedItem = Game1.getFarm().lastItemShipped; + string name = lastShippedItem.DisplayName; + int count = lastShippedItem.Stack; + + string toSpeak = $"Last Shipped: {count} {name}"; + + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + // TODO Add color names private static string getChestColorName(int i) { @@ -258,7 +220,8 @@ namespace stardew_access.Patches return toReturn; } - internal static void Cleanup() { + internal static void Cleanup() + { hoveredItemQueryKey = ""; itemGrabMenuQueryKey = ""; } diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 5f5e16b..9a46e1e 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -45,6 +45,7 @@ namespace stardew_access.Patches { string toSpeak = ""; bool isDropItemButton = false; + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) { toSpeak = "Drop Item"; From 2ddebd36159e953f4a097a95ae563c2b5de9ca9d Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:06:13 +0530 Subject: [PATCH 26/40] Organised code for donation menu patches --- stardew-access/HarmonyPatches.cs | 14 +- stardew-access/Patches/CarpenterMenuPach.cs | 11 + stardew-access/Patches/ChatMenuPatches.cs | 29 +- stardew-access/Patches/DonationMenuPatches.cs | 328 ------------------ .../FieldOfficeMenuPatch.cs | 122 +++++++ .../DonationMenuPatches/MuseumMenuPatch.cs | 245 +++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 12 +- 7 files changed, 402 insertions(+), 359 deletions(-) delete mode 100644 stardew-access/Patches/DonationMenuPatches.cs create mode 100644 stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs create mode 100644 stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index a77c76e..69bccb5 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -167,11 +167,6 @@ namespace stardew_access 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(DonationMenuPatches), nameof(DonationMenuPatches.MuseumMenuKeyPressPatch)) - ); - harmony.Patch( original: AccessTools.Method(typeof(ChooseFromListMenu), nameof(ChooseFromListMenu.draw), new Type[] { typeof(SpriteBatch) }), postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ChooseFromListMenuPatch)) @@ -255,12 +250,17 @@ namespace stardew_access #region Donation Menus harmony.Patch( original: AccessTools.Method(typeof(MuseumMenu), nameof(MuseumMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DonationMenuPatches), nameof(DonationMenuPatches.MuseumMenuPatch)) + postfix: new HarmonyMethod(typeof(MuseumMenuPatch), nameof(MuseumMenuPatch.DrawPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(MuseumMenu), nameof(MuseumMenu.receiveKeyPress), new Type[] { typeof(Keys) }), + prefix: new HarmonyMethod(typeof(MuseumMenuPatch), nameof(MuseumMenuPatch.RecieveKeyPressPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(FieldOfficeMenu), nameof(FieldOfficeMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DonationMenuPatches), nameof(DonationMenuPatches.FieldOfficeMenuPatch)) + postfix: new HarmonyMethod(typeof(FieldOfficeMenuPatch), nameof(FieldOfficeMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPach.cs index 856d817..81f4d29 100644 --- a/stardew-access/Patches/CarpenterMenuPach.cs +++ b/stardew-access/Patches/CarpenterMenuPach.cs @@ -159,5 +159,16 @@ namespace stardew_access.Patches MainClass.ScreenReader.Say(toSpeak, true); } } + + internal static void Cleanup() + { + CarpenterMenuPatch.carpenterMenuQuery = ""; + CarpenterMenuPatch.isUpgrading = false; + CarpenterMenuPatch.isDemolishing = false; + CarpenterMenuPatch.isPainting = false; + CarpenterMenuPatch.isMoving = false; + CarpenterMenuPatch.isConstructing = false; + CarpenterMenuPatch.carpenterMenu = null; + } } } diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatches.cs index 6155a70..c997ac7 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatches.cs @@ -19,23 +19,22 @@ namespace stardew_access.Patches bool isPrevButtonPressed = MainClass.Config.ChatMenuNextKey.JustPressed(); bool isNextButtonPressed = MainClass.Config.ChatMenuPreviousKey.JustPressed(); - if (___messages.Count > 0) + if (___messages.Count <= 0) return; + + #region To narrate previous and next chat messages + if (isNextButtonPressed && !isChatRunning) { - #region To narrate previous and next chat messages - if (isNextButtonPressed && !isChatRunning) - { - isChatRunning = true; - CycleThroughChatMessages(true, ___messages); - Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); - } - else if (isPrevButtonPressed && !isChatRunning) - { - isChatRunning = true; - CycleThroughChatMessages(false, ___messages); - Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); - } - #endregion + isChatRunning = true; + CycleThroughChatMessages(true, ___messages); + Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); } + else if (isPrevButtonPressed && !isChatRunning) + { + isChatRunning = true; + CycleThroughChatMessages(false, ___messages); + Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); + } + #endregion } else if (___messages.Count > 0) { diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs deleted file mode 100644 index ffffa2f..0000000 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ /dev/null @@ -1,328 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -using StardewValley; -using StardewValley.Locations; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class DonationMenuPatches - { - internal static string museumQueryKey = " "; - internal static string fieldOfficeMenuQuery = " "; - private static bool isMoving = false; - private static (int x, int y)[] donationTiles = - { - (26,5),(26,6),(26,7),(26,8),(26,9),(26,10),(26,11), - (29,5),(30,5),(31,5),(32,5),(33,5),(34,5),(35,5),(36,5), - (28,6),(29,6),(30,6),(31,6),(32,6),(33,6),(34,6),(35,6),(36,6),(37,6), - (28,9),(29,9),(30,9),(31,9),(32,9),(33,9),(34,9),(35,9),(36,9), - (28,10),(29,10),(30,10),(31,10),(32,10),(33,10),(34,10),(35,10),(36,10), - (30,13),(31,13),(32,13),(33,13),(34,13), - (30,14),(31,14),(32,14),(33,14),(34,14), - (28,15),(29,15),(30,15),(31,15),(32,15),(33,15),(34,15),(35,15),(36,15), - (28,16),(29,16),(30,16),(31,16),(32,16),(33,16),(34,16),(35,16),(36,16), - (39,6),(40,6),(41,6),(42,6),(43,6),(44,6),(45,6),(46,6), - (39,7),(40,7),(41,7),(42,7),(43,7),(44,7),(45,7),(46,7), - (48,5),(48,6),(48,7), - (42,15),(43,15),(44,15),(45,15),(46,15),(47,15), - (42,16),(43,16),(44,16),(45,16),(46,16),(47,16), - }; - - #region Museum - - 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(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.heldItem != null) - { - // Museum Inventory - string toSpeak = " "; - int tileX = (int)(Utility.ModifyCoordinateFromUIScale(x) + (float)Game1.viewport.X) / 64; - int tileY = (int)(Utility.ModifyCoordinateFromUIScale(y) + (float)Game1.viewport.Y) / 64; - LibraryMuseum libraryMuseum = (LibraryMuseum)Game1.currentLocation; - - if (libraryMuseum.isTileSuitableForMuseumPiece(tileX, tileY)) - toSpeak = $"slot {tileX}x {tileY}y"; - - if (museumQueryKey != toSpeak) - { - museumQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - // Player Inventory - int i = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, - handleHighlightedItem: true, highlightedItemPrefix: "Donatable "); - if (i != -9999) - { - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For donating hovered item - - if (isPrimaryInfoKeyPressed && __instance.inventory.actualInventory[i] != null) - { - foreach (var tile in donationTiles) - { - #region Manually donates the hovered item (https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Menus/MuseumMenu.cs#L206-L247) - int tileX = tile.x; - int tileY = tile.y; - - if (((LibraryMuseum)Game1.currentLocation).isTileSuitableForMuseumPiece(tileX, tileY) && ((LibraryMuseum)Game1.currentLocation).isItemSuitableForDonation(__instance.inventory.actualInventory[i])) - { - int objectID = __instance.inventory.actualInventory[i].ParentSheetIndex; - int rewardsCount = ((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count; - ((LibraryMuseum)Game1.currentLocation).museumPieces.Add(new Vector2(tileX, tileY), ((StardewValley.Object)__instance.inventory.actualInventory[i]).ParentSheetIndex); - Game1.playSound("stoneStep"); - if (((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count > rewardsCount) - { - Game1.playSound("reward"); - } - else - { - Game1.playSound("newArtifact"); - } - Game1.player.completeQuest(24); - __instance.inventory.actualInventory[i].Stack--; - if (__instance.inventory.actualInventory[i].Stack <= 0) - { - __instance.inventory.actualInventory[i] = null; - } - int pieces = ((LibraryMuseum)Game1.currentLocation).museumPieces.Count(); - Game1.stats.checkForArchaeologyAchievements(); - switch (pieces) - { - case 95: - globalChatInfoMessage("MuseumComplete", Game1.player.farmName.Value); - break; - case 40: - globalChatInfoMessage("Museum40", Game1.player.farmName.Value); - break; - default: - globalChatInfoMessage("donation", Game1.player.Name, "object:" + objectID); - break; - } - break; - } - #endregion - } - } - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - if (museumQueryKey != $"ok button") - { - museumQueryKey = $"ok button"; - MainClass.ScreenReader.Say("ok button", true); - } - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - - #region These methods are taken from the game's source code, https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Multiplayer.cs#L1331-L1395 - internal static void globalChatInfoMessage(string messageKey, params string[] args) - { - if (Game1.IsMultiplayer || Game1.multiplayerMode != 0) - { - receiveChatInfoMessage(Game1.player, messageKey, args); - sendChatInfoMessage(messageKey, args); - } - } - - internal static void sendChatInfoMessage(string messageKey, params string[] args) - { - if (Game1.IsClient) - { - Game1.client.sendMessage(15, messageKey, args); - } - else if (Game1.IsServer) - { - foreach (long id in Game1.otherFarmers.Keys) - { - Game1.server.sendMessage(id, 15, Game1.player, messageKey, args); - } - } - } - - internal static void receiveChatInfoMessage(Farmer sourceFarmer, string messageKey, string[] args) - { - if (Game1.chatBox != null) - { - try - { - string[] processedArgs = args.Select(delegate (string arg) - { - if (arg.StartsWith("achievement:")) - { - int key = Convert.ToInt32(arg.Substring("achievement:".Length)); - return Game1.content.Load>("Data\\Achievements")[key].Split('^')[0]; - } - return arg.StartsWith("object:") ? new StardewValley.Object(Convert.ToInt32(arg.Substring("object:".Length)), 1).DisplayName : arg; - }).ToArray(); - ChatBox chatBox = Game1.chatBox; - LocalizedContentManager content = Game1.content; - string path = "Strings\\UI:Chat_" + messageKey; - object[] substitutions = processedArgs; - chatBox.addInfoMessage(content.LoadString(path, substitutions)); - } - catch (ContentLoadException) - { - } - catch (FormatException) - { - } - catch (OverflowException) - { - } - catch (KeyNotFoundException) - { - } - } - } - #endregion - - #endregion - - #region Field Office - - internal static void FieldOfficeMenuPatch(FieldOfficeMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " "; - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - toSpeak = "Trashcan"; - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "drop item"; - } - else - { - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - for (int i = 0; i < __instance.pieceHolders.Count; i++) - { - if (!__instance.pieceHolders[i].containsPoint(x, y)) - continue; - - if (__instance.pieceHolders[i].item == null) - toSpeak = i switch - { - 0 => "Center skeleton slot", - 1 => "Center skeleton slot", - 2 => "Center skeleton slot", - 3 => "Center skeleton slot", - 4 => "Center skeleton slot", - 5 => "Center skeleton slot", - 6 => "Snake slot", - 7 => "Snake slot", - 8 => "Snake slot", - 9 => "Bat slot", - 10 => "Frog slot", - _ => "Donation slot" - }; - else - toSpeak = $"Slot {i + 1} finished: {__instance.pieceHolders[i].item.DisplayName}"; - - if (!MainClass.Config.DisableInventoryVerbosity && __instance.heldItem != null && __instance.pieceHolders[i].item == null) - { - int highlight = getPieceIndexForDonationItem(__instance.heldItem.ParentSheetIndex); - if (highlight != -1 && highlight == i) - toSpeak += "Donatable "; - } - - if (fieldOfficeMenuQuery != $"{toSpeak}:{i}") - { - fieldOfficeMenuQuery = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - - return; - } - } - - if (fieldOfficeMenuQuery != toSpeak) - { - fieldOfficeMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - Game1.playSound("drop_item"); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static int getPieceIndexForDonationItem(int itemIndex) - { - switch (itemIndex) - { - case 820: - return 5; - case 821: - return 4; - case 822: - return 3; - case 823: - return 0; - case 824: - return 1; - case 825: - return 8; - case 826: - return 7; - case 827: - return 9; - case 828: - return 10; - default: - return -1; - } - } - - #endregion - } -} diff --git a/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs new file mode 100644 index 0000000..088c098 --- /dev/null +++ b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs @@ -0,0 +1,122 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class FieldOfficeMenuPatch + { + private static string fieldOfficeMenuQuery = ""; + + internal static void DrawPatch(FieldOfficeMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = " "; + + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trashcan"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "drop item"; + } + else + { + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; + + for (int i = 0; i < __instance.pieceHolders.Count; i++) + { + if (!__instance.pieceHolders[i].containsPoint(x, y)) + continue; + + if (__instance.pieceHolders[i].item == null) + toSpeak = i switch + { + 0 => "Center skeleton slot", + 1 => "Center skeleton slot", + 2 => "Center skeleton slot", + 3 => "Center skeleton slot", + 4 => "Center skeleton slot", + 5 => "Center skeleton slot", + 6 => "Snake slot", + 7 => "Snake slot", + 8 => "Snake slot", + 9 => "Bat slot", + 10 => "Frog slot", + _ => "Donation slot" + }; + else + toSpeak = $"Slot {i + 1} finished: {__instance.pieceHolders[i].item.DisplayName}"; + + if (!MainClass.Config.DisableInventoryVerbosity && __instance.heldItem != null && __instance.pieceHolders[i].item == null) + { + int highlight = getPieceIndexForDonationItem(__instance.heldItem.ParentSheetIndex); + if (highlight != -1 && highlight == i) + toSpeak += "Donatable "; + } + + if (fieldOfficeMenuQuery != $"{toSpeak}:{i}") + { + fieldOfficeMenuQuery = $"{toSpeak}:{i}"; + MainClass.ScreenReader.Say(toSpeak, true); + } + + return; + } + } + + if (fieldOfficeMenuQuery != toSpeak) + { + fieldOfficeMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + Game1.playSound("drop_item"); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static int getPieceIndexForDonationItem(int itemIndex) + { + switch (itemIndex) + { + case 820: + return 5; + case 821: + return 4; + case 822: + return 3; + case 823: + return 0; + case 824: + return 1; + case 825: + return 8; + case 826: + return 7; + case 827: + return 9; + case 828: + return 10; + default: + return -1; + } + } + + internal static void Cleanup() + { + fieldOfficeMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs new file mode 100644 index 0000000..a79c2b2 --- /dev/null +++ b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs @@ -0,0 +1,245 @@ +using Microsoft.Xna.Framework; +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class MuseumMenuPatch + { + private static string museumQueryKey = ""; + private static bool isMoving = false; + private static (int x, int y)[] donationTiles = + { + (26,5),(26,6),(26,7),(26,8),(26,9),(26,10),(26,11), + (29,5),(30,5),(31,5),(32,5),(33,5),(34,5),(35,5),(36,5), + (28,6),(29,6),(30,6),(31,6),(32,6),(33,6),(34,6),(35,6),(36,6),(37,6), + (28,9),(29,9),(30,9),(31,9),(32,9),(33,9),(34,9),(35,9),(36,9), + (28,10),(29,10),(30,10),(31,10),(32,10),(33,10),(34,10),(35,10),(36,10), + (30,13),(31,13),(32,13),(33,13),(34,13), + (30,14),(31,14),(32,14),(33,14),(34,14), + (28,15),(29,15),(30,15),(31,15),(32,15),(33,15),(34,15),(35,15),(36,15), + (28,16),(29,16),(30,16),(31,16),(32,16),(33,16),(34,16),(35,16),(36,16), + (39,6),(40,6),(41,6),(42,6),(43,6),(44,6),(45,6),(46,6), + (39,7),(40,7),(41,7),(42,7),(43,7),(44,7),(45,7),(46,7), + (48,5),(48,6),(48,7), + (42,15),(43,15),(44,15),(45,15),(46,15),(47,15), + (42,16),(43,16),(44,16),(45,16),(46,16),(47,16), + }; + + internal static bool RecieveKeyPressPatch() + { + 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 DrawPatch(MuseumMenu __instance, bool ___holdingMuseumPiece) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + narrateMuseumInventory(__instance, x, y); + + narratePlayerInventory(__instance, x, y); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void narrateMuseumInventory(MuseumMenu __instance, int x, int y) + { + if (__instance.heldItem == null) return; + + string toSpeak = ""; + int tileX = (int)(Utility.ModifyCoordinateFromUIScale(x) + (float)Game1.viewport.X) / 64; + int tileY = (int)(Utility.ModifyCoordinateFromUIScale(y) + (float)Game1.viewport.Y) / 64; + LibraryMuseum libraryMuseum = (LibraryMuseum)Game1.currentLocation; + + if (libraryMuseum.isTileSuitableForMuseumPiece(tileX, tileY)) + toSpeak = $"slot {tileX}x {tileY}y"; + + if (museumQueryKey != toSpeak) + { + museumQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + private static void narratePlayerInventory(MuseumMenu __instance, int x, int y) + { + if (__instance.heldItem != null) return; + + int hoveredItemIndex = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, + handleHighlightedItem: true, highlightedItemPrefix: "Donatable "); + if (hoveredItemIndex != -9999) + { + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For donating hovered item + + if (isPrimaryInfoKeyPressed && hoveredItemIndex >= 0 && hoveredItemIndex < __instance.inventory.actualInventory.Count && __instance.inventory.actualInventory[hoveredItemIndex] != null) + { + manuallyDonateItem(__instance, hoveredItemIndex); + } + } + else + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else + { + return; + } + + if (museumQueryKey != toSpeak) + { + museumQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + } + } + + private static void manuallyDonateItem(MuseumMenu __instance, int i) + { + foreach (var tile in donationTiles) + { + #region Manually donates the hovered item (https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Menus/MuseumMenu.cs#L206-L247) + int tileX = tile.x; + int tileY = tile.y; + + if (((LibraryMuseum)Game1.currentLocation).isTileSuitableForMuseumPiece(tileX, tileY) && ((LibraryMuseum)Game1.currentLocation).isItemSuitableForDonation(__instance.inventory.actualInventory[i])) + { + int objectID = __instance.inventory.actualInventory[i].ParentSheetIndex; + int rewardsCount = ((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count; + ((LibraryMuseum)Game1.currentLocation).museumPieces.Add(new Vector2(tileX, tileY), ((StardewValley.Object)__instance.inventory.actualInventory[i]).ParentSheetIndex); + Game1.playSound("stoneStep"); + if (((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count > rewardsCount) + { + Game1.playSound("reward"); + } + else + { + Game1.playSound("newArtifact"); + } + Game1.player.completeQuest(24); + __instance.inventory.actualInventory[i].Stack--; + if (__instance.inventory.actualInventory[i].Stack <= 0) + { + __instance.inventory.actualInventory[i] = null; + } + int pieces = ((LibraryMuseum)Game1.currentLocation).museumPieces.Count(); + Game1.stats.checkForArchaeologyAchievements(); + switch (pieces) + { + case 95: + globalChatInfoMessage("MuseumComplete", Game1.player.farmName.Value); + break; + case 40: + globalChatInfoMessage("Museum40", Game1.player.farmName.Value); + break; + default: + globalChatInfoMessage("donation", Game1.player.Name, "object:" + objectID); + break; + } + break; + } + #endregion + } + } + + #region These methods are taken from the game's source code, https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Multiplayer.cs#L1331-L1395 + internal static void globalChatInfoMessage(string messageKey, params string[] args) + { + if (Game1.IsMultiplayer || Game1.multiplayerMode != 0) + { + receiveChatInfoMessage(Game1.player, messageKey, args); + sendChatInfoMessage(messageKey, args); + } + } + + internal static void sendChatInfoMessage(string messageKey, params string[] args) + { + if (Game1.IsClient) + { + Game1.client.sendMessage(15, messageKey, args); + } + else if (Game1.IsServer) + { + foreach (long id in Game1.otherFarmers.Keys) + { + Game1.server.sendMessage(id, 15, Game1.player, messageKey, args); + } + } + } + + internal static void receiveChatInfoMessage(Farmer sourceFarmer, string messageKey, string[] args) + { + if (Game1.chatBox != null) + { + try + { + string[] processedArgs = args.Select(delegate (string arg) + { + if (arg.StartsWith("achievement:")) + { + int key = Convert.ToInt32(arg.Substring("achievement:".Length)); + return Game1.content.Load>("Data\\Achievements")[key].Split('^')[0]; + } + return arg.StartsWith("object:") ? new StardewValley.Object(Convert.ToInt32(arg.Substring("object:".Length)), 1).DisplayName : arg; + }).ToArray(); + ChatBox chatBox = Game1.chatBox; + LocalizedContentManager content = Game1.content; + string path = "Strings\\UI:Chat_" + messageKey; + object[] substitutions = processedArgs; + chatBox.addInfoMessage(content.LoadString(path, substitutions)); + } + catch (Microsoft.Xna.Framework.Content.ContentLoadException) + { + } + catch (FormatException) + { + } + catch (OverflowException) + { + } + catch (KeyNotFoundException) + { + } + } + } + #endregion + + internal static void Cleanup() + { + museumQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 36bb1cc..49c552f 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -263,13 +263,7 @@ namespace stardew_access.Patches } else if (menu is CarpenterMenu) { - CarpenterMenuPatch.carpenterMenuQuery = ""; - CarpenterMenuPatch.isUpgrading = false; - CarpenterMenuPatch.isDemolishing = false; - CarpenterMenuPatch.isPainting = false; - CarpenterMenuPatch.isMoving = false; - CarpenterMenuPatch.isConstructing = false; - CarpenterMenuPatch.carpenterMenu = null; + CarpenterMenuPatch.Cleanup(); } else if (menu is PurchaseAnimalsMenu) { @@ -305,11 +299,11 @@ namespace stardew_access.Patches } else if (menu is FieldOfficeMenu) { - DonationMenuPatches.fieldOfficeMenuQuery = " "; + FieldOfficeMenuPatch.Cleanup(); } else if (menu is MuseumMenu) { - DonationMenuPatches.museumQueryKey = " "; + MuseumMenuPatch.Cleanup(); } else if (menu is PondQueryMenu) { From 8970a2c4414109b561f0111ff099280b28b50843 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:12:07 +0530 Subject: [PATCH 27/40] Fixed bug for Museum menu patch --- .../DonationMenuPatches/MuseumMenuPatch.cs | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs index a79c2b2..284f40a 100644 --- a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs +++ b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs @@ -88,6 +88,8 @@ namespace stardew_access.Patches { if (__instance.heldItem != null) return; + if (narrateHoveredButtons(__instance, x, y)) return; + int hoveredItemIndex = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, handleHighlightedItem: true, highlightedItemPrefix: "Donatable "); if (hoveredItemIndex != -9999) @@ -99,32 +101,35 @@ namespace stardew_access.Patches manuallyDonateItem(__instance, hoveredItemIndex); } } + } + + private static bool narrateHoveredButtons(MuseumMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } else { - string toSpeak = ""; - bool isDropItemButton = false; - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "Ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "Drop Item"; - isDropItemButton = true; - } - else - { - return; - } - - if (museumQueryKey != toSpeak) - { - museumQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - if (isDropItemButton) Game1.playSound("drop_item"); - } + return false; } + + if (museumQueryKey != toSpeak) + { + museumQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; } private static void manuallyDonateItem(MuseumMenu __instance, int i) From 1346e90bf5adfd16fe7bef4f1149b1b18400ee2b Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:21:46 +0530 Subject: [PATCH 28/40] Organised code for geode menu patch --- stardew-access/Patches/GeodeMenuPatch.cs | 126 ++++++++---------- stardew-access/Patches/IClickableMenuPatch.cs | 4 + 2 files changed, 61 insertions(+), 69 deletions(-) diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs index e08beec..4b99ad6 100644 --- a/stardew-access/Patches/GeodeMenuPatch.cs +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -5,7 +5,7 @@ namespace stardew_access.Patches { internal class GeodeMenuPatch { - internal static string geodeMenuQueryKey = ""; + private static string geodeMenuQueryKey = ""; internal static void DrawPatch(GeodeMenu __instance) { @@ -13,77 +13,11 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - #region Narrate the treasure recieved on breaking the geode - if (__instance.geodeTreasure != null) - { - string name = __instance.geodeTreasure.DisplayName; - int stack = __instance.geodeTreasure.Stack; + if (narrateRecievedTreasure(__instance)) return; + if (narrateHoveredButton(__instance, x, y)) return; - string toSpeak = $"Recieved {stack} {name}"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered buttons in the menu - if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) - { - string toSpeak = "Place geode here"; - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop item here"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash can"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok button"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) geodeMenuQueryKey = ""; - #endregion } catch (Exception e) { @@ -91,6 +25,60 @@ namespace stardew_access.Patches } } + private static bool narrateRecievedTreasure(GeodeMenu __instance) + { + // Narrates the treasure recieved on breaking the geode + if (__instance.geodeTreasure == null) return false; + + string name = __instance.geodeTreasure.DisplayName; + int stack = __instance.geodeTreasure.Stack; + + string toSpeak = $"Recieved {stack} {name}"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + + private static bool narrateHoveredButton(GeodeMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) + { + toSpeak = "Place geode here"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop item here"; + isDropItemButton = true; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash can"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok button"; + } + else + { + return false; + } + + if (geodeMenuQueryKey == toSpeak) return true; + + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + internal static void Cleanup() { geodeMenuQueryKey = ""; diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 49c552f..63278ca 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -309,6 +309,10 @@ namespace stardew_access.Patches { MenuPatches.pondQueryMenuQuery = " "; } + else if (menu is GeodeMenu) + { + GeodeMenuPatch.Cleanup(); + } InventoryUtils.Cleanup(); TextBoxPatch.activeTextBoxes = ""; From 2c233f6e6b427fb19c3c925699ed2591317b5a83 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:27:02 +0530 Subject: [PATCH 29/40] Moved InventoryUtils.cs --- stardew-access/{Patches => Features}/InventoryUtils.cs | 2 +- .../Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs | 1 + stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs | 1 + stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs | 1 + stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs | 1 + stardew-access/Patches/GeodeMenuPatch.cs | 1 + stardew-access/Patches/IClickableMenuPatch.cs | 1 + stardew-access/Patches/ItemGrabMenuPatch.cs | 1 + stardew-access/Patches/ShopMenuPatch.cs | 1 + 9 files changed, 9 insertions(+), 1 deletion(-) rename stardew-access/{Patches => Features}/InventoryUtils.cs (99%) diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Features/InventoryUtils.cs similarity index 99% rename from stardew-access/Patches/InventoryUtils.cs rename to stardew-access/Features/InventoryUtils.cs index f4a7602..8b8e913 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Features/InventoryUtils.cs @@ -2,7 +2,7 @@ using StardewValley; using StardewValley.Menus; -namespace stardew_access.Patches +namespace stardew_access.Features { internal class InventoryUtils { diff --git a/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs index 088c098..5eec4ba 100644 --- a/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs +++ b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs @@ -1,4 +1,5 @@ using StardewValley; +using stardew_access.Features; using StardewValley.Menus; namespace stardew_access.Patches diff --git a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs index 284f40a..bd76c97 100644 --- a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs +++ b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using StardewValley; +using stardew_access.Features; using StardewValley.Locations; using StardewValley.Menus; diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index 59e6140..1cad73e 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -1,4 +1,5 @@ using StardewValley; +using stardew_access.Features; using StardewValley.Menus; using StardewValley.Objects; diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs index dc05fd3..cbb8dd5 100644 --- a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs index 4b99ad6..e9ca166 100644 --- a/stardew-access/Patches/GeodeMenuPatch.cs +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 63278ca..356dbd9 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs index cf2428e..b9b7674 100644 --- a/stardew-access/Patches/ItemGrabMenuPatch.cs +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 9a46e1e..8e000d8 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; From 53fe73140110d6c32a2619210cad72e148f28e1b Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:32:45 +0530 Subject: [PATCH 30/40] Moved and organized mini game patches --- stardew-access/HarmonyPatches.cs | 4 +- .../GrandpaStoryPatch.cs} | 36 +---------------- .../Patches/MiniGamesPatches/IntroPatch.cs | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+), 36 deletions(-) rename stardew-access/Patches/{MiniGamesPatches.cs => MiniGamesPatches/GrandpaStoryPatch.cs} (71%) create mode 100644 stardew-access/Patches/MiniGamesPatches/IntroPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 69bccb5..900e674 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -267,12 +267,12 @@ namespace stardew_access #region Mini Games harmony.Patch( original: AccessTools.Method(typeof(Intro), nameof(Intro.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MiniGamesPatches), nameof(MiniGamesPatches.IntroPatch)) + postfix: new HarmonyMethod(typeof(IntroPatch), nameof(IntroPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(GrandpaStory), nameof(GrandpaStory.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MiniGamesPatches), nameof(MiniGamesPatches.GrandpaStoryPatch)) + postfix: new HarmonyMethod(typeof(GrandpaStoryPatch), nameof(GrandpaStoryPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/MiniGamesPatches.cs b/stardew-access/Patches/MiniGamesPatches/GrandpaStoryPatch.cs similarity index 71% rename from stardew-access/Patches/MiniGamesPatches.cs rename to stardew-access/Patches/MiniGamesPatches/GrandpaStoryPatch.cs index 07480bf..90e93d2 100644 --- a/stardew-access/Patches/MiniGamesPatches.cs +++ b/stardew-access/Patches/MiniGamesPatches/GrandpaStoryPatch.cs @@ -4,43 +4,11 @@ using StardewValley.Minigames; namespace stardew_access.Patches { - public class MiniGamesPatches + public class GrandpaStoryPatch { public static string grandpaStoryQuery = " "; - public static string introQuery = " "; - internal static void IntroPatch(Intro __instance, int ___currentState) - { - try - { - if (MainClass.ModHelper == null) - return; - - string toSpeak = " "; - - if (___currentState == 3) - { - toSpeak = MainClass.ModHelper.Translation.Get("intro.scene3"); - } - else if (___currentState == 4) - { - toSpeak = MainClass.ModHelper.Translation.Get("intro.scene4"); - } - - if (toSpeak != " " && introQuery != toSpeak) - { - introQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, false); - return; - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void GrandpaStoryPatch(GrandpaStory __instance, StardewValley.Menus.LetterViewerMenu ___letterView, bool ___drawGrandpa, bool ___letterReceived, bool ___mouseActive, Queue ___grandpaSpeech, int ___grandpaSpeechTimer, int ___totalMilliseconds, int ___scene, int ___parallaxPan) + internal static void DrawPatch(GrandpaStory __instance, StardewValley.Menus.LetterViewerMenu ___letterView, bool ___drawGrandpa, bool ___letterReceived, bool ___mouseActive, Queue ___grandpaSpeech, int ___grandpaSpeechTimer, int ___totalMilliseconds, int ___scene, int ___parallaxPan) { try { diff --git a/stardew-access/Patches/MiniGamesPatches/IntroPatch.cs b/stardew-access/Patches/MiniGamesPatches/IntroPatch.cs new file mode 100644 index 0000000..08759a7 --- /dev/null +++ b/stardew-access/Patches/MiniGamesPatches/IntroPatch.cs @@ -0,0 +1,40 @@ +using StardewValley.Minigames; + +namespace stardew_access.Patches +{ + public class IntroPatch + { + public static string introQuery = " "; + + internal static void DrawPatch(Intro __instance, int ___currentState) + { + try + { + if (MainClass.ModHelper == null) + return; + + string toSpeak = " "; + + if (___currentState == 3) + { + toSpeak = MainClass.ModHelper.Translation.Get("intro.scene3"); + } + else if (___currentState == 4) + { + toSpeak = MainClass.ModHelper.Translation.Get("intro.scene4"); + } + + if (toSpeak != " " && introQuery != toSpeak) + { + introQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, false); + return; + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"An error occured in intro minigame patch:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 50e8afc78c5f07e6ebedfc62e93e1c9e133e9298 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 14:01:58 +0530 Subject: [PATCH 31/40] Moved and organized quest patches --- stardew-access/HarmonyPatches.cs | 6 +- stardew-access/Patches/IClickableMenuPatch.cs | 8 +- stardew-access/Patches/QuestPatches.cs | 276 ------------------ .../Patches/QuestPatches/BillboardPatch.cs | 98 +++++++ .../Patches/QuestPatches/QuestLogPatch.cs | 164 +++++++++++ .../QuestPatches/SpecialOrdersBoardPatch.cs | 84 ++++++ 6 files changed, 355 insertions(+), 281 deletions(-) create mode 100644 stardew-access/Patches/QuestPatches/BillboardPatch.cs create mode 100644 stardew-access/Patches/QuestPatches/QuestLogPatch.cs create mode 100644 stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 900e674..78d8c22 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -196,17 +196,17 @@ namespace stardew_access #region Quest Patches harmony.Patch( original: AccessTools.Method(typeof(SpecialOrdersBoard), nameof(SpecialOrdersBoard.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.SpecialOrdersBoardPatch)) + postfix: new HarmonyMethod(typeof(SpecialOrdersBoardPatch), nameof(SpecialOrdersBoardPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(QuestLog), nameof(QuestLog.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.QuestLogPatch)) + postfix: new HarmonyMethod(typeof(QuestLogPatch), nameof(QuestLogPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(Billboard), nameof(Billboard.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.BillboardPatch)) + postfix: new HarmonyMethod(typeof(BillboardPatch), nameof(BillboardPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 356dbd9..f935345 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -235,7 +235,7 @@ namespace stardew_access.Patches } else if (menu is Billboard) { - QuestPatches.currentDailyQuestText = " "; + BillboardPatch.Cleanup(); } else if (menu is GameMenu) { @@ -284,7 +284,7 @@ namespace stardew_access.Patches } else if (menu is QuestLog) { - QuestPatches.questLogQuery = " "; + QuestLogPatch.Cleaup(); } else if (menu is TailoringMenu) { @@ -314,6 +314,10 @@ namespace stardew_access.Patches { GeodeMenuPatch.Cleanup(); } + else if (menu is SpecialOrdersBoard) + { + SpecialOrdersBoardPatch.Cleanup(); + } InventoryUtils.Cleanup(); TextBoxPatch.activeTextBoxes = ""; diff --git a/stardew-access/Patches/QuestPatches.cs b/stardew-access/Patches/QuestPatches.cs index 0b38787..cbe8441 100644 --- a/stardew-access/Patches/QuestPatches.cs +++ b/stardew-access/Patches/QuestPatches.cs @@ -7,281 +7,5 @@ namespace stardew_access.Patches { internal class QuestPatches { - internal static string currentDailyQuestText = " "; - internal static string questLogQuery = " "; - internal static bool isNarratingQuestInfo = false, firstTimeInIndividualQuest = true; - - #region For Special Orders Board - internal static void SpecialOrdersBoardPatch(SpecialOrdersBoard __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.acceptLeftQuestButton.visible && __instance.acceptLeftQuestButton.containsPoint(x, y)) - { - string toSpeak = getSpecialOrderDetails(__instance.leftOrder); - - toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - return; - } - - if (__instance.acceptRightQuestButton.visible && __instance.acceptRightQuestButton.containsPoint(x, y)) - { - string toSpeak = getSpecialOrderDetails(__instance.rightOrder); - - toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - return; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static string getSpecialOrderDetails(SpecialOrder order) - { - int daysLeft = order.GetDaysLeft(); - string description = order.GetDescription(); - string objectiveDescription = ""; - string name = order.GetName(); - int moneyReward = order.GetMoneyReward(); - - // Get each objectives - for (int i = 0; i < order.GetObjectiveDescriptions().Count; i++) - { - objectiveDescription += order.GetObjectiveDescriptions()[i] + ", \n"; - } - - string toReturn = $"{name}\n\tDescription:{description}\n\tObjectives: {objectiveDescription}"; - - if (order.IsTimedQuest()) - { - toReturn = $"{toReturn}\n\tTime: {daysLeft} days"; - } - - if (order.HasMoneyReward()) - { - toReturn = $"{toReturn}\n\tReward: {moneyReward}g"; - } - - return toReturn; - } - #endregion - - #region For Normal Billboard in the town - internal static void BillboardPatch(Billboard __instance, bool ___dailyQuestBoard) - { - try - { - if (!___dailyQuestBoard) - { - #region Callender - for (int i = 0; i < __instance.calendarDays.Count; i++) - { - if (__instance.calendarDays[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = $"Day {i + 1}"; - - if (__instance.calendarDays[i].name.Length > 0) - { - toSpeak += $", {__instance.calendarDays[i].name}"; - } - if (__instance.calendarDays[i].hoverText.Length > 0) - { - toSpeak += $", {__instance.calendarDays[i].hoverText}"; - } - - if (Game1.dayOfMonth == i + 1) - toSpeak += $", Current"; - - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - } - #endregion - } - else - { - #region Daily Quest Board - if (Game1.questOfTheDay == null || Game1.questOfTheDay.currentObjective == null || Game1.questOfTheDay.currentObjective.Length == 0) - { - // No quests - string toSpeak = "No quests for today!"; - if (currentDailyQuestText != toSpeak) - { - currentDailyQuestText = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - SpriteFont font = ((LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko) ? Game1.smallFont : Game1.dialogueFont); - string description = Game1.parseText(Game1.questOfTheDay.questDescription, font, 640); - string toSpeak = description; - - if (currentDailyQuestText != toSpeak) - { - currentDailyQuestText = toSpeak; - - // Snap to accept quest button - if (__instance.acceptQuestButton.visible) - { - toSpeak += "\t\n Left click to accept quest."; - __instance.acceptQuestButton.snapMouseCursorToCenter(); - } - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - #endregion - - #region Journal Menu - internal static void QuestLogPatch(QuestLog __instance, int ___questPage, List> ___pages, int ___currentPage, IQuest ____shownQuest, List ____objectiveText) - { - try - { - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " ", extra = ""; - - if (___questPage == -1) - { - #region Quest Lists - if (!firstTimeInIndividualQuest) - firstTimeInIndividualQuest = true; - - for (int i = 0; i < __instance.questLogButtons.Count; i++) - { - if (___pages.Count() > 0 && ___pages[___currentPage].Count() > i) - { - if (!__instance.questLogButtons[i].containsPoint(x, y)) - continue; - - string name = ___pages[___currentPage][i].GetName(); - int daysLeft = ___pages[___currentPage][i].GetDaysLeft(); - toSpeak = $"{name}"; - - if (daysLeft > 0 && ___pages[___currentPage][i].ShouldDisplayAsComplete()) - toSpeak += $"\t\n {daysLeft} days left"; - - toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; - break; - } - } - - if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) - toSpeak = "Previous page button"; - else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next page button"; - else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) - toSpeak = "Close menu button"; - - if (questLogQuery != toSpeak) - { - questLogQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - #endregion - } - else - { - #region Individual quest - bool containsReward = __instance.HasReward() || __instance.HasMoneyReward(); - string description = Game1.parseText(____shownQuest.GetDescription(), Game1.dialogueFont, __instance.width - 128); - string title = ____shownQuest.GetName(); - - if (firstTimeInIndividualQuest || (isPrimaryInfoKeyPressed && !isNarratingQuestInfo)) - { - if (firstTimeInIndividualQuest) - toSpeak = "Back button"; - - if (____shownQuest.ShouldDisplayAsComplete()) - { - #region Quest completed menu - - extra = $"Quest: {title} Completed!"; - - if (__instance.HasMoneyReward()) - extra += $"you recieved {____shownQuest.GetMoneyReward()}g"; - - #endregion - } - else - { - #region Quest in-complete menu - extra = $"Title: {title}. \t\n Description: {description}"; - - for (int j = 0; j < ____objectiveText.Count; j++) - { - string parsed_text = Game1.parseText(____objectiveText[j], width: __instance.width - 192, whichFont: Game1.dialogueFont); - if (____shownQuest != null && ____shownQuest is SpecialOrder) - { - OrderObjective order_objective = ((SpecialOrder)____shownQuest).objectives[j]; - if (order_objective.GetMaxCount() > 1 && order_objective.ShouldShowProgress()) - parsed_text += "\n\t" + order_objective.GetCount() + " of " + order_objective.GetMaxCount() + " completed"; - } - - extra += $"\t\nOrder {j + 1}: {parsed_text} \t\n"; - } - - if (____shownQuest != null) - { - int daysLeft = ____shownQuest.GetDaysLeft(); - - if (daysLeft > 0) - extra += $"\t\n{daysLeft} days left."; - } - #endregion - } - - isNarratingQuestInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingQuestInfo = false; }); - questLogQuery = " "; - } - - if (!firstTimeInIndividualQuest) - if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) - toSpeak = (___currentPage > 0) ? "Previous page button" : "Back button"; - else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next page button"; - else if (__instance.cancelQuestButton != null && __instance.cancelQuestButton.visible && __instance.cancelQuestButton.containsPoint(x, y)) - toSpeak = "Cancel quest button"; - else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) - toSpeak = "Close menu button"; - else if (containsReward && __instance.rewardBox.containsPoint(x, y)) - toSpeak = "Left click to collect reward"; - - if (firstTimeInIndividualQuest || (questLogQuery != toSpeak)) - { - questLogQuery = toSpeak; - MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); - - if (firstTimeInIndividualQuest) - firstTimeInIndividualQuest = false; - } - - #endregion - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - #endregion - } } diff --git a/stardew-access/Patches/QuestPatches/BillboardPatch.cs b/stardew-access/Patches/QuestPatches/BillboardPatch.cs new file mode 100644 index 0000000..f8e4f47 --- /dev/null +++ b/stardew-access/Patches/QuestPatches/BillboardPatch.cs @@ -0,0 +1,98 @@ +using Microsoft.Xna.Framework.Graphics; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class BillboardPatch + { + private static string billboardQueryKey = ""; + + internal static void DrawPatch(Billboard __instance, bool ___dailyQuestBoard) + { + try + { + if (___dailyQuestBoard) + { + narrateDailyQuestBoard(__instance); + } + else + { + narrateCallendar(__instance); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void narrateCallendar(Billboard __instance) + { + for (int i = 0; i < __instance.calendarDays.Count; i++) + { + if (!__instance.calendarDays[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + continue; + + string toSpeak = $"Day {i + 1}"; + + if (__instance.calendarDays[i].name.Length > 0) + { + toSpeak += $", {__instance.calendarDays[i].name}"; + } + if (__instance.calendarDays[i].hoverText.Length > 0) + { + toSpeak += $", {__instance.calendarDays[i].hoverText}"; + } + + if (Game1.dayOfMonth == i + 1) + toSpeak += $", Current"; + + if (billboardQueryKey != toSpeak) + { + billboardQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + } + + private static void narrateDailyQuestBoard(Billboard __instance) + { + if (Game1.questOfTheDay == null || Game1.questOfTheDay.currentObjective == null || Game1.questOfTheDay.currentObjective.Length == 0) + { + // No quests + string toSpeak = "No quests for today!"; + if (billboardQueryKey != toSpeak) + { + billboardQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + else + { + SpriteFont font = ((LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko) ? Game1.smallFont : Game1.dialogueFont); + string description = Game1.parseText(Game1.questOfTheDay.questDescription, font, 640); + string toSpeak = description; + + if (billboardQueryKey != toSpeak) + { + billboardQueryKey = toSpeak; + + // Snap to accept quest button + if (__instance.acceptQuestButton.visible) + { + toSpeak += "\t\n Left click to accept quest."; + __instance.acceptQuestButton.snapMouseCursorToCenter(); + } + + MainClass.ScreenReader.Say(toSpeak, true); + } + } + } + + internal static void Cleanup() + { + billboardQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/QuestPatches/QuestLogPatch.cs b/stardew-access/Patches/QuestPatches/QuestLogPatch.cs new file mode 100644 index 0000000..c93ddc1 --- /dev/null +++ b/stardew-access/Patches/QuestPatches/QuestLogPatch.cs @@ -0,0 +1,164 @@ +using StardewValley; +using StardewValley.Menus; +using StardewValley.Quests; + +namespace stardew_access.Patches +{ + // a.k.a. Journal Menu + internal class QuestLogPatch + { + internal static string questLogQuery = ""; + internal static bool isNarratingQuestInfo = false; + internal static bool firstTimeInIndividualQuest = true; + + internal static void DrawPatch(QuestLog __instance, int ___questPage, List> ___pages, int ___currentPage, IQuest ____shownQuest, List ____objectiveText) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (___questPage == -1) + { + narrateQuestList(__instance, ___pages, ___currentPage, x, y); + } + else + { + narrateIndividualQuest(__instance, ___currentPage, ____shownQuest, ____objectiveText, x, y); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void narrateQuestList(QuestLog __instance, List> ___pages, int ___currentPage, int x, int y) + { + string toSpeak = ""; + + if (!firstTimeInIndividualQuest) firstTimeInIndividualQuest = true; + + if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) + toSpeak = "Previous page button"; + else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next page button"; + else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) + toSpeak = "Close menu button"; + else + { + for (int i = 0; i < __instance.questLogButtons.Count; i++) + { + if (___pages.Count() <= 0 || ___pages[___currentPage].Count() <= i) + continue; + + if (!__instance.questLogButtons[i].containsPoint(x, y)) + continue; + + string name = ___pages[___currentPage][i].GetName(); + int daysLeft = ___pages[___currentPage][i].GetDaysLeft(); + toSpeak = $"{name}"; + + if (daysLeft > 0 && ___pages[___currentPage][i].ShouldDisplayAsComplete()) + toSpeak += $"\t\n {daysLeft} days left"; + + toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; + break; + } + } + + if (questLogQuery != toSpeak) + { + questLogQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + private static void narrateIndividualQuest(QuestLog __instance, int ___currentPage, IQuest ____shownQuest, List ____objectiveText, int x, int y) + { + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + bool containsReward = __instance.HasReward() || __instance.HasMoneyReward(); + string description = Game1.parseText(____shownQuest.GetDescription(), Game1.dialogueFont, __instance.width - 128); + string title = ____shownQuest.GetName(); + string toSpeak = ""; + string extra = ""; + + if (firstTimeInIndividualQuest || (isPrimaryInfoKeyPressed && !isNarratingQuestInfo)) + { + if (firstTimeInIndividualQuest) + toSpeak = "Back button"; + + if (____shownQuest.ShouldDisplayAsComplete()) + { + #region Quest completed menu + + extra = $"Quest: {title} Completed!"; + + if (__instance.HasMoneyReward()) + extra += $"you recieved {____shownQuest.GetMoneyReward()}g"; + + #endregion + } + else + { + #region Quest in-complete menu + extra = $"Title: {title}. \t\n Description: {description}"; + + for (int j = 0; j < ____objectiveText.Count; j++) + { + string parsed_text = Game1.parseText(____objectiveText[j], width: __instance.width - 192, whichFont: Game1.dialogueFont); + if (____shownQuest != null && ____shownQuest is SpecialOrder) + { + OrderObjective order_objective = ((SpecialOrder)____shownQuest).objectives[j]; + if (order_objective.GetMaxCount() > 1 && order_objective.ShouldShowProgress()) + parsed_text += "\n\t" + order_objective.GetCount() + " of " + order_objective.GetMaxCount() + " completed"; + } + + extra += $"\t\nOrder {j + 1}: {parsed_text} \t\n"; + } + + if (____shownQuest != null) + { + int daysLeft = ____shownQuest.GetDaysLeft(); + + if (daysLeft > 0) + extra += $"\t\n{daysLeft} days left."; + } + #endregion + } + + isNarratingQuestInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingQuestInfo = false; }); + questLogQuery = ""; + } + + if (!firstTimeInIndividualQuest) + { + if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) + toSpeak = (___currentPage > 0) ? "Previous page button" : "Back button"; + else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next page button"; + else if (__instance.cancelQuestButton != null && __instance.cancelQuestButton.visible && __instance.cancelQuestButton.containsPoint(x, y)) + toSpeak = "Cancel quest button"; + else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) + toSpeak = "Close menu button"; + else if (containsReward && __instance.rewardBox.containsPoint(x, y)) + toSpeak = "Left click to collect reward"; + } + + if (firstTimeInIndividualQuest || (questLogQuery != toSpeak)) + { + questLogQuery = toSpeak; + MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); + + if (firstTimeInIndividualQuest) firstTimeInIndividualQuest = false; + } + } + + internal static void Cleaup() + { + questLogQuery = ""; + isNarratingQuestInfo = false; + firstTimeInIndividualQuest = true; + } + } +} diff --git a/stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs b/stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs new file mode 100644 index 0000000..eb27f5a --- /dev/null +++ b/stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs @@ -0,0 +1,84 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class SpecialOrdersBoardPatch + { + private static string specialOrdersBoardQueryKey = ""; + + internal static void DrawPatch(SpecialOrdersBoard __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (__instance.acceptLeftQuestButton.visible && __instance.acceptLeftQuestButton.containsPoint(x, y)) + { + string toSpeak = getSpecialOrderDetails(__instance.leftOrder); + + toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; + + Speak(toSpeak); + return; + } + + if (__instance.acceptRightQuestButton.visible && __instance.acceptRightQuestButton.containsPoint(x, y)) + { + string toSpeak = getSpecialOrderDetails(__instance.rightOrder); + + toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; + + Speak(toSpeak); + return; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static string getSpecialOrderDetails(SpecialOrder order) + { + int daysLeft = order.GetDaysLeft(); + string description = order.GetDescription(); + string objectiveDescription = ""; + string name = order.GetName(); + int moneyReward = order.GetMoneyReward(); + + // Get each objectives + for (int i = 0; i < order.GetObjectiveDescriptions().Count; i++) + { + objectiveDescription += order.GetObjectiveDescriptions()[i] + ", \n"; + } + + string toReturn = $"{name}\n\tDescription:{description}\n\tObjectives: {objectiveDescription}"; + + if (order.IsTimedQuest()) + { + toReturn = $"{toReturn}\n\tTime: {daysLeft} days"; + } + + if (order.HasMoneyReward()) + { + toReturn = $"{toReturn}\n\tReward: {moneyReward}g"; + } + + return toReturn; + } + + private static void Speak(string toSpeak) + { + if (specialOrdersBoardQueryKey == toSpeak) return; + + specialOrdersBoardQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + specialOrdersBoardQueryKey = ""; + } + } +} From c553b589abbd87d90b995a2e958382f2f6d97b39 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:32:43 +0530 Subject: [PATCH 32/40] Moved patches related to Game1 and InstanceGame to their own class --- stardew-access/HarmonyPatches.cs | 7 +-- stardew-access/Patches/Game1Patch.cs | 56 +++++++++++++++++++++ stardew-access/Patches/InstanceGamePatch.cs | 11 ++++ stardew-access/Patches/MenuPatches.cs | 48 ------------------ stardew-access/Patches/QuestPatches.cs | 11 ---- 5 files changed, 71 insertions(+), 62 deletions(-) create mode 100644 stardew-access/Patches/Game1Patch.cs create mode 100644 stardew-access/Patches/InstanceGamePatch.cs delete mode 100644 stardew-access/Patches/QuestPatches.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 78d8c22..cb8d85c 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -222,9 +222,10 @@ namespace stardew_access original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)), postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.ExitThisMenuPatch)) ); + harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.exitActiveMenu)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.Game1ExitActiveMenuPatch)) + prefix: new HarmonyMethod(typeof(Game1Patch), nameof(Game1Patch.ExitActiveMenuPatch)) ); #endregion @@ -278,12 +279,12 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.playSound)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.PlaySoundPatch)) + prefix: new HarmonyMethod(typeof(Game1Patch), nameof(Game1Patch.PlaySoundPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(InstanceGame), nameof(InstanceGame.Exit)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ExitEventPatch)) + prefix: new HarmonyMethod(typeof(InstanceGamePatch), nameof(InstanceGamePatch.ExitPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/Game1Patch.cs b/stardew-access/Patches/Game1Patch.cs new file mode 100644 index 0000000..04ba91f --- /dev/null +++ b/stardew-access/Patches/Game1Patch.cs @@ -0,0 +1,56 @@ +using Microsoft.Xna.Framework; +using stardew_access.Features; +using StardewModdingAPI; +using StardewValley; + +namespace stardew_access.Patches +{ + internal class Game1Patch + { + private static Vector2? prevTile = null; + + internal static void ExitActiveMenuPatch() + { + try + { + IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static bool PlaySoundPatch(string cueName) + { + try + { + if (!Context.IsPlayerFree) + return true; + + if (!Game1.player.isMoving()) + return true; + + if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") + { + Vector2 nextTile = CurrentPlayer.FacingTile; + if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) + { + if (prevTile != nextTile) + { + prevTile = nextTile; + //Game1.playSound("colliding"); + } + return false; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + + return true; + } + } +} diff --git a/stardew-access/Patches/InstanceGamePatch.cs b/stardew-access/Patches/InstanceGamePatch.cs new file mode 100644 index 0000000..93affb1 --- /dev/null +++ b/stardew-access/Patches/InstanceGamePatch.cs @@ -0,0 +1,11 @@ +namespace stardew_access.Patches +{ + internal class InstanceGamePatch + { + internal static void ExitPatch() + { + if (MainClass.ScreenReader != null) + MainClass.ScreenReader.CloseScreenReader(); + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 2576c40..1aa61a1 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -17,7 +17,6 @@ namespace stardew_access.Patches internal static string forgeMenuQuery = " "; internal static string itemListMenuQuery = " "; internal static int prevSlotIndex = -999; - public static Vector2? prevTile = null; internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) { @@ -312,37 +311,6 @@ namespace stardew_access.Patches } } - internal static bool PlaySoundPatch(string cueName) - { - try - { - if (!Context.IsPlayerFree) - return true; - - if (!Game1.player.isMoving()) - return true; - - if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") - { - Vector2 nextTile = CurrentPlayer.FacingTile; - if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) - { - if (prevTile != nextTile) - { - prevTile = nextTile; - //Game1.playSound("colliding"); - } - return false; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - - return true; - } internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) { @@ -604,22 +572,6 @@ namespace stardew_access.Patches } } - internal static void Game1ExitActiveMenuPatch() - { - try - { - IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ExitEventPatch() - { - if (MainClass.ScreenReader != null) - MainClass.ScreenReader.CloseScreenReader(); - } } } diff --git a/stardew-access/Patches/QuestPatches.cs b/stardew-access/Patches/QuestPatches.cs deleted file mode 100644 index cbe8441..0000000 --- a/stardew-access/Patches/QuestPatches.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewValley; -using StardewValley.Menus; -using StardewValley.Quests; - -namespace stardew_access.Patches -{ - internal class QuestPatches - { - } -} From a250cbd98df64a8a2e96aee31fa0bf1049320b7e Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:35:46 +0530 Subject: [PATCH 33/40] Renamed classes --- stardew-access/HarmonyPatches.cs | 2 +- .../{CarpenterMenuPach.cs => CarpenterMenuPatch.cs} | 0 .../Patches/{ChatMenuPatches.cs => ChatMenuPatch.cs} | 7 +++---- stardew-access/Patches/MenuPatches.cs | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) rename stardew-access/Patches/{CarpenterMenuPach.cs => CarpenterMenuPatch.cs} (100%) rename stardew-access/Patches/{ChatMenuPatches.cs => ChatMenuPatch.cs} (93%) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index cb8d85c..b6cf1e3 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -213,7 +213,7 @@ namespace stardew_access #region Chat Menu Patches harmony.Patch( original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(ChatMenuPatches), nameof(ChatMenuPatches.ChatBoxPatch)) + postfix: new HarmonyMethod(typeof(ChatMenuPatch), nameof(ChatMenuPatch.UpdatePatch)) ); #endregion diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPatch.cs similarity index 100% rename from stardew-access/Patches/CarpenterMenuPach.cs rename to stardew-access/Patches/CarpenterMenuPatch.cs diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatch.cs similarity index 93% rename from stardew-access/Patches/ChatMenuPatches.cs rename to stardew-access/Patches/ChatMenuPatch.cs index c997ac7..a0b521e 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatch.cs @@ -1,14 +1,13 @@ -using StardewValley; -using StardewValley.Menus; +using StardewValley.Menus; namespace stardew_access.Patches { - internal class ChatMenuPatches + internal class ChatMenuPatch { private static int currentChatMessageIndex = 0; private static bool isChatRunning = false; - internal static void ChatBoxPatch(ChatBox __instance, List ___messages) + internal static void UpdatePatch(ChatBox __instance, List ___messages) { try { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 1aa61a1..46acc3f 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -311,7 +311,6 @@ namespace stardew_access.Patches } } - internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) { try From 64300c58eb3032280cf04ede83718b3190ae0a51 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:41:30 +0530 Subject: [PATCH 34/40] Moved item list menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ItemListMenuPatch.cs | 55 +++++++++++++++++++ stardew-access/Patches/MenuPatches.cs | 46 ---------------- 4 files changed, 57 insertions(+), 48 deletions(-) create mode 100644 stardew-access/Patches/ItemListMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index b6cf1e3..f894686 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -189,7 +189,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ItemListMenu), nameof(ItemListMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ItemListMenuPatch)) + postfix: new HarmonyMethod(typeof(ItemListMenuPatch), nameof(ItemListMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index f935345..35ffe98 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -296,7 +296,7 @@ namespace stardew_access.Patches } else if (menu is ItemListMenu) { - MenuPatches.itemListMenuQuery = " "; + ItemListMenuPatch.Cleanup(); } else if (menu is FieldOfficeMenu) { diff --git a/stardew-access/Patches/ItemListMenuPatch.cs b/stardew-access/Patches/ItemListMenuPatch.cs new file mode 100644 index 0000000..e94a206 --- /dev/null +++ b/stardew-access/Patches/ItemListMenuPatch.cs @@ -0,0 +1,55 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ItemListMenuPatch + { + private static string itemListMenuQuery = ""; + + internal static void DrawPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = "", currentList = ""; + + for (int i = ___currentTab * __instance.itemsPerCategoryPage; i < ___currentTab * __instance.itemsPerCategoryPage + __instance.itemsPerCategoryPage; i++) + { + if (i == 0) currentList = ___title; + if (___itemsToList.Count <= i) continue; + + if (___itemsToList[i] == null) + { + currentList = $"{currentList}, \n" + Game1.content.LoadString("Strings\\UI:ItemList_ItemsLostValue", ___totalValueOfItems); + continue; + } + + currentList = $"{currentList}, \n {___itemsToList[i].Stack} {___itemsToList[i].DisplayName}"; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = $"Page {___currentTab + 1} of {((int)___itemsToList.Count / __instance.itemsPerCategoryPage) + 1} \n {currentList} \n ok button"; + else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next page button"; + else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + toSpeak = "Previous page button"; + + if (itemListMenuQuery != toSpeak) + { + itemListMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + itemListMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 46acc3f..20ca4c4 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -15,52 +15,8 @@ namespace stardew_access.Patches internal static string tailoringMenuQuery = " "; internal static string pondQueryMenuQuery = " "; internal static string forgeMenuQuery = " "; - internal static string itemListMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " ", currentList = " "; - - for (int i = ___currentTab * __instance.itemsPerCategoryPage; i < ___currentTab * __instance.itemsPerCategoryPage + __instance.itemsPerCategoryPage; i++) - { - if (i == 0) - currentList = ___title; - - if (___itemsToList.Count > i) - { - if (___itemsToList[i] == null) - { - currentList = $"{currentList}, \n" + Game1.content.LoadString("Strings\\UI:ItemList_ItemsLostValue", ___totalValueOfItems); - continue; - } - - currentList = $"{currentList}, \n {___itemsToList[i].Stack} {___itemsToList[i].DisplayName}"; - } - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = $"Page {___currentTab + 1} of {((int)___itemsToList.Count / __instance.itemsPerCategoryPage) + 1} \n {currentList} \n ok button"; - else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next page button"; - else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - toSpeak = "Previous page button"; - - if (itemListMenuQuery != toSpeak) - { - itemListMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ForgeMenuPatch(ForgeMenu __instance) { try @@ -570,7 +526,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - } } From 07fcc942960ce66790891f8054a486f0ca215cb8 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:50:40 +0530 Subject: [PATCH 35/40] Moved forge menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/ForgeMenuPatch.cs | 116 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 85 ------------- 4 files changed, 118 insertions(+), 87 deletions(-) create mode 100644 stardew-access/Patches/ForgeMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index f894686..5e84c6b 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -184,7 +184,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ForgeMenu), nameof(ForgeMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ForgeMenuPatch)) + postfix: new HarmonyMethod(typeof(ForgeMenuPatch), nameof(ForgeMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/ForgeMenuPatch.cs b/stardew-access/Patches/ForgeMenuPatch.cs new file mode 100644 index 0000000..d5b6671 --- /dev/null +++ b/stardew-access/Patches/ForgeMenuPatch.cs @@ -0,0 +1,116 @@ +using stardew_access.Features; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ForgeMenuPatch + { + private static string forgeMenuQuery = ""; + + internal static void DrawPatch(ForgeMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (narrateHoveredButton(__instance, x, y)) return; + + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + { + Cleanup(); + } + + } + catch (System.Exception e) + { + MainClass.ErrorLog($"An error occured in forge menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static bool narrateHoveredButton(ForgeMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) + { + if (__instance.leftIngredientSpot.item == null) + { + toSpeak = "Input weapon or tool here"; + } + else + { + Item item = __instance.leftIngredientSpot.item; + toSpeak = $"Weapon slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) + { + if (__instance.rightIngredientSpot.item == null) + { + toSpeak = "Input gemstone here"; + } + else + { + Item item = __instance.rightIngredientSpot.item; + toSpeak = $"Gemstone slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) + { + toSpeak = "Star forging button"; + } + else if (__instance.unforgeButton != null && __instance.unforgeButton.containsPoint(x, y)) + { + toSpeak = "Unforge button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trashcan"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "drop item"; + isDropItemButton = true; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) + { + toSpeak = "Left ring Slot"; + + if (Game1.player.leftRing.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.leftRing.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) + { + toSpeak = "Right ring Slot"; + + if (Game1.player.rightRing.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.rightRing.Value.DisplayName}"; + } + else + { + return false; + } + + if (forgeMenuQuery != toSpeak) + { + forgeMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + internal static void Cleanup() + { + forgeMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 35ffe98..6f8f121 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -292,7 +292,7 @@ namespace stardew_access.Patches } else if (menu is ForgeMenu) { - MenuPatches.forgeMenuQuery = " "; + ForgeMenuPatch.Cleanup(); } else if (menu is ItemListMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 20ca4c4..9a1b2d4 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -14,93 +14,8 @@ namespace stardew_access.Patches internal static bool isNarratingPondInfo = false; internal static string tailoringMenuQuery = " "; internal static string pondQueryMenuQuery = " "; - internal static string forgeMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void ForgeMenuPatch(ForgeMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " "; - - if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) - { - if (__instance.leftIngredientSpot.item == null) - { - toSpeak = "Input weapon or tool here"; - } - else - { - Item item = __instance.leftIngredientSpot.item; - toSpeak = $"Weapon slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) - { - if (__instance.rightIngredientSpot.item == null) - { - toSpeak = "Input gemstone here"; - } - else - { - Item item = __instance.rightIngredientSpot.item; - toSpeak = $"Gemstone slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) - { - toSpeak = "Star forging button"; - } - else if (__instance.unforgeButton != null && __instance.unforgeButton.containsPoint(x, y)) - { - toSpeak = "Unforge button"; - } - else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - toSpeak = "Trashcan"; - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "drop item"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) - { - toSpeak = "Left ring Slot"; - - if (Game1.player.leftRing.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.leftRing.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) - { - toSpeak = "Right ring Slot"; - - if (Game1.player.rightRing.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.rightRing.Value.DisplayName}"; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - if (forgeMenuQuery != toSpeak) - { - forgeMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - Game1.playSound("drop_item"); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void PondQueryMenuPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) { try From af0ec1ab8d55231f3cc3f553ba5463640bd9d103 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:55:07 +0530 Subject: [PATCH 36/40] Moved pond query menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 56 --------------- stardew-access/Patches/PondQuerMenuPatch.cs | 72 +++++++++++++++++++ 4 files changed, 74 insertions(+), 58 deletions(-) create mode 100644 stardew-access/Patches/PondQuerMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 5e84c6b..d576d60 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -179,7 +179,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(PondQueryMenu), nameof(PondQueryMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.PondQueryMenuPatch)) + postfix: new HarmonyMethod(typeof(PondQueryMenuPatch), nameof(PondQueryMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 6f8f121..993c4f3 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -308,7 +308,7 @@ namespace stardew_access.Patches } else if (menu is PondQueryMenu) { - MenuPatches.pondQueryMenuQuery = " "; + PondQueryMenuPatch.Cleanup(); } else if (menu is GeodeMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 9a1b2d4..0cca006 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -11,65 +11,9 @@ namespace stardew_access.Patches { internal static string currentLevelUpTitle = " "; internal static bool firstTimeInNamingMenu = true; - internal static bool isNarratingPondInfo = false; internal static string tailoringMenuQuery = " "; - internal static string pondQueryMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void PondQueryMenuPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - string toSpeak = " ", extra = ""; - - if (___confirmingEmpty) - { - if (__instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm button"; - else if (__instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel button"; - } - else - { - if (isPrimaryInfoKeyPressed && !isNarratingPondInfo) - { - string pond_name_text = Game1.content.LoadString("Strings\\UI:PondQuery_Name", ____fishItem.DisplayName); - string population_text = Game1.content.LoadString("Strings\\UI:PondQuery_Population", string.Concat(____pond.FishCount), ____pond.maxOccupants.Value); - bool has_unresolved_needs = ____pond.neededItem.Value != null && ____pond.HasUnresolvedNeeds() && !____pond.hasCompletedRequest.Value; - string bring_text = ""; - - if (has_unresolved_needs && ____pond.neededItem.Value != null) - bring_text = Game1.content.LoadString("Strings\\UI:PondQuery_StatusRequest_Bring") + $": {____pond.neededItemCount} {____pond.neededItem.Value.DisplayName}"; - - extra = $"{pond_name_text} {population_text} {bring_text} Status: {____statusText}"; - pondQueryMenuQuery = " "; - - isNarratingPondInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingPondInfo = false; }); - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "Ok button"; - else if (__instance.changeNettingButton != null && __instance.changeNettingButton.containsPoint(x, y)) - toSpeak = "Change netting button"; - else if (__instance.emptyButton != null && __instance.emptyButton.containsPoint(x, y)) - toSpeak = "Empty pond button"; - } - - if (pondQueryMenuQuery != toSpeak) - { - pondQueryMenuQuery = toSpeak; - MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void TailoringMenuPatch(TailoringMenu __instance) { try diff --git a/stardew-access/Patches/PondQuerMenuPatch.cs b/stardew-access/Patches/PondQuerMenuPatch.cs new file mode 100644 index 0000000..a370fc1 --- /dev/null +++ b/stardew-access/Patches/PondQuerMenuPatch.cs @@ -0,0 +1,72 @@ +using StardewValley; +using StardewValley.Buildings; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class PondQueryMenuPatch + { + private static string pondQueryMenuQuery = ""; + private static bool isNarratingPondInfo = false; + + internal static void DrawPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + string toSpeak = "", extra = ""; + + if (___confirmingEmpty) + { + if (__instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm button"; + else if (__instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel button"; + } + else + { + if (isPrimaryInfoKeyPressed && !isNarratingPondInfo) + { + string pond_name_text = Game1.content.LoadString("Strings\\UI:PondQuery_Name", ____fishItem.DisplayName); + string population_text = Game1.content.LoadString("Strings\\UI:PondQuery_Population", string.Concat(____pond.FishCount), ____pond.maxOccupants.Value); + bool has_unresolved_needs = ____pond.neededItem.Value != null && ____pond.HasUnresolvedNeeds() && !____pond.hasCompletedRequest.Value; + string bring_text = ""; + + if (has_unresolved_needs && ____pond.neededItem.Value != null) + bring_text = Game1.content.LoadString("Strings\\UI:PondQuery_StatusRequest_Bring") + $": {____pond.neededItemCount} {____pond.neededItem.Value.DisplayName}"; + + extra = $"{pond_name_text} {population_text} {bring_text} Status: {____statusText}"; + pondQueryMenuQuery = ""; + + isNarratingPondInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingPondInfo = false; }); + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "Ok button"; + else if (__instance.changeNettingButton != null && __instance.changeNettingButton.containsPoint(x, y)) + toSpeak = "Change netting button"; + else if (__instance.emptyButton != null && __instance.emptyButton.containsPoint(x, y)) + toSpeak = "Empty pond button"; + } + + if (pondQueryMenuQuery != toSpeak) + { + pondQueryMenuQuery = toSpeak; + MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + pondQueryMenuQuery = ""; + isNarratingPondInfo = false; + } + } +} From b0c1d9e17368b2d126d518d09afa9340f100d700 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:00:31 +0530 Subject: [PATCH 37/40] Moved tailoring menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 89 -------------- stardew-access/Patches/TailoringMenuPatch.cs | 115 ++++++++++++++++++ 4 files changed, 117 insertions(+), 91 deletions(-) create mode 100644 stardew-access/Patches/TailoringMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index d576d60..fc08646 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -174,7 +174,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(TailoringMenu), nameof(TailoringMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.TailoringMenuPatch)) + postfix: new HarmonyMethod(typeof(TailoringMenuPatch), nameof(TailoringMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 993c4f3..6668365 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -288,7 +288,7 @@ namespace stardew_access.Patches } else if (menu is TailoringMenu) { - MenuPatches.tailoringMenuQuery = " "; + TailoringMenuPatch.Cleanup(); } else if (menu is ForgeMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 0cca006..420073d 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -11,97 +11,8 @@ namespace stardew_access.Patches { internal static string currentLevelUpTitle = " "; internal static bool firstTimeInNamingMenu = true; - internal static string tailoringMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void TailoringMenuPatch(TailoringMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " "; - - if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) - { - if (__instance.leftIngredientSpot.item == null) - { - toSpeak = "Input cloth here"; - } - else - { - Item item = __instance.leftIngredientSpot.item; - toSpeak = $"Cloth slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) - { - if (__instance.rightIngredientSpot.item == null) - { - toSpeak = "Input ingredient here"; - } - else - { - Item item = __instance.rightIngredientSpot.item; - toSpeak = $"Ingredient slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) - { - toSpeak = "Star tailoring button"; - } - else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - toSpeak = "Trashcan"; - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "drop item"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) - { - toSpeak = "Hat Slot"; - - if (Game1.player.hat.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.hat.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) - { - toSpeak = "Shirt Slot"; - - if (Game1.player.shirtItem.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.shirtItem.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[2].containsPoint(x, y)) - { - toSpeak = "Pants Slot"; - - if (Game1.player.pantsItem.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}"; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - - if (tailoringMenuQuery != toSpeak) - { - tailoringMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - Game1.playSound("drop_item"); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ChooseFromListMenuPatch(ChooseFromListMenu __instance, List ___options, int ___index, bool ___isJukebox) { try diff --git a/stardew-access/Patches/TailoringMenuPatch.cs b/stardew-access/Patches/TailoringMenuPatch.cs new file mode 100644 index 0000000..3718730 --- /dev/null +++ b/stardew-access/Patches/TailoringMenuPatch.cs @@ -0,0 +1,115 @@ +using stardew_access.Features; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TailoringMenuPatch + { + internal static string tailoringMenuQuery = ""; + + internal static void DrawPatch(TailoringMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; + + + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static bool narrateHoveredButton(TailoringMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) + { + if (__instance.leftIngredientSpot.item == null) + { + toSpeak = "Input cloth here"; + } + else + { + Item item = __instance.leftIngredientSpot.item; + toSpeak = $"Cloth slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) + { + if (__instance.rightIngredientSpot.item == null) + { + toSpeak = "Input ingredient here"; + } + else + { + Item item = __instance.rightIngredientSpot.item; + toSpeak = $"Ingredient slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) + { + toSpeak = "Star tailoring button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trashcan"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "drop item"; + isDropItemButton = true; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) + { + toSpeak = "Hat Slot"; + + if (Game1.player.hat.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.hat.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) + { + toSpeak = "Shirt Slot"; + + if (Game1.player.shirtItem.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.shirtItem.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[2].containsPoint(x, y)) + { + toSpeak = "Pants Slot"; + + if (Game1.player.pantsItem.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}"; + } + else { + return false; + } + + if (tailoringMenuQuery != toSpeak) + { + tailoringMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + internal static void Cleanup() + { + tailoringMenuQuery = ""; + } + } +} From ea03f9a4cbf0f71b59436ccc021cdf341d6fe98f Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:09:56 +0530 Subject: [PATCH 38/40] Moved some menus to their own class --- stardew-access/HarmonyPatches.cs | 6 +- .../Patches/ChooseFromListMenuPatch.cs | 32 ++++++++ .../Patches/LanguageSelectionMenuPatch.cs | 41 ++++++++++ stardew-access/Patches/MenuPatches.cs | 74 ------------------- .../Patches/MineElevatorMenuPatch.cs | 28 +++++++ 5 files changed, 104 insertions(+), 77 deletions(-) create mode 100644 stardew-access/Patches/ChooseFromListMenuPatch.cs create mode 100644 stardew-access/Patches/LanguageSelectionMenuPatch.cs create mode 100644 stardew-access/Patches/MineElevatorMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index fc08646..35db304 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -159,17 +159,17 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(MineElevatorMenu), nameof(MineElevatorMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.MineElevatorMenuPatch)) + postfix: new HarmonyMethod(typeof(MineElevatorMenuPatch), nameof(MineElevatorMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(LanguageSelectionMenu), nameof(LanguageSelectionMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LanguageSelectionMenuPatch)) + postfix: new HarmonyMethod(typeof(LanguageSelectionMenuPatch), nameof(LanguageSelectionMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(ChooseFromListMenu), nameof(ChooseFromListMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ChooseFromListMenuPatch)) + postfix: new HarmonyMethod(typeof(ChooseFromListMenuPatch), nameof(ChooseFromListMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/ChooseFromListMenuPatch.cs b/stardew-access/Patches/ChooseFromListMenuPatch.cs new file mode 100644 index 0000000..2e19781 --- /dev/null +++ b/stardew-access/Patches/ChooseFromListMenuPatch.cs @@ -0,0 +1,32 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ChooseFromListMenuPatch + { + internal static void DrawPatch(ChooseFromListMenu __instance, List ___options, int ___index, bool ___isJukebox) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = ""; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "Select " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[___index]) : ___options[___index]) + " button"; + else if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) + toSpeak = "Cancel button"; + else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + toSpeak = "Previous option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Max(0, ___index - 1)]) : ___options[Math.Max(0, ___index - 1)]) + " button"; + else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Min(___options.Count, ___index + 1)]) : ___options[Math.Min(___options.Count, ___index + 1)]) + " button"; + + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/LanguageSelectionMenuPatch.cs b/stardew-access/Patches/LanguageSelectionMenuPatch.cs new file mode 100644 index 0000000..968a171 --- /dev/null +++ b/stardew-access/Patches/LanguageSelectionMenuPatch.cs @@ -0,0 +1,41 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class LanguageSelectionMenuPatch + { + internal static void DrawPatch(LanguageSelectionMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"Next Page Button", true); + return; + } + + if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"Previous Page Button", true); + return; + } + + for (int i = 0; i < __instance.languages.Count; i++) + { + if (__instance.languages[i].containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"{__instance.languageList[i]} Button", true); + break; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 420073d..6e343cd 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -13,82 +13,8 @@ namespace stardew_access.Patches internal static bool firstTimeInNamingMenu = true; internal static int prevSlotIndex = -999; - internal static void ChooseFromListMenuPatch(ChooseFromListMenu __instance, List ___options, int ___index, bool ___isJukebox) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = ""; - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "Select " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[___index]) : ___options[___index]) + " button"; - else if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) - toSpeak = "Cancel button"; - else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - toSpeak = "Previous option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Max(0, ___index - 1)]) : ___options[Math.Max(0, ___index - 1)]) + " button"; - else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Min(___options.Count, ___index + 1)]) : ___options[Math.Min(___options.Count, ___index + 1)]) + " button"; - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"Next Page Button", true); - return; - } - - if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"Previous Page Button", true); - return; - } - - for (int i = 0; i < __instance.languages.Count; i++) - { - if (__instance.languages[i].containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"{__instance.languageList[i]} Button", true); - break; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void MineElevatorMenuPatch(List ___elevators) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - for (int i = 0; i < ___elevators.Count; i++) - { - if (___elevators[i].containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"{___elevators[i].name} level", true); - break; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } internal static void TitleTextInputMenuPatch(TitleTextInputMenu __instance) { diff --git a/stardew-access/Patches/MineElevatorMenuPatch.cs b/stardew-access/Patches/MineElevatorMenuPatch.cs new file mode 100644 index 0000000..c1110f1 --- /dev/null +++ b/stardew-access/Patches/MineElevatorMenuPatch.cs @@ -0,0 +1,28 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class MineElevatorMenuPatch + { + internal static void DrawPatch(List ___elevators) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + for (int i = 0; i < ___elevators.Count; i++) + { + if (___elevators[i].containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"{___elevators[i].name} level", true); + break; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From b8fce68bec27a74a2f0eff61a180b3030043d666 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:24:08 +0530 Subject: [PATCH 39/40] Moved more menus to their own class --- stardew-access/HarmonyPatches.cs | 10 +- .../Patches/ConfirmationDialogMenuPatch.cs | 32 +++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/LevelUpMenuPatch.cs | 109 +++++++++ stardew-access/Patches/MenuPatches.cs | 226 ------------------ stardew-access/Patches/NamingMenuPatch.cs | 42 ++++ stardew-access/Patches/ShippingMenuPatch.cs | 46 ++++ .../Patches/TitleTextInputMenuPatch.cs | 27 +++ 8 files changed, 262 insertions(+), 232 deletions(-) create mode 100644 stardew-access/Patches/ConfirmationDialogMenuPatch.cs create mode 100644 stardew-access/Patches/LevelUpMenuPatch.cs delete mode 100644 stardew-access/Patches/MenuPatches.cs create mode 100644 stardew-access/Patches/NamingMenuPatch.cs create mode 100644 stardew-access/Patches/ShippingMenuPatch.cs create mode 100644 stardew-access/Patches/TitleTextInputMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 35db304..5171631 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -134,27 +134,27 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ShippingMenu), nameof(ShippingMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ShippingMenuPatch)) + postfix: new HarmonyMethod(typeof(ShippingMenuPatch), nameof(ShippingMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(LevelUpMenu), nameof(LevelUpMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LevelUpMenuPatch)) + postfix: new HarmonyMethod(typeof(LevelUpMenuPatch), nameof(LevelUpMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(ConfirmationDialog), nameof(ConfirmationDialog.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ConfirmationDialogPatch)) + postfix: new HarmonyMethod(typeof(ConfirmationDialogMenuPatch), nameof(ConfirmationDialogMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(TitleTextInputMenu), nameof(TitleTextInputMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.TitleTextInputMenuPatch)) + postfix: new HarmonyMethod(typeof(TitleTextInputMenuPatch), nameof(TitleTextInputMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(NamingMenu), nameof(NamingMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.NamingMenuPatch)) + postfix: new HarmonyMethod(typeof(NamingMenuPatch), nameof(NamingMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/ConfirmationDialogMenuPatch.cs b/stardew-access/Patches/ConfirmationDialogMenuPatch.cs new file mode 100644 index 0000000..ffde9ec --- /dev/null +++ b/stardew-access/Patches/ConfirmationDialogMenuPatch.cs @@ -0,0 +1,32 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ConfirmationDialogMenuPatch + { + internal static void DrawPatch(ConfirmationDialog __instance, string ___message) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string toSpeak = ___message; + + if (__instance.okButton.containsPoint(x, y)) + { + toSpeak += "\n\tOk Button"; + } + else if (__instance.cancelButton.containsPoint(x, y)) + { + toSpeak += "\n\tCancel Button"; + } + + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 6668365..7069fb5 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -231,7 +231,7 @@ namespace stardew_access.Patches } else if (menu is LevelUpMenu) { - MenuPatches.currentLevelUpTitle = " "; + LevelUpMenuPatch.Cleanup(); } else if (menu is Billboard) { diff --git a/stardew-access/Patches/LevelUpMenuPatch.cs b/stardew-access/Patches/LevelUpMenuPatch.cs new file mode 100644 index 0000000..cb4535b --- /dev/null +++ b/stardew-access/Patches/LevelUpMenuPatch.cs @@ -0,0 +1,109 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class LevelUpMenuPatch + { + private static string currentLevelUpTitle = ""; + + internal static void DrawPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title, bool ___isActive, bool ___isProfessionChooser) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + 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)) + { + if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) + { + Game1.player.professions.Add(___professionsToChoose[0]); + __instance.getImmediateProfessionPerk(___professionsToChoose[0]); + ___isActive = false; + __instance.informationUp = false; + ___isProfessionChooser = false; + __instance.RemoveLevelFromLevelList(); + __instance.exitThisMenu(); + return; + } + + toSpeak = $"Selected: {leftProfession} Left click to choose."; + } + + if (__instance.rightProfession.containsPoint(x, y)) + { + if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) + { + Game1.player.professions.Add(___professionsToChoose[1]); + __instance.getImmediateProfessionPerk(___professionsToChoose[1]); + ___isActive = false; + __instance.informationUp = false; + ___isProfessionChooser = false; + __instance.RemoveLevelFromLevelList(); + __instance.exitThisMenu(); + return; + } + + 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)) + { + if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) + __instance.okButtonClicked(); + + toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close."; + } + + if (toSpeak != "") + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") + { + MainClass.ScreenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true); + currentLevelUpTitle = $"{___title}. Select a new profession."; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + currentLevelUpTitle = ""; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs deleted file mode 100644 index 6e343cd..0000000 --- a/stardew-access/Patches/MenuPatches.cs +++ /dev/null @@ -1,226 +0,0 @@ -using Microsoft.Xna.Framework; -using stardew_access.Features; -using StardewModdingAPI; -using StardewValley; -using StardewValley.Buildings; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class MenuPatches - { - internal static string currentLevelUpTitle = " "; - internal static bool firstTimeInNamingMenu = true; - internal static int prevSlotIndex = -999; - - - - - internal static void TitleTextInputMenuPatch(TitleTextInputMenu __instance) - { - try - { - string toSpeak = ""; - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.pasteButton != null && __instance.pasteButton.containsPoint(x, y)) - toSpeak = $"Paste button"; - - if (toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void NamingMenuPatch(NamingMenu __instance, TextBox ___textBox, string ___title) - { - try - { - if (firstTimeInNamingMenu) - { - firstTimeInNamingMenu = false; - ___textBox.Selected = false; - } - - if (TextBoxPatch.isAnyTextBoxActive) return; - - string toSpeak = ""; - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box - - if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = $"{___title} text box"; - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - toSpeak = $"Done naming button"; - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - toSpeak = $"Random button"; - - if (toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void ConfirmationDialogPatch(ConfirmationDialog __instance, string ___message) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - string toSpeak = ___message; - - if (__instance.okButton.containsPoint(x, y)) - { - toSpeak += "\n\tOk Button"; - } - else if (__instance.cancelButton.containsPoint(x, y)) - { - toSpeak += "\n\tCancel Button"; - } - - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void LevelUpMenuPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title, bool ___isActive, bool ___isProfessionChooser) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - 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)) - { - if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) - { - Game1.player.professions.Add(___professionsToChoose[0]); - __instance.getImmediateProfessionPerk(___professionsToChoose[0]); - ___isActive = false; - __instance.informationUp = false; - ___isProfessionChooser = false; - __instance.RemoveLevelFromLevelList(); - __instance.exitThisMenu(); - return; - } - - toSpeak = $"Selected: {leftProfession} Left click to choose."; - } - - if (__instance.rightProfession.containsPoint(x, y)) - { - if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) - { - Game1.player.professions.Add(___professionsToChoose[1]); - __instance.getImmediateProfessionPerk(___professionsToChoose[1]); - ___isActive = false; - __instance.informationUp = false; - ___isProfessionChooser = false; - __instance.RemoveLevelFromLevelList(); - __instance.exitThisMenu(); - return; - } - - 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)) - { - if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) - __instance.okButtonClicked(); - - toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close."; - } - - if (toSpeak != " ") - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") - { - MainClass.ScreenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true); - currentLevelUpTitle = $"{___title}. Select a new profession."; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void ShippingMenuPatch(ShippingMenu __instance, List ___categoryTotals) - { - try - { - - if (__instance.currentPage == -1) - { - int total = ___categoryTotals[5]; - string toSpeak; - if (__instance.okButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - // Perform Left Click - if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) - { - Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); - } - toSpeak = $"{total}g in total. Press left mouse button to save."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - for (int i = 0; i < __instance.categories.Count; i++) - { - if (__instance.categories[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - } -} diff --git a/stardew-access/Patches/NamingMenuPatch.cs b/stardew-access/Patches/NamingMenuPatch.cs new file mode 100644 index 0000000..06e8f0e --- /dev/null +++ b/stardew-access/Patches/NamingMenuPatch.cs @@ -0,0 +1,42 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class NamingMenuPatch + { + internal static bool firstTimeInNamingMenu = true; + + internal static void DrawPatch(NamingMenu __instance, TextBox ___textBox, string ___title) + { + try + { + if (firstTimeInNamingMenu) + { + firstTimeInNamingMenu = false; + ___textBox.Selected = false; + } + + if (TextBoxPatch.isAnyTextBoxActive) return; + + string toSpeak = ""; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box + + if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = $"{___title} text box"; + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + toSpeak = $"Done naming button"; + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + toSpeak = $"Random button"; + + if (toSpeak != "") + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/ShippingMenuPatch.cs b/stardew-access/Patches/ShippingMenuPatch.cs new file mode 100644 index 0000000..692d9ee --- /dev/null +++ b/stardew-access/Patches/ShippingMenuPatch.cs @@ -0,0 +1,46 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ShippingMenuPatch + { + internal static int prevSlotIndex = -999; + + internal static void DrawPatch(ShippingMenu __instance, List ___categoryTotals) + { + try + { + + if (__instance.currentPage == -1) + { + int total = ___categoryTotals[5]; + string toSpeak; + if (__instance.okButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + // Perform Left Click + if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) + { + Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); + } + toSpeak = $"{total}g in total. Press left mouse button to save."; + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + + for (int i = 0; i < __instance.categories.Count; i++) + { + if (__instance.categories[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/TitleTextInputMenuPatch.cs b/stardew-access/Patches/TitleTextInputMenuPatch.cs new file mode 100644 index 0000000..2ed19ac --- /dev/null +++ b/stardew-access/Patches/TitleTextInputMenuPatch.cs @@ -0,0 +1,27 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TitleTextInputMenuPatch + { + internal static void DrawPatch(TitleTextInputMenu __instance) + { + try + { + string toSpeak = ""; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (__instance.pasteButton != null && __instance.pasteButton.containsPoint(x, y)) + toSpeak = $"Paste button"; + + if (toSpeak != "") + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 2b6b60494e1bc42c14a6972caf77fdc16e7e3ef0 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:33:39 +0530 Subject: [PATCH 40/40] Grouped files --- stardew-access/HarmonyPatches.cs | 2 +- .../Patches/{ => MenuWithInventoryPatches}/ForgeMenuPatch.cs | 0 .../Patches/{ => MenuWithInventoryPatches}/GeodeMenuPatch.cs | 0 .../Patches/{ => MenuWithInventoryPatches}/ItemGrabMenuPatch.cs | 0 .../Patches/{ => MenuWithInventoryPatches}/ShopMenuPatch.cs | 0 .../{ => MenuWithInventoryPatches}/TailoringMenuPatch.cs | 0 .../Patches/{ChatMenuPatch.cs => MiscPatches/ChatBoxPatch.cs} | 2 +- stardew-access/Patches/{ => MiscPatches}/DialogueBoxPatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/Game1Patch.cs | 0 stardew-access/Patches/{ => MiscPatches}/IClickableMenuPatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/InstanceGamePatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/NPCPatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/TextBoxPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/AnimalQueryMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/CarpenterMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/ChooseFromListMenuPatch.cs | 0 .../{ => OtherMenuPatches}/ConfirmationDialogMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/ItemListMenuPatch.cs | 0 .../{ => OtherMenuPatches}/LanguageSelectionMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/LetterViewerMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/LevelUpMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/MineElevatorMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/NamingMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/PondQuerMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/PurchaseAnimalsMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/ShippingMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/TitleTextInputMenuPatch.cs | 0 27 files changed, 2 insertions(+), 2 deletions(-) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/ForgeMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/GeodeMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/ItemGrabMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/ShopMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/TailoringMenuPatch.cs (100%) rename stardew-access/Patches/{ChatMenuPatch.cs => MiscPatches/ChatBoxPatch.cs} (98%) rename stardew-access/Patches/{ => MiscPatches}/DialogueBoxPatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/Game1Patch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/IClickableMenuPatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/InstanceGamePatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/NPCPatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/TextBoxPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/AnimalQueryMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/CarpenterMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ChooseFromListMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ConfirmationDialogMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ItemListMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/LanguageSelectionMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/LetterViewerMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/LevelUpMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/MineElevatorMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/NamingMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/PondQuerMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/PurchaseAnimalsMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ShippingMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/TitleTextInputMenuPatch.cs (100%) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 5171631..659cb28 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -213,7 +213,7 @@ namespace stardew_access #region Chat Menu Patches harmony.Patch( original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(ChatMenuPatch), nameof(ChatMenuPatch.UpdatePatch)) + postfix: new HarmonyMethod(typeof(ChatBoxPatch), nameof(ChatBoxPatch.UpdatePatch)) ); #endregion diff --git a/stardew-access/Patches/ForgeMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/ForgeMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ForgeMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/ForgeMenuPatch.cs diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/GeodeMenuPatch.cs similarity index 100% rename from stardew-access/Patches/GeodeMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/GeodeMenuPatch.cs diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/ItemGrabMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ItemGrabMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/ItemGrabMenuPatch.cs diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/ShopMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ShopMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/ShopMenuPatch.cs diff --git a/stardew-access/Patches/TailoringMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/TailoringMenuPatch.cs similarity index 100% rename from stardew-access/Patches/TailoringMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/TailoringMenuPatch.cs diff --git a/stardew-access/Patches/ChatMenuPatch.cs b/stardew-access/Patches/MiscPatches/ChatBoxPatch.cs similarity index 98% rename from stardew-access/Patches/ChatMenuPatch.cs rename to stardew-access/Patches/MiscPatches/ChatBoxPatch.cs index a0b521e..8ded908 100644 --- a/stardew-access/Patches/ChatMenuPatch.cs +++ b/stardew-access/Patches/MiscPatches/ChatBoxPatch.cs @@ -2,7 +2,7 @@ namespace stardew_access.Patches { - internal class ChatMenuPatch + internal class ChatBoxPatch { private static int currentChatMessageIndex = 0; private static bool isChatRunning = false; diff --git a/stardew-access/Patches/DialogueBoxPatch.cs b/stardew-access/Patches/MiscPatches/DialogueBoxPatch.cs similarity index 100% rename from stardew-access/Patches/DialogueBoxPatch.cs rename to stardew-access/Patches/MiscPatches/DialogueBoxPatch.cs diff --git a/stardew-access/Patches/Game1Patch.cs b/stardew-access/Patches/MiscPatches/Game1Patch.cs similarity index 100% rename from stardew-access/Patches/Game1Patch.cs rename to stardew-access/Patches/MiscPatches/Game1Patch.cs diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/MiscPatches/IClickableMenuPatch.cs similarity index 100% rename from stardew-access/Patches/IClickableMenuPatch.cs rename to stardew-access/Patches/MiscPatches/IClickableMenuPatch.cs diff --git a/stardew-access/Patches/InstanceGamePatch.cs b/stardew-access/Patches/MiscPatches/InstanceGamePatch.cs similarity index 100% rename from stardew-access/Patches/InstanceGamePatch.cs rename to stardew-access/Patches/MiscPatches/InstanceGamePatch.cs diff --git a/stardew-access/Patches/NPCPatch.cs b/stardew-access/Patches/MiscPatches/NPCPatch.cs similarity index 100% rename from stardew-access/Patches/NPCPatch.cs rename to stardew-access/Patches/MiscPatches/NPCPatch.cs diff --git a/stardew-access/Patches/TextBoxPatch.cs b/stardew-access/Patches/MiscPatches/TextBoxPatch.cs similarity index 100% rename from stardew-access/Patches/TextBoxPatch.cs rename to stardew-access/Patches/MiscPatches/TextBoxPatch.cs diff --git a/stardew-access/Patches/AnimalQueryMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs similarity index 100% rename from stardew-access/Patches/AnimalQueryMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs diff --git a/stardew-access/Patches/CarpenterMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/CarpenterMenuPatch.cs similarity index 100% rename from stardew-access/Patches/CarpenterMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/CarpenterMenuPatch.cs diff --git a/stardew-access/Patches/ChooseFromListMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ChooseFromListMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ChooseFromListMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ChooseFromListMenuPatch.cs diff --git a/stardew-access/Patches/ConfirmationDialogMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ConfirmationDialogMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ConfirmationDialogMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ConfirmationDialogMenuPatch.cs diff --git a/stardew-access/Patches/ItemListMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ItemListMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ItemListMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ItemListMenuPatch.cs diff --git a/stardew-access/Patches/LanguageSelectionMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/LanguageSelectionMenuPatch.cs similarity index 100% rename from stardew-access/Patches/LanguageSelectionMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/LanguageSelectionMenuPatch.cs diff --git a/stardew-access/Patches/LetterViewerMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/LetterViewerMenuPatch.cs similarity index 100% rename from stardew-access/Patches/LetterViewerMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/LetterViewerMenuPatch.cs diff --git a/stardew-access/Patches/LevelUpMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/LevelUpMenuPatch.cs similarity index 100% rename from stardew-access/Patches/LevelUpMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/LevelUpMenuPatch.cs diff --git a/stardew-access/Patches/MineElevatorMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/MineElevatorMenuPatch.cs similarity index 100% rename from stardew-access/Patches/MineElevatorMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/MineElevatorMenuPatch.cs diff --git a/stardew-access/Patches/NamingMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/NamingMenuPatch.cs similarity index 100% rename from stardew-access/Patches/NamingMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/NamingMenuPatch.cs diff --git a/stardew-access/Patches/PondQuerMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/PondQuerMenuPatch.cs similarity index 100% rename from stardew-access/Patches/PondQuerMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/PondQuerMenuPatch.cs diff --git a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/PurchaseAnimalsMenuPatch.cs similarity index 100% rename from stardew-access/Patches/PurchaseAnimalsMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/PurchaseAnimalsMenuPatch.cs diff --git a/stardew-access/Patches/ShippingMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ShippingMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ShippingMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ShippingMenuPatch.cs diff --git a/stardew-access/Patches/TitleTextInputMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/TitleTextInputMenuPatch.cs similarity index 100% rename from stardew-access/Patches/TitleTextInputMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/TitleTextInputMenuPatch.cs