✨ Boot screen
This commit is contained in:
parent
34100ee727
commit
40b0f2e176
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=9 format=3 uid="uid://bjhmjrldq4lkt"]
|
[gd_scene load_steps=10 format=3 uid="uid://bjhmjrldq4lkt"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://b3gx0bl43lku3" path="res://Scenes/Player.tscn" id="1_vby0g"]
|
[ext_resource type="PackedScene" uid="uid://b3gx0bl43lku3" path="res://Scenes/Player.tscn" id="1_vby0g"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dk8x2aeq1eevf" path="res://Scenes/UI/BootScreen.tscn" id="2_7aede"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bvll23f5ibd4v" path="res://Scenes/UI/LaunchScreen.tscn" id="2_7o53i"]
|
[ext_resource type="PackedScene" uid="uid://bvll23f5ibd4v" path="res://Scenes/UI/LaunchScreen.tscn" id="2_7o53i"]
|
||||||
[ext_resource type="Script" path="res://Scripts/Launcher.cs" id="2_u5cms"]
|
[ext_resource type="Script" path="res://Scripts/Launcher.cs" id="2_u5cms"]
|
||||||
[ext_resource type="Script" path="res://Scripts/Logic/Scoreboard.cs" id="3_as2wg"]
|
[ext_resource type="Script" path="res://Scripts/Logic/Scoreboard.cs" id="3_as2wg"]
|
||||||
@ -21,9 +22,14 @@ properties/1/replication_mode = 1
|
|||||||
[node name="LaunchScreen" parent="." node_paths=PackedStringArray("Launcher") instance=ExtResource("2_7o53i")]
|
[node name="LaunchScreen" parent="." node_paths=PackedStringArray("Launcher") instance=ExtResource("2_7o53i")]
|
||||||
Launcher = NodePath("../LauncherNode")
|
Launcher = NodePath("../LauncherNode")
|
||||||
|
|
||||||
[node name="LauncherNode" type="Node" parent="." node_paths=PackedStringArray("World", "Overlay")]
|
[node name="BootScreen" parent="." node_paths=PackedStringArray("World") instance=ExtResource("2_7aede")]
|
||||||
|
visible = false
|
||||||
|
World = NodePath("../World")
|
||||||
|
|
||||||
|
[node name="LauncherNode" type="Node" parent="." node_paths=PackedStringArray("World", "BootMenu", "Overlay")]
|
||||||
script = ExtResource("2_u5cms")
|
script = ExtResource("2_u5cms")
|
||||||
World = NodePath("../World")
|
World = NodePath("../World")
|
||||||
|
BootMenu = NodePath("../BootScreen")
|
||||||
Overlay = NodePath("../OverlayLayer")
|
Overlay = NodePath("../OverlayLayer")
|
||||||
|
|
||||||
[node name="ScoreboardNode" type="Node" parent="."]
|
[node name="ScoreboardNode" type="Node" parent="."]
|
||||||
@ -32,6 +38,7 @@ script = ExtResource("3_as2wg")
|
|||||||
[node name="OverlayLayer" type="CanvasLayer" parent="."]
|
[node name="OverlayLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
[node name="Hud" parent="OverlayLayer" node_paths=PackedStringArray("World") instance=ExtResource("5_qvun1")]
|
[node name="Hud" parent="OverlayLayer" node_paths=PackedStringArray("World") instance=ExtResource("5_qvun1")]
|
||||||
|
visible = false
|
||||||
World = NodePath("../../World")
|
World = NodePath("../../World")
|
||||||
|
|
||||||
[node name="PlayerDiedScreen" parent="OverlayLayer" instance=ExtResource("5_pimes")]
|
[node name="PlayerDiedScreen" parent="OverlayLayer" instance=ExtResource("5_pimes")]
|
||||||
|
49
Scenes/UI/BootScreen.tscn
Normal file
49
Scenes/UI/BootScreen.tscn
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://dk8x2aeq1eevf"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://Scripts/UI/BootScreen.cs" id="1_ajoaa"]
|
||||||
|
|
||||||
|
[node name="BootScreen" type="Control" node_paths=PackedStringArray("StartGameButton", "PlayerNameInput", "PlayerCountLabel")]
|
||||||
|
process_mode = 3
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
script = ExtResource("1_ajoaa")
|
||||||
|
StartGameButton = NodePath("CenterContainer/VBoxContainer/StartButton")
|
||||||
|
PlayerNameInput = NodePath("CenterContainer/VBoxContainer/NameEdit")
|
||||||
|
PlayerCountLabel = NodePath("CenterContainer/VBoxContainer/PlayerCountLabel")
|
||||||
|
|
||||||
|
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_right = 1152.0
|
||||||
|
offset_bottom = 648.0
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="PlayerCountLabel" type="Label" parent="CenterContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_font_sizes/font_size = 28
|
||||||
|
text = "01/16"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="PlayerCountHint" type="Label" parent="CenterContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Waiting for Players"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="Spacer" type="BoxContainer" parent="CenterContainer/VBoxContainer"]
|
||||||
|
custom_minimum_size = Vector2(2.08165e-12, 8)
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="NameEdit" type="LineEdit" parent="CenterContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
placeholder_text = "Player name"
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="StartButton" type="Button" parent="CenterContainer/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
disabled = true
|
||||||
|
text = "Start the Game"
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" path="res://Scripts/UI/LaunchScreen.cs" id="1_hiet3"]
|
[ext_resource type="Script" path="res://Scripts/UI/LaunchScreen.cs" id="1_hiet3"]
|
||||||
|
|
||||||
[node name="LaunchScreen" type="Control" node_paths=PackedStringArray("PlayerNameInput", "ServerPortInput", "ServerAddrInput", "StartAsServerButton", "StartAsClientButton")]
|
[node name="LaunchScreen" type="Control" node_paths=PackedStringArray("ServerPortInput", "ServerAddrInput", "StartAsServerButton", "StartAsClientButton")]
|
||||||
process_mode = 3
|
process_mode = 3
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
@ -11,7 +11,6 @@ anchor_bottom = 1.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = ExtResource("1_hiet3")
|
script = ExtResource("1_hiet3")
|
||||||
PlayerNameInput = NodePath("CenterContainer/VBoxContainer/NameEdit")
|
|
||||||
ServerPortInput = NodePath("CenterContainer/VBoxContainer/PortEdit")
|
ServerPortInput = NodePath("CenterContainer/VBoxContainer/PortEdit")
|
||||||
ServerAddrInput = NodePath("CenterContainer/VBoxContainer/AddrEdit")
|
ServerAddrInput = NodePath("CenterContainer/VBoxContainer/AddrEdit")
|
||||||
StartAsServerButton = NodePath("CenterContainer/VBoxContainer/MultiplayerActions/HostButton")
|
StartAsServerButton = NodePath("CenterContainer/VBoxContainer/MultiplayerActions/HostButton")
|
||||||
@ -31,9 +30,9 @@ text = "AceField
|
|||||||
Prototype · Closed test"
|
Prototype · Closed test"
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
|
|
||||||
[node name="NameEdit" type="LineEdit" parent="CenterContainer/VBoxContainer"]
|
[node name="Spacer" type="BoxContainer" parent="CenterContainer/VBoxContainer"]
|
||||||
|
custom_minimum_size = Vector2(2.08165e-12, 16)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
placeholder_text = "Player name"
|
|
||||||
|
|
||||||
[node name="PlayTitle" type="Label" parent="CenterContainer/VBoxContainer"]
|
[node name="PlayTitle" type="Label" parent="CenterContainer/VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using AceField.Scripts.Logic;
|
using AceField.Scripts.Logic;
|
||||||
|
using AceField.Scripts.UI;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace AceField.Scripts;
|
namespace AceField.Scripts;
|
||||||
@ -6,6 +7,9 @@ namespace AceField.Scripts;
|
|||||||
public partial class Launcher : Node
|
public partial class Launcher : Node
|
||||||
{
|
{
|
||||||
[Export] public World World;
|
[Export] public World World;
|
||||||
|
|
||||||
|
[Export] public BootScreen BootMenu;
|
||||||
|
|
||||||
[Export] public CanvasLayer Overlay;
|
[Export] public CanvasLayer Overlay;
|
||||||
|
|
||||||
private void GameFreeze()
|
private void GameFreeze()
|
||||||
@ -20,6 +24,7 @@ public partial class Launcher : Node
|
|||||||
GetTree().Paused = false;
|
GetTree().Paused = false;
|
||||||
World.Show();
|
World.Show();
|
||||||
Overlay.Show();
|
Overlay.Show();
|
||||||
|
BootMenu.StartGame -= GameUnfreeze;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
@ -33,13 +38,12 @@ public partial class Launcher : Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartAsSingle(string currentPlayerName = null)
|
public void StartAsSingle()
|
||||||
{
|
{
|
||||||
GameUnfreeze();
|
GameUnfreeze();
|
||||||
World.StartGame(currentPlayerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool StartAsServer(int port, string currentPlayerName = null)
|
public bool StartAsServer(int port)
|
||||||
{
|
{
|
||||||
var peer = new ENetMultiplayerPeer();
|
var peer = new ENetMultiplayerPeer();
|
||||||
peer.CreateServer(port);
|
peer.CreateServer(port);
|
||||||
@ -53,13 +57,13 @@ public partial class Launcher : Node
|
|||||||
GD.Print("Running game as server...");
|
GD.Print("Running game as server...");
|
||||||
|
|
||||||
Multiplayer.MultiplayerPeer = peer;
|
Multiplayer.MultiplayerPeer = peer;
|
||||||
GameUnfreeze();
|
BootMenu.StartGame += GameUnfreeze;
|
||||||
World.StartGame(currentPlayerName);
|
BootMenu.Show();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool StartAsClient(string addr, int port, string currentPlayerName = null)
|
public bool StartAsClient(string addr, int port)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(addr)) return false;
|
if (string.IsNullOrEmpty(addr)) return false;
|
||||||
|
|
||||||
@ -76,8 +80,8 @@ public partial class Launcher : Node
|
|||||||
GD.Print("Running game as client...");
|
GD.Print("Running game as client...");
|
||||||
|
|
||||||
Multiplayer.MultiplayerPeer = peer;
|
Multiplayer.MultiplayerPeer = peer;
|
||||||
GameUnfreeze();
|
BootMenu.StartGame += GameUnfreeze;
|
||||||
World.StartGame(currentPlayerName);
|
BootMenu.Show();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,15 @@ public partial class World : Node2D
|
|||||||
AddChild(_roundTimer);
|
AddChild(_roundTimer);
|
||||||
_roundTimer.Start();
|
_roundTimer.Start();
|
||||||
|
|
||||||
|
// Add players into the game
|
||||||
|
PutPlayers(currentPlayerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
if (!Multiplayer.IsServer())
|
||||||
|
return;
|
||||||
|
|
||||||
// Handling player connect / disconnect after this client connected
|
// Handling player connect / disconnect after this client connected
|
||||||
Multiplayer.PeerDisconnected += RemovePlayer_Adaptor;
|
Multiplayer.PeerDisconnected += RemovePlayer_Adaptor;
|
||||||
Multiplayer.PeerConnected += AddPlayer_Adaptor;
|
Multiplayer.PeerConnected += AddPlayer_Adaptor;
|
||||||
@ -37,10 +46,7 @@ public partial class World : Node2D
|
|||||||
|
|
||||||
// Add this client as a player if client isn't a dedicated server
|
// Add this client as a player if client isn't a dedicated server
|
||||||
if (!OS.HasFeature("dedicated_server"))
|
if (!OS.HasFeature("dedicated_server"))
|
||||||
Scoreboard.AddPlayer(1, currentPlayerName);
|
Scoreboard.AddPlayer(1);
|
||||||
|
|
||||||
// Add players into the game
|
|
||||||
PutPlayers(currentPlayerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
|
40
Scripts/UI/BootScreen.cs
Normal file
40
Scripts/UI/BootScreen.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,6 @@ public partial class LaunchScreen : Control
|
|||||||
|
|
||||||
[Export] public Launcher Launcher;
|
[Export] public Launcher Launcher;
|
||||||
|
|
||||||
[Export] public LineEdit PlayerNameInput;
|
|
||||||
[Export] public LineEdit ServerPortInput;
|
[Export] public LineEdit ServerPortInput;
|
||||||
[Export] public LineEdit ServerAddrInput;
|
[Export] public LineEdit ServerAddrInput;
|
||||||
[Export] public Button StartAsServerButton;
|
[Export] public Button StartAsServerButton;
|
||||||
@ -51,8 +50,7 @@ public partial class LaunchScreen : Control
|
|||||||
}
|
}
|
||||||
|
|
||||||
var port = ServerPortInput.Text;
|
var port = ServerPortInput.Text;
|
||||||
var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
|
var result = Launcher.StartAsServer(int.Parse(port));
|
||||||
var result = Launcher.StartAsServer(int.Parse(port), currentPlayerName: name);
|
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
Hide();
|
Hide();
|
||||||
@ -67,8 +65,7 @@ public partial class LaunchScreen : Control
|
|||||||
|
|
||||||
var addr = ServerAddrInput.Text;
|
var addr = ServerAddrInput.Text;
|
||||||
var port = ServerPortInput.Text;
|
var port = ServerPortInput.Text;
|
||||||
var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
|
var result = Launcher.StartAsClient(addr, int.Parse(port));
|
||||||
var result = Launcher.StartAsClient(addr, int.Parse(port), currentPlayerName: name);
|
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
Hide();
|
Hide();
|
||||||
|
Loading…
Reference in New Issue
Block a user