Starting on the most basic trees implementation
Also: * Track files with git-lfs (png, xcf) * Debugger tooltip for UI elements * Make tooltip render above everything elsemain
parent
c14f2484e6
commit
04777a4e33
@ -0,0 +1,2 @@
|
|||||||
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xcf filter=lfs diff=lfs merge=lfs -text
|
||||||
Binary file not shown.
Binary file not shown.
@ -1,7 +1,5 @@
|
|||||||
use games::*;
|
use games::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new().add_plugins(BaseGamePlugin).run();
|
||||||
.add_plugins(BaseGamePlugin)
|
|
||||||
.run();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
use games::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new().add_plugins(BaseGamePlugin).run();
|
||||||
|
}
|
||||||
@ -0,0 +1,162 @@
|
|||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
|
use games::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
.add_plugins(BaseGamePlugin)
|
||||||
|
.insert_resource(ClearColor(WHITE.into()))
|
||||||
|
.add_systems(
|
||||||
|
Startup,
|
||||||
|
(init_trees, init_ui, position_camera.after(setup_camera)),
|
||||||
|
)
|
||||||
|
.add_systems(
|
||||||
|
Update,
|
||||||
|
dialog_engine.run_if(input_just_pressed(KeyCode::KeyN)),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Tree;
|
||||||
|
|
||||||
|
fn init_trees(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
server: Res<AssetServer>,
|
||||||
|
) {
|
||||||
|
let tree_card_mesh = meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)));
|
||||||
|
|
||||||
|
let tree_image = server.load("placeholder/tree.png");
|
||||||
|
|
||||||
|
// 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 tree_transform_red =
|
||||||
|
Transform::from_xyz(-15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0));
|
||||||
|
commands.spawn((
|
||||||
|
Tree,
|
||||||
|
Mesh3d(tree_card_mesh.clone()),
|
||||||
|
MeshMaterial3d(tree_material_red),
|
||||||
|
tree_transform_red,
|
||||||
|
Name::new("Red"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 tree_transform_green =
|
||||||
|
Transform::from_xyz(15.0, 0.0, 15.0).with_scale(Vec3::splat(10.0));
|
||||||
|
commands.spawn((
|
||||||
|
Tree,
|
||||||
|
Mesh3d(tree_card_mesh.clone()),
|
||||||
|
MeshMaterial3d(tree_material_green),
|
||||||
|
tree_transform_green,
|
||||||
|
Name::new("Green"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 tree_transform_blue =
|
||||||
|
Transform::from_xyz(0.0, 0.0, -15.0).with_scale(Vec3::splat(10.0));
|
||||||
|
commands.spawn((
|
||||||
|
Tree,
|
||||||
|
Mesh3d(tree_card_mesh.clone()),
|
||||||
|
MeshMaterial3d(tree_material_blue),
|
||||||
|
tree_transform_blue,
|
||||||
|
Name::new("Blue"),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct DialogBox;
|
||||||
|
|
||||||
|
fn init_ui(mut commands: Commands) {
|
||||||
|
commands.spawn((
|
||||||
|
DialogBox,
|
||||||
|
BackgroundColor(BLACK.with_alpha(0.9).into()),
|
||||||
|
Node {
|
||||||
|
align_self: AlignSelf::End,
|
||||||
|
justify_self: JustifySelf::Center,
|
||||||
|
width: Val::Percent(98.0),
|
||||||
|
max_height: Val::Percent(25.0),
|
||||||
|
align_items: AlignItems::Center,
|
||||||
|
margin: UiRect::all(Val::Percent(1.0)),
|
||||||
|
padding: UiRect::all(Val::Percent(1.0)),
|
||||||
|
flex_direction: FlexDirection::Column,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn position_camera(mut query: Query<&mut Transform, (With<Camera>, With<Camera3d>)>) {
|
||||||
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
query.iter_mut().for_each(|mut t| {
|
||||||
|
*t = Transform::from_xyz(0.0, 100.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y);
|
||||||
|
t.rotate_y(-PI * 0.5)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct DialogOption;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct DialogLine;
|
||||||
|
|
||||||
|
fn dialog_engine(
|
||||||
|
mut commands: Commands,
|
||||||
|
dialog_box: Single<Entity, With<DialogBox>>,
|
||||||
|
mut idx: Local<usize>,
|
||||||
|
) {
|
||||||
|
let dialog: Vec<Vec<&str>> = vec![
|
||||||
|
vec!["A", "B", "C"],
|
||||||
|
vec!["E", "F", "G"],
|
||||||
|
vec!["H", "I"],
|
||||||
|
vec!["J", "K"],
|
||||||
|
vec!["L"],
|
||||||
|
];
|
||||||
|
|
||||||
|
info!("Show options: {:?}", dialog.get(*idx));
|
||||||
|
|
||||||
|
commands.entity(*dialog_box).with_children(|parent| {
|
||||||
|
if let Some(options) = dialog.get(*idx) {
|
||||||
|
options.iter().for_each(|option| {
|
||||||
|
parent
|
||||||
|
.spawn((Text::new(*option), Button, DialogOption))
|
||||||
|
.observe(choose_dialog);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
*idx += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn choose_dialog(trigger: Trigger<Pointer<Click>>, mut commands: Commands) {
|
||||||
|
info!("Choosing dialog {:?}", trigger.target());
|
||||||
|
commands
|
||||||
|
.entity(trigger.target())
|
||||||
|
.remove::<Button>()
|
||||||
|
.remove::<DialogOption>()
|
||||||
|
.insert(DialogLine);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue