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