Update player listings correctly, remove unused print

This commit is contained in:
Sofia 2026-07-22 22:28:09 +03:00
parent 0aae697b96
commit 8c44050846
4 changed files with 58 additions and 6 deletions

View File

@ -1,6 +1,10 @@
[gd_scene format=3 uid="uid://2sfy0vq0fqt3"]
[node name="player_listing" type="PlayerListing" unique_id=965142972]
[node name="player_listing" type="PlayerListing" unique_id=965142972 node_paths=PackedStringArray("name_label", "kills_label", "deaths_label", "ping_label")]
name_label = NodePath("name")
kills_label = NodePath("kills")
deaths_label = NodePath("deaths")
ping_label = NodePath("ping")
[node name="name" type="Label" parent="." unique_id=1361759955]
custom_minimum_size = Vector2(200, 0)

View File

@ -1,5 +1,9 @@
use godot::{
classes::{Button, HBoxContainer, IPanel, Label, Panel, VBoxContainer},
classes::{
Button, HBoxContainer, IPanel, Label, Panel, VBoxContainer, box_container::AlignmentMode,
control::LayoutDirection,
},
global::{HorizontalAlignment, VerticalAlignment},
prelude::*,
};
@ -44,10 +48,12 @@ impl GameFinishedScreen {
if let Some(game) = Game::singleton() {
for (id, team) in game.bind().get_teams().iter_shared().enumerate() {
let mut vbox = VBoxContainer::new_alloc();
vbox.set_alignment(AlignmentMode::CENTER);
let mut team_label = Label::new_alloc();
team_label.set_modulate(team.bind().color);
team_label.set_text(&team.bind().name);
team_label.set_horizontal_alignment(HorizontalAlignment::CENTER);
vbox.add_child(&team_label);
if let Some(listing_scene) = &self.player_listing_scene {
@ -58,7 +64,8 @@ impl GameFinishedScreen {
.filter(|p| p.data.team == id as u8)
.collect::<Vec<_>>();
for player in players {
let listing = listing_scene.instantiate_as::<PlayerListing>();
let mut listing = listing_scene.instantiate_as::<PlayerListing>();
listing.bind_mut().player_id = Some(player.id());
vbox.add_child(&listing);
}
}

View File

@ -130,7 +130,6 @@ impl LobbyPlayerListing {
&& let Some(player_label) = &mut self.name_label
&& let Some(team) = game.bind().get_team(player.data.team)
{
godot_print!("Setting color");
player_label.add_theme_color_override("font_color", team.bind().color);
}
}
@ -146,7 +145,6 @@ impl LobbyPlayerListing {
&& let Some(player_label) = &mut self.name_label
&& let Some(team) = game.bind().get_team(player.data.team)
{
godot_print!("Setting color");
player_label.add_theme_color_override("font_color", team.bind().color);
}
}

View File

@ -1,7 +1,50 @@
use godot::{classes::HBoxContainer, prelude::*};
use godot::{
classes::{HBoxContainer, IHBoxContainer, Label},
prelude::*,
};
use crate::game_manager::Game;
#[derive(GodotClass)]
#[class(base=HBoxContainer, init)]
pub struct PlayerListing {
#[export]
name_label: Option<Gd<Label>>,
#[export]
kills_label: Option<Gd<Label>>,
#[export]
deaths_label: Option<Gd<Label>>,
#[export]
ping_label: Option<Gd<Label>>,
pub player_id: Option<u16>,
base: Base<HBoxContainer>,
}
#[godot_api]
impl IHBoxContainer for PlayerListing {
fn ready(&mut self) {
self.update();
if let Some(game) = Game::singleton() {
game.signals()
.on_players_updated()
.connect_other(self, |s| s.update());
}
}
}
impl PlayerListing {
pub fn update(&mut self) {
if let Some(game) = Game::singleton()
&& let Some(player) = game.bind().find_player(self.player_id.unwrap_or(0))
{
if let Some(name_label) = &mut self.name_label {
name_label.set_text(&player.data.name);
}
if let Some(ping_label) = &mut self.ping_label {
ping_label.set_text(&format!("{}ms", player.data.ping));
}
}
}
}