Added in a simple item display menu with a search field.

This commit is contained in:
JoshuaNavarro 2019-07-24 08:44:55 -07:00
parent 87f0ddcb2c
commit 9caaae43b8
8 changed files with 415 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

View File

@ -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<Item> items;
public List<StardustCore.UIUtilities.MenuComponents.ItemDisplayButton> 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<Item> Inventory, int AmountToDisplay) : base(xPos, yPos, width, height, showCloseButton)
{
this.items = Inventory;
this.storageDisplay = new List<ItemDisplayButton>();
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);
}
}
}
}
/// <summary>
/// Gets an item from the list of items.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
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)
{
}
/// <summary>
/// What happens when a key is pressed.
/// </summary>
/// <param name="key"></param>
public override void receiveKeyPress(Keys key)
{
base.receiveKeyPress(key);
}
/// <summary>
/// What happens when the menu is left clicked.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="playSound"></param>
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;
}
}
/// <summary>
/// Swaps the item's position in the menu.
/// </summary>
/// <param name="insertIndex"></param>
/// <param name="I"></param>
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);
}
/// <summary>
/// Takes the active item from this menu.
/// </summary>
/// <returns></returns>
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;
}
}
}
}

View File

@ -6,6 +6,8 @@ using System.Threading.Tasks;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using StardewValley; using StardewValley;
using StardewValley.Menus;
using StardustCore.UIUtilities;
namespace Revitalize.Framework.Menus namespace Revitalize.Framework.Menus
{ {
@ -13,12 +15,27 @@ namespace Revitalize.Framework.Menus
{ {
public List<Item> stroageInventory; public List<Item> stroageInventory;
public List<Item> receivingInventory; public List<Item> receivingInventory;
public List<StardustCore.UIUtilities.MenuComponents.Button> clickableItems; public List<StardustCore.UIUtilities.MenuComponents.ItemDisplayButton> storageDisplay;
public SimpleItemGrabMenu(int xPos,int yPos,int width, int height,bool showCloseButton,List<Item> StorageInventory,List<Item>ReceivingInventory) : base(xPos, yPos, width, height, showCloseButton) public StardewValley.Menus.ItemGrabMenu playerInventory;
public int amountToDisplay = 9;
public SimpleItemGrabMenu(int xPos,int yPos,int width, int height,bool showCloseButton,List<Item> StorageInventory,List<Item>ReceivingInventory) : this(xPos, yPos, width, height, showCloseButton,StorageInventory,ReceivingInventory,9)
{
}
public SimpleItemGrabMenu(int xPos, int yPos, int width, int height, bool showCloseButton, List<Item> StorageInventory, List<Item> ReceivingInventory,int AmountToDisplay) : base(xPos, yPos, width, height, showCloseButton)
{ {
this.stroageInventory = StorageInventory; this.stroageInventory = StorageInventory;
this.receivingInventory = ReceivingInventory; this.receivingInventory = ReceivingInventory;
this.clickableItems = new List<StardustCore.UIUtilities.MenuComponents.Button>(); this.storageDisplay = new List<StardustCore.UIUtilities.MenuComponents.ItemDisplayButton>();
if (this.receivingInventory == null)
{
this.receivingInventory = (List<Item>)Game1.player.Items;
}
this.amountToDisplay = AmountToDisplay;
this.playerInventory = new ItemGrabMenu(this.receivingInventory);
} }
public override void performHoverAction(int x, int y) 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) 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 receiveRightClick(int x, int y, bool playSound = true)

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using StardustCore.UIUtilities.SpriteFonts.Components;
using xTile; using xTile;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMaps namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMaps
@ -16,6 +17,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMaps
public static int highScore; public static int highScore;
public TexturedString timeRemaining;
public ShootingGallery():base() public ShootingGallery():base()
{ {
@ -51,5 +54,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMaps
{ {
this.score[player] += amount; this.score[player] += amount;
} }
public void startTimer(int amount)
{
}
} }
} }

View File

@ -18,6 +18,7 @@ using StardewValley;
using StardewValley.Objects; using StardewValley.Objects;
using StardustCore.UIUtilities; using StardustCore.UIUtilities;
using StardustCore.Animations; using StardustCore.Animations;
using StardewValley.Menus;
namespace Revitalize namespace Revitalize
{ {
@ -161,6 +162,8 @@ namespace Revitalize
TextureManager.AddTextureManager(Manifest,"Furniture"); TextureManager.AddTextureManager(Manifest,"Furniture");
TextureManager.GetTextureManager(Manifest,"Furniture").searchForTextures(ModHelper,this.ModManifest,Path.Combine("Content", "Graphics", "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"))); //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(); 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) 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")); Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content", "Graphics", "Furniture", "Tables"));
} }
/// <summary>
/// Initialize all modular components for this mod.
/// </summary>
private void initailizeComponents() private void initailizeComponents()
{ {
DarkerNight.InitializeConfig(); DarkerNight.InitializeConfig();

View File

@ -64,6 +64,7 @@
<Compile Include="Framework\Illuminate\ColorExtensions.cs" /> <Compile Include="Framework\Illuminate\ColorExtensions.cs" />
<Compile Include="Framework\Illuminate\FakeLightSource.cs" /> <Compile Include="Framework\Illuminate\FakeLightSource.cs" />
<Compile Include="Framework\Illuminate\LightManager.cs" /> <Compile Include="Framework\Illuminate\LightManager.cs" />
<Compile Include="Framework\Menus\InventoryMenu.cs" />
<Compile Include="Framework\Menus\SimpleItemGrabMenu.cs" /> <Compile Include="Framework\Menus\SimpleItemGrabMenu.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\Interfaces\ICollider.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\Interfaces\ICollider.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\Interfaces\ISpawner.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\Interfaces\ISpawner.cs" />
@ -155,6 +156,9 @@
<Content Include="Content\Graphics\Furniture\Tables\Oak Table.png"> <Content Include="Content\Graphics\Furniture\Tables\Oak Table.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Graphics\Menus\InventoryMenu\ItemBackground.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\Enemies\Target.png"> <Content Include="Content\Minigames\SeasideScramble\Graphics\Enemies\Target.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>

View File

@ -92,6 +92,7 @@
<Compile Include="Menus\ModualGameMenu.cs" /> <Compile Include="Menus\ModualGameMenu.cs" />
<Compile Include="ModConfig.cs" /> <Compile Include="ModConfig.cs" />
<Compile Include="UIUtilities\IClickableMenuExtended.cs" /> <Compile Include="UIUtilities\IClickableMenuExtended.cs" />
<Compile Include="UIUtilities\MenuComponents\ItemDisplayButton.cs" />
<Compile Include="UIUtilities\LayeredTexture.cs" /> <Compile Include="UIUtilities\LayeredTexture.cs" />
<Compile Include="Animations\AnimatedSprite.cs" /> <Compile Include="Animations\AnimatedSprite.cs" />
<Compile Include="UIUtilities\MenuComponents\BlinkingText.cs" /> <Compile Include="UIUtilities\MenuComponents\BlinkingText.cs" />

View File

@ -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
{
/// <summary>
/// A simple menu component for displaying SDV Items as well as being able to click them.
/// </summary>
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;
/// <summary>
/// The position of the button on screen.
/// </summary>
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()
{
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="I">The itme to display.</param>
/// <param name="Position">The position of the item.</param>
/// <param name="BoundingBox">The bounding box for the item.</param>
/// <param name="Scale"></param>
/// <param name="DrawStackNumber"></param>
/// <param name="DrawColor"></param>
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)
{
}
/// <summary>
/// A simple draw function.
/// </summary>
/// <param name="b"></param>
public void draw(SpriteBatch b)
{
this.background.draw(b);
if(this.item!=null)this.item.drawInMenu(b, this.position, this.scale);
}
/// <summary>
/// The full draw function for drawing this component to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="Depth"></param>
/// <param name="Alpha"></param>
/// <param name="DrawShadow"></param>
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));
}
}
}