From 9caaae43b88f95d992516e6a5d0633d964042436 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Wed, 24 Jul 2019 08:44:55 -0700 Subject: [PATCH] Added in a simple item display menu with a search field. --- .../Menus/InventoryMenu/ItemBackground.png | Bin 0 -> 357 bytes .../Framework/Menus/InventoryMenu.cs | 259 ++++++++++++++++++ .../Framework/Menus/SimpleItemGrabMenu.cs | 25 +- .../SSCMaps/ShootingGallery.cs | 8 + GeneralMods/Revitalize/ModCore.cs | 11 + GeneralMods/Revitalize/Revitalize.csproj | 4 + GeneralMods/StardustCore/StardustCore.csproj | 1 + .../MenuComponents/ItemDisplayButton.cs | 111 ++++++++ 8 files changed, 415 insertions(+), 4 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemBackground.png create mode 100644 GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs create mode 100644 GeneralMods/StardustCore/UIUtilities/MenuComponents/ItemDisplayButton.cs diff --git a/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemBackground.png b/GeneralMods/Revitalize/Content/Graphics/Menus/InventoryMenu/ItemBackground.png new file mode 100644 index 0000000000000000000000000000000000000000..10551924c7345d6b057c3fbd9f23dbc61a699283 GIT binary patch literal 357 zcmV-r0h<1aP)(8_&hm5Z;;Ig$k-w56;e}Wv=?VK18RvO4vJ#% z;y3!w_kQ2!bfSt$OMMw#u!K`7Xe%# zLKD3SUE-Xhs;b52Qp(9XL4ermtxXGHj7bX+QU=HX86X2>fPVv^l%@rkod=XsD9bX6 z`Ba@C0HqX4sVL@Cb-YaYdcOmC-np@Ho!fSnaVXfnHH{b1y-c|88oZcC06*XCVY8V9 zFs4f?nvCV^!-*WX+A+o!8xEzl2JrbosR!%He@0m!j6rSTLgg8E00000NkvXXu0mjf Da-5hT literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs b/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs new file mode 100644 index 00000000..0fa86ace --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs @@ -0,0 +1,259 @@ +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 Microsoft.Xna.Framework.Input; +using StardewValley; +using StardewValley.Menus; +using StardustCore.Animations; +using StardustCore.UIUtilities; +using StardustCore.UIUtilities.MenuComponents; + +namespace Revitalize.Framework.Menus +{ + public class InventoryMenu : IClickableMenuExtended + { + public IList items; + public List storageDisplay; + + public int amountToDisplay = 9; + public int pages = 1; + + public Item activeItem; + + public int rows = 6; + public int collumns = 6; + public int xOffset = 64; + public int yOffset = 128; + + public StardewValley.Menus.TextBox searchBox; + + public InventoryMenu(int xPos, int yPos, int width, int height, bool showCloseButton, IList Inventory, int AmountToDisplay) : base(xPos, yPos, width, height, showCloseButton) + { + this.items = Inventory; + this.storageDisplay = new List(); + this.amountToDisplay = AmountToDisplay; + this.pages = 1; //Change this to allow for more pages. + this.populateClickableItems(this.rows, this.collumns, xPos + this.xOffset, yPos + this.yOffset); + this.searchBox = new TextBox((Texture2D)null, (Texture2D)null, Game1.dialogueFont, Game1.textColor); + this.searchBox.X = this.xPositionOnScreen; + this.searchBox.Y = this.yPositionOnScreen; + this.searchBox.Width = 256; + this.searchBox.Height = 192; + Game1.keyboardDispatcher.Subscriber = (IKeyboardSubscriber)this.searchBox; + } + + public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds) + { + base.gameWindowSizeChanged(oldBounds, newBounds); + + this.searchBox.X = this.xPositionOnScreen; + this.searchBox.Y = this.yPositionOnScreen; + this.populateClickableItems(this.rows, this.collumns, this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen + this.yOffset); + } + + public void populateClickableItems(int rows, int collums, int xPosition, int yPosition) + { + this.storageDisplay.Clear(); + for (int page = 0; page < this.pages; page++) + { + for (int y = 0; y < collums; y++) + { + for (int i = 0; i < rows; i++) + { + int index = ((y * rows) + i)+(page*rows*collums); + if (index > this.items.Count) + { + Vector2 pos2 = new Vector2(i * 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); + this.storageDisplay.Add(b2); + continue; + } + Item item = this.getItemFromList(index); + Vector2 pos = new Vector2(i * 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); + this.storageDisplay.Add(b); + } + } + } + } + + /// + /// Gets an item from the list of items. + /// + /// + /// + private Item getItemFromList(int index) + { + if (this.items == null) return null; + if (index >= this.items.Count) return null; + else return this.items.ElementAt(index); + } + + public override void performHoverAction(int x, int y) + { + + } + + /// + /// What happens when a key is pressed. + /// + /// + public override void receiveKeyPress(Keys key) + { + base.receiveKeyPress(key); + } + + + /// + /// What happens when the menu is left clicked. + /// + /// + /// + /// + public override void receiveLeftClick(int x, int y, bool playSound = true) + { + int index = 0; + Item swap = null; + foreach (ItemDisplayButton button in this.storageDisplay) + { + if (button.receiveLeftClick(x, y)) + { + if (this.activeItem == null) + { + this.activeItem = button.item; + if (this.activeItem != null) + { + ModCore.log("Got item: " + this.activeItem.DisplayName); + } + return; + } + else if (this.activeItem != null) + { + if (button.item == null) + { + ModCore.log("Placed item: " + this.activeItem.DisplayName); + swap = this.activeItem; + this.activeItem = null; + break; + } + else + { + swap = button.item; + ModCore.log("Swap item: " + swap.DisplayName); + break; + } + } + } + index++; + } + if (swap != null && this.activeItem == null) + { + this.swapItemPosition(index, swap); + swap = null; + } + else if (swap != null && this.activeItem != null) + { + this.swapItemPosition(index, this.activeItem); + this.activeItem = null; + swap = null; + } + + Rectangle r = new Rectangle(this.searchBox.X, this.searchBox.Y, this.searchBox.Width, this.searchBox.Height/2); + if (r.Contains(x, y)) + { + this.searchBox.Update(); + this.searchBox.SelectMe(); + } + else + { + this.searchBox.Selected = false; + } + } + + /// + /// 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) + { + 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; + } + + 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.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, Color.Blue); + + foreach (ItemDisplayButton button in this.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); + } + } + + this.searchBox.Draw(b, true); + + this.drawMouse(b); + //base.draw(b); + } + + private float getItemDrawAlpha(Item I) + { + if (I == null) return 1f; + if (string.IsNullOrEmpty(this.searchBox.Text) == false) + { + return I.DisplayName.ToLowerInvariant().Contains(this.searchBox.Text.ToLowerInvariant()) ? 1f : 0.25f; + } + else + { + return 1f; + } + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs b/GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs index eab161b4..cd3dca52 100644 --- a/GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs +++ b/GeneralMods/Revitalize/Framework/Menus/SimpleItemGrabMenu.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewValley; +using StardewValley.Menus; +using StardustCore.UIUtilities; namespace Revitalize.Framework.Menus { @@ -13,12 +15,27 @@ namespace Revitalize.Framework.Menus { public List stroageInventory; public List receivingInventory; - public List clickableItems; - public SimpleItemGrabMenu(int xPos,int yPos,int width, int height,bool showCloseButton,List StorageInventory,ListReceivingInventory) : base(xPos, yPos, width, height, showCloseButton) + 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.clickableItems = new List(); + 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) @@ -28,7 +45,7 @@ namespace Revitalize.Framework.Menus 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) diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMaps/ShootingGallery.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMaps/ShootingGallery.cs index c89d110d..592f5cd4 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMaps/ShootingGallery.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMaps/ShootingGallery.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using StardustCore.UIUtilities.SpriteFonts.Components; using xTile; namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMaps @@ -16,6 +17,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMaps public static int highScore; + public TexturedString timeRemaining; + public ShootingGallery():base() { @@ -51,5 +54,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMaps { this.score[player] += amount; } + + public void startTimer(int amount) + { + + } } } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 78687be1..5e4851da 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -18,6 +18,7 @@ using StardewValley; using StardewValley.Objects; using StardustCore.UIUtilities; using StardustCore.Animations; +using StardewValley.Menus; namespace Revitalize { @@ -161,6 +162,8 @@ namespace Revitalize TextureManager.AddTextureManager(Manifest,"Furniture"); TextureManager.GetTextureManager(Manifest,"Furniture").searchForTextures(ModHelper,this.ModManifest,Path.Combine("Content", "Graphics", "Furniture")); + TextureManager.AddTextureManager(Manifest, "InventoryMenu"); + TextureManager.GetTextureManager(Manifest, "InventoryMenu").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Menus","InventoryMenu")); //TextureManager.addTexture("Furniture","Oak Chair", new Texture2DExtended(this.Helper, this.ModManifest, Path.Combine("Content","Graphics","Furniture", "Chairs", "Oak Chair.png"))); @@ -189,6 +192,11 @@ namespace Revitalize { Game1.currentMinigame = new Revitalize.Framework.Minigame.SeasideScrambleMinigame.SeasideScramble(); } + else 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, false, Game1.player.Items, 9); + } } private void GameLoop_ReturnedToTitle(object sender, StardewModdingAPI.Events.ReturnedToTitleEventArgs e) @@ -247,6 +255,9 @@ namespace Revitalize Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content", "Graphics", "Furniture", "Tables")); } + /// + /// Initialize all modular components for this mod. + /// private void initailizeComponents() { DarkerNight.InitializeConfig(); diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 9e129fa6..c00025f1 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -64,6 +64,7 @@ + @@ -155,6 +156,9 @@ PreserveNewest + + Always + Always diff --git a/GeneralMods/StardustCore/StardustCore.csproj b/GeneralMods/StardustCore/StardustCore.csproj index 2ed4ed41..b51ceac1 100644 --- a/GeneralMods/StardustCore/StardustCore.csproj +++ b/GeneralMods/StardustCore/StardustCore.csproj @@ -92,6 +92,7 @@ + diff --git a/GeneralMods/StardustCore/UIUtilities/MenuComponents/ItemDisplayButton.cs b/GeneralMods/StardustCore/UIUtilities/MenuComponents/ItemDisplayButton.cs new file mode 100644 index 00000000..f2f3360e --- /dev/null +++ b/GeneralMods/StardustCore/UIUtilities/MenuComponents/ItemDisplayButton.cs @@ -0,0 +1,111 @@ +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; + +namespace StardustCore.UIUtilities.MenuComponents +{ + /// + /// A simple menu component for displaying SDV Items as well as being able to click them. + /// + public class ItemDisplayButton + { + + private Vector2 position; + public StardewValley.Item item; + public Rectangle boundingBox; + public float scale; + public bool drawStackNumber; + public Color drawColor; + public StardustCore.Animations.AnimatedSprite background; + + /// + /// The position of the button on screen. + /// + public Vector2 Position + { + get + { + return this.position; + } + set + { + this.position = value; + this.boundingBox.X =(int)this.position.X; + this.boundingBox.Y =(int)this.position.Y; + } + } + + public ItemDisplayButton() + { + + } + + /// + /// Constructor. + /// + /// The itme to display. + /// The position of the item. + /// The bounding box for the item. + /// + /// + /// + 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.Position = Position; + this.scale = Scale; + this.drawStackNumber = DrawStackNumber; + this.drawColor = DrawColor; + this.background = Background; + } + + public void update(GameTime time) + { + + } + + /// + /// A simple draw function. + /// + /// + public void draw(SpriteBatch b) + { + this.background.draw(b); + if(this.item!=null)this.item.drawInMenu(b, this.position, this.scale); + } + + /// + /// The full draw function for drawing this component to the screen. + /// + /// + /// + /// + /// + public void draw(SpriteBatch b,float Depth, float Alpha,bool DrawShadow) + { + this.background.draw(b, this.scale, Depth); + if(this.item!=null)this.item.drawInMenu(b, this.position, 1f,Alpha,Depth,this.drawStackNumber,this.drawColor,DrawShadow); + } + + public bool receiveLeftClick(int x, int y) + { + return this.boundingBox.Contains(new Point(x, y)); + } + + public bool receiveRightClick(int x, int y) + { + return this.boundingBox.Contains(new Point(x, y)); + } + + public bool Contains(int x, int y) + { + return this.boundingBox.Contains(new Point(x, y)); + } + } +}