Files
tbd-station-14/Content.Client/Arcade/UI/BlockGameBoundUserInterface.cs
metalgearsloth cbf329a82d Remove some BUI boilerplate (#28399)
* Remove some BUI boilerplate

- The disposals overrides got removed due to the helper method handling it.
- Replace window creation with CreateWindow helper.
- Fixed some stinky code which would cause exceptions.

* More

* moar

* weh

* done

* More BUIs

* More updates

* weh

* moar

* look who it is

* weh

* merge

* weh

* fixes
2024-07-20 15:40:16 +10:00

76 lines
2.8 KiB
C#

using Content.Shared.Arcade;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Arcade.UI;
public sealed class BlockGameBoundUserInterface : BoundUserInterface
{
private BlockGameMenu? _menu;
public BlockGameBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_menu = this.CreateWindow<BlockGameMenu>();
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
switch (message)
{
case BlockGameMessages.BlockGameVisualUpdateMessage updateMessage:
switch (updateMessage.GameVisualType)
{
case BlockGameMessages.BlockGameVisualType.GameField:
_menu?.UpdateBlocks(updateMessage.Blocks);
break;
case BlockGameMessages.BlockGameVisualType.HoldBlock:
_menu?.UpdateHeldBlock(updateMessage.Blocks);
break;
case BlockGameMessages.BlockGameVisualType.NextBlock:
_menu?.UpdateNextBlock(updateMessage.Blocks);
break;
}
break;
case BlockGameMessages.BlockGameScoreUpdateMessage scoreUpdate:
_menu?.UpdatePoints(scoreUpdate.Points);
break;
case BlockGameMessages.BlockGameUserStatusMessage userMessage:
_menu?.SetUsability(userMessage.IsPlayer);
break;
case BlockGameMessages.BlockGameSetScreenMessage statusMessage:
if (statusMessage.IsStarted) _menu?.SetStarted();
_menu?.SetScreen(statusMessage.Screen);
if (statusMessage is BlockGameMessages.BlockGameGameOverScreenMessage gameOverScreenMessage)
_menu?.SetGameoverInfo(gameOverScreenMessage.FinalScore, gameOverScreenMessage.LocalPlacement, gameOverScreenMessage.GlobalPlacement);
break;
case BlockGameMessages.BlockGameHighScoreUpdateMessage highScoreUpdateMessage:
_menu?.UpdateHighscores(highScoreUpdateMessage.LocalHighscores,
highScoreUpdateMessage.GlobalHighscores);
break;
case BlockGameMessages.BlockGameLevelUpdateMessage levelUpdateMessage:
_menu?.UpdateLevel(levelUpdateMessage.Level);
break;
}
}
public void SendAction(BlockGamePlayerAction action)
{
SendMessage(new BlockGameMessages.BlockGamePlayerActionMessage(action));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
}