mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using Robust.Client.Graphics;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.Client.GameObjects
|
|
{
|
|
public sealed class VelocityDebugSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
internal bool Enabled { get; set; }
|
|
|
|
private Label _label = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_label = new Label();
|
|
IoCManager.Resolve<IUserInterfaceManager>().StateRoot.AddChild(_label);
|
|
}
|
|
|
|
public override void FrameUpdate(float frameTime)
|
|
{
|
|
base.FrameUpdate(frameTime);
|
|
if (!Enabled)
|
|
{
|
|
_label.Visible = false;
|
|
return;
|
|
}
|
|
|
|
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
|
|
|
if (player == null || !EntityManager.TryGetComponent(player.Value, out PhysicsComponent? body))
|
|
{
|
|
_label.Visible = false;
|
|
return;
|
|
}
|
|
|
|
var screenPos = _eyeManager.WorldToScreen(EntityManager.GetComponent<TransformComponent>(player.Value).WorldPosition);
|
|
LayoutContainer.SetPosition(_label, screenPos + new Vector2(0, 50));
|
|
_label.Visible = true;
|
|
|
|
_label.Text = $"Speed: {body.LinearVelocity.Length}\nLinear: {body.LinearVelocity.X:0.00}, {body.LinearVelocity.Y:0.00}\nAngular:{body.AngularVelocity}";
|
|
}
|
|
}
|
|
}
|