diff --git a/GeneralMods/Revitalize/Framework/Menus/InventoryMenuPage.cs b/GeneralMods/Revitalize/Framework/Menus/InventoryMenuPage.cs index 3d07efb3..2d5e7541 100644 --- a/GeneralMods/Revitalize/Framework/Menus/InventoryMenuPage.cs +++ b/GeneralMods/Revitalize/Framework/Menus/InventoryMenuPage.cs @@ -72,11 +72,11 @@ namespace Revitalize.Framework.Menus { get { - return this.items.Count >= this.capacity && this.items.Where(i=>i==null).Count()==0; + return this.items.Count >= this.capacity && this.items.Where(i => i == null).Count() == 0; } } - public InventoryMenu(int xPos, int yPos, int width, int height, int Rows, int Collumns, bool showCloseButton, IList Inventory, int maxCapacity,Color BackgroundColor) : base(xPos, yPos, width, height, showCloseButton) + public InventoryMenu(int xPos, int yPos, int width, int height, int Rows, int Collumns, bool showCloseButton, IList Inventory, int maxCapacity, Color BackgroundColor) : base(xPos, yPos, width, height, showCloseButton) { //Amount to display is the lower cap per page. // @@ -97,8 +97,8 @@ namespace Revitalize.Framework.Menus Game1.keyboardDispatcher.Subscriber = (IKeyboardSubscriber)this.searchBox; this.searchBox.Selected = false; - this.nextPage = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Next Page", new Vector2(128 + (this.searchBox.X + this.searchBox.Width), this.searchBox.Y),new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "NextPageButton"),new Animation(0,0,32,32)),Color.White),new Rectangle(0, 0, 32, 32), 2f); - this.previousPage= new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Previous Page", new Vector2(64 + (this.searchBox.X + this.searchBox.Width), this.searchBox.Y), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "PreviousPageButton"), new Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); + this.nextPage = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Next Page", new Vector2(128 + (this.searchBox.X + this.searchBox.Width), this.searchBox.Y), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "NextPageButton"), new Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); + this.previousPage = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Previous Page", new Vector2(64 + (this.searchBox.X + this.searchBox.Width), this.searchBox.Y), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "PreviousPageButton"), new Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); } @@ -115,7 +115,7 @@ namespace Revitalize.Framework.Menus this.searchBox.Y = this.yPositionOnScreen; this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); this.nextPage.Position = new Vector2(128 + (this.searchBox.X + this.searchBox.Width), this.searchBox.Y); - this.previousPage.Position= new Vector2(64 + (this.searchBox.X + this.searchBox.Width),this.searchBox.Y); + this.previousPage.Position = new Vector2(64 + (this.searchBox.X + this.searchBox.Width), this.searchBox.Y); } public void populateClickableItems() @@ -241,6 +241,7 @@ namespace Revitalize.Framework.Menus { if (button.receiveLeftClick(x, y)) { + if (index > this.capacity) continue; if (this.activeItem == null) { this.activeItem = button.item; @@ -312,42 +313,42 @@ namespace Revitalize.Framework.Menus } } - /// - /// Swaps the item's position in the menu. - /// - /// - /// - public void swapItemPosition(int insertIndex, Item I) + /// + /// Swaps the item's position in the menu. + /// + /// + /// + public void swapItemPosition(int insertIndex, Item I) + { + if (I == null) + { + //ModCore.log("Odd item is null"); + return; + } + if (insertIndex + 1 > this.items.Count) { - if (I == null) - { - //ModCore.log("Odd item is null"); - return; - } - if (insertIndex + 1 > this.items.Count) - { - this.items.Remove(I); - this.items.Add(I); - this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); - return; - } - this.items.Insert(insertIndex + 1, I); this.items.Remove(I); + this.items.Add(I); this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); + return; } + this.items.Insert(insertIndex + 1, I); + this.items.Remove(I); + this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); + } - /// - /// Takes the active item from this menu. - /// - /// - public Item takeActiveItem() - { - this.items.Remove(this.activeItem); - this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); - Item i = this.activeItem; - this.activeItem = null; - return i; - } + /// + /// Takes the active item from this menu. + /// + /// + public Item takeActiveItem() + { + this.items.Remove(this.activeItem); + this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); + Item i = this.activeItem; + this.activeItem = null; + return i; + } /// /// What happens when this menu is right clicked. @@ -377,22 +378,19 @@ namespace Revitalize.Framework.Menus { this.drawDialogueBoxBackground(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, this.backgroundColor); + int index = -1; foreach (ItemDisplayButton button in this.pages[this.pageIndex].storageDisplay) { - if (string.IsNullOrEmpty(this.searchBox.Text) == false) - { - button.draw(b, 0.25f, this.getItemDrawAlpha(button.item), true); - } - else - { - button.draw(b, 0.25f, 1f, true); - } + index++; + float alpha = this.getItemDrawAlpha(button.item, index + this.pageIndex * this.rows*this.collumns); + button.draw(b, 0.25f, alpha, true); + } this.searchBox.Draw(b, true); - this.nextPage.draw(b,0.25f,1f); - this.previousPage.draw(b,0.25f,1f); + this.nextPage.draw(b, 0.25f, 1f); + this.previousPage.draw(b, 0.25f, 1f); b.DrawString(Game1.dialogueFont, ("Page: " + (this.pageIndex + 1) + " / " + this.pages.Count).ToString(), new Vector2(this.xPositionOnScreen, this.yPositionOnScreen + this.height), Color.White); @@ -412,8 +410,9 @@ namespace Revitalize.Framework.Menus /// /// /// - private float getItemDrawAlpha(Item I) - { + private float getItemDrawAlpha(Item I, int index) + { + if (index >= this.capacity) return 0.0f; if (string.IsNullOrEmpty(this.searchBox.Text) == false) { if (I == null) return 0.25f; diff --git a/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs b/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs index 1a3b21c7..d7120e5b 100644 --- a/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs +++ b/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs @@ -36,11 +36,11 @@ namespace Revitalize.Framework.Menus } private CurrentMode currentMode; - public InventoryTransferMenu(int x, int y, int width, int height, IList OtherItems, int OtherCapacity) : base(x, y, width, height, true) + public InventoryTransferMenu(int x, int y, int width, int height, IList OtherItems, int OtherCapacity,int OtherRows=6,int OtherCollumns=6) : base(x, y, width, height, true) { this.playerInventory = new InventoryMenu(x, y, width, height, 6, 6, true, Game1.player.Items, Game1.player.MaxItems, Color.SandyBrown); this.otherItems = OtherItems; - this.otherInventory = new InventoryMenu(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 128, y, width, height, 6, 6, true, this.otherItems, OtherCapacity, Color.SandyBrown); + this.otherInventory = new InventoryMenu(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 128, y, width, height, OtherRows, OtherCollumns, true, this.otherItems, OtherCapacity, Color.SandyBrown); this.isPlayerInventory = true; this.currentMode = CurrentMode.TransferItems; this.transferButton = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Transfer Button", new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f)), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemTransferButton"), new Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); diff --git a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs index 5bf4401b..14bdcab8 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs @@ -294,7 +294,7 @@ namespace Revitalize.Framework.Objects.Machines if (this.InventoryManager.capacity > 0) { - InventoryTransferMenu transferMenu = new InventoryTransferMenu(100, 150, 500, 600, this.InventoryManager.items, 36); + InventoryTransferMenu transferMenu = new InventoryTransferMenu(100, 150, 500, 600, this.InventoryManager.items, this.InventoryManager.capacity,this.InventoryManager.displayRows,this.InventoryManager.displayColumns); machineMenu.addInMenuTab("Inventory", new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Inventory Tab", new Vector2(), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus", "MenuTab"), new Animation(0, 0, 24, 24)), Color.White), new Rectangle(0, 0, 24, 24), 2f), transferMenu, false); } diff --git a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs index 2ab18da0..7f3acc34 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs @@ -232,8 +232,8 @@ namespace Revitalize.Framework.Objects ///Consumes energy. Produces batteries. - MultiTiledObject batteryBin = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.BatteryBin", TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Battery Bin", "Omegasis.Revitalize.Objects.Machines.BatteryBin", "Consumes energy over time to produce battery packs.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "BatteryBin"), new Animation(0, 0, 16, 16)), Color.White, false, new InventoryManager(1), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Consumes))); - Machine batteryBin_0_0 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.BatteryBin", TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Battery Bin", "Omegasis.Revitalize.Objects.Machines.BatteryBin", "Consumes energy over time to produce battery packs.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "BatteryBin"), new Animation(0, 0, 16, 16)), Color.White, false, new InventoryManager(1), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Consumes)), new List() + MultiTiledObject batteryBin = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.BatteryBin", TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Battery Bin", "Omegasis.Revitalize.Objects.Machines.BatteryBin", "Consumes energy over time to produce battery packs.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "BatteryBin"), new Animation(0, 0, 16, 16)), Color.White, false, new InventoryManager(9,3,3), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Consumes))); + Machine batteryBin_0_0 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.BatteryBin", TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Battery Bin", "Omegasis.Revitalize.Objects.Machines.BatteryBin", "Consumes energy over time to produce battery packs.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "BatteryBin"), new Animation(0, 0, 16, 16)), Color.White, false, new InventoryManager(9,3,3), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Consumes)), new List() { new InformationFiles.ResourceInformation(new StardewValley.Object((int)Enums.SDVObject.BatteryPack,1),1,1,1,1,1,1,0,0,0,0) diff --git a/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs b/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs index 76202707..b2c106ba 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs @@ -40,6 +40,9 @@ namespace Revitalize.Framework.Utilities } } + public int displayRows; + public int displayColumns; + [JsonIgnore] public bool requiresUpdate; public InventoryManager() @@ -51,38 +54,46 @@ namespace Revitalize.Framework.Utilities } /// Construct an instance. - public InventoryManager(List items) + public InventoryManager(List items,int DisplayRows=6,int DisplayColumns=6) { this.capacity = int.MaxValue; this.setMaxLimit(int.MaxValue); this.items = items; this.bufferItems = new List(); + this.displayRows = DisplayRows; + this.displayColumns = DisplayColumns; } - public InventoryManager(IList items) + public InventoryManager(IList items, int DisplayRows = 6, int DisplayColumns = 6) { this.capacity = int.MaxValue; this.setMaxLimit(int.MaxValue); this.items = items; this.bufferItems = new List(); + this.displayRows = DisplayRows; + this.displayColumns = DisplayColumns; } /// Construct an instance. - public InventoryManager(int capacity) + public InventoryManager(int capacity, int DisplayRows = 6, int DisplayColumns = 6) { this.capacity = capacity; this.MaxCapacity = int.MaxValue; this.items = new List(); this.bufferItems = new List(); + this.displayRows = DisplayRows; + this.displayColumns = DisplayColumns; } /// Construct an instance. - public InventoryManager(int capacity, int MaxCapacity) + public InventoryManager(int capacity, int MaxCapacity, int DisplayRows = 6, int DisplayColumns = 6) { this.capacity = capacity; this.setMaxLimit(MaxCapacity); this.items = new List(); this.bufferItems = new List(); + this.displayRows = DisplayRows; + this.displayColumns = DisplayColumns; } /// Add the item to the inventory. @@ -181,7 +192,7 @@ namespace Revitalize.Framework.Utilities /// public InventoryManager Copy() { - return new InventoryManager(this.capacity, this.MaxCapacity); + return new InventoryManager(this.capacity, this.MaxCapacity,this.displayRows,this.displayColumns); } public void dumpBufferToItems()