- add: Cleanup TelescopeSystem. (#325)

This commit is contained in:
Aviu00
2024-06-02 17:50:04 +00:00
committed by GitHub
parent 981a83799e
commit ad72eea8a1
4 changed files with 29 additions and 9 deletions

View File

@@ -1,10 +1,12 @@
using System.Numerics; using System.Numerics;
using Content.Client.Viewport;
using Content.Shared._White.Telescope; using Content.Shared._White.Telescope;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Input; using Robust.Client.Input;
using Robust.Client.Player; using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Shared.Input; using Robust.Shared.Input;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -17,7 +19,9 @@ public sealed class TelescopeSystem : SharedTelescopeSystem
[Dependency] private readonly IPlayerManager _player = default!; [Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IInputManager _input = default!; [Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IClyde _displayManager = default!; [Dependency] private readonly IUserInterfaceManager _uiManager = default!;
private ScalingViewport? _viewport;
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
@@ -44,14 +48,23 @@ public sealed class TelescopeSystem : SharedTelescopeSystem
return; return;
} }
var mousePos = _input.MouseScreenPosition.Position; var mousePos = _input.MouseScreenPosition;
if (_uiManager.MouseGetControl(mousePos) as ScalingViewport is { } viewport)
_viewport = viewport;
if (_viewport == null)
return;
var centerPos = _eyeManager.WorldToScreen(eye.Eye.Position.Position + eye.Offset); var centerPos = _eyeManager.WorldToScreen(eye.Eye.Position.Position + eye.Offset);
var diff = mousePos - centerPos; var diff = mousePos.Position - centerPos;
var len = diff.Length(); var len = diff.Length();
var maxLength = _displayManager.ScreenSize.Y / 2.5f; var size = _viewport.PixelSize;
var minLength = maxLength / 5f;
var maxLength = Math.Min(size.X, size.Y) * 0.4f;
var minLength = maxLength * 0.2f;
if (len > maxLength) if (len > maxLength)
{ {
@@ -59,7 +72,7 @@ public sealed class TelescopeSystem : SharedTelescopeSystem
len = maxLength; len = maxLength;
} }
var divisor = maxLength / 10f * telescope.Divisor; var divisor = maxLength * telescope.Divisor;
if (len > minLength) if (len > minLength)
{ {

View File

@@ -1,5 +1,7 @@
using Content.Shared._White.Telescope;
namespace Content.Server._White.Telescope; namespace Content.Server._White.Telescope;
public sealed class TelescopeSystem : EntitySystem public sealed class TelescopeSystem : SharedTelescopeSystem
{ {
} }

View File

@@ -54,7 +54,9 @@ public abstract class SharedTelescopeSystem : EntitySystem
!TryComp(ent, out EyeComponent? eye)) !TryComp(ent, out EyeComponent? eye))
return; return;
SetOffset((ent, eye), msg.Offset, telescope); var offset = Vector2.Lerp(eye.Offset, msg.Offset, telescope.LerpAmount);
SetOffset((ent, eye), offset, telescope);
} }
private void SetOffset(Entity<EyeComponent> ent, Vector2 offset, TelescopeComponent telescope) private void SetOffset(Entity<EyeComponent> ent, Vector2 offset, TelescopeComponent telescope)

View File

@@ -6,7 +6,10 @@ namespace Content.Shared._White.Telescope;
public sealed partial class TelescopeComponent : Component public sealed partial class TelescopeComponent : Component
{ {
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Divisor = 1f; public float Divisor = 0.1f;
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float LerpAmount = 0.1f;
[ViewVariables] [ViewVariables]
public EntityUid? LastHoldingEntity; public EntityUid? LastHoldingEntity;