Action UI fixes (#27468)
This commit is contained in:
@@ -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,6 +522,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
||||
button.ClearData();
|
||||
if (_container?.TryGetButtonIndex(button, out position) ?? false)
|
||||
{
|
||||
if (_actions.Count > position && position >= 0)
|
||||
_actions.RemoveAt(position);
|
||||
}
|
||||
}
|
||||
@@ -539,23 +546,22 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
|
||||
|
||||
private void DragAction()
|
||||
{
|
||||
EntityUid? swapAction = null;
|
||||
if (UIManager.CurrentlyHovered is ActionButton button)
|
||||
{
|
||||
if (!_menuDragHelper.IsDragging || _menuDragHelper.Dragged?.ActionId is not { } type)
|
||||
if (_menuDragHelper.Dragged is not {ActionId: {} action} dragged)
|
||||
{
|
||||
_menuDragHelper.EndDrag();
|
||||
return;
|
||||
}
|
||||
|
||||
EntityUid? swapAction = null;
|
||||
var currentlyHovered = UIManager.MouseGetControl(_input.MouseScreenPosition);
|
||||
if (currentlyHovered is ActionButton button)
|
||||
{
|
||||
swapAction = button.ActionId;
|
||||
SetAction(button, type, false);
|
||||
SetAction(button, action, false);
|
||||
}
|
||||
|
||||
if (_menuDragHelper.Dragged is {Parent: ActionButtonContainer} old)
|
||||
{
|
||||
SetAction(old, swapAction, false);
|
||||
}
|
||||
if (dragged.Parent is ActionButtonContainer)
|
||||
SetAction(dragged, swapAction, false);
|
||||
|
||||
if (_actionsSystem != null)
|
||||
_container?.SetActionData(_actionsSystem, _actions.ToArray());
|
||||
@@ -610,61 +616,59 @@ 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)
|
||||
SetAction(button, null);
|
||||
args.Handle();
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Function != EngineKeyFunctions.UIClick)
|
||||
return;
|
||||
|
||||
args.Handle();
|
||||
if (button.ActionId != null)
|
||||
{
|
||||
_menuDragHelper.MouseDown(button);
|
||||
return;
|
||||
}
|
||||
|
||||
var ev = new FillActionSlotEvent();
|
||||
EntityManager.EventBus.RaiseEvent(EventSource.Local, ev);
|
||||
if (ev.Action != null)
|
||||
SetAction(button, ev.Action);
|
||||
}
|
||||
else
|
||||
{
|
||||
_menuDragHelper.MouseDown(button);
|
||||
}
|
||||
|
||||
args.Handle();
|
||||
}
|
||||
else if (args.Function == EngineKeyFunctions.UIRightClick)
|
||||
{
|
||||
SetAction(button, null);
|
||||
args.Handle();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnActionUnpressed(GUIBoundKeyEventArgs args, ActionButton button)
|
||||
{
|
||||
if (args.Function != EngineKeyFunctions.UIClick || _actionsSystem == null)
|
||||
return;
|
||||
|
||||
//todo: make dragging onto the same spot NOT trigger again
|
||||
if (UIManager.CurrentlyHovered == button)
|
||||
args.Handle();
|
||||
|
||||
if (_menuDragHelper.IsDragging)
|
||||
{
|
||||
DragAction();
|
||||
return;
|
||||
}
|
||||
|
||||
_menuDragHelper.EndDrag();
|
||||
|
||||
if (_actionsSystem.TryGetActionData(button.ActionId, out var baseAction))
|
||||
{
|
||||
if (baseAction is BaseTargetActionComponent action)
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
_actionsSystem?.TriggerAction(button.ActionId.Value, baseAction);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DragAction();
|
||||
}
|
||||
|
||||
args.Handle();
|
||||
}
|
||||
|
||||
private bool OnMenuBeginDrag()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user