don't implicitly depend on DataManager in data widget load functions

This commit is contained in:
goat 2024-12-26 17:16:19 +01:00
parent f3d7c6f2ea
commit 10f4009a0c
3 changed files with 35 additions and 16 deletions

View file

@ -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
{
}
}

View file

@ -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<byte> testStringBuffer;
private string testString = string.Empty;
private ExcelSheet<Addon> 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<DataManager>.Get().GetExcelSheet<Addon>();
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<DataManager>.GetNullable()?.GetExcelSheet<Addon>() ??
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);

View file

@ -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;
/// </summary>
internal class UiColorWidget : IDataWindowWidget
{
private ExcelSheet<UIColor> colors;
/// <inheritdoc/>
public string[]? CommandShortcuts { get; init; } = ["uicolor"];
@ -37,12 +31,14 @@ internal class UiColorWidget : IDataWindowWidget
public void Load()
{
this.Ready = true;
this.colors = Service<DataManager>.Get().GetExcelSheet<UIColor>();
}
/// <inheritdoc/>
public unsafe void Draw()
{
var colors = Service<DataManager>.GetNullable()?.GetExcelSheet<UIColor>()
?? throw new InvalidOperationException("UIColor sheet not loaded.");
Service<SeStringRenderer>.Get().CompileAndDrawWrapped(
"· Color notation is #" +
"<edgecolor(0xFFEEEE)><color(0xFF0000)>RR<color(stackcolor)><edgecolor(stackcolor)>" +
@ -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;