From 04c84f466a03b96a85c3c1b57e467848efbc13d7 Mon Sep 17 00:00:00 2001 From: jugeeya Date: Mon, 11 Sep 2023 18:02:10 -0700 Subject: [PATCH] Fixes to notifications --- src/training/ui/display.rs | 30 ++++++++++++++++-------------- src/training/ui/notifications.rs | 10 ++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/training/ui/display.rs b/src/training/ui/display.rs index 6f335ba..05abc3e 100644 --- a/src/training/ui/display.rs +++ b/src/training/ui/display.rs @@ -25,7 +25,7 @@ pub unsafe fn draw(root_pane: &Pane) { let notification_idx = 0; let queue = &mut ui::notifications::QUEUE; - let notification = queue.first(); + let notification = queue.first_mut(); root_pane .find_pane_by_name_recursive(display_parent_fmt!(notification_idx)) @@ -38,21 +38,23 @@ pub unsafe fn draw(root_pane: &Pane) { let notification = notification.unwrap(); let color = notification.color; - root_pane - .find_pane_by_name_recursive(display_header_fmt!(notification_idx)) - .unwrap() - .as_textbox() - .set_text_string(¬ification.header); + if !notification.has_drawn() { + notification.set_drawn(); + root_pane + .find_pane_by_name_recursive(display_header_fmt!(notification_idx)) + .unwrap() + .as_textbox() + .set_text_string(¬ification.header); - let text = root_pane - .find_pane_by_name_recursive(display_txt_fmt!(notification_idx)) - .unwrap() - .as_textbox(); - text.set_text_string(¬ification.message); - text.set_default_material_colors(); - text.set_color(color.r, color.g, color.b, color.a); + let text = root_pane + .find_pane_by_name_recursive(display_txt_fmt!(notification_idx)) + .unwrap() + .as_textbox(); + text.set_text_string(¬ification.message); + text.set_default_material_colors(); + text.set_color(color.r, color.g, color.b, color.a); + } - let notification = queue.first_mut().unwrap(); let has_completed = notification.check_completed(); if has_completed { queue.remove(0); diff --git a/src/training/ui/notifications.rs b/src/training/ui/notifications.rs index 6d1ac58..f137495 100644 --- a/src/training/ui/notifications.rs +++ b/src/training/ui/notifications.rs @@ -8,6 +8,7 @@ pub struct Notification { pub message: String, length: u32, pub color: ResColor, + has_drawn: bool, } impl Notification { @@ -17,9 +18,18 @@ impl Notification { message, length, color, + has_drawn: false, } } + pub fn set_drawn(&mut self) { + self.has_drawn = true; + } + + pub fn has_drawn(&mut self) -> bool { + self.has_drawn + } + pub fn tick(&mut self) { self.length -= 1; }