diff --git a/godot/maps/default_map.tres b/godot/maps/default_map.tres index 297c123..9efaa0f 100644 --- a/godot/maps/default_map.tres +++ b/godot/maps/default_map.tres @@ -1,7 +1,10 @@ [gd_resource type="MapResource" format=3 uid="uid://c7n1tacc7a73t"] [ext_resource type="PackedScene" uid="uid://7iooamjot1tg" path="res://maps/default_map/map0.tscn" id="1_k5804"] +[ext_resource type="TeamResource" uid="uid://p2fqqnaejjn7" path="res://maps/teams/blue_team.tres" id="2_kkbjr"] +[ext_resource type="TeamResource" uid="uid://db4b3sjsftg15" path="res://maps/teams/red_ream.tres" id="3_o48fm"] [resource] name = "Default Map" scene = ExtResource("1_k5804") +teams = Array[TeamResource]([ExtResource("2_kkbjr"), ExtResource("3_o48fm")]) diff --git a/godot/maps/teams/blue_team.tres b/godot/maps/teams/blue_team.tres new file mode 100644 index 0000000..159b923 --- /dev/null +++ b/godot/maps/teams/blue_team.tres @@ -0,0 +1,5 @@ +[gd_resource type="TeamResource" format=3 uid="uid://p2fqqnaejjn7"] + +[resource] +name = "Blue Team" +color = Color(0, 0, 1, 1) diff --git a/godot/maps/teams/red_ream.tres b/godot/maps/teams/red_ream.tres new file mode 100644 index 0000000..b378098 --- /dev/null +++ b/godot/maps/teams/red_ream.tres @@ -0,0 +1,5 @@ +[gd_resource type="TeamResource" format=3 uid="uid://db4b3sjsftg15"] + +[resource] +name = "Red Team" +color = Color(1, 0, 0, 1) diff --git a/godot/scenes/player/local_player.tscn b/godot/scenes/player/local_player.tscn index 23879bd..5708b29 100644 --- a/godot/scenes/player/local_player.tscn +++ b/godot/scenes/player/local_player.tscn @@ -35,7 +35,7 @@ transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.09660053, -0.1177212, transform = Transform3D(-0.5, 0, -4.371139e-08, 0, 0.5, 0, 4.371139e-08, 0, -0.5, 0.15878421, 0, 0.19227558) [node name="collision_shape_3d2" type="CollisionShape3D" parent="." unique_id=442150782] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0310049, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("CapsuleShape3D_oh8vq") [node name="splorch" parent="." unique_id=986677517 instance=ExtResource("2_ywmwa")] diff --git a/godot/scenes/player/remote_player.tscn b/godot/scenes/player/remote_player.tscn index a8d385d..49ad68c 100644 --- a/godot/scenes/player/remote_player.tscn +++ b/godot/scenes/player/remote_player.tscn @@ -20,7 +20,7 @@ collision_mask = 4 transform = Transform3D(-0.5, 0, -4.371139e-08, 0, 0.5, 0, 4.371139e-08, 0, -0.5, 0, 0, 0) [node name="collision_shape_3d" type="CollisionShape3D" parent="." unique_id=1110995513] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0310049, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("CapsuleShape3D_1cgct") [node name="gpu_particles_3d" parent="." unique_id=986677517 instance=ExtResource("2_orxjf")] diff --git a/godot/scenes/ui/player_listing.tscn b/godot/scenes/ui/player_listing.tscn index 725b78b..5ad1a98 100644 --- a/godot/scenes/ui/player_listing.tscn +++ b/godot/scenes/ui/player_listing.tscn @@ -6,13 +6,17 @@ ping_label = NodePath("ping") ready_label = NodePath("ready") offset_right = 319.0 offset_bottom = 23.0 -columns = 3 +columns = 4 + +[node name="option_button" type="OptionButton" parent="." unique_id=199328927] +layout_mode = 2 [node name="name" type="Label" parent="." unique_id=635700663] -custom_minimum_size = Vector2(200, 0) -custom_maximum_size = Vector2(200, -1) +custom_minimum_size = Vector2(400, 0) +custom_maximum_size = Vector2(400, -1) layout_mode = 2 text = "Name" +clip_text = true [node name="ready" type="Label" parent="." unique_id=1064828735] custom_minimum_size = Vector2(100, 0) diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index a1a1f00..c23efaf 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -16,11 +16,18 @@ use crate::{ util::NetVector3, }, player::{DamageSource, IPlayer, LocalPlayer, NetTransform, RemotePlayer}, + team_resource::TeamResource, weapon::WeaponType, }; pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal"; +pub struct Team { + name: String, + color: String, + id: u8, +} + #[derive(GodotClass)] #[class(base=Node, init)] pub struct GameManager { @@ -205,6 +212,14 @@ impl Game { } } + pub fn get_teams(&self) -> Array> { + if let Some(map) = &self.selected_map { + map.bind().teams.clone() + } else { + Array::new() + } + } + pub fn start_game(&mut self) { self.game_started = true; if let Some(map) = &self.selected_map { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index cdef4b2..0e01a22 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -9,6 +9,7 @@ pub mod net; pub mod player; pub mod player_hand_remover; pub mod soldier_mesh; +pub mod team_resource; pub mod ui; pub mod weapon; diff --git a/rust/src/map_resource.rs b/rust/src/map_resource.rs index 8f15f5c..42e7502 100644 --- a/rust/src/map_resource.rs +++ b/rust/src/map_resource.rs @@ -1,5 +1,7 @@ use godot::prelude::*; +use crate::team_resource::TeamResource; + #[derive(GodotClass)] #[class(base=Resource, init, tool)] pub struct MapResource { @@ -7,17 +9,11 @@ pub struct MapResource { pub name: GString, #[export] pub scene: Option>, + #[export] + pub teams: Array>, base: Base, } #[godot_api] -impl IResource for MapResource { - fn to_string(&self) -> GString { - "Hello there".to_gstring() - } - - fn setup_local_to_scene(&mut self) {} - - fn reset_state(&mut self) {} -} +impl IResource for MapResource {} diff --git a/rust/src/team_resource.rs b/rust/src/team_resource.rs new file mode 100644 index 0000000..06902f0 --- /dev/null +++ b/rust/src/team_resource.rs @@ -0,0 +1,15 @@ +use godot::{meta::Element, prelude::*}; + +#[derive(GodotClass)] +#[class(base=Resource, init, tool)] +pub struct TeamResource { + #[export] + pub name: GString, + #[export] + pub color: Color, + + base: Base, +} + +#[godot_api] +impl IResource for TeamResource {} diff --git a/rust/src/ui/lobby.rs b/rust/src/ui/lobby.rs index 179d7cc..ef0e3c1 100644 --- a/rust/src/ui/lobby.rs +++ b/rust/src/ui/lobby.rs @@ -138,12 +138,13 @@ impl LobbyPanel { for child in list.get_children().iter_shared() { list.remove_child(&child); } - if let Some(game) = &GameManager::singleton().bind().game { + if let Some(game) = &Game::singleton() { if let Some(prefab) = &self.player_listing_prefab { for player in &game.bind().players { if let Some(node) = prefab.instantiate() { let mut listing = node.cast::(); listing.bind_mut().player_id = Some(player.id); + listing.bind_mut().update_teams(game.bind().get_teams()); listing.bind_mut().update(); list.add_child(&listing); } @@ -152,7 +153,11 @@ impl LobbyPanel { } } else { for child in list.get_children().iter_shared() { - child.cast::().bind_mut().update(); + let mut listing = child.cast::(); + if let Some(game) = Game::singleton() { + listing.bind_mut().update_teams(game.bind().get_teams()); + } + listing.bind_mut().update(); } } } @@ -192,12 +197,14 @@ impl LobbyPanel { PeerKind::Client(..) => { if let Some(map_selection) = &mut self.map_selection { map_selection.select(idx as i32); + self.run_deferred(|s| s.update_players(false)); } } PeerKind::Server(peer, _) => { if let Some(game) = &mut Game::singleton() { game.bind_mut().change_map_selection(idx, false); } + self.run_deferred(|s| s.update_players(false)); peer.broadcast_reliable(Package::SelectMap(idx)); } } diff --git a/rust/src/ui/player_listing.rs b/rust/src/ui/player_listing.rs index 398ef4d..6235a5c 100644 --- a/rust/src/ui/player_listing.rs +++ b/rust/src/ui/player_listing.rs @@ -1,9 +1,9 @@ use godot::{ - classes::{GridContainer, Label}, + classes::{GridContainer, Label, OptionButton}, prelude::*, }; -use crate::game_manager::Game; +use crate::{game_manager::Game, team_resource::TeamResource}; #[derive(GodotClass)] #[class(base=GridContainer, init)] @@ -14,6 +14,8 @@ pub struct PlayerListing { pub ping_label: Option>, #[export] pub ready_label: Option>, + #[export] + pub team_dropdown: Option>, pub player_id: Option, @@ -43,4 +45,13 @@ impl PlayerListing { } } } + + pub fn update_teams(&mut self, teams: Array>) { + if let Some(dropdown) = &mut self.team_dropdown { + dropdown.clear(); + for team in teams.iter_shared() { + dropdown.add_item(&team.bind().name); + } + } + } }