diff options
Diffstat (limited to 'UI/GameLobby')
-rw-r--r-- | UI/GameLobby/game_lobby.gd | 57 | ||||
-rw-r--r-- | UI/GameLobby/game_lobby.tscn | 94 | ||||
-rw-r--r-- | UI/GameLobby/lobby_game.gd | 19 | ||||
-rw-r--r-- | UI/GameLobby/lobby_game.tscn | 19 |
4 files changed, 189 insertions, 0 deletions
diff --git a/UI/GameLobby/game_lobby.gd b/UI/GameLobby/game_lobby.gd new file mode 100644 index 0000000..9f13882 --- /dev/null +++ b/UI/GameLobby/game_lobby.gd @@ -0,0 +1,57 @@ +extends Control + + +var games := [] + +var refresh_interval := 15.0 + +@onready var lobby_game_scene := preload("res://UI/GameLobby/lobby_game.tscn") + + +func _ready() -> void: + %GamesList.get_child(0).queue_free() + + if await check_game_lobby_available(): + get_server_list() + $RefreshTimer.wait_time = refresh_interval + $RefreshTimer.start() + else: + %ServerNotReachable.text = %ServerNotReachable.text.replace("%SERVER%", Client.game_lobby_url) + + +func check_game_lobby_available(): + var is_available = await Client.check_game_lobby_available() + + %ServerNotReachable.visible = !is_available + + return is_available + + +func get_server_list(): + var response = await Client.request("%s/?get-list" % [Client.game_lobby_url], [], HTTPClient.METHOD_GET) + var result = response.parse_json() + print(result) + + if result["success"]: + for node in %GamesList.get_children(): + node.queue_free() + + for game in result["data"]: + var lobby_game = lobby_game_scene.instantiate() + lobby_game.game_id = game["id"] + lobby_game.game_name = game["name"] + %GamesList.add_child(lobby_game) + + +func _on_back_button_pressed() -> void: + get_tree().change_scene_to_file("res://UI/Start.tscn") + + +func _on_refresh_pressed() -> void: + if await check_game_lobby_available(): + get_server_list() + $RefreshTimer.start(refresh_interval) + + +func _on_refresh_timer_timeout() -> void: + get_server_list() diff --git a/UI/GameLobby/game_lobby.tscn b/UI/GameLobby/game_lobby.tscn new file mode 100644 index 0000000..241dbe5 --- /dev/null +++ b/UI/GameLobby/game_lobby.tscn @@ -0,0 +1,94 @@ +[gd_scene load_steps=5 format=3 uid="uid://b0uqf5h2j7fvk"] + +[ext_resource type="Script" path="res://UI/GameLobby/game_lobby.gd" id="1_1vvm7"] +[ext_resource type="Texture2D" uid="uid://kwgx33awj4y2" path="res://UI/Assets/Enjl-Starry Space Background/background_1.png" id="2_tyk1u"] +[ext_resource type="Theme" uid="uid://bt84t61hrvoyn" path="res://UI/PlayerLobby/lobby_theme.tres" id="3_3iumi"] +[ext_resource type="PackedScene" uid="uid://cs2a7wfrj4wn0" path="res://UI/GameLobby/lobby_game.tscn" id="3_83gpr"] + +[node name="GameLobby" 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_1vvm7") + +[node name="Background" type="Control" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="ColorRect" type="ColorRect" parent="Background"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0, 0, 0, 1) + +[node name="TextureRect" type="TextureRect" parent="Background"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("2_tyk1u") +stretch_mode = 1 + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 4 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 4 +theme_override_constants/margin_bottom = 4 + +[node name="CenterContainer" type="CenterContainer" parent="MarginContainer"] +layout_mode = 2 + +[node name="GamesList" type="VBoxContainer" parent="MarginContainer/CenterContainer"] +unique_name_in_owner = true +layout_mode = 2 + +[node name="LobbyGame" parent="MarginContainer/CenterContainer/GamesList" instance=ExtResource("3_83gpr")] +layout_mode = 2 + +[node name="ServerNotReachable" type="Label" parent="MarginContainer/CenterContainer"] +unique_name_in_owner = true +visible = false +layout_mode = 2 +text = "Game Lobby Server at %SERVER% not reachable" + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 8 +size_flags_vertical = 8 +theme = ExtResource("3_3iumi") + +[node name="Refresh" type="Button" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +mouse_default_cursor_shape = 2 +text = "Refresh" + +[node name="BackButton" type="Button" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +mouse_default_cursor_shape = 2 +text = "Back" + +[node name="RefreshTimer" type="Timer" parent="."] + +[connection signal="pressed" from="MarginContainer/VBoxContainer/Refresh" to="." method="_on_refresh_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/BackButton" to="." method="_on_back_button_pressed"] +[connection signal="timeout" from="RefreshTimer" to="." method="_on_refresh_timer_timeout"] diff --git a/UI/GameLobby/lobby_game.gd b/UI/GameLobby/lobby_game.gd new file mode 100644 index 0000000..4736d44 --- /dev/null +++ b/UI/GameLobby/lobby_game.gd @@ -0,0 +1,19 @@ +extends HBoxContainer + +@export var game_id := "" +@export var game_name := "": + set = set_game_name + + +func set_game_name(value): + game_name = value + %Name.text = value + + +func _on_join_pressed() -> void: + var response = await Network.request("%s/?join=%s" % [Client.game_lobby_url, game_id]) + var result = response.parse_json() + var game_data = result["data"] + + Network.join_game(game_data["ip"], game_data["port"]) + get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn") diff --git a/UI/GameLobby/lobby_game.tscn b/UI/GameLobby/lobby_game.tscn new file mode 100644 index 0000000..a6809ac --- /dev/null +++ b/UI/GameLobby/lobby_game.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=2 format=3 uid="uid://cs2a7wfrj4wn0"] + +[ext_resource type="Script" path="res://UI/GameLobby/lobby_game.gd" id="1_cvsql"] + +[node name="LobbyGame" type="HBoxContainer"] +script = ExtResource("1_cvsql") + +[node name="Name" type="Label" parent="."] +unique_name_in_owner = true +layout_mode = 2 +text = "Game Name" + +[node name="Join" type="Button" parent="."] +unique_name_in_owner = true +layout_mode = 2 +mouse_default_cursor_shape = 2 +text = "Join" + +[connection signal="pressed" from="Join" to="." method="_on_join_pressed"] |