Skip to content

Commit

Permalink
Add an "RT ViewVariables" button to the right-click menu (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored May 14, 2024
1 parent f342634 commit 348261e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
4 changes: 0 additions & 4 deletions OpenDreamClient/Input/ContextMenu/ContextMenuItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ internal sealed partial class ContextMenuItem : PanelContainer {
private static readonly StyleBox HoverStyle = new StyleBoxFlat(Color.Gray);

public readonly ClientObjectReference Target;
public readonly MetaDataComponent EntityMetaData;
public readonly DMISpriteComponent? EntitySprite;

private readonly ContextMenuPopup _menu;

Expand All @@ -22,8 +20,6 @@ public ContextMenuItem(ContextMenuPopup menu, ClientObjectReference target, Meta
RobustXamlLoader.Load(this);

Target = target;
EntityMetaData = metadata;
EntitySprite = sprite;
_menu = menu;

NameLabel.Margin = new Thickness(2, 0, 4, 0);
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Input/ContextMenu/ContextMenuPopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void SetActiveItem(ContextMenuItem item) {
_uiManager.ModalRoot.RemoveChild(_currentVerbMenu);
}

_currentVerbMenu = new VerbMenuPopup(_verbSystem, GetSeeInvisible(), item.Target, item.EntityMetaData, item.EntitySprite);
_currentVerbMenu = new VerbMenuPopup(_verbSystem, GetSeeInvisible(), item.Target);

_currentVerbMenu.OnVerbSelected += Close;

Expand Down
30 changes: 24 additions & 6 deletions OpenDreamClient/Input/ContextMenu/VerbMenuPopup.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Linq;
using OpenDreamClient.Interface.Controls;
using OpenDreamClient.Rendering;
using OpenDreamShared.Dream;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.ViewVariables;

namespace OpenDreamClient.Input.ContextMenu;

Expand All @@ -18,7 +18,7 @@ internal sealed partial class VerbMenuPopup : Popup {

private readonly ClientObjectReference _target;

public VerbMenuPopup(ClientVerbSystem? verbSystem, sbyte seeInvisible, ClientObjectReference target, MetaDataComponent? entityMetaData, DMISpriteComponent? entitySprite) {
public VerbMenuPopup(ClientVerbSystem? verbSystem, sbyte seeInvisible, ClientObjectReference target) {
RobustXamlLoader.Load(this);

_verbSystem = verbSystem;
Expand All @@ -36,21 +36,39 @@ public VerbMenuPopup(ClientVerbSystem? verbSystem, sbyte seeInvisible, ClientObj
AddVerb(verbId, verbSrc, verbInfo);
}
}

#if TOOLS
// If we're compiling with TOOLS and this is an entity, provide the option to use RT's VV on it
if (_target.Type == ClientObjectReference.RefType.Entity) {
var viewVariablesButton = AddButton("RT ViewVariables");

viewVariablesButton.OnPressed += _ => {
IoCManager.Resolve<IClientViewVariablesManager>().OpenVV(_target.Entity);
};
}
#endif
}

private void AddVerb(int verbId, ClientObjectReference verbSrc, VerbSystem.VerbInfo verbInfo) {
var button = new Button {
Text = verbInfo.Name
};

var button = AddButton(verbInfo.Name);
var takesTargetArg = verbInfo.GetTargetType() != null && !verbSrc.Equals(_target);

button.OnPressed += _ => {
_verbSystem?.ExecuteVerb(verbSrc, verbId, takesTargetArg ? [_target] : []);
};
}

private Button AddButton(string text) {
var button = new Button {
Text = text
};

button.OnPressed += _ => {
Close();
OnVerbSelected?.Invoke();
};

VerbMenu.AddChild(button);
return button;
}
}

0 comments on commit 348261e

Please sign in to comment.