diff --git a/GeneralMods/Revitalize/Framework/Hacks/MenuHacks.cs b/GeneralMods/Revitalize/Framework/Hacks/MenuHacks.cs index dc00e61c..d31b4676 100644 --- a/GeneralMods/Revitalize/Framework/Hacks/MenuHacks.cs +++ b/GeneralMods/Revitalize/Framework/Hacks/MenuHacks.cs @@ -6,7 +6,9 @@ using System.Threading.Tasks; using Revitalize.Framework.Objects; using StardewValley; using StardewValley.BellsAndWhistles; +using StardewValley.Locations; using StardewValley.Menus; +using StardewValley.Objects; namespace Revitalize.Framework.Hacks { @@ -140,8 +142,49 @@ namespace Revitalize.Framework.Hacks { EndOfDay_HasProcessedModdedItems = false; } - + /// + /// Recreates the farmhand's inventory even when they are offline. + /// + /// + /// + public static void RecreateFarmhandInventory(object sender, StardewModdingAPI.Events.MenuChangedEventArgs e) + { + if (e.NewMenu != null) + { + ModCore.log(e.NewMenu.GetType()); + + if (e.NewMenu.GetType() == typeof(StardewValley.Menus.ItemGrabMenu)) + { + if (Game1.player.currentLocation is Cabin) + { + //ModCore.log("Let's get processing!"); + List> addition = new List>(); + for (int i = 0; i < (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory.Count; i++) + { + Item I = (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[i]; + if (I is Chest && I.Name != "Chest") + { + //ModCore.log("Found a custom object!"); + Item cObj = ModCore.Serializer.DeserializeFromFarmhandInventory(I.Name); + if (cObj == null) continue; + addition.Add(new KeyValuePair(i, cObj)); + } + } + + foreach (KeyValuePair pair in addition) + { + (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[pair.Key] = pair.Value; + } + + (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu = new InventoryMenu((Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.xPositionOnScreen, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.yPositionOnScreen, true, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.highlightMethod, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.capacity, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.rows, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.horizontalGap, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.verticalGap, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.drawSlots); + (Game1.activeClickableMenu as ItemGrabMenu).populateClickableComponentList(); + (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.populateClickableComponentList(); + } + } + } + } + } } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 34045f16..f5666cb0 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -267,68 +267,10 @@ namespace Revitalize //Adds in recipes to the mod. VanillaRecipeBook = new VanillaRecipeBook(); - ModHelper.Events.Display.MenuChanged += this.Display_MenuChanged; + ModHelper.Events.Display.MenuChanged += MenuHacks.RecreateFarmhandInventory; } - private void Display_MenuChanged(object sender, StardewModdingAPI.Events.MenuChangedEventArgs e) - { - if (e.NewMenu != null) - { - ModCore.log(e.NewMenu.GetType()); - - if (e.NewMenu.GetType() == typeof(StardewValley.Menus.ItemGrabMenu)) - { - if (Game1.player.currentLocation is Cabin) - { - ModCore.log("Let's get processing!"); - List> addition = new List>(); - for (int i = 0; i < (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory.Count; i++) - { - Item I = (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[i]; - if (I is Chest && I.Name != "Chest") - { - ModCore.log("Found a custom object!"); - Item cObj= ModCore.Serializer.DeserializeFromFarmhandInventory(I.Name); - if (cObj == null) - { - ModCore.log("NULL OBJ"); - } - else - { - ModCore.log("Not null!"); - } - if (cObj == null) continue; - addition.Add(new KeyValuePair(i,cObj)); - } - } - - /* - for(int I=0; I< (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory.Count; I++) - { - if((Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[I] == null) - { - if (addition.Count > 0) { - (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[I] = addition[0].Value; - addition.RemoveAt(0); - } - } - } - */ - - foreach(KeyValuePair pair in addition) - { - (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory[pair.Key] = pair.Value; - } - - (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu = new InventoryMenu((Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.xPositionOnScreen, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.yPositionOnScreen, true, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.actualInventory, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.highlightMethod, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.capacity, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.rows, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.horizontalGap, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.verticalGap, (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.drawSlots); - (Game1.activeClickableMenu as ItemGrabMenu).populateClickableComponentList(); - (Game1.activeClickableMenu as ItemGrabMenu).ItemsToGrabMenu.populateClickableComponentList(); - } - } - } - } - private void GameLoop_Saving(object sender, StardewModdingAPI.Events.SavingEventArgs e) {