From 43d683ac662aff398ea62f4d3ecd6ee17b95add6 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 9 Apr 2024 15:21:19 +0200 Subject: [PATCH] Fix WeaponCombo missing favorite. --- Glamourer/Gui/Equipment/EquipmentDrawer.cs | 6 +-- Glamourer/Gui/Equipment/WeaponCombo.cs | 50 ++++++++++++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Glamourer/Gui/Equipment/EquipmentDrawer.cs b/Glamourer/Gui/Equipment/EquipmentDrawer.cs index 53c3d3e..33c5378 100644 --- a/Glamourer/Gui/Equipment/EquipmentDrawer.cs +++ b/Glamourer/Gui/Equipment/EquipmentDrawer.cs @@ -49,12 +49,12 @@ public class EquipmentDrawer foreach (var type in Enum.GetValues()) { if (type.ToSlot() is EquipSlot.MainHand) - _weaponCombo.TryAdd(type, new WeaponCombo(items, type, Glamourer.Log)); + _weaponCombo.TryAdd(type, new WeaponCombo(items, type, Glamourer.Log, favorites)); else if (type.ToSlot() is EquipSlot.OffHand) - _weaponCombo.TryAdd(type, new WeaponCombo(items, type, Glamourer.Log)); + _weaponCombo.TryAdd(type, new WeaponCombo(items, type, Glamourer.Log, favorites)); } - _weaponCombo.Add(FullEquipType.Unknown, new WeaponCombo(items, FullEquipType.Unknown, Glamourer.Log)); + _weaponCombo.Add(FullEquipType.Unknown, new WeaponCombo(items, FullEquipType.Unknown, Glamourer.Log, favorites)); } private Vector2 _iconSize; diff --git a/Glamourer/Gui/Equipment/WeaponCombo.cs b/Glamourer/Gui/Equipment/WeaponCombo.cs index 17abb24..f6531a2 100644 --- a/Glamourer/Gui/Equipment/WeaponCombo.cs +++ b/Glamourer/Gui/Equipment/WeaponCombo.cs @@ -1,4 +1,5 @@ using Glamourer.Services; +using Glamourer.Unlocks; using ImGuiNET; using OtterGui; using OtterGui.Classes; @@ -12,13 +13,15 @@ namespace Glamourer.Gui.Equipment; public sealed class WeaponCombo : FilterComboCache { - public readonly string Label; - private ItemId _currentItemId; - private float _innerWidth; + private readonly FavoriteManager _favorites; + public readonly string Label; + private ItemId _currentItem; + private float _innerWidth; - public WeaponCombo(ItemManager items, FullEquipType type, Logger log) - : base(() => GetWeapons(items, type), MouseWheelType.Control, log) + public WeaponCombo(ItemManager items, FullEquipType type, Logger log, FavoriteManager favorites) + : base(() => GetWeapons(favorites, items, type), MouseWheelType.Control, log) { + _favorites = favorites; Label = GetLabel(type); SearchByParts = true; } @@ -32,29 +35,38 @@ public sealed class WeaponCombo : FilterComboCache protected override int UpdateCurrentSelected(int currentSelected) { - if (CurrentSelection.ItemId == _currentItemId) + if (CurrentSelection.ItemId == _currentItem) return currentSelected; - CurrentSelectionIdx = Items.IndexOf(i => i.ItemId == _currentItemId); + CurrentSelectionIdx = Items.IndexOf(i => i.ItemId == _currentItem); CurrentSelection = CurrentSelectionIdx >= 0 ? Items[CurrentSelectionIdx] : default; return base.UpdateCurrentSelected(CurrentSelectionIdx); } + public bool Draw(string previewName, ItemId previewIdx, float width, float innerWidth) + { + _innerWidth = innerWidth; + _currentItem = previewIdx; + return Draw($"##{Label}", previewName, string.Empty, width, ImGui.GetTextLineHeightWithSpacing()); + } + protected override float GetFilterWidth() => _innerWidth - 2 * ImGui.GetStyle().FramePadding.X; - public bool Draw(string previewName, ItemId previewId, float width, float innerWidth) - { - _currentItemId = previewId; - _innerWidth = innerWidth; - return Draw($"##{Label}", previewName, string.Empty, width, ImGui.GetTextLineHeightWithSpacing()); - } protected override bool DrawSelectable(int globalIdx, bool selected) { var obj = Items[globalIdx]; var name = ToString(obj); - var ret = ImGui.Selectable(name, selected); + if (UiHelpers.DrawFavoriteStar(_favorites, obj) && CurrentSelectionIdx == globalIdx) + { + CurrentSelectionIdx = -1; + _currentItem = obj.ItemId; + CurrentSelection = default; + } + + ImGui.SameLine(); + var ret = ImGui.Selectable(name, selected); ImGui.SameLine(); using var color = ImRaii.PushColor(ImGuiCol.Text, 0xFF808080); ImGuiUtil.RightAlign($"({obj.PrimaryId.Id}-{obj.SecondaryId.Id}-{obj.Variant})"); @@ -70,7 +82,7 @@ public sealed class WeaponCombo : FilterComboCache private static string GetLabel(FullEquipType type) => type is FullEquipType.Unknown ? "Mainhand" : type.ToName(); - private static IReadOnlyList GetWeapons(ItemManager items, FullEquipType type) + private static IReadOnlyList GetWeapons(FavoriteManager favorites, ItemManager items, FullEquipType type) { if (type is FullEquipType.Unknown) { @@ -81,15 +93,15 @@ public sealed class WeaponCombo : FilterComboCache enumerable = enumerable.Concat(l); } - return enumerable.OrderBy(e => e.Name).ToList(); + return [.. enumerable.OrderByDescending(favorites.Contains).ThenBy(e => e.Name)]; } if (!items.ItemData.ByType.TryGetValue(type, out var list)) - return Array.Empty(); + return []; if (type.AllowsNothing()) - return list.OrderBy(e => e.Name).Prepend(ItemManager.NothingItem(type)).ToList(); + return [ItemManager.NothingItem(type), .. list.OrderByDescending(favorites.Contains).ThenBy(e => e.Name)]; - return list.OrderBy(e => e.Name).ToList(); + return [.. list.OrderByDescending(favorites.Contains).ThenBy(e => e.Name)]; } }