]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix ghost FOV toggling (#15751)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Tue, 25 Apr 2023 01:11:42 +0000 (13:11 +1200)
committerGitHub <noreply@github.com>
Tue, 25 Apr 2023 01:11:42 +0000 (11:11 +1000)
Content.Client/Ghost/GhostSystem.cs
Content.Client/Movement/Systems/ContentEyeSystem.cs
Content.Client/Sandbox/SandboxSystem.cs
Content.Shared/Movement/Systems/SharedContentEyeSystem.cs

index e93735fad9fa728b575d49aada1fb314a6e9f34c..d46c9639fea956431b846744a05ffe6b8275cee8 100644 (file)
@@ -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;
         }
 
index 9e7345e199778a9c9cbbefa8527af7fccbac3b32..c6de5984081a4c58b8b28a7dff4afe7bd64f07e8 100644 (file)
@@ -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);
index e52648609e879317db66ce204c8fed5b03f1edfa..9ffd7e52587b152439159666c4abfd3801500f94 100644 (file)
@@ -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()
index e58a7f81d75e8b7826f564787c6a1185b983f3aa..456792c853898576bd4665461a827a545b6c84a7 100644 (file)
@@ -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;
+    }
 }