From 7a94c4ee0758a11f6b7c35f5f773bd8bf1e1548c Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 16 Oct 2023 15:05:17 +0200 Subject: [PATCH] Improve unlocks table. --- Glamourer/Gui/DesignQuickBar.cs | 2 +- Glamourer/Gui/Tabs/UnlocksTab/UnlockTable.cs | 119 ++++++------------- Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs | 12 ++ Penumbra.GameData | 2 +- 4 files changed, 49 insertions(+), 86 deletions(-) diff --git a/Glamourer/Gui/DesignQuickBar.cs b/Glamourer/Gui/DesignQuickBar.cs index 3a0fe3f..b47c810 100644 --- a/Glamourer/Gui/DesignQuickBar.cs +++ b/Glamourer/Gui/DesignQuickBar.cs @@ -184,7 +184,7 @@ public class DesignQuickBar : Window, IDisposable if (available == 0) tooltip = "Neither player character nor target are available, have state modified by Glamourer, or their state is locked."; - var (clicked, id, data, state) = ResolveTarget(FontAwesomeIcon.RedoAlt, buttonSize, tooltip, available); + var (clicked, id, data, state) = ResolveTarget(FontAwesomeIcon.UndoAlt, buttonSize, tooltip, available); if (clicked) _stateManager.ResetState(state!, StateChanged.Source.Manual); } diff --git a/Glamourer/Gui/Tabs/UnlocksTab/UnlockTable.cs b/Glamourer/Gui/Tabs/UnlocksTab/UnlockTable.cs index 5ccd037..5ac087f 100644 --- a/Glamourer/Gui/Tabs/UnlocksTab/UnlockTable.cs +++ b/Glamourer/Gui/Tabs/UnlocksTab/UnlockTable.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; using Dalamud.Game.Text.SeStringHandling; -using Dalamud.Interface; using Dalamud.Interface.Utility; using Glamourer.Events; using Glamourer.Interop; @@ -35,7 +34,7 @@ public class UnlockTable : Table, IDisposable new ItemIdColumn() { Label = "Item Id..." }, new ModelDataColumn(items) { Label = "Model Data..." }, new JobColumn(jobs) { Label = "Jobs" }, - new LevelColumn() { Label = "Level..." }, + new RequiredLevelColumn() { Label = "Level..." }, new DyableColumn() { Label = "Dye" }, new CrestColumn() { Label = "Crest" }, new TradableColumn() { Label = "Trade" } @@ -43,14 +42,14 @@ public class UnlockTable : Table, IDisposable { _event = @event; Sortable = true; - Flags |= ImGuiTableFlags.Hideable; + Flags |= ImGuiTableFlags.Hideable | ImGuiTableFlags.Reorderable | ImGuiTableFlags.Resizable; _event.Subscribe(OnObjectUnlock, ObjectUnlocked.Priority.UnlockTable); } public void Dispose() => _event.Unsubscribe(OnObjectUnlock); - private sealed class FavoriteColumn : YesNoColumn + private sealed class FavoriteColumn : YesNoColumn { public override float Width => ImGui.GetFrameHeightWithSpacing(); @@ -60,8 +59,9 @@ public class UnlockTable : Table, IDisposable public FavoriteColumn(FavoriteManager favorites, ObjectUnlocked hackEvent) { - _favorites = favorites; - _hackEvent = hackEvent; + _favorites = favorites; + _hackEvent = hackEvent; + Flags |= ImGuiTableColumnFlags.NoResize; } protected override bool GetValue(EquipItem item) @@ -145,8 +145,9 @@ public class UnlockTable : Table, IDisposable public SlotColumn() { - AllFlags = Values.Aggregate((a, b) => a | b); - _filterValue = AllFlags; + Flags &= ~ImGuiTableColumnFlags.NoResize; + AllFlags = Values.Aggregate((a, b) => a | b); + _filterValue = AllFlags; } public override void DrawColumn(EquipItem item, int idx) @@ -225,7 +226,10 @@ public class UnlockTable : Table, IDisposable => 110 * ImGuiHelpers.GlobalScale; public UnlockDateColumn(ItemUnlockManager unlocks) - => _unlocks = unlocks; + { + _unlocks = unlocks; + Flags &= ~ImGuiTableColumnFlags.NoResize; + } public override void DrawColumn(EquipItem item, int idx) { @@ -245,22 +249,17 @@ public class UnlockTable : Table, IDisposable } } - private sealed class ItemIdColumn : ColumnString + private sealed class ItemIdColumn : ColumnNumber { public override float Width => 70 * ImGuiHelpers.GlobalScale; - public override int Compare(EquipItem lhs, EquipItem rhs) - => lhs.ItemId.Id.CompareTo(rhs.ItemId.Id); + public override int ToValue(EquipItem item) + => (int) item.Id.Id; - public override string ToName(EquipItem item) - => item.ItemId.ToString(); - - public override void DrawColumn(EquipItem item, int _) - { - ImGui.AlignTextToFramePadding(); - ImGuiUtil.RightAlign(item.ItemId.ToString()); - } + public ItemIdColumn() + : base(ComparisonMethod.Equal) + { } } private sealed class ModelDataColumn : ColumnString @@ -287,7 +286,7 @@ public class UnlockTable : Table, IDisposable } public override int Compare(EquipItem lhs, EquipItem rhs) - => lhs.Weapon().Value.CompareTo(rhs.Weapon().Value); + => lhs.Weapon().CompareTo(rhs.Weapon()); public override bool FilterFunc(EquipItem item) { @@ -306,7 +305,7 @@ public class UnlockTable : Table, IDisposable } } - private sealed class LevelColumn : ColumnString + private sealed class RequiredLevelColumn : ColumnNumber { public override float Width => 70 * ImGuiHelpers.GlobalScale; @@ -314,11 +313,12 @@ public class UnlockTable : Table, IDisposable public override string ToName(EquipItem item) => item.Level.ToString(); - public override void DrawColumn(EquipItem item, int _) - => ImGuiUtil.RightAlign(item.Level.Value.ToString()); + public override int ToValue(EquipItem item) + => item.Level.Value; - public override int Compare(EquipItem lhs, EquipItem rhs) - => lhs.Level.Value.CompareTo(rhs.Level.Value); + public RequiredLevelColumn() + : base(ComparisonMethod.LessEqual) + { } } @@ -338,11 +338,12 @@ public class UnlockTable : Table, IDisposable public JobColumn(JobService jobs) { - _jobs = jobs; - _values = _jobs.Jobs.Values.Skip(1).Select(j => j.Flag).ToArray(); - _names = _jobs.Jobs.Values.Skip(1).Select(j => j.Abbreviation).ToArray(); - AllFlags = _values.Aggregate((l, r) => l | r); - _filterValue = AllFlags; + _jobs = jobs; + _values = _jobs.Jobs.Values.Skip(1).Select(j => j.Flag).ToArray(); + _names = _jobs.Jobs.Values.Skip(1).Select(j => j.Abbreviation).ToArray(); + AllFlags = _values.Aggregate((l, r) => l | r); + _filterValue = AllFlags; + Flags &= ~ImGuiTableColumnFlags.NoResize; } protected override void SetValue(JobFlag value, bool enable) @@ -383,57 +384,7 @@ public class UnlockTable : Table, IDisposable } } - [Flags] - private enum YesNoFlag - { - Yes = 0x01, - No = 0x02, - }; - - private class YesNoColumn : ColumnFlags - { - public string Tooltip = string.Empty; - - private YesNoFlag _filterValue; - - public override YesNoFlag FilterValue - => _filterValue; - - public YesNoColumn() - { - AllFlags = YesNoFlag.Yes | YesNoFlag.No; - _filterValue = AllFlags; - } - - protected override void SetValue(YesNoFlag value, bool enable) - => _filterValue = enable ? _filterValue | value : _filterValue & ~value; - - protected virtual bool GetValue(EquipItem item) - => false; - - public override float Width - => ImGui.GetFrameHeight() * 2; - - public override bool FilterFunc(EquipItem item) - => GetValue(item) - ? FilterValue.HasFlag(YesNoFlag.Yes) - : FilterValue.HasFlag(YesNoFlag.No); - - public override int Compare(EquipItem lhs, EquipItem rhs) - => GetValue(lhs).CompareTo(GetValue(rhs)); - - public override void DrawColumn(EquipItem item, int idx) - { - using (var font = ImRaii.PushFont(UiBuilder.IconFont)) - { - ImGuiUtil.Center(GetValue(item) ? FontAwesomeIcon.Check.ToIconString() : FontAwesomeIcon.Times.ToIconString()); - } - - ImGuiUtil.HoverTooltip(Tooltip); - } - } - - private sealed class DyableColumn : YesNoColumn + private sealed class DyableColumn : YesNoColumn { public DyableColumn() => Tooltip = "Whether the item is dyable."; @@ -442,7 +393,7 @@ public class UnlockTable : Table, IDisposable => item.Flags.HasFlag(ItemFlags.IsDyable); } - private sealed class TradableColumn : YesNoColumn + private sealed class TradableColumn : YesNoColumn { public TradableColumn() => Tooltip = "Whether the item is tradable."; @@ -451,7 +402,7 @@ public class UnlockTable : Table, IDisposable => item.Flags.HasFlag(ItemFlags.IsTradable); } - private sealed class CrestColumn : YesNoColumn + private sealed class CrestColumn : YesNoColumn { public CrestColumn() => Tooltip = "Whether a crest can be applied to the item.."; diff --git a/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs b/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs index 75f180f..30f7ad3 100644 --- a/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs +++ b/Glamourer/Gui/Tabs/UnlocksTab/UnlocksTab.cs @@ -50,6 +50,7 @@ public class UnlocksTab : Window, ITab _table.Draw(ImGui.GetFrameHeightWithSpacing()); else _overview.Draw(); + _table.Flags |= ImGuiTableFlags.Resizable; } public override void Draw() @@ -64,6 +65,8 @@ public class UnlocksTab : Window, ITab var buttonSize = new Vector2(ImGui.GetContentRegionAvail().X / 2, ImGui.GetFrameHeight()); if (!IsOpen) buttonSize.X -= ImGui.GetFrameHeight() / 2; + if (DetailMode) + buttonSize.X -= ImGui.GetFrameHeight() / 2; if (ImGuiUtil.DrawDisabledButton("Overview Mode", buttonSize, "Show tinted icons of sets of unlocks.", !DetailMode)) DetailMode = false; @@ -72,6 +75,15 @@ public class UnlocksTab : Window, ITab if (ImGuiUtil.DrawDisabledButton("Detailed Mode", buttonSize, "Show all unlockable data as a combined filterable and sortable table.", DetailMode)) DetailMode = true; + + if (DetailMode) + { + ImGui.SameLine(); + if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Expand.ToIconString(), new Vector2(ImGui.GetFrameHeight()), + "Restore all columns to their original size.", false, true)) + _table.Flags &= ~ImGuiTableFlags.Resizable; + } + if (!IsOpen) { ImGui.SameLine(); diff --git a/Penumbra.GameData b/Penumbra.GameData index 0c0554e..6a0daf2 160000 --- a/Penumbra.GameData +++ b/Penumbra.GameData @@ -1 +1 @@ -Subproject commit 0c0554e7c482fac35110c3375e890540ee31abb3 +Subproject commit 6a0daf2f309c27c5a260825bce31094987fce3d1