Self-highlight player listing

This commit is contained in:
Sofia 2026-08-03 17:49:57 +03:00
parent 604b97925b
commit 00776a4c52
2 changed files with 22 additions and 5 deletions

View File

@ -19,6 +19,7 @@ ping_high = ExtResource("3_kx1on")
ping_high_color = Color(0.99999994, 0.22953579, 0.17418489, 1)
ping_icon = NodePath("ping_icon")
stats_button = NodePath("stats_button")
self_color = Color(1, 1, 0.41000003, 1)
size_flags_horizontal = 3
theme = ExtResource("4_kx1on")

View File

@ -35,6 +35,9 @@ pub struct PlayerListing {
#[export]
stats_button: Option<Gd<Button>>,
#[export]
self_color: Color,
pub player_id: Option<u16>,
#[export]
@ -86,25 +89,38 @@ impl PlayerListing {
pub fn update(&mut self) {
if let Some(player_id) = self.player_id {
if let Some(game) = Game::singleton() {
let is_self = player_id == game.bind().self_id.unwrap_or(0);
if let Some(player) = game.bind().find_player(player_id) {
if let Some(name_label) = &mut self.name_label {
name_label.set_text(&player.data.name);
if is_self {
name_label.set_modulate(self.self_color);
}
}
if let Some(kills_label) = &mut self.kills_label {
kills_label.set_text(&player.stats.kills.to_string());
if is_self {
kills_label.set_modulate(self.self_color);
}
}
if let Some(deaths_label) = &mut self.deaths_label {
deaths_label.set_text(&player.stats.deaths.to_string());
if is_self {
deaths_label.set_modulate(self.self_color);
}
}
let (icon, color) = match player.data.ping {
..100 => (self.ping_low.clone(), self.ping_low_color),
100..200 => (self.ping_medium.clone(), self.ping_medium_color),
200.. => (self.ping_high.clone(), self.ping_high_color),
};
if let Some(ping_label) = &mut self.ping_label {
ping_label.set_text(&player.data.ping.to_string());
ping_label.set_modulate(color);
}
if let Some(ping_icon) = &mut self.ping_icon {
let (icon, color) = match player.data.ping {
..100 => (self.ping_low.clone(), self.ping_low_color),
100..200 => (self.ping_medium.clone(), self.ping_medium_color),
200.. => (self.ping_high.clone(), self.ping_high_color),
};
if let Some(icon) = icon {
ping_icon.set_texture(&icon);
}