using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.ContextMenu.UI
{
public partial class EntityMenuElement : ContextMenuElement
{
public const string StyleClassEntityMenuCountText = "contextMenuCount";
///
/// The entity that can be accessed by interacting with this element.
///
public EntityUid Entity;
///
/// How many entities are accessible through this element's sub-menus.
///
///
/// This is used for
///
public int Count;
public readonly Label CountLabel;
public readonly SpriteView EntityIcon = new() { OverrideDirection = Direction.South};
public EntityMenuElement(EntityUid entity = default)
{
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 != default)
{
Count = 1;
CountLabel.Visible = false;
UpdateEntity();
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Entity = default;
Count = 0;
}
///
/// Update the icon and text of this element based on the given entity or this element's own entity if none
/// is provided.
///
public void UpdateEntity(EntityUid entity = default)
{
if (Entity != default && IoCManager.Resolve().EntityExists(Entity) && !entity.Valid)
entity = Entity;
if (entity == default)
{
Text = string.Empty;
return;
}
EntityIcon.Sprite = IoCManager.Resolve().GetComponentOrNull(entity);
if (UserInterfaceManager.DebugMonitors.Visible)
Text = $"{IoCManager.Resolve().GetComponent(entity!).EntityName} ({entity})";
else
Text = IoCManager.Resolve().GetComponent(entity!).EntityName;
}
}
}