From 10f4009a0c03be9e165f90e14811bda2e6972733 Mon Sep 17 00:00:00 2001 From: goat Date: Thu, 26 Dec 2024 17:16:19 +0100 Subject: [PATCH] don't implicitly depend on DataManager in data widget load functions --- .../Internal/Asserts/RenderScopes.cs | 23 +++++++++++++++++++ .../Widgets/SeStringRendererTestWidget.cs | 10 ++++---- .../Windows/Data/Widgets/UIColorWidget.cs | 18 ++++++--------- 3 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 Dalamud/Interface/Internal/Asserts/RenderScopes.cs diff --git a/Dalamud/Interface/Internal/Asserts/RenderScopes.cs b/Dalamud/Interface/Internal/Asserts/RenderScopes.cs new file mode 100644 index 000000000..1e0448e87 --- /dev/null +++ b/Dalamud/Interface/Internal/Asserts/RenderScopes.cs @@ -0,0 +1,23 @@ +using System.Diagnostics; + +namespace Dalamud.Interface.Internal.Asserts; + +public static class RenderScopes +{ + private static RenderScopeFrame currentFrame = new(); + private static RenderScopeFrame lastFrame = new(); + + public static RenderScopeFrame GetLastFrame() => lastFrame; + + public static RenderScopeFrame GetCurrentFrame() => currentFrame; + + public static void NewFrame() + { + //Debug.Assert(currentFrame.IsRoot, "NewFrame() but we didn't pop all the way to ."); + } + + public class RenderScopeFrame + { + + } +} diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringRendererTestWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringRendererTestWidget.cs index 5afda62ac..323c9ce62 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringRendererTestWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringRendererTestWidget.cs @@ -15,7 +15,6 @@ using FFXIVClientStructs.FFXIV.Component.GUI; using ImGuiNET; -using Lumina.Excel; using Lumina.Excel.Sheets; using Lumina.Text; using Lumina.Text.Payloads; @@ -31,7 +30,6 @@ internal unsafe class SeStringRendererTestWidget : IDataWindowWidget private static readonly string[] ThemeNames = ["Dark", "Light", "Classic FF", "Clear Blue"]; private ImVectorWrapper testStringBuffer; private string testString = string.Empty; - private ExcelSheet addons = null!; private ReadOnlySeString? logkind; private SeStringDrawParams style; private bool interactable; @@ -51,7 +49,6 @@ internal unsafe class SeStringRendererTestWidget : IDataWindowWidget public void Load() { this.style = new() { GetEntity = this.GetEntity }; - this.addons = Service.Get().GetExcelSheet(); this.logkind = null; this.testString = string.Empty; this.interactable = this.useEntity = true; @@ -193,13 +190,16 @@ internal unsafe class SeStringRendererTestWidget : IDataWindowWidget ImGui.CalcTextSize("AAAAAAAAAAAAAAAAA").X); ImGui.TableHeadersRow(); + var addon = Service.GetNullable()?.GetExcelSheet() ?? + throw new InvalidOperationException("Addon sheet not loaded."); + var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); - clipper.Begin(this.addons.Count); + clipper.Begin(addon.Count); while (clipper.Step()) { for (var i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { - var row = this.addons.GetRowAt(i); + var row = addon.GetRowAt(i); ImGui.TableNextRow(); ImGui.PushID(i); diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/UIColorWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/UIColorWidget.cs index 6b57f7a6a..d43ae50a3 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/UIColorWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/UIColorWidget.cs @@ -1,5 +1,4 @@ using System.Buffers.Binary; -using System.Linq; using System.Numerics; using System.Text; @@ -7,12 +6,9 @@ using Dalamud.Data; using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification.Internal; using Dalamud.Interface.ImGuiSeStringRenderer.Internal; -using Dalamud.Interface.Utility; -using Dalamud.Storage.Assets; using ImGuiNET; -using Lumina.Excel; using Lumina.Excel.Sheets; namespace Dalamud.Interface.Internal.Windows.Data.Widgets; @@ -22,8 +18,6 @@ namespace Dalamud.Interface.Internal.Windows.Data.Widgets; /// internal class UiColorWidget : IDataWindowWidget { - private ExcelSheet colors; - /// public string[]? CommandShortcuts { get; init; } = ["uicolor"]; @@ -37,12 +31,14 @@ internal class UiColorWidget : IDataWindowWidget public void Load() { this.Ready = true; - this.colors = Service.Get().GetExcelSheet(); } /// public unsafe void Draw() { + var colors = Service.GetNullable()?.GetExcelSheet() + ?? throw new InvalidOperationException("UIColor sheet not loaded."); + Service.Get().CompileAndDrawWrapped( "· Color notation is #" + "RR" + @@ -71,16 +67,16 @@ internal class UiColorWidget : IDataWindowWidget ImGui.TableHeadersRow(); var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); - clipper.Begin(this.colors.Count, ImGui.GetFrameHeightWithSpacing()); + clipper.Begin(colors.Count, ImGui.GetFrameHeightWithSpacing()); while (clipper.Step()) { for (var i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { - var row = this.colors.GetRowAt(i); + var row = colors.GetRowAt(i); UIColor? adjacentRow = null; - if (i + 1 < this.colors.Count) + if (i + 1 < colors.Count) { - var adjRow = this.colors.GetRowAt(i + 1); + var adjRow = colors.GetRowAt(i + 1); if (adjRow.RowId == row.RowId + 1) { adjacentRow = adjRow;