Refactor Context Menus and make them use XAML & stylesheets (#4768)

* 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
This commit is contained in:
Leon Friedrich
2021-10-28 18:21:19 +13:00
committed by GitHub
parent 224952110e
commit 49296e33a0
36 changed files with 1421 additions and 1535 deletions

View File

@@ -0,0 +1,70 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.ContextMenu.UI
{
/// <summary>
/// The base context-menu pop-up window used for both the entity and verb menus.
/// </summary>
[GenerateTypedNameReferences]
public partial class ContextMenuPopup : Popup
{
public const string StyleClassContextMenuPopup = "contextMenuPopup";
/// <summary>
/// How many items to list before limiting the size and adding a scroll bar.
/// </summary>
public const int MaxItemsBeforeScroll = 10;
/// <summary>
/// If this pop-up is created by hovering over some element in another pop-up, this is that element.
/// </summary>
public ContextMenuElement? ParentElement;
/// <summary>
/// This is the main body of the menu. The menu entries should be added to this object.
/// </summary>
public BoxContainer MenuBody = new() { Orientation = LayoutOrientation.Vertical };
private ContextMenuPresenter _presenter;
public ContextMenuPopup (ContextMenuPresenter presenter, ContextMenuElement? parentElement) : base()
{
RobustXamlLoader.Load(this);
MenuPanel.SetOnlyStyleClass(StyleClassContextMenuPopup);
_presenter = presenter;
ParentElement = parentElement;
//XAML controls are private. So defining and adding MenuBody here instead.
Scroll.AddChild(MenuBody);
// Set Max Height based on MaxItemsBeforeScroll and the panel's style box
MenuPanel.ForceRunStyleUpdate();
MenuPanel.TryGetStyleProperty<StyleBox>(PanelContainer.StylePropertyPanel, out var box);
var styleSize = (box?.MinimumSize ?? Vector2.Zero) / UIScale;
MenuPanel.MaxHeight = MaxItemsBeforeScroll * (ContextMenuElement.ElementHeight + 2 * ContextMenuElement.ElementMargin) + styleSize.Y;
UserInterfaceManager.ModalRoot.AddChild(this);
MenuBody.OnChildRemoved += ctrl => _presenter.OnRemoveElement(this, ctrl);
if (ParentElement != null)
{
DebugTools.Assert(ParentElement.SubMenu == null);
ParentElement.SubMenu = this;
}
}
protected override void Dispose(bool disposing)
{
MenuBody.OnChildRemoved -= ctrl => _presenter.OnRemoveElement(this, ctrl);
ParentElement = null;
base.Dispose(disposing);
}
}
}