diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/FateTableWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/FateTableWidget.cs index b36a7836c..77c05cb46 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/FateTableWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/FateTableWidget.cs @@ -1,4 +1,7 @@ -using Dalamud.Game.ClientState.Fates; +using Dalamud.Game.ClientState.Fates; +using Dalamud.Interface.Textures.Internal; +using Dalamud.Interface.Utility; +using Dalamud.Interface.Utility.Raii; using ImGuiNET; @@ -9,8 +12,6 @@ namespace Dalamud.Interface.Internal.Windows.Data.Widgets; /// internal class FateTableWidget : IDataWindowWidget { - private bool resolveGameData; - /// public string[]? CommandShortcuts { get; init; } = { "fate", "fatetable" }; @@ -29,44 +30,154 @@ internal class FateTableWidget : IDataWindowWidget /// public void Draw() { - ImGui.Checkbox("Resolve GameData", ref this.resolveGameData); - var fateTable = Service.Get(); + var textureManager = Service.Get(); - var stateString = string.Empty; if (fateTable.Length == 0) { ImGui.TextUnformatted("No fates or data not ready."); + return; } - else + + using var table = ImRaii.Table("FateTable", 13, ImGuiTableFlags.ScrollY | ImGuiTableFlags.RowBg | ImGuiTableFlags.Borders | ImGuiTableFlags.NoSavedSettings); + if (!table) return; + + ImGui.TableSetupColumn("Index", ImGuiTableColumnFlags.WidthFixed, 40); + ImGui.TableSetupColumn("Address", ImGuiTableColumnFlags.WidthFixed, 120); + ImGui.TableSetupColumn("FateId", ImGuiTableColumnFlags.WidthFixed, 40); + ImGui.TableSetupColumn("State", ImGuiTableColumnFlags.WidthFixed, 80); + ImGui.TableSetupColumn("Level", ImGuiTableColumnFlags.WidthFixed, 50); + ImGui.TableSetupColumn("Icon", ImGuiTableColumnFlags.WidthFixed, 30); + ImGui.TableSetupColumn("MapIcon", ImGuiTableColumnFlags.WidthFixed, 30); + ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.WidthStretch); + ImGui.TableSetupColumn("Progress", ImGuiTableColumnFlags.WidthFixed, 55); + ImGui.TableSetupColumn("Duration", ImGuiTableColumnFlags.WidthFixed, 80); + ImGui.TableSetupColumn("Bonus", ImGuiTableColumnFlags.WidthFixed, 40); + ImGui.TableSetupColumn("Position", ImGuiTableColumnFlags.WidthFixed, 240); + ImGui.TableSetupColumn("Radius", ImGuiTableColumnFlags.WidthFixed, 40); + ImGui.TableSetupScrollFreeze(7, 1); + ImGui.TableHeadersRow(); + + for (var i = 0; i < fateTable.Length; i++) { - stateString += $"FateTableLen: {fateTable.Length}\n"; + var fate = fateTable[i]; + if (fate == null) + continue; - ImGui.TextUnformatted(stateString); + ImGui.TableNextRow(); + ImGui.TableNextColumn(); // Index + ImGui.TextUnformatted($"#{i}"); - for (var i = 0; i < fateTable.Length; i++) + ImGui.TableNextColumn(); // Address + DrawCopyableText($"0x{fate.Address:X}", "Click to copy Address"); + + ImGui.TableNextColumn(); // FateId + DrawCopyableText(fate.FateId.ToString(), "Click to copy FateId (RowId of Fate sheet)"); + + ImGui.TableNextColumn(); // State + ImGui.TextUnformatted(fate.State.ToString()); + + ImGui.TableNextColumn(); // Level + + if (fate.Level == fate.MaxLevel) { - var fate = fateTable[i]; - if (fate == null) - continue; + ImGui.TextUnformatted($"{fate.Level}"); + } + else + { + ImGui.TextUnformatted($"{fate.Level}-{fate.MaxLevel}"); + } - var fateString = $"{fate.Address.ToInt64():X}:[{i}]" + - $" - Lv.{fate.Level} {fate.Name} ({fate.Progress}%)" + - $" - X{fate.Position.X} Y{fate.Position.Y} Z{fate.Position.Z}" + - $" - Territory {(this.resolveGameData ? (fate.TerritoryType.GameData?.Name ?? fate.TerritoryType.Id.ToString()) : fate.TerritoryType.Id.ToString())}\n"; + ImGui.TableNextColumn(); // Icon - fateString += $" StartTimeEpoch: {fate.StartTimeEpoch}" + - $" - Duration: {fate.Duration}" + - $" - State: {fate.State}" + - $" - GameData name: {(this.resolveGameData ? (fate.GameData.Name ?? fate.FateId.ToString()) : fate.FateId.ToString())}"; - - ImGui.TextUnformatted(fateString); - ImGui.SameLine(); - if (ImGui.Button($"C##{fate.Address.ToInt64():X}")) + if (fate.IconId != 0) + { + if (textureManager.Shared.GetFromGameIcon(fate.IconId).TryGetWrap(out var texture, out _)) { - ImGui.SetClipboardText(fate.Address.ToString("X")); + ImGui.Image(texture.ImGuiHandle, new(ImGui.GetTextLineHeight())); + + if (ImGui.IsItemHovered()) + { + ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); + ImGui.BeginTooltip(); + ImGui.TextUnformatted("Click to copy IconId"); + ImGui.TextUnformatted($"ID: {fate.IconId} – Size: {texture.Width}x{texture.Height}"); + ImGui.Image(texture.ImGuiHandle, new(texture.Width, texture.Height)); + ImGui.EndTooltip(); + } + + if (ImGui.IsItemClicked()) + { + ImGui.SetClipboardText(fate.IconId.ToString()); + } } } + + ImGui.TableNextColumn(); // MapIconId + + if (fate.MapIconId != 0) + { + if (textureManager.Shared.GetFromGameIcon(fate.MapIconId).TryGetWrap(out var texture, out _)) + { + ImGui.Image(texture.ImGuiHandle, new(ImGui.GetTextLineHeight())); + + if (ImGui.IsItemHovered()) + { + ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); + ImGui.BeginTooltip(); + ImGui.TextUnformatted("Click to copy MapIconId"); + ImGui.TextUnformatted($"ID: {fate.MapIconId} – Size: {texture.Width}x{texture.Height}"); + ImGui.Image(texture.ImGuiHandle, new(texture.Width, texture.Height)); + ImGui.EndTooltip(); + } + + if (ImGui.IsItemClicked()) + { + ImGui.SetClipboardText(fate.MapIconId.ToString()); + } + } + } + + ImGui.TableNextColumn(); // Name + + DrawCopyableText(fate.Name.ToString(), "Click to copy Name"); + + ImGui.TableNextColumn(); // Progress + ImGui.TextUnformatted($"{fate.Progress}%"); + + ImGui.TableNextColumn(); // TimeRemaining + + if (fate.State == FateState.Running) + { + ImGui.TextUnformatted($"{TimeSpan.FromSeconds(fate.TimeRemaining):mm\\:ss} / {TimeSpan.FromSeconds(fate.Duration):mm\\:ss}"); + } + + ImGui.TableNextColumn(); // HasExpBonus + ImGui.TextUnformatted(fate.HasExpBonus.ToString()); + + ImGui.TableNextColumn(); // Position + DrawCopyableText(fate.Position.ToString(), "Click to copy Position"); + + ImGui.TableNextColumn(); // Radius + DrawCopyableText(fate.Radius.ToString(), "Click to copy Radius"); + } + } + + private static void DrawCopyableText(string text, string tooltipText) + { + ImGuiHelpers.SafeTextWrapped(text); + + if (ImGui.IsItemHovered()) + { + ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); + ImGui.BeginTooltip(); + ImGui.TextUnformatted(tooltipText); + ImGui.EndTooltip(); + } + + if (ImGui.IsItemClicked()) + { + ImGui.SetClipboardText(text); } } }