Viewport improvements (#3765)
This commit is contained in:
committed by
GitHub
parent
8e2fc49357
commit
147a54c642
@@ -2,14 +2,15 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.Components;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.State;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
@@ -28,7 +29,6 @@ namespace Content.Client.State
|
||||
[Dependency] protected readonly IClientEntityManager EntityManager = default!;
|
||||
[Dependency] protected readonly IInputManager InputManager = default!;
|
||||
[Dependency] protected readonly IPlayerManager PlayerManager = default!;
|
||||
[Dependency] protected readonly IEyeManager EyeManager = default!;
|
||||
[Dependency] protected readonly IEntitySystemManager EntitySystemManager = default!;
|
||||
[Dependency] protected readonly IGameTiming Timing = default!;
|
||||
[Dependency] protected readonly IMapManager MapManager = default!;
|
||||
@@ -68,10 +68,18 @@ namespace Content.Client.State
|
||||
if (localPlayer == null)
|
||||
return;
|
||||
|
||||
var mousePosWorld = EyeManager.ScreenToMap(InputManager.MouseScreenPosition);
|
||||
var entityToClick = UserInterfaceManager.CurrentlyHovered != null
|
||||
? null
|
||||
: GetEntityUnderPosition(mousePosWorld);
|
||||
IEntity? entityToClick = null;
|
||||
var renderScale = 1;
|
||||
if (UserInterfaceManager.CurrentlyHovered is IViewportControl vp)
|
||||
{
|
||||
var mousePosWorld = vp.ScreenToMap(InputManager.MouseScreenPosition);
|
||||
entityToClick = GetEntityUnderPosition(mousePosWorld);
|
||||
|
||||
if (vp is ScalingViewport svp)
|
||||
{
|
||||
renderScale = svp.CurrentRenderScale;
|
||||
}
|
||||
}
|
||||
|
||||
var inRange = false;
|
||||
if (localPlayer.ControlledEntity != null && entityToClick != null)
|
||||
@@ -93,7 +101,7 @@ namespace Content.Client.State
|
||||
{
|
||||
if (entityToClick != null && entityToClick.TryGetComponent(out outline))
|
||||
{
|
||||
outline.UpdateInRange(inRange);
|
||||
outline.UpdateInRange(inRange, renderScale);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -109,7 +117,7 @@ namespace Content.Client.State
|
||||
|
||||
if (_lastHoveredEntity != null && _lastHoveredEntity.TryGetComponent(out outline))
|
||||
{
|
||||
outline.OnMouseEnter(inRange);
|
||||
outline.OnMouseEnter(inRange, renderScale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,30 +214,36 @@ namespace Content.Client.State
|
||||
/// Converts a state change event from outside the simulation to inside the simulation.
|
||||
/// </summary>
|
||||
/// <param name="args">Event data values for a bound key state change.</param>
|
||||
private void OnKeyBindStateChanged(BoundKeyEventArgs args)
|
||||
private void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
|
||||
{
|
||||
// If there is no InputSystem, then there is nothing to forward to, and nothing to do here.
|
||||
if(!EntitySystemManager.TryGetEntitySystem(out InputSystem inputSys))
|
||||
return;
|
||||
|
||||
var func = args.Function;
|
||||
var kArgs = args.KeyEventArgs;
|
||||
var func = kArgs.Function;
|
||||
var funcId = InputManager.NetworkBindMap.KeyFunctionID(func);
|
||||
|
||||
var mousePosWorld = EyeManager.ScreenToMap(args.PointerLocation);
|
||||
var entityToClick = GetEntityUnderPosition(mousePosWorld);
|
||||
EntityCoordinates coordinates = default;
|
||||
EntityUid entityToClick = default;
|
||||
if (args.Viewport is IViewportControl vp)
|
||||
{
|
||||
var mousePosWorld = vp.ScreenToMap(kArgs.PointerLocation.Position);
|
||||
entityToClick = GetEntityUnderPosition(mousePosWorld)?.Uid ?? EntityUid.Invalid;
|
||||
|
||||
var coordinates = MapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) :
|
||||
EntityCoordinates.FromMap(EntityManager, MapManager, mousePosWorld);
|
||||
coordinates = MapManager.TryFindGridAt(mousePosWorld, out var grid) ? grid.MapToGrid(mousePosWorld) :
|
||||
EntityCoordinates.FromMap(EntityManager, MapManager, mousePosWorld);
|
||||
}
|
||||
|
||||
var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, args.State,
|
||||
coordinates , args.PointerLocation,
|
||||
entityToClick?.Uid ?? EntityUid.Invalid);
|
||||
var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, kArgs.State,
|
||||
coordinates , kArgs.PointerLocation,
|
||||
entityToClick);
|
||||
|
||||
// client side command handlers will always be sent the local player session.
|
||||
var session = PlayerManager.LocalPlayer?.Session;
|
||||
if (inputSys.HandleInputCommand(session, func, message))
|
||||
{
|
||||
args.Handle();
|
||||
kArgs.Handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user