+using Content.Client.Movement.Systems;
+using Content.Shared.Movement.Components;
+using Content.Shared.Movement.Systems;
using JetBrains.Annotations;
using Robust.Client.Graphics;
+using Robust.Client.Player;
using Robust.Shared.Console;
namespace Content.Client.Commands;
[UsedImplicitly]
public sealed class ZoomCommand : IConsoleCommand
{
+ [Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IEyeManager _eyeMan = default!;
+ [Dependency] private readonly IPlayerManager _playerManager = default!;
public string Command => "zoom";
public string Description => Loc.GetString("zoom-command-description");
}
}
+ 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;
}
}
{
[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)
{
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;
-
- // 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);
+ if (eyeComp.Zoom.Equals(comp.TargetZoom))
continue;
- }
UpdateEye(uid, comp, eyeComp, frameTime);
}
+++ /dev/null
-namespace Content.Shared.Movement.Components;
-
-[RegisterComponent]
-public sealed class ActiveContentEyeComponent : Component
-{
-
-}
+using Content.Shared.Movement.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Movement.Components;
/// <summary>
/// Holds SS14 eye data not relevant for engine, e.g. lerp targets.
/// </summary>
-[RegisterComponent, NetworkedComponent]
-public sealed class ContentEyeComponent : Component
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedContentEyeSystem))]
+public sealed partial class ContentEyeComponent : Component
{
/// <summary>
/// Zoom we're lerping to.
/// </summary>
- [DataField("targetZoom")]
+ [DataField("targetZoom"), AutoNetworkedField]
public Vector2 TargetZoom = Vector2.One;
/// <summary>
/// How far we're allowed to zoom out.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField("maxZoom")]
+ [ViewVariables(VVAccess.ReadWrite), DataField("maxZoom"), AutoNetworkedField]
public Vector2 MaxZoom = Vector2.One;
}
using Content.Shared.Input;
using Content.Shared.Movement.Components;
-using Robust.Shared.GameStates;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
-using Robust.Shared.Timing;
namespace Content.Shared.Movement.Systems;
public override void Initialize()
{
base.Initialize();
- SubscribeLocalEvent<ContentEyeComponent, ComponentGetState>(OnGetState);
- SubscribeLocalEvent<ContentEyeComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<ContentEyeComponent, ComponentStartup>(OnContentEyeStartup);
+ SubscribeAllEvent<RequestTargetZoomEvent>(OnContentZoomRequest);
CommandBinds.Builder
.Bind(ContentKeyFunctions.ZoomIn, new ScrollInputCmdHandler(true, this))
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()
{
base.Shutdown();
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)
{
var diff = content.TargetZoom - eye.Zoom;
{
eye.Zoom = content.TargetZoom;
Dirty(eye);
- RemComp<ActiveContentEyeComponent>(uid);
return;
}
return;
component.TargetZoom = Vector2.One;
- EnsureComp<ActiveContentEyeComponent>(uid);
Dirty(component);
}
return;
component.TargetZoom = actual;
- EnsureComp<ActiveContentEyeComponent>(uid);
Dirty(component);
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 readonly SharedContentEyeSystem _system;
return false;
}
}
+
+ /// <summary>
+ /// Sendable from client to server to request a target zoom.
+ /// </summary>
+ [Serializable, NetSerializable]
+ public sealed class RequestTargetZoomEvent : EntityEventArgs
+ {
+ public Vector2 TargetZoom;
+ }
}