render choices
This commit is contained in:
parent
9cd1cf19e2
commit
9698dcdfee
28
src/chat.rs
28
src/chat.rs
|
@ -57,7 +57,10 @@ pub struct Chat {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Choice;
|
||||
pub struct Choice {
|
||||
pub text: String,
|
||||
pub key: usize,
|
||||
}
|
||||
|
||||
// This is the only place where any YAML interaction should be happening.
|
||||
#[derive(Resource)]
|
||||
|
@ -116,7 +119,7 @@ impl ChatDB {
|
|||
let mut is_skipping_through = false;
|
||||
chat.position += 1;
|
||||
if chat.position >= conv.len() {
|
||||
event.send(ChatEvent::DisplayMessage("Disconnected.".to_string()));
|
||||
event.send(ChatEvent::SpawnMessage("Disconnected.".to_string()));
|
||||
event.send(ChatEvent::DespawnAllChats);
|
||||
return;
|
||||
}
|
||||
|
@ -124,17 +127,19 @@ impl ChatDB {
|
|||
is_skipping_through = true;
|
||||
}
|
||||
else if let Some(message) = conv[chat.position].as_str() {
|
||||
event.send(ChatEvent::DisplayMessage(message.to_string()));
|
||||
event.send(ChatEvent::SpawnMessage(message.to_string()));
|
||||
}
|
||||
|
||||
// Check if the immediately following entries are choices
|
||||
let mut pos = chat.position + 1;
|
||||
let mut key: usize = 0;
|
||||
loop {
|
||||
if is_skipping_through || pos >= conv.len() {
|
||||
break;
|
||||
}
|
||||
if let Some(choice) = self.search_choice(&conv[pos]) {
|
||||
event.send(ChatEvent::DisplayMessage(choice));
|
||||
event.send(ChatEvent::SpawnChoice(choice, key));
|
||||
key += 1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
|
@ -162,8 +167,8 @@ pub struct StartConversationEvent {
|
|||
pub enum ChatEvent {
|
||||
DespawnAllChoices,
|
||||
DespawnAllChats,
|
||||
DisplayMessage(String),
|
||||
//SpawnChoice(String),
|
||||
SpawnMessage(String),
|
||||
SpawnChoice(String, usize),
|
||||
//Script(String, String, String),
|
||||
}
|
||||
|
||||
|
@ -251,10 +256,19 @@ pub fn handle_chat_events(
|
|||
ChatEvent::DespawnAllChats => {
|
||||
commands.entity(chat_entity).despawn();
|
||||
}
|
||||
ChatEvent::DisplayMessage(message) => {
|
||||
ChatEvent::SpawnMessage(message) => {
|
||||
log.chat(message.into(), chat.talker.name.clone().unwrap_or(NAME_FALLBACK.to_string()));
|
||||
chat.timer = now + ((message.len() as f32).max(CHAT_SPEED_MIN_LEN) * TALKER_SPEED_FACTOR * chat.talker.talking_speed / settings.chat_speed) as f64;
|
||||
}
|
||||
ChatEvent::SpawnChoice(replytext, key) => {
|
||||
commands.spawn((
|
||||
world::DespawnOnPlayerDeath,
|
||||
Choice {
|
||||
text: replytext.into(),
|
||||
key: *key,
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,10 @@
|
|||
- Thank you!:
|
||||
- label: thx
|
||||
- No worries. Folks are stretched thin around this corner, we gotta watch out for each other.
|
||||
- How talkcount are you feeling?
|
||||
- How are you feeling?
|
||||
- goto: howru
|
||||
- I didn't ask for this.:
|
||||
- label: didntask
|
||||
- "Sure, 'cause you were unconscious. I just did what felt right. Is there a problem?"
|
||||
- Nevermind. Thank you.:
|
||||
- goto: thx
|
||||
|
|
44
src/hud.rs
44
src/hud.rs
|
@ -1,4 +1,4 @@
|
|||
use crate::{actor, audio, camera, nature, settings, world};
|
||||
use crate::{actor, audio, camera, chat, nature, settings, world};
|
||||
use bevy::prelude::*;
|
||||
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
||||
use bevy::transform::TransformSystem;
|
||||
|
@ -412,7 +412,7 @@ fn update_hud(
|
|||
q_camera: Query<(&Position, &LinearVelocity), With<actor::PlayerCamera>>,
|
||||
mut timer: ResMut<FPSUpdateTimer>,
|
||||
mut query: Query<&mut Text, With<GaugesText>>,
|
||||
//q_choices: Query<&chat::ChoiceAvailable>,
|
||||
q_choices: Query<&chat::Choice>,
|
||||
mut query_chat: Query<&mut Text, (With<ChatText>, Without<GaugesText>)>,
|
||||
query_all_actors: Query<&actor::Actor>,
|
||||
settings: Res<settings::Settings>,
|
||||
|
@ -515,26 +515,26 @@ fn update_hud(
|
|||
}
|
||||
|
||||
if let Ok(mut chat) = query_chat.get_single_mut() {
|
||||
// // Choices
|
||||
// let mut choices: Vec<String> = Vec::new();
|
||||
// let mut count = 0;
|
||||
// for choice in &q_choices {
|
||||
// if count > 9 {
|
||||
// break;
|
||||
// }
|
||||
// let press_this = REPLY_NUMBERS[count];
|
||||
// let reply = &choice.text;
|
||||
// //let recipient = &choice.recipient;
|
||||
// // TODO: indicate recipients if there's more than one
|
||||
// choices.push(format!("{press_this} {reply}"));
|
||||
// count += 1;
|
||||
// }
|
||||
// if count < 4 {
|
||||
// for _padding in 0..(4-count) {
|
||||
// choices.push(" ".to_string());
|
||||
// }
|
||||
// }
|
||||
// chat.sections[2].value = choices.join("\n");
|
||||
// Choices
|
||||
let mut choices: Vec<String> = Vec::new();
|
||||
let mut count = 0;
|
||||
for choice in &q_choices {
|
||||
if count > 9 {
|
||||
break;
|
||||
}
|
||||
let press_this = REPLY_NUMBERS[choice.key];
|
||||
let reply = &choice.text;
|
||||
//let recipient = &choice.recipient;
|
||||
// TODO: indicate recipients if there's more than one
|
||||
choices.push(format!("{press_this} {reply}"));
|
||||
count += 1;
|
||||
}
|
||||
if count < 4 {
|
||||
for _padding in 0..(4-count) {
|
||||
choices.push(" ".to_string());
|
||||
}
|
||||
}
|
||||
chat.sections[2].value = choices.join("\n");
|
||||
|
||||
// Chat Log and System Log
|
||||
let logfilter = if settings.hud_active {
|
||||
|
|
Loading…
Reference in a new issue