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