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