From 33386a1f17358ddf3a98a11b3ed401702aacba16 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 19 Jan 2023 13:41:08 +0100 Subject: [PATCH] highlight delta board player entry --- .../elements/leaderboard/leaderboard_entry.rs | 4 -- .../leaderboard/leaderboard_entry.xml | 4 +- src/overlay/elements/leaderboard/mod.rs | 45 +++++++++++++------ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/overlay/elements/leaderboard/leaderboard_entry.rs b/src/overlay/elements/leaderboard/leaderboard_entry.rs index 8a1acb4..6d5a9db 100644 --- a/src/overlay/elements/leaderboard/leaderboard_entry.rs +++ b/src/overlay/elements/leaderboard/leaderboard_entry.rs @@ -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; diff --git a/src/overlay/elements/leaderboard/leaderboard_entry.xml b/src/overlay/elements/leaderboard/leaderboard_entry.xml index c67a5c2..5d1f74f 100644 --- a/src/overlay/elements/leaderboard/leaderboard_entry.xml +++ b/src/overlay/elements/leaderboard/leaderboard_entry.xml @@ -4,9 +4,9 @@ + x_slot="1" y_slot="0" x_size="7" text_color="black"> + x_slot="8" y_slot="0" x_size="3" text_color="black" text_alignment="right"> \ No newline at end of file diff --git a/src/overlay/elements/leaderboard/mod.rs b/src/overlay/elements/leaderboard/mod.rs index ee662c3..3fee545 100644 --- a/src/overlay/elements/leaderboard/mod.rs +++ b/src/overlay/elements/leaderboard/mod.rs @@ -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,9 +164,14 @@ impl LeaderBoard { for (i, entry) in self.leaderboard_entries.iter_mut().enumerate() { 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; @@ -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())?; - 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() { 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 {