]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Action UI fixes (#27468)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Mon, 29 Apr 2024 08:36:18 +0000 (20:36 +1200)
committerGitHub <noreply@github.com>
Mon, 29 Apr 2024 08:36:18 +0000 (18:36 +1000)
Content.Client/UserInterface/Systems/Actions/ActionUIController.cs
Content.Client/UserInterface/Systems/Actions/Controls/ActionButton.cs

index c79f0f80f96dfe39caa1b7af583eaf561c3f38a0..5d9706452c9ea9823daab16a4bb45e6ec65e5911 100644 (file)
@@ -15,6 +15,7 @@ using Content.Shared.Actions;
 using Content.Shared.Input;
 using Robust.Client.GameObjects;
 using Robust.Client.Graphics;
+using Robust.Client.Input;
 using Robust.Client.Player;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controllers;
@@ -42,6 +43,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
     [Dependency] private readonly IGameTiming _timing = default!;
     [Dependency] private readonly IPlayerManager _playerManager = default!;
     [Dependency] private readonly IEntityManager _entMan = default!;
+    [Dependency] private readonly IInputManager _input = default!;
 
     [UISystemDependency] private readonly ActionsSystem? _actionsSystem = default;
     [UISystemDependency] private readonly InteractionOutlineSystem? _interactionOutline = default;
@@ -356,6 +358,10 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
     {
         QueueWindowUpdate();
 
+        // TODO ACTIONS allow buttons to persist across state applications
+        // Then we don't have to interrupt drags any time the buttons get rebuilt.
+        _menuDragHelper.EndDrag();
+
         if (_actionsSystem != null)
             _container?.SetActionData(_actionsSystem, _actions.ToArray());
     }
@@ -516,7 +522,8 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
             button.ClearData();
             if (_container?.TryGetButtonIndex(button, out position) ?? false)
             {
-                _actions.RemoveAt(position);
+                if (_actions.Count > position && position >= 0)
+                    _actions.RemoveAt(position);
             }
         }
         else if (button.TryReplaceWith(actionId.Value, _actionsSystem) &&
@@ -539,24 +546,23 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
 
     private void DragAction()
     {
-        EntityUid? swapAction = null;
-        if (UIManager.CurrentlyHovered is ActionButton button)
+        if (_menuDragHelper.Dragged is not {ActionId: {} action} dragged)
         {
-            if (!_menuDragHelper.IsDragging || _menuDragHelper.Dragged?.ActionId is not { } type)
-            {
-                _menuDragHelper.EndDrag();
-                return;
-            }
-
-            swapAction = button.ActionId;
-            SetAction(button, type, false);
+            _menuDragHelper.EndDrag();
+            return;
         }
 
-        if (_menuDragHelper.Dragged is {Parent: ActionButtonContainer} old)
+        EntityUid? swapAction = null;
+        var currentlyHovered = UIManager.MouseGetControl(_input.MouseScreenPosition);
+        if (currentlyHovered is ActionButton button)
         {
-            SetAction(old, swapAction, false);
+            swapAction = button.ActionId;
+            SetAction(button, action, false);
         }
 
+        if (dragged.Parent is ActionButtonContainer)
+            SetAction(dragged, swapAction, false);
+
         if (_actionsSystem != null)
             _container?.SetActionData(_actionsSystem, _actions.ToArray());
 
@@ -610,27 +616,27 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
 
     private void OnActionPressed(GUIBoundKeyEventArgs args, ActionButton button)
     {
-        if (args.Function == EngineKeyFunctions.UIClick)
+        if (args.Function == EngineKeyFunctions.UIRightClick)
         {
-            if (button.ActionId == null)
-            {
-                var ev = new FillActionSlotEvent();
-                EntityManager.EventBus.RaiseEvent(EventSource.Local, ev);
-                if (ev.Action != null)
-                    SetAction(button, ev.Action);
-            }
-            else
-            {
-                _menuDragHelper.MouseDown(button);
-            }
-
+            SetAction(button, null);
             args.Handle();
+            return;
         }
-        else if (args.Function == EngineKeyFunctions.UIRightClick)
+
+        if (args.Function != EngineKeyFunctions.UIClick)
+            return;
+
+        args.Handle();
+        if (button.ActionId != null)
         {
-            SetAction(button, null);
-            args.Handle();
+            _menuDragHelper.MouseDown(button);
+            return;
         }
+
+        var ev = new FillActionSlotEvent();
+        EntityManager.EventBus.RaiseEvent(EventSource.Local, ev);
+        if (ev.Action != null)
+            SetAction(button, ev.Action);
     }
 
     private void OnActionUnpressed(GUIBoundKeyEventArgs args, ActionButton button)
@@ -638,33 +644,31 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
         if (args.Function != EngineKeyFunctions.UIClick || _actionsSystem == null)
             return;
 
-        //todo: make dragging onto the same spot NOT trigger again
-        if (UIManager.CurrentlyHovered == button)
-        {
-            _menuDragHelper.EndDrag();
+        args.Handle();
 
-            if (_actionsSystem.TryGetActionData(button.ActionId, out var baseAction))
-            {
-                if (baseAction is BaseTargetActionComponent action)
-                {
-                    // for target actions, we go into "select target" mode, we don't
-                    // message the server until we actually pick our target.
-
-                    // if we're clicking the same thing we're already targeting for, then we simply cancel
-                    // targeting
-                    ToggleTargeting(button.ActionId.Value, action);
-                    return;
-                }
-
-                _actionsSystem?.TriggerAction(button.ActionId.Value, baseAction);
-            }
-        }
-        else
+        if (_menuDragHelper.IsDragging)
         {
             DragAction();
+            return;
         }
 
-        args.Handle();
+        _menuDragHelper.EndDrag();
+
+        if (!_actionsSystem.TryGetActionData(button.ActionId, out var baseAction))
+            return;
+
+        if (baseAction is not BaseTargetActionComponent action)
+        {
+            _actionsSystem?.TriggerAction(button.ActionId.Value, baseAction);
+            return;
+        }
+
+        // for target actions, we go into "select target" mode, we don't
+        // message the server until we actually pick our target.
+
+        // if we're clicking the same thing we're already targeting for, then we simply cancel
+        // targeting
+        ToggleTargeting(button.ActionId.Value, action);
     }
 
     private bool OnMenuBeginDrag()
index 2372d98f8ddbe38da4576956517d68f7d854143e..2cdd4cb79bd6fdcde5d25c3fea53dc526bbff14b 100644 (file)
@@ -152,16 +152,8 @@ public sealed class ActionButton : Control, IEntityControl
 
         OnThemeUpdated();
 
-        OnKeyBindDown += args =>
-        {
-            Depress(args, true);
-            OnPressed(args);
-        };
-        OnKeyBindUp += args =>
-        {
-            Depress(args, false);
-            OnUnpressed(args);
-        };
+        OnKeyBindDown += OnPressed;
+        OnKeyBindUp += OnUnpressed;
 
         TooltipSupplier = SupplyTooltip;
     }
@@ -175,11 +167,23 @@ public sealed class ActionButton : Control, IEntityControl
 
     private void OnPressed(GUIBoundKeyEventArgs args)
     {
+        if (args.Function != EngineKeyFunctions.UIClick && args.Function != EngineKeyFunctions.UIRightClick)
+            return;
+
+        if (args.Function == EngineKeyFunctions.UIRightClick)
+            Depress(args, true);
+
         ActionPressed?.Invoke(args, this);
     }
 
     private void OnUnpressed(GUIBoundKeyEventArgs args)
     {
+        if (args.Function != EngineKeyFunctions.UIClick && args.Function != EngineKeyFunctions.UIRightClick)
+            return;
+
+        if (args.Function == EngineKeyFunctions.UIRightClick)
+            Depress(args, false);
+
         ActionUnpressed?.Invoke(args, this);
     }
 
@@ -378,12 +382,6 @@ public sealed class ActionButton : Control, IEntityControl
         if (_action is not {Enabled: true})
             return;
 
-        if (_depressed && !depress)
-        {
-            // fire the action
-            OnUnpressed(args);
-        }
-
         _depressed = depress;
         DrawModeChanged();
     }