Fix Admin Object tab sorting and search - Part 2 (#28681)
* admin Object tab sorting and searchable * Fix for showing disconnected players on player admin tab * Fix namespace and search bar location. * Change linq to loop. * No more Linq to sort * Fix item click vv menu * Added refresh button and refresh on opening tab. * Clear spaces. * Move tab magic numbers to enums * Get rid of old unused xaml * Fix code style issues and button event type. * Merge in baby jail * More style cleanup and move cast around. * Make the localization a little more easy to read, same loc var names. * Missed Loc for label * Fix class field order * Over zelous delete. * Small updates. * Min syntax issues fix
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Client.UserInterface.Controls;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -15,17 +16,14 @@ public sealed partial class ObjectsTab : Control
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private readonly List<ObjectsTabEntry> _objects = new();
|
||||
private readonly List<ObjectsTabSelection> _selections = new();
|
||||
private bool _ascending = false; // Set to false for descending order by default
|
||||
private ObjectsTabHeader.Header _headerClicked = ObjectsTabHeader.Header.ObjectName;
|
||||
private readonly Color _altColor = Color.FromHex("#292B38");
|
||||
private readonly Color _defaultColor = Color.FromHex("#2F2F3B");
|
||||
|
||||
public event Action<GUIBoundKeyEventArgs, ListData>? OnEntryKeyBindDown;
|
||||
private bool _ascending;
|
||||
private ObjectsTabHeader.Header _headerClicked = ObjectsTabHeader.Header.ObjectName;
|
||||
|
||||
private readonly TimeSpan _updateFrequency = TimeSpan.FromSeconds(2);
|
||||
private TimeSpan _nextUpdate;
|
||||
private readonly List<ObjectsTabSelection> _selections = [];
|
||||
public event Action<GUIBoundKeyEventArgs, ListData>? OnEntryKeyBindDown;
|
||||
|
||||
public ObjectsTab()
|
||||
{
|
||||
@@ -38,40 +36,25 @@ public sealed partial class ObjectsTab : Control
|
||||
RefreshObjectList(_selections[ev.Id]);
|
||||
};
|
||||
|
||||
foreach (var type in Enum.GetValues(typeof(ObjectsTabSelection)))
|
||||
foreach (var type in Enum.GetValues<ObjectsTabSelection>())
|
||||
{
|
||||
_selections.Add((ObjectsTabSelection)type!);
|
||||
ObjectTypeOptions.AddItem(Loc.GetString($"object-tab-object-type-{((Enum.GetName((ObjectsTabSelection)type))!.ToString().ToLower())}"));
|
||||
_selections.Add(type);
|
||||
ObjectTypeOptions.AddItem(GetLocalizedEnumValue(type));
|
||||
}
|
||||
|
||||
ListHeader.OnHeaderClicked += HeaderClicked;
|
||||
SearchList.SearchBar = SearchLineEdit;
|
||||
SearchList.GenerateItem += GenerateButton;
|
||||
SearchList.DataFilterCondition += DataFilterCondition;
|
||||
SearchList.ItemKeyBindDown += (args, data) => OnEntryKeyBindDown?.Invoke(args, data);
|
||||
RefreshListButton.OnPressed += _ => RefreshObjectList();
|
||||
|
||||
RefreshObjectList();
|
||||
// Set initial selection and refresh the list to apply the initial sort order
|
||||
var defaultSelection = ObjectsTabSelection.Grids;
|
||||
ObjectTypeOptions.SelectId((int)defaultSelection); // Set the default selection
|
||||
RefreshObjectList(defaultSelection); // Refresh the list with the default selection
|
||||
|
||||
// Initialize the next update time
|
||||
_nextUpdate = TimeSpan.Zero;
|
||||
ObjectTypeOptions.SelectId((int) defaultSelection);
|
||||
RefreshObjectList(defaultSelection);
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
if (_timing.CurTime < _nextUpdate)
|
||||
return;
|
||||
|
||||
_nextUpdate = _timing.CurTime + _updateFrequency;
|
||||
|
||||
RefreshObjectList();
|
||||
}
|
||||
|
||||
private void RefreshObjectList()
|
||||
public void RefreshObjectList()
|
||||
{
|
||||
RefreshObjectList(_selections[ObjectTypeOptions.SelectedId]);
|
||||
}
|
||||
@@ -101,6 +84,7 @@ public sealed partial class ObjectsTab : Control
|
||||
{
|
||||
entities.Add((metadata.EntityName, _entityManager.GetNetEntity(uid)));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -111,14 +95,18 @@ public sealed partial class ObjectsTab : Control
|
||||
{
|
||||
var valueA = GetComparableValue(a, _headerClicked);
|
||||
var valueB = GetComparableValue(b, _headerClicked);
|
||||
return _ascending ? Comparer<object>.Default.Compare(valueA, valueB) : Comparer<object>.Default.Compare(valueB, valueA);
|
||||
return _ascending
|
||||
? Comparer<object>.Default.Compare(valueA, valueB)
|
||||
: Comparer<object>.Default.Compare(valueB, valueA);
|
||||
});
|
||||
|
||||
var listData = new List<ObjectsListData>();
|
||||
for (int index = 0; index < entities.Count; index++)
|
||||
for (var index = 0; index < entities.Count; index++)
|
||||
{
|
||||
var info = entities[index];
|
||||
listData.Add(new ObjectsListData(info, $"{info.Name} {info.Entity}", index % 2 == 0 ? _altColor : _defaultColor));
|
||||
listData.Add(new ObjectsListData(info,
|
||||
$"{info.Name} {info.Entity}",
|
||||
index % 2 == 0 ? _altColor : _defaultColor));
|
||||
}
|
||||
|
||||
SearchList.PopulateList(listData);
|
||||
@@ -129,10 +117,11 @@ public sealed partial class ObjectsTab : Control
|
||||
if (data is not ObjectsListData { Info: var info, BackgroundColor: var backgroundColor })
|
||||
return;
|
||||
|
||||
var entry = new ObjectsTabEntry(info.Name, info.Entity, new StyleBoxFlat { BackgroundColor = backgroundColor });
|
||||
var entry = new ObjectsTabEntry(info.Name,
|
||||
info.Entity,
|
||||
new StyleBoxFlat { BackgroundColor = backgroundColor });
|
||||
button.ToolTip = $"{info.Name}, {info.Entity}";
|
||||
|
||||
button.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(args, data);
|
||||
button.AddChild(entry);
|
||||
}
|
||||
|
||||
@@ -154,7 +143,7 @@ public sealed partial class ObjectsTab : Control
|
||||
{
|
||||
ObjectsTabHeader.Header.ObjectName => entity.Name,
|
||||
ObjectsTabHeader.Header.EntityID => entity.Entity.ToString(),
|
||||
_ => entity.Name
|
||||
_ => entity.Name,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -174,6 +163,17 @@ public sealed partial class ObjectsTab : Control
|
||||
RefreshObjectList();
|
||||
}
|
||||
|
||||
private string GetLocalizedEnumValue(ObjectsTabSelection selection)
|
||||
{
|
||||
return selection switch
|
||||
{
|
||||
ObjectsTabSelection.Grids => Loc.GetString("object-tab-object-type-grids"),
|
||||
ObjectsTabSelection.Maps => Loc.GetString("object-tab-object-type-maps"),
|
||||
ObjectsTabSelection.Stations => Loc.GetString("object-tab-object-type-stations"),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(selection), selection, null),
|
||||
};
|
||||
}
|
||||
|
||||
private enum ObjectsTabSelection
|
||||
{
|
||||
Grids,
|
||||
@@ -182,4 +182,5 @@ public sealed partial class ObjectsTab : Control
|
||||
}
|
||||
}
|
||||
|
||||
public record ObjectsListData((string Name, NetEntity Entity) Info, string FilteringString, Color BackgroundColor) : ListData;
|
||||
public record ObjectsListData((string Name, NetEntity Entity) Info, string FilteringString, Color BackgroundColor)
|
||||
: ListData;
|
||||
|
||||
Reference in New Issue
Block a user