AceField/Scripts/UI/BootScreen.cs
2024-08-09 14:55:45 +08:00

41 lines
1.1 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 ?? $"Player#{Multiplayer.GetUniqueId()}");
World.StartGame(currentPlayerName: name);
Hide();
}
}