From d796dcfcca04ced810c2a8203bb9427931bda2ea Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Sun, 2 May 2021 20:48:00 +0200 Subject: [PATCH] Multi-window input handling. (#3911) --- Content.Client/ClientNotifyManager.cs | 4 ++-- .../GameObjects/EntitySystems/DoAfter/DoAfterGui.cs | 2 +- Content.Client/GameObjects/EntitySystems/ExamineSystem.cs | 2 +- .../EntitySystems/HealthOverlay/HealthOverlayGui.cs | 2 +- Content.Client/GameObjects/EntitySystems/VerbSystem.cs | 2 +- Content.Client/State/GameScreenBase.cs | 2 +- Content.Client/UserInterface/ActionMenu.cs | 4 ++-- Content.Client/UserInterface/ActionsUI.cs | 4 ++-- .../UserInterface/ContextMenu/ContextMenuView.cs | 2 +- Content.Client/UserInterface/ItemSlotManager.cs | 2 +- Content.Client/Utility/DragDropHelper.cs | 8 ++++---- RobustToolbox | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Content.Client/ClientNotifyManager.cs b/Content.Client/ClientNotifyManager.cs index 5bbe778b29..544c8a38c8 100644 --- a/Content.Client/ClientNotifyManager.cs +++ b/Content.Client/ClientNotifyManager.cs @@ -104,14 +104,14 @@ namespace Content.Client label.Measure(Vector2.Infinity); var minimumSize = label.DesiredSize; - label.InitialPos = (coordinates.Position / _userInterfaceManager.UIScale) - minimumSize / 2; + label.InitialPos = (coordinates.Position / label.UIScale) - minimumSize / 2; LayoutContainer.SetPosition(label, label.InitialPos); _aliveLabels.Add(label); } public void PopupMessage(string message) { - PopupMessage(new ScreenCoordinates(_userInterfaceManager.MousePositionScaled), message); + PopupMessage(_userInterfaceManager.MousePositionScaled, message); } public void FrameUpdate(FrameEventArgs eventArgs) diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs index 530c98d2ea..6990470eca 100644 --- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs +++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs @@ -210,7 +210,7 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter } var screenCoordinates = _eyeManager.CoordinatesToScreen(AttachedEntity.Transform.Coordinates); - _playerPosition = new ScreenCoordinates(screenCoordinates.X / UIScale, screenCoordinates.Y / UIScale); + _playerPosition = new ScreenCoordinates(screenCoordinates.Position / UIScale, screenCoordinates.Window); LayoutContainer.SetPosition(this, new Vector2(_playerPosition.X - Width / 2, _playerPosition.Y - Height - 30.0f)); } } diff --git a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs index 9c217e98c4..a893c53819 100644 --- a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs @@ -96,7 +96,7 @@ namespace Content.Client.GameObjects.EntitySystems panel.Measure(Vector2.Infinity); var size = Vector2.ComponentMax((minWidth, 0), panel.DesiredSize); - _examineTooltipOpen.Open(UIBox2.FromDimensions(popupPos, size)); + _examineTooltipOpen.Open(UIBox2.FromDimensions(popupPos.Position, size)); FormattedMessage message; if (entity.Uid.IsClientSide()) diff --git a/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs b/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs index 3480d32381..da35fc2e3d 100644 --- a/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs +++ b/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs @@ -147,7 +147,7 @@ namespace Content.Client.GameObjects.EntitySystems.HealthOverlay Visible = true; var screenCoordinates = _eyeManager.CoordinatesToScreen(Entity.Transform.Coordinates); - var playerPosition = new ScreenCoordinates(screenCoordinates.X / UIScale, screenCoordinates.Y / UIScale); + var playerPosition = UserInterfaceManager.ScreenToUIPosition(screenCoordinates); LayoutContainer.SetPosition(this, new Vector2(playerPosition.X - Width / 2, playerPosition.Y - Height - 30.0f)); } diff --git a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs index 613e9b1cb1..1fdb1ae2d5 100644 --- a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs @@ -119,7 +119,7 @@ namespace Content.Client.GameObjects.EntitySystems public void OnContextButtonPressed(IEntity entity) { - OpenContextMenu(entity, new ScreenCoordinates(_userInterfaceManager.MousePositionScaled)); + OpenContextMenu(entity, _userInterfaceManager.MousePositionScaled); } private void FillEntityPopup(VerbSystemMessages.VerbsResponseMessage msg) diff --git a/Content.Client/State/GameScreenBase.cs b/Content.Client/State/GameScreenBase.cs index 230e49c9d4..72b8ac8f24 100644 --- a/Content.Client/State/GameScreenBase.cs +++ b/Content.Client/State/GameScreenBase.cs @@ -72,7 +72,7 @@ namespace Content.Client.State var renderScale = 1; if (UserInterfaceManager.CurrentlyHovered is IViewportControl vp) { - var mousePosWorld = vp.ScreenToMap(InputManager.MouseScreenPosition); + var mousePosWorld = vp.ScreenToMap(InputManager.MouseScreenPosition.Position); entityToClick = GetEntityUnderPosition(mousePosWorld); if (vp is ScalingViewport svp) diff --git a/Content.Client/UserInterface/ActionMenu.cs b/Content.Client/UserInterface/ActionMenu.cs index fda8e7ad9d..6ae2592b7a 100644 --- a/Content.Client/UserInterface/ActionMenu.cs +++ b/Content.Client/UserInterface/ActionMenu.cs @@ -198,14 +198,14 @@ namespace Content.Client.UserInterface { _dragShadow.Texture = _dragDropHelper.Dragged!.Action.Icon.Frame0(); // don't make visible until frameupdate, otherwise it'll flicker - LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled - (32, 32)); + LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled.Position - (32, 32)); return true; } private bool OnContinueActionDrag(float frameTime) { // keep dragged entity centered under mouse - LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled - (32, 32)); + LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled.Position - (32, 32)); // we don't set this visible until frameupdate, otherwise it flickers _dragShadow.Visible = true; return true; diff --git a/Content.Client/UserInterface/ActionsUI.cs b/Content.Client/UserInterface/ActionsUI.cs index 322b4fc894..308e6d79b0 100644 --- a/Content.Client/UserInterface/ActionsUI.cs +++ b/Content.Client/UserInterface/ActionsUI.cs @@ -533,7 +533,7 @@ namespace Content.Client.UserInterface if (Locked || DragDropHelper.Dragged?.Action == null) return false; _dragShadow.Texture = DragDropHelper.Dragged.Action.Icon.Frame0(); - LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled - (32, 32)); + LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled.Position - (32, 32)); DragDropHelper.Dragged.CancelPress(); return true; } @@ -544,7 +544,7 @@ namespace Content.Client.UserInterface if (Locked || DragDropHelper.Dragged?.Action == null) return false; // keep dragged entity centered under mouse - LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled - (32, 32)); + LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled.Position - (32, 32)); // we don't set this visible until frameupdate, otherwise it flickers _dragShadow.Visible = true; return true; diff --git a/Content.Client/UserInterface/ContextMenu/ContextMenuView.cs b/Content.Client/UserInterface/ContextMenu/ContextMenuView.cs index 3d7bacd94e..bdf837dbaf 100644 --- a/Content.Client/UserInterface/ContextMenu/ContextMenuView.cs +++ b/Content.Client/UserInterface/ContextMenu/ContextMenuView.cs @@ -79,7 +79,7 @@ namespace Content.Client.UserInterface.ContextMenu _userInterfaceManager.ModalRoot.AddChild(rootContextMenu); var size = rootContextMenu.List.CombinedMinimumSize; - var box = UIBox2.FromDimensions(_userInterfaceManager.MousePositionScaled, size); + var box = UIBox2.FromDimensions(_userInterfaceManager.MousePositionScaled.Position, size); rootContextMenu.Open(box); } public void AddChildMenu(IEnumerable entities, Vector2 position, StackContextElement? stack) diff --git a/Content.Client/UserInterface/ItemSlotManager.cs b/Content.Client/UserInterface/ItemSlotManager.cs index 437d5036e7..382195c0f8 100644 --- a/Content.Client/UserInterface/ItemSlotManager.cs +++ b/Content.Client/UserInterface/ItemSlotManager.cs @@ -59,7 +59,7 @@ namespace Content.Client.UserInterface else if (args.Function == ContentKeyFunctions.OpenContextMenu) { _entitySystemManager.GetEntitySystem() - .OpenContextMenu(item, new ScreenCoordinates(_uiMgr.ScreenToUIPosition(args.PointerLocation))); + .OpenContextMenu(item, _uiMgr.ScreenToUIPosition(args.PointerLocation)); } else if (args.Function == ContentKeyFunctions.ActivateItemInWorld) { diff --git a/Content.Client/Utility/DragDropHelper.cs b/Content.Client/Utility/DragDropHelper.cs index d116a9a29f..917bfb8335 100644 --- a/Content.Client/Utility/DragDropHelper.cs +++ b/Content.Client/Utility/DragDropHelper.cs @@ -1,6 +1,6 @@ using Robust.Client.Input; using Robust.Shared.IoC; -using Robust.Shared.Maths; +using Robust.Shared.Map; namespace Content.Client.Utility { @@ -33,7 +33,7 @@ namespace Content.Client.Utility /// /// Convenience method, current mouse screen position as provided by inputmanager. /// - public Vector2 MouseScreenPosition => _inputManager.MouseScreenPosition; + public ScreenCoordinates MouseScreenPosition => _inputManager.MouseScreenPosition; /// /// True if initiated a drag and currently dragging something. @@ -48,7 +48,7 @@ namespace Content.Client.Utility public T? Dragged { get; private set; } // screen pos where the mouse down began for the drag - private Vector2 _mouseDownScreenPos; + private ScreenCoordinates _mouseDownScreenPos; private DragState _state = DragState.NotDragging; private enum DragState : byte @@ -128,7 +128,7 @@ namespace Content.Client.Utility case DragState.MouseDown: { var screenPos = _inputManager.MouseScreenPosition; - if ((_mouseDownScreenPos - screenPos).Length > _deadzone) + if ((_mouseDownScreenPos.Position - screenPos.Position).Length > _deadzone) { StartDragging(); } diff --git a/RobustToolbox b/RobustToolbox index 7c008e857d..5f31036ab2 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 7c008e857d305b8d6e617113cebdfc77d0ab52b9 +Subproject commit 5f31036ab2fc3587f060e27c6964fe318267d568