Files
tbd-station-14/Content.Client/ContextMenu/UI/EntityMenuElement.cs
Leon Friedrich 49296e33a0 Refactor Context Menus and make them use XAML & stylesheets (#4768)
* XAML verb menu

* fix ghost FOV

* spacing

* rename missed "ContextMenu"->"EntityMenu" instances

* move visibility checks to verb system

* update comment

* Remove CanSeeContainerCheck

* use ScrollContainer measure option

* MaxWidth / texxt line wrapping

* verb category default

Now when you click on a verb category, it should default to running the first member of that category.

This makes it much more convenient to eject/insert when there is only a single option

* only apply style to first verb category entry

* Use new visibility flags

* FoV -> Fov

* Revert "only apply style to first verb category entry"

This reverts commit 9a6a17dba600e3ae0421caed59fcab145c260c99.

* make all entity menu visibility checks clientside

* Fix empty unbuckle category

* fix merge
2021-10-27 22:21:19 -07:00

71 lines
2.3 KiB
C#

using Content.Client.Stylesheets;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
namespace Content.Client.ContextMenu.UI
{
public partial class EntityMenuElement : ContextMenuElement
{
public const string StyleClassEntityMenuCountText = "contextMenuCount";
/// <summary>
/// The entity that can be accessed by interacting with this element.
/// </summary>
public IEntity? Entity;
/// <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 Label CountLabel;
public SpriteView EntityIcon = new SpriteView { OverrideDirection = Direction.South};
public EntityMenuElement(IEntity? entity = null) : base()
{
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)
{
Count = 1;
CountLabel.Visible = false;
UpdateEntity();
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Entity = null;
Count = 0;
}
/// <summary>
/// Update the icon and text of this element based on the given entity or this element's own entity if none
/// is provided.
/// </summary>
public void UpdateEntity(IEntity? entity = null)
{
entity ??= Entity;
EntityIcon.Sprite = entity?.GetComponentOrNull<ISpriteComponent>();
if (UserInterfaceManager.DebugMonitors.Visible)
Text = $"{entity?.Name} ({entity?.Uid})";
else
Text = entity?.Name ?? string.Empty;
}
}
}