Bugfixes + Menu.

This commit is contained in:
Patrick 2024-12-12 15:23:16 +01:00
parent 1ee6f6cc6d
commit 26ee79c57d
6 changed files with 94 additions and 21 deletions

View file

@ -0,0 +1,64 @@
[gd_scene load_steps=2 format=3 uid="uid://b2te55um4ya0l"]
[ext_resource type="Script" path="res://scripts/ui/create_room.gd" id="1_2jvdo"]
[node name="CreateRoom" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_2jvdo")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -87.5
offset_top = -71.0
offset_right = 87.5
offset_bottom = 71.0
grow_horizontal = 2
grow_vertical = 2
[node name="UsernameHBox" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 8
[node name="Label" type="Label" parent="VBoxContainer/UsernameHBox"]
layout_mode = 2
size_flags_horizontal = 4
theme_override_font_sizes/font_size = 30
text = "Username:"
[node name="LineEdit" type="LineEdit" parent="VBoxContainer/UsernameHBox"]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
[node name="RoomnameHBox" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 8
[node name="Label" type="Label" parent="VBoxContainer/RoomnameHBox"]
layout_mode = 2
size_flags_horizontal = 4
theme_override_font_sizes/font_size = 30
text = "Roomname:"
[node name="LineEdit" type="LineEdit" parent="VBoxContainer/RoomnameHBox"]
custom_minimum_size = Vector2(300, 0)
layout_mode = 2
[node name="SendButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_font_sizes/font_size = 30
text = "Join Game"
[node name="Timer" type="Timer" parent="."]
wait_time = 10.0

View file

@ -11,13 +11,12 @@ var skip: bool = false
func _ready() -> void:
if Networking.isManager:
if timer.timeout.connect(_timer_done) != OK:
Log.error("FAILED to connect the timeout signal to _timer_done!", "Internal Error: Failed to connect signal.")
if timer.timeout.connect(_timer_done):
pass
first_frame.call_deferred()
func _timer_done() -> void:
if angry_meter > 0:
Log.debug("angrier %d" % angry_meter)
angry_meter -= 1
else:
timer.stop()

10
scripts/ui/create_room.gd Normal file
View file

@ -0,0 +1,10 @@
extends Control
func _ready() -> void:
if ($VBoxContainer/SendButton as Button).pressed.connect(_on_send_button_pressed):
pass
func _on_send_button_pressed() -> void:
Game.username = ($VBoxContainer/UsernameHBox/LineEdit as LineEdit).text
Game.roomname = ($VBoxContainer/RoomnameHBox/LineEdit as LineEdit).text
Networking.join_room()

View file

@ -6,11 +6,11 @@ extends Control
var label: PackedScene = preload("res://scenes/ui/elements/name_label.tscn")
func _ready() -> void:
if Networking.playerlist_changed.connect(_on_playerlist_changed) != OK:
Log.error("FAILED to connect the playerlist_changed signal to _on_playerlist_changed!", "Internal Error: Failed to connect signal.")
if Networking.playerlist_changed.connect(_on_playerlist_changed):
pass
var start_button: Button = $StartButton
if start_button.pressed.connect(_on_start_button_pressed) != OK:
Log.error("FAILED to connect the pressed signal to _on_start_button_pressed!", "Internal Error: Failed to connect signal.")
if start_button.pressed.connect(_on_start_button_pressed):
pass
_on_playerlist_changed()
func _on_playerlist_changed() -> void:

View file

@ -54,8 +54,9 @@ func _ready() -> void:
match launchmode:
0:
# Will eventually redirect to the main menu
pass
# Menu
if get_tree().change_scene_to_file("res://scenes/ui/create_room.tscn") != OK:
Log.error("Couldn't change to the create room scene! Closing application.", "Couldn't change to the create room scene!")
1:
# Client with direct join
Networking.join_room()

View file

@ -9,16 +9,16 @@ signal playerlist_changed()
# Connect the signals.
func _ready() -> void:
if multiplayer.connected_to_server.connect(_on_connected_ok) != OK:
Log.error("FAILED to connect the connected_to_server signal to _on_connected_ok!", "Internal Error: Failed to connect signal.")
if multiplayer.connection_failed.connect(close_network) != OK:
Log.error("FAILED to connect the connection_failed signal to _on_connected_fail!", "Internal Error: Failed to connect signal.")
if multiplayer.server_disconnected.connect(close_network) != OK:
Log.error("FAILED to connect the server_disconnected signal to _on_server_disconnected!", "Internal Error: Failed to connect signal.")
if multiplayer.peer_disconnected.connect(_on_peer_disconnected) != OK:
Log.error("FAILED to connect the peer_disconnected signal to _on_peer_disconnected!", "Internal Error: Failed to connect signal.")
if playerlist_changed.connect(_on_playerlist_changed) != OK:
Log.error("FAILED to connect the playerlist_changed signal to _on_playerlist_changed!", "Internal Error: Failed to connect signal.")
if multiplayer.connected_to_server.connect(_on_connected_ok):
pass
if multiplayer.connection_failed.connect(close_network):
pass
if multiplayer.server_disconnected.connect(close_network):
pass
if multiplayer.peer_disconnected.connect(_on_peer_disconnected):
pass
if playerlist_changed.connect(_on_playerlist_changed):
pass
func _on_playerlist_changed() -> void:
pass
@ -139,8 +139,7 @@ func host_disconnected_message() -> void:
Log.info("Host disconnected from the session.")
managerID = 1
close_network()
if get_tree().change_scene_to_file("res://start.tscn"):
Log.warning("Failed to change back to the main scene!")
Game._ready()
# This is the message sent out if a peer in the room has left.
@rpc("authority", "call_remote", "reliable")