Add team colors to lobby names
This commit is contained in:
parent
f3a5a18400
commit
034c50d6f5
Binary file not shown.
@ -37,6 +37,8 @@ offset_bottom = 200.0
|
|||||||
|
|
||||||
[node name="h_box_container" type="HBoxContainer" parent="v_box_container" unique_id=1789302658]
|
[node name="h_box_container" type="HBoxContainer" parent="v_box_container" unique_id=1789302658]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
offset_transform_enabled = true
|
||||||
|
offset_transform_position = Vector2(100, 0)
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="label" type="Label" parent="v_box_container/h_box_container" unique_id=626633696]
|
[node name="label" type="Label" parent="v_box_container/h_box_container" unique_id=626633696]
|
||||||
|
|||||||
@ -10,11 +10,14 @@ offset_bottom = 23.0
|
|||||||
columns = 4
|
columns = 4
|
||||||
|
|
||||||
[node name="option_button" type="OptionButton" parent="." unique_id=199328927]
|
[node name="option_button" type="OptionButton" parent="." unique_id=199328927]
|
||||||
|
custom_minimum_size = Vector2(150, 0)
|
||||||
|
custom_maximum_size = Vector2(150, -1)
|
||||||
|
clip_contents = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="name" type="Label" parent="." unique_id=635700663]
|
[node name="name" type="Label" parent="." unique_id=635700663]
|
||||||
custom_minimum_size = Vector2(400, 0)
|
custom_minimum_size = Vector2(350, 0)
|
||||||
custom_maximum_size = Vector2(400, -1)
|
custom_maximum_size = Vector2(350, -1)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Name"
|
text = "Name"
|
||||||
clip_text = true
|
clip_text = true
|
||||||
|
|||||||
@ -254,6 +254,10 @@ impl Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_team(&self, team: u8) -> Option<Gd<TeamResource>> {
|
||||||
|
self.get_teams().get(team as usize)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn try_set_player_team(&mut self, player_id: u16, team: u8, emit: bool) {
|
pub fn try_set_player_team(&mut self, player_id: u16, team: u8, emit: bool) {
|
||||||
if let Some(player) = self.find_player_mut(player_id) {
|
if let Some(player) = self.find_player_mut(player_id) {
|
||||||
player.data.team = team;
|
player.data.team = team;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use godot::{
|
use godot::{
|
||||||
classes::{GridContainer, IGridContainer, Label, OptionButton},
|
classes::{GridContainer, IGridContainer, Label, OptionButton, TextEdit},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,13 +47,7 @@ impl IGridContainer for PlayerListing {
|
|||||||
.signals()
|
.signals()
|
||||||
.item_selected()
|
.item_selected()
|
||||||
.connect_other(self, |s, selection| {
|
.connect_other(self, |s, selection| {
|
||||||
if let Some(mut game) = Game::singleton() {
|
s.on_team_selection_changed(selection as u8);
|
||||||
game.bind_mut().try_set_player_team(
|
|
||||||
s.player_id.unwrap_or(0),
|
|
||||||
selection as u8,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +76,10 @@ impl PlayerListing {
|
|||||||
"{} ({})",
|
"{} ({})",
|
||||||
player.data.name, player.connection_addr
|
player.data.name, player.connection_addr
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if let Some(team) = game.bind().get_team(player.data.team) {
|
||||||
|
player_label.add_theme_color_override("font_color", team.bind().color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ready_label) = &mut self.ready_label {
|
if let Some(ready_label) = &mut self.ready_label {
|
||||||
@ -113,9 +111,33 @@ impl PlayerListing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn on_team_selection_changed(&mut self, team: u8) {
|
||||||
|
if let Some(mut game) = Game::singleton() {
|
||||||
|
game.bind_mut()
|
||||||
|
.try_set_player_team(self.player_id.unwrap_or(0), team, false);
|
||||||
|
|
||||||
|
if let Some(player) = game.bind().find_player(self.player_id.unwrap_or(0))
|
||||||
|
&& 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn on_team_update(&mut self, team: u8) {
|
fn on_team_update(&mut self, team: u8) {
|
||||||
if let Some(dropdown) = &mut self.team_dropdown {
|
if let Some(dropdown) = &mut self.team_dropdown {
|
||||||
dropdown.select(team as i32);
|
dropdown.select(team as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(game) = Game::singleton()
|
||||||
|
&& let Some(player) = game.bind().find_player(self.player_id.unwrap_or(0))
|
||||||
|
&& 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user