Organization+ modularity with pages for inventory menu.

This commit is contained in:
JoshuaNavarro 2019-07-24 14:16:04 -07:00
parent 9caaae43b8
commit bda8c38c7d
18 changed files with 259 additions and 70 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

View File

@ -11,39 +11,74 @@ using StardewValley.Menus;
using StardustCore.Animations;
using StardustCore.UIUtilities;
using StardustCore.UIUtilities.MenuComponents;
using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons;
namespace Revitalize.Framework.Menus
{
public class InventoryMenuPage
{
int index;
public List<ItemDisplayButton> storageDisplay;
public int amountToDisplay;
public InventoryMenuPage()
{
}
public InventoryMenuPage(int index, List<ItemDisplayButton> Buttons, int AmountToDisplay)
{
this.index = index;
this.storageDisplay = Buttons;
this.amountToDisplay = AmountToDisplay;
}
}
/// <summary>
/// //TODO: Combine two of these to make an item grab menu.
/// </summary>
public class InventoryMenu : IClickableMenuExtended
{
public IList<Item> items;
public List<StardustCore.UIUtilities.MenuComponents.ItemDisplayButton> storageDisplay;
public int amountToDisplay = 9;
public int pages = 1;
public int capacity;
public Item activeItem;
public int rows = 6;
public int collumns = 6;
public int rows;
public int collumns;
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<Item> Inventory, int AmountToDisplay) : base(xPos, yPos, width, height, showCloseButton)
public Dictionary<int, InventoryMenuPage> pages;
public int pageIndex = 0;
public AnimatedButton nextPage;
public AnimatedButton previousPage;
public InventoryMenu(int xPos, int yPos, int width, int height, int Rows, int Collumns, bool showCloseButton, IList<Item> Inventory, int maxCapacity) : base(xPos, yPos, width, height, showCloseButton)
{
//Amount to display is the lower cap per page.
//
this.items = Inventory;
this.storageDisplay = new List<ItemDisplayButton>();
this.amountToDisplay = AmountToDisplay;
this.pages = 1; //Change this to allow for more pages.
this.pages = new Dictionary<int, InventoryMenuPage>();
this.capacity = maxCapacity;
this.rows = Rows;
this.collumns = Collumns;
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;
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);
}
public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds)
@ -53,32 +88,59 @@ 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));
}
public void populateClickableItems(int rows, int collums, int xPosition, int yPosition)
{
this.storageDisplay.Clear();
for (int page = 0; page < this.pages; page++)
this.pages.Clear();
int size = this.capacity;
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<ItemDisplayButton>(), amount));
ModCore.log("Added in a new page with size: " + size);
size -= amount;
for (int y = 0; y < collums; y++)
{
for (int i = 0; i < rows; i++)
for (int x = 0; x < rows; x++)
{
int index = ((y * rows) + i)+(page*rows*collums);
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);
break;
}
if (index > this.items.Count)
{
Vector2 pos2 = new Vector2(i * 64 + xPosition, y * 64 + yPosition);
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);
this.storageDisplay.Add(b2);
this.pages[i].storageDisplay.Add(b2);
continue;
}
ModCore.log("Add in a new display item");
Item item = this.getItemFromList(index);
Vector2 pos = new Vector2(i * 64 + xPosition, y * 64 + yPosition);
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);
this.storageDisplay.Add(b);
this.pages[i].storageDisplay.Add(b);
}
}
}
}
/// <summary>
@ -116,9 +178,9 @@ namespace Revitalize.Framework.Menus
/// <param name="playSound"></param>
public override void receiveLeftClick(int x, int y, bool playSound = true)
{
int index = 0;
int index = 0 + (this.rows * this.collumns * this.pageIndex);
Item swap = null;
foreach (ItemDisplayButton button in this.storageDisplay)
foreach (ItemDisplayButton button in this.pages[this.pageIndex].storageDisplay)
{
if (button.receiveLeftClick(x, y))
{
@ -162,7 +224,7 @@ namespace Revitalize.Framework.Menus
swap = null;
}
Rectangle r = new Rectangle(this.searchBox.X, this.searchBox.Y, this.searchBox.Width, this.searchBox.Height/2);
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();
@ -172,6 +234,25 @@ namespace Revitalize.Framework.Menus
{
this.searchBox.Selected = false;
}
if (this.nextPage.containsPoint(x, y))
{
ModCore.log("Left click next page");
if (this.pageIndex + 1 < this.pages.Count)
{
this.pageIndex++;
Game1.soundBank.PlayCue("shwip");
}
}
if (this.previousPage.containsPoint(x, y))
{
ModCore.log("Left click previous page");
if (this.pageIndex > 0)
{
this.pageIndex--;
Game1.soundBank.PlayCue("shwip");
}
}
}
/// <summary>
@ -225,7 +306,7 @@ namespace Revitalize.Framework.Menus
{
this.drawDialogueBoxBackground(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, Color.Blue);
foreach (ItemDisplayButton button in this.storageDisplay)
foreach (ItemDisplayButton button in this.pages[this.pageIndex].storageDisplay)
{
if (string.IsNullOrEmpty(this.searchBox.Text) == false)
{
@ -239,6 +320,11 @@ namespace Revitalize.Framework.Menus
this.searchBox.Draw(b, true);
this.nextPage.draw(b,0.25f);
this.previousPage.draw(b,0.25f);
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);
//base.draw(b);
}

View File

@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using StardewValley.Menus;
using StardustCore.UIUtilities;
using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons;
namespace Revitalize.Framework.Menus
{
@ -15,7 +16,7 @@ namespace Revitalize.Framework.Menus
{
public List<Item> stroageInventory;
public List<Item> receivingInventory;
public List<StardustCore.UIUtilities.MenuComponents.ItemDisplayButton> storageDisplay;
public List<ItemDisplayButton> storageDisplay;
public StardewValley.Menus.ItemGrabMenu playerInventory;
public int amountToDisplay = 9;
@ -28,7 +29,7 @@ namespace Revitalize.Framework.Menus
{
this.stroageInventory = StorageInventory;
this.receivingInventory = ReceivingInventory;
this.storageDisplay = new List<StardustCore.UIUtilities.MenuComponents.ItemDisplayButton>();
this.storageDisplay = new List<ItemDisplayButton>();
if (this.receivingInventory == null)
{
this.receivingInventory = (List<Item>)Game1.player.Items;

View File

@ -12,6 +12,7 @@ using StardewValley;
using StardustCore.Animations;
using StardustCore.UIUtilities;
using StardustCore.UIUtilities.MenuComponents;
using StardustCore.UIUtilities.MenuComponents.ComponentsV1;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
{

View File

@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics;
using Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies.Spawners;
using StardustCore.UIUtilities;
using StardustCore.UIUtilities.MenuComponents;
using StardustCore.UIUtilities.MenuComponents.ComponentsV1;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
{

View File

@ -5,20 +5,21 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardustCore.UIUtilities.MenuComponents.ComponentsV2;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
{
public class TitleScreen: StardustCore.UIUtilities.IClickableMenuExtended
{
StardustCore.UIUtilities.Texture2DExtended background;
StardustCore.UIUtilities.MenuComponents.BlinkingText menuText;
BlinkingText menuText;
public bool closeMenu;
public TitleScreen(int x, int y, int width, int height):base(x,y,width,height,false)
{
this.background = SeasideScramble.self.textureUtils.getExtendedTexture("SSCMaps", "TitleScreenBackground");
this.menuText = new StardustCore.UIUtilities.MenuComponents.BlinkingText("Sea Side Scramble: Lite Edition" + System.Environment.NewLine + "Click or press A to start.",1000);
this.menuText = new BlinkingText("Sea Side Scramble: Lite Edition" + System.Environment.NewLine + "Click or press A to start.",1000);
}
public TitleScreen(xTile.Dimensions.Rectangle viewport) : this(0, 0, viewport.Width, viewport.Height)

View File

@ -195,7 +195,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, false, Game1.player.Items, 9);
Game1.activeClickableMenu = new Revitalize.Framework.Menus.InventoryMenu(100, 100, 500, 500,3,4,false, Game1.player.Items,15);
}
}

View File

@ -159,6 +159,12 @@
<Content Include="Content\Graphics\Menus\InventoryMenu\ItemBackground.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Menus\InventoryMenu\NextPageButton.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Menus\InventoryMenu\PreviousPageButton.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\Enemies\Target.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@ -8,6 +8,7 @@ using StardewValley;
using StardewValley.Menus;
using StardustCore.UIUtilities;
using StardustCore.UIUtilities.MenuComponents;
using StardustCore.UIUtilities.MenuComponents.ComponentsV1;
namespace StardustCore.Menus
{

View File

@ -92,15 +92,16 @@
<Compile Include="Menus\ModualGameMenu.cs" />
<Compile Include="ModConfig.cs" />
<Compile Include="UIUtilities\IClickableMenuExtended.cs" />
<Compile Include="UIUtilities\MenuComponents\ItemDisplayButton.cs" />
<Compile Include="UIUtilities\MenuComponents\ComponentsV2\Buttons\AnimatedButton.cs" />
<Compile Include="UIUtilities\MenuComponents\ComponentsV2\Buttons\ItemDisplayButton.cs" />
<Compile Include="UIUtilities\LayeredTexture.cs" />
<Compile Include="Animations\AnimatedSprite.cs" />
<Compile Include="UIUtilities\MenuComponents\BlinkingText.cs" />
<Compile Include="UIUtilities\MenuComponents\CycleButton.cs" />
<Compile Include="UIUtilities\MenuComponents\ComponentsV2\BlinkingText.cs" />
<Compile Include="UIUtilities\MenuComponents\ComponentsV1\CycleButton.cs" />
<Compile Include="UIUtilities\MenuComponents\Delegates\Delegates.cs" />
<Compile Include="UIUtilities\MenuComponents\Delegates\DelegatePairing.cs" />
<Compile Include="UIUtilities\MenuComponents\Delegates\Functionality\ButtonFunctionality.cs" />
<Compile Include="UIUtilities\MenuComponents\SliderButton.cs" />
<Compile Include="UIUtilities\MenuComponents\ComponentsV1\SliderButton.cs" />
<Compile Include="UIUtilities\SpriteFonts\CharacterSheets\GenericCharacterSheets.cs" />
<Compile Include="UIUtilities\SpriteFonts\CharacterSheets\VanillaCharacterSheet.cs" />
<Compile Include="UIUtilities\SpriteFonts\Fonts\Components\CharacterSpacing.cs" />
@ -110,7 +111,7 @@
<Compile Include="ModCore.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StaticClass.cs" />
<Compile Include="UIUtilities\MenuComponents\Button.cs" />
<Compile Include="UIUtilities\MenuComponents\ComponentsV1\Button.cs" />
<Compile Include="UIUtilities\SpriteFonts\Fonts\VanillaFont.cs" />
<Compile Include="UIUtilities\SpriteFonts\SpriteFont.cs" />
<Compile Include="UIUtilities\Texture2DExtended.cs" />

View File

@ -4,6 +4,7 @@ using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using StardustCore.UIUtilities.MenuComponents.ComponentsV1;
namespace StardustCore.UIUtilities
{
@ -16,7 +17,7 @@ namespace StardustCore.UIUtilities
/// <summary>
/// All buttons belonging to this menu.
/// </summary>
public List<MenuComponents.Button> buttons;
public List<Button> buttons;
/// <summary>
/// The background color of this menu.
/// </summary>

View File

@ -5,7 +5,7 @@ using StardewValley;
using StardewValley.Menus;
using StardustCore.UIUtilities.MenuComponents.Delegates.Functionality;
namespace StardustCore.UIUtilities.MenuComponents
namespace StardustCore.UIUtilities.MenuComponents.ComponentsV1
{
public enum ExtraTextureDrawOrder
{

View File

@ -6,7 +6,7 @@ using StardewValley;
using StardewValley.Menus;
using StardustCore.UIUtilities.MenuComponents.Delegates.Functionality;
namespace StardustCore.UIUtilities.MenuComponents
namespace StardustCore.UIUtilities.MenuComponents.ComponentsV1
{
public class CycleButton : Button
{

View File

@ -5,7 +5,7 @@ using StardewValley;
using StardewValley.Menus;
using StardustCore.UIUtilities.MenuComponents.Delegates.Functionality;
namespace StardustCore.UIUtilities.MenuComponents
namespace StardustCore.UIUtilities.MenuComponents.ComponentsV1
{
/// <summary>An enum describing the types of slider bars that can exist.</summary>
public enum SliderStyle

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StardustCore.UIUtilities.MenuComponents
namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2
{
public class BlinkingText
{

View File

@ -0,0 +1,90 @@
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;
namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons
{
public class AnimatedButton
{
public Animations.AnimatedSprite sprite;
private Rectangle defaultBounds;
public Rectangle bounds
{
get
{
return new Rectangle((int)this.Position.X, (int)this.Position.Y, (int)(this.defaultBounds.Width * this.scale), (int)(this.defaultBounds.Height * this.scale));
}
}
public float scale;
public string label;
public string name;
public string hoverText;
/// <summary>
/// The position of the bounding box.
/// </summary>
public Vector2 Position
{
get
{
return this.sprite.position;
}
set
{
this.sprite.position = value;
this.defaultBounds.X = (int)this.sprite.position.X;
this.defaultBounds.Y = (int)this.sprite.position.Y;
}
}
public AnimatedButton(Animations.AnimatedSprite Sprite, Rectangle DefaultBounds, float Scale)
{
this.sprite = Sprite;
this.scale = Scale;
this.defaultBounds = DefaultBounds;
this.label = "";
this.name = "";
this.hoverText = "";
}
public void update(GameTime time)
{
}
public void draw(SpriteBatch b)
{
this.sprite.draw(b);
}
public void draw(SpriteBatch b, float Depth)
{
this.sprite.draw(b, this.scale, Depth);
}
public bool containsPoint(int x, int y)
{
return this.bounds.Contains(x, y);
}
public bool receiveLeftClick(int x, int y)
{
return this.containsPoint(x, y);
}
public bool receiveRightClick(int x, int y)
{
return this.containsPoint(x, y);
}
public bool receiveHover(int x, int y)
{
return this.containsPoint(x, y);
}
}
}

View File

@ -7,7 +7,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
namespace StardustCore.UIUtilities.MenuComponents
namespace StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons
{
/// <summary>
/// A simple menu component for displaying SDV Items as well as being able to click them.