Files
tbd-station-14/Content.Client/Verbs/UI/VerbMenuElement.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

70 lines
2.5 KiB
C#

using Content.Client.ContextMenu.UI;
using Content.Shared.Verbs;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Utility;
namespace Content.Client.Verbs.UI
{
/// <summary>
/// Slight extension of <see cref="ContextMenuElement"/> that uses a SpriteSpecifier for it's icon and provides
/// constructors that take verbs or verb categories.
/// </summary>
public partial class VerbMenuElement : ContextMenuElement
{
public const string StyleClassVerbInteractionText = "InteractionVerb";
public const string StyleClassVerbActivationText = "ActivationVerb";
public const string StyleClassVerbAlternativeText = "AlternativeVerb";
public const string StyleClassVerbOtherText = "OtherVerb";
public const float VerbTooltipDelay = 0.5f;
// Setters to provide access to children generated by XAML.
public bool IconVisible { set => Icon.Visible = value; }
public bool TextVisible { set => Label.Visible = value; }
// Top quality variable naming
public Verb? Verb;
public VerbType Type;
public VerbMenuElement(string? text, SpriteSpecifier? icon, VerbType verbType) : base(text)
{
Icon.AddChild(new TextureRect()
{
Texture = icon?.Frame0(),
Stretch = TextureRect.StretchMode.KeepAspectCentered
});
Type = verbType;
// Set text font style based on verb type
switch (verbType)
{
case VerbType.Interaction:
Label.SetOnlyStyleClass(StyleClassVerbInteractionText);
break;
case VerbType.Activation:
Label.SetOnlyStyleClass(StyleClassVerbActivationText);
break;
case VerbType.Alternative:
Label.SetOnlyStyleClass(StyleClassVerbAlternativeText);
break;
default:
Label.SetOnlyStyleClass(StyleClassVerbOtherText);
break;
}
}
public VerbMenuElement(Verb verb, VerbType verbType) : this(verb.Text, verb.Icon, verbType)
{
ToolTip = verb.Message;
TooltipDelay = VerbTooltipDelay;
Disabled = verb.Disabled;
Verb = verb;
}
public VerbMenuElement(VerbCategory category, VerbType verbType) : this(category.Text, category.Icon, verbType) { }
}
}