From 3cedcaf004d8f64b4c05f03d20639367bc08861e Mon Sep 17 00:00:00 2001 From: ComicIronic Date: Fri, 12 Jun 2020 17:36:25 +0100 Subject: [PATCH] Silence ScreenToWorld warnings (#1098) This fixes one case of GridCoordinates being used unnecessarily, in GameScreenBase. It replaces other cases with explicit calls to TryFindGridAt and GetDefaultGrid. --- .../EntitySystems/RangedWeaponSystem.cs | 9 ++++++-- Content.Client/State/GameScreenBase.cs | 23 +++++++++++++------ .../UserInterface/ItemSlotManager.cs | 11 ++++++--- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs b/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs index 04b6f11730..dcd874bd84 100644 --- a/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs @@ -6,6 +6,7 @@ using Robust.Client.Interfaces.Input; using Robust.Client.Player; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; +using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Log; @@ -18,6 +19,7 @@ namespace Content.Client.GameObjects.EntitySystems #pragma warning disable 649 [Dependency] private readonly IPlayerManager _playerManager; [Dependency] private readonly IEyeManager _eyeManager; + [Dependency] private readonly IMapManager _mapManager; [Dependency] private readonly IInputManager _inputManager; [Dependency] private readonly IGameTiming _gameTiming; #pragma warning restore 649 @@ -74,11 +76,14 @@ namespace Content.Client.GameObjects.EntitySystems return; } - var worldPos = _eyeManager.ScreenToWorld(_inputManager.MouseScreenPosition); + var worldPos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition); + + if (!_mapManager.TryFindGridAt(worldPos, out var grid)) + grid = _mapManager.GetDefaultGrid(worldPos.MapId); if (weapon.Automatic || canFireSemi) { - weapon.SyncFirePos(worldPos); + weapon.SyncFirePos(grid.MapToGrid(worldPos)); } } } diff --git a/Content.Client/State/GameScreenBase.cs b/Content.Client/State/GameScreenBase.cs index e426a8ce6a..d01db8f42f 100644 --- a/Content.Client/State/GameScreenBase.cs +++ b/Content.Client/State/GameScreenBase.cs @@ -53,7 +53,7 @@ namespace Content.Client.State { base.FrameUpdate(e); - var mousePosWorld = _eyeManager.ScreenToWorld(_inputManager.MouseScreenPosition); + var mousePosWorld = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition); var entityToClick = _userInterfaceManager.CurrentlyHovered != null ? null : GetEntityUnderPosition(mousePosWorld); var inRange = false; @@ -89,17 +89,21 @@ namespace Content.Client.State } } - public IEntity GetEntityUnderPosition(GridCoordinates coordinates) + public IEntity GetEntityUnderPosition(MapCoordinates coordinates) { var entitiesUnderPosition = GetEntitiesUnderPosition(coordinates); return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : null; } public IList GetEntitiesUnderPosition(GridCoordinates coordinates) + { + return GetEntitiesUnderPosition(coordinates.ToMap(_mapManager)); + } + + public IList GetEntitiesUnderPosition(MapCoordinates coordinates) { // Find all the entities intersecting our click - var mapCoords = coordinates.ToMap(_mapManager); - var entities = _entityManager.GetEntitiesIntersecting(mapCoords.MapId, mapCoords.Position); + var entities = _entityManager.GetEntitiesIntersecting(coordinates.MapId, coordinates.Position); // Check the entities against whether or not we can click them var foundEntities = new List<(IEntity clicked, int drawDepth)>(); @@ -149,10 +153,15 @@ namespace Content.Client.State var func = args.Function; var funcId = _inputManager.NetworkBindMap.KeyFunctionID(func); - var mousePosWorld = _eyeManager.ScreenToWorld(args.PointerLocation); + var mousePosWorld = _eyeManager.ScreenToMap(args.PointerLocation); var entityToClick = GetEntityUnderPosition(mousePosWorld); - var message = new FullInputCmdMessage(_timing.CurTick, funcId, args.State, mousePosWorld, - args.PointerLocation, entityToClick?.Uid ?? EntityUid.Invalid); + + if (!_mapManager.TryFindGridAt(mousePosWorld, out var grid)) + grid = _mapManager.GetDefaultGrid(mousePosWorld.MapId); + + var message = new FullInputCmdMessage(_timing.CurTick, funcId, args.State, + grid.MapToGrid(mousePosWorld), args.PointerLocation, + entityToClick?.Uid ?? EntityUid.Invalid); // client side command handlers will always be sent the local player session. var session = _playerManager.LocalPlayer.Session; diff --git a/Content.Client/UserInterface/ItemSlotManager.cs b/Content.Client/UserInterface/ItemSlotManager.cs index 69a7736b55..c5eb215fab 100644 --- a/Content.Client/UserInterface/ItemSlotManager.cs +++ b/Content.Client/UserInterface/ItemSlotManager.cs @@ -15,6 +15,7 @@ using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Shared.Input; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; using Robust.Shared.Map; @@ -30,6 +31,7 @@ namespace Content.Client.UserInterface [Dependency] private readonly IInputManager _inputManager; [Dependency] private readonly IEntitySystemManager _entitySystemManager; [Dependency] private readonly IEyeManager _eyeManager; + [Dependency] private readonly IMapManager _mapManager; #pragma warning restore 0649 public bool SetItemSlot(ItemSlotButton button, IEntity entity) @@ -71,9 +73,12 @@ namespace Content.Client.UserInterface var func = args.Function; var funcId = _inputManager.NetworkBindMap.KeyFunctionID(args.Function); - var mousePosWorld = _eyeManager.ScreenToWorld(args.PointerLocation); - var message = new FullInputCmdMessage(_gameTiming.CurTick, funcId, BoundKeyState.Down, mousePosWorld, - args.PointerLocation, item.Uid); + var mousePosWorld = _eyeManager.ScreenToMap(args.PointerLocation); + if (!_mapManager.TryFindGridAt(mousePosWorld, out var grid)) + grid = _mapManager.GetDefaultGrid(mousePosWorld.MapId); + + var message = new FullInputCmdMessage(_gameTiming.CurTick, funcId, BoundKeyState.Down, + grid.MapToGrid(mousePosWorld), args.PointerLocation, item.Uid); // client side command handlers will always be sent the local player session. var session = _playerManager.LocalPlayer.Session;