push project up sabs assets
This commit is contained in:
100
scenes/screens/lobby_screen/lobby.gd
Normal file
100
scenes/screens/lobby_screen/lobby.gd
Normal file
@@ -0,0 +1,100 @@
|
||||
class_name Lobby extends LobbyBase
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Globals.lobby_data.lobby_ui = self
|
||||
|
||||
setup_signals()
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if Globals.multiplayer_data.is_multiplayer_active: return
|
||||
|
||||
if client.peer:
|
||||
client.close_connection()
|
||||
|
||||
func setup_signals() -> void:
|
||||
rpc_signals.match_list_entries.connect(_match_list_entries)
|
||||
rpc_signals.match_list_entry_activated.connect(_on_match_list_entry_activated)
|
||||
rpc_signals.match_list_entry_added.connect(_on_match_list_entry_added)
|
||||
rpc_signals.match_list_entry_removed.connect(_on_match_list_entry_removed)
|
||||
rpc_signals.match_list_entry_load_match.connect(_on_match_list_entry_load_match)
|
||||
|
||||
func _server_host_started() -> void:
|
||||
host_connect_bttn.visible = false
|
||||
|
||||
# NOTE: 'matches_list' can be empty but so long as we get the call from the
|
||||
# server we know we are connected and thus hide respective UI elements.
|
||||
func _match_list_entries(matches_list: Array) -> void:
|
||||
push_warning("Client Joined Host: Full Match List Recieved...\n", matches_list)
|
||||
|
||||
match_create_vbox.visible = true
|
||||
search_vbox.visible = true
|
||||
host_disconnect_bttn.visible = true
|
||||
host_connect_bttn.visible = false
|
||||
|
||||
for match_entry in matches_list:
|
||||
_create_match_entry(match_entry)
|
||||
|
||||
func _on_match_list_entry_activated(match_id: String) -> void:
|
||||
for match_entry in match_list.get_children():
|
||||
match_entry.join_bttn.visible = false
|
||||
if not match_entry.match_id == match_id: continue
|
||||
|
||||
active_match = match_entry
|
||||
match_entry.join_bttn.text = "Delete"
|
||||
match_entry.join_bttn.visible = true
|
||||
match_create_vbox.visible = false
|
||||
|
||||
match_entry.join_bttn.pressed.disconnect(_join_match)
|
||||
match_entry.join_bttn.pressed.connect(
|
||||
_delete_match.bind(match_entry.match_id)
|
||||
)
|
||||
|
||||
func _on_match_list_entry_added(match_entry: Dictionary) -> void:
|
||||
push_warning("Client: Added Match List Entry...", match_entry)
|
||||
_create_match_entry(match_entry)
|
||||
|
||||
func _on_match_list_entry_removed(match_id: String) -> void:
|
||||
push_warning("Client: Removed Match List Entry...", match_id)
|
||||
|
||||
if active_match && (match_id == active_match.match_id):
|
||||
active_match = null
|
||||
match_create_vbox.visible = true
|
||||
|
||||
for match_entry in match_list.get_children():
|
||||
if not active_match:
|
||||
match_entry.join_bttn.visible = true
|
||||
|
||||
if not match_id == match_entry.match_id: continue
|
||||
match_entry.queue_free()
|
||||
|
||||
func _on_match_list_entry_load_match(match_entry: Dictionary, is_player_1: bool) -> void:
|
||||
push_warning(
|
||||
"Client: Loading Game Match...\nMatch Data: ", match_entry, "\nis_player_1: ", is_player_1
|
||||
)
|
||||
|
||||
Globals.multiplayer_data.set_multiplayer_active()
|
||||
Globals.game_data.set_game_mode(match_entry.type)
|
||||
Globals.game_data.set_player_id(is_player_1)
|
||||
Globals.game_state.set_game_scene("res://scenes/game.tscn")
|
||||
|
||||
func _create_match_entry(match_entry: Dictionary) -> void:
|
||||
var container = MATCH_ENTRY.instantiate()
|
||||
match_list.add_child(container)
|
||||
|
||||
container.name_lbl.text = match_entry.name
|
||||
container.type_lbl.text = match_entry.type
|
||||
container.match_id = match_entry.match_id
|
||||
|
||||
container.join_bttn.pressed.connect(
|
||||
_join_match.bind(match_entry.match_id)
|
||||
)
|
||||
|
||||
if active_match:
|
||||
container.join_bttn.visible = false
|
||||
|
||||
func _join_match(match_id: String) -> void:
|
||||
Globals.lobby_data.rpc_id(1, "match_list_join_entry", match_id)
|
||||
|
||||
func _delete_match(match_id: String) -> void:
|
||||
Globals.lobby_data.rpc_id(1, "match_list_remove_entry", match_id)
|
||||
1
scenes/screens/lobby_screen/lobby.gd.uid
Normal file
1
scenes/screens/lobby_screen/lobby.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dk7afnf7ol7dy
|
||||
28
scenes/screens/lobby_screen/lobby.tscn
Normal file
28
scenes/screens/lobby_screen/lobby.tscn
Normal file
@@ -0,0 +1,28 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dkes5cdu45q6e"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dk7afnf7ol7dy" path="res://scenes/screens/lobby_screen/lobby.gd" id="1_hhiik"]
|
||||
[ext_resource type="PackedScene" uid="uid://dg7pgj6i5pk8p" path="res://scenes/ui_controls/lobby_screen/lobby_ui.tscn" id="2_lqt48"]
|
||||
[ext_resource type="Script" uid="uid://sihv0kwbcr33" path="res://scenes/screens/lobby_screen/lobby_rpc.gd" id="3_rurl6"]
|
||||
[ext_resource type="Script" uid="uid://ci57tiuqsx1jp" path="res://scripts/client_networking.gd" id="4_glu7g"]
|
||||
|
||||
[node name="lobby" type="Node"]
|
||||
script = ExtResource("1_hhiik")
|
||||
|
||||
[node name="ui" parent="." instance=ExtResource("2_lqt48")]
|
||||
|
||||
[node name="rpc_signals" type="Node" parent="."]
|
||||
script = ExtResource("3_rurl6")
|
||||
|
||||
[node name="client" type="Node" parent="."]
|
||||
script = ExtResource("4_glu7g")
|
||||
|
||||
[connection signal="pressed" from="ui/body/left_body/server_host_hbox/home_bttn" to="." method="_on_home_bttn_pressed"]
|
||||
[connection signal="pressed" from="ui/body/left_body/server_host_hbox/host_connect_bttn" to="." method="_on_host_connect_bttn_pressed"]
|
||||
[connection signal="pressed" from="ui/body/left_body/server_host_hbox/host_disconnect_bttn" to="." method="_on_host_disconnect_bttn_pressed"]
|
||||
[connection signal="pressed" from="ui/body/left_body/search_vbox/search_hbox/match_search_bttn" to="." method="_on_match_search_bttn_pressed"]
|
||||
[connection signal="pressed" from="ui/body/right_body/create_match_hbox/match_create_bttn" to="." method="_on_match_create_bttn_pressed"]
|
||||
[connection signal="pressed" from="ui/body/right_body/vbox/8ball" to="." method="_on_mode_bttn_pressed" flags=18]
|
||||
[connection signal="pressed" from="ui/body/right_body/vbox/9ball" to="." method="_on_mode_bttn_pressed" flags=18]
|
||||
[connection signal="pressed" from="ui/body/right_body/vbox/snooker" to="." method="_on_mode_bttn_pressed" flags=18]
|
||||
|
||||
[editable path="ui"]
|
||||
58
scenes/screens/lobby_screen/lobby_base.gd
Normal file
58
scenes/screens/lobby_screen/lobby_base.gd
Normal file
@@ -0,0 +1,58 @@
|
||||
class_name LobbyBase extends Node
|
||||
|
||||
|
||||
const MATCH_ENTRY = preload("res://scenes/screens/lobby_screen/match_entry.tscn")
|
||||
|
||||
@onready var host_address_input: LineEdit = $ui/body/left_body/server_host_hbox/host_address_input
|
||||
@onready var host_port_range: SpinBox = $ui/body/left_body/server_host_hbox/host_port_range
|
||||
@onready var host_connect_bttn: Button = $ui/body/left_body/server_host_hbox/host_connect_bttn
|
||||
@onready var host_disconnect_bttn: Button = $ui/body/left_body/server_host_hbox/host_disconnect_bttn
|
||||
|
||||
@onready var search_vbox: VBoxContainer = $ui/body/left_body/search_vbox
|
||||
@onready var match_search_input: LineEdit = $ui/body/left_body/search_vbox/search_hbox/match_search_input
|
||||
@onready var match_list: VBoxContainer = $ui/body/left_body/search_vbox/scroll_container/match_list
|
||||
|
||||
@onready var match_create_vbox: VBoxContainer = $ui/body/right_body
|
||||
@onready var new_match_name_input: LineEdit = $ui/body/right_body/create_match_hbox/new_match_name_input
|
||||
|
||||
@onready var rpc_signals: Node = $rpc_signals
|
||||
@onready var client: Node = $client
|
||||
|
||||
var active_mode: String = "snooker"
|
||||
var active_match: HBoxContainer = null
|
||||
|
||||
|
||||
func _on_home_bttn_pressed() -> void:
|
||||
Globals.game_state.set_game_scene(
|
||||
"res://scenes/screens/start_screen/start.tscn"
|
||||
)
|
||||
|
||||
func _on_host_connect_bttn_pressed() -> void:
|
||||
client.start_client(host_address_input.text, int(host_port_range.value))
|
||||
|
||||
func _on_host_disconnect_bttn_pressed() -> void:
|
||||
match_create_vbox.visible = false
|
||||
search_vbox.visible = false
|
||||
host_disconnect_bttn.visible = false
|
||||
host_connect_bttn.visible = true
|
||||
|
||||
for match_block in match_list.get_children():
|
||||
match_block.queue_free()
|
||||
|
||||
client.close_connection()
|
||||
|
||||
func _on_match_search_bttn_pressed() -> void:
|
||||
pass
|
||||
|
||||
func _on_match_create_bttn_pressed() -> void:
|
||||
if active_match: return
|
||||
|
||||
var match_entry: Dictionary = {
|
||||
"name": new_match_name_input.text,
|
||||
"type": active_mode
|
||||
}
|
||||
|
||||
Globals.lobby_data.rpc_id(1, "match_list_add_entry", match_entry)
|
||||
|
||||
func _on_mode_bttn_pressed(button: Button) -> void:
|
||||
active_mode = button.text.remove_chars("-").to_lower()
|
||||
1
scenes/screens/lobby_screen/lobby_base.gd.uid
Normal file
1
scenes/screens/lobby_screen/lobby_base.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://5tvhtoe6fdu1
|
||||
35
scenes/screens/lobby_screen/lobby_rpc.gd
Normal file
35
scenes/screens/lobby_screen/lobby_rpc.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
extends Node
|
||||
|
||||
|
||||
signal match_list_entries(match_list: Array)
|
||||
signal match_list_entry_activated(match_id: String)
|
||||
signal match_list_entry_added(match_entry: Dictionary)
|
||||
signal match_list_entry_removed(match_id: String)
|
||||
signal match_list_entry_load_match(
|
||||
match_entry: Dictionary, is_player_1: bool
|
||||
)
|
||||
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func match_list_add_entry(match_entry: Dictionary) -> void:
|
||||
push_warning("Client received new match entry...")
|
||||
match_list_entry_added.emit(match_entry)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func match_list_remove_entry(match_id: String) -> void:
|
||||
push_warning("Client received delete match entry...")
|
||||
match_list_entry_removed.emit(match_id)
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func receive_match_list(match_list: Array) -> void:
|
||||
push_warning("Client received match list...")
|
||||
match_list_entries.emit(match_list)
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func match_list_activate_entry(match_id: String) -> void:
|
||||
push_warning("Client set active match entry...")
|
||||
match_list_entry_activated.emit(match_id)
|
||||
|
||||
func load_game_scene(match_entry: Dictionary, is_player_1: bool) -> void:
|
||||
push_warning("Client load game scene...")
|
||||
match_list_entry_load_match.emit(match_entry, is_player_1)
|
||||
1
scenes/screens/lobby_screen/lobby_rpc.gd.uid
Normal file
1
scenes/screens/lobby_screen/lobby_rpc.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://sihv0kwbcr33
|
||||
8
scenes/screens/lobby_screen/match_entry.gd
Normal file
8
scenes/screens/lobby_screen/match_entry.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
class_name MatchEntry extends HBoxContainer
|
||||
|
||||
|
||||
@onready var name_lbl: Label = $name_lbl
|
||||
@onready var type_lbl: Label = $type_lbl
|
||||
@onready var join_bttn: Button = $join_bttn
|
||||
|
||||
var match_id: String = ""
|
||||
1
scenes/screens/lobby_screen/match_entry.gd.uid
Normal file
1
scenes/screens/lobby_screen/match_entry.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ck663xy8rqumo
|
||||
23
scenes/screens/lobby_screen/match_entry.tscn
Normal file
23
scenes/screens/lobby_screen/match_entry.tscn
Normal file
@@ -0,0 +1,23 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b5b18vkfe3caa"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ck663xy8rqumo" path="res://scenes/screens/lobby_screen/match_entry.gd" id="1_kw53p"]
|
||||
|
||||
[node name="match_entry" type="HBoxContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_kw53p")
|
||||
|
||||
[node name="name_lbl" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="type_lbl" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="join_bttn" type="Button" parent="."]
|
||||
layout_mode = 2
|
||||
text = "Join"
|
||||
Reference in New Issue
Block a user