Start adding teams, move player capsule down a bit
This commit is contained in:
parent
f750f2843c
commit
1fcd74d220
@ -1,7 +1,10 @@
|
|||||||
[gd_resource type="MapResource" format=3 uid="uid://c7n1tacc7a73t"]
|
[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="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]
|
[resource]
|
||||||
name = "Default Map"
|
name = "Default Map"
|
||||||
scene = ExtResource("1_k5804")
|
scene = ExtResource("1_k5804")
|
||||||
|
teams = Array[TeamResource]([ExtResource("2_kkbjr"), ExtResource("3_o48fm")])
|
||||||
|
|||||||
5
godot/maps/teams/blue_team.tres
Normal file
5
godot/maps/teams/blue_team.tres
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[gd_resource type="TeamResource" format=3 uid="uid://p2fqqnaejjn7"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
name = "Blue Team"
|
||||||
|
color = Color(0, 0, 1, 1)
|
||||||
5
godot/maps/teams/red_ream.tres
Normal file
5
godot/maps/teams/red_ream.tres
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[gd_resource type="TeamResource" format=3 uid="uid://db4b3sjsftg15"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
name = "Red Team"
|
||||||
|
color = Color(1, 0, 0, 1)
|
||||||
@ -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)
|
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]
|
[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")
|
shape = SubResource("CapsuleShape3D_oh8vq")
|
||||||
|
|
||||||
[node name="splorch" parent="." unique_id=986677517 instance=ExtResource("2_ywmwa")]
|
[node name="splorch" parent="." unique_id=986677517 instance=ExtResource("2_ywmwa")]
|
||||||
|
|||||||
@ -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)
|
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]
|
[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")
|
shape = SubResource("CapsuleShape3D_1cgct")
|
||||||
|
|
||||||
[node name="gpu_particles_3d" parent="." unique_id=986677517 instance=ExtResource("2_orxjf")]
|
[node name="gpu_particles_3d" parent="." unique_id=986677517 instance=ExtResource("2_orxjf")]
|
||||||
|
|||||||
@ -6,13 +6,17 @@ ping_label = NodePath("ping")
|
|||||||
ready_label = NodePath("ready")
|
ready_label = NodePath("ready")
|
||||||
offset_right = 319.0
|
offset_right = 319.0
|
||||||
offset_bottom = 23.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]
|
[node name="name" type="Label" parent="." unique_id=635700663]
|
||||||
custom_minimum_size = Vector2(200, 0)
|
custom_minimum_size = Vector2(400, 0)
|
||||||
custom_maximum_size = Vector2(200, -1)
|
custom_maximum_size = Vector2(400, -1)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Name"
|
text = "Name"
|
||||||
|
clip_text = true
|
||||||
|
|
||||||
[node name="ready" type="Label" parent="." unique_id=1064828735]
|
[node name="ready" type="Label" parent="." unique_id=1064828735]
|
||||||
custom_minimum_size = Vector2(100, 0)
|
custom_minimum_size = Vector2(100, 0)
|
||||||
|
|||||||
@ -16,11 +16,18 @@ use crate::{
|
|||||||
util::NetVector3,
|
util::NetVector3,
|
||||||
},
|
},
|
||||||
player::{DamageSource, IPlayer, LocalPlayer, NetTransform, RemotePlayer},
|
player::{DamageSource, IPlayer, LocalPlayer, NetTransform, RemotePlayer},
|
||||||
|
team_resource::TeamResource,
|
||||||
weapon::WeaponType,
|
weapon::WeaponType,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal";
|
pub const GAME_MANAGER_GLOBAL: &str = "GameManagerGlobal";
|
||||||
|
|
||||||
|
pub struct Team {
|
||||||
|
name: String,
|
||||||
|
color: String,
|
||||||
|
id: u8,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Node, init)]
|
#[class(base=Node, init)]
|
||||||
pub struct GameManager {
|
pub struct GameManager {
|
||||||
@ -205,6 +212,14 @@ impl Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_teams(&self) -> Array<Gd<TeamResource>> {
|
||||||
|
if let Some(map) = &self.selected_map {
|
||||||
|
map.bind().teams.clone()
|
||||||
|
} else {
|
||||||
|
Array::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn start_game(&mut self) {
|
pub fn start_game(&mut self) {
|
||||||
self.game_started = true;
|
self.game_started = true;
|
||||||
if let Some(map) = &self.selected_map {
|
if let Some(map) = &self.selected_map {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ pub mod net;
|
|||||||
pub mod player;
|
pub mod player;
|
||||||
pub mod player_hand_remover;
|
pub mod player_hand_remover;
|
||||||
pub mod soldier_mesh;
|
pub mod soldier_mesh;
|
||||||
|
pub mod team_resource;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod weapon;
|
pub mod weapon;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
use godot::prelude::*;
|
use godot::prelude::*;
|
||||||
|
|
||||||
|
use crate::team_resource::TeamResource;
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Resource, init, tool)]
|
#[class(base=Resource, init, tool)]
|
||||||
pub struct MapResource {
|
pub struct MapResource {
|
||||||
@ -7,17 +9,11 @@ pub struct MapResource {
|
|||||||
pub name: GString,
|
pub name: GString,
|
||||||
#[export]
|
#[export]
|
||||||
pub scene: Option<Gd<PackedScene>>,
|
pub scene: Option<Gd<PackedScene>>,
|
||||||
|
#[export]
|
||||||
|
pub teams: Array<Gd<TeamResource>>,
|
||||||
|
|
||||||
base: Base<Resource>,
|
base: Base<Resource>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[godot_api]
|
#[godot_api]
|
||||||
impl IResource for MapResource {
|
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) {}
|
|
||||||
}
|
|
||||||
|
|||||||
15
rust/src/team_resource.rs
Normal file
15
rust/src/team_resource.rs
Normal file
@ -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<Resource>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[godot_api]
|
||||||
|
impl IResource for TeamResource {}
|
||||||
@ -138,12 +138,13 @@ impl LobbyPanel {
|
|||||||
for child in list.get_children().iter_shared() {
|
for child in list.get_children().iter_shared() {
|
||||||
list.remove_child(&child);
|
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 {
|
if let Some(prefab) = &self.player_listing_prefab {
|
||||||
for player in &game.bind().players {
|
for player in &game.bind().players {
|
||||||
if let Some(node) = prefab.instantiate() {
|
if let Some(node) = prefab.instantiate() {
|
||||||
let mut listing = node.cast::<PlayerListing>();
|
let mut listing = node.cast::<PlayerListing>();
|
||||||
listing.bind_mut().player_id = Some(player.id);
|
listing.bind_mut().player_id = Some(player.id);
|
||||||
|
listing.bind_mut().update_teams(game.bind().get_teams());
|
||||||
listing.bind_mut().update();
|
listing.bind_mut().update();
|
||||||
list.add_child(&listing);
|
list.add_child(&listing);
|
||||||
}
|
}
|
||||||
@ -152,7 +153,11 @@ impl LobbyPanel {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for child in list.get_children().iter_shared() {
|
for child in list.get_children().iter_shared() {
|
||||||
child.cast::<PlayerListing>().bind_mut().update();
|
let mut listing = child.cast::<PlayerListing>();
|
||||||
|
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(..) => {
|
PeerKind::Client(..) => {
|
||||||
if let Some(map_selection) = &mut self.map_selection {
|
if let Some(map_selection) = &mut self.map_selection {
|
||||||
map_selection.select(idx as i32);
|
map_selection.select(idx as i32);
|
||||||
|
self.run_deferred(|s| s.update_players(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PeerKind::Server(peer, _) => {
|
PeerKind::Server(peer, _) => {
|
||||||
if let Some(game) = &mut Game::singleton() {
|
if let Some(game) = &mut Game::singleton() {
|
||||||
game.bind_mut().change_map_selection(idx, false);
|
game.bind_mut().change_map_selection(idx, false);
|
||||||
}
|
}
|
||||||
|
self.run_deferred(|s| s.update_players(false));
|
||||||
peer.broadcast_reliable(Package::SelectMap(idx));
|
peer.broadcast_reliable(Package::SelectMap(idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
use godot::{
|
use godot::{
|
||||||
classes::{GridContainer, Label},
|
classes::{GridContainer, Label, OptionButton},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::game_manager::Game;
|
use crate::{game_manager::Game, team_resource::TeamResource};
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=GridContainer, init)]
|
#[class(base=GridContainer, init)]
|
||||||
@ -14,6 +14,8 @@ pub struct PlayerListing {
|
|||||||
pub ping_label: Option<Gd<Label>>,
|
pub ping_label: Option<Gd<Label>>,
|
||||||
#[export]
|
#[export]
|
||||||
pub ready_label: Option<Gd<Label>>,
|
pub ready_label: Option<Gd<Label>>,
|
||||||
|
#[export]
|
||||||
|
pub team_dropdown: Option<Gd<OptionButton>>,
|
||||||
|
|
||||||
pub player_id: Option<u16>,
|
pub player_id: Option<u16>,
|
||||||
|
|
||||||
@ -43,4 +45,13 @@ impl PlayerListing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_teams(&mut self, teams: Array<Gd<TeamResource>>) {
|
||||||
|
if let Some(dropdown) = &mut self.team_dropdown {
|
||||||
|
dropdown.clear();
|
||||||
|
for team in teams.iter_shared() {
|
||||||
|
dropdown.add_item(&team.bind().name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user