From cad59d2cb4c3bc3929592fbd368b1e4e4ad29f24 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Sat, 23 May 2020 03:09:44 +0200 Subject: [PATCH] Fancy Verb Menu & Verb API Refactor (#928) --- .../GameObjects/EntitySystems/VerbSystem.cs | 516 +++++++++++++++--- .../GlobalVerbs/ViewVariablesVerb.cs | 16 +- .../Components/Chemistry/SolutionComponent.cs | 59 +- .../Components/Fluids/CanSpillComponent.cs | 17 +- .../Interactable/HandheldLightComponent.cs | 17 +- .../Items/Storage/EntityStorageComponent.cs | 26 +- .../Components/Items/Storage/ItemComponent.cs | 16 +- .../Medical/MedicalScannerComponent.cs | 20 +- .../Chargers/PowerCellChargerComponent.cs | 36 +- .../WeaponCapacitorChargerComponent.cs | 43 +- .../Components/RotatableComponent.cs | 26 +- .../BallisticMagazineWeaponComponent.cs | 14 +- .../GameObjects/EntitySystems/VerbSystem.cs | 23 +- Content.Server/GlobalVerbs/ControlMobVerb.cs | 41 +- Content.Server/GlobalVerbs/RejuvenateVerb.cs | 22 +- .../VerbSystemMessages.cs | 19 +- .../GameObjects/Verbs/GlobalVerb.cs | 30 +- Content.Shared/GameObjects/Verbs/Verb.cs | 97 +--- .../GameObjects/Verbs/VerbCategories.cs | 13 + .../GameObjects/Verbs/VerbCategoryData.cs | 24 + Content.Shared/GameObjects/Verbs/VerbData.cs | 65 +++ .../GameObjects/Verbs/VerbUtility.cs | 12 - .../GameObjects/Verbs/VerbVisibility.cs | 23 + .../UserInterface/VerbIcons/debug.svg | 103 ++++ .../VerbIcons/debug.svg.96dpi.png | Bin 0 -> 590 bytes .../UserInterface/VerbIcons/group.svg | 68 +++ .../VerbIcons/group.svg.96dpi.png | Bin 0 -> 280 bytes .../UserInterface/VerbIcons/rotate_ccw.svg | 73 +++ .../VerbIcons/rotate_ccw.svg.96dpi.png | Bin 0 -> 417 bytes .../UserInterface/VerbIcons/rotate_cw.svg | 73 +++ .../VerbIcons/rotate_cw.svg.96dpi.png | Bin 0 -> 427 bytes Resources/keybinds.yml | 5 + SpaceStation14.sln.DotSettings | 1 + 33 files changed, 1099 insertions(+), 399 deletions(-) create mode 100644 Content.Shared/GameObjects/Verbs/VerbCategories.cs create mode 100644 Content.Shared/GameObjects/Verbs/VerbCategoryData.cs create mode 100644 Content.Shared/GameObjects/Verbs/VerbData.cs create mode 100644 Content.Shared/GameObjects/Verbs/VerbVisibility.cs create mode 100644 Resources/Textures/UserInterface/VerbIcons/debug.svg create mode 100644 Resources/Textures/UserInterface/VerbIcons/debug.svg.96dpi.png create mode 100644 Resources/Textures/UserInterface/VerbIcons/group.svg create mode 100644 Resources/Textures/UserInterface/VerbIcons/group.svg.96dpi.png create mode 100644 Resources/Textures/UserInterface/VerbIcons/rotate_ccw.svg create mode 100644 Resources/Textures/UserInterface/VerbIcons/rotate_ccw.svg.96dpi.png create mode 100644 Resources/Textures/UserInterface/VerbIcons/rotate_cw.svg create mode 100644 Resources/Textures/UserInterface/VerbIcons/rotate_cw.svg.96dpi.png diff --git a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs index 7b91aaedaa..53b7cf87af 100644 --- a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs @@ -1,25 +1,37 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Threading; using Content.Client.State; +using Content.Client.UserInterface; +using Content.Client.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.EntitySystemMessages; using Content.Shared.Input; using JetBrains.Annotations; using Robust.Client.GameObjects.EntitySystems; +using Robust.Client.Graphics; +using Robust.Client.Graphics.Drawing; +using Robust.Client.Interfaces.GameObjects.Components; using Robust.Client.Interfaces.Input; +using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.Interfaces.State; +using Robust.Client.Interfaces.UserInterface; using Robust.Client.Player; +using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; +using Robust.Client.Utility; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Utility; +using Timer = Robust.Shared.Timers.Timer; namespace Content.Client.GameObjects.EntitySystems { @@ -31,11 +43,21 @@ namespace Content.Client.GameObjects.EntitySystems [Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly IPlayerManager _playerManager; [Dependency] private readonly IInputManager _inputManager; + [Dependency] private readonly IItemSlotManager _itemSlotManager; + [Dependency] private readonly IGameTiming _gameTiming; + [Dependency] private readonly IUserInterfaceManager _userInterfaceManager; + [Dependency] private readonly IResourceCache _resourceCache; #pragma warning restore 649 - private VerbPopup _currentPopup; + private EntityList _currentEntityList; + private VerbPopup _currentVerbListRoot; + private VerbPopup _currentGroupList; + private EntityUid _currentEntity; + private bool IsAnyContextMenuOpen => _currentEntityList != null || _currentVerbListRoot != null; + + public override void Initialize() { base.Initialize(); @@ -51,29 +73,28 @@ namespace Content.Client.GameObjects.EntitySystems public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates) { - if (_currentPopup != null) + if (_currentVerbListRoot != null) { - CloseContextMenu(); + CloseVerbMenu(); } _currentEntity = entity.Uid; - _currentPopup = new VerbPopup(); - _currentPopup.UserInterfaceManager.ModalRoot.AddChild(_currentPopup); - _currentPopup.OnPopupHide += CloseContextMenu; + _currentVerbListRoot = new VerbPopup(); + _userInterfaceManager.ModalRoot.AddChild(_currentVerbListRoot); + _currentVerbListRoot.OnPopupHide += CloseVerbMenu; - _currentPopup.List.AddChild(new Label {Text = "Waiting on Server..."}); + _currentVerbListRoot.List.AddChild(new Label {Text = "Waiting on Server..."}); RaiseNetworkEvent(new VerbSystemMessages.RequestVerbsMessage(_currentEntity)); - var size = _currentPopup.List.CombinedMinimumSize; - var box = UIBox2.FromDimensions(screenCoordinates.Position, size); - _currentPopup.Open(box); + var box = UIBox2.FromDimensions(screenCoordinates.Position, (1, 1)); + _currentVerbListRoot.Open(box); } private bool OnOpenContextMenu(in PointerInputCmdHandler.PointerInputCmdArgs args) { - if (_currentPopup != null) + if (IsAnyContextMenuOpen) { - CloseContextMenu(); + CloseAllMenus(); return true; } @@ -89,20 +110,29 @@ namespace Content.Client.GameObjects.EntitySystems return false; } - _currentPopup = new VerbPopup(); - _currentPopup.OnPopupHide += CloseContextMenu; - foreach (var entity in entities) + _currentEntityList = new EntityList(); + _currentEntityList.OnPopupHide += CloseAllMenus; + for (var i = 0; i < entities.Count; i++) { - var button = new Button {Text = entity.Name}; - _currentPopup.List.AddChild(button); - button.OnPressed += _ => OnContextButtonPressed(entity); + if (i != 0) + { + _currentEntityList.List.AddChild(new PanelContainer + { + CustomMinimumSize = (0, 2), + PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#333")} + }); + } + + var entity = entities[i]; + + _currentEntityList.List.AddChild(new EntityButton(this, entity)); } - _currentPopup.UserInterfaceManager.ModalRoot.AddChild(_currentPopup); + _userInterfaceManager.ModalRoot.AddChild(_currentEntityList); - var size = _currentPopup.List.CombinedMinimumSize; + var size = _currentEntityList.List.CombinedMinimumSize; var box = UIBox2.FromDimensions(args.ScreenCoordinates.Position, size); - _currentPopup.Open(box); + _currentEntityList.Open(box); return true; } @@ -119,28 +149,31 @@ namespace Content.Client.GameObjects.EntitySystems return; } - DebugTools.AssertNotNull(_currentPopup); + DebugTools.AssertNotNull(_currentVerbListRoot); - var buttons = new Dictionary>(); + var buttons = new Dictionary>(); + var groupIcons = new Dictionary(); - var vBox = _currentPopup.List; + var vBox = _currentVerbListRoot.List; vBox.DisposeAllChildren(); + + // Local variable so that scope capture ensures this is the correct value. + var curEntity = _currentEntity; + foreach (var data in msg.Verbs) { - var button = new Button {Text = data.Text, Disabled = !data.Available}; - if (data.Available) + var list = buttons.GetOrNew(data.Category); + + if (data.CategoryIcon != null && !groupIcons.ContainsKey(data.Category)) { - button.OnPressed += _ => - { - RaiseNetworkEvent(new VerbSystemMessages.UseVerbMessage(_currentEntity, data.Key)); - CloseContextMenu(); - }; + groupIcons.Add(data.Category, data.CategoryIcon); } - if(!buttons.ContainsKey(data.Category)) - buttons[data.Category] = new List