different colors for different console log levels

This commit is contained in:
yuni 2024-04-15 21:18:02 +02:00
parent 8533b689b2
commit f01fd06bac
3 changed files with 11 additions and 21 deletions

View file

@ -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 => {

View file

@ -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<var::Settings>,
asset_server: Res<AssetServer>,
mut log: ResMut<Log>,
mut ambient_light: ResMut<AmbientLight>,
) {
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;
}

View file

@ -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),