137 lines
4.6 KiB
C#
137 lines
4.6 KiB
C#
using System.Numerics;
|
|
using Content.Shared.Shuttles.BUIStates;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.Shuttles.UI;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class NavScreen : BoxContainer
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
private SharedTransformSystem _xformSystem;
|
|
|
|
private EntityUid? _consoleEntity; // Entity of controlling console
|
|
private EntityUid? _shuttleEntity;
|
|
|
|
public NavScreen()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
_xformSystem = _entManager.System<SharedTransformSystem>();
|
|
|
|
IFFToggle.OnToggled += OnIFFTogglePressed;
|
|
IFFToggle.Pressed = NavRadar.ShowIFF;
|
|
|
|
IFFShuttleToggle.OnToggled += OnIFFShuttleTogglePressed;
|
|
IFFShuttleToggle.Pressed = NavRadar.ShowIFFShuttles;
|
|
|
|
DockToggle.OnToggled += OnDockTogglePressed;
|
|
DockToggle.Pressed = NavRadar.ShowDocks;
|
|
|
|
NfInitialize(); // Frontier Initialization for the NavScreen
|
|
}
|
|
|
|
// Frontier - IFF search
|
|
private void OnIffSearchChanged(string text)
|
|
{
|
|
text = text.Trim();
|
|
|
|
NavRadar.IFFFilter = text.Length == 0
|
|
? null // If empty, do not filter
|
|
: (entity, grid, iff) => // Otherwise use simple search criteria
|
|
{
|
|
// Check entity name
|
|
if (_entManager.TryGetComponent<MetaDataComponent>(entity, out var metadata) &&
|
|
metadata.EntityName.Contains(text, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
};
|
|
}
|
|
|
|
public void SetShuttle(EntityUid? shuttle)
|
|
{
|
|
_shuttleEntity = shuttle;
|
|
|
|
NfAddShuttleDesignation(shuttle); // Frontier - PR #1284 Add Shuttle Designation
|
|
}
|
|
|
|
public void SetConsole(EntityUid? console)
|
|
{
|
|
_consoleEntity = console;
|
|
NavRadar.SetConsole(console);
|
|
}
|
|
|
|
private void OnIFFTogglePressed(BaseButton.ButtonEventArgs args)
|
|
{
|
|
NavRadar.ShowIFF ^= true;
|
|
args.Button.Pressed = NavRadar.ShowIFF;
|
|
}
|
|
|
|
private void OnIFFShuttleTogglePressed(BaseButton.ButtonEventArgs args)
|
|
{
|
|
NavRadar.ShowIFFShuttles ^= true;
|
|
args.Button.Pressed = NavRadar.ShowIFFShuttles;
|
|
}
|
|
|
|
private void OnDockTogglePressed(BaseButton.ButtonEventArgs args)
|
|
{
|
|
NavRadar.ShowDocks ^= true;
|
|
args.Button.Pressed = NavRadar.ShowDocks;
|
|
}
|
|
|
|
public void UpdateState(NavInterfaceState scc)
|
|
{
|
|
NavRadar.UpdateState(scc);
|
|
NfUpdateState(scc); // Frontier Update State
|
|
}
|
|
|
|
public void SetMatrix(EntityCoordinates? coordinates, Angle? angle)
|
|
{
|
|
_shuttleEntity = coordinates?.EntityId;
|
|
NavRadar.SetMatrix(coordinates, angle);
|
|
}
|
|
|
|
protected override void Draw(DrawingHandleScreen handle)
|
|
{
|
|
base.Draw(handle);
|
|
|
|
if (!_entManager.TryGetComponent(_shuttleEntity, out TransformComponent? gridXform) ||
|
|
!_entManager.TryGetComponent(_shuttleEntity, out PhysicsComponent? gridBody))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var (_, worldRot, worldMatrix) = _xformSystem.GetWorldPositionRotationMatrix(gridXform);
|
|
var worldPos = Vector2.Transform(gridBody.LocalCenter, worldMatrix);
|
|
|
|
// Get the positive reduced angle.
|
|
var displayRot = -worldRot.Reduced();
|
|
|
|
GridPosition.Text = Loc.GetString("shuttle-console-position-value",
|
|
("X", $"{worldPos.X:0.0}"),
|
|
("Y", $"{worldPos.Y:0.0}"));
|
|
GridOrientation.Text = Loc.GetString("shuttle-console-orientation-value",
|
|
("angle", $"{displayRot.Degrees:0.0}"));
|
|
|
|
var gridVelocity = gridBody.LinearVelocity;
|
|
gridVelocity = displayRot.RotateVec(gridVelocity);
|
|
// Get linear velocity relative to the console entity
|
|
GridLinearVelocity.Text = Loc.GetString("shuttle-console-linear-velocity-value",
|
|
("X", $"{gridVelocity.X + 10f * float.Epsilon:0.0}"),
|
|
("Y", $"{gridVelocity.Y + 10f * float.Epsilon:0.0}"));
|
|
GridAngularVelocity.Text = Loc.GetString("shuttle-console-angular-velocity-value",
|
|
("angularVelocity", $"{-MathHelper.RadiansToDegrees(gridBody.AngularVelocity) + 10f * float.Epsilon:0.0}"));
|
|
}
|
|
}
|