Files
tbd-station-14/Content.Client/MouseRotator/MouseRotatorSystem.cs
metalgearsloth a9502be29e Revert "Fix chat bubbles (#25643)" (#25645)
* Revert "Fix chat bubbles (#25643)"

This reverts commit 23d2c4d924.

* Revert "Fixes obsolete Transform warnings in Content. (#25256)"

This reverts commit f284b43ff6.
2024-02-28 00:51:20 +11:00

78 lines
2.4 KiB
C#

using Content.Shared.MouseRotator;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Shared.Map;
using Robust.Shared.Timing;
namespace Content.Client.MouseRotator;
/// <inheritdoc/>
public sealed class MouseRotatorSystem : SharedMouseRotatorSystem
{
[Dependency] private readonly IInputManager _input = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!_timing.IsFirstTimePredicted || !_input.MouseScreenPosition.IsValid)
return;
var player = _player.LocalEntity;
if (player == null || !TryComp<MouseRotatorComponent>(player, out var rotator))
return;
var xform = Transform(player.Value);
// Get mouse loc and convert to angle based on player location
var coords = _input.MouseScreenPosition;
var mapPos = _eye.PixelToMap(coords);
if (mapPos.MapId == MapId.Nullspace)
return;
var angle = (mapPos.Position - xform.MapPosition.Position).ToWorldAngle();
var curRot = _transform.GetWorldRotation(xform);
// 4-dir handling is separate --
// only raise event if the cardinal direction has changed
if (rotator.Simple4DirMode)
{
var angleDir = angle.GetCardinalDir();
if (angleDir == curRot.GetCardinalDir())
return;
RaisePredictiveEvent(new RequestMouseRotatorRotationSimpleEvent()
{
Direction = angleDir,
});
return;
}
// Don't raise event if mouse ~hasn't moved (or if too close to goal rotation already)
var diff = Angle.ShortestDistance(angle, curRot);
if (Math.Abs(diff.Theta) < rotator.AngleTolerance.Theta)
return;
if (rotator.GoalRotation != null)
{
var goalDiff = Angle.ShortestDistance(angle, rotator.GoalRotation.Value);
if (Math.Abs(goalDiff.Theta) < rotator.AngleTolerance.Theta)
return;
}
RaisePredictiveEvent(new RequestMouseRotatorRotationEvent
{
Rotation = angle
});
}
}