Files
crystall-punk-14/Content.Client/Verbs/UI/VerbMenuElement.cs

79 lines
2.7 KiB
C#
Raw Permalink Normal View History

using System.Numerics;
using Content.Client.ContextMenu.UI;
using Content.Shared.Verbs;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
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 sealed partial class VerbMenuElement : ContextMenuElement
{
2022-01-13 06:28:17 -08:00
public const string StyleClassVerbMenuConfirmationTexture = "verbMenuConfirmationTexture";
// 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
2022-10-04 14:24:19 +11:00
public readonly Verb? Verb;
public VerbMenuElement(Verb verb) : base(verb.Text)
{
ToolTip = verb.Message;
Disabled = verb.Disabled;
Verb = verb;
2022-01-13 06:28:17 -08:00
Label.SetOnlyStyleClass(verb.TextStyleClass);
// There are no confirmations in debug fam.
#if !DEBUG
2022-01-13 06:28:17 -08:00
if (verb.ConfirmationPopup)
{
ExpansionIndicator.SetOnlyStyleClass(StyleClassVerbMenuConfirmationTexture);
ExpansionIndicator.Visible = true;
}
#endif
2022-10-04 14:24:19 +11:00
var entManager = IoCManager.Resolve<IEntityManager>();
2022-02-24 23:48:53 +13:00
if (verb.Icon == null && verb.IconEntity != null)
{
var spriteView = new SpriteView()
{
OverrideDirection = Direction.South,
SetSize = new Vector2(ElementHeight, ElementHeight),
2022-02-24 23:48:53 +13:00
};
spriteView.SetEntity(entManager.GetEntity(verb.IconEntity.Value));
2022-02-24 23:48:53 +13:00
Icon.AddChild(spriteView);
return;
}
Icon.AddChild(new TextureRect()
{
2022-10-04 14:24:19 +11:00
Texture = verb.Icon != null ? entManager.System<SpriteSystem>().Frame0(verb.Icon) : null,
Stretch = TextureRect.StretchMode.KeepAspectCentered
});
}
public VerbMenuElement(VerbCategory category, string styleClass) : base(category.Text)
{
Label.SetOnlyStyleClass(styleClass);
Icon.AddChild(new TextureRect()
{
2022-10-04 14:24:19 +11:00
Texture = category.Icon != null ? IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>().Frame0(category.Icon) : null,
Stretch = TextureRect.StretchMode.KeepAspectCentered
});
}
}
}