Verb confirmation (#6137)
This commit is contained in:
34
Content.Client/Verbs/UI/ConfirmationMenuElement.cs
Normal file
34
Content.Client/Verbs/UI/ConfirmationMenuElement.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Content.Client.ContextMenu.UI;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Verbs.UI;
|
||||
|
||||
public partial class ConfirmationMenuElement : ContextMenuElement
|
||||
{
|
||||
public const string StyleClassConfirmationContextMenuButton = "confirmationContextMenuButton";
|
||||
|
||||
public readonly Verb Verb;
|
||||
public readonly VerbType Type;
|
||||
|
||||
public override string Text
|
||||
{
|
||||
set
|
||||
{
|
||||
var message = new FormattedMessage();
|
||||
message.PushColor(Color.White);
|
||||
message.AddMarkupPermissive(value.Trim());
|
||||
Label.SetMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public ConfirmationMenuElement(Verb verb, string? text, VerbType type) : base(text)
|
||||
{
|
||||
Verb = verb;
|
||||
Type = type;
|
||||
Icon.Visible = false;
|
||||
|
||||
SetOnlyStyleClass(StyleClassConfirmationContextMenuButton);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ namespace Content.Client.Verbs.UI
|
||||
public const string StyleClassVerbActivationText = "ActivationVerb";
|
||||
public const string StyleClassVerbAlternativeText = "AlternativeVerb";
|
||||
public const string StyleClassVerbOtherText = "OtherVerb";
|
||||
public const string StyleClassVerbMenuConfirmationTexture = "verbMenuConfirmationTexture";
|
||||
|
||||
public const float VerbTooltipDelay = 0.5f;
|
||||
|
||||
@@ -62,6 +63,12 @@ namespace Content.Client.Verbs.UI
|
||||
TooltipDelay = VerbTooltipDelay;
|
||||
Disabled = verb.Disabled;
|
||||
Verb = verb;
|
||||
|
||||
if (verb.ConfirmationPopup)
|
||||
{
|
||||
ExpansionIndicator.SetOnlyStyleClass(StyleClassVerbMenuConfirmationTexture);
|
||||
ExpansionIndicator.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
public VerbMenuElement(VerbCategory category, VerbType verbType) : this(category.Text, category.Icon, verbType) { }
|
||||
|
||||
@@ -170,7 +170,14 @@ namespace Content.Client.Verbs.UI
|
||||
return;
|
||||
|
||||
if (element is not VerbMenuElement verbElement)
|
||||
{
|
||||
if (element is not ConfirmationMenuElement confElement)
|
||||
return;
|
||||
|
||||
args.Handle();
|
||||
ExecuteVerb(confElement.Verb, confElement.Type);
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handle();
|
||||
var verb = verbElement.Verb;
|
||||
@@ -178,25 +185,45 @@ namespace Content.Client.Verbs.UI
|
||||
if (verb == null)
|
||||
{
|
||||
// The user probably clicked on a verb category.
|
||||
// We will act as if they clicked on the first verb in that category.
|
||||
// If there's only one verb in the category, then it will act as if they clicked on that verb.
|
||||
// Otherwise it opens the category menu.
|
||||
|
||||
if (verbElement.SubMenu == null || verbElement.SubMenu.ChildCount == 0)
|
||||
return;
|
||||
|
||||
if (verbElement.SubMenu.MenuBody.ChildCount != 1
|
||||
|| verbElement.SubMenu.MenuBody.Children.First() is not VerbMenuElement verbCategoryElement)
|
||||
|| verbElement.SubMenu.MenuBody.Children.First() is not VerbMenuElement verbMenuElement)
|
||||
{
|
||||
OpenSubMenu(verbElement);
|
||||
return;
|
||||
}
|
||||
|
||||
verb = verbCategoryElement.Verb;
|
||||
verb = verbMenuElement.Verb;
|
||||
|
||||
if (verb == null)
|
||||
return;
|
||||
}
|
||||
|
||||
_verbSystem.ExecuteVerb(CurrentTarget, verb, verbElement.Type);
|
||||
if (verb.ConfirmationPopup)
|
||||
{
|
||||
if (verbElement.SubMenu == null)
|
||||
{
|
||||
var popupElement = new ConfirmationMenuElement(verb, "Confirm", verbElement.Type);
|
||||
verbElement.SubMenu = new ContextMenuPopup(this, verbElement);
|
||||
AddElement(verbElement.SubMenu, popupElement);
|
||||
}
|
||||
|
||||
OpenSubMenu(verbElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecuteVerb(verb, verbElement.Type);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteVerb(Verb verb, VerbType verbType)
|
||||
{
|
||||
_verbSystem.ExecuteVerb(CurrentTarget, verb, verbType);
|
||||
if (verb.CloseMenu)
|
||||
_verbSystem.CloseAllMenus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user