2024-08-09 06:14:51 +00:00
|
|
|
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}";
|
|
|
|
|
2024-08-09 07:45:40 +00:00
|
|
|
StartGameButton.Disabled = !Multiplayer.IsServer() || Multiplayer.GetPeers().Length == 0;
|
2024-08-09 06:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true)]
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
EmitSignal(SignalName.StartGame);
|
|
|
|
var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
|
2024-08-09 06:55:45 +00:00
|
|
|
World.Scoreboard.SetName(Multiplayer.GetUniqueId(), name ?? $"Player#{Multiplayer.GetUniqueId()}");
|
2024-08-09 06:14:51 +00:00
|
|
|
World.StartGame(currentPlayerName: name);
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
}
|