From cbdabf794f5aaa19ff3f862527e3e0eeeb882535 Mon Sep 17 00:00:00 2001 From: Ivan Filipenkov Date: Thu, 17 Aug 2023 21:53:17 +0300 Subject: [PATCH] DebugHUD --- DangerousD/Content/Content.mgcb | 7 ++ DangerousD/Content/Font_12.spritefont | 64 +++++++++++++++++++ DangerousD/GameCore/GUI/DebugHUD.cs | 50 +++++++++++++++ .../GameCore/GameObjects/IDrawableObject.cs | 2 +- DangerousD/GameCore/Managers/AppManager.cs | 8 ++- 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 DangerousD/Content/Font_12.spritefont create mode 100644 DangerousD/GameCore/GUI/DebugHUD.cs diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index c977303..713c20a 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -87,6 +87,13 @@ /processorParam:Quality=Best /build:DoomTestSong.mp3 +#begin Font_12.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Font_12.spritefont + #begin Font_25.spritefont /importer:FontDescriptionImporter /processor:FontDescriptionProcessor diff --git a/DangerousD/Content/Font_12.spritefont b/DangerousD/Content/Font_12.spritefont new file mode 100644 index 0000000..4cffaf7 --- /dev/null +++ b/DangerousD/Content/Font_12.spritefont @@ -0,0 +1,64 @@ + + + + + + + Arial + + + 12 + + + 0 + + + true + + + + + + + + + + + + ~ + + + а + я + + + + diff --git a/DangerousD/GameCore/GUI/DebugHUD.cs b/DangerousD/GameCore/GUI/DebugHUD.cs new file mode 100644 index 0000000..c37626e --- /dev/null +++ b/DangerousD/GameCore/GUI/DebugHUD.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using MonogameLibrary.UI.Elements; +using static System.String; + +namespace DangerousD.GameCore.GUI +{ + public class DebugHUD : IDrawableObject + { + private SpriteFont _spriteFont; + private Dictionary _text = new(); + + public void Initialize() + { + } + + public void LoadContent() + { + _spriteFont = AppManager.Instance.Content.Load("Font_12"); + } + + public void Update(GameTime gameTime) + { + } + + public void Draw(SpriteBatch spriteBatch) + { + spriteBatch.Begin(); + spriteBatch.DrawString( + _spriteFont, + Join(",", _text.Select(el => el.Key + ": " + el.Value).ToList()), + new Vector2(10, 10), + Color.Cyan, + 0, + Vector2.Zero, + 1, + SpriteEffects.None, + 0 + ); + spriteBatch.End(); + } + + public void Set(string key, string value) + { + _text[key] = value; + } + } +} \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/IDrawableObject.cs b/DangerousD/GameCore/GameObjects/IDrawableObject.cs index 1d9ca5c..42d8320 100644 --- a/DangerousD/GameCore/GameObjects/IDrawableObject.cs +++ b/DangerousD/GameCore/GameObjects/IDrawableObject.cs @@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics; namespace DangerousD.GameCore.GUI { - interface IDrawableObject + public interface IDrawableObject { void Initialize(); void LoadContent(); diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index d5bf99c..a4a1063 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -24,12 +24,13 @@ namespace DangerousD.GameCore public GameState gameState { get; private set; } public MultiPlayerStatus multiPlayerStatus { get; private set; } = MultiPlayerStatus.SinglePlayer; public Point resolution = new Point(1920, 1080); - public Point inGameResolution = new Point(1920, 1080); + public Point inGameResolution = new Point(1366, 768); IDrawableObject MenuGUI; IDrawableObject OptionsGUI; IDrawableObject LoginGUI; IDrawableObject LobbyGUI; IDrawableObject DeathGUI; + public DebugHUD DebugHUD; public GameManager GameManager { get; private set; } = new(); public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder(); @@ -62,6 +63,7 @@ namespace DangerousD.GameCore OptionsGUI = new OptionsGUI(); LobbyGUI = new LobbyGUI(); DeathGUI = new DeathGUI(); + DebugHUD = new DebugHUD(); UIManager.resolution = resolution; UIManager.resolutionInGame = inGameResolution; } @@ -72,6 +74,7 @@ namespace DangerousD.GameCore MenuGUI.Initialize(); LoginGUI.Initialize(); + DebugHUD.Initialize(); OptionsGUI.Initialize(); LobbyGUI.Initialize(); @@ -82,6 +85,7 @@ namespace DangerousD.GameCore protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); + DebugHUD.LoadContent(); MenuGUI.LoadContent(); LoginGUI.LoadContent(); OptionsGUI.LoadContent(); @@ -125,6 +129,7 @@ namespace DangerousD.GameCore default: break; } + DebugHUD.Update(gameTime); base.Update(gameTime); } @@ -165,6 +170,7 @@ namespace DangerousD.GameCore _spriteBatch.End(); + DebugHUD.Draw(_spriteBatch); base.Draw(gameTime); }