mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-21 15:27:51 +01:00
Move some stuff to shared things, improve some filesystem rename handling.
This commit is contained in:
parent
8ea6893fc3
commit
00bc17c57a
11 changed files with 67 additions and 136 deletions
|
|
@ -2,7 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Dalamud.Game.ClientState.Objects.Enums;
|
||||
using ImGuiNET;
|
||||
using OtterGui.Raii;
|
||||
using OtterGui.Custom;
|
||||
using Penumbra.Collections;
|
||||
using Penumbra.Collections.Manager;
|
||||
using Penumbra.Communication;
|
||||
|
|
@ -63,22 +63,8 @@ public class IndividualAssignmentUi : IDisposable
|
|||
|
||||
public void DrawObjectKindCombo(float width)
|
||||
{
|
||||
if (!_ready)
|
||||
return;
|
||||
|
||||
ImGui.SetNextItemWidth(width);
|
||||
using var combo = ImRaii.Combo("##newKind", _newKind.ToName());
|
||||
if (!combo)
|
||||
return;
|
||||
|
||||
foreach (var kind in ObjectKinds)
|
||||
{
|
||||
if (!ImGui.Selectable(kind.ToName(), _newKind == kind))
|
||||
continue;
|
||||
|
||||
_newKind = kind;
|
||||
if (_ready && IndividualHelpers.DrawObjectKindCombo(width, _newKind, out _newKind, ObjectKinds))
|
||||
UpdateIdentifiersInternal();
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawNewPlayerCollection(float width)
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using OtterGui.Widgets;
|
||||
|
||||
namespace Penumbra.UI.CollectionTab;
|
||||
|
||||
public sealed class NpcCombo : FilterComboCache<(string Name, uint[] Ids)>
|
||||
{
|
||||
private readonly string _label;
|
||||
|
||||
public NpcCombo(string label, IReadOnlyDictionary<uint, string> names)
|
||||
: base(() => names.GroupBy(kvp => kvp.Value).Select(g => (g.Key, g.Select(g => g.Key).ToArray())).OrderBy(g => g.Key, Comparer)
|
||||
.ToList())
|
||||
=> _label = label;
|
||||
|
||||
protected override string ToString((string Name, uint[] Ids) obj)
|
||||
=> obj.Name;
|
||||
|
||||
protected override bool DrawSelectable(int globalIdx, bool selected)
|
||||
{
|
||||
var (name, ids) = Items[globalIdx];
|
||||
var ret = ImGui.Selectable(name, selected);
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(string.Join('\n', ids.Select(i => i.ToString())));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool Draw(float width)
|
||||
=> Draw(_label, CurrentSelection.Name, string.Empty, width, ImGui.GetTextLineHeightWithSpacing());
|
||||
|
||||
|
||||
/// <summary> Compare strings in a way that letters and numbers are sorted before any special symbols. </summary>
|
||||
private class NameComparer : IComparer<string>
|
||||
{
|
||||
public int Compare(string? x, string? y)
|
||||
{
|
||||
if (x.IsNullOrEmpty() || y.IsNullOrEmpty())
|
||||
return StringComparer.OrdinalIgnoreCase.Compare(x, y);
|
||||
|
||||
return (char.IsAsciiLetterOrDigit(x[0]), char.IsAsciiLetterOrDigit(y[0])) switch
|
||||
{
|
||||
(true, false) => -1,
|
||||
(false, true) => 1,
|
||||
_ => StringComparer.OrdinalIgnoreCase.Compare(x, y),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly NameComparer Comparer = new();
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ImGuiNET;
|
||||
using OtterGui.Widgets;
|
||||
|
||||
namespace Penumbra.UI.CollectionTab;
|
||||
|
||||
public sealed class WorldCombo : FilterComboCache<KeyValuePair<ushort, string>>
|
||||
{
|
||||
private static readonly KeyValuePair<ushort, string> AllWorldPair = new(ushort.MaxValue, "Any World");
|
||||
|
||||
public WorldCombo(IReadOnlyDictionary<ushort, string> worlds)
|
||||
: base(worlds.OrderBy(kvp => kvp.Value).Prepend(AllWorldPair))
|
||||
{
|
||||
CurrentSelection = AllWorldPair;
|
||||
CurrentSelectionIdx = 0;
|
||||
}
|
||||
|
||||
protected override string ToString(KeyValuePair<ushort, string> obj)
|
||||
=> obj.Value;
|
||||
|
||||
public bool Draw(float width)
|
||||
=> Draw("##worldCombo", CurrentSelection.Value, string.Empty, width, ImGui.GetTextLineHeightWithSpacing());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue