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:
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -40,7 +41,17 @@ public sealed class ExamineButton : ContainerButton
|
||||
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
|
||||
{
|
||||
|
||||
@@ -298,10 +298,28 @@ namespace Content.Client.Examine
|
||||
{
|
||||
Name = "ExamineButtonsHBox",
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
HorizontalAlignment = Control.HAlignment.Right,
|
||||
HorizontalAlignment = Control.HAlignment.Stretch,
|
||||
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
|
||||
foreach (var verb in verbs)
|
||||
{
|
||||
@@ -316,8 +334,15 @@ namespace Content.Client.Examine
|
||||
|
||||
var button = new ExamineButton(examine);
|
||||
|
||||
if (examine.HoverVerb)
|
||||
{
|
||||
hoverExamineBox.AddChild(button);
|
||||
}
|
||||
else
|
||||
{
|
||||
button.OnPressed += VerbButtonPressed;
|
||||
buttonsHBox.AddChild(button);
|
||||
clickExamineBox.AddChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
var vbox = _examineTooltipOpen?.GetChild(0).GetChild(0);
|
||||
@@ -334,6 +359,8 @@ namespace Content.Client.Examine
|
||||
{
|
||||
vbox.Children.Remove(hbox.First());
|
||||
}
|
||||
buttonsHBox.AddChild(hoverExamineBox);
|
||||
buttonsHBox.AddChild(clickExamineBox);
|
||||
vbox.AddChild(buttonsHBox);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@ using Content.Client.ContextMenu.UI;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Verbs.UI
|
||||
{
|
||||
@@ -27,7 +29,17 @@ namespace Content.Client.Verbs.UI
|
||||
|
||||
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;
|
||||
Verb = verb;
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace Content.Client.Verbs
|
||||
{
|
||||
// maybe send an informative pop-up message.
|
||||
if (!string.IsNullOrWhiteSpace(verb.Message))
|
||||
_popupSystem.PopupEntity(verb.Message, user);
|
||||
_popupSystem.PopupEntity(FormattedMessage.RemoveMarkupOrThrow(verb.Message), user);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Shared.Database;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Inventory.VirtualItem;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Verbs
|
||||
{
|
||||
@@ -75,7 +76,7 @@ namespace Content.Server.Verbs
|
||||
{
|
||||
// Send an informative pop-up message
|
||||
if (!string.IsNullOrWhiteSpace(verb.Message))
|
||||
_popupSystem.PopupEntity(verb.Message, user, user);
|
||||
_popupSystem.PopupEntity(FormattedMessage.RemoveMarkupOrThrow(verb.Message), user, user);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Content.Shared.Examine
|
||||
/// <summary>
|
||||
/// Either sends the details to a GroupExamineComponent if it finds one, or adds a details examine verb itself.
|
||||
/// </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 (TryComp<GroupExamineComponent>(verbsEvent.Target, out var groupExamine))
|
||||
@@ -142,17 +142,23 @@ namespace Content.Shared.Examine
|
||||
}
|
||||
|
||||
var formattedMessage = GetFormattedMessageFromExamineEntries(entries);
|
||||
var act = () =>
|
||||
{
|
||||
SendExamineTooltip(verbsEvent.User, verbsEvent.Target, formattedMessage, false, false);
|
||||
};
|
||||
if (isHoverExamine)
|
||||
{
|
||||
act = () => { };
|
||||
}
|
||||
|
||||
var examineVerb = new ExamineVerb()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
SendExamineTooltip(verbsEvent.User, verbsEvent.Target, formattedMessage, false, false);
|
||||
},
|
||||
Act = act,
|
||||
Text = verbText,
|
||||
Message = hoverMessage,
|
||||
Category = VerbCategory.Examine,
|
||||
Icon = new SpriteSpecifier.Texture(new(iconTexture)),
|
||||
HoverVerb = isHoverExamine
|
||||
};
|
||||
|
||||
verbsEvent.Verbs.Add(examineVerb);
|
||||
@@ -161,18 +167,26 @@ namespace Content.Shared.Examine
|
||||
/// <summary>
|
||||
/// Either adds a details examine verb, or sends the details to a GroupExamineComponent if it finds one.
|
||||
/// </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>
|
||||
/// Either adds a details examine verb, or sends the details to a GroupExamineComponent if it finds one.
|
||||
/// </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());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,6 +347,7 @@ namespace Content.Shared.Verbs
|
||||
public override bool CloseMenuDefault => false; // for examine verbs, this will close the examine tooltip.
|
||||
|
||||
public bool ShowOnExamineTooltip = true;
|
||||
public bool HoverVerb = false; // aligned to the left, gives text on hover
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user