From 6629c6f4565459cb7aa53a87f767e16c08bc3826 Mon Sep 17 00:00:00 2001
From: asimon-1 <40246417+asimon-1@users.noreply.github.com>
Date: Thu, 14 Nov 2024 19:29:20 -0500
Subject: [PATCH] Small adjustment to notifications

---
 src/training/combo.rs            |  4 ++--
 src/training/input_record.rs     | 12 ++++++------
 src/training/save_states.rs      |  2 +-
 src/training/ui/notifications.rs | 11 +++++++----
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/training/combo.rs b/src/training/combo.rs
index cc6857b..a1d20ec 100644
--- a/src/training/combo.rs
+++ b/src/training/combo.rs
@@ -55,8 +55,8 @@ unsafe fn is_actionable(module_accessor: *mut BattleObjectModuleAccessor) -> boo
 fn update_frame_advantage(frame_advantage: i32) {
     if get(&MENU).frame_advantage == OnOff::ON {
         // Prioritize Frame Advantage over Input Recording Playback
-        notifications::clear_notifications_except("Input Recording");
-        notifications::clear_notifications_except("Frame Advantage");
+        notifications::clear_notification("Input Recording");
+        notifications::clear_notification("Frame Advantage");
         notifications::color_notification(
             "Frame Advantage".to_string(),
             format!("{frame_advantage}"),
diff --git a/src/training/input_record.rs b/src/training/input_record.rs
index d7b7143..f91d0a7 100644
--- a/src/training/input_record.rs
+++ b/src/training/input_record.rs
@@ -15,7 +15,7 @@ use crate::common::{
     get_module_accessor, is_in_hitstun, is_in_shieldstun, try_get_module_accessor, MENU,
 };
 use crate::training::mash;
-use crate::training::ui::notifications::{clear_notifications_except, color_notification};
+use crate::training::ui::notifications::{clear_notification, color_notification};
 use crate::{error, warn};
 
 use training_mod_sync::*;
@@ -205,7 +205,7 @@ unsafe fn handle_recording_for_fighter(module_accessor: &mut BattleObjectModuleA
         }
         let input_record = read_rwlock(&INPUT_RECORD);
         if input_record == None {
-            clear_notifications_except("Input Recording");
+            clear_notification("Input Recording");
         }
         // Handle recording end
         let mut input_record_frame = lock_write_rwlock(&INPUT_RECORD_FRAME);
@@ -248,7 +248,7 @@ unsafe fn handle_recording_for_fighter(module_accessor: &mut BattleObjectModuleA
     // Handle Possession Coloring
     let possession = read_rwlock(&POSSESSION);
     if entry_id_int == 1 && possession == Lockout {
-        clear_notifications_except("Input Recording");
+        clear_notification("Input Recording");
         color_notification(
             "Input Recording".to_string(),
             "Lockout".to_owned(),
@@ -268,7 +268,7 @@ unsafe fn handle_recording_for_fighter(module_accessor: &mut BattleObjectModuleA
             *MODEL_COLOR_TYPE_COLOR_BLEND,
         );
     } else if entry_id_int == 1 && possession == Standby {
-        clear_notifications_except("Input Recording");
+        clear_notification("Input Recording");
         color_notification(
             "Input Recording".to_string(),
             "Standby".to_owned(),
@@ -288,7 +288,7 @@ unsafe fn handle_recording_for_fighter(module_accessor: &mut BattleObjectModuleA
             *MODEL_COLOR_TYPE_COLOR_BLEND,
         );
     } else if entry_id_int == 1 && possession == Cpu {
-        clear_notifications_except("Input Recording");
+        clear_notification("Input Recording");
         color_notification(
             "Input Recording".to_string(),
             "Recording".to_owned(),
@@ -313,7 +313,7 @@ unsafe fn handle_recording_for_fighter(module_accessor: &mut BattleObjectModuleA
         let input_record_frame = read_rwlock(&INPUT_RECORD_FRAME);
         if input_record_frame == 0 || input_record_frame == 1 {
             // can be either, seems like a thread issue
-            clear_notifications_except("Input Recording");
+            clear_notification("Input Recording");
             color_notification(
                 "Input Recording".to_string(),
                 "Playback".to_owned(),
diff --git a/src/training/save_states.rs b/src/training/save_states.rs
index 7a5da23..24bdd75 100644
--- a/src/training/save_states.rs
+++ b/src/training/save_states.rs
@@ -712,7 +712,7 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
         MIRROR_STATE = 1.0;
         save_state_player(get(&MENU).save_state_slot.into_idx().unwrap_or(0)).state = Save;
         save_state_cpu(get(&MENU).save_state_slot.into_idx().unwrap_or(0)).state = Save;
-        notifications::clear_notifications_except("Save State");
+        notifications::clear_notification("Save State");
         notifications::notification(
             "Save State".to_string(),
             format!("Saved Slot {}", get(&MENU).save_state_slot),
diff --git a/src/training/ui/notifications.rs b/src/training/ui/notifications.rs
index 44ead91..b832d3e 100644
--- a/src/training/ui/notifications.rs
+++ b/src/training/ui/notifications.rs
@@ -63,9 +63,12 @@ pub fn color_notification(header: String, message: String, len: u32, color: ResC
     drop(queue_guard);
 }
 
-pub fn clear_notifications_except(header: &'static str) {
-    if (*lock_read_rwlock(&NOTIFICATIONS_QUEUE)).is_empty() {
-        // Before acquiring an exclusive write lock, check if there are even any notificatiosn to clear out
+pub fn clear_notification(header: &'static str) {
+    if !read_rwlock(&NOTIFICATIONS_QUEUE)
+        .iter()
+        .any(|notif| notif.header == header)
+    {
+        // Before acquiring an exclusive write lock, check if there are even any relevant notifications to clear out
         return;
     }
     let mut queue_guard = lock_write_rwlock(&NOTIFICATIONS_QUEUE);
@@ -74,7 +77,7 @@ pub fn clear_notifications_except(header: &'static str) {
 }
 
 pub fn clear_all_notifications() {
-    if (*lock_read_rwlock(&NOTIFICATIONS_QUEUE)).is_empty() {
+    if read_rwlock(&NOTIFICATIONS_QUEUE).is_empty() {
         // Before acquiring an exclusive write lock, check if there are even any notificatiosn to clear out
         return;
     }