Added keybinds to cycle through crafting recipies

master
shoaib11120 2022-01-07 16:04:37 +05:30
parent a649f3a2ec
commit fcadea8a8b
3 changed files with 88 additions and 28 deletions

View File

@ -200,6 +200,10 @@ namespace stardew_access
original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)),
postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.IClickableMenuOnExitPatch))
);
harmony.Patch(
original: AccessTools.Method(typeof(Game1), nameof(Game1.exitActiveMenu)),
prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.Game1ExitActiveMenuPatch))
);
#endregion
#endregion

View File

@ -16,6 +16,8 @@ namespace stardew_access.Patches
internal static string inventoryPageQueryKey = "";
internal static string exitPageQueryKey = "";
internal static string optionsPageQueryKey = "";
internal static int currentSelectedCraftingRecipe = -1;
internal static bool isSelectingRecipe = false;
internal static void GameMenuPatch(GameMenu __instance)
{
@ -231,11 +233,30 @@ namespace stardew_access.Patches
}
}
internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe)
internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage)
{
try
{
int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; // Mouse x and y position
bool isIPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.I);
bool isCPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.C);
bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift);
if (isLeftShiftPressed && isIPressed && __instance.inventory != null)
{
// snap to first inventory slot
__instance.inventory.inventory[0].snapMouseCursorToCenter();
currentSelectedCraftingRecipe = -1;
}
else if (!isLeftShiftPressed && isIPressed && __instance.inventory != null)
{
// snap to first crafting recipe
__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter();
currentSelectedCraftingRecipe = 0;
} else if (isCPressed && !isSelectingRecipe)
{
_ = CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage);
}
#region Narrate buttons in the menu
if (__instance.upButton != null && __instance.upButton.containsPoint(x, y))
@ -379,6 +400,20 @@ namespace stardew_access.Patches
}
}
private static async Task CycleThroughRecipies(List<Dictionary<ClickableTextureComponent, CraftingRecipe>> pagesOfCraftingRecipes, int ___currentCraftingPage)
{
isSelectingRecipe = true;
currentSelectedCraftingRecipe++;
if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count)
currentSelectedCraftingRecipe = 0;
pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter();
await Task.Delay(200);
isSelectingRecipe = false;
}
// 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<Item> getContainerContents(List<Chest> materialContainers)
@ -415,6 +450,32 @@ namespace stardew_access.Patches
return;
}
if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y))
{
string toSpeak = "Organize Inventory Button";
if (inventoryPageQueryKey != toSpeak)
{
inventoryPageQueryKey = toSpeak;
gameMenuQueryKey = "";
hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true);
}
return;
}
if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y))
{
string toSpeak = "Trash Can";
if (inventoryPageQueryKey != toSpeak)
{
inventoryPageQueryKey = toSpeak;
gameMenuQueryKey = "";
hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true);
}
return;
}
#region Narrate equipment slots
for (int i=0; i<__instance.equipmentIcons.Count; i++)
{

View File

@ -256,6 +256,27 @@ namespace stardew_access.Patches
}
}
internal static void Game1ExitActiveMenuPatch()
{
try
{
if (Game1.activeClickableMenu is GameMenu)
{
GameMenuPatches.gameMenuQueryKey = "";
GameMenuPatches.craftingPageQueryKey = "";
GameMenuPatches.inventoryPageQueryKey = "";
GameMenuPatches.exitPageQueryKey = "";
GameMenuPatches.optionsPageQueryKey = "";
GameMenuPatches.currentSelectedCraftingRecipe = -1;
GameMenuPatches.isSelectingRecipe = false;
}
}
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
internal static void IClickableMenuOnExitPatch(IClickableMenu __instance)
{
try
@ -265,32 +286,6 @@ namespace stardew_access.Patches
GameMenuPatches.geodeMenuQueryKey = "";
}
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is InventoryPage)
{
GameMenuPatches.inventoryPageQueryKey = "";
}
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is CraftingPage)
{
GameMenuPatches.craftingPageQueryKey = "";
}
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is ExitPage)
{
GameMenuPatches.exitPageQueryKey = "";
}
if (Game1.activeClickableMenu is GameMenu && (Game1.activeClickableMenu as GameMenu).GetCurrentPage() is CraftingPage)
{
GameMenuPatches.craftingPageQueryKey = "";
}
// This should be after checking all pages/tabs in the GameMenu
if (Game1.activeClickableMenu is GameMenu)
{
GameMenuPatches.gameMenuQueryKey = "";
}
if(__instance is ItemGrabMenu)
{
GameMenuPatches.itemGrabMenuQueryKey = "";