From d6fa1672db2c5a2e4b70a17c8d53d80df4843971 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Mon, 5 Aug 2019 21:19:56 -0700 Subject: [PATCH] Finished the work for the first stage of the item transfer menu! --- .../InventoryMenu/ItemBackgroundNoSpacing.png | Bin 0 -> 230 bytes .../InventoryMenu/ItemTransferButton.png | Bin 0 -> 1035 bytes .../Menus/InventoryMenu/TrashButton.png | Bin 0 -> 722 bytes .../Framework/Menus/InventoryMenu.cs | 68 ++- .../Framework/Menus/InventoryTransferMenu.cs | 443 ++++++++++++++++++ .../Framework/Menus/SimpleItemGrabMenu.cs | 69 --- GeneralMods/Revitalize/ModCore.cs | 11 +- GeneralMods/Revitalize/Revitalize.csproj | 11 +- .../StardustCore/Animations/AnimatedSprite.cs | 32 +- .../ComponentsV2/Buttons/AnimatedButton.cs | 73 ++- .../ComponentsV2/Buttons/ItemDisplayButton.cs | 47 +- 11 files changed, 634 insertions(+), 120 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemBackgroundNoSpacing.png create mode 100644 GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemTransferButton.png create mode 100644 GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/TrashButton.png create mode 100644 GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs delete mode 100644 GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs diff --git a/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemBackgroundNoSpacing.png b/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemBackgroundNoSpacing.png new file mode 100644 index 0000000000000000000000000000000000000000..e4ab4358406a94daed72d90c6388aa37ba26d334 GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJwVp1HArY-_uWuA>RuE}@cz;gG zr2|&^a#E59BxM++ml-uXBxeOzs61cd!EW|m??e4tS(hgdj@dE>d7b&(vvu0V8OsiS z-xuta7%8^rJC9P4#q+G1-i?|GTnm+o&e=5N6*icm5s04F^W9 zfCeU!1q>i2zs37YB2L?1h%l|s{mta1c~{`N>29-*6BC0DRreRKvs8G_GpBvWyvxt7 c+W%&#+vIfen*q})pu-tFUHx3vIVCg!04i=-ZU6uP literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemTransferButton.png b/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemTransferButton.png new file mode 100644 index 0000000000000000000000000000000000000000..03d1a5342c97957cbe8ea828ff331a038dd52ff0 GIT binary patch literal 1035 zcmV+m1oZofP)bC9LGNqi&#T3S)`_Hty>os2HXmvRWszWheAP53$=J3LK7GE=4I=_?!`+lu9lE{ z>7Qd33LZRcXlg0}ZDF9WcC#LgMK*e{x>9KNFnKR;{^?99>=y!gZzlPE-tYZ>?>7_C zb-l^|s7`=Fp}_3yEU{ROo@kVZ&zI#5cW-6CsNsjhL-zOgSy))WFbpEPt~cZHxXnEC z2=dd=eD`_5Nv2Z(R7+*owQMdYAsUSa9e{o1KiPi}xf-#3f|w_Uk4Ow3kxZu~jL`DZ z5(^u?VsR{uwIe+YekiNREH(%_$Xovn4P@xTj0#gZ>7s+%A%`mxe`5OS% z=DKBGWOF%QZ*I0DkQoOSTjoO3Epu8hqXfzWVSet;bIX_T3=)srOV%WwNyNP@1u+wxk_ z9H^Gce0;o)W|(qLn5&XoP^{J2*glaL#HzdcZgaBtl-0@(#ai8ESNREp><}QF@tcS=a>scu13f_I^EnCKtKp{uPi^yJZM+-1yGIE_8M3LyQ(jMsAEyf^*84OB~{q2 z>IslcrzXV-w52dn;>yA`*X|pL#FHnqk_^gD7lQ zbyY#NRAz0in?401RQMgy>3h~>-a7k3Sz{{Sk!_r>Ww86W@v002ovPDHLk FV1m2L>H+`& literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/TrashButton.png b/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/TrashButton.png new file mode 100644 index 0000000000000000000000000000000000000000..871af725a9443a2c0c2179df14375f249f2b161b GIT binary patch literal 722 zcmV;@0xkWCP)+1(5F@UC3(e(aB!-9u(6lN-L}zVo?sjc~xw#vG)b&ath>^ym$6Oqr@Mq>Z#nBP~Xa8EUabr(`RH0CyI9j@`gPW5ekE0L@6LYi7 z&%EwBwnG7sk_FgVkW*7rkv25|2xcqF3PLDME0YMJ@bcA*uuTo%?$S;xlM!F1oeDr2 ziUn9&SPZXYc_RXRb$>+0b=pG%kUBp<2jJJw-}jEOZTCU{zyM1NiyT<{0QkNiNhD`3 zZRtOhdRj=#yI<;Djd_JE#K&useqGis^Q$NrD1D3KHhz!(?4gdfE07*qoM6N<$ Eg7(`*%m4rY literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs b/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs index cb82c390..405fef98 100644 --- a/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs +++ b/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs @@ -63,6 +63,16 @@ namespace Revitalize.Framework.Menus public string hoverTitle; public Item displayItem; + /// + /// Checks if the given inventory is full or not. + /// + public bool isFull + { + get + { + 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) { @@ -106,6 +116,11 @@ namespace Revitalize.Framework.Menus this.previousPage.Position= new Vector2(64 + (this.searchBox.X + this.searchBox.Width),this.searchBox.Y); } + public void populateClickableItems() + { + this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); + } + /// /// Populates the menu with all of the items on display. /// @@ -116,17 +131,15 @@ namespace Revitalize.Framework.Menus public void populateClickableItems(int rows, int collums, int xPosition, int yPosition) { this.pages.Clear(); - - int size = this.capacity; - ModCore.log("Hello World! SIZE IS: " + size); + //ModCore.log("Hello World! SIZE IS: " + size); int maxPages = ((size) / (this.rows * this.collumns)) + 1; for (int i = 0; i < maxPages; i++) { int amount = Math.Min(rows * collums, size); this.pages.Add(i, new InventoryMenuPage(i, new List(), amount)); - ModCore.log("Added in a new page with size: " + size); + //ModCore.log("Added in a new page with size: " + size); size -= amount; for (int y = 0; y < collums; y++) { @@ -135,33 +148,28 @@ namespace Revitalize.Framework.Menus int index = ((y * rows) + x) + (rows * collums * i); if (index >= this.pages[i].amountToDisplay + (rows * collums * i)) { - ModCore.log("Break page creation."); - ModCore.log("Index is: " + index); - ModCore.log("Max display is: " + this.pages[i].amountToDisplay); + //ModCore.log("Break page creation."); + //ModCore.log("Index is: " + index); + //ModCore.log("Max display is: " + this.pages[i].amountToDisplay); break; } if (index > this.items.Count) { - ModCore.log("Index greater than items!"); Vector2 pos2 = new Vector2(x * 64 + xPosition, y * 64 + yPosition); - ItemDisplayButton b2 = new ItemDisplayButton(null, new StardustCore.Animations.AnimatedSprite("ItemBackground", pos2, new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemBackground"), new Animation(0, 0, 32, 32)), Color.White), pos2, new Rectangle(0, 0, 32 * 2, 32 * 2), 2f, true, Color.White); + ItemDisplayButton b2 = new ItemDisplayButton(null, new StardustCore.Animations.AnimatedSprite("ItemBackground", pos2, new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemBackground"), new Animation(0, 0, 32, 32)), Color.White), pos2, new Rectangle(0, 0, 32, 32), 2f, true, Color.White); this.pages[i].storageDisplay.Add(b2); continue; } - ModCore.log("Add in a new display item"); Item item = this.getItemFromList(index); Vector2 pos = new Vector2(x * 64 + xPosition, y * 64 + yPosition); - ItemDisplayButton b = new ItemDisplayButton(item, new StardustCore.Animations.AnimatedSprite("ItemBackground", pos, new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemBackground"), new Animation(0, 0, 32, 32)), Color.White), pos, new Rectangle(0, 0, 32 * 2, 32 * 2), 2f, true, Color.White); + ItemDisplayButton b = new ItemDisplayButton(item, new StardustCore.Animations.AnimatedSprite("ItemBackground", pos, new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemBackground"), new Animation(0, 0, 32, 32)), Color.White), pos, new Rectangle(0, 0, 32, 32), 2f, true, Color.White); this.pages[i].storageDisplay.Add(b); } } } - - - } /// @@ -176,6 +184,11 @@ namespace Revitalize.Framework.Menus else return this.items.ElementAt(index); } + /// + /// What happens when this menu is hover overed. + /// + /// + /// public override void performHoverAction(int x, int y) { bool hovered = false; @@ -231,7 +244,7 @@ namespace Revitalize.Framework.Menus this.activeItem = button.item; if (this.activeItem != null) { - ModCore.log("Got item: " + this.activeItem.DisplayName); + //ModCore.log("Got item: " + this.activeItem.DisplayName); } return; } @@ -239,7 +252,7 @@ namespace Revitalize.Framework.Menus { if (button.item == null) { - ModCore.log("Placed item: " + this.activeItem.DisplayName); + //ModCore.log("Placed item: " + this.activeItem.DisplayName); swap = this.activeItem; this.activeItem = null; break; @@ -247,7 +260,7 @@ namespace Revitalize.Framework.Menus else { swap = button.item; - ModCore.log("Swap item: " + swap.DisplayName); + //ModCore.log("Swap item: " + swap.DisplayName); break; } } @@ -279,7 +292,7 @@ namespace Revitalize.Framework.Menus if (this.nextPage.containsPoint(x, y)) { - ModCore.log("Left click next page"); + //ModCore.log("Left click next page"); if (this.pageIndex + 1 < this.pages.Count) { this.pageIndex++; @@ -288,7 +301,7 @@ namespace Revitalize.Framework.Menus } if (this.previousPage.containsPoint(x, y)) { - ModCore.log("Left click previous page"); + //ModCore.log("Left click previous page"); if (this.pageIndex > 0) { this.pageIndex--; @@ -306,7 +319,7 @@ namespace Revitalize.Framework.Menus { if (I == null) { - ModCore.log("Odd item is null"); + //ModCore.log("Odd item is null"); return; } if (insertIndex + 1 > this.items.Count) @@ -376,27 +389,32 @@ namespace Revitalize.Framework.Menus this.searchBox.Draw(b, true); - this.nextPage.draw(b,0.25f); - this.previousPage.draw(b,0.25f); + 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); this.drawMouse(b); - if (this.displayItem != null) IClickableMenu.drawToolTip(b, this.hoverText, this.hoverTitle, this.displayItem, false, -1, 0, -1, -1, (CraftingRecipe)null, -1); + this.drawToolTip(b); //base.draw(b); } + public void drawToolTip(SpriteBatch b) + { + if (this.displayItem != null) IClickableMenu.drawToolTip(b, this.hoverText, this.hoverTitle, this.displayItem, false, -1, 0, -1, -1, (CraftingRecipe)null, -1); + } + /// /// Draws the item as a transparent icon if the item is not part of the seach patern. /// /// /// private float getItemDrawAlpha(Item I) - { - if (I == null) return 1f; + { if (string.IsNullOrEmpty(this.searchBox.Text) == false) { + if (I == null) return 0.25f; return I.DisplayName.ToLowerInvariant().Contains(this.searchBox.Text.ToLowerInvariant()) ? 1f : 0.25f; } else diff --git a/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs b/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs new file mode 100644 index 00000000..8367489f --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Menus/InventoryTransferMenu.cs @@ -0,0 +1,443 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; +using StardewValley.Menus; +using StardustCore.Animations; +using StardustCore.UIUtilities; +using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons; + +namespace Revitalize.Framework.Menus +{ + public class InventoryTransferMenu : IClickableMenuExtended + { + public InventoryMenu playerInventory; + public InventoryMenu otherInventory; + private IList otherItems; + private bool isPlayerInventory; + public AnimatedButton transferButton; + public AnimatedButton trashButton; + public string hoverText; + + public ItemDisplayButton trashedItem; + private bool displayTrashedItem; + + private enum CurrentMode + { + TransferItems, + TrashItem + } + private CurrentMode currentMode; + + public InventoryTransferMenu(int x, int y, int width, int height, IList OtherItems, int OtherCapacity) : 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.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); + this.trashButton = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Trash Button", new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f) + 96), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "TrashButton"), new Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); + this.trashedItem = new ItemDisplayButton(null, new StardustCore.Animations.AnimatedSprite("ItemBackground", new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f) + 180), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemBackground"), new Animation(0, 0, 32, 32)), Color.White), new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f) + 180), new Rectangle(0, 0, 32, 32), 2f, true, Color.White); + } + + + /// + /// Handles what happens when the menu is left clicked. + /// + /// + /// + /// + public override void receiveLeftClick(int x, int y, bool playSound = true) + { + if (this.currentMode == CurrentMode.TransferItems) + { + if (this.otherInventory.isFull == false) + { + this.playerInventory.receiveLeftClick(x, y); + if (this.playerInventory.activeItem != null) + { + this.transferItem(ref this.playerInventory, ref this.otherInventory); + } + } + if (this.playerInventory.isFull == false) + { + this.otherInventory.receiveLeftClick(x, y); + if (this.otherInventory.activeItem != null) + { + this.transferItem(ref this.otherInventory, ref this.playerInventory); + } + } + } + + if (this.currentMode == CurrentMode.TrashItem) + { + this.playerInventory.receiveLeftClick(x, y); + this.otherInventory.receiveLeftClick(x, y); + if (this.playerInventory.activeItem != null) + { + this.trashItem(ref this.playerInventory); + } + if (this.otherInventory.activeItem != null) + { + this.trashItem(ref this.otherInventory); + } + } + + if (this.transferButton.receiveLeftClick(x, y)) + { + this.currentMode = CurrentMode.TransferItems; + Game1.playSound("shwip"); + } + if (this.trashButton.receiveLeftClick(x, y)) + { + this.currentMode = CurrentMode.TrashItem; + Game1.playSound("shwip"); + } + if (this.trashedItem.receiveLeftClick(x, y)) + { + this.recoverTrashedItem(); + this.playerInventory.populateClickableItems(); + this.otherInventory.populateClickableItems(); + } + } + + /// + /// What happens when the menu is right clicked. + /// + /// + /// + /// + public override void receiveRightClick(int x, int y, bool playSound = true) + { + if (this.currentMode == CurrentMode.TransferItems) + { + if (this.otherInventory.isFull == false) + { + this.playerInventory.receiveLeftClick(x, y); + if (this.playerInventory.activeItem != null) + { + this.transferOneItem(ref this.playerInventory, ref this.otherInventory); + } + } + if (this.playerInventory.isFull == false) + { + this.otherInventory.receiveLeftClick(x, y); + if (this.otherInventory.activeItem != null) + { + this.transferOneItem(ref this.otherInventory, ref this.playerInventory); + } + } + } + } + + /// + /// Handles what happens when a menu is hover overed. + /// + /// + /// + public override void performHoverAction(int x, int y) + { + this.playerInventory.performHoverAction(x, y); + this.otherInventory.performHoverAction(x, y); + + if (this.transferButton.containsPoint(x, y)) + { + this.hoverText = "Transfer Items"; + } + else if (this.trashButton.containsPoint(x, y)) + { + this.hoverText = "Trash Items"; + } + else + { + this.hoverText = ""; + } + + if (this.trashedItem.Contains(x, y)) + { + if (this.trashedItem.item != null) + { + this.displayTrashedItem = true; + } + else + { + this.displayTrashedItem = false; + } + } + else + { + this.displayTrashedItem = false; + } + } + + /// + /// Transfers an item between inventories. + /// + /// + /// + private void transferItem(ref InventoryMenu From, ref InventoryMenu To) + { + //Stack size control logic. + foreach (Item I in To.items) + { + if (I == null) continue; + if (From.activeItem.canStackWith(I)) + { + I.addToStack(From.activeItem.Stack); + From.items.Remove(From.activeItem); + From.activeItem = null; + From.populateClickableItems(); + To.populateClickableItems(); + return; + } + else if (I.maximumStackSize() > I.Stack + From.activeItem.Stack && From.activeItem.canStackWith(I)) + { + int sizeLeft = I.getRemainingStackSpace(); + I.Stack = I.maximumStackSize(); + From.activeItem.Stack -= sizeLeft; + + break; + } + } + if (To.isFull == false) + { + To.items.Add(From.activeItem); + From.items.Remove(From.activeItem); + From.activeItem = null; + From.populateClickableItems(); + To.populateClickableItems(); + } + } + + /// + /// Transfers exactly one item across inventories. + /// + /// + /// + private void transferOneItem(ref InventoryMenu From, ref InventoryMenu To) + { + //Stack size control logic. + foreach (Item I in To.items) + { + if (I == null) continue; + if (From.activeItem.canStackWith(I)) + { + I.addToStack(1); + From.activeItem.Stack--; + if (From.activeItem.Stack <= 0) + { + From.items.Remove(From.activeItem); + } + From.activeItem = null; + From.populateClickableItems(); + To.populateClickableItems(); + return; + } + } + if (To.isFull == false) + { + To.items.Add(From.activeItem.getOne()); + From.activeItem.Stack--; + if (From.activeItem.Stack <= 0) + { + From.items.Remove(From.activeItem); + } + From.activeItem = null; + From.populateClickableItems(); + To.populateClickableItems(); + } + } + + + /// + /// Puts an item into the trash. + /// + /// + private void trashItem(ref InventoryMenu From) + { + if (From.activeItem != null) + { + this.trashedItem.item = From.activeItem; + From.items.Remove(From.activeItem); + From.activeItem = null; + From.populateClickableItems(); + } + } + + /// + /// Trashes a single item from the given inventory. + /// + /// + private void transhOneItem(ref InventoryMenu From) + { + if (From.activeItem != null) + { + if (this.trashedItem.item == null) + { + this.trashedItem.item = From.activeItem.getOne(); + From.activeItem.Stack--; + if (From.activeItem.Stack == 0) + { + From.items.Remove(From.activeItem); + } + From.activeItem = null; + From.populateClickableItems(); + } + else if (this.trashedItem.item != null) + { + if (From.activeItem.canStackWith(this.trashedItem.item)) + { + this.trashedItem.item.Stack += 1; + From.activeItem.Stack--; + if (From.activeItem.Stack == 0) + { + From.items.Remove(From.activeItem); + } + From.activeItem = null; + From.populateClickableItems(); + return; + } + else + { + this.trashedItem.item = From.activeItem.getOne(); + From.activeItem.Stack--; + if (From.activeItem.Stack == 0) + { + From.items.Remove(From.activeItem); + } + From.activeItem = null; + From.populateClickableItems(); + return; + } + } + } + } + + /// + /// Tries to recover the previously trashed item. + /// + private void recoverTrashedItem() + { + if (this.trashedItem.item != null) + { + if (this.playerInventory.isFull == false) + { + foreach (Item I in this.playerInventory.items) + { + if (I == null) continue; + if (this.trashedItem.item.canStackWith(I)) + { + I.addToStack(this.trashedItem.item.Stack); + this.trashedItem.item = null; + return; + } + else if (I.maximumStackSize() > I.Stack + this.trashedItem.item.Stack && this.trashedItem.item.canStackWith(I)) + { + int sizeLeft = I.getRemainingStackSpace(); + I.Stack = I.maximumStackSize(); + this.trashedItem.item.Stack -= sizeLeft; + break; + } + } + if (this.playerInventory.isFull == false) + { + this.playerInventory.items.Add(this.trashedItem.item); + this.trashedItem.item = null; + return; + } + else if (this.otherInventory.isFull == false) + { + foreach (Item I in this.otherInventory.items) + { + if (I == null) continue; + if (this.trashedItem.item.canStackWith(I)) + { + I.addToStack(this.trashedItem.item.Stack); + this.trashedItem.item = null; + return; + } + else if (I.maximumStackSize() > I.Stack + this.trashedItem.item.Stack && this.trashedItem.item.canStackWith(I)) + { + int sizeLeft = I.getRemainingStackSpace(); + I.Stack = I.maximumStackSize(); + this.trashedItem.item.Stack -= sizeLeft; + + break; + } + } + if (this.otherInventory.isFull == false) + { + this.otherInventory.items.Add(this.trashedItem.item); + this.trashedItem.item = null; + return; + } + } + } + else if (this.otherInventory.isFull == false) + { + foreach (Item I in this.otherInventory.items) + { + if (I == null) continue; + if (this.trashedItem.item.canStackWith(I)) + { + I.addToStack(this.trashedItem.item.Stack); + this.trashedItem.item = null; + return; + } + else if (I.maximumStackSize() > I.Stack + this.trashedItem.item.Stack && this.trashedItem.item.canStackWith(I)) + { + int sizeLeft = I.getRemainingStackSpace(); + I.Stack = I.maximumStackSize(); + this.trashedItem.item.Stack -= sizeLeft; + + break; + } + } + if (this.otherInventory.isFull == false) + { + this.otherInventory.items.Add(this.trashedItem.item); + this.trashedItem.item = null; + return; + } + + } + } + } + + /// + /// Draws + /// + /// + public override void draw(SpriteBatch b) + { + this.playerInventory.draw(b); + this.otherInventory.draw(b); + + this.transferButton.draw(b, 1f, this.currentMode== CurrentMode.TransferItems? 1f:.4f); + this.trashButton.draw(b, 1f, this.currentMode == CurrentMode.TrashItem ? 1f : .4f); + this.trashedItem.draw(b,0.25f, (this.currentMode == CurrentMode.TrashItem || this.trashedItem.item!=null) ? 1f:.4f, false); + if (this.hoverText != null) + { + IClickableMenuExtended.drawHoverText(b, this.hoverText, Game1.dialogueFont); + } + //To prevent awkward overlap from the other menu. + if (this.playerInventory.hoverText != null) + { + this.playerInventory.drawToolTip(b); + } + + this.drawToolTip(b); + this.drawMouse(b); + } + + public void drawToolTip(SpriteBatch b) + { + if (this.displayTrashedItem && this.trashedItem.item!=null) IClickableMenu.drawToolTip(b, this.trashedItem.item.getDescription(), this.trashedItem.item.DisplayName, this.trashedItem.item, false, -1, 0, -1, -1, (CraftingRecipe)null, -1); + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs b/GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs deleted file mode 100644 index 79a468f8..00000000 --- a/GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using StardewValley; -using StardewValley.Menus; -using StardustCore.UIUtilities; -using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons; - -namespace Revitalize.Framework.Menus -{ - public class SimpleItemGrabMenu: StardustCore.UIUtilities.IClickableMenuExtended - { - public List stroageInventory; - public List receivingInventory; - public List storageDisplay; - public StardewValley.Menus.ItemGrabMenu playerInventory; - - public int amountToDisplay = 9; - public SimpleItemGrabMenu(int xPos,int yPos,int width, int height,bool showCloseButton,List StorageInventory,ListReceivingInventory) : this(xPos, yPos, width, height, showCloseButton,StorageInventory,ReceivingInventory,9) - { - - } - - public SimpleItemGrabMenu(int xPos, int yPos, int width, int height, bool showCloseButton, List StorageInventory, List ReceivingInventory,int AmountToDisplay) : base(xPos, yPos, width, height, showCloseButton) - { - this.stroageInventory = StorageInventory; - this.receivingInventory = ReceivingInventory; - this.storageDisplay = new List(); - if (this.receivingInventory == null) - { - this.receivingInventory = (List)Game1.player.Items; - } - this.amountToDisplay = AmountToDisplay; - - this.playerInventory = new ItemGrabMenu(this.receivingInventory); - } - - public override void performHoverAction(int x, int y) - { - - } - - public override void receiveLeftClick(int x, int y, bool playSound = true) - { - this.playerInventory.receiveLeftClick(x, y, playSound); - } - - public override void receiveRightClick(int x, int y, bool playSound = true) - { - - } - - public override void update(GameTime time) - { - - } - - public override void draw(SpriteBatch b) - { - this.drawDialogueBoxBackground(); - this.drawMouse(b); - //base.draw(b); - } - } -} diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index ead6be26..27cdb10c 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -189,14 +189,21 @@ namespace Revitalize private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e) { + /* if(e.Button== SButton.U) { Game1.currentMinigame = new Revitalize.Framework.Minigame.SeasideScrambleMinigame.SeasideScramble(); } - else if(e.Button== SButton.Y) + */ + if(e.Button== SButton.Y) { //Game1.activeClickableMenu = new ItemGrabMenu(Game1.player.Items,false,true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems),); - Game1.activeClickableMenu = new Revitalize.Framework.Menus.InventoryMenu(100, 100, 500, 500,3,4,false, Game1.player.Items,15,Color.SandyBrown); + List newItems = new List() + { + new StardewValley.Object(184,10) + }; + + Game1.activeClickableMenu = new Revitalize.Framework.Menus.InventoryTransferMenu(100, 100, 500, 500,newItems,36); } } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 94376b17..85395509 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -66,7 +66,7 @@ - + @@ -172,12 +172,21 @@ Always + + PreserveNewest + + + PreserveNewest + Always Always + + PreserveNewest + Always diff --git a/GeneralMods/StardustCore/Animations/AnimatedSprite.cs b/GeneralMods/StardustCore/Animations/AnimatedSprite.cs index 952e9009..b8406802 100644 --- a/GeneralMods/StardustCore/Animations/AnimatedSprite.cs +++ b/GeneralMods/StardustCore/Animations/AnimatedSprite.cs @@ -67,9 +67,9 @@ namespace StardustCore.Animations /// Draws the sprite to the screen. /// /// - public virtual void draw(SpriteBatch b) + public virtual void draw(SpriteBatch b,float Alpha=1f) { - this.draw(b, 1f, 0f); + this.draw(b, 1f, 0f,Alpha); } /// @@ -78,9 +78,10 @@ namespace StardustCore.Animations /// /// /// - public virtual void draw(SpriteBatch b, float scale, float depth) + /// + public virtual void draw(SpriteBatch b, float scale, float depth,float alpha=1f) { - this.animation.draw(b, this.position, this.color, scale, SpriteEffects.None, depth); + this.animation.draw(b, this.position, new Color(this.color.R, this.color.G, this.color.B, alpha), scale, SpriteEffects.None, depth); } /// @@ -90,14 +91,24 @@ namespace StardustCore.Animations /// /// /// - public virtual void draw(SpriteBatch b,Vector2 position ,float scale, float depth) + /// /// + public virtual void draw(SpriteBatch b,Vector2 position ,float scale, float depth,float alpha=1f) { - this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth); + this.animation.draw(b, position, new Color(this.color.R, this.color.G, this.color.B, alpha), scale, SpriteEffects.None, depth); } - public virtual void draw(SpriteBatch b, Vector2 position, float scale,float rotation ,float depth) + /// + /// Draws the sprite to the screen. + /// + /// The spritebatch which to draw the sprite. + /// The position on screen. + /// The scale of the sprite. + /// The rotation of the sprite. + /// The depth of the sprite. + /// The alpha for the sprite. + public virtual void draw(SpriteBatch b, Vector2 position, float scale,float rotation ,float depth,float alpha=1f) { - this.animation.draw(b, position, this.color, scale, rotation,SpriteEffects.None, depth); + this.animation.draw(b, position, new Color(this.color.R,this.color.G,this.color.B,alpha), scale, rotation,SpriteEffects.None, depth); } /// @@ -107,9 +118,10 @@ namespace StardustCore.Animations /// /// /// - public virtual void draw(SpriteBatch b, Vector2 position, Vector2 scale, float depth) + /// + public virtual void draw(SpriteBatch b, Vector2 position, Vector2 scale, float depth,float alpha=1f) { - this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth); + this.animation.draw(b, position, new Color(this.color.R, this.color.G, this.color.B, alpha), scale, SpriteEffects.None, depth); } diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/AnimatedButton.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/AnimatedButton.cs index 92549f8a..70fe129a 100644 --- a/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/AnimatedButton.cs +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/AnimatedButton.cs @@ -10,9 +10,17 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons { public class AnimatedButton { + /// + /// The sprite that handles all of the visuals for the button. + /// public Animations.AnimatedSprite sprite; - + /// + /// The default bounds for the button. + /// private Rectangle defaultBounds; + /// + /// The actual bounds for the button which takes scale into acount. + /// public Rectangle bounds { get @@ -20,10 +28,22 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons return new Rectangle((int)this.Position.X, (int)this.Position.Y, (int)(this.defaultBounds.Width * this.scale), (int)(this.defaultBounds.Height * this.scale)); } } + /// + /// The scale for the button. + /// public float scale; + /// + /// The label for the button. + /// public string label; + /// + /// The name of the button. + /// public string name; + /// + /// The hovertext for the button. + /// public string hoverText; /// @@ -43,6 +63,12 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons } } + /// + /// Constructor. + /// + /// The sprite for the button. + /// The default hitbox for the button. + /// The scale for the button's sprite and it's hitbox public AnimatedButton(Animations.AnimatedSprite Sprite, Rectangle DefaultBounds, float Scale) { @@ -54,34 +80,71 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons this.hoverText = ""; } + /// + /// Update the button's logic. + /// + /// public void update(GameTime time) { } - public void draw(SpriteBatch b) + /// + /// Draw the button to the screen. + /// + /// + public void draw(SpriteBatch b,float Alpha=1f) { - this.sprite.draw(b); + this.sprite.draw(b,Alpha); } - public void draw(SpriteBatch b, float Depth) + /// + /// Draw the button to the screen. + /// + /// + /// + public void draw(SpriteBatch b, float Depth,float Alpha=1f) { - this.sprite.draw(b, this.scale, Depth); + this.sprite.draw(b, this.scale, Depth,Alpha); } + /// + /// Checks to see if the bounding box for this button contains the given x,y cordinates. + /// + /// + /// + /// public bool containsPoint(int x, int y) { return this.bounds.Contains(x, y); } + /// + /// Checks to see if this button has been left clicked. + /// + /// + /// + /// public bool receiveLeftClick(int x, int y) { return this.containsPoint(x, y); } + /// + /// Checks to see if this button has been right clicked. + /// + /// + /// + /// public bool receiveRightClick(int x, int y) { return this.containsPoint(x, y); } + /// + /// Checks to see if this button has been hover overed. + /// + /// + /// + /// public bool receiveHover(int x, int y) { return this.containsPoint(x, y); diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/ItemDisplayButton.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/ItemDisplayButton.cs index 5fb3fb3e..87d38efd 100644 --- a/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/ItemDisplayButton.cs +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/ComponentsV2/Buttons/ItemDisplayButton.cs @@ -15,12 +15,42 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons public class ItemDisplayButton { + /// + /// The position for the button. + /// private Vector2 position; + /// + /// The item owned by the button. + /// public StardewValley.Item item; - public Rectangle boundingBox; + + private Rectangle defaultBounds; + + /// + /// The hit box for detecting interaction. + /// + public Rectangle boundingBox + { + get + { + return new Rectangle((int)this.Position.X, (int)this.Position.Y, (int)(this.defaultBounds.Width * this.scale), (int)(this.defaultBounds.Height * this.scale)); + } + } + /// + /// The scale of the button. + /// public float scale; + /// + /// Should the stack number be drawn? + /// public bool drawStackNumber; + /// + /// The color for the item. + /// public Color drawColor; + /// + /// The background sprite for the item. + /// public StardustCore.Animations.AnimatedSprite background; /// @@ -35,8 +65,8 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons set { this.position = value; - this.boundingBox.X =(int)this.position.X; - this.boundingBox.Y =(int)this.position.Y; + this.defaultBounds.X =(int)this.position.X; + this.defaultBounds.Y =(int)this.position.Y; } } @@ -57,7 +87,7 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons public ItemDisplayButton(Item I,StardustCore.Animations.AnimatedSprite Background,Vector2 Position, Rectangle BoundingBox, float Scale, bool DrawStackNumber, Color DrawColor) { this.item = I; - this.boundingBox = BoundingBox; + this.defaultBounds = BoundingBox; this.Position = Position; this.scale = Scale; this.drawStackNumber = DrawStackNumber; @@ -74,10 +104,11 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons /// A simple draw function. /// /// - public void draw(SpriteBatch b) + public void draw(SpriteBatch b,float Alpha=1f) { - this.background.draw(b); - if(this.item!=null)this.item.drawInMenu(b, this.position, this.scale); + //this.background.draw(b); + //if(this.item!=null)this.item.drawInMenu(b, this.position, this.scale); + this.draw(b, 1f, Alpha, false); } /// @@ -89,7 +120,7 @@ namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons /// public void draw(SpriteBatch b,float Depth, float Alpha,bool DrawShadow) { - this.background.draw(b, this.scale, Depth); + this.background.draw(b, this.scale, Depth,Alpha); if(this.item!=null)this.item.drawInMenu(b, this.position, 1f,Alpha,Depth,this.drawStackNumber,this.drawColor,DrawShadow); }