Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor debug window #2341

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Intersect.Client.Framework/Gwen/Control/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,14 +863,20 @@ 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))
{
Log.Warn($"Attempted to load layout for nameless {GetType().FullName}");
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 12 additions & 17 deletions Intersect.Client/Interface/Debugging/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDisposable>();

_disposables = [];
DisableResizing();

CheckboxDrawDebugOutlines = CreateCheckboxDrawDebugOutlines();
CheckboxEnableLayoutHotReloading = CreateCheckboxEnableLayoutHotReloading();
ButtonShutdownServer = CreateButtonShutdownServer();
ButtonShutdownServerAndExit = CreateButtonShutdownServerAndExit();
TableDebugStats = CreateTableDebugStats();
IsHidden = true;
}

Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -160,7 +155,7 @@ private Table CreateTableDebugStats()
ColumnCount = 2,
};

var fpsProvider = new ValueTableCellDataProvider<int>(() => Graphics.Renderer.GetFps());
var fpsProvider = new ValueTableCellDataProvider<int>(() => Graphics.Renderer?.GetFps() ?? 0);
table.AddRow(Strings.Debug.Fps).Listen(fpsProvider, 1);
_disposables.Add(fpsProvider.Generator.Start());

Expand Down Expand Up @@ -218,7 +213,7 @@ private Table CreateTableDebugStats()
table.AddRow(Strings.Debug.LightsDrawn).Listen(lightsDrawnProvider, 1);
_disposables.Add(lightsDrawnProvider.Generator.Start());

var timeProvider = new ValueTableCellDataProvider<string>(() => Time.GetTime());
var timeProvider = new ValueTableCellDataProvider<string>(Time.GetTime);
table.AddRow(Strings.Debug.Time).Listen(timeProvider, 1);
_disposables.Add(timeProvider.Generator.Start());

Expand All @@ -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;
}
Expand Down Expand Up @@ -264,7 +259,7 @@ public ControlUnderCursorProvider()
Generator = new CancellableGenerator<Base>(CreateControlUnderCursorGenerator);
}

public event TableDataChangedEventHandler DataChanged;
public event TableDataChangedEventHandler? DataChanged;

public CancellableGenerator<Base> Generator { get; }

Expand Down
Loading