diff options
Diffstat (limited to 'UI/PlayerLobby')
-rw-r--r-- | UI/PlayerLobby/Lobby.tscn | 155 | ||||
-rw-r--r-- | UI/PlayerLobby/lobby.gd | 201 | ||||
-rw-r--r-- | UI/PlayerLobby/lobby_setting.gd | 42 | ||||
-rw-r--r-- | UI/PlayerLobby/lobby_setting.tscn | 21 | ||||
-rw-r--r-- | UI/PlayerLobby/lobby_theme.tres | 19 |
5 files changed, 438 insertions, 0 deletions
diff --git a/UI/PlayerLobby/Lobby.tscn b/UI/PlayerLobby/Lobby.tscn new file mode 100644 index 0000000..228d512 --- /dev/null +++ b/UI/PlayerLobby/Lobby.tscn @@ -0,0 +1,155 @@ +[gd_scene load_steps=11 format=3 uid="uid://r45j806p4a74"] + +[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="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"] +[ext_resource type="Texture2D" uid="uid://cfiu7ah67vdpg" path="res://Stages/Square/Assets/thumbnail.png" id="5_5ewsi"] +[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"] + +[node name="Lobby" 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_mm4gt") + +[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_0pdjl") +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="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 + +[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/separation = 32 + +[node name="Teams" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 + +[node name="PlayersListContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Teams" instance=ExtResource("3_2r7nj")] +unique_name_in_owner = true +layout_mode = 2 + +[node name="Maps" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +theme = ExtResource("2_syjfh") + +[node name="MapButton" type="Button" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Maps"] +layout_mode = 2 +mouse_default_cursor_shape = 2 +toggle_mode = true +text = "Wintermaul" +metadata/map_scene = ExtResource("3_3hc3h") +metadata/thumbnail = ExtResource("3_8r1n2") +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 +mouse_default_cursor_shape = 2 +toggle_mode = true +text = "Squares" +metadata/thumbnail = ExtResource("5_5ewsi") + +[node name="MapButton3" type="Button" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Maps"] +layout_mode = 2 +mouse_default_cursor_shape = 2 +toggle_mode = true +text = "Wintermaul 2" +metadata/map_scene = ExtResource("4_v1caa") +metadata/thumbnail = ExtResource("5_j23oc") + +[node name="MapButton4" type="Button" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer/Maps"] +visible = false +layout_mode = 2 +mouse_default_cursor_shape = 2 +toggle_mode = true +text = "Wintermaul Tiny Swords" +metadata/map_scene = ExtResource("5_hnsfx") + +[node name="Thumbnail" type="TextureRect" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(300, 260) +layout_mode = 2 +texture = ExtResource("3_8r1n2") +expand_mode = 1 +stretch_mode = 4 + +[node name="Settings" type="VBoxContainer" parent="MarginContainer/VBoxContainer/CenterContainer/HBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 0 +theme_override_constants/separation = 0 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 8 +theme = ExtResource("2_syjfh") + +[node name="StartButton" type="Button" parent="MarginContainer/VBoxContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +mouse_default_cursor_shape = 2 +text = "Start" + +[node name="CancelButton" type="Button" parent="MarginContainer/VBoxContainer/VBoxContainer"] +unique_name_in_owner = true +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/PlayerLobby/lobby_setting.tscn b/UI/PlayerLobby/lobby_setting.tscn new file mode 100644 index 0000000..62d1c66 --- /dev/null +++ b/UI/PlayerLobby/lobby_setting.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=2 format=3 uid="uid://fgqkxat8pwjk"] + +[ext_resource type="Script" path="res://UI/PlayerLobby/lobby_setting.gd" id="1_ntovh"] + +[node name="LobbySetting" type="HBoxContainer"] +size_flags_vertical = 2 +script = ExtResource("1_ntovh") + +[node name="Label" type="Label" parent="."] +layout_mode = 2 +text = "Setting" + +[node name="TextEdit" type="LineEdit" parent="."] +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/PlayerLobby/lobby_theme.tres b/UI/PlayerLobby/lobby_theme.tres new file mode 100644 index 0000000..0307ae1 --- /dev/null +++ b/UI/PlayerLobby/lobby_theme.tres @@ -0,0 +1,19 @@ +[gd_resource type="Theme" load_steps=3 format=3 uid="uid://bt84t61hrvoyn"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_vhn61"] +content_margin_left = 8.0 +content_margin_top = 4.0 +content_margin_right = 8.0 +content_margin_bottom = 4.0 +bg_color = Color(0, 0, 0, 1) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4s0gx"] +content_margin_left = 8.0 +content_margin_top = 4.0 +content_margin_right = 8.0 +content_margin_bottom = 4.0 +bg_color = Color(0, 0, 0, 1) + +[resource] +Button/styles/disabled = SubResource("StyleBoxFlat_vhn61") +Button/styles/normal = SubResource("StyleBoxFlat_4s0gx") |