fix: internal TSM entries must always come first

This commit is contained in:
goat 2023-08-23 21:51:46 +02:00
parent d2e463247c
commit 3c8e474fe5
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 22 additions and 10 deletions

View file

@ -97,16 +97,17 @@ internal class TitleScreenMenuWindow : Window, IDisposable
public override void Draw() public override void Draw()
{ {
var scale = ImGui.GetIO().FontGlobalScale; var scale = ImGui.GetIO().FontGlobalScale;
var entries = Service<TitleScreenMenu>.Get().Entries
var tsm = Service<TitleScreenMenu>.Get(); .OrderByDescending(x => x.IsInternal)
.ToList();
switch (this.state) switch (this.state)
{ {
case State.Show: case State.Show:
{ {
for (var i = 0; i < tsm.Entries.Count; i++) for (var i = 0; i < entries.Count; i++)
{ {
var entry = tsm.Entries[i]; var entry = entries[i];
if (!this.moveEasings.TryGetValue(entry.Id, out var moveEasing)) if (!this.moveEasings.TryGetValue(entry.Id, out var moveEasing))
{ {
@ -172,9 +173,9 @@ internal class TitleScreenMenuWindow : Window, IDisposable
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value)) using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value))
{ {
for (var i = 0; i < tsm.Entries.Count; i++) for (var i = 0; i < entries.Count; i++)
{ {
var entry = tsm.Entries[i]; var entry = entries[i];
var finalPos = (i + 1) * this.shadeTexture.Height * scale; var finalPos = (i + 1) * this.shadeTexture.Height * scale;
@ -205,7 +206,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
case State.Hide: case State.Hide:
{ {
if (this.DrawEntry(tsm.Entries[0], true, false, true, true, false)) if (this.DrawEntry(entries[0], true, false, true, true, false))
{ {
this.state = State.Show; this.state = State.Show;
} }
@ -217,7 +218,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
} }
} }
var srcText = tsm.Entries.Select(e => e.Name).ToHashSet(); var srcText = entries.Select(e => e.Name).ToHashSet();
var keys = this.specialGlyphRequests.Keys.ToHashSet(); var keys = this.specialGlyphRequests.Keys.ToHashSet();
keys.RemoveWhere(x => srcText.Contains(x)); keys.RemoveWhere(x => srcText.Contains(x));
foreach (var key in keys) foreach (var key in keys)

View file

@ -121,7 +121,10 @@ public class TitleScreenMenu : IServiceType
lock (this.entries) lock (this.entries)
{ {
var entry = new TitleScreenMenuEntry(null, priority, text, texture, onTriggered); var entry = new TitleScreenMenuEntry(null, priority, text, texture, onTriggered)
{
IsInternal = true,
};
this.entries.Add(entry); this.entries.Add(entry);
return entry; return entry;
} }
@ -148,7 +151,10 @@ public class TitleScreenMenu : IServiceType
var priority = entriesOfAssembly.Any() var priority = entriesOfAssembly.Any()
? unchecked(entriesOfAssembly.Select(x => x.Priority).Max() + 1) ? unchecked(entriesOfAssembly.Select(x => x.Priority).Max() + 1)
: 0; : 0;
var entry = new TitleScreenMenuEntry(null, priority, text, texture, onTriggered); var entry = new TitleScreenMenuEntry(null, priority, text, texture, onTriggered)
{
IsInternal = true,
};
this.entries.Add(entry); this.entries.Add(entry);
return entry; return entry;
} }
@ -192,6 +198,11 @@ public class TitleScreenMenu : IServiceType
/// Gets or sets the texture of this entry. /// Gets or sets the texture of this entry.
/// </summary> /// </summary>
public TextureWrap Texture { get; set; } public TextureWrap Texture { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not this entry is internal.
/// </summary>
internal bool IsInternal { get; set; }
/// <summary> /// <summary>
/// Gets the calling assembly of this entry. /// Gets the calling assembly of this entry.