From dd4b4a0ee3c3ece312f26f309862d1ac9673bf87 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Tue, 3 Sep 2019 13:49:21 -0700 Subject: [PATCH] Added left and right buttons to the crafting menu. Also centered item name text. --- .../Menus/CraftingInformationPage.cs | 14 ++- .../Framework/Menus/CraftingMenuV1.cs | 95 +++++++++++++++++-- GeneralMods/Revitalize/ModCore.cs | 4 +- 3 files changed, 103 insertions(+), 10 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Menus/CraftingInformationPage.cs b/GeneralMods/Revitalize/Framework/Menus/CraftingInformationPage.cs index 154cdc2f..1d482ba2 100644 --- a/GeneralMods/Revitalize/Framework/Menus/CraftingInformationPage.cs +++ b/GeneralMods/Revitalize/Framework/Menus/CraftingInformationPage.cs @@ -32,6 +32,8 @@ namespace Revitalize.Framework.Menus public AnimatedButton craftingButton; + public bool isPlayerInventory; + public Item actualItem { get @@ -45,12 +47,13 @@ namespace Revitalize.Framework.Menus } - public CraftingInformationPage(int x, int y, int width, int height,Color BackgroundColor,CraftingRecipeButton ItemToDisplay,ref IList Inventory) : base(x, y, width, height, false) + public CraftingInformationPage(int x, int y, int width, int height,Color BackgroundColor,CraftingRecipeButton ItemToDisplay,ref IList Inventory,bool IsPlayerInventory) : base(x, y, width, height, false) { this.backgroundColor = BackgroundColor; this.infoButton = ItemToDisplay; this.itemDisplayLocation = new Vector2(this.xPositionOnScreen + (this.width / 2) - 32, this.yPositionOnScreen + (128)); this.inventory = Inventory; + this.isPlayerInventory = IsPlayerInventory; this.requiredItems = new Dictionary(); for (int i = 0; i < this.infoButton.recipe.ingredients.Count; i++) @@ -69,6 +72,11 @@ namespace Revitalize.Framework.Menus { Game1.soundBank.PlayCue("coin"); this.infoButton.craftItem(); + + if (this.isPlayerInventory) + { + this.inventory = Game1.player.Items; + } } } } @@ -78,7 +86,7 @@ namespace Revitalize.Framework.Menus this.drawDialogueBoxBackground(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, this.backgroundColor); this.infoButton.draw(b,this.itemDisplayLocation); - b.DrawString(Game1.dialogueFont, this.actualItem.DisplayName, this.itemDisplayLocation + this.getHeightOffsetFromItem()-this.getItemNameOffset(), this.getNameColor()); + b.DrawString(Game1.dialogueFont, this.actualItem.DisplayName,new Vector2(this.xPositionOnScreen+ (this.width/2),this.itemDisplayLocation.Y)+ this.getHeightOffsetFromItem()-this.getItemNameOffset(), this.getNameColor()); b.DrawString(Game1.smallFont, Game1.parseText(this.actualItem.getDescription(), Game1.smallFont, this.width),new Vector2(this.xPositionOnScreen+64,this.getItemDescriptionOffset().Y), Color.Black); @@ -150,7 +158,7 @@ namespace Revitalize.Framework.Menus private Vector2 getItemNameOffset() { Vector2 length = Game1.dialogueFont.MeasureString(this.actualItem.DisplayName); - length.X = length.X / 4; + length.X = length.X / 2; length.Y = 0; return length; } diff --git a/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs b/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs index c217d23a..9c36f563 100644 --- a/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs +++ b/GeneralMods/Revitalize/Framework/Menus/CraftingMenuV1.cs @@ -26,7 +26,6 @@ namespace Revitalize.Framework.Menus public int currentPageIndex; public string currentTab; - public int currentScrollIndex; public Color backgroundColor; @@ -37,17 +36,39 @@ namespace Revitalize.Framework.Menus /// /// How many crafting recipes to display at a time. /// - public int amountOfRecipesToShow = 4; + public int amountOfRecipesToShow = 6; public bool playerInventory; public CraftingInformationPage craftingInfo; + public AnimatedButton leftButton; + public AnimatedButton rightButton; + + + private int maxPages + { + get + { + if (string.IsNullOrEmpty(this.currentTab)) return 0; + return (this.craftingItemsToDisplay[this.currentTab].Count / this.amountOfRecipesToShow) + 1; + } + } + public CraftingMenuV1() : base() { } + /// + /// Constructor to be used when the inventory is the player's + /// + /// + /// + /// + /// + /// + /// public CraftingMenuV1(int X, int Y, int Width, int Height, Color BackgroundColor, IList Inventory) : base(X, Y, Width, Height, false) { this.backgroundColor = BackgroundColor; @@ -57,8 +78,18 @@ namespace Revitalize.Framework.Menus this.fromInventory = Inventory; this.toInventory = Inventory; this.playerInventory = true; + this.initializeButtons(); } + /// + /// Constructor to be used when inventory destination is the same and not the player. + /// + /// + /// + /// + /// + /// + /// public CraftingMenuV1(int X, int Y, int Width, int Height, Color BackgroundColor, ref IList Inventory) : base(X, Y, Width, Height, false) { this.backgroundColor = BackgroundColor; @@ -67,8 +98,19 @@ namespace Revitalize.Framework.Menus this.currentPageIndex = 0; this.fromInventory = Inventory; this.toInventory = Inventory; + this.initializeButtons(); } + /// + /// Inventory constructor to be used when the input and output inventories are different. + /// + /// + /// + /// + /// + /// + /// + /// public CraftingMenuV1(int X, int Y, int Width, int Height, Color BackgroundColor, ref IList FromInventory, ref IList ToInventory) : base(X, Y, Width, Height, false) { this.backgroundColor = BackgroundColor; @@ -77,6 +119,23 @@ namespace Revitalize.Framework.Menus this.currentPageIndex = 0; this.fromInventory = FromInventory; this.toInventory = ToInventory; + this.initializeButtons(); + } + + public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds) + { + base.gameWindowSizeChanged(oldBounds, newBounds); + if (this.craftingInfo != null) + { + this.craftingInfo.gameWindowSizeChanged(oldBounds, newBounds); + + } + } + + private void initializeButtons() + { + this.leftButton = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Left Button", new Vector2(this.xPositionOnScreen, this.yPositionOnScreen), new StardustCore.Animations.AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "PreviousPageButton"), new StardustCore.Animations.Animation(0, 0, 32, 32)), Color.White),new Rectangle(0,0,32,32),2f); + this.rightButton = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Right Button", new Vector2(this.xPositionOnScreen+this.width, this.yPositionOnScreen), new StardustCore.Animations.AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "NextPageButton"), new StardustCore.Animations.Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); } public void addInCraftingPageTab(string name, AnimatedButton Button) @@ -89,7 +148,7 @@ namespace Revitalize.Framework.Menus } else { - Vector2 newPos = new Vector2(100 + (48) * (count + 1), 100 + (24 * 4) * (count + 1)); + Vector2 newPos = new Vector2(100 + (48) * (count + 1), this.yPositionOnScreen + (24 * 4) * (count + 1)); Button.Position = newPos; this.CraftingTabs.Add(name, Button); this.craftingItemsToDisplay.Add(name, new List()); @@ -102,7 +161,7 @@ namespace Revitalize.Framework.Menus if (this.craftingItemsToDisplay.ContainsKey(WhichTab)) { int count = this.craftingItemsToDisplay.Count; - Vector2 newPos = new Vector2(100 + (64) * (count + 1), 100 + (16 * 4) * (count + 1)); + Vector2 newPos = new Vector2(this.xPositionOnScreen + (64) * (count + 1), this.yPositionOnScreen + (16 * 4) * (count + 1)); Button.displayItem.Position = newPos; this.craftingItemsToDisplay[WhichTab].Add(Button); } @@ -155,11 +214,28 @@ namespace Revitalize.Framework.Menus public override void receiveLeftClick(int x, int y, bool playSound = true) { + if (this.leftButton.containsPoint(x, y)) + { + if (this.currentPageIndex <= 0) this.currentPageIndex = 0; + else + { + this.currentPageIndex--; + } + } + if (this.rightButton.containsPoint(x, y)) + { + if (this.currentPageIndex+1 < this.maxPages) + { + this.currentPageIndex++; + } + } + foreach (KeyValuePair pair in this.CraftingTabs) { if (pair.Value.containsPoint(x, y)) { this.currentTab = pair.Key; + this.currentPageIndex = 0; return; } } @@ -174,7 +250,7 @@ namespace Revitalize.Framework.Menus if (button.containsPoint(x, y)) { //button.craftItem(this.fromInventory, this.toInventory); - this.craftingInfo = new CraftingInformationPage(this.xPositionOnScreen + this.width+this.xOffset, this.yPositionOnScreen, 400, this.height, this.backgroundColor, button,ref this.fromInventory); + this.craftingInfo = new CraftingInformationPage(this.xPositionOnScreen + this.width+this.xOffset, this.yPositionOnScreen, 400, this.height, this.backgroundColor, button,ref this.fromInventory,this.playerInventory); Game1.soundBank.PlayCue("coin"); if (this.playerInventory) { @@ -198,6 +274,13 @@ namespace Revitalize.Framework.Menus public override void draw(SpriteBatch b) { this.drawDialogueBoxBackground(this.xPositionOnScreen + this.xOffset, this.yPositionOnScreen, this.width, this.height, this.backgroundColor); + + this.leftButton.draw(b); + //Draw page numbers here. + //b.DrawString(Game1.smallFont,"Page: "+this.currentPageIndex.ToString()/) + b.DrawString(Game1.dialogueFont, ("Page: " + (this.currentPageIndex + 1) + " / " + this.maxPages).ToString(), new Vector2(this.xPositionOnScreen+128, this.yPositionOnScreen), Color.White); + this.rightButton.draw(b); + //this.drawDialogueBoxBackground(); foreach (KeyValuePair pair in this.CraftingTabs) { @@ -250,7 +333,7 @@ namespace Revitalize.Framework.Menus public List getRecipeButtonsToDisplay() { - List buttonsToDraw = this.craftingItemsToDisplay[this.currentTab].GetRange(this.currentScrollIndex, Math.Min(this.craftingItemsToDisplay[this.currentTab].Count, this.amountOfRecipesToShow)); + List buttonsToDraw = this.craftingItemsToDisplay[this.currentTab].GetRange(this.currentPageIndex* this.amountOfRecipesToShow, Math.Min(this.craftingItemsToDisplay[this.currentTab].Count, this.amountOfRecipesToShow)); return buttonsToDraw; } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 025dc24f..6d04ebbd 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -199,6 +199,8 @@ namespace Revitalize -Earings -Pendants + + make chat notification when people are sleeping */ public class ModCore : Mod @@ -326,7 +328,7 @@ namespace Revitalize if (e.Button == SButton.U) { - CraftingMenuV1 menu= new Framework.Menus.CraftingMenuV1(100, 0, 400, 800, Color.White, Game1.player.Items); + CraftingMenuV1 menu= new Framework.Menus.CraftingMenuV1(100, 100, 400, 700, Color.White, Game1.player.Items); menu.addInCraftingPageTab("Default",new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Default Tab", new Vector2(100 + 48, 100 + (24 * 4)), new AnimationManager(TextureManager.GetExtendedTexture(Manifest, "Menus", "MenuTabHorizontal"), new Animation(0, 0, 24, 24)), Color.White), new Rectangle(0, 0, 24, 24), 2f)); menu.addInCraftingRecipe(new Framework.Menus.MenuComponents.CraftingRecipeButton(new Recipe(new Dictionary()