Made a Gui and created a dropdown menu to select block
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Collector.Character
|
||||
{
|
||||
public class Collision
|
||||
{
|
||||
public RectangleF Rectangle { get; private set; }
|
||||
public RectangleF Rectangle { get; }
|
||||
|
||||
public Collision(int x, int y)
|
||||
{
|
||||
|
||||
@@ -166,10 +166,15 @@ namespace Collector.Character
|
||||
}
|
||||
if (mouseState.RightButton == ButtonState.Pressed)
|
||||
{
|
||||
Chunks.PlaceBlock(PlayerMouse.GetSelectedX(),PlayerMouse.GetSelectedY(),Blocks.BlockWood);
|
||||
PlaceSelectedBlock(Inventory.GetSelectedItem());
|
||||
}
|
||||
}
|
||||
|
||||
private static void PlaceSelectedBlock(Blocks selectedItem)
|
||||
{
|
||||
Chunks.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
|
||||
}
|
||||
|
||||
private void UpdateAnimationFrame(GameTime gameTime)
|
||||
{
|
||||
_timeSinceLastFrame += gameTime.GetElapsedSeconds();
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Collector.Dimension;
|
||||
|
||||
using Collector.UI;
|
||||
using Myra.Graphics2D.UI;
|
||||
|
||||
public class Inventory {
|
||||
private LinkedList<ItemStack> inventory = new LinkedList<ItemStack>();
|
||||
|
||||
public static Blocks GetSelectedItem()
|
||||
{
|
||||
return (Blocks) Gui._combo.SelectedIndex.Value;
|
||||
}
|
||||
|
||||
public LinkedList<ItemStack> GetInventory() {
|
||||
return inventory;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
namespace Collector.Dimension
|
||||
{
|
||||
public enum Blocks
|
||||
public enum Blocks : byte
|
||||
{
|
||||
BlockAir,
|
||||
BlockGrass,
|
||||
BlockWood,
|
||||
BlockStone,
|
||||
BlockSnow,
|
||||
BlockSand,
|
||||
BlockRoof,
|
||||
BlockWall,
|
||||
BlockWater
|
||||
BlockAir = 0,
|
||||
BlockGrass = 1,
|
||||
BlockWood = 2,
|
||||
BlockStone = 3,
|
||||
BlockSnow = 4,
|
||||
BlockSand = 5,
|
||||
BlockRoof = 6,
|
||||
BlockWall = 7,
|
||||
BlockWater = 8
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,79 @@
|
||||
|
||||
|
||||
using Collector;
|
||||
using System;
|
||||
using Collector.Dimension;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Myra.Graphics2D.UI;
|
||||
|
||||
public class GUI: IRestrictions {
|
||||
namespace Collector.UI
|
||||
{
|
||||
public class Gui: IRestrictions {
|
||||
private Desktop _desktop;
|
||||
public static ComboBox _combo;
|
||||
private TextButton _button;
|
||||
|
||||
public Gui(Desktop desktop)
|
||||
{
|
||||
_desktop = desktop;
|
||||
}
|
||||
|
||||
public void LoadGUI()
|
||||
{
|
||||
var grid = new Grid
|
||||
{
|
||||
RowSpacing = 8,
|
||||
ColumnSpacing = 8
|
||||
};
|
||||
|
||||
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
|
||||
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
|
||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
|
||||
|
||||
|
||||
//Position
|
||||
_combo = new ComboBox
|
||||
{
|
||||
GridColumn = 0,
|
||||
GridRow = 0
|
||||
};
|
||||
_button = new TextButton
|
||||
{
|
||||
GridColumn = 1,
|
||||
GridRow = 0,
|
||||
Text = "Inventory"
|
||||
};
|
||||
|
||||
|
||||
foreach (Blocks name in Enum.GetValues(typeof(Blocks)))
|
||||
{
|
||||
_combo.Items.Add(new ListItem(name.ToString(), Color.White));
|
||||
}
|
||||
|
||||
grid.Widgets.Add(_combo);
|
||||
|
||||
|
||||
_button.Click += (s, a) =>
|
||||
{
|
||||
var messageBox = Dialog.CreateMessageBox("Message", "Some message!");
|
||||
messageBox.ShowModal(_desktop);
|
||||
};
|
||||
|
||||
grid.Widgets.Add(_button);
|
||||
|
||||
_desktop = new Desktop
|
||||
{
|
||||
Root = grid
|
||||
};
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
_desktop.Render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user