1
0

MakeGhostRoleEui.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Content.Client.Eui;
  2. using Content.Server.Ghost.Roles.Raffles;
  3. using Content.Shared.Eui;
  4. using Content.Shared.Ghost.Roles;
  5. using JetBrains.Annotations;
  6. using Robust.Client.Console;
  7. using Robust.Client.Player;
  8. using Robust.Shared.Utility;
  9. namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles;
  10. [UsedImplicitly]
  11. public sealed class MakeGhostRoleEui : BaseEui
  12. {
  13. [Dependency] private readonly IEntityManager _entManager = default!;
  14. [Dependency] private readonly IPlayerManager _playerManager = default!;
  15. [Dependency] private readonly IClientConsoleHost _consoleHost = default!;
  16. private readonly MakeGhostRoleWindow _window;
  17. public MakeGhostRoleEui()
  18. {
  19. _window = new MakeGhostRoleWindow();
  20. _window.OnClose += OnClose;
  21. _window.OnMake += OnMake;
  22. }
  23. public override void HandleState(EuiStateBase state)
  24. {
  25. if (state is not MakeGhostRoleEuiState uiState)
  26. {
  27. return;
  28. }
  29. _window.SetEntity(_entManager, uiState.Entity);
  30. }
  31. public override void Opened()
  32. {
  33. base.Opened();
  34. _window.OpenCentered();
  35. }
  36. private void OnMake(NetEntity entity, string name, string description, string rules, bool makeSentient, GhostRoleRaffleSettings? raffleSettings)
  37. {
  38. var session = _playerManager.LocalSession;
  39. if (session == null)
  40. {
  41. return;
  42. }
  43. var command = raffleSettings is not null ? "makeghostroleraffled" : "makeghostrole";
  44. var makeGhostRoleCommand =
  45. $"{command} " +
  46. $"\"{CommandParsing.Escape(entity.ToString())}\" " +
  47. $"\"{CommandParsing.Escape(name)}\" " +
  48. $"\"{CommandParsing.Escape(description)}\" ";
  49. if (raffleSettings is not null)
  50. {
  51. makeGhostRoleCommand += $"{raffleSettings.InitialDuration} " +
  52. $"{raffleSettings.JoinExtendsDurationBy} " +
  53. $"{raffleSettings.MaxDuration} ";
  54. }
  55. makeGhostRoleCommand += $"\"{CommandParsing.Escape(rules)}\"";
  56. _consoleHost.ExecuteCommand(session, makeGhostRoleCommand);
  57. if (makeSentient)
  58. {
  59. var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(entity.ToString())}\"";
  60. _consoleHost.ExecuteCommand(session, makeSentientCommand);
  61. }
  62. _window.Close();
  63. }
  64. private void OnClose()
  65. {
  66. base.Closed();
  67. SendMessage(new CloseEuiMessage());
  68. }
  69. }