ShuttleConsoleSystem.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Content.Shared.Input;
  2. using Content.Shared.Shuttles.Components;
  3. using Content.Shared.Shuttles.Systems;
  4. using Robust.Client.Input;
  5. using Robust.Client.Player;
  6. using Robust.Shared.GameStates;
  7. namespace Content.Client.Shuttles.Systems
  8. {
  9. public sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
  10. {
  11. [Dependency] private readonly IInputManager _input = default!;
  12. [Dependency] private readonly IPlayerManager _playerManager = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<PilotComponent, ComponentHandleState>(OnHandleState);
  17. var shuttle = _input.Contexts.New("shuttle", "common");
  18. shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeUp);
  19. shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeDown);
  20. shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeLeft);
  21. shuttle.AddFunction(ContentKeyFunctions.ShuttleStrafeRight);
  22. shuttle.AddFunction(ContentKeyFunctions.ShuttleRotateLeft);
  23. shuttle.AddFunction(ContentKeyFunctions.ShuttleRotateRight);
  24. shuttle.AddFunction(ContentKeyFunctions.ShuttleBrake);
  25. }
  26. public override void Shutdown()
  27. {
  28. base.Shutdown();
  29. _input.Contexts.Remove("shuttle");
  30. }
  31. protected override void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args)
  32. {
  33. base.HandlePilotShutdown(uid, component, args);
  34. if (_playerManager.LocalEntity != uid) return;
  35. _input.Contexts.SetActiveContext("human");
  36. }
  37. private void OnHandleState(EntityUid uid, PilotComponent component, ref ComponentHandleState args)
  38. {
  39. if (args.Current is not PilotComponentState state) return;
  40. var console = EnsureEntity<PilotComponent>(state.Console, uid);
  41. if (console == null)
  42. {
  43. component.Console = null;
  44. _input.Contexts.SetActiveContext("human");
  45. return;
  46. }
  47. if (!HasComp<ShuttleConsoleComponent>(console))
  48. {
  49. Log.Warning($"Unable to set Helmsman console to {console}");
  50. return;
  51. }
  52. component.Console = console;
  53. ActionBlockerSystem.UpdateCanMove(uid);
  54. _input.Contexts.SetActiveContext("shuttle");
  55. }
  56. }
  57. }