41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
|
using AceField.Scripts.Logic;
|
||
|
using Godot;
|
||
|
|
||
|
namespace AceField.Scripts.UI;
|
||
|
|
||
|
public partial class BootScreen : Control
|
||
|
{
|
||
|
[Export] public World World;
|
||
|
|
||
|
[Export] public Button StartGameButton;
|
||
|
[Export] public LineEdit PlayerNameInput;
|
||
|
[Export] public Label PlayerCountLabel;
|
||
|
|
||
|
[Signal]
|
||
|
public delegate void StartGameEventHandler();
|
||
|
|
||
|
public override void _Ready()
|
||
|
{
|
||
|
StartGameButton.Pressed += () => { Rpc(nameof(Start)); };
|
||
|
}
|
||
|
|
||
|
public override void _Process(double delta)
|
||
|
{
|
||
|
var count = Multiplayer.GetPeers().Length;
|
||
|
PlayerCountLabel.Text = $"{(count + 1):00}/{16}";
|
||
|
|
||
|
StartGameButton.Disabled = !Multiplayer.IsServer();
|
||
|
}
|
||
|
|
||
|
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
||
|
private void Start()
|
||
|
{
|
||
|
EmitSignal(SignalName.StartGame);
|
||
|
var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
|
||
|
// TODO Fix this I don't know why the first round player's name won't fully apply
|
||
|
World.Scoreboard.SetName(Multiplayer.GetUniqueId(), name);
|
||
|
World.StartGame(currentPlayerName: name);
|
||
|
Hide();
|
||
|
}
|
||
|
}
|