Making animal purchase menu accessible
This commit is contained in:
		@@ -333,7 +333,8 @@ namespace stardew_access
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            helper.ConsoleCommands.Add("buildlist", "List all buildings for selection for upgrading/demolishing/painting", (string commmand, string[] args) =>
 | 
					            helper.ConsoleCommands.Add("buildlist", "List all buildings for selection for upgrading/demolishing/painting", (string commmand, string[] args) =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (Game1.activeClickableMenu is not CarpenterMenu || !BuildingNAnimalMenuPatches.isOnFarm)
 | 
					                MainClass.monitor.Log($"{Game1.activeClickableMenu is PurchaseAnimalsMenu}\t{BuildingNAnimalMenuPatches.isOnFarm}", LogLevel.Debug);
 | 
				
			||||||
 | 
					                if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu) || !BuildingNAnimalMenuPatches.isOnFarm)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    MainClass.monitor.Log($"Cannot list buildings.", LogLevel.Info);
 | 
					                    MainClass.monitor.Log($"Cannot list buildings.", LogLevel.Info);
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
@@ -367,9 +368,9 @@ namespace stardew_access
 | 
				
			|||||||
            helper.ConsoleCommands.Add("buildsel", "Select the building index which you want to upgrade/demolish/paint", (string commmand, string[] args) =>
 | 
					            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 || !BuildingNAnimalMenuPatches.isOnFarm)
 | 
					                if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu) || !BuildingNAnimalMenuPatches.isOnFarm)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    MainClass.monitor.Log($"Cannot list buildings.", LogLevel.Info);
 | 
					                    MainClass.monitor.Log($"Cannot select building.", LogLevel.Info);
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -436,11 +437,16 @@ namespace stardew_access
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                string? response = null;
 | 
					                string? response = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (Game1.activeClickableMenu is PurchaseAnimalsMenu) { BuildingNAnimalMenuPatches.PurchaseAnimal(BuildingNAnimalMenuPatches.availableBuildings[index]); }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
                    if (BuildingNAnimalMenuPatches.isConstructing) { response = BuildingNAnimalMenuPatches.Contstruct(BuildingNAnimalMenuPatches.marked[index]); }
 | 
					                    if (BuildingNAnimalMenuPatches.isConstructing) { response = BuildingNAnimalMenuPatches.Contstruct(BuildingNAnimalMenuPatches.marked[index]); }
 | 
				
			||||||
                    else if (BuildingNAnimalMenuPatches.isMoving) { response = BuildingNAnimalMenuPatches.Move(BuildingNAnimalMenuPatches.availableBuildings[index], BuildingNAnimalMenuPatches.marked[positionIndex]); }
 | 
					                    else if (BuildingNAnimalMenuPatches.isMoving) { response = BuildingNAnimalMenuPatches.Move(BuildingNAnimalMenuPatches.availableBuildings[index], BuildingNAnimalMenuPatches.marked[positionIndex]); }
 | 
				
			||||||
                if (BuildingNAnimalMenuPatches.isDemolishing) { response = BuildingNAnimalMenuPatches.Demolish(BuildingNAnimalMenuPatches.availableBuildings[index]); }
 | 
					                    else if (BuildingNAnimalMenuPatches.isDemolishing) { response = BuildingNAnimalMenuPatches.Demolish(BuildingNAnimalMenuPatches.availableBuildings[index]); }
 | 
				
			||||||
                    else if (BuildingNAnimalMenuPatches.isUpgrading) { response = BuildingNAnimalMenuPatches.Upgrade(BuildingNAnimalMenuPatches.availableBuildings[index]); }
 | 
					                    else if (BuildingNAnimalMenuPatches.isUpgrading) { response = BuildingNAnimalMenuPatches.Upgrade(BuildingNAnimalMenuPatches.availableBuildings[index]); }
 | 
				
			||||||
                    else if (BuildingNAnimalMenuPatches.isPainting) { response = BuildingNAnimalMenuPatches.Paint(BuildingNAnimalMenuPatches.availableBuildings[index]); }
 | 
					                    else if (BuildingNAnimalMenuPatches.isPainting) { response = BuildingNAnimalMenuPatches.Paint(BuildingNAnimalMenuPatches.availableBuildings[index]); }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (response != null)
 | 
					                if (response != null)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -181,6 +181,11 @@ namespace stardew_access
 | 
				
			|||||||
                    prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.CarpenterMenuPatch))
 | 
					                    prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.CarpenterMenuPatch))
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            harmony.Patch(
 | 
				
			||||||
 | 
					                    original: AccessTools.Method(typeof(PurchaseAnimalsMenu), nameof(PurchaseAnimalsMenu.draw), new Type[] { typeof(SpriteBatch) }),
 | 
				
			||||||
 | 
					                    prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.PurchaseAnimalsMenuPatch))
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            #endregion
 | 
					            #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            harmony.Patch(
 | 
					            harmony.Patch(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -123,6 +123,17 @@ namespace stardew_access
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        private void OnButtonPressed(object? sender, ButtonPressedEventArgs? e)
 | 
					        private void OnButtonPressed(object? sender, ButtonPressedEventArgs? e)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            if (e == null)
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (Game1.activeClickableMenu != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (Equals(e.Button, SButton.OemOpenBrackets))
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!Context.IsPlayerFree)
 | 
					            if (!Context.IsPlayerFree)
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,10 +13,61 @@ namespace stardew_access.Patches
 | 
				
			|||||||
        internal static Vector2[] marked = new Vector2[10];
 | 
					        internal static Vector2[] marked = new Vector2[10];
 | 
				
			||||||
        internal static Building?[] availableBuildings = new Building[100];
 | 
					        internal static Building?[] availableBuildings = new Building[100];
 | 
				
			||||||
        internal static CarpenterMenu? carpenterMenu = null;
 | 
					        internal static CarpenterMenu? carpenterMenu = null;
 | 
				
			||||||
        internal static string carpenterMenuQuery = "";
 | 
					        internal static string carpenterMenuQuery = "", purchaseAnimalMenuQuery = "";
 | 
				
			||||||
        internal static bool isSayingBlueprintInfo = false;
 | 
					        internal static bool isSayingBlueprintInfo = false;
 | 
				
			||||||
        internal static string prevBlueprintInfo = "";
 | 
					        internal static string prevBlueprintInfo = "";
 | 
				
			||||||
        internal static bool isOnFarm = false, isUpgrading = false, isDemolishing = false, isPainting = false, isConstructing = false, isMoving = false, isMagicalConstruction = false;
 | 
					        internal static bool isOnFarm = false, isUpgrading = false, isDemolishing = false, isPainting = false, isConstructing = false, isMoving = false, isMagicalConstruction = false;
 | 
				
			||||||
 | 
					        internal static PurchaseAnimalsMenu? purchaseAnimalsMenu;
 | 
				
			||||||
 | 
					        internal static void PurchaseAnimalsMenuPatch(PurchaseAnimalsMenu __instance,
 | 
				
			||||||
 | 
					            bool ___onFarm,
 | 
				
			||||||
 | 
					            bool ___namingAnimal,
 | 
				
			||||||
 | 
					            FarmAnimal ___animalBeingPurchased,
 | 
				
			||||||
 | 
					            Building ___newAnimalHome,
 | 
				
			||||||
 | 
					            TextBox ___textBox,
 | 
				
			||||||
 | 
					            TextBoxEvent ___e,
 | 
				
			||||||
 | 
					            int ___priceOfAnimal)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                purchaseAnimalsMenu = __instance;
 | 
				
			||||||
 | 
					                isOnFarm = ___onFarm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (___onFarm && ___namingAnimal)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else if (___onFarm && !___namingAnimal) { }
 | 
				
			||||||
 | 
					                else if (!___onFarm && !___namingAnimal)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    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.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        internal static void CarpenterMenuPatch(
 | 
					        internal static void CarpenterMenuPatch(
 | 
				
			||||||
            CarpenterMenu __instance, bool ___onFarm, List<Item> ___ingredients, int ___price,
 | 
					            CarpenterMenu __instance, bool ___onFarm, List<Item> ___ingredients, int ___price,
 | 
				
			||||||
@@ -186,6 +237,7 @@ namespace stardew_access.Patches
 | 
				
			|||||||
                MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
 | 
					                MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static async void SayBlueprintInfo(string info)
 | 
					        private static async void SayBlueprintInfo(string info)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            isSayingBlueprintInfo = true;
 | 
					            isSayingBlueprintInfo = true;
 | 
				
			||||||
@@ -458,6 +510,18 @@ namespace stardew_access.Patches
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            return response;
 | 
					            return response;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static void PurchaseAnimal(Building? selection)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (selection == null)
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (purchaseAnimalsMenu == null)
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            int x = (selection.tileX * Game1.tileSize) - Game1.viewport.X;
 | 
				
			||||||
 | 
					            int y = (selection.tileY * Game1.tileSize) - Game1.viewport.Y;
 | 
				
			||||||
 | 
					            purchaseAnimalsMenu.receiveLeftClick(x, y);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -154,6 +154,9 @@ namespace stardew_access.Patches
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                if (Game1.activeClickableMenu is CarpenterMenu)
 | 
					                if (Game1.activeClickableMenu is CarpenterMenu)
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (Game1.activeClickableMenu is PurchaseAnimalsMenu)
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
                #endregion
 | 
					                #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                StringBuilder toSpeak = new StringBuilder(" ");
 | 
					                StringBuilder toSpeak = new StringBuilder(" ");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -354,7 +354,7 @@ namespace stardew_access.Patches
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                if (__instance is CarpenterMenu)
 | 
					                if (__instance is CarpenterMenu)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    BuildingNAnimalMenuPatches.isOnFarm = false;
 | 
					                    BuildingNAnimalMenuPatches.carpenterMenuQuery = "";
 | 
				
			||||||
                    BuildingNAnimalMenuPatches.isUpgrading = false;
 | 
					                    BuildingNAnimalMenuPatches.isUpgrading = false;
 | 
				
			||||||
                    BuildingNAnimalMenuPatches.isDemolishing = false;
 | 
					                    BuildingNAnimalMenuPatches.isDemolishing = false;
 | 
				
			||||||
                    BuildingNAnimalMenuPatches.isPainting = false;
 | 
					                    BuildingNAnimalMenuPatches.isPainting = false;
 | 
				
			||||||
@@ -362,6 +362,11 @@ namespace stardew_access.Patches
 | 
				
			|||||||
                    BuildingNAnimalMenuPatches.isConstructing = false;
 | 
					                    BuildingNAnimalMenuPatches.isConstructing = false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (__instance is PurchaseAnimalsMenu)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = "";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                GameMenuPatches.hoveredItemQueryKey = "";
 | 
					                GameMenuPatches.hoveredItemQueryKey = "";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            catch (Exception e)
 | 
					            catch (Exception e)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user