From cb718c56d53ad64436381f637af3b5f585b97f12 Mon Sep 17 00:00:00 2001 From: WeylonSantana <63019821+WeylonSantana@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:46:51 -0300 Subject: [PATCH] chore: refactor debug window (#2341) --- .../Gwen/Control/Base.cs | 8 ++++- .../Gwen/Control/Data/ITableDataProvider.cs | 2 +- .../Interface/Debugging/DebugWindow.cs | 29 ++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Intersect.Client.Framework/Gwen/Control/Base.cs b/Intersect.Client.Framework/Gwen/Control/Base.cs index 5185c5818..628a82e50 100644 --- a/Intersect.Client.Framework/Gwen/Control/Base.cs +++ b/Intersect.Client.Framework/Gwen/Control/Base.cs @@ -863,7 +863,7 @@ public virtual JObject FixJson(JObject json) return json; } - public void LoadJsonUi(GameContentManager.UI stage, string resolution, bool saveOutput = true) + public void LoadJsonUi(GameContentManager.UI stage, string? resolution, bool saveOutput = true) { if (string.IsNullOrWhiteSpace(Name)) { @@ -871,6 +871,12 @@ public void LoadJsonUi(GameContentManager.UI stage, string resolution, bool save return; } + if (string.IsNullOrWhiteSpace(resolution) || string.IsNullOrEmpty(resolution)) + { + Log.Warn($"Attempted to load layout for {Name} with no resolution"); + return; + } + _ = GameContentManager.Current?.GetLayout(stage, Name, resolution, false, (rawLayout, cacheHit) => { if (!string.IsNullOrWhiteSpace(rawLayout)) diff --git a/Intersect.Client.Framework/Gwen/Control/Data/ITableDataProvider.cs b/Intersect.Client.Framework/Gwen/Control/Data/ITableDataProvider.cs index c54897df7..81f51c5d6 100644 --- a/Intersect.Client.Framework/Gwen/Control/Data/ITableDataProvider.cs +++ b/Intersect.Client.Framework/Gwen/Control/Data/ITableDataProvider.cs @@ -2,7 +2,7 @@ namespace Intersect.Client.Framework.Gwen.Control.Data; public partial class TableDataChangedEventArgs : RowDataChangedEventArgs { - public TableDataChangedEventArgs(int row, int column, object oldValue, object newValue) + public TableDataChangedEventArgs(int row, int column, object? oldValue, object newValue) : base(column, oldValue, newValue) { Row = row; diff --git a/Intersect.Client/Interface/Debugging/DebugWindow.cs b/Intersect.Client/Interface/Debugging/DebugWindow.cs index 3c9d3351b..2b23a6192 100644 --- a/Intersect.Client/Interface/Debugging/DebugWindow.cs +++ b/Intersect.Client/Interface/Debugging/DebugWindow.cs @@ -20,10 +20,14 @@ internal sealed partial class DebugWindow : Window public DebugWindow(Base parent) : base(parent, Strings.Debug.Title, false, nameof(DebugWindow)) { - _disposables = new List(); - + _disposables = []; DisableResizing(); + CheckboxDrawDebugOutlines = CreateCheckboxDrawDebugOutlines(); + CheckboxEnableLayoutHotReloading = CreateCheckboxEnableLayoutHotReloading(); + ButtonShutdownServer = CreateButtonShutdownServer(); + ButtonShutdownServerAndExit = CreateButtonShutdownServerAndExit(); + TableDebugStats = CreateTableDebugStats(); IsHidden = true; } @@ -39,13 +43,7 @@ public DebugWindow(Base parent) : base(parent, Strings.Debug.Title, false, nameo protected override void EnsureInitialized() { - CheckboxDrawDebugOutlines = CreateCheckboxDrawDebugOutlines(); - CheckboxEnableLayoutHotReloading = CreateCheckboxEnableLayoutHotReloading(); - ButtonShutdownServer = CreateButtonShutdownServer(); - ButtonShutdownServerAndExit = CreateButtonShutdownServerAndExit(); - TableDebugStats = CreateTableDebugStats(); - - LoadJsonUi(UI.Debug, Graphics.Renderer.GetResolutionString()); + LoadJsonUi(UI.Debug, Graphics.Renderer?.GetResolutionString()); } protected override void OnAttached(Base parent) @@ -110,10 +108,7 @@ private LabeledCheckBox CreateCheckboxEnableLayoutHotReloading() Text = Strings.Debug.EnableLayoutHotReloading, }; - checkbox.CheckChanged += (sender, args) => - { - Globals.ContentManager.ContentWatcher.Enabled = checkbox.IsChecked; - }; + checkbox.CheckChanged += (sender, args) => Globals.ContentManager.ContentWatcher.Enabled = checkbox.IsChecked; checkbox.SetToolTipText(Strings.Internals.ExperimentalFeatureTooltip); checkbox.ToolTipFont = Skin.DefaultFont; @@ -160,7 +155,7 @@ private Table CreateTableDebugStats() ColumnCount = 2, }; - var fpsProvider = new ValueTableCellDataProvider(() => Graphics.Renderer.GetFps()); + var fpsProvider = new ValueTableCellDataProvider(() => Graphics.Renderer?.GetFps() ?? 0); table.AddRow(Strings.Debug.Fps).Listen(fpsProvider, 1); _disposables.Add(fpsProvider.Generator.Start()); @@ -218,7 +213,7 @@ private Table CreateTableDebugStats() table.AddRow(Strings.Debug.LightsDrawn).Listen(lightsDrawnProvider, 1); _disposables.Add(lightsDrawnProvider.Generator.Start()); - var timeProvider = new ValueTableCellDataProvider(() => Time.GetTime()); + var timeProvider = new ValueTableCellDataProvider(Time.GetTime); table.AddRow(Strings.Debug.Time).Listen(timeProvider, 1); _disposables.Add(timeProvider.Generator.Start()); @@ -227,7 +222,7 @@ private Table CreateTableDebugStats() try { return Interface.CurrentInterface?.Children.ToArray().SelectManyRecursive( - x => x.Children.ToArray(), + x => [.. x.Children], cancellationToken ).ToArray().Length ?? 0; } @@ -264,7 +259,7 @@ public ControlUnderCursorProvider() Generator = new CancellableGenerator(CreateControlUnderCursorGenerator); } - public event TableDataChangedEventHandler DataChanged; + public event TableDataChangedEventHandler? DataChanged; public CancellableGenerator Generator { get; }