mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Scrollable Self-Test table (#2284)
This commit is contained in:
parent
e415699bb3
commit
e52e0b6df9
1 changed files with 108 additions and 78 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
|
|
@ -9,7 +10,9 @@ using Dalamud.Interface.Utility;
|
||||||
using Dalamud.Interface.Utility.Raii;
|
using Dalamud.Interface.Utility.Raii;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.Logging.Internal;
|
using Dalamud.Logging.Internal;
|
||||||
|
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.Sheets;
|
||||||
|
|
||||||
namespace Dalamud.Interface.Internal.Windows.SelfTest;
|
namespace Dalamud.Interface.Internal.Windows.SelfTest;
|
||||||
|
|
@ -61,7 +64,7 @@ internal class SelfTestWindow : Window
|
||||||
|
|
||||||
private bool selfTestRunning = false;
|
private bool selfTestRunning = false;
|
||||||
private int currentStep = 0;
|
private int currentStep = 0;
|
||||||
|
private int scrollToStep = -1;
|
||||||
private DateTimeOffset lastTestStart;
|
private DateTimeOffset lastTestStart;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -90,9 +93,10 @@ internal class SelfTestWindow : Window
|
||||||
|
|
||||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.StepForward))
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.StepForward))
|
||||||
{
|
{
|
||||||
this.testIndexToResult.Add(this.currentStep, (SelfTestStepResult.NotRan, null));
|
this.testIndexToResult[this.currentStep] = (SelfTestStepResult.NotRan, null);
|
||||||
this.steps[this.currentStep].CleanUp();
|
this.steps[this.currentStep].CleanUp();
|
||||||
this.currentStep++;
|
this.currentStep++;
|
||||||
|
this.scrollToStep = this.currentStep;
|
||||||
this.lastTestStart = DateTimeOffset.Now;
|
this.lastTestStart = DateTimeOffset.Now;
|
||||||
|
|
||||||
if (this.currentStep >= this.steps.Count)
|
if (this.currentStep >= this.steps.Count)
|
||||||
|
|
@ -107,6 +111,7 @@ internal class SelfTestWindow : Window
|
||||||
{
|
{
|
||||||
this.selfTestRunning = true;
|
this.selfTestRunning = true;
|
||||||
this.currentStep = 0;
|
this.currentStep = 0;
|
||||||
|
this.scrollToStep = this.currentStep;
|
||||||
this.testIndexToResult.Clear();
|
this.testIndexToResult.Clear();
|
||||||
this.lastTestStart = DateTimeOffset.Now;
|
this.lastTestStart = DateTimeOffset.Now;
|
||||||
}
|
}
|
||||||
|
|
@ -116,11 +121,11 @@ internal class SelfTestWindow : Window
|
||||||
|
|
||||||
ImGui.TextUnformatted($"Step: {this.currentStep} / {this.steps.Count}");
|
ImGui.TextUnformatted($"Step: {this.currentStep} / {this.steps.Count}");
|
||||||
|
|
||||||
ImGuiHelpers.ScaledDummy(10);
|
ImGui.Spacing();
|
||||||
|
|
||||||
this.DrawResultTable();
|
this.DrawResultTable();
|
||||||
|
|
||||||
ImGuiHelpers.ScaledDummy(10);
|
ImGui.Spacing();
|
||||||
|
|
||||||
if (this.currentStep >= this.steps.Count)
|
if (this.currentStep >= this.steps.Count)
|
||||||
{
|
{
|
||||||
|
|
@ -131,11 +136,11 @@ internal class SelfTestWindow : Window
|
||||||
|
|
||||||
if (this.testIndexToResult.Any(x => x.Value.Result == SelfTestStepResult.Fail))
|
if (this.testIndexToResult.Any(x => x.Value.Result == SelfTestStepResult.Fail))
|
||||||
{
|
{
|
||||||
ImGui.TextColored(ImGuiColors.DalamudRed, "One or more checks failed!");
|
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudRed, "One or more checks failed!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImGui.TextColored(ImGuiColors.HealerGreen, "All checks passed!");
|
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.HealerGreen, "All checks passed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
@ -146,8 +151,6 @@ internal class SelfTestWindow : Window
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Separator();
|
|
||||||
|
|
||||||
var step = this.steps[this.currentStep];
|
var step = this.steps[this.currentStep];
|
||||||
ImGui.TextUnformatted($"Current: {step.Name}");
|
ImGui.TextUnformatted($"Current: {step.Name}");
|
||||||
|
|
||||||
|
|
@ -164,13 +167,12 @@ internal class SelfTestWindow : Window
|
||||||
result = SelfTestStepResult.Fail;
|
result = SelfTestStepResult.Fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Separator();
|
|
||||||
|
|
||||||
if (result != SelfTestStepResult.Waiting)
|
if (result != SelfTestStepResult.Waiting)
|
||||||
{
|
{
|
||||||
var duration = DateTimeOffset.Now - this.lastTestStart;
|
var duration = DateTimeOffset.Now - this.lastTestStart;
|
||||||
this.testIndexToResult.Add(this.currentStep, (result, duration));
|
this.testIndexToResult[this.currentStep] = (result, duration);
|
||||||
this.currentStep++;
|
this.currentStep++;
|
||||||
|
this.scrollToStep = this.currentStep;
|
||||||
|
|
||||||
this.lastTestStart = DateTimeOffset.Now;
|
this.lastTestStart = DateTimeOffset.Now;
|
||||||
}
|
}
|
||||||
|
|
@ -178,90 +180,111 @@ internal class SelfTestWindow : Window
|
||||||
|
|
||||||
private void DrawResultTable()
|
private void DrawResultTable()
|
||||||
{
|
{
|
||||||
if (ImGui.BeginTable("agingResultTable", 5, ImGuiTableFlags.Borders))
|
var tableSize = ImGui.GetContentRegionAvail();
|
||||||
|
|
||||||
|
if (this.selfTestRunning)
|
||||||
|
tableSize -= new Vector2(0, 150);
|
||||||
|
|
||||||
|
tableSize.Y = Math.Min(tableSize.Y, ImGui.GetWindowViewport().Size.Y * 0.5f);
|
||||||
|
|
||||||
|
using var table = ImRaii.Table("agingResultTable", 5, ImGuiTableFlags.Borders | ImGuiTableFlags.ScrollY, tableSize);
|
||||||
|
if (!table)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ImGui.TableSetupColumn("###index", ImGuiTableColumnFlags.WidthFixed, 12f * ImGuiHelpers.GlobalScale);
|
||||||
|
ImGui.TableSetupColumn("Name");
|
||||||
|
ImGui.TableSetupColumn("Result", ImGuiTableColumnFlags.WidthFixed, 40f * ImGuiHelpers.GlobalScale);
|
||||||
|
ImGui.TableSetupColumn("Duration", ImGuiTableColumnFlags.WidthFixed, 90f * ImGuiHelpers.GlobalScale);
|
||||||
|
ImGui.TableSetupColumn(string.Empty, ImGuiTableColumnFlags.WidthFixed, 30f * ImGuiHelpers.GlobalScale);
|
||||||
|
|
||||||
|
ImGui.TableSetupScrollFreeze(0, 1);
|
||||||
|
ImGui.TableHeadersRow();
|
||||||
|
|
||||||
|
for (var i = 0; i < this.steps.Count; i++)
|
||||||
{
|
{
|
||||||
ImGui.TableSetupColumn("###index", ImGuiTableColumnFlags.WidthFixed, 12f * ImGuiHelpers.GlobalScale);
|
var step = this.steps[i];
|
||||||
ImGui.TableSetupColumn("Name");
|
ImGui.TableNextRow();
|
||||||
ImGui.TableSetupColumn("Result", ImGuiTableColumnFlags.WidthFixed, 40f * ImGuiHelpers.GlobalScale);
|
|
||||||
ImGui.TableSetupColumn("Duration", ImGuiTableColumnFlags.WidthFixed, 90f * ImGuiHelpers.GlobalScale);
|
|
||||||
ImGui.TableSetupColumn(string.Empty, ImGuiTableColumnFlags.WidthFixed, 30f * ImGuiHelpers.GlobalScale);
|
|
||||||
|
|
||||||
ImGui.TableHeadersRow();
|
if (this.selfTestRunning && this.currentStep == i)
|
||||||
|
|
||||||
for (var i = 0; i < this.steps.Count; i++)
|
|
||||||
{
|
{
|
||||||
var step = this.steps[i];
|
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg0, ImGui.GetColorU32(ImGuiCol.TableRowBgAlt));
|
||||||
ImGui.TableNextRow();
|
}
|
||||||
|
|
||||||
ImGui.TableSetColumnIndex(0);
|
ImGui.TableSetColumnIndex(0);
|
||||||
ImGui.Text(i.ToString());
|
ImGui.AlignTextToFramePadding();
|
||||||
|
ImGui.TextUnformatted(i.ToString());
|
||||||
|
|
||||||
ImGui.TableSetColumnIndex(1);
|
if (this.selfTestRunning && this.scrollToStep == i)
|
||||||
ImGui.Text(step.Name);
|
{
|
||||||
|
ImGui.SetScrollHereY();
|
||||||
|
this.scrollToStep = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.testIndexToResult.TryGetValue(i, out var result))
|
ImGui.TableSetColumnIndex(1);
|
||||||
|
ImGui.AlignTextToFramePadding();
|
||||||
|
ImGui.TextUnformatted(step.Name);
|
||||||
|
|
||||||
|
if (this.testIndexToResult.TryGetValue(i, out var result))
|
||||||
|
{
|
||||||
|
ImGui.TableSetColumnIndex(2);
|
||||||
|
ImGui.AlignTextToFramePadding();
|
||||||
|
|
||||||
|
switch (result.Result)
|
||||||
{
|
{
|
||||||
ImGui.TableSetColumnIndex(2);
|
case SelfTestStepResult.Pass:
|
||||||
ImGui.PushFont(InterfaceManager.MonoFont);
|
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.HealerGreen, "PASS");
|
||||||
|
break;
|
||||||
|
case SelfTestStepResult.Fail:
|
||||||
|
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudRed, "FAIL");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, "NR");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (result.Result)
|
ImGui.TableSetColumnIndex(3);
|
||||||
{
|
if (result.Duration.HasValue)
|
||||||
case SelfTestStepResult.Pass:
|
{
|
||||||
ImGui.TextColored(ImGuiColors.HealerGreen, "PASS");
|
ImGui.AlignTextToFramePadding();
|
||||||
break;
|
ImGui.TextUnformatted(this.FormatTimeSpan(result.Duration.Value));
|
||||||
case SelfTestStepResult.Fail:
|
}
|
||||||
ImGui.TextColored(ImGuiColors.DalamudRed, "FAIL");
|
}
|
||||||
break;
|
else
|
||||||
default:
|
{
|
||||||
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
|
ImGui.TableSetColumnIndex(2);
|
||||||
break;
|
ImGui.AlignTextToFramePadding();
|
||||||
}
|
if (this.selfTestRunning && this.currentStep == i)
|
||||||
|
{
|
||||||
ImGui.PopFont();
|
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, "WAIT");
|
||||||
|
|
||||||
ImGui.TableSetColumnIndex(3);
|
|
||||||
if (result.Duration.HasValue)
|
|
||||||
{
|
|
||||||
ImGui.TextUnformatted(result.Duration.Value.ToString("g"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImGui.TableSetColumnIndex(2);
|
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, "NR");
|
||||||
if (this.selfTestRunning && this.currentStep == i)
|
|
||||||
{
|
|
||||||
ImGui.TextColored(ImGuiColors.DalamudGrey, "WAIT");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui.TableSetColumnIndex(3);
|
|
||||||
if (this.selfTestRunning && this.currentStep == i)
|
|
||||||
{
|
|
||||||
ImGui.TextUnformatted((DateTimeOffset.Now - this.lastTestStart).ToString("g"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.TableSetColumnIndex(4);
|
ImGui.TableSetColumnIndex(3);
|
||||||
using var id = ImRaii.PushId($"selfTest{i}");
|
ImGui.AlignTextToFramePadding();
|
||||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.FastForward))
|
if (this.selfTestRunning && this.currentStep == i)
|
||||||
{
|
{
|
||||||
this.StopTests();
|
ImGui.TextUnformatted(this.FormatTimeSpan(DateTimeOffset.Now - this.lastTestStart));
|
||||||
this.testIndexToResult.Remove(i);
|
|
||||||
this.currentStep = i;
|
|
||||||
this.selfTestRunning = true;
|
|
||||||
this.lastTestStart = DateTimeOffset.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui.IsItemHovered())
|
|
||||||
{
|
|
||||||
ImGui.SetTooltip("Jump to this test");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.EndTable();
|
ImGui.TableSetColumnIndex(4);
|
||||||
|
using var id = ImRaii.PushId($"selfTest{i}");
|
||||||
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.FastForward))
|
||||||
|
{
|
||||||
|
this.StopTests();
|
||||||
|
this.testIndexToResult.Remove(i);
|
||||||
|
this.currentStep = i;
|
||||||
|
this.selfTestRunning = true;
|
||||||
|
this.lastTestStart = DateTimeOffset.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.IsItemHovered())
|
||||||
|
{
|
||||||
|
ImGui.SetTooltip("Jump to this test");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,4 +304,11 @@ internal class SelfTestWindow : Window
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string FormatTimeSpan(TimeSpan ts)
|
||||||
|
{
|
||||||
|
var str = ts.ToString("g", CultureInfo.InvariantCulture);
|
||||||
|
var commaPos = str.LastIndexOf('.');
|
||||||
|
return commaPos > -1 && commaPos + 5 < str.Length ? str[..(commaPos + 5)] : str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue