Making animal purchase menu accessible

master
Mohammad Shoaib 2022-02-04 14:15:24 +05:30
parent c83d06a74f
commit 5100b4fd89
6 changed files with 106 additions and 12 deletions

View File

@ -333,7 +333,8 @@ namespace stardew_access
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);
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) =>
{
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;
}
@ -436,11 +437,16 @@ namespace stardew_access
}
string? response = null;
if (BuildingNAnimalMenuPatches.isConstructing) { response = BuildingNAnimalMenuPatches.Contstruct(BuildingNAnimalMenuPatches.marked[index]); }
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.isUpgrading) { response = BuildingNAnimalMenuPatches.Upgrade(BuildingNAnimalMenuPatches.availableBuildings[index]); }
else if (BuildingNAnimalMenuPatches.isPainting) { response = BuildingNAnimalMenuPatches.Paint(BuildingNAnimalMenuPatches.availableBuildings[index]); }
if (Game1.activeClickableMenu is PurchaseAnimalsMenu) { BuildingNAnimalMenuPatches.PurchaseAnimal(BuildingNAnimalMenuPatches.availableBuildings[index]); }
else
{
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.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 (response != null)
{

View File

@ -181,6 +181,11 @@ namespace stardew_access
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
harmony.Patch(

View File

@ -72,7 +72,7 @@ namespace stardew_access
{
BuildingNAnimalMenuPatches.availableBuildings[i] = null;
}
#endregion
#endregion
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked;
@ -123,6 +123,17 @@ namespace stardew_access
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)
return;

View File

@ -13,10 +13,61 @@ namespace stardew_access.Patches
internal static Vector2[] marked = new Vector2[10];
internal static Building?[] availableBuildings = new Building[100];
internal static CarpenterMenu? carpenterMenu = null;
internal static string carpenterMenuQuery = "";
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 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(
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);
}
}
private static async void SayBlueprintInfo(string info)
{
isSayingBlueprintInfo = true;
@ -458,6 +510,18 @@ namespace stardew_access.Patches
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);
}
}
}

View File

@ -154,6 +154,9 @@ namespace stardew_access.Patches
if (Game1.activeClickableMenu is CarpenterMenu)
return;
if (Game1.activeClickableMenu is PurchaseAnimalsMenu)
return;
#endregion
StringBuilder toSpeak = new StringBuilder(" ");

View File

@ -354,7 +354,7 @@ namespace stardew_access.Patches
if (__instance is CarpenterMenu)
{
BuildingNAnimalMenuPatches.isOnFarm = false;
BuildingNAnimalMenuPatches.carpenterMenuQuery = "";
BuildingNAnimalMenuPatches.isUpgrading = false;
BuildingNAnimalMenuPatches.isDemolishing = false;
BuildingNAnimalMenuPatches.isPainting = false;
@ -362,6 +362,11 @@ namespace stardew_access.Patches
BuildingNAnimalMenuPatches.isConstructing = false;
}
if (__instance is PurchaseAnimalsMenu)
{
BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = "";
}
GameMenuPatches.hoveredItemQueryKey = "";
}
catch (Exception e)