Start adding teams, move player capsule down a bit

This commit is contained in:
Sofia 2026-07-22 00:00:21 +03:00
parent f750f2843c
commit 1fcd74d220
12 changed files with 80 additions and 18 deletions

View File

@ -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")])

View File

@ -0,0 +1,5 @@
[gd_resource type="TeamResource" format=3 uid="uid://p2fqqnaejjn7"]
[resource]
name = "Blue Team"
color = Color(0, 0, 1, 1)

View File

@ -0,0 +1,5 @@
[gd_resource type="TeamResource" format=3 uid="uid://db4b3sjsftg15"]
[resource]
name = "Red Team"
color = Color(1, 0, 0, 1)

View File

@ -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")]

View File

@ -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")]

View File

@ -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)

View File

@ -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<Gd<TeamResource>> {
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 {

View File

@ -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;

View File

@ -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<Gd<PackedScene>>,
#[export]
pub teams: Array<Gd<TeamResource>>,
base: Base<Resource>,
}
#[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 {}

15
rust/src/team_resource.rs Normal file
View 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 {}

View File

@ -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::<PlayerListing>();
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::<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(..) => {
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));
}
}

View File

@ -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<Gd<Label>>,
#[export]
pub ready_label: Option<Gd<Label>>,
#[export]
pub team_dropdown: Option<Gd<OptionButton>>,
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);
}
}
}
}