This commit is contained in:
gravity 2023-08-17 23:46:30 +03:00
parent 7f981ccd5a
commit b848347c56
5 changed files with 117 additions and 8 deletions

View file

@ -1,15 +1,46 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using System.Xml.Linq;
using DangerousD.GameCore.Managers;
using DangerousD.GameCore;
using System.Collections.Generic;
namespace DangerousD.GameCore.GUI
{
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()
{
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);
}
}
}

View file

@ -63,7 +63,8 @@ namespace DangerousD.GameCore.GUI
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" };
Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => {
bTExit.LeftButtonPressed += () =>
{
AppManager.Instance.ChangeGameState(GameState.Menu);
};
}

View file

@ -14,7 +14,7 @@ using DangerousD.GameCore.Managers;
namespace DangerousD.GameCore
{
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 static AppManager Instance { get; private set; }
@ -30,6 +30,7 @@ namespace DangerousD.GameCore
IDrawableObject LoginGUI;
IDrawableObject LobbyGUI;
IDrawableObject DeathGUI;
IDrawableObject HUD;
public GameManager GameManager { get; private set; } = new();
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
@ -55,13 +56,14 @@ namespace DangerousD.GameCore
resolution = SettingsManager.Resolution;
_graphics.PreferredBackBufferWidth = resolution.X;
_graphics.PreferredBackBufferHeight = resolution.Y;
_graphics.IsFullScreen = true;
gameState = GameState.Menu;
//_graphics.IsFullScreen = true;
gameState = GameState.HUD;
MenuGUI = new MenuGUI();
LoginGUI = new LoginGUI();
OptionsGUI = new OptionsGUI();
LobbyGUI = new LobbyGUI();
DeathGUI = new DeathGUI();
HUD = new HUD();
UIManager.resolution = resolution;
UIManager.resolutionInGame = inGameResolution;
}
@ -73,7 +75,7 @@ namespace DangerousD.GameCore
LoginGUI.Initialize();
OptionsGUI.Initialize();
HUD.Initialize();
LobbyGUI.Initialize();
DeathGUI.Initialize();
base.Initialize();
@ -87,6 +89,7 @@ namespace DangerousD.GameCore
OptionsGUI.LoadContent();
LobbyGUI.LoadContent();
DeathGUI.LoadContent();
HUD.LoadContent();
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
SoundManager.LoadSounds();
@ -119,6 +122,9 @@ namespace DangerousD.GameCore
case GameState.Death:
DeathGUI.Update(gameTime);
break;
case GameState.HUD:
HUD.Update(gameTime);
break;
case GameState.Game:
GameManager.Update(gameTime);
break;
@ -151,6 +157,9 @@ namespace DangerousD.GameCore
case GameState.Death:
DeathGUI.Draw(_spriteBatch);
break;
case GameState.HUD:
HUD.Draw(_spriteBatch);
break;
case GameState.Game:
_spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
GameManager.Draw(_spriteBatch);

View file

@ -15,7 +15,7 @@ namespace MonogameLibrary.UI.Base
protected Texture2D texture;
protected int layerIndex;
protected UIManager Manager;
public string textureName;
public string textureName = "";
public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
public Color mainColor = Color.White;

View 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);
}
}
}