50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
use godot::{
|
|
classes::{GridContainer, IGridContainer, Label, Panel, TextEdit, VBoxContainer},
|
|
prelude::*,
|
|
};
|
|
|
|
use crate::{
|
|
game_manager::{Game, Player},
|
|
net::network_manager::NetworkManager,
|
|
};
|
|
|
|
#[derive(GodotClass)]
|
|
#[class(base=GridContainer, init)]
|
|
pub struct PlayerListing {
|
|
#[export]
|
|
pub name_label: Option<Gd<Label>>,
|
|
#[export]
|
|
pub ping_label: Option<Gd<Label>>,
|
|
#[export]
|
|
pub ready_label: Option<Gd<Label>>,
|
|
|
|
pub player_id: Option<u16>,
|
|
|
|
base: Base<GridContainer>,
|
|
}
|
|
|
|
impl PlayerListing {
|
|
pub fn update(&mut self) {
|
|
if let Some(player_id) = &self.player_id
|
|
&& let Some(game) = Game::singleton()
|
|
&& let Some(player) = game.bind().find_player(*player_id)
|
|
{
|
|
if let Some(player_label) = &mut self.name_label {
|
|
player_label.set_text(&format!("{} ({})", player.name, player.connection_addr));
|
|
}
|
|
|
|
if let Some(ready_label) = &mut self.ready_label {
|
|
if player.ready {
|
|
ready_label.set_text("Ready");
|
|
} else {
|
|
ready_label.set_text("Not Ready");
|
|
}
|
|
}
|
|
|
|
if let Some(ping_label) = &mut self.ping_label {
|
|
ping_label.set_text(&format!("({}ms)", player.ping));
|
|
}
|
|
}
|
|
}
|
|
}
|