From 446094445540de9e6f7fe674d3579dba7030cf96 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Wed, 9 Jul 2025 15:16:33 -0700 Subject: [PATCH] Only grey out the tree you spoke to, not all matching that monologue --- src/bin/trees/main.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/bin/trees/main.rs b/src/bin/trees/main.rs index 0a4d9cd..19aef47 100644 --- a/src/bin/trees/main.rs +++ b/src/bin/trees/main.rs @@ -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), + Start(Entity, Handle), 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>, + // Track active entity as well as the monologue + mut tree_entity: Local>, // Index into "active" monologue mut idx: Local, // 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::(); - }); + // Remove the TreeMonologue component from the tree we just "spoke to" + commands.entity(tree_entity.unwrap()).remove::(); // Remove lines from dialog box lines.iter().for_each(|e| {