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;
[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;
{
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());
}
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) &&
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());
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)
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()