addDebugHUD

This commit is contained in:
dvaer 2024-08-15 11:36:04 +03:00
parent 59b04ce7f1
commit fb2b685136
8 changed files with 80 additions and 9 deletions

View file

@ -13,14 +13,14 @@
#---------------------------------- Content ---------------------------------#
#begin Font/Font.spritefont
#begin Fonts/Font.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Font/Font.spritefont
/build:Fonts/Font.spritefont
#begin Texture/GUI/MenuBackground.jpg
#begin Textures/GUI/MenuBackground.jpg
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
@ -30,5 +30,5 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Texture/GUI/MenuBackground.jpg
/build:Textures/GUI/MenuBackground.jpg

View file

Before

Width:  |  Height:  |  Size: 592 KiB

After

Width:  |  Height:  |  Size: 592 KiB

View file

@ -1,6 +1,72 @@
namespace ZoFo.GameCore.GUI;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Elements;
using static System.String;
using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GUI;
public class DebugHUD
{
private SpriteFont _spriteFont;
private Dictionary<string, string> _text = new();
private List<string> _log = new();
public void Initialize()
{
}
public void LoadContent()
{
_spriteFont = AppManager.Instance.Content.Load<SpriteFont>("Fonts\\Font");
}
public void Update(GameTime gameTime)
{
}
public void Draw(SpriteBatch spriteBatch)
{
var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
spriteBatch.Begin();
spriteBatch.DrawString(
_spriteFont,
keysString,
new Vector2(10, 10),
Color.Cyan,
0,
Vector2.Zero,
1,
SpriteEffects.None,
0
);
spriteBatch.DrawString(
_spriteFont,
Join("\n", _log),
new Vector2(10, 10 + _spriteFont.MeasureString(keysString).Y),
Color.Green,
0,
Vector2.Zero,
1,
SpriteEffects.None,
0
);
spriteBatch.End();
}
public void Set(string key, string value)
{
_text[key] = value;
}
public void Log(string value)
{
_log.Add(value);
if (_log.Count > 30)
{
_log.RemoveAt(0);
}
}
}

View file

@ -21,7 +21,7 @@ public class MainMenuGUI : AbstractGUI
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), textureName = "Texture\\GUI\\MenuBackground" };
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), textureName = "Textures\\GUI\\MenuBackground" };
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
}

View file

@ -22,6 +22,7 @@ namespace ZoFo.GameCore.GameManagers
public static AppManager Instance { get; private set; }
public GameState gamestate;
public AbstractGUI currentGUI;
public DebugHUD debugHud;
public Point CurentScreenResolution = new Point(1920, 1080);
//public Client client;
//public Server server;
@ -43,12 +44,14 @@ namespace ZoFo.GameCore.GameManagers
InputManager = new InputManager();
currentGUI = new MainMenuGUI();
debugHud = new DebugHUD();
}
protected override void Initialize()
{
currentGUI.Initialize();
debugHud.Initialize();
@ -58,7 +61,8 @@ namespace ZoFo.GameCore.GameManagers
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
debugHud.LoadContent();
currentGUI.LoadContent();
@ -96,6 +100,7 @@ namespace ZoFo.GameCore.GameManagers
currentGUI.Draw(_spriteBatch);
debugHud.Draw(_spriteBatch);
switch (gamestate)
{
case GameState.ClientPlaying:

View file

@ -27,7 +27,7 @@
<ProjectReference Include="..\MonogameLibrary\MonogameLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Content\Texture\GUI\" />
<Folder Include="Content\Textures\GUI\" />
</ItemGroup>
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
<Message Text="Restoring dotnet tools" Importance="High" />