HUD
This commit is contained in:
parent
7f981ccd5a
commit
b848347c56
5 changed files with 117 additions and 8 deletions
|
@ -1,15 +1,46 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using MonogameLibrary.UI.Base;
|
||||||
using MonogameLibrary.UI.Elements;
|
using MonogameLibrary.UI.Elements;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using DangerousD.GameCore.Managers;
|
||||||
|
using DangerousD.GameCore;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GUI
|
namespace DangerousD.GameCore.GUI
|
||||||
{
|
{
|
||||||
public class HUD : AbstractGui
|
public class HUD : AbstractGui
|
||||||
{
|
{
|
||||||
|
Button[] buttons = new Button[2];
|
||||||
|
int ammout = 0;
|
||||||
|
List<Rect> rects = new List<Rect> { };
|
||||||
|
int wigth = AppManager.Instance.inGameResolution.X;
|
||||||
|
int height = AppManager.Instance.inGameResolution.Y;
|
||||||
protected override void CreateUI()
|
protected override void CreateUI()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
DrawableUIElement background = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), mainColor = Color.Transparent };
|
||||||
|
Elements.Add(background);
|
||||||
|
Rect rect = new Rect(Manager) { rectangle = new Rectangle(wigth / 35, height / 35, 120, 70), mainColor = Color.DarkRed };
|
||||||
|
Elements.Add(rect);
|
||||||
|
Label label = new Label(Manager) { rectangle = new Rectangle(wigth / 34, height / 30, 120, 20), text = "ammout", fontName = "font2", scale = 0.2f, mainColor = Color.Transparent, fontColor = Color.Black };
|
||||||
|
Elements.Add(label);
|
||||||
|
buttons[0] = new Button(Manager) { rectangle = new Rectangle(300, 300, 50, 50), text = ammout.ToString() };
|
||||||
|
Elements.Add(buttons[0]);
|
||||||
|
buttons[1] = new Button(Manager) { rectangle = new Rectangle(300, 400, 50, 50) };
|
||||||
|
Elements.Add(buttons[1]);
|
||||||
|
|
||||||
|
}
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
rects.Clear();
|
||||||
|
for (int i = 0; i < ammout; i++)
|
||||||
|
{ ammout += 1;
|
||||||
|
ammout %= 8;
|
||||||
|
rects.Add(new Rect(Manager) { rectangle = new Rectangle(wigth / 29 + i * 13, height / 17, 5, 20), mainColor = Color.Yellow });
|
||||||
|
rects[i].LoadTexture(AppManager.Instance.Content);
|
||||||
|
}
|
||||||
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,8 @@ namespace DangerousD.GameCore.GUI
|
||||||
Button bTExit = new Button(Manager)
|
Button bTExit = new Button(Manager)
|
||||||
{ fontName = "Font2", scale = 0.72f, text = "<-", rectangle = new Rectangle(wigth / 30, height / 30, (int)(40 * 2.4), (int)(40 * 2.4)), textureName = "textboxbackground1-1" };
|
{ fontName = "Font2", scale = 0.72f, text = "<-", rectangle = new Rectangle(wigth / 30, height / 30, (int)(40 * 2.4), (int)(40 * 2.4)), textureName = "textboxbackground1-1" };
|
||||||
Elements.Add(bTExit);
|
Elements.Add(bTExit);
|
||||||
bTExit.LeftButtonPressed += () => {
|
bTExit.LeftButtonPressed += () =>
|
||||||
|
{
|
||||||
AppManager.Instance.ChangeGameState(GameState.Menu);
|
AppManager.Instance.ChangeGameState(GameState.Menu);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ using DangerousD.GameCore.Managers;
|
||||||
namespace DangerousD.GameCore
|
namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
public enum MultiPlayerStatus { SinglePlayer, Host, Client }
|
public enum MultiPlayerStatus { SinglePlayer, Host, Client }
|
||||||
public enum GameState { Menu, Options, Lobby, Game, Login, Death }
|
public enum GameState { Menu, Options, Lobby, Game, Login, Death, HUD }
|
||||||
public class AppManager : Game
|
public class AppManager : Game
|
||||||
{
|
{
|
||||||
public static AppManager Instance { get; private set; }
|
public static AppManager Instance { get; private set; }
|
||||||
|
@ -30,6 +30,7 @@ namespace DangerousD.GameCore
|
||||||
IDrawableObject LoginGUI;
|
IDrawableObject LoginGUI;
|
||||||
IDrawableObject LobbyGUI;
|
IDrawableObject LobbyGUI;
|
||||||
IDrawableObject DeathGUI;
|
IDrawableObject DeathGUI;
|
||||||
|
IDrawableObject HUD;
|
||||||
|
|
||||||
public GameManager GameManager { get; private set; } = new();
|
public GameManager GameManager { get; private set; } = new();
|
||||||
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
|
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
|
||||||
|
@ -55,13 +56,14 @@ namespace DangerousD.GameCore
|
||||||
resolution = SettingsManager.Resolution;
|
resolution = SettingsManager.Resolution;
|
||||||
_graphics.PreferredBackBufferWidth = resolution.X;
|
_graphics.PreferredBackBufferWidth = resolution.X;
|
||||||
_graphics.PreferredBackBufferHeight = resolution.Y;
|
_graphics.PreferredBackBufferHeight = resolution.Y;
|
||||||
_graphics.IsFullScreen = true;
|
//_graphics.IsFullScreen = true;
|
||||||
gameState = GameState.Menu;
|
gameState = GameState.HUD;
|
||||||
MenuGUI = new MenuGUI();
|
MenuGUI = new MenuGUI();
|
||||||
LoginGUI = new LoginGUI();
|
LoginGUI = new LoginGUI();
|
||||||
OptionsGUI = new OptionsGUI();
|
OptionsGUI = new OptionsGUI();
|
||||||
LobbyGUI = new LobbyGUI();
|
LobbyGUI = new LobbyGUI();
|
||||||
DeathGUI = new DeathGUI();
|
DeathGUI = new DeathGUI();
|
||||||
|
HUD = new HUD();
|
||||||
UIManager.resolution = resolution;
|
UIManager.resolution = resolution;
|
||||||
UIManager.resolutionInGame = inGameResolution;
|
UIManager.resolutionInGame = inGameResolution;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +75,7 @@ namespace DangerousD.GameCore
|
||||||
LoginGUI.Initialize();
|
LoginGUI.Initialize();
|
||||||
|
|
||||||
OptionsGUI.Initialize();
|
OptionsGUI.Initialize();
|
||||||
|
HUD.Initialize();
|
||||||
LobbyGUI.Initialize();
|
LobbyGUI.Initialize();
|
||||||
DeathGUI.Initialize();
|
DeathGUI.Initialize();
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
@ -87,6 +89,7 @@ namespace DangerousD.GameCore
|
||||||
OptionsGUI.LoadContent();
|
OptionsGUI.LoadContent();
|
||||||
LobbyGUI.LoadContent();
|
LobbyGUI.LoadContent();
|
||||||
DeathGUI.LoadContent();
|
DeathGUI.LoadContent();
|
||||||
|
HUD.LoadContent();
|
||||||
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||||
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
|
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
|
||||||
SoundManager.LoadSounds();
|
SoundManager.LoadSounds();
|
||||||
|
@ -119,6 +122,9 @@ namespace DangerousD.GameCore
|
||||||
case GameState.Death:
|
case GameState.Death:
|
||||||
DeathGUI.Update(gameTime);
|
DeathGUI.Update(gameTime);
|
||||||
break;
|
break;
|
||||||
|
case GameState.HUD:
|
||||||
|
HUD.Update(gameTime);
|
||||||
|
break;
|
||||||
case GameState.Game:
|
case GameState.Game:
|
||||||
GameManager.Update(gameTime);
|
GameManager.Update(gameTime);
|
||||||
break;
|
break;
|
||||||
|
@ -151,6 +157,9 @@ namespace DangerousD.GameCore
|
||||||
case GameState.Death:
|
case GameState.Death:
|
||||||
DeathGUI.Draw(_spriteBatch);
|
DeathGUI.Draw(_spriteBatch);
|
||||||
break;
|
break;
|
||||||
|
case GameState.HUD:
|
||||||
|
HUD.Draw(_spriteBatch);
|
||||||
|
break;
|
||||||
case GameState.Game:
|
case GameState.Game:
|
||||||
_spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
|
_spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
|
||||||
GameManager.Draw(_spriteBatch);
|
GameManager.Draw(_spriteBatch);
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace MonogameLibrary.UI.Base
|
||||||
protected Texture2D texture;
|
protected Texture2D texture;
|
||||||
protected int layerIndex;
|
protected int layerIndex;
|
||||||
protected UIManager Manager;
|
protected UIManager Manager;
|
||||||
public string textureName;
|
public string textureName = "";
|
||||||
public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
|
public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
|
||||||
public Color mainColor = Color.White;
|
public Color mainColor = Color.White;
|
||||||
|
|
||||||
|
|
68
MonogameLibrary/UI/Elements/Rect.cs
Normal file
68
MonogameLibrary/UI/Elements/Rect.cs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using MonogameLibrary.UI.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using static MonogameLibrary.UI.Elements.Button;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Elements
|
||||||
|
{
|
||||||
|
public class Rect : DrawableTextedUiElement, IInteractable
|
||||||
|
{
|
||||||
|
public delegate void OnButtonPressed();
|
||||||
|
public event OnButtonPressed? RightButtonPressed;
|
||||||
|
public event OnButtonPressed? LeftButtonPressed;
|
||||||
|
protected HoverState hoverState = HoverState.None;
|
||||||
|
|
||||||
|
public Rect(UIManager manager, int layerIndex = 0) : base(manager, layerIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
|
||||||
|
{
|
||||||
|
//if (Manager.)
|
||||||
|
if (rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero)))
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton == ButtonState.Pressed || mouseState.RightButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Hovering;
|
||||||
|
}
|
||||||
|
if (prevmouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton != prevmouseState.LeftButton)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
LeftButtonPressed?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(prevmouseState.RightButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (mouseState.RightButton != prevmouseState.RightButton)
|
||||||
|
{
|
||||||
|
RightButtonPressed?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.None;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public override void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
_spriteBatch.Draw(texture, rectangle, Color.White);
|
||||||
|
DrawText(_spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue