From b022947542056f3880bb8571f9f8da548e41163c Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Mon, 5 Aug 2019 18:03:52 -0700 Subject: [PATCH] Added in hover display text to the inventory menu. --- .../Framework/Menus/InventoryMenu.cs | 72 +++++++++++++++++-- GeneralMods/Revitalize/ModCore.cs | 2 +- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs b/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs index 0056bb65..cb82c390 100644 --- a/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs +++ b/GeneralMods/Revitalize/Framework/Menus/InventoryMenu.cs @@ -57,11 +57,18 @@ namespace Revitalize.Framework.Menus public AnimatedButton nextPage; public AnimatedButton previousPage; + public Color backgroundColor; - public InventoryMenu(int xPos, int yPos, int width, int height, int Rows, int Collumns, bool showCloseButton, IList Inventory, int maxCapacity) : base(xPos, yPos, width, height, showCloseButton) + public string hoverText; + public string hoverTitle; + public Item displayItem; + + + 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. // + this.backgroundColor = BackgroundColor == null ? Color.White : BackgroundColor; this.items = Inventory; this.pages = new Dictionary(); @@ -76,12 +83,18 @@ namespace Revitalize.Framework.Menus this.searchBox.Width = 256; this.searchBox.Height = 192; 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); } + /// + /// What happens when the game's viewport is changed. + /// + /// + /// public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds) { base.gameWindowSizeChanged(oldBounds, newBounds); @@ -89,10 +102,17 @@ namespace Revitalize.Framework.Menus this.searchBox.X = this.xPositionOnScreen; 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.previousPage.Position= new Vector2(64 + (this.searchBox.X + this.searchBox.Width)); + 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); } + /// + /// Populates the menu with all of the items on display. + /// + /// + /// + /// + /// public void populateClickableItems(int rows, int collums, int xPosition, int yPosition) { this.pages.Clear(); @@ -158,7 +178,28 @@ namespace Revitalize.Framework.Menus public override void performHoverAction(int x, int y) { - + bool hovered = false; + foreach (ItemDisplayButton button in this.pages[this.pageIndex].storageDisplay) + { + if (button.Contains(x, y)) + { + if (button.item == null) + { + continue; + } + else if (button.item != null) + { + this.displayItem = button.item; + this.hoverTitle = this.displayItem.DisplayName; + this.hoverText = this.displayItem.getDescription(); + hovered = true; + } + } + } + if (hovered == false) + { + this.displayItem = null; + } } /// @@ -293,19 +334,33 @@ namespace Revitalize.Framework.Menus return i; } + /// + /// What happens when this menu is right clicked. + /// + /// + /// + /// public override void receiveRightClick(int x, int y, bool playSound = true) { } + /// + /// What happens when the menu is updated. + /// + /// public override void update(GameTime time) { } + /// + /// Draws the menu to the screen. + /// + /// public override void draw(SpriteBatch b) { - this.drawDialogueBoxBackground(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, Color.Blue); + this.drawDialogueBoxBackground(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, this.backgroundColor); foreach (ItemDisplayButton button in this.pages[this.pageIndex].storageDisplay) { @@ -327,9 +382,16 @@ namespace Revitalize.Framework.Menus 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); //base.draw(b); } + /// + /// 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; diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 16bff745..ead6be26 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -196,7 +196,7 @@ namespace Revitalize 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,3,4,false, Game1.player.Items,15); + Game1.activeClickableMenu = new Revitalize.Framework.Menus.InventoryMenu(100, 100, 500, 500,3,4,false, Game1.player.Items,15,Color.SandyBrown); } }