From b2f28c36f18ae913c00552688b10146a649344b6 Mon Sep 17 00:00:00 2001 From: yuni Date: Sat, 26 Oct 2024 02:19:27 +0200 Subject: [PATCH] fix ending of chats --- src/chat.rs | 51 +++++++++++++++++++++++++++++++---------- src/chats/serenity.yaml | 2 +- src/hud.rs | 43 +++++++++++++++++++++++----------- 3 files changed, 69 insertions(+), 27 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index ce29041..ef0511e 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -108,6 +108,7 @@ pub struct Chat { pub internal_id: usize, pub position: ChatPos, pub timer: f64, + pub message_open: bool, pub talker: Talker, } @@ -476,6 +477,7 @@ impl ChatDB { let mut processed_a_choice = false; match current_item { Some(Value::String(message)) => { + chat.message_open = true; event.send(ChatEvent::SpawnMessage( message.to_string(), hud::LogLevel::Chat, @@ -523,23 +525,35 @@ impl ChatDB { let key = key.as_str(); match (key, value) { (Some(TOKEN_MSG), Value::String(message)) => { + let loglevel = hud::LogLevel::Chat; + if loglevel.is_subtitle() { + chat.message_open = true; + } event.send(ChatEvent::SpawnMessage( message.to_string(), - hud::LogLevel::Chat, + loglevel, sound.clone(), )); } (Some(TOKEN_SYSTEM), Value::String(message)) => { + let loglevel = hud::LogLevel::Info; + if loglevel.is_subtitle() { + chat.message_open = true; + } event.send(ChatEvent::SpawnMessage( message.to_string(), - hud::LogLevel::Info, + loglevel, sound.clone(), )); } (Some(TOKEN_WARN), Value::String(message)) => { + let loglevel = hud::LogLevel::Warning; + if loglevel.is_subtitle() { + chat.message_open = true; + } event.send(ChatEvent::SpawnMessage( message.to_string(), - hud::LogLevel::Warning, + loglevel, sound.clone(), )); } @@ -578,11 +592,7 @@ impl ChatDB { } None => { if chat.position.len() == 0 { - event.send(ChatEvent::SpawnMessage( - "Disconnected.".to_string(), - hud::LogLevel::Info, - DEFAULT_SOUND.to_string(), - )); + // Here it used to spawn the "Disconnected" message. event.send(ChatEvent::DespawnAllChats); } } @@ -639,8 +649,7 @@ impl ChatDB { // Add a "Continue" choice to any conversation line that doesn't define any choices let choices_available = key > 0; - let at_exit = chat.position.is_empty(); - if !choices_available && !at_exit { + if chat.message_open && !choices_available { let goto: Vec = chat.position.clone(); event.send(ChatEvent::SpawnChoice( String::from(TEXT_CONTINUE), @@ -688,6 +697,7 @@ pub fn handle_new_conversations( let mut chat = Chat { internal_id: chat_id, position: vec![0], + message_open: false, timer: time.elapsed_seconds_f64(), talker: event.talker.clone(), }; @@ -745,6 +755,12 @@ pub fn handle_chat_events( } ChatEvent::DespawnAllChats => { commands.entity(chat_entity).despawn(); + + // also despawn all choices (keep in sync with DespawnAllChoices handler) + for entity in &q_choices { + commands.entity(entity).despawn(); + } + choice_key = 0; } ChatEvent::SpawnMessage(message, level, sound) => { match level { @@ -801,6 +817,8 @@ pub fn handle_chat_events( choice_key += 1; if ENABLE_CHOICE_TIMER && !nowait { chat.timer = now + CHOICE_TIMER / settings.chat_speed as f64; + } else { + chat.timer = f64::INFINITY; } } ChatEvent::RunScript(script) => { @@ -830,7 +848,8 @@ fn handle_reply_keys( settings: Res, q_choices: Query<&Choice>, mut q_chats: Query<&mut Chat>, - mut evwriter_sfx: EventWriter, + mut ew_sfx: EventWriter, + mut ew_chat: EventWriter, time: Res