diff options
| author | hazel <hazel@hazelthats.me> | 2026-01-26 22:04:39 +0100 |
|---|---|---|
| committer | hazel <hazel@hazelthats.me> | 2026-01-26 22:04:39 +0100 |
| commit | 567c422f8cd42eba2437f9a8c2522716a1649be7 (patch) | |
| tree | 93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/ui/guis/DebugGUI.cs | |
| download | celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2 celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip | |
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/ui/guis/DebugGUI.cs')
| -rw-r--r-- | source/ui/guis/DebugGUI.cs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/source/ui/guis/DebugGUI.cs b/source/ui/guis/DebugGUI.cs new file mode 100644 index 0000000..7ee44ae --- /dev/null +++ b/source/ui/guis/DebugGUI.cs @@ -0,0 +1,66 @@ +using System.Diagnostics; +using Celesteia.Resources; +using Celesteia.UI; +using Celesteia.UI.Elements; +using Celesteia.UI.Properties; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using MonoGame.Extended; + +namespace Celesteia.GUIs { + public class DebugGUI : GUI { + private new GameInstance Game => (GameInstance) base.Game; + public DebugGUI(GameInstance game) : base(game, Rect.ScreenFull) {} + + private Label updateLabel; + private Label drawLabel; + + public override void LoadContent(ContentManager Content) { + float fontSize = 12f; + + Label template = new Label(new Rect( + AbsoluteUnit.WithValue(10), + AbsoluteUnit.WithValue(10), + AbsoluteUnit.WithValue(200), + AbsoluteUnit.WithValue(50) + )) + .SetTextProperties(new TextProperties() + .SetColor(Color.White) + .SetFont(ResourceManager.Fonts.GetFontType("Hobo")) + .SetFontSize(fontSize) + .SetTextAlignment(TextAlignment.Top | TextAlignment.Left) + ); + float textSpacing = 4f; + float textRow(int number) => 10f + number * (fontSize + textSpacing); + + Root.AddChild(template.Clone().SetNewRect(template.GetRect().SetY(AbsoluteUnit.WithValue(textRow(0)))).SetText($"Celesteia {GameInstance.Version}")); + Root.AddChild(updateLabel = template.Clone().SetNewRect(template.GetRect().SetY(AbsoluteUnit.WithValue(textRow(1)))).SetText("")); + Root.AddChild(drawLabel = template.Clone().SetNewRect(template.GetRect().SetY(AbsoluteUnit.WithValue(textRow(2)))).SetText("")); + + Debug.WriteLine("Loaded Debug GUI."); + } + + private double updateTime; + private double lastUpdate; + public override void Update(GameTime gameTime, out bool clickedAnything) { + clickedAnything = false; + + updateTime = gameTime.TotalGameTime.TotalMilliseconds - lastUpdate; + lastUpdate = gameTime.TotalGameTime.TotalMilliseconds; + + updateLabel.SetText($"Update: {updateTime.ToString("0.00")}ms"); + } + + private double drawTime; + private double lastDraw; + public override void Draw(GameTime gameTime) + { + drawTime = gameTime.TotalGameTime.TotalMilliseconds - lastDraw; + lastDraw = gameTime.TotalGameTime.TotalMilliseconds; + + drawLabel.SetText($"Draw: {drawTime.ToString("0.00")}ms"); + + if (GameInstance.DebugMode) base.Draw(gameTime); + } + } +}
\ No newline at end of file |
