From b1c78e4ccbd3f56377b83e4878b7cd149433bf9b Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 4 Apr 2024 18:53:20 +0200 Subject: [PATCH] move send reply code to chat.rs --- src/chat.rs | 31 ++++++++++++++++++++++++++++++- src/hud.rs | 22 ---------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index a797462..82fbe39 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use crate::{actor, audio, hud}; +use crate::{actor, audio, hud, settings}; pub struct ChatPlugin; impl Plugin for ChatPlugin { @@ -7,6 +7,7 @@ impl Plugin for ChatPlugin { app.register_type::(); app.add_systems(Update, ( handle_new_conversations, + handle_reply_keys, handle_send_messages, handle_conversations, handle_chat_scripts, @@ -109,6 +110,34 @@ pub fn handle_new_conversations( } } +fn handle_reply_keys( + keyboard_input: Res>, + settings: ResMut, + q_choices: Query<&ChoiceAvailable>, + mut evwriter_sendmsg: EventWriter, + mut evwriter_sfx: EventWriter, +) { + let mut selected_choice = 1; + 'outer: for key in settings.get_reply_keys() { + if keyboard_input.just_pressed(key) { + let mut count = 1; + for choice in &q_choices { + if count == selected_choice { + evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); + evwriter_sendmsg.send(SendMessageEvent { + conv_id: choice.conv_id.clone(), + conv_label: choice.conv_label.clone(), + text: choice.text.clone(), + }); + break 'outer; + } + count += 1; + } + } + selected_choice += 1; + } +} + pub fn handle_send_messages( mut commands: Commands, mut er_sendmsg: EventReader, diff --git a/src/hud.rs b/src/hud.rs index c467b22..b1948dc 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -477,8 +477,6 @@ fn handle_input( keyboard_input: Res>, mut settings: ResMut, mut q_hud: Query<&mut Visibility, With>, - q_choices: Query<&chat::ChoiceAvailable>, - mut evwriter_sendmsg: EventWriter, mut evwriter_sfx: EventWriter, mut evwriter_togglemusic: EventWriter, mut ambient_light: ResMut, @@ -501,24 +499,4 @@ fn handle_input( evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); evwriter_togglemusic.send(audio::ToggleMusicEvent()); } - - let mut selected_choice = 1; - 'outer: for key in settings.get_reply_keys() { - if keyboard_input.just_pressed(key) { - let mut count = 1; - for choice in &q_choices { - if count == selected_choice { - evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); - evwriter_sendmsg.send(chat::SendMessageEvent { - conv_id: choice.conv_id.clone(), - conv_label: choice.conv_label.clone(), - text: choice.text.clone(), - }); - break 'outer; - } - count += 1; - } - } - selected_choice += 1; - } }