Only grey out the tree you spoke to, not all matching that monologue

main
Elijah Voigt 4 months ago
parent 7c3e68dc02
commit 4460944455

@ -134,7 +134,7 @@ fn init_debug_ui(mut commands: Commands) {
padding: UiRect::all(Val::Px(10.0)),
..default()
},
BackgroundColor(PINK.with_alpha(0.5).into()),
BackgroundColor(PINK.with_alpha(0.9).into()),
MonologuesList,
));
parent.spawn((
@ -144,7 +144,7 @@ fn init_debug_ui(mut commands: Commands) {
padding: UiRect::all(Val::Px(10.0)),
..default()
},
BackgroundColor(ORANGE.with_alpha(0.5).into()),
BackgroundColor(ORANGE.with_alpha(0.9).into()),
MonologuePreview,
));
});
@ -221,7 +221,7 @@ struct DialogLine;
/// Events that drive the dialog engine
#[derive(Event, PartialEq)]
enum DialogEvent {
Start(Handle<Monologue>),
Start(Entity, Handle<Monologue>),
NextBatch,
End,
}
@ -248,7 +248,7 @@ fn start_dialog(
debug!("Click event detected");
if let Ok(TreeMonologue(handle)) = query.get(event.target) {
debug!("Tree Monologue received, sending start dialog event");
dialog_events.write(DialogEvent::Start(handle.clone()));
dialog_events.write(DialogEvent::Start(event.target, handle.clone()));
dialog_events.write(DialogEvent::NextBatch);
}
})
@ -278,6 +278,8 @@ fn dialog_engine(
mut commands: Commands,
// Handle to "active" monologue
mut handle: Local<Handle<Monologue>>,
// Track active entity as well as the monologue
mut tree_entity: Local<Option<Entity>>,
// Index into "active" monologue
mut idx: Local<usize>,
// Inform the rest of the game what state of dialog we are in
@ -296,7 +298,7 @@ fn dialog_engine(
events.read().for_each(|event| {
match event {
DialogEvent::Start(h) => {
DialogEvent::Start(e, h) => {
debug!("Dialog start: {:?}", h);
// Set state to "Active"
@ -304,6 +306,7 @@ fn dialog_engine(
// Copy monologue asset into local
*handle = h.clone();
*tree_entity = Some(*e);
}
DialogEvent::NextBatch => {
debug!("Dialog batch");
@ -332,15 +335,8 @@ fn dialog_engine(
DialogEvent::End => {
debug!("Dialog ended");
// Remove the TreeMonologue component from the active tree
monologue_trees
.iter()
.filter_map(|(entity, tree_monologue)| {
(*tree_monologue == TreeMonologue(handle.clone())).then_some(entity)
})
.for_each(|e| {
commands.entity(e).remove::<TreeMonologue>();
});
// Remove the TreeMonologue component from the tree we just "spoke to"
commands.entity(tree_entity.unwrap()).remove::<TreeMonologue>();
// Remove lines from dialog box
lines.iter().for_each(|e| {

Loading…
Cancel
Save