summaryrefslogtreecommitdiff
path: root/UI
diff options
context:
space:
mode:
Diffstat (limited to 'UI')
-rw-r--r--UI/GameLobby/game_lobby.gd57
-rw-r--r--UI/GameLobby/game_lobby.tscn94
-rw-r--r--UI/GameLobby/lobby_game.gd19
-rw-r--r--UI/GameLobby/lobby_game.tscn19
-rw-r--r--UI/PlayerLobby/Lobby.tscn (renamed from UI/Lobby.tscn)47
-rw-r--r--UI/PlayerLobby/lobby.gd201
-rw-r--r--UI/PlayerLobby/lobby_setting.gd42
-rw-r--r--UI/PlayerLobby/lobby_setting.tscn (renamed from UI/lobby_setting.tscn)6
-rw-r--r--UI/PlayerLobby/lobby_theme.tres (renamed from UI/lobby_theme.tres)0
-rw-r--r--UI/Start.gd40
-rw-r--r--UI/Start.tscn21
-rw-r--r--UI/lobby.gd135
-rw-r--r--UI/lobby_setting.gd26
-rw-r--r--UI/players_list_container.gd24
-rw-r--r--UI/players_list_container.tscn54
-rw-r--r--UI/spawn_button.gd19
16 files changed, 576 insertions, 228 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"]
diff --git a/UI/Lobby.tscn b/UI/PlayerLobby/Lobby.tscn
index 08055de..228d512 100644
--- a/UI/Lobby.tscn
+++ b/UI/PlayerLobby/Lobby.tscn
@@ -1,9 +1,9 @@
-[gd_scene load_steps=12 format=3 uid="uid://r45j806p4a74"]
+[gd_scene load_steps=11 format=3 uid="uid://r45j806p4a74"]
-[ext_resource type="Script" path="res://UI/lobby.gd" id="1_mm4gt"]
+[ext_resource type="Script" path="res://UI/PlayerLobby/lobby.gd" id="1_mm4gt"]
[ext_resource type="Texture2D" uid="uid://kwgx33awj4y2" path="res://UI/Assets/Enjl-Starry Space Background/background_1.png" id="2_0pdjl"]
-[ext_resource type="PackedScene" uid="uid://dslebs7aarkoa" path="res://UI/panel_background_blue.tscn" id="2_1qhg6"]
-[ext_resource type="Theme" uid="uid://bt84t61hrvoyn" path="res://UI/lobby_theme.tres" id="2_syjfh"]
+[ext_resource type="Theme" uid="uid://bt84t61hrvoyn" path="res://UI/PlayerLobby/lobby_theme.tres" id="2_syjfh"]
+[ext_resource type="PackedScene" uid="uid://cq6p055yuac0o" path="res://UI/players_list_container.tscn" id="3_2r7nj"]
[ext_resource type="PackedScene" uid="uid://bl65jllb3e2py" path="res://Stages/Wintermaul/Wintermaul.tscn" id="3_3hc3h"]
[ext_resource type="Texture2D" uid="uid://ci7qydmwbanbp" path="res://Stages/Wintermaul/Assets/thumbnail.png" id="3_8r1n2"]
[ext_resource type="PackedScene" uid="uid://dwscklgkbhq28" path="res://Stages/Wintermaul2/Wintermaul2.tscn" id="4_v1caa"]
@@ -11,8 +11,6 @@
[ext_resource type="PackedScene" uid="uid://jxy7fj7yymfl" path="res://Stages/TinySwords/WintermaulTinySwords.tscn" id="5_hnsfx"]
[ext_resource type="Texture2D" uid="uid://cujvoqsqfrl4a" path="res://Stages/Wintermaul2/Assets/thumbnail.png" id="5_j23oc"]
-[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_fm6m2"]
-
[node name="Lobby" type="Control"]
layout_mode = 3
anchors_preset = 15
@@ -73,39 +71,13 @@ layout_mode = 2
size_flags_vertical = 3
theme_override_constants/separation = 32
-[node name="PanelContainer" type="PanelContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"]
-layout_mode = 2
-size_flags_horizontal = 3
-theme_override_styles/panel = SubResource("StyleBoxEmpty_fm6m2")
-
-[node name="PanelBackgroundBlue" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer" instance=ExtResource("2_1qhg6")]
-layout_mode = 2
-
-[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer"]
-layout_mode = 2
-theme_override_constants/margin_left = 16
-theme_override_constants/margin_top = 16
-theme_override_constants/margin_right = 16
-theme_override_constants/margin_bottom = 16
-
-[node name="PlayersList" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer"]
+[node name="Teams" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"]
unique_name_in_owner = true
-custom_minimum_size = Vector2(0, 100)
layout_mode = 2
-[node name="Control" type="MarginContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList"]
-layout_mode = 2
-
-[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList/Control"]
-layout_mode = 2
-text = "A"
-
-[node name="Control2" type="MarginContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList"]
-layout_mode = 2
-
-[node name="Label2" type="Label" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/PanelContainer/MarginContainer/PlayersList/Control2"]
+[node name="PlayersListContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Teams" instance=ExtResource("3_2r7nj")]
+unique_name_in_owner = true
layout_mode = 2
-text = "B"
[node name="Maps" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"]
unique_name_in_owner = true
@@ -120,7 +92,7 @@ toggle_mode = true
text = "Wintermaul"
metadata/map_scene = ExtResource("3_3hc3h")
metadata/thumbnail = ExtResource("3_8r1n2")
-metadata/settings = ["starting_lives", "starting_money", "starting_income"]
+metadata/settings = ["starting_lives", "starting_money", "starting_income", "use_premade_teams"]
[node name="MapButton2" type="Button" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Maps"]
layout_mode = 2
@@ -176,5 +148,8 @@ layout_mode = 2
mouse_default_cursor_shape = 2
text = "Cancel"
+[node name="KeepAliveTimer" type="Timer" parent="."]
+wait_time = 30.0
+
[connection signal="pressed" from="MarginContainer/VBoxContainer/VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/VBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"]
diff --git a/UI/PlayerLobby/lobby.gd b/UI/PlayerLobby/lobby.gd
new file mode 100644
index 0000000..6506097
--- /dev/null
+++ b/UI/PlayerLobby/lobby.gd
@@ -0,0 +1,201 @@
+extends Control
+
+
+signal joined
+
+var current_map_idx := 0
+var current_map_scene: Node
+
+var settings := {}
+var teams := {}
+
+@onready var list: Control = %PlayersListContainer.list
+
+
+func _ready() -> void:
+ if not multiplayer.is_server():
+ %StartButton.disabled = true
+
+ if multiplayer.is_server():
+ joined.connect(func():
+ set_map.rpc(current_map_idx)
+ )
+ for idx in %Maps.get_child_count():
+ %Maps.get_child(idx).pressed.connect(func():
+ if current_map_idx != idx:
+ set_map.rpc(idx)
+ )
+
+ if not multiplayer.is_server():
+ for node: Control in %Maps.get_children():
+ node.mouse_filter = Control.MOUSE_FILTER_IGNORE
+
+ Network.players_changed.connect(update_players)
+ update_players()
+
+ multiplayer.peer_disconnected.connect(remove_player)
+ multiplayer.peer_connected.connect(_on_peer_connected)
+ multiplayer.peer_disconnected.connect(_on_peer_disconnected)
+
+ # reset map texture for clean load
+ %Thumbnail.texture = null
+ set_map(current_map_idx)
+
+ # send keep-alive to game-lobby-server
+ if multiplayer.is_server():
+ $KeepAliveTimer.start()
+ $KeepAliveTimer.timeout.connect(func():
+ Client.request(Client.game_lobby_url, [], HTTPClient.METHOD_POST, JSON.stringify({"keep-alive": Client.current_game_id}))
+ )
+
+
+func update_players():
+ update_list(list, Network.get_ordered_player_ids())
+
+
+func remove_player(id):
+ list.remove_child(list.get_node(str(id)))
+
+
+func update_list(current_list: Control, player_ids: Array):
+ for id in player_ids:
+ var player: Player = Network.get_player(id)
+
+ var control: Control = current_list.get_node_or_null(str(id))
+ if not control:
+ control = MarginContainer.new()
+ control.name = str(id)
+ var label = Label.new()
+ label.add_theme_color_override("font_color", player.get_color())
+ if id == multiplayer.get_unique_id():
+ label.add_theme_color_override("font_outline_color", Color(0.75, 0.75, 0.75, 0.75))
+ label.add_theme_constant_override("outline_size", 10)
+ control.add_child(label)
+ current_list.add_child(control)
+ #joined.emit()
+
+ control.get_child(0).text = str(player.username)
+ control.get_child(0).tooltip_text = str(id)
+ current_list.move_child(control, player_ids.find(id) + 1)
+
+
+func _on_peer_connected(id):
+ Network._on_peer_connected(id)
+func _on_peer_disconnected(id):
+ Network._on_peer_disconnected(id)
+
+
+func _on_start_button_pressed() -> void:
+ start.rpc()
+
+
+func _on_cancel_button_pressed() -> void:
+ multiplayer.multiplayer_peer.close()
+
+ await Client.request(
+ "%s" % [Client.game_lobby_url],
+ [],
+ HTTPClient.METHOD_POST,
+ JSON.stringify({"close": Client.current_game_id})
+ )
+
+ # TODO: if was host => Start. if was joined and connected from list => List
+ get_tree().change_scene_to_file("res://UI/Start.tscn")
+
+
+@rpc("authority", "call_local")
+func start():
+ var packed_scene = %Maps.get_child(current_map_idx).get_meta("map_scene")
+ var scene = packed_scene.instantiate()
+
+ for setting in settings:
+ scene[setting] = settings[setting]
+
+ if settings.get("use_premade_teams"):
+ var premade_teams = {}
+ for team_name in teams:
+ premade_teams[team_name] = teams[team_name]["players"]
+ scene.premade_teams = premade_teams
+
+ Client.change_scene_to_instance(scene)
+
+
+@rpc("authority", "call_local")
+func set_map(index: int):
+ current_map_idx = index
+
+ for node: Control in %Teams.get_children().slice(1):
+ node.queue_free()
+ %PlayersListContainer.visible = true
+
+ for node: Button in %Maps.get_children():
+ node.add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 0.5))
+
+ var map_button = %Maps.get_child(index)
+ var thumbnail = map_button.get_meta("thumbnail")
+
+ # settings
+ for child in %Settings.get_children():
+ child.queue_free()
+ if map_button.has_meta("settings"):
+ current_map_scene = map_button.get_meta("map_scene").instantiate()
+ var map_settings = map_button.get_meta("settings", [])
+ for setting in map_settings:
+ settings[setting] = current_map_scene[setting]
+ var control = preload("res://UI/PlayerLobby/lobby_setting.tscn").instantiate()
+ control.label = setting
+ control.value = settings[setting]
+ control.disabled = !multiplayer.is_server()
+ if multiplayer.is_server():
+ control.value_changed.connect(func(value):
+ set_setting.rpc(setting, value)
+ )
+ %Settings.add_child(control)
+
+ map_button.add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 1.0))
+ %Thumbnail.texture = thumbnail
+
+
+@rpc("authority", "call_local")
+func set_setting(key: String, value: Variant):
+ settings[key] = value
+
+ if not multiplayer.is_server():
+ %Settings.get_node(key).value = value
+
+ # generate PlayersLists per team with clickable labels to switch team
+ if settings.get("use_premade_teams"):
+ %PlayersListContainer.visible = false
+ var team_names = current_map_scene.teams.names()
+ var players_per_team = Network.get_ordered_player_ids().size() / team_names.size()
+ for idx in team_names.size():
+ var team_name = team_names[idx]
+
+ var new_list_container = preload("res://UI/players_list_container.tscn").instantiate()
+ new_list_container.label = team_name.to_upper()
+ new_list_container.clicked.connect(func():
+ switch_team.rpc(team_name)
+ )
+ %Teams.add_child(new_list_container)
+
+ var offset = players_per_team * idx
+ teams[team_name] = {}
+ teams[team_name]["players"] = Network.get_ordered_player_ids().slice(offset, offset + players_per_team)
+ teams[team_name]["list"] = new_list_container.list
+
+ update_list(teams[team_name]["list"], teams[team_name]["players"])
+
+
+@rpc("any_peer", "call_local")
+func switch_team(team_name: String):
+#func switch_team(previous_team_name: String, new_team_name: String):
+ var player_id = multiplayer.get_remote_sender_id()
+
+ for key in teams:
+ var team = teams[key]
+ team["players"].erase(player_id)
+ var node = team["list"].get_node_or_null(str(player_id))
+ if node: team["list"].remove_child(node)
+
+ teams[team_name]["players"].append(player_id)
+ update_list(teams[team_name]["list"], teams[team_name]["players"])
diff --git a/UI/PlayerLobby/lobby_setting.gd b/UI/PlayerLobby/lobby_setting.gd
new file mode 100644
index 0000000..8f0efe3
--- /dev/null
+++ b/UI/PlayerLobby/lobby_setting.gd
@@ -0,0 +1,42 @@
+extends HBoxContainer
+
+
+signal value_changed(value: Variant)
+
+var label := "":
+ set(value):
+ $Label.text = str(value)
+ name = str(value)
+ get():
+ return $Label.text
+
+var value: Variant = "":
+ set(new_value):
+ value = new_value
+ if typeof(new_value) == TYPE_BOOL:
+ $TextEdit.visible = false
+ $CheckBox.visible = true
+
+ $CheckBox.set_pressed_no_signal(new_value)
+ else:
+ $TextEdit.visible = true
+ $CheckBox.visible = false
+ $TextEdit.text = str(new_value)
+ get():
+ if typeof(value) == TYPE_BOOL:
+ return $CheckBox.button_pressed
+ else:
+ return $TextEdit.text
+
+var disabled := false:
+ set(value):
+ disabled = value
+ $TextEdit.editable = !value
+ $CheckBox.disabled = value
+
+
+func _on_text_edit_text_changed(new_text: String) -> void:
+ value_changed.emit(new_text)
+
+func _on_check_box_toggled(_toggled_on: bool) -> void:
+ value_changed.emit($CheckBox.button_pressed)
diff --git a/UI/lobby_setting.tscn b/UI/PlayerLobby/lobby_setting.tscn
index 8c462b4..62d1c66 100644
--- a/UI/lobby_setting.tscn
+++ b/UI/PlayerLobby/lobby_setting.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://fgqkxat8pwjk"]
-[ext_resource type="Script" path="res://UI/lobby_setting.gd" id="1_ntovh"]
+[ext_resource type="Script" path="res://UI/PlayerLobby/lobby_setting.gd" id="1_ntovh"]
[node name="LobbySetting" type="HBoxContainer"]
size_flags_vertical = 2
@@ -14,4 +14,8 @@ text = "Setting"
layout_mode = 2
text = "5"
+[node name="CheckBox" type="CheckBox" parent="."]
+layout_mode = 2
+
[connection signal="text_changed" from="TextEdit" to="." method="_on_text_edit_text_changed"]
+[connection signal="toggled" from="CheckBox" to="." method="_on_check_box_toggled"]
diff --git a/UI/lobby_theme.tres b/UI/PlayerLobby/lobby_theme.tres
index 0307ae1..0307ae1 100644
--- a/UI/lobby_theme.tres
+++ b/UI/PlayerLobby/lobby_theme.tres
diff --git a/UI/Start.gd b/UI/Start.gd
index fbfa8db..b078d65 100644
--- a/UI/Start.gd
+++ b/UI/Start.gd
@@ -6,9 +6,11 @@ func _ready():
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
if OS.has_environment("USER"):
- %Name.text = OS.get_environment("USER")
+ %Username.text = OS.get_environment("USER")
elif OS.has_environment("USERNAME"):
- %Name.text = OS.get_environment("USERNAME")
+ %Username.text = OS.get_environment("USERNAME")
+
+ %GameName.text = "%s's Game" % [%Username.text]
func get_ip() -> String:
@@ -27,19 +29,37 @@ func get_port() -> int:
return port
+func _on_peer_connected(id):
+ Network._on_peer_connected(id)
+func _on_peer_disconnected(id):
+ Network._on_peer_disconnected(id)
+
+
func _on_host_pressed() -> void:
- Client.player.username = %Name.text
+ Client.player.username = %Username.text
+
+ var response = await Client.request(
+ "%s" % [Client.game_lobby_url],
+ [],
+ HTTPClient.METHOD_POST,
+ JSON.stringify({"host": true, "port": get_port(), "name" : %GameName.text})
+ )
+
+ if response.result_code == HTTPRequest.RESULT_SUCCESS:
+ var result = response.parse_json()
+ if result["success"]:
+ Client.current_game_id = result["data"]
+
Network.host_game(get_port())
- get_tree().change_scene_to_file("res://UI/Lobby.tscn")
+ get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn")
func _on_join_pressed() -> void:
- Client.player.username = %Name.text
+ Client.player.username = %Username.text
Network.join_game(get_ip(), get_port())
- get_tree().change_scene_to_file("res://UI/Lobby.tscn")
+ get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn")
-func _on_peer_connected(id):
- Network._on_peer_connected(id)
-func _on_peer_disconnected(id):
- Network._on_peer_disconnected(id)
+func _on_search_pressed() -> void:
+ Client.player.username = %Username.text
+ get_tree().change_scene_to_file("res://UI/GameLobby/game_lobby.tscn")
diff --git a/UI/Start.tscn b/UI/Start.tscn
index 64b789d..efa061c 100644
--- a/UI/Start.tscn
+++ b/UI/Start.tscn
@@ -52,11 +52,18 @@ grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
layout_mode = 2
-[node name="Name" type="LineEdit" parent="CenterContainer/VBoxContainer"]
+[node name="GameName" type="LineEdit" parent="CenterContainer/VBoxContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(175, 0)
+layout_mode = 2
+theme_override_font_sizes/font_size = 18
+placeholder_text = "Game Name"
+
+[node name="Username" type="LineEdit" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
-placeholder_text = "Name"
+placeholder_text = "Username"
[node name="Host" type="Button" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
@@ -86,5 +93,15 @@ mouse_default_cursor_shape = 2
theme_override_font_sizes/font_size = 24
text = "Join"
+[node name="Search" type="Button" parent="CenterContainer/VBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+mouse_default_cursor_shape = 2
+theme_override_font_sizes/font_size = 24
+text = "Search"
+
+[node name="ServerHost" type="HTTPRequest" parent="."]
+
[connection signal="pressed" from="CenterContainer/VBoxContainer/Host" to="." method="_on_host_pressed"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/Join" to="." method="_on_join_pressed"]
+[connection signal="pressed" from="CenterContainer/VBoxContainer/Search" to="." method="_on_search_pressed"]
diff --git a/UI/lobby.gd b/UI/lobby.gd
deleted file mode 100644
index f7d8405..0000000
--- a/UI/lobby.gd
+++ /dev/null
@@ -1,135 +0,0 @@
-extends Control
-
-
-signal joined
-
-var current_map_idx := 0
-
-var settings := {}
-
-@onready var list: VBoxContainer = %PlayersList
-
-
-func _ready() -> void:
- if not multiplayer.is_server():
- %StartButton.disabled = true
- #%StartButton.queue_free()
-
- %PlayersList.remove_child(%PlayersList.get_child(0))
- %PlayersList.remove_child(%PlayersList.get_child(0))
-
- if multiplayer.is_server():
- set_map.rpc(current_map_idx)
- joined.connect(func():
- set_map.rpc(current_map_idx)
- )
- for idx in %Maps.get_child_count():
- %Maps.get_child(idx).pressed.connect(func():
- set_map.rpc(idx)
- )
- if not multiplayer.is_server():
- set_map(0)
- for node: Control in %Maps.get_children():
- node.mouse_filter = Control.MOUSE_FILTER_IGNORE
-
- Network.players_changed.connect(update_players)
- update_players()
-
- multiplayer.peer_disconnected.connect(remove_player)
- multiplayer.peer_connected.connect(_on_peer_connected)
- multiplayer.peer_disconnected.connect(_on_peer_disconnected)
-
- # reset map texture for clean load
- %Thumbnail.texture = null
- set_map(current_map_idx)
-
-
-func update_players():
- for id in Network.get_ordered_player_ids():
- var player: Player = Network.get_player(id)
-
- var control: Control = list.get_node_or_null(str(id))
- if not control:
- control = MarginContainer.new()
- control.name = str(id)
- var label = Label.new()
- label.add_theme_color_override("font_color", player.get_color())
- if id == multiplayer.get_unique_id():
- label.add_theme_color_override("font_outline_color", Color(0.75, 0.75, 0.75, 0.75))
- label.add_theme_constant_override("outline_size", 10)
- control.add_child(label)
- list.add_child(control)
- joined.emit()
-
- control.get_child(0).text = str(player.username)
- control.get_child(0).tooltip_text = str(id)
- list.move_child(control, Network.get_ordered_player_ids().find(id) + 1)
-
-
-func remove_player(id):
- list.remove_child(list.get_node(str(id)))
-
-
-func _on_peer_connected(id):
- Network._on_peer_connected(id)
-func _on_peer_disconnected(id):
- Network._on_peer_disconnected(id)
-
-
-func _on_start_button_pressed() -> void:
- start.rpc()
-
-
-func _on_cancel_button_pressed() -> void:
- multiplayer.multiplayer_peer.close()
- get_tree().change_scene_to_file("res://UI/Start.tscn")
-
-
-@rpc("authority", "call_local")
-func start():
- var packed_scene = %Maps.get_child(current_map_idx).get_meta("map_scene")
- var scene = packed_scene.instantiate()
-
- for setting in settings:
- scene[setting] = settings[setting]
-
- Client.change_scene_to_instance(scene)
-
-
-@rpc("authority", "call_local")
-func set_map(index: int):
- current_map_idx = index
-
- for node: Button in %Maps.get_children():
- node.add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 0.5))
-
- var node = %Maps.get_child(index)
- var thumbnail = node.get_meta("thumbnail")
-
- # settings
- for child in %Settings.get_children():
- child.queue_free()
- if node.get_meta("settings"):
- var scene = node.get_meta("map_scene").instantiate()
- for setting in node.get_meta("settings", []):
- settings[setting] = scene[setting]
- var control = preload("res://UI/lobby_setting.tscn").instantiate()
- control.label = setting
- control.value = settings[setting]
- control.disabled = !multiplayer.is_server()
- if multiplayer.is_server():
- control.value_changed.connect(func(value):
- set_setting.rpc(setting, value)
- )
- %Settings.add_child(control)
-
- node.add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 1.0))
- %Thumbnail.texture = thumbnail
-
-
-@rpc("authority", "call_local")
-func set_setting(key: String, value: Variant):
- settings[key] = value
-
- if not multiplayer.is_server():
- %Settings.get_node(key).value = value
diff --git a/UI/lobby_setting.gd b/UI/lobby_setting.gd
deleted file mode 100644
index a5b9e7e..0000000
--- a/UI/lobby_setting.gd
+++ /dev/null
@@ -1,26 +0,0 @@
-extends HBoxContainer
-
-
-signal value_changed(value: String)
-
-var label := "":
- set(value):
- $Label.text = str(value)
- name = str(value)
- get():
- return $Label.text
-
-var value: Variant = "":
- set(value):
- $TextEdit.text = str(value)
- get():
- return $TextEdit.text
-
-var disabled := false:
- set(value):
- disabled = value
- $TextEdit.editable = !disabled
-
-
-func _on_text_edit_text_changed(new_text: String) -> void:
- value_changed.emit(new_text)
diff --git a/UI/players_list_container.gd b/UI/players_list_container.gd
new file mode 100644
index 0000000..238a703
--- /dev/null
+++ b/UI/players_list_container.gd
@@ -0,0 +1,24 @@
+extends VBoxContainer
+
+
+signal clicked
+
+@export var label: String:
+ set(value):
+ label = value
+ $Label.text = value
+ $Label.visible = !!value
+
+@onready var list := %PlayersList
+
+
+func _ready():
+ $Label.visible = !!label
+
+ list.remove_child(list.get_child(0))
+ list.remove_child(list.get_child(0))
+
+
+func _on_label_gui_input(event: InputEvent) -> void:
+ if event.is_action("select"):
+ clicked.emit()
diff --git a/UI/players_list_container.tscn b/UI/players_list_container.tscn
new file mode 100644
index 0000000..8920286
--- /dev/null
+++ b/UI/players_list_container.tscn
@@ -0,0 +1,54 @@
+[gd_scene load_steps=4 format=3 uid="uid://cq6p055yuac0o"]
+
+[ext_resource type="Script" path="res://UI/players_list_container.gd" id="1_f2j1s"]
+[ext_resource type="PackedScene" uid="uid://dslebs7aarkoa" path="res://UI/panel_background_blue.tscn" id="1_y7ccy"]
+
+[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_fm6m2"]
+
+[node name="VBoxContainer" type="VBoxContainer"]
+offset_right = 64.0
+offset_bottom = 132.0
+script = ExtResource("1_f2j1s")
+
+[node name="Label" type="Label" parent="."]
+layout_mode = 2
+mouse_filter = 0
+mouse_default_cursor_shape = 2
+text = "Label"
+
+[node name="PlayersListContainer" type="PanelContainer" parent="."]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 3
+theme_override_styles/panel = SubResource("StyleBoxEmpty_fm6m2")
+
+[node name="PanelBackgroundBlue" parent="PlayersListContainer" instance=ExtResource("1_y7ccy")]
+layout_mode = 2
+
+[node name="MarginContainer" type="MarginContainer" parent="PlayersListContainer"]
+layout_mode = 2
+theme_override_constants/margin_left = 16
+theme_override_constants/margin_top = 16
+theme_override_constants/margin_right = 16
+theme_override_constants/margin_bottom = 16
+
+[node name="PlayersList" type="VBoxContainer" parent="PlayersListContainer/MarginContainer"]
+unique_name_in_owner = true
+custom_minimum_size = Vector2(0, 100)
+layout_mode = 2
+
+[node name="Control" type="MarginContainer" parent="PlayersListContainer/MarginContainer/PlayersList"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="PlayersListContainer/MarginContainer/PlayersList/Control"]
+layout_mode = 2
+text = "A"
+
+[node name="Control2" type="MarginContainer" parent="PlayersListContainer/MarginContainer/PlayersList"]
+layout_mode = 2
+
+[node name="Label2" type="Label" parent="PlayersListContainer/MarginContainer/PlayersList/Control2"]
+layout_mode = 2
+text = "B"
+
+[connection signal="gui_input" from="Label" to="." method="_on_label_gui_input"]
diff --git a/UI/spawn_button.gd b/UI/spawn_button.gd
index 70ff3f5..bcf9da0 100644
--- a/UI/spawn_button.gd
+++ b/UI/spawn_button.gd
@@ -1,33 +1,16 @@
extends TextureButton
-@export var texture: Texture2D
-@export var sprite_sheet: SpriteFrames
-
-@export var cost := 5
-@export var hp := 5
-@export var speed := 100
-
@export var unit_resource: UnitResource
func _ready():
- tooltip_text = "Cost: " + str(cost)
+ tooltip_text = "Cost: " + str(unit_resource.cost) + "\n" + "Income: " + str(unit_resource.income)
func _on_pressed() -> void:
var unit = preload("res://Units/Unit.tscn").instantiate() as Unit
- #if texture:
- #unit.get_node("Sprite2D").texture = texture
- #unit.get_node("Sprite2D").scale = Vector2(32,32) / texture.get_size()
-
- #if sprite_sheet:
- #unit.get_node("AnimatedSprite2D").sprite_frames = sprite_sheet
-
unit.unit_resource = unit_resource
- #unit.hp = hp
- #unit.base_speed = speed
- #unit.additional_data = {"cost": cost}
Client.spawn_unit(unit, Client.current_stage.get_spawn(), Client.current_stage.get_overwrite_target())