detect choice selection keys

This commit is contained in:
yuni 2024-04-13 15:44:23 +02:00
parent 2b0de07427
commit 826638416f

View file

@ -42,6 +42,7 @@ impl Plugin for ChatPlugin {
app.add_systems(Update, ( app.add_systems(Update, (
handle_new_conversations.before(handle_chat_events), handle_new_conversations.before(handle_chat_events),
handle_chat_events, handle_chat_events,
handle_reply_keys,
handle_chat_timer.before(handle_chat_events), handle_chat_timer.before(handle_chat_events),
)); ));
app.add_event::<StartConversationEvent>(); app.add_event::<StartConversationEvent>();
@ -275,3 +276,29 @@ pub fn handle_chat_events(
} }
} }
} }
fn handle_reply_keys(
keyboard_input: Res<ButtonInput<KeyCode>>,
settings: ResMut<settings::Settings>,
q_choices: Query<&Choice>,
//mut evwriter_sendmsg: EventWriter<SendMessageEvent>,
mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>,
) {
let mut selected_choice: usize = 0;
'outer: for key in settings.get_reply_keys() {
if keyboard_input.just_pressed(key) {
for choice in &q_choices {
if choice.key == 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;
}
}
}
selected_choice += 1;
}
}