Fix ghost FOV toggling (#15751)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Content.Client.Movement.Systems;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Ghost;
|
||||
using JetBrains.Annotations;
|
||||
@@ -16,7 +17,7 @@ namespace Content.Client.Ghost
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||
[Dependency] private readonly ILightManager _lightManager = default!;
|
||||
[Dependency] private readonly IEyeManager _eye = default!;
|
||||
[Dependency] private readonly ContentEyeSystem _contentEye = default!;
|
||||
|
||||
public int AvailableGhostRoleCount { get; private set; }
|
||||
|
||||
@@ -98,7 +99,7 @@ namespace Content.Client.Ghost
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
_eye.CurrentEye.DrawFov = !_eye.CurrentEye.DrawFov;
|
||||
_contentEye.RequestToggleFov(uid);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,26 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
|
||||
});
|
||||
}
|
||||
|
||||
public void RequestToggleFov()
|
||||
{
|
||||
if (_player.LocalPlayer?.ControlledEntity is { } player)
|
||||
RequestToggleFov(player);
|
||||
}
|
||||
|
||||
public void RequestToggleFov(EntityUid uid, EyeComponent? eye = null)
|
||||
{
|
||||
if (Resolve(uid, ref eye, false))
|
||||
RequestFov(!eye.DrawFov);
|
||||
}
|
||||
|
||||
public void RequestFov(bool value)
|
||||
{
|
||||
RaisePredictiveEvent(new RequestFovEvent()
|
||||
{
|
||||
Fov = value,
|
||||
});
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Movement.Systems;
|
||||
using Content.Shared.Sandbox;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Placement;
|
||||
using Robust.Client.Placement.Modes;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Client.Sandbox
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
[Dependency] private readonly IPlacementManager _placement = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
[Dependency] private readonly ContentEyeSystem _contentEye = default!;
|
||||
|
||||
private bool _sandboxEnabled;
|
||||
public bool SandboxAllowed { get; private set; }
|
||||
@@ -132,7 +132,7 @@ namespace Content.Client.Sandbox
|
||||
|
||||
public void ToggleFov()
|
||||
{
|
||||
_consoleHost.ExecuteCommand("togglefov");
|
||||
_contentEye.RequestToggleFov();
|
||||
}
|
||||
|
||||
public void ToggleShadows()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Content.Shared.Administration.Managers;
|
||||
using Content.Shared.Ghost;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.Input;
|
||||
@@ -12,6 +14,8 @@ namespace Content.Shared.Movement.Systems;
|
||||
/// </summary>
|
||||
public abstract class SharedContentEyeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISharedAdminManager _admin = default!;
|
||||
|
||||
private const float ZoomMod = 1.2f;
|
||||
private const byte ZoomMultiple = 10;
|
||||
|
||||
@@ -24,6 +28,7 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
|
||||
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
|
||||
SubscribeAllEvent<RequestFovEvent>(OnRequestFov);
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.ZoomIn, new ScrollInputCmdHandler(true, this))
|
||||
@@ -43,6 +48,21 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
||||
Dirty(content);
|
||||
}
|
||||
|
||||
private void OnRequestFov(RequestFovEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (args.SenderSession.AttachedEntity is not { } player)
|
||||
return;
|
||||
|
||||
if (!HasComp<SharedGhostComponent>(player) && !_admin.IsAdmin(player))
|
||||
return;
|
||||
|
||||
if (TryComp<SharedEyeComponent>(player, out var eyeComp))
|
||||
{
|
||||
eyeComp.DrawFov = msg.Fov;
|
||||
Dirty(eyeComp);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
@@ -179,4 +199,13 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
||||
{
|
||||
public Vector2 TargetZoom;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sendable from client to server to request changing fov.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class RequestFovEvent : EntityEventArgs
|
||||
{
|
||||
public bool Fov;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user