* Use new Subs.CVar helper Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe. This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown. * Fix a bunch of warnings * More warning fixes * Use new DateTime serializer to get rid of ISerializationHooks in changelog code. * Get rid of some more ISerializationHooks for enums * And a little more * Apply suggestions from code review Co-authored-by: 0x6273 <0x40@keemail.me> --------- Co-authored-by: 0x6273 <0x40@keemail.me>
68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using Content.Shared.Input;
|
|
using Content.Shared.Shuttles.Components;
|
|
using Content.Shared.Shuttles.Systems;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.GameStates;
|
|
|
|
namespace Content.Client.Shuttles.Systems
|
|
{
|
|
public sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
|
{
|
|
[Dependency] private readonly IInputManager _input = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<PilotComponent, ComponentHandleState>(OnHandleState);
|
|
var shuttle = _input.Contexts.New("shuttle", "common");
|
|
shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeUp);
|
|
shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeDown);
|
|
shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeLeft);
|
|
shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeRight);
|
|
shuttle.AddFunction(ContentKeyFunctions.ShuttleRotateLeft);
|
|
shuttle.AddFunction(ContentKeyFunctions.ShuttleRotateRight);
|
|
shuttle.AddFunction(ContentKeyFunctions.ShuttleBrake);
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
_input.Contexts.Remove("shuttle");
|
|
}
|
|
|
|
protected override void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args)
|
|
{
|
|
base.HandlePilotShutdown(uid, component, args);
|
|
if (_playerManager.LocalEntity != uid) return;
|
|
|
|
_input.Contexts.SetActiveContext("human");
|
|
}
|
|
|
|
private void OnHandleState(EntityUid uid, PilotComponent component, ref ComponentHandleState args)
|
|
{
|
|
if (args.Current is not PilotComponentState state) return;
|
|
|
|
var console = EnsureEntity<PilotComponent>(state.Console, uid);
|
|
|
|
if (console == null)
|
|
{
|
|
component.Console = null;
|
|
_input.Contexts.SetActiveContext("human");
|
|
return;
|
|
}
|
|
|
|
if (!HasComp<ShuttleConsoleComponent>(console))
|
|
{
|
|
Log.Warning($"Unable to set Helmsman console to {console}");
|
|
return;
|
|
}
|
|
|
|
component.Console = console;
|
|
ActionBlockerSystem.UpdateCanMove(uid);
|
|
_input.Contexts.SetActiveContext("shuttle");
|
|
}
|
|
}
|
|
}
|