mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
fix(DtrBar): fix ordering
This commit is contained in:
parent
095e7c3037
commit
badc73c3aa
1 changed files with 12 additions and 14 deletions
|
|
@ -48,10 +48,14 @@ namespace Dalamud.Game.Gui.Dtr
|
||||||
if (this.entries.Any(x => x.Title == title))
|
if (this.entries.Any(x => x.Title == title))
|
||||||
throw new ArgumentException("An entry with the same title already exists.");
|
throw new ArgumentException("An entry with the same title already exists.");
|
||||||
|
|
||||||
|
var configuration = Service<DalamudConfiguration>.Get();
|
||||||
var node = this.MakeNode(++this.runningNodeIds);
|
var node = this.MakeNode(++this.runningNodeIds);
|
||||||
var entry = new DtrBarEntry(title, node);
|
var entry = new DtrBarEntry(title, node);
|
||||||
entry.Text = text;
|
entry.Text = text;
|
||||||
|
|
||||||
|
// Add the entry to the end of the order list, if it's not there already.
|
||||||
|
if (!configuration.DtrOrder!.Contains(title))
|
||||||
|
configuration.DtrOrder!.Add(title);
|
||||||
this.entries.Add(entry);
|
this.entries.Add(entry);
|
||||||
this.ApplySort();
|
this.ApplySort();
|
||||||
|
|
||||||
|
|
@ -98,22 +102,16 @@ namespace Dalamud.Game.Gui.Dtr
|
||||||
var configuration = Service<DalamudConfiguration>.Get();
|
var configuration = Service<DalamudConfiguration>.Get();
|
||||||
|
|
||||||
// Sort the current entry list, based on the order in the configuration.
|
// Sort the current entry list, based on the order in the configuration.
|
||||||
var ordered = configuration.DtrOrder.Select(entry => this.entries.FirstOrDefault(x => x.Title == entry)).Where(value => value != null).ToList();
|
var positions = configuration.DtrOrder!
|
||||||
|
.Select(entry => (entry, index: configuration.DtrOrder!.IndexOf(entry)))
|
||||||
|
.ToDictionary(x => x.entry, x => x.index);
|
||||||
|
|
||||||
// Add entries that weren't sorted to the end of the list.
|
this.entries.Sort((x, y) =>
|
||||||
if (ordered.Count != this.entries.Count)
|
|
||||||
{
|
{
|
||||||
ordered.AddRange(this.entries.Where(x => ordered.All(y => y.Title != x.Title)));
|
var xPos = positions.TryGetValue(x.Title, out var xIndex) ? xIndex : int.MaxValue;
|
||||||
}
|
var yPos = positions.TryGetValue(y.Title, out var yIndex) ? yIndex : int.MaxValue;
|
||||||
|
return xPos.CompareTo(yPos);
|
||||||
// Update the order list for new entries.
|
});
|
||||||
configuration.DtrOrder.Clear();
|
|
||||||
foreach (var dtrEntry in ordered)
|
|
||||||
{
|
|
||||||
configuration.DtrOrder.Add(dtrEntry.Title);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.entries = ordered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AtkUnitBase* GetDtr() => (AtkUnitBase*)Service<GameGui>.Get().GetAddonByName("_DTR", 1).ToPointer();
|
private static AtkUnitBase* GetDtr() => (AtkUnitBase*)Service<GameGui>.Get().GetAddonByName("_DTR", 1).ToPointer();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue