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
This commit is contained in:
Killerqu00
2025-03-22 03:22:01 +01:00
committed by GitHub
parent 4027115e0c
commit dacf0d915c
7 changed files with 82 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ using Content.Shared.Verbs;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility; using Robust.Client.Utility;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -40,7 +41,17 @@ public sealed class ExamineButton : ContainerButton
Disabled = true; Disabled = true;
} }
ToolTip = verb.Message ?? verb.Text; 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 Icon = new TextureRect
{ {

View File

@@ -298,10 +298,28 @@ namespace Content.Client.Examine
{ {
Name = "ExamineButtonsHBox", Name = "ExamineButtonsHBox",
Orientation = LayoutOrientation.Horizontal, Orientation = LayoutOrientation.Horizontal,
HorizontalAlignment = Control.HAlignment.Right, HorizontalAlignment = Control.HAlignment.Stretch,
VerticalAlignment = Control.VAlignment.Bottom, VerticalAlignment = Control.VAlignment.Bottom,
}; };
var hoverExamineBox = new BoxContainer
{
Name = "HoverExamineHBox",
Orientation = LayoutOrientation.Horizontal,
HorizontalAlignment = Control.HAlignment.Left,
VerticalAlignment = Control.VAlignment.Center,
HorizontalExpand = true
};
var clickExamineBox = new BoxContainer
{
Name = "ClickExamineHBox",
Orientation = LayoutOrientation.Horizontal,
HorizontalAlignment = Control.HAlignment.Right,
VerticalAlignment = Control.VAlignment.Center,
HorizontalExpand = true
};
// Examine button time // Examine button time
foreach (var verb in verbs) foreach (var verb in verbs)
{ {
@@ -316,8 +334,15 @@ namespace Content.Client.Examine
var button = new ExamineButton(examine); var button = new ExamineButton(examine);
if (examine.HoverVerb)
{
hoverExamineBox.AddChild(button);
}
else
{
button.OnPressed += VerbButtonPressed; button.OnPressed += VerbButtonPressed;
buttonsHBox.AddChild(button); clickExamineBox.AddChild(button);
}
} }
var vbox = _examineTooltipOpen?.GetChild(0).GetChild(0); var vbox = _examineTooltipOpen?.GetChild(0).GetChild(0);
@@ -334,6 +359,8 @@ namespace Content.Client.Examine
{ {
vbox.Children.Remove(hbox.First()); vbox.Children.Remove(hbox.First());
} }
buttonsHBox.AddChild(hoverExamineBox);
buttonsHBox.AddChild(clickExamineBox);
vbox.AddChild(buttonsHBox); vbox.AddChild(buttonsHBox);
} }

View File

@@ -3,10 +3,12 @@ using Content.Client.ContextMenu.UI;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.Utility; using Robust.Client.Utility;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Content.Client.Verbs.UI namespace Content.Client.Verbs.UI
{ {
@@ -27,7 +29,17 @@ namespace Content.Client.Verbs.UI
public VerbMenuElement(Verb verb) : base(verb.Text) public VerbMenuElement(Verb verb) : base(verb.Text)
{ {
ToolTip = verb.Message; 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;
};
Disabled = verb.Disabled; Disabled = verb.Disabled;
Verb = verb; Verb = verb;

View File

@@ -213,7 +213,7 @@ namespace Content.Client.Verbs
{ {
// maybe send an informative pop-up message. // maybe send an informative pop-up message.
if (!string.IsNullOrWhiteSpace(verb.Message)) if (!string.IsNullOrWhiteSpace(verb.Message))
_popupSystem.PopupEntity(verb.Message, user); _popupSystem.PopupEntity(FormattedMessage.RemoveMarkupOrThrow(verb.Message), user);
return; return;
} }

View File

@@ -7,6 +7,7 @@ using Content.Shared.Database;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Inventory.VirtualItem; using Content.Shared.Inventory.VirtualItem;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Shared.Utility;
namespace Content.Server.Verbs namespace Content.Server.Verbs
{ {
@@ -75,7 +76,7 @@ namespace Content.Server.Verbs
{ {
// Send an informative pop-up message // Send an informative pop-up message
if (!string.IsNullOrWhiteSpace(verb.Message)) if (!string.IsNullOrWhiteSpace(verb.Message))
_popupSystem.PopupEntity(verb.Message, user, user); _popupSystem.PopupEntity(FormattedMessage.RemoveMarkupOrThrow(verb.Message), user, user);
return; return;
} }

View File

@@ -111,7 +111,7 @@ namespace Content.Shared.Examine
/// <summary> /// <summary>
/// Either sends the details to a GroupExamineComponent if it finds one, or adds a details examine verb itself. /// Either sends the details to a GroupExamineComponent if it finds one, or adds a details examine verb itself.
/// </summary> /// </summary>
public void AddDetailedExamineVerb(GetVerbsEvent<ExamineVerb> verbsEvent, Component component, List<ExamineEntry> entries, string verbText, string iconTexture = DefaultIconTexture, string hoverMessage = "") public void AddDetailedExamineVerb(GetVerbsEvent<ExamineVerb> verbsEvent, Component component, List<ExamineEntry> entries, string verbText, string iconTexture = DefaultIconTexture, string hoverMessage = "", bool isHoverExamine = false)
{ {
// If the entity has the GroupExamineComponent // If the entity has the GroupExamineComponent
if (TryComp<GroupExamineComponent>(verbsEvent.Target, out var groupExamine)) if (TryComp<GroupExamineComponent>(verbsEvent.Target, out var groupExamine))
@@ -142,17 +142,23 @@ namespace Content.Shared.Examine
} }
var formattedMessage = GetFormattedMessageFromExamineEntries(entries); var formattedMessage = GetFormattedMessageFromExamineEntries(entries);
var act = () =>
{
SendExamineTooltip(verbsEvent.User, verbsEvent.Target, formattedMessage, false, false);
};
if (isHoverExamine)
{
act = () => { };
}
var examineVerb = new ExamineVerb() var examineVerb = new ExamineVerb()
{ {
Act = () => Act = act,
{
SendExamineTooltip(verbsEvent.User, verbsEvent.Target, formattedMessage, false, false);
},
Text = verbText, Text = verbText,
Message = hoverMessage, Message = hoverMessage,
Category = VerbCategory.Examine, Category = VerbCategory.Examine,
Icon = new SpriteSpecifier.Texture(new(iconTexture)), Icon = new SpriteSpecifier.Texture(new(iconTexture)),
HoverVerb = isHoverExamine
}; };
verbsEvent.Verbs.Add(examineVerb); verbsEvent.Verbs.Add(examineVerb);
@@ -161,18 +167,26 @@ namespace Content.Shared.Examine
/// <summary> /// <summary>
/// Either adds a details examine verb, or sends the details to a GroupExamineComponent if it finds one. /// Either adds a details examine verb, or sends the details to a GroupExamineComponent if it finds one.
/// </summary> /// </summary>
public void AddDetailedExamineVerb(GetVerbsEvent<ExamineVerb> verbsEvent, Component component, ExamineEntry entry, string verbText, string iconTexture = DefaultIconTexture, string hoverMessage = "") public void AddDetailedExamineVerb(GetVerbsEvent<ExamineVerb> verbsEvent, Component component, ExamineEntry entry, string verbText, string iconTexture = DefaultIconTexture, string hoverMessage = "", bool isHoverExamine = false)
{ {
AddDetailedExamineVerb(verbsEvent, component, new List<ExamineEntry> { entry }, verbText, iconTexture, hoverMessage); AddDetailedExamineVerb(verbsEvent, component, new List<ExamineEntry> { entry }, verbText, iconTexture, hoverMessage, isHoverExamine);
} }
/// <summary> /// <summary>
/// Either adds a details examine verb, or sends the details to a GroupExamineComponent if it finds one. /// Either adds a details examine verb, or sends the details to a GroupExamineComponent if it finds one.
/// </summary> /// </summary>
public void AddDetailedExamineVerb(GetVerbsEvent<ExamineVerb> verbsEvent, Component component, FormattedMessage message, string verbText, string iconTexture = DefaultIconTexture, string hoverMessage = "") public void AddDetailedExamineVerb(GetVerbsEvent<ExamineVerb> verbsEvent, Component component, FormattedMessage message, string verbText, string iconTexture = DefaultIconTexture, string hoverMessage = "", bool isHoverExamine = false)
{ {
var componentName = _componentFactory.GetComponentName(component.GetType()); var componentName = _componentFactory.GetComponentName(component.GetType());
AddDetailedExamineVerb(verbsEvent, component, new ExamineEntry(componentName, 0f, message), verbText, iconTexture, hoverMessage); AddDetailedExamineVerb(verbsEvent, component, new ExamineEntry(componentName, 0f, message), verbText, iconTexture, hoverMessage, isHoverExamine);
}
/// <summary>
/// Adds an icon aligned to the left of examine window that gives you info on hover.
/// </summary>
public void AddHoverExamineVerb(GetVerbsEvent<ExamineVerb> verbsEvent, Component component, string hoverMessage, string iconTexture = DefaultIconTexture)
{
AddDetailedExamineVerb(verbsEvent, component, FormattedMessage.Empty, "", iconTexture, hoverMessage, true);
} }
} }
} }

View File

@@ -347,6 +347,7 @@ namespace Content.Shared.Verbs
public override bool CloseMenuDefault => false; // for examine verbs, this will close the examine tooltip. public override bool CloseMenuDefault => false; // for examine verbs, this will close the examine tooltip.
public bool ShowOnExamineTooltip = true; public bool ShowOnExamineTooltip = true;
public bool HoverVerb = false; // aligned to the left, gives text on hover
} }
/// <summary> /// <summary>