Add simple menu player to lobby
This commit is contained in:
parent
9faab53ca5
commit
35c5209257
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://ccd0wj2usx5os" path="res://scenes/ui/lobby_player_listing.tscn" id="1_o1atq"]
|
[ext_resource type="PackedScene" uid="uid://ccd0wj2usx5os" path="res://scenes/ui/lobby_player_listing.tscn" id="1_o1atq"]
|
||||||
[ext_resource type="PackedScene" uid="uid://ffh5txda3j1" path="res://scenes/ui/chat_box.tscn" id="2_5gu6x"]
|
[ext_resource type="PackedScene" uid="uid://ffh5txda3j1" path="res://scenes/ui/chat_box.tscn" id="2_5gu6x"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bbmc2gmy7g8ag" path="res://scenes/player/menu_player.tscn" id="3_q60fs"]
|
||||||
|
|
||||||
[sub_resource type="LabelSettings" id="LabelSettings_1cgct"]
|
[sub_resource type="LabelSettings" id="LabelSettings_1cgct"]
|
||||||
font_size = 32
|
font_size = 32
|
||||||
@ -9,7 +10,10 @@ font_size = 32
|
|||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbm04"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbm04"]
|
||||||
bg_color = Color(0.30692267, 0.3069227, 0.30692264, 1)
|
bg_color = Color(0.30692267, 0.3069227, 0.30692264, 1)
|
||||||
|
|
||||||
[node name="lobby" type="LobbyPanel" unique_id=915192272 node_paths=PackedStringArray("players_list", "name_field", "ready_button", "map_selection", "options_panel", "options_grid")]
|
[node name="lobby_world" type="LobbyWorld" unique_id=129662054]
|
||||||
|
menu_player_scene = ExtResource("3_q60fs")
|
||||||
|
|
||||||
|
[node name="lobby" type="LobbyPanel" parent="." unique_id=915192272 node_paths=PackedStringArray("players_list", "name_field", "ready_button", "map_selection", "options_panel", "options_grid")]
|
||||||
players_list = NodePath("v_box_container/players_list")
|
players_list = NodePath("v_box_container/players_list")
|
||||||
name_field = NodePath("v_box_container/h_box_container/text_edit")
|
name_field = NodePath("v_box_container/h_box_container/text_edit")
|
||||||
player_listing_prefab = ExtResource("1_o1atq")
|
player_listing_prefab = ExtResource("1_o1atq")
|
||||||
@ -23,7 +27,7 @@ anchor_bottom = 1.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="label" type="Label" parent="." unique_id=1445541926]
|
[node name="label" type="Label" parent="lobby" unique_id=1445541926]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 10
|
anchors_preset = 10
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
@ -34,37 +38,37 @@ text = "Lobby"
|
|||||||
label_settings = SubResource("LabelSettings_1cgct")
|
label_settings = SubResource("LabelSettings_1cgct")
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
|
|
||||||
[node name="v_box_container" type="VBoxContainer" parent="." unique_id=336946640]
|
[node name="v_box_container" type="VBoxContainer" parent="lobby" unique_id=336946640]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
offset_left = 85.0
|
offset_left = 85.0
|
||||||
offset_top = 111.0
|
offset_top = 111.0
|
||||||
offset_right = 290.0
|
offset_right = 290.0
|
||||||
offset_bottom = 165.0
|
offset_bottom = 165.0
|
||||||
|
|
||||||
[node name="h_box_container" type="HBoxContainer" parent="v_box_container" unique_id=1789302658]
|
[node name="h_box_container" type="HBoxContainer" parent="lobby/v_box_container" unique_id=1789302658]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
offset_transform_position = Vector2(100, 0)
|
offset_transform_position = Vector2(100, 0)
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="label" type="Label" parent="v_box_container/h_box_container" unique_id=626633696]
|
[node name="label" type="Label" parent="lobby/v_box_container/h_box_container" unique_id=626633696]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Name:"
|
text = "Name:"
|
||||||
|
|
||||||
[node name="text_edit" type="LineEdit" parent="v_box_container/h_box_container" unique_id=284528736]
|
[node name="text_edit" type="LineEdit" parent="lobby/v_box_container/h_box_container" unique_id=284528736]
|
||||||
custom_minimum_size = Vector2(150, 0)
|
custom_minimum_size = Vector2(150, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
max_length = 20
|
max_length = 20
|
||||||
|
|
||||||
[node name="players_label" type="Label" parent="v_box_container" unique_id=1537542117]
|
[node name="players_label" type="Label" parent="lobby/v_box_container" unique_id=1537542117]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Players:"
|
text = "Players:"
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="players_list" type="VBoxContainer" parent="v_box_container" unique_id=1834737379]
|
[node name="players_list" type="VBoxContainer" parent="lobby/v_box_container" unique_id=1834737379]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="v_box_container2" type="VBoxContainer" parent="." unique_id=653902328]
|
[node name="v_box_container2" type="VBoxContainer" parent="lobby" unique_id=653902328]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 1
|
anchors_preset = 1
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
@ -75,11 +79,11 @@ offset_right = -727.0
|
|||||||
offset_bottom = 169.0
|
offset_bottom = 169.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
|
|
||||||
[node name="option_button" type="OptionButton" parent="v_box_container2" unique_id=426342653]
|
[node name="option_button" type="OptionButton" parent="lobby/v_box_container2" unique_id=426342653]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="options_panel" type="Panel" parent="." unique_id=1194589850]
|
[node name="options_panel" type="Panel" parent="lobby" unique_id=1194589850]
|
||||||
visible = false
|
visible = false
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = 8
|
||||||
@ -95,7 +99,7 @@ grow_horizontal = 2
|
|||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
theme_override_styles/panel = SubResource("StyleBoxFlat_jbm04")
|
theme_override_styles/panel = SubResource("StyleBoxFlat_jbm04")
|
||||||
|
|
||||||
[node name="options_close" type="Button" parent="options_panel" unique_id=2115857774]
|
[node name="options_close" type="Button" parent="lobby/options_panel" unique_id=2115857774]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 1
|
anchors_preset = 1
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
@ -105,25 +109,25 @@ offset_bottom = 31.0
|
|||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
text = "X"
|
text = "X"
|
||||||
|
|
||||||
[node name="h_box_container" type="VBoxContainer" parent="options_panel" unique_id=1163233032]
|
[node name="h_box_container" type="VBoxContainer" parent="lobby/options_panel" unique_id=1163233032]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
offset_left = 0.5
|
offset_left = 0.5
|
||||||
offset_top = 3.5
|
offset_top = 3.5
|
||||||
offset_right = 115.5
|
offset_right = 115.5
|
||||||
offset_bottom = 43.5
|
offset_bottom = 43.5
|
||||||
|
|
||||||
[node name="label" type="Label" parent="options_panel/h_box_container" unique_id=1002581329]
|
[node name="label" type="Label" parent="lobby/options_panel/h_box_container" unique_id=1002581329]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Game Options"
|
text = "Game Options"
|
||||||
|
|
||||||
[node name="v_box_container" type="HBoxContainer" parent="options_panel/h_box_container" unique_id=1445409921]
|
[node name="v_box_container" type="HBoxContainer" parent="lobby/options_panel/h_box_container" unique_id=1445409921]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="options_grid" type="GridContainer" parent="options_panel/h_box_container" unique_id=504671462]
|
[node name="options_grid" type="GridContainer" parent="lobby/options_panel/h_box_container" unique_id=504671462]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
columns = 2
|
columns = 2
|
||||||
|
|
||||||
[node name="chat_box" parent="." unique_id=1125601400 instance=ExtResource("2_5gu6x")]
|
[node name="chat_box" parent="lobby" unique_id=1125601400 instance=ExtResource("2_5gu6x")]
|
||||||
custom_minimum_size = Vector2(400, 300)
|
custom_minimum_size = Vector2(400, 300)
|
||||||
custom_maximum_size = Vector2(400, 300)
|
custom_maximum_size = Vector2(400, 300)
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
@ -139,34 +143,38 @@ offset_bottom = -52.0
|
|||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
|
||||||
[node name="v_box_container3" type="VBoxContainer" parent="." unique_id=1320505732]
|
[node name="v_box_container3" type="VBoxContainer" parent="lobby" unique_id=1320505732]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
offset_left = 87.0
|
offset_left = 87.0
|
||||||
offset_top = 538.0
|
offset_top = 538.0
|
||||||
offset_right = 198.0
|
offset_right = 198.0
|
||||||
offset_bottom = 604.0
|
offset_bottom = 604.0
|
||||||
|
|
||||||
[node name="ready_button" type="Button" parent="v_box_container3" unique_id=311553419]
|
[node name="ready_button" type="Button" parent="lobby/v_box_container3" unique_id=311553419]
|
||||||
custom_minimum_size = Vector2(100, 0)
|
custom_minimum_size = Vector2(100, 0)
|
||||||
custom_maximum_size = Vector2(100, -1)
|
custom_maximum_size = Vector2(100, -1)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Not Ready"
|
text = "Not Ready"
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="h_box_container" type="HBoxContainer" parent="v_box_container3" unique_id=1165099293]
|
[node name="h_box_container" type="HBoxContainer" parent="lobby/v_box_container3" unique_id=1165099293]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="exit_button" type="Button" parent="v_box_container3/h_box_container" unique_id=267703633]
|
[node name="exit_button" type="Button" parent="lobby/v_box_container3/h_box_container" unique_id=267703633]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Exit"
|
text = "Exit"
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="options_button" type="Button" parent="v_box_container3/h_box_container" unique_id=2109111628]
|
[node name="options_button" type="Button" parent="lobby/v_box_container3/h_box_container" unique_id=2109111628]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Options"
|
text = "Options"
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[connection signal="pressed" from="options_panel/options_close" to="." method="close_options"]
|
[node name="camera_3d" type="Camera3D" parent="." unique_id=131019329]
|
||||||
[connection signal="pressed" from="v_box_container3/h_box_container/exit_button" to="." method="exit"]
|
transform = Transform3D(0.69531304, -0.068955034, 0.7153915, 3.1173069e-09, 0.99538684, 0.09594317, -0.718707, -0.06671053, 0.6921054, 3.165125, 2.0609732, 2.7751796)
|
||||||
[connection signal="pressed" from="v_box_container3/h_box_container/options_button" to="." method="open_options"]
|
current = true
|
||||||
|
|
||||||
|
[connection signal="pressed" from="lobby/options_panel/options_close" to="lobby" method="close_options"]
|
||||||
|
[connection signal="pressed" from="lobby/v_box_container3/h_box_container/exit_button" to="lobby" method="exit"]
|
||||||
|
[connection signal="pressed" from="lobby/v_box_container3/h_box_container/options_button" to="lobby" method="open_options"]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[gd_scene format=4 uid="uid://lahirbqfppvw"]
|
[gd_scene format=4 uid="uid://lahirbqfppvw"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bbmc2gmy7g8ag" path="res://scenes/misc/menu_player.tscn" id="1_o5qli"]
|
[ext_resource type="PackedScene" uid="uid://bbmc2gmy7g8ag" path="res://scenes/player/menu_player.tscn" id="1_o5qli"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dsxu0y8pjbw3k" path="res://scenes/ui/credits.tscn" id="1_sugp2"]
|
[ext_resource type="PackedScene" uid="uid://dsxu0y8pjbw3k" path="res://scenes/ui/credits.tscn" id="1_sugp2"]
|
||||||
[ext_resource type="PackedScene" uid="uid://n3u0jr4wiib1" path="res://scenes/ui/settings.tscn" id="2_0wfyh"]
|
[ext_resource type="PackedScene" uid="uid://n3u0jr4wiib1" path="res://scenes/ui/settings.tscn" id="2_0wfyh"]
|
||||||
[ext_resource type="Script" uid="uid://cwu5cf7a0awcd" path="res://addons/func_godot/src/map/func_godot_map.gd" id="4_yc10j"]
|
[ext_resource type="Script" uid="uid://cwu5cf7a0awcd" path="res://addons/func_godot/src/map/func_godot_map.gd" id="4_yc10j"]
|
||||||
|
|||||||
@ -9,6 +9,7 @@ pub mod game_manager;
|
|||||||
pub mod game_settings;
|
pub mod game_settings;
|
||||||
pub mod goal;
|
pub mod goal;
|
||||||
pub mod killbox;
|
pub mod killbox;
|
||||||
|
pub mod lobby_world;
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod map_resource;
|
pub mod map_resource;
|
||||||
pub mod net;
|
pub mod net;
|
||||||
|
|||||||
67
rust/src/lobby_world.rs
Normal file
67
rust/src/lobby_world.rs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
use std::{collections::HashMap, f32::consts::PI};
|
||||||
|
|
||||||
|
use godot::{classes::RandomNumberGenerator, prelude::*};
|
||||||
|
|
||||||
|
use crate::{game_manager::Game, ui::menu_player::MenuPlayer};
|
||||||
|
|
||||||
|
#[derive(GodotClass)]
|
||||||
|
#[class(base=Node3D, init)]
|
||||||
|
pub struct LobbyWorld {
|
||||||
|
#[export]
|
||||||
|
menu_player_scene: Option<Gd<PackedScene>>,
|
||||||
|
|
||||||
|
rng: Gd<RandomNumberGenerator>,
|
||||||
|
|
||||||
|
menu_players: HashMap<u16, Gd<MenuPlayer>>,
|
||||||
|
|
||||||
|
base: Base<Node3D>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[godot_api]
|
||||||
|
impl INode3D for LobbyWorld {
|
||||||
|
fn ready(&mut self) {
|
||||||
|
if let Some(game) = Game::singleton()
|
||||||
|
&& let Some(scene) = self.menu_player_scene.clone()
|
||||||
|
{
|
||||||
|
for player in &game.bind().players {
|
||||||
|
self.spawn_player(player.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
game.signals()
|
||||||
|
.on_new_player()
|
||||||
|
.connect_other(self, Self::on_new_player);
|
||||||
|
game.signals()
|
||||||
|
.on_player_disconnected()
|
||||||
|
.connect_other(self, Self::on_player_disconnected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LobbyWorld {
|
||||||
|
fn on_new_player(&mut self, player_id: u16) {
|
||||||
|
self.spawn_player(player_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_player_disconnected(&mut self, player_id: u16) {
|
||||||
|
if let Some(mut player) = self.menu_players.remove(&player_id) {
|
||||||
|
player.queue_free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_player(&mut self, player_id: u16) {
|
||||||
|
self.run_deferred(move |s| {
|
||||||
|
if let Some(scene) = s.menu_player_scene.clone() {
|
||||||
|
let x = s.rng.randf_range(-2., 2.);
|
||||||
|
let z = s.rng.randf_range(-2., 2.);
|
||||||
|
let rotation = s.rng.randf_range(PI / 4., PI / 2.);
|
||||||
|
|
||||||
|
let mut menu_player = scene.instantiate_as::<MenuPlayer>();
|
||||||
|
s.menu_players.insert(player_id, menu_player.clone());
|
||||||
|
s.base_mut().add_child(&menu_player);
|
||||||
|
|
||||||
|
menu_player.set_position(Vector3::new(x, 0., z));
|
||||||
|
menu_player.set_rotation(Vector3::UP * rotation);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user