From ad72eea8a14a79a02f3a49ac1fc74bf008db205c Mon Sep 17 00:00:00 2001 From: Aviu00 <93730715+Aviu00@users.noreply.github.com> Date: Sun, 2 Jun 2024 17:50:04 +0000 Subject: [PATCH] - add: Cleanup TelescopeSystem. (#325) --- .../_White/Telescope/TelescopeSystem.cs | 25 ++++++++++++++----- .../_White/Telescope/TelescopeSystem.cs | 4 ++- .../_White/Telescope/SharedTelescopeSystem.cs | 4 ++- .../_White/Telescope/TelescopeComponent.cs | 5 +++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Content.Client/_White/Telescope/TelescopeSystem.cs b/Content.Client/_White/Telescope/TelescopeSystem.cs index 22f4ad5f3f..2e2f3f4901 100644 --- a/Content.Client/_White/Telescope/TelescopeSystem.cs +++ b/Content.Client/_White/Telescope/TelescopeSystem.cs @@ -1,10 +1,12 @@ using System.Numerics; +using Content.Client.Viewport; using Content.Shared._White.Telescope; using Content.Shared.Hands.Components; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.Input; using Robust.Client.Player; +using Robust.Client.UserInterface; using Robust.Shared.Input; using Robust.Shared.Timing; @@ -17,7 +19,9 @@ public sealed class TelescopeSystem : SharedTelescopeSystem [Dependency] private readonly IPlayerManager _player = default!; [Dependency] private readonly IInputManager _input = 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) { @@ -44,14 +48,23 @@ public sealed class TelescopeSystem : SharedTelescopeSystem 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 diff = mousePos - centerPos; + var diff = mousePos.Position - centerPos; var len = diff.Length(); - var maxLength = _displayManager.ScreenSize.Y / 2.5f; - var minLength = maxLength / 5f; + var size = _viewport.PixelSize; + + var maxLength = Math.Min(size.X, size.Y) * 0.4f; + var minLength = maxLength * 0.2f; if (len > maxLength) { @@ -59,7 +72,7 @@ public sealed class TelescopeSystem : SharedTelescopeSystem len = maxLength; } - var divisor = maxLength / 10f * telescope.Divisor; + var divisor = maxLength * telescope.Divisor; if (len > minLength) { diff --git a/Content.Server/_White/Telescope/TelescopeSystem.cs b/Content.Server/_White/Telescope/TelescopeSystem.cs index 7320c67694..d04cf22b5c 100644 --- a/Content.Server/_White/Telescope/TelescopeSystem.cs +++ b/Content.Server/_White/Telescope/TelescopeSystem.cs @@ -1,5 +1,7 @@ +using Content.Shared._White.Telescope; + namespace Content.Server._White.Telescope; -public sealed class TelescopeSystem : EntitySystem +public sealed class TelescopeSystem : SharedTelescopeSystem { } diff --git a/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs b/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs index a6fd829922..4bb6f39053 100644 --- a/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs +++ b/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs @@ -54,7 +54,9 @@ public abstract class SharedTelescopeSystem : EntitySystem !TryComp(ent, out EyeComponent? eye)) 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 ent, Vector2 offset, TelescopeComponent telescope) diff --git a/Content.Shared/_White/Telescope/TelescopeComponent.cs b/Content.Shared/_White/Telescope/TelescopeComponent.cs index 56f39e060b..960ef80c52 100644 --- a/Content.Shared/_White/Telescope/TelescopeComponent.cs +++ b/Content.Shared/_White/Telescope/TelescopeComponent.cs @@ -6,7 +6,10 @@ namespace Content.Shared._White.Telescope; public sealed partial class TelescopeComponent : Component { [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] public EntityUid? LastHoldingEntity;