|
|
|
|
@ -61,77 +61,15 @@ fn main() {
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct Tree;
|
|
|
|
|
|
|
|
|
|
#[derive(Component, PartialEq)]
|
|
|
|
|
#[derive(Component, PartialEq, Clone)]
|
|
|
|
|
struct TreeMonologue(Handle<Monologue>);
|
|
|
|
|
|
|
|
|
|
/// Initialize the trees, currently placeholders
|
|
|
|
|
/// Trees are 2d cards in a 3d world for flexibility
|
|
|
|
|
/// Might move fully 2d if the art style allows it
|
|
|
|
|
fn init_trees(
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
mut ambient_light: ResMut<AmbientLight>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
fn init_trees(mut ambient_light: ResMut<AmbientLight>) {
|
|
|
|
|
// Global light
|
|
|
|
|
{
|
|
|
|
|
ambient_light.brightness = 500.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Spawn placeholder tree (red)
|
|
|
|
|
{
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
Tree,
|
|
|
|
|
TreeMonologue(server.load("trees/red.mono")),
|
|
|
|
|
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
|
|
|
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
|
|
|
base_color_texture: Some(server.load("placeholder/tree.png")),
|
|
|
|
|
base_color: WHITE.into(),
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
..default()
|
|
|
|
|
})),
|
|
|
|
|
Transform::from_xyz(-15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0)),
|
|
|
|
|
))
|
|
|
|
|
.observe(delete_tree);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Spawn placeholder tree (green)
|
|
|
|
|
{
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
Tree,
|
|
|
|
|
TreeMonologue(server.load("trees/green.mono")),
|
|
|
|
|
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
|
|
|
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
|
|
|
base_color_texture: Some(server.load("placeholder/tree.png")),
|
|
|
|
|
base_color: WHITE.into(),
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
..default()
|
|
|
|
|
})),
|
|
|
|
|
Transform::from_xyz(15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0)),
|
|
|
|
|
))
|
|
|
|
|
.observe(delete_tree);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Spawn placeholder tree (blue)
|
|
|
|
|
{
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
Tree,
|
|
|
|
|
TreeMonologue(server.load("trees/blue.mono")),
|
|
|
|
|
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
|
|
|
|
|
MeshMaterial3d(materials.add(StandardMaterial {
|
|
|
|
|
base_color_texture: Some(server.load("placeholder/tree.png")),
|
|
|
|
|
base_color: WHITE.into(),
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
..default()
|
|
|
|
|
})),
|
|
|
|
|
Transform::from_xyz(0.0, 0.0, -15.0).with_scale(Vec3::splat(10.0)),
|
|
|
|
|
))
|
|
|
|
|
.observe(delete_tree);
|
|
|
|
|
}
|
|
|
|
|
ambient_light.brightness = 500.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Dialog box marker component
|
|
|
|
|
@ -184,7 +122,6 @@ fn init_debug_ui(mut commands: Commands) {
|
|
|
|
|
justify_self: JustifySelf::Start,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
BackgroundColor(GREEN.into()),
|
|
|
|
|
MonologuesContainer,
|
|
|
|
|
GlobalZIndex(i32::MAX - 1),
|
|
|
|
|
DebuggingState::On,
|
|
|
|
|
@ -197,7 +134,7 @@ fn init_debug_ui(mut commands: Commands) {
|
|
|
|
|
padding: UiRect::all(Val::Px(10.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
BackgroundColor(PINK.into()),
|
|
|
|
|
BackgroundColor(PINK.with_alpha(0.5).into()),
|
|
|
|
|
MonologuesList,
|
|
|
|
|
));
|
|
|
|
|
parent.spawn((
|
|
|
|
|
@ -207,7 +144,7 @@ fn init_debug_ui(mut commands: Commands) {
|
|
|
|
|
padding: UiRect::all(Val::Px(10.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
BackgroundColor(ORANGE.into()),
|
|
|
|
|
BackgroundColor(ORANGE.with_alpha(0.5).into()),
|
|
|
|
|
MonologuePreview,
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
@ -305,7 +242,7 @@ enum DialogState {
|
|
|
|
|
fn start_dialog(
|
|
|
|
|
mut click_events: EventReader<Pointer<Click>>,
|
|
|
|
|
mut dialog_events: EventWriter<DialogEvent>,
|
|
|
|
|
query: Query<&TreeMonologue>,
|
|
|
|
|
query: Query<&TreeMonologue, With<Tree>>,
|
|
|
|
|
) {
|
|
|
|
|
click_events.read().for_each(|event| {
|
|
|
|
|
debug!("Click event detected");
|
|
|
|
|
@ -348,7 +285,7 @@ fn dialog_engine(
|
|
|
|
|
// Monologue assets for obvious reasons
|
|
|
|
|
monologues: Res<Assets<Monologue>>,
|
|
|
|
|
// Monologue trees so we can remove that component at end of monologue
|
|
|
|
|
monologue_trees: Query<(Entity, &TreeMonologue)>,
|
|
|
|
|
monologue_trees: Query<(Entity, &TreeMonologue), With<Tree>>,
|
|
|
|
|
// Dialog lines to despawn them at the end/start of a dialog
|
|
|
|
|
lines: Query<Entity, With<DialogLine>>,
|
|
|
|
|
) {
|
|
|
|
|
@ -508,7 +445,7 @@ fn monologue_asset_tooltip(
|
|
|
|
|
mut over_events: EventReader<Pointer<Over>>,
|
|
|
|
|
mut out_events: EventReader<Pointer<Out>>,
|
|
|
|
|
mut tooltip: ResMut<ToolTip>,
|
|
|
|
|
scripts: Query<&TreeMonologue>,
|
|
|
|
|
scripts: Query<&TreeMonologue, With<Button>>,
|
|
|
|
|
) {
|
|
|
|
|
out_events
|
|
|
|
|
.read()
|
|
|
|
|
@ -684,8 +621,54 @@ fn preview_monologue(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn spawn_monologue_tree(trigger: Trigger<Pointer<Click>>, mut commands: Commands) {
|
|
|
|
|
// todo!("Spawn monologue tree when button is clicked")
|
|
|
|
|
fn spawn_monologue_tree(
|
|
|
|
|
trigger: Trigger<Pointer<Click>>,
|
|
|
|
|
tree_monologues: Query<&TreeMonologue, With<Button>>,
|
|
|
|
|
trees: Query<Entity, With<Tree>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let tree_monologue = tree_monologues.get(trigger.target()).unwrap();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Generate "random" X and Y Coordinates for this tree
|
|
|
|
|
// 1. Take the top 2 bytes
|
|
|
|
|
// 2. Interpet as u8s
|
|
|
|
|
// 3. Re-interpret as i8s
|
|
|
|
|
// 4. Cast to f32
|
|
|
|
|
let transform = {
|
|
|
|
|
let [a, b, c, d] = time.elapsed().as_secs_f32().to_be_bytes();
|
|
|
|
|
info!("Time bits: {a} {b} {c} {d}");
|
|
|
|
|
let x = c as i8 / 4;
|
|
|
|
|
let y = d as i8 / 4;
|
|
|
|
|
// Avoid mesh clipping by offsetting each on the z axis
|
|
|
|
|
let z = trees.iter().len() as f32;
|
|
|
|
|
info!("Coordiantes: {x} {y}");
|
|
|
|
|
Transform::from_xyz(x.into(), z, y.into()).with_scale(Vec3::splat(10.0))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let material = MeshMaterial3d(materials.add(StandardMaterial {
|
|
|
|
|
base_color_texture: Some(server.load("placeholder/tree.png")),
|
|
|
|
|
base_color: WHITE.into(),
|
|
|
|
|
alpha_mode: AlphaMode::Blend,
|
|
|
|
|
..default()
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
let mesh = Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0))));
|
|
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
Tree,
|
|
|
|
|
mesh,
|
|
|
|
|
material,
|
|
|
|
|
tree_monologue.clone(),
|
|
|
|
|
transform
|
|
|
|
|
))
|
|
|
|
|
.observe(delete_tree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn hide_monologue_preview(
|
|
|
|
|
|