JunimoNoteMenu Patch
unknown
json
a month ago
7.6 kB
4
Indexable
Never
using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using HarmonyLib; using StardewModdingAPI; using StardewValley; using StardewValley.ItemTypeDefinitions; using StardewValley.Menus; using StardewValley.BellsAndWhistles; using StardewValley.Extensions; using System.Runtime.CompilerServices; using StardewValley.Inventories; namespace SVBundleTest { internal sealed class ModEntry : Mod { public override void Entry(IModHelper helper) { var harmony = new Harmony(this.ModManifest.UniqueID); harmony.Patch( original: AccessTools.Method(typeof(JunimoNoteMenu), "setUpBundleSpecificPage"), prefix: new HarmonyMethod(typeof(JunimoPatch), nameof(JunimoPatch.BundleSpecificPage_Prefix)) ); } } public class JunimoPatch { private static IMonitor monitor; private static IModHelper helper; public static void Initialize(IMonitor m, IModHelper h) { monitor = m; helper = h; } public static void BundleSpecificPage_Prefix(JunimoNoteMenu __instance, Bundle b) { try { JunimoNoteMenu.tempSprites.Clear(); __instance.currentPageBundle = b; __instance.specificBundlePage = true; if (__instance.whichArea == 4) { if (!__instance.fromGameMenu) { __instance.purchaseButton = new ClickableTextureComponent(new Rectangle(__instance.xPositionOnScreen + 800, __instance.yPositionOnScreen + 504, 260, 72), __instance.noteTexture, new Rectangle(517, 286, 65, 20), 4f) { myID = 797, leftNeighborID = 103 }; if (Game1.options.SnappyMenus) { __instance.currentlySnappedComponent = __instance.purchaseButton; __instance.snapCursorToCurrentSnappedComponent(); } } return; } int numberOfIngredientSlots = b.numberOfIngredientSlots; List<Rectangle> ingredientSlotRectangles = new List<Rectangle>(); helper.Reflection.GetMethod(typeof(JunimoNoteMenu), "addRectangleRowsToList").Invoke(ingredientSlotRectangles, numberOfIngredientSlots, 932, 540); for (int i = 0; i < ingredientSlotRectangles.Count; i++) { __instance.ingredientSlots.Add(new ClickableTextureComponent(ingredientSlotRectangles[i], __instance.noteTexture, new Rectangle(512, 244, 18, 18), 4f) { myID = i + 250, upNeighborID = -99998, rightNeighborID = -99998, leftNeighborID = -99998, downNeighborID = -99998 }); } List<Rectangle> ingredientListRectangles = new List<Rectangle>(); helper.Reflection.GetMethod(typeof(JunimoNoteMenu), "addRectangleRowsToList").Invoke(ingredientListRectangles, b.ingredients.Count, 932, 364); for (int i = 0; i < ingredientListRectangles.Count; i++) { BundleIngredientDescription ingredient = b.ingredients[i]; string id = helper.Reflection.GetMethod(typeof(JunimoNoteMenu), "GetRepresentativeItemId").Invoke<string>(ingredient); ParsedItemData itemData = ItemRegistry.GetDataOrErrorItem(id); if (itemData.HasTypeObject() || itemData.HasTypeBigCraftable()) { string displayName = ingredient.category switch { -2 => Game1.content.LoadString("Strings\\StringsFromCSFiles:CraftingRecipe.cs.569"), -75 => Game1.content.LoadString("Strings\\StringsFromCSFiles:CraftingRecipe.cs.570"), -4 => Game1.content.LoadString("Strings\\StringsFromCSFiles:CraftingRecipe.cs.571"), -5 => Game1.content.LoadString("Strings\\StringsFromCSFiles:CraftingRecipe.cs.572"), -6 => Game1.content.LoadString("Strings\\StringsFromCSFiles:CraftingRecipe.cs.573"), _ => itemData.DisplayName, }; Item item; if (ingredient.preservesId != null) { item = Utility.CreateFlavoredItem(ingredient.id, ingredient.preservesId, ingredient.quality, ingredient.stack); displayName = item.DisplayName; } else { item = ItemRegistry.Create(id, ingredient.stack, ingredient.quality); } Texture2D texture = itemData.GetTexture(); Rectangle sourceRect = itemData.GetSourceRect(); __instance.ingredientList.Add(new ClickableTextureComponent("ingredient_list_slot", ingredientListRectangles[i], "", displayName, texture, sourceRect, 4f) { myID = i + 1000, item = item, upNeighborID = -99998, rightNeighborID = -99998, leftNeighborID = -99998, downNeighborID = -99998 }); } } helper.Reflection.GetMethod(typeof(JunimoNoteMenu), "updateIngredientSlots").Invoke(); if (!Game1.options.SnappyMenus) { return; } __instance.populateClickableComponentList(); if (__instance.inventory?.inventory != null) { for (int i = 0; i < __instance.inventory.inventory.Count; i++) { if (__instance.inventory.inventory[i] != null) { if (__instance.inventory.inventory[i].downNeighborID == 101) { __instance.inventory.inventory[i].downNeighborID = -1; } if (__instance.inventory.inventory[i].leftNeighborID == -1) { __instance.inventory.inventory[i].leftNeighborID = 103; } if (__instance.inventory.inventory[i].upNeighborID >= 1000) { __instance.inventory.inventory[i].upNeighborID = 103; } } } } __instance.currentlySnappedComponent = __instance.getComponentWithID(0); __instance.snapCursorToCurrentSnappedComponent(); return; } catch (Exception ex) { monitor.Log("Error! :("); return; } } } }
Leave a Comment