From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/ui/guis/DebugGUI.cs | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 source/ui/guis/DebugGUI.cs (limited to 'source/ui/guis/DebugGUI.cs') 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 -- cgit v1.2.3