From f01fd06bac3bf30a6292504b0486301cb8e7cd43 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 15 Apr 2024 21:18:02 +0200 Subject: [PATCH] different colors for different console log levels --- src/chat.rs | 2 +- src/hud.rs | 26 ++++++-------------------- src/var.rs | 4 ++++ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index e2ec067..97519c8 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -685,7 +685,7 @@ pub fn handle_chat_events( hud::LogLevel::Chat => { log.chat(message.into(), chat.talker.name.clone().unwrap_or("".to_string())); } - hud::LogLevel::Info | hud::LogLevel::Notice => { + hud::LogLevel::Info => { log.info(message.into()); } hud::LogLevel::Warning => { diff --git a/src/hud.rs b/src/hud.rs index 9f7ae78..5b36a74 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -80,7 +80,6 @@ pub enum LogLevel { //Debug, Chat, //Ping, - Notice, } struct Message { @@ -135,10 +134,6 @@ impl Log { self.add(message, "WARNING".to_string(), LogLevel::Warning); } - pub fn notice(&mut self, message: String) { - self.add(message, "".to_string(), LogLevel::Notice); - } - pub fn add(&mut self, text: String, sender: String, level: LogLevel) { if self.logs.len() == LOG_MAX { self.logs.pop_front(); @@ -174,11 +169,8 @@ fn setup( mut commands: Commands, settings: Res, asset_server: Res, - mut log: ResMut, mut ambient_light: ResMut, ) { - log.notice("Resuming from suspend".to_string()); - log.notice("WARNING: Oxygen Low".to_string()); let visibility = if settings.hud_active { Visibility::Inherited } else { @@ -508,20 +500,9 @@ fn update_hud( let mut row = 0; // Chat Log and System Log - let logfilter = if settings.hud_active { - |_msg: &&Message| { true } - } else { - |msg: &&Message| { match msg.level { - LogLevel::Chat => true, - LogLevel::Warning => true, - LogLevel::Info => true, - _ => false - }} - }; let messages: Vec<&Message> = log.logs.iter() - .filter(logfilter) .rev() - .take(15) + .take(LOG_MAX_ROWS) .collect(); //messages.reverse(); for msg in &messages { @@ -529,6 +510,11 @@ fn update_hud( let freshness = msg.get_freshness(); let clr: f32 = (freshness.powf(1.5) as f32).clamp(0.1, 1.0); freshest_line = freshest_line.max(freshness); + chat.sections[row].style.color = match msg.level { + LogLevel::Warning => settings.hud_color_console_warn, + LogLevel::Info => settings.hud_color_console_system, + _ => settings.hud_color_console, + }; chat.sections[row].style.color.set_a(clr); row += 1; } diff --git a/src/var.rs b/src/var.rs index fc1d9d4..201e273 100644 --- a/src/var.rs +++ b/src/var.rs @@ -33,6 +33,8 @@ pub struct Settings { pub font_size_console: f32, pub hud_color: Color, pub hud_color_console: Color, + pub hud_color_console_warn: Color, + pub hud_color_console_system: Color, pub hud_color_alert: Color, pub hud_color_subtitles: Color, pub hud_color_choices: Color, @@ -126,6 +128,8 @@ impl Default for Settings { font_size_console: 20.0, hud_color: Color::rgb(0.2, 0.5, 0.2), hud_color_console: Color::rgb(0.2, 0.5, 0.2), + hud_color_console_warn: Color::rgb(1.0, 0.3, 0.3), + hud_color_console_system: Color::rgb(0.5, 0.5, 0.5), hud_color_alert: Color::rgb(0.7, 0.3, 0.3), hud_color_subtitles: Color::rgb(0.8, 0.8, 0.8), hud_color_choices: Color::rgb(0.45, 0.45, 0.45),