Files
tbd-station-14/Content.Client/Examine/ExamineButton.cs
Killerqu00 dacf0d915c Hover examine buttons (#35206)
* hover examine verbs (not aligned to the left yet)

* handle click hovers and align them to the left

* revert contrabandsystem changes (this is for another PR)

* add support for markup tags
2025-03-22 13:22:01 +11:00

71 lines
1.8 KiB
C#

using Content.Client.ContextMenu.UI;
using Content.Client.Stylesheets;
using Content.Shared.Verbs;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.Utility;
namespace Content.Client.Examine;
/// <summary>
/// Buttons that show up in the examine tooltip to specify more detailed
/// ways to examine an item.
/// </summary>
public sealed class ExamineButton : ContainerButton
{
public const string StyleClassExamineButton = "examine-button";
public const int ElementHeight = 32;
public const int ElementWidth = 32;
private const int Thickness = 4;
public TextureRect Icon;
public ExamineVerb Verb;
public ExamineButton(ExamineVerb verb)
{
Margin = new Thickness(Thickness, Thickness, Thickness, Thickness);
SetOnlyStyleClass(StyleClassExamineButton);
Verb = verb;
if (verb.Disabled)
{
Disabled = true;
}
TooltipSupplier = sender =>
{
var label = new RichTextLabel();
label.SetMessage(FormattedMessage.FromMarkupOrThrow(verb.Message ?? verb.Text));
var tooltip = new Tooltip();
tooltip.GetChild(0).Children.Clear();
tooltip.GetChild(0).Children.Add(label);
return tooltip;
};
Icon = new TextureRect
{
SetWidth = ElementWidth,
SetHeight = ElementHeight
};
if (verb.Icon != null)
{
Icon.Texture = verb.Icon.Frame0();
Icon.Stretch = TextureRect.StretchMode.KeepAspectCentered;
AddChild(Icon);
}
}
}