From d21bf8862e0e07c915063bbe85806cd2e6859ada Mon Sep 17 00:00:00 2001 From: Sofia Date: Wed, 22 Jul 2026 22:28:09 +0300 Subject: [PATCH] Update player listings correctly, remove unused print --- godot/scenes/ui/player_listing.tscn | 6 +++- rust/src/ui/game_finished_screen.rs | 11 +++++-- rust/src/ui/lobby_player_listing.rs | 2 -- rust/src/ui/player_listing.rs | 45 ++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/godot/scenes/ui/player_listing.tscn b/godot/scenes/ui/player_listing.tscn index bd5ff61..5d7a5d9 100644 --- a/godot/scenes/ui/player_listing.tscn +++ b/godot/scenes/ui/player_listing.tscn @@ -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) diff --git a/rust/src/ui/game_finished_screen.rs b/rust/src/ui/game_finished_screen.rs index c942985..ec35e60 100644 --- a/rust/src/ui/game_finished_screen.rs +++ b/rust/src/ui/game_finished_screen.rs @@ -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::>(); for player in players { - let listing = listing_scene.instantiate_as::(); + let mut listing = listing_scene.instantiate_as::(); + listing.bind_mut().player_id = Some(player.id()); vbox.add_child(&listing); } } diff --git a/rust/src/ui/lobby_player_listing.rs b/rust/src/ui/lobby_player_listing.rs index b07769d..3eda1b1 100644 --- a/rust/src/ui/lobby_player_listing.rs +++ b/rust/src/ui/lobby_player_listing.rs @@ -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); } } diff --git a/rust/src/ui/player_listing.rs b/rust/src/ui/player_listing.rs index e146719..0d0dbe3 100644 --- a/rust/src/ui/player_listing.rs +++ b/rust/src/ui/player_listing.rs @@ -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>, + #[export] + kills_label: Option>, + #[export] + deaths_label: Option>, + #[export] + ping_label: Option>, + + pub player_id: Option, + base: Base, } + +#[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)); + } + } + } +}