* XAML verb menu * fix ghost FOV * spacing * rename missed "ContextMenu"->"EntityMenu" instances * move visibility checks to verb system * update comment * Remove CanSeeContainerCheck * use ScrollContainer measure option * MaxWidth / texxt line wrapping * verb category default Now when you click on a verb category, it should default to running the first member of that category. This makes it much more convenient to eject/insert when there is only a single option * only apply style to first verb category entry * Use new visibility flags * FoV -> Fov * Revert "only apply style to first verb category entry" This reverts commit 9a6a17dba600e3ae0421caed59fcab145c260c99. * make all entity menu visibility checks clientside * Fix empty unbuckle category * fix merge
102 lines
3.2 KiB
C#
102 lines
3.2 KiB
C#
using Content.Client.Resources;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.ContextMenu.UI
|
|
{
|
|
/// <summary>
|
|
/// This is a basic entry in a context menu. It has a label and room for some sort of icon on the left.
|
|
/// If this entry has a sub-menu, it also shows a little ">" icon on the right.
|
|
/// </summary>
|
|
[GenerateTypedNameReferences]
|
|
public partial class ContextMenuElement : ContainerButton
|
|
{
|
|
public const string StyleClassContextMenuButton = "contextMenuButton";
|
|
|
|
public const float ElementMargin = 2;
|
|
public const float ElementHeight = 32;
|
|
|
|
/// <summary>
|
|
/// The menu that contains this element
|
|
/// </summary>
|
|
public ContextMenuPopup? ParentMenu;
|
|
|
|
private ContextMenuPopup? _subMenu;
|
|
|
|
/// <summary>
|
|
/// The pop-up menu that is opened when hovering over this element.
|
|
/// </summary>
|
|
public ContextMenuPopup? SubMenu
|
|
{
|
|
get => _subMenu;
|
|
set
|
|
{
|
|
_subMenu = value;
|
|
ExpansionIndicator.Visible = _subMenu != null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convenience property to set label text.
|
|
/// </summary>
|
|
public string Text { set => Label.SetMessage(FormattedMessage.FromMarkupPermissive(value.Trim())); }
|
|
|
|
public ContextMenuElement(string? text = null)
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
Margin = new Thickness(ElementMargin, ElementMargin, ElementMargin, ElementMargin);
|
|
SetOnlyStyleClass(StyleClassContextMenuButton);
|
|
|
|
if (text != null)
|
|
Text = text;
|
|
|
|
ExpansionIndicator.Texture = IoCManager.Resolve<IResourceCache>()
|
|
.GetTexture("/Textures/Interface/VerbIcons/group.svg.192dpi.png");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
_subMenu?.Dispose();
|
|
_subMenu = null;
|
|
ParentMenu = null;
|
|
}
|
|
|
|
protected override void Draw(DrawingHandleScreen handle)
|
|
{
|
|
UpdateStyle();
|
|
base.Draw(handle);
|
|
}
|
|
|
|
/// <summary>
|
|
/// If this element's sub-menu is currently visible, give it the hovered pseudo class.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Basically: if we are in a sub menu, keep the element in the parent menu highlighted even though we are
|
|
/// not actually hovering over it.
|
|
/// </remarks>
|
|
protected virtual void UpdateStyle()
|
|
{
|
|
if ((_subMenu?.Visible ?? false) && !HasStylePseudoClass(StylePseudoClassHover))
|
|
{
|
|
AddStylePseudoClass(StylePseudoClassHover);
|
|
return;
|
|
}
|
|
|
|
if (DrawMode == DrawModeEnum.Hover)
|
|
return;
|
|
|
|
if (_subMenu?.Visible ?? true)
|
|
return;
|
|
|
|
RemoveStylePseudoClass(StylePseudoClassHover);
|
|
}
|
|
}
|
|
}
|