Fix objects tab not showing nents (#23837)
* Fix objects tab not showing nents * Fix everything
This commit is contained in:
@@ -3,6 +3,7 @@ using Robust.Client.AutoGenerated;
|
|||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Client.Administration.UI.Tabs.ObjectsTab;
|
namespace Content.Client.Administration.UI.Tabs.ObjectsTab;
|
||||||
|
|
||||||
@@ -10,12 +11,20 @@ namespace Content.Client.Administration.UI.Tabs.ObjectsTab;
|
|||||||
public sealed partial class ObjectsTab : Control
|
public sealed partial class ObjectsTab : Control
|
||||||
{
|
{
|
||||||
[Dependency] private readonly EntityManager _entityManager = default!;
|
[Dependency] private readonly EntityManager _entityManager = default!;
|
||||||
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
|
||||||
private readonly List<ObjectsTabEntry> _objects = new();
|
private readonly List<ObjectsTabEntry> _objects = new();
|
||||||
private List<ObjectsTabSelection> _selections = new();
|
private List<ObjectsTabSelection> _selections = new();
|
||||||
|
|
||||||
public event Action<ObjectsTabEntry, GUIBoundKeyEventArgs>? OnEntryKeyBindDown;
|
public event Action<ObjectsTabEntry, GUIBoundKeyEventArgs>? OnEntryKeyBindDown;
|
||||||
|
|
||||||
|
// Listen I could either have like 4 different event subscribers (for map / grid / station changes) and manage their lifetimes in AdminUIController
|
||||||
|
// OR
|
||||||
|
// I can do this.
|
||||||
|
private TimeSpan _updateFrequency = TimeSpan.FromSeconds(2);
|
||||||
|
|
||||||
|
private TimeSpan _nextUpdate = TimeSpan.FromSeconds(2);
|
||||||
|
|
||||||
public ObjectsTab()
|
public ObjectsTab()
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
@@ -33,12 +42,17 @@ public sealed partial class ObjectsTab : Control
|
|||||||
ObjectTypeOptions.AddItem(Enum.GetName((ObjectsTabSelection)type)!);
|
ObjectTypeOptions.AddItem(Enum.GetName((ObjectsTabSelection)type)!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefreshObjectList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshObjectList()
|
||||||
|
{
|
||||||
RefreshObjectList(_selections[ObjectTypeOptions.SelectedId]);
|
RefreshObjectList(_selections[ObjectTypeOptions.SelectedId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshObjectList(ObjectsTabSelection selection)
|
private void RefreshObjectList(ObjectsTabSelection selection)
|
||||||
{
|
{
|
||||||
var entities = new List<EntityUid>();
|
var entities = new List<(string Name, NetEntity Entity)>();
|
||||||
switch (selection)
|
switch (selection)
|
||||||
{
|
{
|
||||||
case ObjectsTabSelection.Stations:
|
case ObjectsTabSelection.Stations:
|
||||||
@@ -46,20 +60,20 @@ public sealed partial class ObjectsTab : Control
|
|||||||
break;
|
break;
|
||||||
case ObjectsTabSelection.Grids:
|
case ObjectsTabSelection.Grids:
|
||||||
{
|
{
|
||||||
var query = _entityManager.AllEntityQueryEnumerator<MapGridComponent>();
|
var query = _entityManager.AllEntityQueryEnumerator<MapGridComponent, MetaDataComponent>();
|
||||||
while (query.MoveNext(out var uid, out _))
|
while (query.MoveNext(out var uid, out _, out var metadata))
|
||||||
{
|
{
|
||||||
entities.Add(uid);
|
entities.Add((metadata.EntityName, _entityManager.GetNetEntity(uid)));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ObjectsTabSelection.Maps:
|
case ObjectsTabSelection.Maps:
|
||||||
{
|
{
|
||||||
var query = _entityManager.AllEntityQueryEnumerator<MapComponent>();
|
var query = _entityManager.AllEntityQueryEnumerator<MapComponent, MetaDataComponent>();
|
||||||
while (query.MoveNext(out var uid, out _))
|
while (query.MoveNext(out var uid, out _, out var metadata))
|
||||||
{
|
{
|
||||||
entities.Add(uid);
|
entities.Add((metadata.EntityName, _entityManager.GetNetEntity(uid)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -74,17 +88,28 @@ public sealed partial class ObjectsTab : Control
|
|||||||
|
|
||||||
_objects.Clear();
|
_objects.Clear();
|
||||||
|
|
||||||
foreach (var entity in entities)
|
foreach (var (name, nent) in entities)
|
||||||
{
|
{
|
||||||
// TODO the server eitehr needs to send the entity's name, or it needs to ensure the client knows about the entity.
|
var ctrl = new ObjectsTabEntry(name, nent);
|
||||||
var name = _entityManager.GetComponentOrNull<MetaDataComponent>(entity)?.EntityName ?? "Unknown Entity"; // this should be fixed, so I CBF localizing.
|
|
||||||
var ctrl = new ObjectsTabEntry(name, entity);
|
|
||||||
_objects.Add(ctrl);
|
_objects.Add(ctrl);
|
||||||
ObjectList.AddChild(ctrl);
|
ObjectList.AddChild(ctrl);
|
||||||
ctrl.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(ctrl, args);
|
ctrl.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(ctrl, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void FrameUpdate(FrameEventArgs args)
|
||||||
|
{
|
||||||
|
base.FrameUpdate(args);
|
||||||
|
|
||||||
|
if (_timing.CurTime < _nextUpdate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// I do not care for precision.
|
||||||
|
_nextUpdate = _timing.CurTime + _updateFrequency;
|
||||||
|
|
||||||
|
RefreshObjectList();
|
||||||
|
}
|
||||||
|
|
||||||
private enum ObjectsTabSelection
|
private enum ObjectsTabSelection
|
||||||
{
|
{
|
||||||
Grids,
|
Grids,
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ namespace Content.Client.Administration.UI.Tabs.ObjectsTab;
|
|||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class ObjectsTabEntry : ContainerButton
|
public sealed partial class ObjectsTabEntry : ContainerButton
|
||||||
{
|
{
|
||||||
public EntityUid AssocEntity;
|
public NetEntity AssocEntity;
|
||||||
|
|
||||||
public ObjectsTabEntry(string name, EntityUid euid)
|
public ObjectsTabEntry(string name, NetEntity nent)
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
AssocEntity = euid;
|
AssocEntity = nent;
|
||||||
EIDLabel.Text = euid.ToString();
|
EIDLabel.Text = nent.ToString();
|
||||||
NameLabel.Text = name;
|
NameLabel.Text = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ namespace Content.Client.Station;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class StationSystem : EntitySystem
|
public sealed class StationSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
private readonly List<(string Name, NetEntity Entity)> _stations = new();
|
||||||
private readonly HashSet<EntityUid> _stations = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All stations that currently exist.
|
/// All stations that currently exist.
|
||||||
@@ -16,7 +15,7 @@ public sealed class StationSystem : EntitySystem
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// I'd have this just invoke an entity query, but we're on the client and the client barely knows about stations.
|
/// I'd have this just invoke an entity query, but we're on the client and the client barely knows about stations.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public IReadOnlySet<EntityUid> Stations => _stations;
|
public IReadOnlyList<(string Name, NetEntity Entity)> Stations => _stations;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -27,7 +26,7 @@ public sealed class StationSystem : EntitySystem
|
|||||||
private void StationsUpdated(StationsUpdatedEvent ev)
|
private void StationsUpdated(StationsUpdatedEvent ev)
|
||||||
{
|
{
|
||||||
_stations.Clear();
|
_stations.Clear();
|
||||||
// TODO this needs to be dona in component states and with the Ensure() methods
|
// TODO this needs to be done in component states and with the Ensure() methods
|
||||||
_stations.UnionWith(GetEntitySet(ev.Stations));
|
_stations.AddRange(ev.Stations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ using static Robust.Client.UserInterface.Controls.BaseButton;
|
|||||||
namespace Content.Client.UserInterface.Systems.Admin;
|
namespace Content.Client.UserInterface.Systems.Admin;
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class AdminUIController : UIController, IOnStateEntered<GameplayState>, IOnStateEntered<LobbyState>, IOnSystemChanged<AdminSystem>
|
public sealed class AdminUIController : UIController,
|
||||||
|
IOnStateEntered<GameplayState>,
|
||||||
|
IOnStateEntered<LobbyState>,
|
||||||
|
IOnSystemChanged<AdminSystem>
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IClientAdminManager _admin = default!;
|
[Dependency] private readonly IClientAdminManager _admin = default!;
|
||||||
[Dependency] private readonly IClientConGroupController _conGroups = default!;
|
[Dependency] private readonly IClientConGroupController _conGroups = default!;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public sealed class StationSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (e.NewStatus == SessionStatus.Connected)
|
if (e.NewStatus == SessionStatus.Connected)
|
||||||
{
|
{
|
||||||
RaiseNetworkEvent(new StationsUpdatedEvent(GetNetEntitySet(GetStationsSet())), e.Session);
|
RaiseNetworkEvent(new StationsUpdatedEvent(GetStationNames()), e.Session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ public sealed class StationSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnStationAdd(EntityUid uid, StationDataComponent component, ComponentStartup args)
|
private void OnStationAdd(EntityUid uid, StationDataComponent component, ComponentStartup args)
|
||||||
{
|
{
|
||||||
RaiseNetworkEvent(new StationsUpdatedEvent(GetNetEntitySet(GetStationsSet())), Filter.Broadcast());
|
RaiseNetworkEvent(new StationsUpdatedEvent(GetStationNames()), Filter.Broadcast());
|
||||||
|
|
||||||
var metaData = MetaData(uid);
|
var metaData = MetaData(uid);
|
||||||
RaiseLocalEvent(new StationInitializedEvent(uid));
|
RaiseLocalEvent(new StationInitializedEvent(uid));
|
||||||
@@ -108,7 +108,7 @@ public sealed class StationSystem : EntitySystem
|
|||||||
RemComp<StationMemberComponent>(grid);
|
RemComp<StationMemberComponent>(grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
RaiseNetworkEvent(new StationsUpdatedEvent(GetNetEntitySet(GetStationsSet())), Filter.Broadcast());
|
RaiseNetworkEvent(new StationsUpdatedEvent(GetStationNames()), Filter.Broadcast());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPreGameMapLoad(PreGameMapLoad ev)
|
private void OnPreGameMapLoad(PreGameMapLoad ev)
|
||||||
@@ -468,6 +468,19 @@ public sealed class StationSystem : EntitySystem
|
|||||||
return stations;
|
return stations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<(string Name, NetEntity Entity)> GetStationNames()
|
||||||
|
{
|
||||||
|
var stations = GetStationsSet();
|
||||||
|
var stats = new List<(string Name, NetEntity Station)>();
|
||||||
|
|
||||||
|
foreach (var weh in stations)
|
||||||
|
{
|
||||||
|
stats.Add((MetaData(weh).EntityName, GetNetEntity(weh)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the first station that has a grid in a certain map.
|
/// Returns the first station that has a grid in a certain map.
|
||||||
/// If the map has no stations, null is returned instead.
|
/// If the map has no stations, null is returned instead.
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ namespace Content.Shared.Station;
|
|||||||
[NetSerializable, Serializable]
|
[NetSerializable, Serializable]
|
||||||
public sealed class StationsUpdatedEvent : EntityEventArgs
|
public sealed class StationsUpdatedEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public readonly HashSet<NetEntity> Stations;
|
public readonly List<(string Name, NetEntity Entity)> Stations;
|
||||||
|
|
||||||
public StationsUpdatedEvent(HashSet<NetEntity> stations)
|
public StationsUpdatedEvent(List<(string Name, NetEntity Entity)> stations)
|
||||||
{
|
{
|
||||||
Stations = stations;
|
Stations = stations;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user