highlight delta board player entry

This commit is contained in:
hodasemi 2023-01-19 13:41:08 +01:00
parent a19dbf4d0d
commit 2bdec6f9c7
3 changed files with 33 additions and 20 deletions

View file

@ -116,10 +116,6 @@ impl LeaderBoardEntry {
Ok(())
}
pub fn _highlight(&self, color: Color) -> Result<()> {
self.name_label.set_background(color)
}
pub fn update_place(&mut self, place: u8) -> Result<()> {
if self.place != place {
self.place_updated = true;

View file

@ -4,9 +4,9 @@
<label id="place" x_slot="0" y_slot="0" text_color="black" text_alignment="right"></label>
<label
id="name"
x_slot="1" y_slot="0" x_size="6" text_color="black" text_alignment="left"></label>
x_slot="1" y_slot="0" x_size="7" text_color="black"></label>
<label
id="time"
x_slot="7" y_slot="0" x_size="4" text_color="black" text_alignment="right"></label>
x_slot="8" y_slot="0" x_size="3" text_color="black" text_alignment="right"></label>
</grid>
</root>

View file

@ -33,7 +33,7 @@ pub struct LeaderBoard {
last_player_id: i32,
entry_backgrounds: [Color; 2],
_player_background: Color,
player_background: Color,
}
impl LeaderBoard {
@ -67,7 +67,7 @@ impl LeaderBoard {
last_player_id: -1,
entry_backgrounds: [Color::try_from("#838383")?, Color::try_from("#545454")?],
_player_background: Color::try_from("#b4bf26")?,
player_background: Color::try_from("#b4bf26")?,
})
}
@ -128,6 +128,9 @@ impl LeaderBoard {
}
}
// TODO: when people disconnect there needs to be a remove function
// vehicle_scorings.len() != self.leaderboard_entries.len()
write_log!("create entries");
// check if entry count in grid is the same as the gathered entries
@ -161,10 +164,15 @@ impl LeaderBoard {
for (i, entry) in self.leaderboard_entries.iter_mut().enumerate() {
entry.resorting_finished();
// don't break here, just skip adding to grid
// because resorting_finished should be called for every entry
if i < self.leaderboard_grid.dimensions().1 {
entry.change_background_color(self.entry_backgrounds[i % 2])?;
self.leaderboard_grid.attach(entry.snippet(), 0, i, 1, 1)?;
}
}
self.leaderboard_redraw = true;
}
@ -203,7 +211,12 @@ impl LeaderBoard {
if let Some(entry) = self.deltaboard_entries.get_mut(i) {
entry.change_id(leaderboard_entry.id());
entry.update_place(leaderboard_entry.place())?;
if entry.id() == self.last_player_id {
entry.change_background_color(self.player_background)?;
} else {
entry.change_background_color(self.entry_backgrounds[i % 2])?;
}
if entry.name() != leaderboard_entry.name() {
entry.change_name(leaderboard_entry.name().to_string())?;
@ -318,15 +331,19 @@ impl DataReceiver for LeaderBoard {
if self.leaderboard_redraw {
self.leaderboard_redraw = false;
// if let Some(player_id) = player_id {
// if let Some(entry) = self.entries.iter().find(|entry| entry.id() == player_id) {
// write_log!(format!(
// "Update player entry background color: {:?}",
// self.player_background
// ));
// entry.highlight(self.player_background)?;
// }
// }
if let Some(player_id) = player_id {
if let Some(entry) = self
.leaderboard_entries
.iter()
.find(|entry| entry.id() == player_id)
{
write_log!(format!(
"Update player entry background color: {:?}",
self.player_background
));
entry.change_background_color(self.player_background)?;
}
}
}
if let Some(player_id) = player_id {