using Content.Shared.IdentityManagement;
using Robust.Client.GameObjects;
using Robust.Client.Player;
-using Robust.Client.UserInterface.Controls;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Maths;
-using Robust.Shared.Utility;
namespace Content.Client.ContextMenu.UI
{
public sealed partial class EntityMenuElement : ContextMenuElement
{
- public const string StyleClassEntityMenuCountText = "contextMenuCount";
-
[Dependency] private readonly IClientAdminManager _adminManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
/// <summary>
/// How many entities are accessible through this element's sub-menus.
/// </summary>
- /// <remarks>
- /// This is used for <see cref="CountLabel"/>
- /// </remarks>
- public int Count;
-
- public readonly Label CountLabel;
- public readonly SpriteView EntityIcon = new() { OverrideDirection = Direction.South};
+ public int Count { get; private set; }
public EntityMenuElement(EntityUid? entity = null)
{
_adminSystem = _entityManager.System<AdminSystem>();
- CountLabel = new Label { StyleClasses = { StyleClassEntityMenuCountText } };
- Icon.AddChild(new LayoutContainer() { Children = { EntityIcon, CountLabel } });
-
- LayoutContainer.SetAnchorPreset(CountLabel, LayoutContainer.LayoutPreset.BottomRight);
- LayoutContainer.SetGrowHorizontal(CountLabel, LayoutContainer.GrowDirection.Begin);
- LayoutContainer.SetGrowVertical(CountLabel, LayoutContainer.GrowDirection.Begin);
-
Entity = entity;
if (Entity == null)
return;
Count = 1;
- CountLabel.Visible = false;
UpdateEntity();
}
Count = 0;
}
+ private string? SearchPlayerName(EntityUid entity)
+ {
+ return _adminSystem.PlayerList.FirstOrDefault(player => player.EntityUid == entity)?.Username;
+ }
+
+ /// <summary>
+ /// Update the entity count
+ /// </summary>
+ public void UpdateCount()
+ {
+ if (SubMenu == null)
+ return;
+
+ Count = 0;
+ foreach (var subElement in SubMenu.MenuBody.Children)
+ {
+ if (subElement is EntityMenuElement entityElement)
+ Count += entityElement.Count;
+ }
+
+ IconLabel.Visible = Count > 1;
+ if (IconLabel.Visible)
+ IconLabel.Text = Count.ToString();
+ }
+
+ private string GetEntityDescriptionAdmin(EntityUid entity)
+ {
+ var representation = _entityManager.ToPrettyString(entity);
+
+ var name = representation.Name;
+ var id = representation.Uid;
+ var prototype = representation.Prototype;
+ var playerName = representation.Session?.Name ?? SearchPlayerName(entity);
+ var deleted = representation.Deleted;
+
+ return $"{name} ({id}{(prototype != null ? $", {prototype}" : "")}{(playerName != null ? $", {playerName}" : "")}){(deleted ? "D" : "")}";
+ }
+
+ private string GetEntityDescription(EntityUid entity)
+ {
+ if (_adminManager.HasFlag(AdminFlags.Admin | AdminFlags.Debug))
+ {
+ return GetEntityDescriptionAdmin(entity);
+ }
+
+ return Identity.Name(entity, _entityManager, _playerManager.LocalPlayer!.ControlledEntity!);
+ }
+
/// <summary>
/// Update the icon and text of this element based on the given entity or this element's own entity if none
/// is provided.
// _entityManager.Deleted() implicitly checks all of these.
if (_entityManager.Deleted(entity))
{
+ Icon.Sprite = null;
Text = string.Empty;
- EntityIcon.Sprite = null;
- return;
}
-
- EntityIcon.Sprite = _entityManager.GetComponentOrNull<SpriteComponent>(entity);
-
- if (_adminManager.HasFlag(AdminFlags.Admin | AdminFlags.Debug))
+ else
{
- var representation = _entityManager.ToPrettyString(entity.Value);
- var name = representation.Name;
- var id = representation.Uid;
- var prototype = representation.Prototype;
- var playerName =
- representation.Session?.Name ??
- _adminSystem.PlayerList.FirstOrDefault(player => player.EntityUid == entity)?.Username;
- var deleted = representation.Deleted;
-
- Text = $"{name} ({id}{(representation.Prototype != null ? $", {prototype}" : "")}{(playerName != null ? $", {playerName}" : "")}){(deleted ? "D" : "")}";
+ Icon.Sprite = _entityManager.GetComponentOrNull<SpriteComponent>(entity);
+ Text = GetEntityDescription(entity.Value);
}
- else
- Text = Identity.Name(entity.Value, _entityManager, _playerManager.LocalPlayer!.ControlledEntity!);
}
}
}
using Content.Client.Verbs;
using Content.Client.Verbs.UI;
using Content.Shared.CCVar;
-using Content.Shared.CombatMode;
using Content.Shared.Examine;
using Content.Shared.Input;
using Robust.Client.GameObjects;
}
element.UpdateEntity(entity);
-
- // Update the entity count & count label
- element.Count = 0;
- foreach (var subElement in element.SubMenu.MenuBody.Children)
- {
- if (subElement is EntityMenuElement entityElement)
- element.Count += entityElement.Count;
- }
- element.CountLabel.Text = element.Count.ToString();
+ element.UpdateCount();
if (element.Count == 1)
{
element.Entity = entity;
element.SubMenu.Dispose();
element.SubMenu = null;
- element.CountLabel.Visible = false;
Elements[entity.Value] = element;
}