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(()) Ok(())
} }
pub fn _highlight(&self, color: Color) -> Result<()> {
self.name_label.set_background(color)
}
pub fn update_place(&mut self, place: u8) -> Result<()> { pub fn update_place(&mut self, place: u8) -> Result<()> {
if self.place != place { if self.place != place {
self.place_updated = true; 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="place" x_slot="0" y_slot="0" text_color="black" text_alignment="right"></label>
<label <label
id="name" 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 <label
id="time" 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> </grid>
</root> </root>

View file

@ -33,7 +33,7 @@ pub struct LeaderBoard {
last_player_id: i32, last_player_id: i32,
entry_backgrounds: [Color; 2], entry_backgrounds: [Color; 2],
_player_background: Color, player_background: Color,
} }
impl LeaderBoard { impl LeaderBoard {
@ -67,7 +67,7 @@ impl LeaderBoard {
last_player_id: -1, last_player_id: -1,
entry_backgrounds: [Color::try_from("#838383")?, Color::try_from("#545454")?], 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"); write_log!("create entries");
// check if entry count in grid is the same as the gathered entries // check if entry count in grid is the same as the gathered entries
@ -161,9 +164,14 @@ impl LeaderBoard {
for (i, entry) in self.leaderboard_entries.iter_mut().enumerate() { for (i, entry) in self.leaderboard_entries.iter_mut().enumerate() {
entry.resorting_finished(); entry.resorting_finished();
entry.change_background_color(self.entry_backgrounds[i % 2])?;
self.leaderboard_grid.attach(entry.snippet(), 0, i, 1, 1)?; // 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; self.leaderboard_redraw = true;
@ -203,7 +211,12 @@ impl LeaderBoard {
if let Some(entry) = self.deltaboard_entries.get_mut(i) { if let Some(entry) = self.deltaboard_entries.get_mut(i) {
entry.change_id(leaderboard_entry.id()); entry.change_id(leaderboard_entry.id());
entry.update_place(leaderboard_entry.place())?; entry.update_place(leaderboard_entry.place())?;
entry.change_background_color(self.entry_backgrounds[i % 2])?;
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() { if entry.name() != leaderboard_entry.name() {
entry.change_name(leaderboard_entry.name().to_string())?; entry.change_name(leaderboard_entry.name().to_string())?;
@ -318,15 +331,19 @@ impl DataReceiver for LeaderBoard {
if self.leaderboard_redraw { if self.leaderboard_redraw {
self.leaderboard_redraw = false; self.leaderboard_redraw = false;
// if let Some(player_id) = player_id { if let Some(player_id) = player_id {
// if let Some(entry) = self.entries.iter().find(|entry| entry.id() == player_id) { if let Some(entry) = self
// write_log!(format!( .leaderboard_entries
// "Update player entry background color: {:?}", .iter()
// self.player_background .find(|entry| entry.id() == player_id)
// )); {
// entry.highlight(self.player_background)?; 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 { if let Some(player_id) = player_id {