|
|
|
@ -122,21 +122,23 @@ struct MonologuePreview;
|
|
|
|
|
|
|
|
|
|
|
|
/// Panel for selecting which monologue tree to spawn
|
|
|
|
/// Panel for selecting which monologue tree to spawn
|
|
|
|
fn init_debug_ui(mut commands: Commands) {
|
|
|
|
fn init_debug_ui(mut commands: Commands) {
|
|
|
|
commands.spawn((
|
|
|
|
commands
|
|
|
|
Name::new("Tree Planter"),
|
|
|
|
.spawn((
|
|
|
|
Text::new("+Tree"),
|
|
|
|
Name::new("Tree Planter"),
|
|
|
|
Node {
|
|
|
|
Text::new("+Tree"),
|
|
|
|
top: Val::Px(0.0),
|
|
|
|
Node {
|
|
|
|
left: Val::Px(0.0),
|
|
|
|
top: Val::Px(0.0),
|
|
|
|
min_width: Val::Px(25.0),
|
|
|
|
left: Val::Px(0.0),
|
|
|
|
min_height: Val::Px(25.0),
|
|
|
|
min_width: Val::Px(25.0),
|
|
|
|
..default()
|
|
|
|
min_height: Val::Px(25.0),
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
BackgroundColor(RED.into()),
|
|
|
|
},
|
|
|
|
DebuggingState::On,
|
|
|
|
BackgroundColor(RED.into()),
|
|
|
|
MonologuesContainer,
|
|
|
|
DebuggingState::On,
|
|
|
|
Button,
|
|
|
|
MonologuesContainer,
|
|
|
|
)).observe(spawn_tree);
|
|
|
|
Button,
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.observe(spawn_tree);
|
|
|
|
|
|
|
|
|
|
|
|
let monologue_button = commands
|
|
|
|
let monologue_button = commands
|
|
|
|
.spawn((
|
|
|
|
.spawn((
|
|
|
|
@ -167,20 +169,23 @@ fn init_debug_ui(mut commands: Commands) {
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
BackgroundColor(BLACK.into()),
|
|
|
|
BackgroundColor(BLACK.into()),
|
|
|
|
)).with_children(|parent| {
|
|
|
|
))
|
|
|
|
parent.spawn((
|
|
|
|
.with_children(|parent| {
|
|
|
|
Name::new("Buttons"),
|
|
|
|
parent
|
|
|
|
Node {
|
|
|
|
.spawn((
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
Name::new("Buttons"),
|
|
|
|
height: Val::Percent(100.0),
|
|
|
|
Node {
|
|
|
|
width: Val::Percent(40.0),
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
overflow: Overflow::scroll_y(),
|
|
|
|
height: Val::Percent(100.0),
|
|
|
|
..default()
|
|
|
|
width: Val::Percent(40.0),
|
|
|
|
},
|
|
|
|
overflow: Overflow::scroll_y(),
|
|
|
|
ScrollPosition::default(),
|
|
|
|
..default()
|
|
|
|
BackgroundColor(ORANGE.into()),
|
|
|
|
},
|
|
|
|
MonologuesList,
|
|
|
|
ScrollPosition::default(),
|
|
|
|
)).observe(scroll);
|
|
|
|
BackgroundColor(ORANGE.into()),
|
|
|
|
|
|
|
|
MonologuesList,
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.observe(scroll);
|
|
|
|
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((
|
|
|
|
Name::new("Preview"),
|
|
|
|
Name::new("Preview"),
|
|
|
|
@ -196,7 +201,7 @@ fn init_debug_ui(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
BackgroundColor(ORANGE_RED.into()),
|
|
|
|
BackgroundColor(ORANGE_RED.into()),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn hover_dialog_box_over(
|
|
|
|
fn hover_dialog_box_over(
|
|
|
|
@ -271,16 +276,16 @@ enum DialogState {
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Start dialog, will expand later with handle to monologue asset
|
|
|
|
/// Start dialog
|
|
|
|
fn start_dialog(
|
|
|
|
fn start_dialog(
|
|
|
|
mut click_events: EventReader<Pointer<Click>>,
|
|
|
|
mut click_events: EventReader<Pointer<Click>>,
|
|
|
|
mut dialog_events: EventWriter<DialogEvent>,
|
|
|
|
mut dialog_events: EventWriter<DialogEvent>,
|
|
|
|
query: Query<&TreeMonologue, With<Tree>>,
|
|
|
|
query: Query<&TreeMonologue, With<Tree>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
click_events.read().for_each(|event| {
|
|
|
|
click_events.read().for_each(|event| {
|
|
|
|
debug!("Click event detected");
|
|
|
|
info!("Click event detected in start dialog systme");
|
|
|
|
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");
|
|
|
|
info!("Tree Monologue received, sending start dialog event");
|
|
|
|
dialog_events.write(DialogEvent::Start(event.target, handle.clone()));
|
|
|
|
dialog_events.write(DialogEvent::Start(event.target, handle.clone()));
|
|
|
|
dialog_events.write(DialogEvent::NextBatch);
|
|
|
|
dialog_events.write(DialogEvent::NextBatch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -483,19 +488,15 @@ fn monologue_asset_tooltip(
|
|
|
|
over_events
|
|
|
|
over_events
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.filter_map(|Pointer { target, .. }| trees.contains(*target).then_some(*target))
|
|
|
|
.filter_map(|Pointer { target, .. }| trees.contains(*target).then_some(*target))
|
|
|
|
.for_each(|e| {
|
|
|
|
.for_each(|e| match trees.get(e) {
|
|
|
|
match trees.get(e) {
|
|
|
|
Ok((_tree, Some(TreeMonologue(handle)))) => match handle.path() {
|
|
|
|
Ok((_tree, Some(TreeMonologue(handle)))) => {
|
|
|
|
Some(p) => tooltip.insert("Script", format!("{p}")),
|
|
|
|
match handle.path() {
|
|
|
|
None => tooltip.insert("Script", "A".into()),
|
|
|
|
Some(p) => tooltip.insert("Script", format!("{p}")),
|
|
|
|
},
|
|
|
|
None => tooltip.insert("Script", "A".into()),
|
|
|
|
Ok((_tree, None)) => {
|
|
|
|
}
|
|
|
|
tooltip.insert("Script", "N/A".into());
|
|
|
|
},
|
|
|
|
|
|
|
|
Ok((_tree, None)) => {
|
|
|
|
|
|
|
|
tooltip.insert("Script", "N/A".into());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => ()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -594,7 +595,14 @@ fn spawn_debug_buttons(
|
|
|
|
parent
|
|
|
|
parent
|
|
|
|
.spawn((
|
|
|
|
.spawn((
|
|
|
|
Button,
|
|
|
|
Button,
|
|
|
|
Text::new(handle.path().unwrap().to_string().trim_prefix("trees/").trim_suffix(".mono")),
|
|
|
|
Text::new(
|
|
|
|
|
|
|
|
handle
|
|
|
|
|
|
|
|
.path()
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.to_string()
|
|
|
|
|
|
|
|
.trim_prefix("trees/")
|
|
|
|
|
|
|
|
.trim_suffix(".mono"),
|
|
|
|
|
|
|
|
),
|
|
|
|
TextLayout::new(JustifyText::Left, LineBreak::WordBoundary),
|
|
|
|
TextLayout::new(JustifyText::Left, LineBreak::WordBoundary),
|
|
|
|
TreeMonologue(handle.clone()),
|
|
|
|
TreeMonologue(handle.clone()),
|
|
|
|
MonologuesList,
|
|
|
|
MonologuesList,
|
|
|
|
@ -636,7 +644,6 @@ fn preview_monologue(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// Get the handle for this button's monologuie
|
|
|
|
// Get the handle for this button's monologuie
|
|
|
|
if let Ok(TreeMonologue(handle)) = tree_monologue.get(trigger.target()) {
|
|
|
|
if let Ok(TreeMonologue(handle)) = tree_monologue.get(trigger.target()) {
|
|
|
|
|
|
|
|
|
|
|
|
// Get the monologue data
|
|
|
|
// Get the monologue data
|
|
|
|
if let Some(monologue) = monologues.get(handle) {
|
|
|
|
if let Some(monologue) = monologues.get(handle) {
|
|
|
|
commands.entity(*container).despawn_related::<Children>();
|
|
|
|
commands.entity(*container).despawn_related::<Children>();
|
|
|
|
@ -738,7 +745,7 @@ fn handle_plant_tree(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Event)]
|
|
|
|
#[derive(Event, Debug)]
|
|
|
|
struct AssignMonologue(Handle<Monologue>);
|
|
|
|
struct AssignMonologue(Handle<Monologue>);
|
|
|
|
|
|
|
|
|
|
|
|
/// Assign the given monologue to a tree
|
|
|
|
/// Assign the given monologue to a tree
|
|
|
|
@ -749,11 +756,14 @@ fn assign_monologue_to_tree(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
events.read().for_each(|event| {
|
|
|
|
events.read().for_each(|event| {
|
|
|
|
// Get a valid tree to assign an entity to
|
|
|
|
// Get a valid tree to assign an entity to
|
|
|
|
let tree = query.iter().next().unwrap();
|
|
|
|
if let Some(tree) = query.iter().next() {
|
|
|
|
// Create the TreeMonologue component
|
|
|
|
// Create the TreeMonologue component
|
|
|
|
let monologue = TreeMonologue(event.0.clone());
|
|
|
|
let monologue = TreeMonologue(event.0.clone());
|
|
|
|
// Insert the component to the entity
|
|
|
|
// Insert the component to the entity
|
|
|
|
commands.entity(tree).insert(monologue);
|
|
|
|
commands.entity(tree).insert(monologue);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
error!("No trees avaliable for {:?}", event.0.path().unwrap());
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -782,9 +792,7 @@ fn drag_tree(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// When you pointer over the '+' make the entire menu visible
|
|
|
|
// When you pointer over the '+' make the entire menu visible
|
|
|
|
fn hide_menu(
|
|
|
|
fn hide_menu(mut nodes: Query<(Entity, &mut Visibility, &NavState), Changed<NavState>>) {
|
|
|
|
mut nodes: Query<(Entity, &mut Visibility, &NavState), Changed<NavState>>
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
nodes.iter_mut().for_each(|(e, mut v, n)| {
|
|
|
|
nodes.iter_mut().for_each(|(e, mut v, n)| {
|
|
|
|
*v = match n {
|
|
|
|
*v = match n {
|
|
|
|
NavState::Open => Visibility::Inherited,
|
|
|
|
NavState::Open => Visibility::Inherited,
|
|
|
|
@ -794,7 +802,10 @@ fn hide_menu(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn clear_monologue(
|
|
|
|
fn clear_monologue(
|
|
|
|
mut nodes: Query<(Entity, &NavState), (Changed<NavState>, With<MonologuePreview>, Without<Text>)>,
|
|
|
|
mut nodes: Query<
|
|
|
|
|
|
|
|
(Entity, &NavState),
|
|
|
|
|
|
|
|
(Changed<NavState>, With<MonologuePreview>, Without<Text>),
|
|
|
|
|
|
|
|
>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
nodes.iter_mut().for_each(|(e, n)| {
|
|
|
|
nodes.iter_mut().for_each(|(e, n)| {
|
|
|
|
@ -843,7 +854,6 @@ fn control_menu(
|
|
|
|
.iter_descendants(root)
|
|
|
|
.iter_descendants(root)
|
|
|
|
.any(|child| is_hovered.contains(&&child));
|
|
|
|
.any(|child| is_hovered.contains(&&child));
|
|
|
|
if !tree_still_hovered {
|
|
|
|
if !tree_still_hovered {
|
|
|
|
|
|
|
|
|
|
|
|
if let Ok(mut n) = nav.get_mut(root) {
|
|
|
|
if let Ok(mut n) = nav.get_mut(root) {
|
|
|
|
*n = NavState::Closed;
|
|
|
|
*n = NavState::Closed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -857,10 +867,7 @@ fn control_menu(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Observer for the "Plant a new tree" button in the debug UI
|
|
|
|
/// Observer for the "Plant a new tree" button in the debug UI
|
|
|
|
fn spawn_tree(
|
|
|
|
fn spawn_tree(_trigger: Trigger<Pointer<Click>>, mut events: EventWriter<PlantTree>) {
|
|
|
|
_trigger: Trigger<Pointer<Click>>,
|
|
|
|
|
|
|
|
mut events: EventWriter<PlantTree>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events.write(PlantTree);
|
|
|
|
events.write(PlantTree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|