|
|
@ -30,18 +30,16 @@ public partial class MultiplayerMenu : MarginContainer |
|
|
|
[Export] public Label PlayersLabel { get; set; } |
|
|
|
[Export] public Label PlayersLabel { get; set; } |
|
|
|
[Export] public Button DisconnectButton { get; set; } |
|
|
|
[Export] public Button DisconnectButton { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
Game _game; |
|
|
|
|
|
|
|
public override void _Ready() |
|
|
|
public override void _Ready() |
|
|
|
{ |
|
|
|
{ |
|
|
|
_game = GetNode<Game>("/root/Game"); |
|
|
|
|
|
|
|
PortDisplay.AddThemeColorOverride("font_uneditable_color", PortDisplay.GetThemeColor("font_color")); |
|
|
|
PortDisplay.AddThemeColorOverride("font_uneditable_color", PortDisplay.GetThemeColor("font_color")); |
|
|
|
|
|
|
|
|
|
|
|
Multiplayer.ConnectedToServer += () => UpdateStatus(Status.Connected); |
|
|
|
Multiplayer.ConnectedToServer += () => UpdateStatus(Status.Connected); |
|
|
|
Multiplayer.ConnectionFailed += () => UpdateStatus(Status.ConnectionFailed); |
|
|
|
Multiplayer.ConnectionFailed += () => UpdateStatus(Status.ConnectionFailed); |
|
|
|
Multiplayer.ServerDisconnected += () => UpdateStatus(Status.Disconnected); |
|
|
|
Multiplayer.ServerDisconnected += () => UpdateStatus(Status.Disconnected); |
|
|
|
|
|
|
|
|
|
|
|
_game.MultiplayerManager.PlayerJoined += (_) => UpdatePlayerCount(); |
|
|
|
Game.Instance.MultiplayerManager.PlayerJoined += _ => UpdatePlayerCount(); |
|
|
|
_game.MultiplayerManager.PlayerLeft += (_) => UpdatePlayerCount(); |
|
|
|
Game.Instance.MultiplayerManager.PlayerLeft += _ => UpdatePlayerCount(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UpdateStatus(Status status) |
|
|
|
void UpdateStatus(Status status) |
|
|
@ -81,7 +79,7 @@ public partial class MultiplayerMenu : MarginContainer |
|
|
|
< Status.Connecting => "Singleplayer", |
|
|
|
< Status.Connecting => "Singleplayer", |
|
|
|
Status.Connecting => "??? Players", |
|
|
|
Status.Connecting => "??? Players", |
|
|
|
> Status.Connecting => ((Func<string>)(() => { |
|
|
|
> Status.Connecting => ((Func<string>)(() => { |
|
|
|
var players = _game.MultiplayerManager.Players.GetChildCount(); |
|
|
|
var players = Game.Instance.MultiplayerManager.Players.GetChildCount(); |
|
|
|
return $"{players} {(players != 1 ? "Players" : "Player")}"; |
|
|
|
return $"{players} {(players != 1 ? "Players" : "Player")}"; |
|
|
|
}))(), |
|
|
|
}))(), |
|
|
|
}; |
|
|
|
}; |
|
|
@ -100,14 +98,14 @@ public partial class MultiplayerMenu : MarginContainer |
|
|
|
var address = AddressInput.Text; |
|
|
|
var address = AddressInput.Text; |
|
|
|
if (address == "") address = AddressInput.PlaceholderText; |
|
|
|
if (address == "") address = AddressInput.PlaceholderText; |
|
|
|
var port = (ushort)RoundToInt(PortInput.Value); |
|
|
|
var port = (ushort)RoundToInt(PortInput.Value); |
|
|
|
_game.MultiplayerManager.Connect(address, port); |
|
|
|
Game.Instance.MultiplayerManager.Connect(address, port); |
|
|
|
UpdateStatus(Status.Connecting); |
|
|
|
UpdateStatus(Status.Connecting); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void OnHostPressed() |
|
|
|
public void OnHostPressed() |
|
|
|
{ |
|
|
|
{ |
|
|
|
var port = (ushort)RoundToInt(PortInput.Value); |
|
|
|
var port = (ushort)RoundToInt(PortInput.Value); |
|
|
|
if (_game.MultiplayerManager.CreateServer(port)) { |
|
|
|
if (Game.Instance.MultiplayerManager.CreateServer(port)) { |
|
|
|
PortDisplay.Text = port.ToString(); |
|
|
|
PortDisplay.Text = port.ToString(); |
|
|
|
UpdateStatus(Status.Hosting); |
|
|
|
UpdateStatus(Status.Hosting); |
|
|
|
} else |
|
|
|
} else |
|
|
@ -116,7 +114,7 @@ public partial class MultiplayerMenu : MarginContainer |
|
|
|
|
|
|
|
|
|
|
|
public void OnDisconnectPressed() |
|
|
|
public void OnDisconnectPressed() |
|
|
|
{ |
|
|
|
{ |
|
|
|
_game.MultiplayerManager.Disconnect(); |
|
|
|
Game.Instance.MultiplayerManager.Disconnect(); |
|
|
|
UpdateStatus(Status.Disconnected); |
|
|
|
UpdateStatus(Status.Disconnected); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|