BlockGameBoundUserInterface.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Content.Shared.Arcade;
  2. using Robust.Client.GameObjects;
  3. using Robust.Client.UserInterface;
  4. namespace Content.Client.Arcade.UI;
  5. public sealed class BlockGameBoundUserInterface : BoundUserInterface
  6. {
  7. private BlockGameMenu? _menu;
  8. public BlockGameBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  9. {
  10. }
  11. protected override void Open()
  12. {
  13. base.Open();
  14. _menu = this.CreateWindow<BlockGameMenu>();
  15. _menu.OnAction += SendAction;
  16. }
  17. protected override void ReceiveMessage(BoundUserInterfaceMessage message)
  18. {
  19. switch (message)
  20. {
  21. case BlockGameMessages.BlockGameVisualUpdateMessage updateMessage:
  22. switch (updateMessage.GameVisualType)
  23. {
  24. case BlockGameMessages.BlockGameVisualType.GameField:
  25. _menu?.UpdateBlocks(updateMessage.Blocks);
  26. break;
  27. case BlockGameMessages.BlockGameVisualType.HoldBlock:
  28. _menu?.UpdateHeldBlock(updateMessage.Blocks);
  29. break;
  30. case BlockGameMessages.BlockGameVisualType.NextBlock:
  31. _menu?.UpdateNextBlock(updateMessage.Blocks);
  32. break;
  33. }
  34. break;
  35. case BlockGameMessages.BlockGameScoreUpdateMessage scoreUpdate:
  36. _menu?.UpdatePoints(scoreUpdate.Points);
  37. break;
  38. case BlockGameMessages.BlockGameUserStatusMessage userMessage:
  39. _menu?.SetUsability(userMessage.IsPlayer);
  40. break;
  41. case BlockGameMessages.BlockGameSetScreenMessage statusMessage:
  42. if (statusMessage.IsStarted) _menu?.SetStarted();
  43. _menu?.SetScreen(statusMessage.Screen);
  44. if (statusMessage is BlockGameMessages.BlockGameGameOverScreenMessage gameOverScreenMessage)
  45. _menu?.SetGameoverInfo(gameOverScreenMessage.FinalScore, gameOverScreenMessage.LocalPlacement, gameOverScreenMessage.GlobalPlacement);
  46. break;
  47. case BlockGameMessages.BlockGameHighScoreUpdateMessage highScoreUpdateMessage:
  48. _menu?.UpdateHighscores(highScoreUpdateMessage.LocalHighscores,
  49. highScoreUpdateMessage.GlobalHighscores);
  50. break;
  51. case BlockGameMessages.BlockGameLevelUpdateMessage levelUpdateMessage:
  52. _menu?.UpdateLevel(levelUpdateMessage.Level);
  53. break;
  54. }
  55. }
  56. public void SendAction(BlockGamePlayerAction action)
  57. {
  58. SendMessage(new BlockGameMessages.BlockGamePlayerActionMessage(action));
  59. }
  60. protected override void Dispose(bool disposing)
  61. {
  62. base.Dispose(disposing);
  63. if (!disposing)
  64. return;
  65. _menu?.Dispose();
  66. }
  67. }