mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-13 12:14:18 +01:00
Fix WeaponCombo missing favorite.
This commit is contained in:
parent
9a52dddba3
commit
43d683ac66
2 changed files with 34 additions and 22 deletions
|
|
@ -49,12 +49,12 @@ public class EquipmentDrawer
|
||||||
foreach (var type in Enum.GetValues<FullEquipType>())
|
foreach (var type in Enum.GetValues<FullEquipType>())
|
||||||
{
|
{
|
||||||
if (type.ToSlot() is EquipSlot.MainHand)
|
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)
|
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;
|
private Vector2 _iconSize;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Glamourer.Services;
|
using Glamourer.Services;
|
||||||
|
using Glamourer.Unlocks;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using OtterGui;
|
using OtterGui;
|
||||||
using OtterGui.Classes;
|
using OtterGui.Classes;
|
||||||
|
|
@ -12,13 +13,15 @@ namespace Glamourer.Gui.Equipment;
|
||||||
|
|
||||||
public sealed class WeaponCombo : FilterComboCache<EquipItem>
|
public sealed class WeaponCombo : FilterComboCache<EquipItem>
|
||||||
{
|
{
|
||||||
public readonly string Label;
|
private readonly FavoriteManager _favorites;
|
||||||
private ItemId _currentItemId;
|
public readonly string Label;
|
||||||
private float _innerWidth;
|
private ItemId _currentItem;
|
||||||
|
private float _innerWidth;
|
||||||
|
|
||||||
public WeaponCombo(ItemManager items, FullEquipType type, Logger log)
|
public WeaponCombo(ItemManager items, FullEquipType type, Logger log, FavoriteManager favorites)
|
||||||
: base(() => GetWeapons(items, type), MouseWheelType.Control, log)
|
: base(() => GetWeapons(favorites, items, type), MouseWheelType.Control, log)
|
||||||
{
|
{
|
||||||
|
_favorites = favorites;
|
||||||
Label = GetLabel(type);
|
Label = GetLabel(type);
|
||||||
SearchByParts = true;
|
SearchByParts = true;
|
||||||
}
|
}
|
||||||
|
|
@ -32,29 +35,38 @@ public sealed class WeaponCombo : FilterComboCache<EquipItem>
|
||||||
|
|
||||||
protected override int UpdateCurrentSelected(int currentSelected)
|
protected override int UpdateCurrentSelected(int currentSelected)
|
||||||
{
|
{
|
||||||
if (CurrentSelection.ItemId == _currentItemId)
|
if (CurrentSelection.ItemId == _currentItem)
|
||||||
return currentSelected;
|
return currentSelected;
|
||||||
|
|
||||||
CurrentSelectionIdx = Items.IndexOf(i => i.ItemId == _currentItemId);
|
CurrentSelectionIdx = Items.IndexOf(i => i.ItemId == _currentItem);
|
||||||
CurrentSelection = CurrentSelectionIdx >= 0 ? Items[CurrentSelectionIdx] : default;
|
CurrentSelection = CurrentSelectionIdx >= 0 ? Items[CurrentSelectionIdx] : default;
|
||||||
return base.UpdateCurrentSelected(CurrentSelectionIdx);
|
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()
|
protected override float GetFilterWidth()
|
||||||
=> _innerWidth - 2 * ImGui.GetStyle().FramePadding.X;
|
=> _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)
|
protected override bool DrawSelectable(int globalIdx, bool selected)
|
||||||
{
|
{
|
||||||
var obj = Items[globalIdx];
|
var obj = Items[globalIdx];
|
||||||
var name = ToString(obj);
|
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();
|
ImGui.SameLine();
|
||||||
using var color = ImRaii.PushColor(ImGuiCol.Text, 0xFF808080);
|
using var color = ImRaii.PushColor(ImGuiCol.Text, 0xFF808080);
|
||||||
ImGuiUtil.RightAlign($"({obj.PrimaryId.Id}-{obj.SecondaryId.Id}-{obj.Variant})");
|
ImGuiUtil.RightAlign($"({obj.PrimaryId.Id}-{obj.SecondaryId.Id}-{obj.Variant})");
|
||||||
|
|
@ -70,7 +82,7 @@ public sealed class WeaponCombo : FilterComboCache<EquipItem>
|
||||||
private static string GetLabel(FullEquipType type)
|
private static string GetLabel(FullEquipType type)
|
||||||
=> type is FullEquipType.Unknown ? "Mainhand" : type.ToName();
|
=> type is FullEquipType.Unknown ? "Mainhand" : type.ToName();
|
||||||
|
|
||||||
private static IReadOnlyList<EquipItem> GetWeapons(ItemManager items, FullEquipType type)
|
private static IReadOnlyList<EquipItem> GetWeapons(FavoriteManager favorites, ItemManager items, FullEquipType type)
|
||||||
{
|
{
|
||||||
if (type is FullEquipType.Unknown)
|
if (type is FullEquipType.Unknown)
|
||||||
{
|
{
|
||||||
|
|
@ -81,15 +93,15 @@ public sealed class WeaponCombo : FilterComboCache<EquipItem>
|
||||||
enumerable = enumerable.Concat(l);
|
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))
|
if (!items.ItemData.ByType.TryGetValue(type, out var list))
|
||||||
return Array.Empty<EquipItem>();
|
return [];
|
||||||
|
|
||||||
if (type.AllowsNothing())
|
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)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue