From 3b0271b7712ed53d8f6e6a9fcc7c064bcbcb0a45 Mon Sep 17 00:00:00 2001 From: William Moorehouse Date: Wed, 30 Sep 2015 15:28:38 -0400 Subject: [PATCH] Initial work on hotbar interface --- TrueCraft.Client/Modules/HUDModule.cs | 51 +++++++++++++++++++ .../Modules/PlayerControlModule.cs | 36 +++++++++++++ TrueCraft.Client/TrueCraftGame.cs | 1 + 3 files changed, 88 insertions(+) diff --git a/TrueCraft.Client/Modules/HUDModule.cs b/TrueCraft.Client/Modules/HUDModule.cs index 1a9a574..66e0e5a 100644 --- a/TrueCraft.Client/Modules/HUDModule.cs +++ b/TrueCraft.Client/Modules/HUDModule.cs @@ -27,12 +27,63 @@ namespace TrueCraft.Client.Modules public void Draw(GameTime gameTime) { SpriteBatch.Begin(samplerState: SamplerState.PointClamp); + SpriteBatch.Draw(Icons, new Vector2( Game.GraphicsDevice.Viewport.Width / 2 - (8 * Game.ScaleFactor * 2), Game.GraphicsDevice.Viewport.Height / 2 - (8 * Game.ScaleFactor * 2)), new Rectangle(0, 0, 16, 16), CrosshairColor, 0, Vector2.Zero, Game.ScaleFactor * 2, SpriteEffects.None, 1); + + DrawHotbar(gameTime); + SpriteBatch.End(); } + + #region "Hotbar" + + /// + /// The dimensions of the hotbar background. + /// + private static readonly Rectangle HotbarBackgroundRect = + new Rectangle(0, 0, 182, 22); + + /// + /// The dimensions of the hotbar selection. + /// + private static readonly Rectangle HotbarSelectionRect = + new Rectangle(0, 22, 24, 24); + + /// + /// Draws the inventory hotbar. + /// + /// + private void DrawHotbar(GameTime gameTime) + { + // Background + SpriteBatch.Draw(GUI, new Vector2( + Game.GraphicsDevice.Viewport.Width / 2 - Scale(HotbarBackgroundRect.Width / 2), + Game.GraphicsDevice.Viewport.Height - Scale(HotbarBackgroundRect.Height + 5)), + HotbarBackgroundRect, Color.White, 0, Vector2.Zero, Game.ScaleFactor * 2, SpriteEffects.None, 1); + + // TODO: Icons + + // Selection + SpriteBatch.Draw(GUI, new Vector2( + Game.GraphicsDevice.Viewport.Width / 2 - Scale(HotbarBackgroundRect.Width / 2) + Scale(Game.HotbarSelection * 20 - 1), + Game.GraphicsDevice.Viewport.Height - Scale(HotbarBackgroundRect.Height + 6)), + HotbarSelectionRect, Color.White, 0, Vector2.Zero, Game.ScaleFactor * 2, SpriteEffects.None, 1); + } + + #endregion + + /// + /// Scales a float depending on the game's scale factor. + /// + /// + /// + private float Scale(float value) + { + return value * Game.ScaleFactor * 2; + } } } diff --git a/TrueCraft.Client/Modules/PlayerControlModule.cs b/TrueCraft.Client/Modules/PlayerControlModule.cs index 5588bae..e761288 100644 --- a/TrueCraft.Client/Modules/PlayerControlModule.cs +++ b/TrueCraft.Client/Modules/PlayerControlModule.cs @@ -78,6 +78,42 @@ namespace TrueCraft.Client.Modules if (Math.Floor(Game.Client.Position.Y) == Game.Client.Position.Y) Game.Client.Velocity += TrueCraft.API.Vector3.Up * 0.3; return true; + + case Keys.NumPad1: + Game.HotbarSelection = 0; + return true; + + case Keys.NumPad2: + Game.HotbarSelection = 1; + return true; + + case Keys.NumPad3: + Game.HotbarSelection = 2; + return true; + + case Keys.NumPad4: + Game.HotbarSelection = 3; + return true; + + case Keys.NumPad5: + Game.HotbarSelection = 4; + return true; + + case Keys.NumPad6: + Game.HotbarSelection = 5; + return true; + + case Keys.NumPad7: + Game.HotbarSelection = 6; + return true; + + case Keys.NumPad8: + Game.HotbarSelection = 7; + return true; + + case Keys.NumPad9: + Game.HotbarSelection = 8; + return true; } return false; } diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index df874b7..18947a8 100644 --- a/TrueCraft.Client/TrueCraftGame.cs +++ b/TrueCraft.Client/TrueCraftGame.cs @@ -38,6 +38,7 @@ namespace TrueCraft.Client public DateTime StartDigging { get; set; } public DateTime EndDigging { get; set; } public Coordinates3D TargetBlock { get; set; } + public int HotbarSelection { get; set; } private List Modules { get; set; } private SpriteBatch SpriteBatch { get; set; }