SpaceVillainArcadeMenu.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System.Numerics;
  2. using Content.Client.Arcade.UI;
  3. using Content.Shared.Arcade;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.CustomControls;
  6. namespace Content.Client.Arcade
  7. {
  8. public sealed class SpaceVillainArcadeMenu : DefaultWindow
  9. {
  10. private readonly Label _enemyNameLabel;
  11. private readonly Label _playerInfoLabel;
  12. private readonly Label _enemyInfoLabel;
  13. private readonly Label _playerActionLabel;
  14. private readonly Label _enemyActionLabel;
  15. private readonly Button[] _gameButtons = new Button[3]; //used to disable/enable all game buttons
  16. public event Action<SharedSpaceVillainArcadeComponent.PlayerAction>? OnPlayerAction;
  17. public SpaceVillainArcadeMenu()
  18. {
  19. MinSize = SetSize = new Vector2(300, 225);
  20. Title = Loc.GetString("spacevillain-menu-title");
  21. var grid = new GridContainer { Columns = 1 };
  22. var infoGrid = new GridContainer { Columns = 3 };
  23. infoGrid.AddChild(new Label { Text = Loc.GetString("spacevillain-menu-label-player"), Align = Label.AlignMode.Center });
  24. infoGrid.AddChild(new Label { Text = "|", Align = Label.AlignMode.Center });
  25. _enemyNameLabel = new Label { Align = Label.AlignMode.Center };
  26. infoGrid.AddChild(_enemyNameLabel);
  27. _playerInfoLabel = new Label { Align = Label.AlignMode.Center };
  28. infoGrid.AddChild(_playerInfoLabel);
  29. infoGrid.AddChild(new Label { Text = "|", Align = Label.AlignMode.Center });
  30. _enemyInfoLabel = new Label { Align = Label.AlignMode.Center };
  31. infoGrid.AddChild(_enemyInfoLabel);
  32. var centerContainer = new CenterContainer();
  33. centerContainer.AddChild(infoGrid);
  34. grid.AddChild(centerContainer);
  35. _playerActionLabel = new Label { Align = Label.AlignMode.Center };
  36. grid.AddChild(_playerActionLabel);
  37. _enemyActionLabel = new Label { Align = Label.AlignMode.Center };
  38. grid.AddChild(_enemyActionLabel);
  39. var buttonGrid = new GridContainer { Columns = 3 };
  40. _gameButtons[0] = new Button()
  41. {
  42. Text = Loc.GetString("spacevillain-menu-button-attack")
  43. };
  44. _gameButtons[0].OnPressed +=
  45. _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Attack);
  46. buttonGrid.AddChild(_gameButtons[0]);
  47. _gameButtons[1] = new Button()
  48. {
  49. Text = Loc.GetString("spacevillain-menu-button-heal")
  50. };
  51. _gameButtons[1].OnPressed +=
  52. _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Heal);
  53. buttonGrid.AddChild(_gameButtons[1]);
  54. _gameButtons[2] = new Button()
  55. {
  56. Text = Loc.GetString("spacevillain-menu-button-recharge")
  57. };
  58. _gameButtons[2].OnPressed +=
  59. _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Recharge);
  60. buttonGrid.AddChild(_gameButtons[2]);
  61. centerContainer = new CenterContainer();
  62. centerContainer.AddChild(buttonGrid);
  63. grid.AddChild(centerContainer);
  64. var newGame = new Button()
  65. {
  66. Text = Loc.GetString("spacevillain-menu-button-new-game")
  67. };
  68. newGame.OnPressed += _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.NewGame);
  69. grid.AddChild(newGame);
  70. Contents.AddChild(grid);
  71. }
  72. private void UpdateMetadata(SharedSpaceVillainArcadeComponent.SpaceVillainArcadeMetaDataUpdateMessage message)
  73. {
  74. Title = message.GameTitle;
  75. _enemyNameLabel.Text = message.EnemyName;
  76. foreach (var gameButton in _gameButtons)
  77. {
  78. gameButton.Disabled = message.ButtonsDisabled;
  79. }
  80. }
  81. public void UpdateInfo(SharedSpaceVillainArcadeComponent.SpaceVillainArcadeDataUpdateMessage message)
  82. {
  83. if (message is SharedSpaceVillainArcadeComponent.SpaceVillainArcadeMetaDataUpdateMessage metaMessage)
  84. UpdateMetadata(metaMessage);
  85. _playerInfoLabel.Text = $"HP: {message.PlayerHP} MP: {message.PlayerMP}";
  86. _enemyInfoLabel.Text = $"HP: {message.EnemyHP} MP: {message.EnemyMP}";
  87. _playerActionLabel.Text = message.PlayerActionMessage;
  88. _enemyActionLabel.Text = message.EnemyActionMessage;
  89. }
  90. }
  91. }