|
|
|
@ -32,15 +32,15 @@ fn main() {
|
|
|
|
dialog_engine.run_if(on_event::<DialogEvent>),
|
|
|
|
dialog_engine.run_if(on_event::<DialogEvent>),
|
|
|
|
mouse_wheel_scroll.run_if(on_event::<MouseWheel>),
|
|
|
|
mouse_wheel_scroll.run_if(on_event::<MouseWheel>),
|
|
|
|
auto_scroll.run_if(any_component_added::<DialogOption>),
|
|
|
|
auto_scroll.run_if(any_component_added::<DialogOption>),
|
|
|
|
dialog_box_visibility
|
|
|
|
dialog_box_visibility.run_if(state_changed::<DialogState>),
|
|
|
|
.run_if(state_changed::<DialogState>),
|
|
|
|
|
|
|
|
monologue_asset_tooltip
|
|
|
|
monologue_asset_tooltip
|
|
|
|
.run_if(on_event::<Pointer<Over>>
|
|
|
|
.run_if(on_event::<Pointer<Over>>.or(on_event::<Pointer<Out>>)),
|
|
|
|
.or(on_event::<Pointer<Out>>)),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_observer(add_dialog_option)
|
|
|
|
.add_observer(add_dialog_option)
|
|
|
|
.add_observer(add_dialog_line)
|
|
|
|
.add_observer(add_dialog_line)
|
|
|
|
|
|
|
|
.add_observer(add_tree_monologue)
|
|
|
|
|
|
|
|
.add_observer(remove_tree_monologue)
|
|
|
|
.run();
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -58,72 +58,59 @@ fn init_trees(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
|
|
|
mut ambient_light: ResMut<AmbientLight>,
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let tree_card_mesh = meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)));
|
|
|
|
// Global light
|
|
|
|
|
|
|
|
{
|
|
|
|
let tree_image = server.load("placeholder/tree.png");
|
|
|
|
ambient_light.brightness = 500.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Spawn placeholder tree (red)
|
|
|
|
// Spawn placeholder tree (red)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let tree_material_red = materials.add(StandardMaterial {
|
|
|
|
|
|
|
|
base_color_texture: Some(tree_image.clone()),
|
|
|
|
|
|
|
|
base_color: RED.into(),
|
|
|
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
let monologue: Handle<Monologue> = server.load("trees/red.mono");
|
|
|
|
|
|
|
|
let tree_transform_red =
|
|
|
|
|
|
|
|
Transform::from_xyz(-15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0));
|
|
|
|
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
Tree,
|
|
|
|
Tree,
|
|
|
|
TreeMonologue(monologue),
|
|
|
|
TreeMonologue(server.load("trees/red.mono")),
|
|
|
|
Mesh3d(tree_card_mesh.clone()),
|
|
|
|
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
|
|
|
|
MeshMaterial3d(tree_material_red),
|
|
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
|
|
tree_transform_red,
|
|
|
|
base_color_texture: Some(server.load("placeholder/tree.png")),
|
|
|
|
Name::new("Red"),
|
|
|
|
base_color: WHITE.into(),
|
|
|
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
})),
|
|
|
|
|
|
|
|
Transform::from_xyz(-15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0)),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Spawn placeholder tree (green)
|
|
|
|
// Spawn placeholder tree (green)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let tree_material_green = materials.add(StandardMaterial {
|
|
|
|
|
|
|
|
base_color_texture: Some(tree_image.clone()),
|
|
|
|
|
|
|
|
base_color: GREEN.into(),
|
|
|
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
let monologue: Handle<Monologue> = server.load("trees/green.mono");
|
|
|
|
|
|
|
|
let tree_transform_green =
|
|
|
|
|
|
|
|
Transform::from_xyz(15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0));
|
|
|
|
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
Tree,
|
|
|
|
Tree,
|
|
|
|
TreeMonologue(monologue),
|
|
|
|
TreeMonologue(server.load("trees/green.mono")),
|
|
|
|
Mesh3d(tree_card_mesh.clone()),
|
|
|
|
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
|
|
|
|
MeshMaterial3d(tree_material_green),
|
|
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
|
|
tree_transform_green,
|
|
|
|
base_color_texture: Some(server.load("placeholder/tree.png")),
|
|
|
|
Name::new("Green"),
|
|
|
|
base_color: WHITE.into(),
|
|
|
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
})),
|
|
|
|
|
|
|
|
Transform::from_xyz(15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0)),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Spawn placeholder tree (blue)
|
|
|
|
// Spawn placeholder tree (blue)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let tree_material_blue = materials.add(StandardMaterial {
|
|
|
|
|
|
|
|
base_color_texture: Some(tree_image.clone()),
|
|
|
|
|
|
|
|
base_color: BLUE.into(),
|
|
|
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
let monologue: Handle<Monologue> = server.load("trees/blue.mono");
|
|
|
|
|
|
|
|
let tree_transform_blue =
|
|
|
|
|
|
|
|
Transform::from_xyz(0.0, 0.0, -15.0).with_scale(Vec3::splat(10.0));
|
|
|
|
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
Tree,
|
|
|
|
Tree,
|
|
|
|
TreeMonologue(monologue),
|
|
|
|
TreeMonologue(server.load("trees/blue.mono")),
|
|
|
|
Mesh3d(tree_card_mesh.clone()),
|
|
|
|
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
|
|
|
|
MeshMaterial3d(tree_material_blue),
|
|
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
|
|
tree_transform_blue,
|
|
|
|
base_color_texture: Some(server.load("placeholder/tree.png")),
|
|
|
|
Name::new("Blue"),
|
|
|
|
base_color: WHITE.into(),
|
|
|
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
})),
|
|
|
|
|
|
|
|
Transform::from_xyz(0.0, 0.0, -15.0).with_scale(Vec3::splat(10.0)),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -252,9 +239,9 @@ fn start_dialog(
|
|
|
|
query: Query<&TreeMonologue>,
|
|
|
|
query: Query<&TreeMonologue>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
click_events.read().for_each(|event| {
|
|
|
|
click_events.read().for_each(|event| {
|
|
|
|
info!("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) {
|
|
|
|
info!("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(handle.clone()));
|
|
|
|
dialog_events.write(DialogEvent::NextBatch);
|
|
|
|
dialog_events.write(DialogEvent::NextBatch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -268,7 +255,7 @@ fn end_dialog(
|
|
|
|
query: Query<Entity, Or<(With<TreeMonologue>, With<DialogBox>, With<DialogOption>)>>,
|
|
|
|
query: Query<Entity, Or<(With<TreeMonologue>, With<DialogBox>, With<DialogOption>)>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
click_events.read().for_each(|event| {
|
|
|
|
click_events.read().for_each(|event| {
|
|
|
|
info!("Click even triggered end of dialog: {:?}", event.target);
|
|
|
|
debug!("Click even triggered end of dialog: {:?}", event.target);
|
|
|
|
if !query.contains(event.target) {
|
|
|
|
if !query.contains(event.target) {
|
|
|
|
dialog_events.write(DialogEvent::End);
|
|
|
|
dialog_events.write(DialogEvent::End);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -336,11 +323,14 @@ fn dialog_engine(
|
|
|
|
debug!("Dialog ended");
|
|
|
|
debug!("Dialog ended");
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the TreeMonologue component from the active tree
|
|
|
|
// Remove the TreeMonologue component from the active tree
|
|
|
|
monologue_trees.iter().filter_map(|(entity, tree_monologue)| {
|
|
|
|
monologue_trees
|
|
|
|
(*tree_monologue == TreeMonologue(handle.clone())).then_some(entity)
|
|
|
|
.iter()
|
|
|
|
}).for_each(|e| {
|
|
|
|
.filter_map(|(entity, tree_monologue)| {
|
|
|
|
commands.entity(e).remove::<TreeMonologue>();
|
|
|
|
(*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| {
|
|
|
|
@ -466,3 +456,32 @@ fn monologue_asset_tooltip(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn add_tree_monologue(
|
|
|
|
|
|
|
|
trigger: Trigger<OnAdd, TreeMonologue>,
|
|
|
|
|
|
|
|
query: Query<&MeshMaterial3d<StandardMaterial>>,
|
|
|
|
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// Get the affected entity's MeshMaterial3d
|
|
|
|
|
|
|
|
if let Ok(handle) = query.get(trigger.target()) {
|
|
|
|
|
|
|
|
// Get the concrete StandardMaterial
|
|
|
|
|
|
|
|
if let Some(material) = materials.get_mut(handle) {
|
|
|
|
|
|
|
|
material.base_color = WHITE.with_alpha(1.0).into();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn remove_tree_monologue(
|
|
|
|
|
|
|
|
trigger: Trigger<OnRemove, TreeMonologue>,
|
|
|
|
|
|
|
|
query: Query<&MeshMaterial3d<StandardMaterial>>,
|
|
|
|
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// Get the affected entity's MeshMaterial3d
|
|
|
|
|
|
|
|
if let Ok(handle) = query.get(trigger.target()) {
|
|
|
|
|
|
|
|
// Get the concrete StandardMaterial
|
|
|
|
|
|
|
|
if let Some(material) = materials.get_mut(handle) {
|
|
|
|
|
|
|
|
// Make it dull
|
|
|
|
|
|
|
|
material.base_color = WHITE.with_alpha(0.9).into();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|