diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 920489b..303db71 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -174,6 +174,15 @@ namespace stardew_access ); #endregion + #region Animal and Building Menu + + harmony.Patch( + original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.draw), new Type[] { typeof(SpriteBatch) }), + prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.CarpenterMenuPatch)) + ); + + #endregion + harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.playSound)), prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.PlaySoundPatch)) diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs new file mode 100644 index 0000000..3f0f115 --- /dev/null +++ b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs @@ -0,0 +1,160 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class BuildingNAnimalMenuPatches + { + internal static string carpenterMenuQuery = ""; + internal static bool isSayingBlueprintInfo = false; + internal static string prevBlueprintInfo = ""; + internal static void CarpenterMenuPatch(CarpenterMenu __instance, bool ___onFarm, List ___ingredients, int ___price, List ___blueprints, int ___currentBlueprintIndex) + { + if (!___onFarm) + { + #region The blueprint menu + BluePrint currentBluprint = __instance.CurrentBlueprint; + if (currentBluprint == null) + return; + + int x = Game1.getMouseX(), y = Game1.getMouseY(); // Mouse x and y position + bool isBPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.B); + string ingredients = ""; + string name = currentBluprint.displayName; + string upgradeName = currentBluprint.nameOfBuildingToUpgrade; + string description = currentBluprint.description; + string price = $"{___price}g"; + string blueprintInfo; + + #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 = (___ingredients[i] as StardewValley.Object).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}, Description: {description}"; + + if (isBPressed && !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 = "Cunstruct 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 + { + + } + } + private static async void SayBlueprintInfo(string info) + { + isSayingBlueprintInfo = true; + MainClass.screenReader.Say(info, true); + await Task.Delay(300); + isSayingBlueprintInfo = false; + } + } + +} \ No newline at end of file diff --git a/stardew-access/Patches/DialoguePatches.cs b/stardew-access/Patches/DialoguePatches.cs index 322ca7d..a008cb2 100644 --- a/stardew-access/Patches/DialoguePatches.cs +++ b/stardew-access/Patches/DialoguePatches.cs @@ -151,6 +151,9 @@ namespace stardew_access.Patches if (Game1.activeClickableMenu is JunimoNoteMenu) return; + + if (Game1.activeClickableMenu is CarpenterMenu) + return; #endregion StringBuilder toSpeak = new StringBuilder(" "); diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 2b0814a..ecff067 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -1,5 +1,4 @@ - -using StardewModdingAPI; +using StardewModdingAPI; using StardewValley; using StardewValley.Locations; using StardewValley.Menus;