|
|
|
|
@ -12,14 +12,22 @@ fn main() {
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
dialog_engine.run_if(input_just_pressed(KeyCode::KeyN)),
|
|
|
|
|
(
|
|
|
|
|
dialog_engine.run_if(input_just_pressed(KeyCode::KeyN)),
|
|
|
|
|
mouse_wheel_scroll.run_if(on_event::<MouseWheel>),
|
|
|
|
|
auto_scroll.run_if(any_component_added::<DialogOption>)
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Tree marker component
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct Tree;
|
|
|
|
|
|
|
|
|
|
/// 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>>,
|
|
|
|
|
@ -88,9 +96,11 @@ fn init_trees(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Dialog box marker component
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct DialogBox;
|
|
|
|
|
|
|
|
|
|
/// Initialize the UI which consists soley of a dialog box (for now?)
|
|
|
|
|
fn init_ui(mut commands: Commands) {
|
|
|
|
|
commands.spawn((
|
|
|
|
|
DialogBox,
|
|
|
|
|
@ -104,11 +114,15 @@ fn init_ui(mut commands: Commands) {
|
|
|
|
|
margin: UiRect::all(Val::Percent(1.0)),
|
|
|
|
|
padding: UiRect::all(Val::Percent(1.0)),
|
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
|
// Scroll on the Y axis
|
|
|
|
|
overflow: Overflow::scroll_y(),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// On startup move the camera to a suitable position
|
|
|
|
|
/// This should be mostly static for the entire game
|
|
|
|
|
fn position_camera(mut query: Query<&mut Transform, (With<Camera>, With<Camera3d>)>) {
|
|
|
|
|
use std::f32::consts::PI;
|
|
|
|
|
|
|
|
|
|
@ -118,12 +132,15 @@ fn position_camera(mut query: Query<&mut Transform, (With<Camera>, With<Camera3d
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A possible line of dialog the user can choose
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct DialogOption;
|
|
|
|
|
|
|
|
|
|
/// A line of dialog which has been chosen, so is permanent
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct DialogLine;
|
|
|
|
|
|
|
|
|
|
/// System which puts DialogOptions into the DialogBox
|
|
|
|
|
fn dialog_engine(
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
dialog_box: Single<Entity, With<DialogBox>>,
|
|
|
|
|
@ -152,6 +169,10 @@ fn dialog_engine(
|
|
|
|
|
*idx += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// When a dialog option is chosen (clicked on) we do the following:
|
|
|
|
|
/// 1. Remove the Button and DialogOption components from that entity
|
|
|
|
|
/// 2. Insert the DialogLine component to that entity
|
|
|
|
|
/// 3. Remove all other DialogOptions from the DialogBox
|
|
|
|
|
fn choose_dialog(trigger: Trigger<Pointer<Click>>, mut commands: Commands) {
|
|
|
|
|
info!("Choosing dialog {:?}", trigger.target());
|
|
|
|
|
commands
|
|
|
|
|
@ -160,3 +181,31 @@ fn choose_dialog(trigger: Trigger<Pointer<Click>>, mut commands: Commands) {
|
|
|
|
|
.remove::<DialogOption>()
|
|
|
|
|
.insert(DialogLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Allows user to scroll (with mouse whell) through old dialog
|
|
|
|
|
fn mouse_wheel_scroll(
|
|
|
|
|
mut events: EventReader<MouseWheel>,
|
|
|
|
|
mut scroll_position: Query<&mut ScrollPosition>,
|
|
|
|
|
) {
|
|
|
|
|
events.read().for_each(|MouseWheel { unit, y, .. }| {
|
|
|
|
|
let offset_y = match unit {
|
|
|
|
|
MouseScrollUnit::Line => 10.0 * y,
|
|
|
|
|
MouseScrollUnit::Pixel => 1.0 * y,
|
|
|
|
|
};
|
|
|
|
|
scroll_position
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.for_each(|mut pos| pos.offset_y += offset_y);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Automatically scrolls dialog when a new batch of options are added
|
|
|
|
|
fn auto_scroll(
|
|
|
|
|
added: Query<Entity, Added<DialogOption>>,
|
|
|
|
|
mut scroll_positions: Query<&mut ScrollPosition>,
|
|
|
|
|
) {
|
|
|
|
|
debug_assert!(!added.is_empty(), "Should only scroll when dialog options are added");
|
|
|
|
|
|
|
|
|
|
scroll_positions.iter_mut().for_each(|mut sp| {
|
|
|
|
|
sp.offset_y = f32::MAX;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|