Fix zoom command for aghost (#15687)
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
|
using Content.Client.Movement.Systems;
|
||||||
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.Systems;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
|
using Robust.Client.Player;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
namespace Content.Client.Commands;
|
namespace Content.Client.Commands;
|
||||||
@@ -7,7 +11,9 @@ namespace Content.Client.Commands;
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class ZoomCommand : IConsoleCommand
|
public sealed class ZoomCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||||
[Dependency] private readonly IEyeManager _eyeMan = default!;
|
[Dependency] private readonly IEyeManager _eyeMan = default!;
|
||||||
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
|
|
||||||
public string Command => "zoom";
|
public string Command => "zoom";
|
||||||
public string Description => Loc.GetString("zoom-command-description");
|
public string Description => Loc.GetString("zoom-command-description");
|
||||||
@@ -53,6 +59,14 @@ public sealed class ZoomCommand : IConsoleCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
||||||
|
|
||||||
|
if (_entManager.TryGetComponent<ContentEyeComponent>(player, out var content))
|
||||||
|
{
|
||||||
|
_entManager.System<ContentEyeSystem>().RequestZoom(player.Value, zoom, content);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_eyeMan.CurrentEye.Zoom = zoom;
|
_eyeMan.CurrentEye.Zoom = zoom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,17 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IPlayerManager _player = default!;
|
[Dependency] private readonly IPlayerManager _player = default!;
|
||||||
|
|
||||||
|
public void RequestZoom(EntityUid uid, Vector2 zoom, ContentEyeComponent? content = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref content, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
RaisePredictiveEvent(new RequestTargetZoomEvent()
|
||||||
|
{
|
||||||
|
TargetZoom = zoom,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
|||||||
@@ -9,19 +9,12 @@ public sealed class ContentEyeSystem : SharedContentEyeSystem
|
|||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
|
||||||
var eyeQuery = GetEntityQuery<SharedEyeComponent>();
|
var query = AllEntityQuery<ContentEyeComponent, SharedEyeComponent>();
|
||||||
|
|
||||||
foreach (var (_, comp) in EntityQuery<ActiveContentEyeComponent, ContentEyeComponent>(true))
|
while (query.MoveNext(out var uid, out var comp, out var eyeComp))
|
||||||
{
|
{
|
||||||
var uid = comp.Owner;
|
if (eyeComp.Zoom.Equals(comp.TargetZoom))
|
||||||
|
|
||||||
// Use a separate query jjuussstt in case any actives mistakenly hang around.
|
|
||||||
if (!eyeQuery.TryGetComponent(comp.Owner, out var eyeComp) ||
|
|
||||||
eyeComp.Zoom.Equals(comp.TargetZoom))
|
|
||||||
{
|
|
||||||
RemComp<ActiveContentEyeComponent>(comp.Owner);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
UpdateEye(uid, comp, eyeComp, frameTime);
|
UpdateEye(uid, comp, eyeComp, frameTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace Content.Shared.Movement.Components;
|
|
||||||
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class ActiveContentEyeComponent : Component
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Content.Shared.Movement.Systems;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
namespace Content.Shared.Movement.Components;
|
namespace Content.Shared.Movement.Components;
|
||||||
@@ -5,18 +6,18 @@ namespace Content.Shared.Movement.Components;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Holds SS14 eye data not relevant for engine, e.g. lerp targets.
|
/// Holds SS14 eye data not relevant for engine, e.g. lerp targets.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedContentEyeSystem))]
|
||||||
public sealed class ContentEyeComponent : Component
|
public sealed partial class ContentEyeComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Zoom we're lerping to.
|
/// Zoom we're lerping to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("targetZoom")]
|
[DataField("targetZoom"), AutoNetworkedField]
|
||||||
public Vector2 TargetZoom = Vector2.One;
|
public Vector2 TargetZoom = Vector2.One;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How far we're allowed to zoom out.
|
/// How far we're allowed to zoom out.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("maxZoom")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("maxZoom"), AutoNetworkedField]
|
||||||
public Vector2 MaxZoom = Vector2.One;
|
public Vector2 MaxZoom = Vector2.One;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Content.Shared.Movement.Components;
|
using Content.Shared.Movement.Components;
|
||||||
using Robust.Shared.GameStates;
|
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Timing;
|
|
||||||
|
|
||||||
namespace Content.Shared.Movement.Systems;
|
namespace Content.Shared.Movement.Systems;
|
||||||
|
|
||||||
@@ -24,9 +22,8 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<ContentEyeComponent, ComponentGetState>(OnGetState);
|
|
||||||
SubscribeLocalEvent<ContentEyeComponent, ComponentHandleState>(OnHandleState);
|
|
||||||
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
|
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
|
||||||
|
SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
|
||||||
|
|
||||||
CommandBinds.Builder
|
CommandBinds.Builder
|
||||||
.Bind(ContentKeyFunctions.ZoomIn, new ScrollInputCmdHandler(true, this))
|
.Bind(ContentKeyFunctions.ZoomIn, new ScrollInputCmdHandler(true, this))
|
||||||
@@ -37,6 +34,15 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
Sawmill.Level = LogLevel.Info;
|
Sawmill.Level = LogLevel.Info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnContentZoomRequest(RequestTargetZoomEvent msg, EntitySessionEventArgs args)
|
||||||
|
{
|
||||||
|
if (!TryComp<ContentEyeComponent>(args.SenderSession.AttachedEntity, out var content))
|
||||||
|
return;
|
||||||
|
|
||||||
|
content.TargetZoom = msg.TargetZoom;
|
||||||
|
Dirty(content);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
base.Shutdown();
|
base.Shutdown();
|
||||||
@@ -52,24 +58,6 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGetState(EntityUid uid, ContentEyeComponent component, ref ComponentGetState args)
|
|
||||||
{
|
|
||||||
args.State = new ContentEyeComponentState()
|
|
||||||
{
|
|
||||||
TargetZoom = component.TargetZoom,
|
|
||||||
MaxZoom = component.MaxZoom,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnHandleState(EntityUid uid, ContentEyeComponent component, ref ComponentHandleState args)
|
|
||||||
{
|
|
||||||
if (args.Current is not ContentEyeComponentState state)
|
|
||||||
return;
|
|
||||||
|
|
||||||
component.TargetZoom = state.TargetZoom;
|
|
||||||
component.MaxZoom = state.MaxZoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateEye(EntityUid uid, ContentEyeComponent content, SharedEyeComponent eye, float frameTime)
|
protected void UpdateEye(EntityUid uid, ContentEyeComponent content, SharedEyeComponent eye, float frameTime)
|
||||||
{
|
{
|
||||||
var diff = content.TargetZoom - eye.Zoom;
|
var diff = content.TargetZoom - eye.Zoom;
|
||||||
@@ -78,7 +66,6 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
eye.Zoom = content.TargetZoom;
|
eye.Zoom = content.TargetZoom;
|
||||||
Dirty(eye);
|
Dirty(eye);
|
||||||
RemComp<ActiveContentEyeComponent>(uid);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +89,6 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
component.TargetZoom = Vector2.One;
|
component.TargetZoom = Vector2.One;
|
||||||
EnsureComp<ActiveContentEyeComponent>(uid);
|
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,18 +115,10 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
component.TargetZoom = actual;
|
component.TargetZoom = actual;
|
||||||
EnsureComp<ActiveContentEyeComponent>(uid);
|
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
Sawmill.Debug($"Set target zoom to {actual}");
|
Sawmill.Debug($"Set target zoom to {actual}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
private sealed class ContentEyeComponentState : ComponentState
|
|
||||||
{
|
|
||||||
public Vector2 TargetZoom;
|
|
||||||
public Vector2 MaxZoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class ResetZoomInputCmdHandler : InputCmdHandler
|
private sealed class ResetZoomInputCmdHandler : InputCmdHandler
|
||||||
{
|
{
|
||||||
private readonly SharedContentEyeSystem _system;
|
private readonly SharedContentEyeSystem _system;
|
||||||
@@ -192,4 +170,13 @@ public abstract class SharedContentEyeSystem : EntitySystem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sendable from client to server to request a target zoom.
|
||||||
|
/// </summary>
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class RequestTargetZoomEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public Vector2 TargetZoom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user