Files
wwdpublic/Content.Client/Telescope/TelescopeSystem.cs
VMSolidus e3639f793a Better Lying Down System (From White Dream) (#815)
# Description

Port of https://github.com/WWhiteDreamProject/wwdpublic/pull/2
And now also https://github.com/WWhiteDreamProject/wwdpublic/pull/8
Because Lying Down System is dependent on the Telescope System.

# TODO

- [x] Reconcile the code with core code, do code cleanup. I'll undraft
this when I'm done. Probably not going to be tonight, because I will
have to get some sleep soon to get up early for my calculus classes.

# Changelog

🆑 Spatison (White Dream)
- add: Added lying down system / Добавлена система лежания
- tweak: Lying down now uses do-afters that are visible to other people
to indicate what is going on.
- add: Added telescope system / Добавлена система прицеливания
- tweak: Now you can aim from Hristov / Теперь можно прицеливаться из
Христова

---------

Signed-off-by: VMSolidus <evilexecutive@gmail.com>
Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>
Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
# Conflicts:
#	Content.Client/Input/ContentContexts.cs
#	Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
#	Content.Shared/Input/ContentKeyFunctions.cs
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml
#	Resources/keybinds.yml
2024-10-19 13:02:04 +07:00

129 lines
3.5 KiB
C#

using System.Numerics;
using Content.Client.Viewport;
using Content.Shared.CCVar;
using Content.Shared.Telescope;
using Content.Shared.Input;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Shared.Configuration;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Timing;
namespace Content.Client.Telescope;
public sealed class TelescopeSystem : SharedTelescopeSystem
{
[Dependency] private readonly InputSystem _inputSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
private ScalingViewport? _viewport;
private bool _holdLookUp;
private bool _toggled;
public override void Initialize()
{
base.Initialize();
_cfg.OnValueChanged(CCVars.HoldLookUp,
val =>
{
var input = val ? null : InputCmdHandler.FromDelegate(_ => _toggled = !_toggled);
_input.SetInputCommand(ContentKeyFunctions.LookUp, input);
_holdLookUp = val;
_toggled = false;
},
true);
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
if (_timing.ApplyingState
|| !_timing.IsFirstTimePredicted
|| !_input.MouseScreenPosition.IsValid)
return;
var player = _player.LocalEntity;
var telescope = GetRightTelescope(player);
if (telescope == null)
{
_toggled = false;
return;
}
if (!TryComp<EyeComponent>(player, out var eye))
return;
var offset = Vector2.Zero;
if (_holdLookUp)
{
if (_inputSystem.CmdStates.GetState(ContentKeyFunctions.LookUp) != BoundKeyState.Down)
{
RaiseEvent(offset);
return;
}
}
else if (!_toggled)
{
RaiseEvent(offset);
return;
}
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.Position - centerPos;
var len = diff.Length();
var size = _viewport.PixelSize;
var maxLength = Math.Min(size.X, size.Y) * 0.4f;
var minLength = maxLength * 0.2f;
if (len > maxLength)
{
diff *= maxLength / len;
len = maxLength;
}
var divisor = maxLength * telescope.Divisor;
if (len > minLength)
{
diff -= diff * minLength / len;
offset = new Vector2(diff.X / divisor, -diff.Y / divisor);
offset = new Angle(-eye.Rotation.Theta).RotateVec(offset);
}
RaiseEvent(offset);
}
private void RaiseEvent(Vector2 offset)
{
RaisePredictiveEvent(new EyeOffsetChangedEvent
{
Offset = offset
});
}
}