2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Client.Arcade.UI;
|
|
|
|
|
|
using Content.Shared.Arcade;
|
2020-09-23 14:30:31 +02:00
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
2020-10-30 11:25:26 +01:00
|
|
|
|
using Robust.Shared.Localization;
|
2020-09-23 14:30:31 +02:00
|
|
|
|
using Vector2 = Robust.Shared.Maths.Vector2;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.Arcade
|
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class SpaceVillainArcadeMenu : DefaultWindow
|
2020-09-23 14:30:31 +02:00
|
|
|
|
{
|
|
|
|
|
|
public SpaceVillainArcadeBoundUserInterface Owner { get; set; }
|
|
|
|
|
|
|
2020-11-21 14:02:00 +01:00
|
|
|
|
private readonly Label _enemyNameLabel;
|
|
|
|
|
|
private readonly Label _playerInfoLabel;
|
|
|
|
|
|
private readonly Label _enemyInfoLabel;
|
|
|
|
|
|
private readonly Label _playerActionLabel;
|
|
|
|
|
|
private readonly Label _enemyActionLabel;
|
2020-10-30 11:25:26 +01:00
|
|
|
|
|
2020-11-21 14:02:00 +01:00
|
|
|
|
private readonly Button[] _gameButtons = new Button[3]; //used to disable/enable all game buttons
|
2020-09-23 14:30:31 +02:00
|
|
|
|
public SpaceVillainArcadeMenu(SpaceVillainArcadeBoundUserInterface owner)
|
|
|
|
|
|
{
|
2021-03-15 01:38:08 -07:00
|
|
|
|
MinSize = SetSize = (300, 225);
|
2021-05-21 15:39:33 +02:00
|
|
|
|
Title = Loc.GetString("spacevillain-menu-title");
|
2020-09-23 14:30:31 +02:00
|
|
|
|
Owner = owner;
|
|
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
var grid = new GridContainer {Columns = 1};
|
2020-09-23 14:30:31 +02:00
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
var infoGrid = new GridContainer {Columns = 3};
|
2021-05-21 15:39:33 +02:00
|
|
|
|
infoGrid.AddChild(new Label{ Text = Loc.GetString("spacevillain-menu-label-player"), Align = Label.AlignMode.Center });
|
2020-09-23 14:30:31 +02:00
|
|
|
|
infoGrid.AddChild(new Label{ Text = "|", Align = Label.AlignMode.Center });
|
|
|
|
|
|
_enemyNameLabel = new Label{ Align = Label.AlignMode.Center};
|
|
|
|
|
|
infoGrid.AddChild(_enemyNameLabel);
|
|
|
|
|
|
|
|
|
|
|
|
_playerInfoLabel = new Label {Align = Label.AlignMode.Center};
|
|
|
|
|
|
infoGrid.AddChild(_playerInfoLabel);
|
|
|
|
|
|
infoGrid.AddChild(new Label{ Text = "|", Align = Label.AlignMode.Center });
|
|
|
|
|
|
_enemyInfoLabel = new Label {Align = Label.AlignMode.Center};
|
|
|
|
|
|
infoGrid.AddChild(_enemyInfoLabel);
|
2020-10-30 11:25:26 +01:00
|
|
|
|
var centerContainer = new CenterContainer();
|
2020-09-23 14:30:31 +02:00
|
|
|
|
centerContainer.AddChild(infoGrid);
|
|
|
|
|
|
grid.AddChild(centerContainer);
|
|
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
_playerActionLabel = new Label {Align = Label.AlignMode.Center};
|
2020-09-23 14:30:31 +02:00
|
|
|
|
grid.AddChild(_playerActionLabel);
|
|
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
_enemyActionLabel = new Label {Align = Label.AlignMode.Center};
|
2020-09-23 14:30:31 +02:00
|
|
|
|
grid.AddChild(_enemyActionLabel);
|
|
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
var buttonGrid = new GridContainer {Columns = 3};
|
|
|
|
|
|
_gameButtons[0] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Attack)
|
2021-05-21 15:39:33 +02:00
|
|
|
|
{Text = Loc.GetString("spacevillain-menu-button-attack")};
|
2020-10-30 11:25:26 +01:00
|
|
|
|
buttonGrid.AddChild(_gameButtons[0]);
|
2020-09-23 14:30:31 +02:00
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
_gameButtons[1] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Heal)
|
2021-05-21 15:39:33 +02:00
|
|
|
|
{Text = Loc.GetString("spacevillain-menu-button-heal")};
|
2020-10-30 11:25:26 +01:00
|
|
|
|
buttonGrid.AddChild(_gameButtons[1]);
|
2020-09-23 14:30:31 +02:00
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
_gameButtons[2] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Recharge)
|
2021-05-21 15:39:33 +02:00
|
|
|
|
{Text = Loc.GetString("spacevillain-menu-button-recharge")};
|
2020-10-30 11:25:26 +01:00
|
|
|
|
buttonGrid.AddChild(_gameButtons[2]);
|
2020-09-23 14:30:31 +02:00
|
|
|
|
|
|
|
|
|
|
centerContainer = new CenterContainer();
|
|
|
|
|
|
centerContainer.AddChild(buttonGrid);
|
|
|
|
|
|
grid.AddChild(centerContainer);
|
|
|
|
|
|
|
2020-10-30 11:25:26 +01:00
|
|
|
|
var newGame = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.NewGame)
|
2021-05-21 15:39:33 +02:00
|
|
|
|
{Text = Loc.GetString("spacevillain-menu-button-new-game")};
|
2020-09-23 14:30:31 +02:00
|
|
|
|
grid.AddChild(newGame);
|
|
|
|
|
|
|
2021-03-15 01:38:08 -07:00
|
|
|
|
Contents.AddChild(grid);
|
2020-09-23 14:30:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateMetadata(SharedSpaceVillainArcadeComponent.SpaceVillainArcadeMetaDataUpdateMessage message)
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = message.GameTitle;
|
|
|
|
|
|
_enemyNameLabel.Text = message.EnemyName;
|
2020-10-30 11:25:26 +01:00
|
|
|
|
|
|
|
|
|
|
foreach (var gameButton in _gameButtons)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameButton.Disabled = message.ButtonsDisabled;
|
|
|
|
|
|
}
|
2020-09-23 14:30:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateInfo(SharedSpaceVillainArcadeComponent.SpaceVillainArcadeDataUpdateMessage message)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(message is SharedSpaceVillainArcadeComponent.SpaceVillainArcadeMetaDataUpdateMessage metaMessage) UpdateMetadata(metaMessage);
|
|
|
|
|
|
|
|
|
|
|
|
_playerInfoLabel.Text = $"HP: {message.PlayerHP} MP: {message.PlayerMP}";
|
|
|
|
|
|
_enemyInfoLabel.Text = $"HP: {message.EnemyHP} MP: {message.EnemyMP}";
|
|
|
|
|
|
_playerActionLabel.Text = message.PlayerActionMessage;
|
|
|
|
|
|
_enemyActionLabel.Text = message.EnemyActionMessage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
|
private sealed class ActionButton : Button
|
2020-09-23 14:30:31 +02:00
|
|
|
|
{
|
2020-11-21 14:02:00 +01:00
|
|
|
|
private readonly SpaceVillainArcadeBoundUserInterface _owner;
|
|
|
|
|
|
private readonly SharedSpaceVillainArcadeComponent.PlayerAction _playerAction;
|
2020-09-23 14:30:31 +02:00
|
|
|
|
|
|
|
|
|
|
public ActionButton(SpaceVillainArcadeBoundUserInterface owner,SharedSpaceVillainArcadeComponent.PlayerAction playerAction)
|
|
|
|
|
|
{
|
|
|
|
|
|
_owner = owner;
|
|
|
|
|
|
_playerAction = playerAction;
|
|
|
|
|
|
OnPressed += Clicked;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Clicked(ButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
_owner.SendAction(_playerAction);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|