diff --git a/Cargo.lock b/Cargo.lock index e1810b2..3cc04c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2226,6 +2226,7 @@ dependencies = [ "bevy", "bevy_rapier3d", "chrono", + "lipsum", "serde", "thiserror 2.0.12", "walkdir", @@ -2780,6 +2781,16 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" +[[package]] +name = "lipsum" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "636860251af8963cc40f6b4baadee105f02e21b28131d76eba8e40ce84ab8064" +dependencies = [ + "rand", + "rand_chacha", +] + [[package]] name = "litrs" version = "0.4.1" diff --git a/Cargo.toml b/Cargo.toml index 6e4a8b0..01f8fe5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,9 +17,9 @@ version = "0.30.0" version = "0.16.1" features = ["wayland", "dynamic_linking"] +[dev-dependencies] +lipsum = "*" + [build-dependencies] chrono = "*" walkdir = "*" - -# [hints] -# mostly-unused = true diff --git a/examples/ui.rs b/examples/ui.rs index a62faa6..ec1ba88 100644 --- a/examples/ui.rs +++ b/examples/ui.rs @@ -5,8 +5,7 @@ use games::*; fn main() { let mut app = App::new(); app.add_plugins(BaseGamePlugin::default()) - .add_systems(Startup, (setup_list, setup_nav_tree)) - .add_systems(Update, run_tree.run_if(any_component_changed::)); + .add_systems(Startup, (setup_list, setup_nav_tree)); app.run(); } @@ -40,62 +39,36 @@ fn setup_nav_tree(mut commands: Commands) { Node { position_type: PositionType::Absolute, right: Val::Px(0.0), - width: Val::Px(100.0), - height: Val::Px(100.0), + top: Val::Percent(50.0), + min_width: Val::Px(25.0), + min_height: Val::Px(25.0), ..default() }, BackgroundColor(RED.into()), - NavTree::Closed, )) .with_children(|parent| { parent .spawn(( Node { position_type: PositionType::Absolute, - right: Val::Px(100.0), - width: Val::Px(100.0), - height: Val::Px(100.0), + right: Val::Px(25.0), + min_width: Val::Px(25.0), + min_height: Val::Px(25.0), ..default() }, BackgroundColor(ORANGE.into()), - NavTree::Closed, )) .with_children(|parent| { parent.spawn(( Node { position_type: PositionType::Absolute, - right: Val::Px(100.0), - width: Val::Px(100.0), - height: Val::Px(100.0), + right: Val::Px(25.0), + min_width: Val::Px(25.0), + min_height: Val::Px(25.0), ..default() }, BackgroundColor(YELLOW.into()), - NavTree::Closed, )); }); }); } - -fn run_tree( - q: Query<(Entity, &NavTree), Changed>, - children: Query<&Children>, - mut query: Query<(&ChildOf, &mut Visibility)>, -) { - q.iter().for_each(|(e, nav)| { - // todo!("Clean this code up please!"); - match nav { - NavTree::Open => children.iter_descendants(e).for_each(|child| { - let (co, mut v) = query.get_mut(child).unwrap(); - if ChildOf(e) == *co { - *v = Visibility::Inherited; - } - }), - NavTree::Closed => children.iter_descendants(e).for_each(|child| { - let (co, mut v) = query.get_mut(child).unwrap(); - if ChildOf(e) == *co { - *v = Visibility::Hidden; - } - }), - } - }); -} diff --git a/src/bin/trees/main.rs b/src/bin/trees/main.rs index 295a502..cd17703 100644 --- a/src/bin/trees/main.rs +++ b/src/bin/trees/main.rs @@ -56,6 +56,8 @@ fn main() { .add_observer(remove_tree_monologue) .add_observer(hide_monologue_preview) .add_observer(populate_tree) + .add_observer(show_monologue_list) + .add_observer(hide_monologue_list) .run(); } @@ -119,13 +121,14 @@ fn init_debug_ui(mut commands: Commands) { commands .spawn(( Node { - height: Val::Percent(90.0), + max_height: Val::Percent(90.0), align_self: AlignSelf::Center, justify_self: JustifySelf::Start, ..default() }, MonologuesContainer, GlobalZIndex(i32::MAX - 1), + BackgroundColor(PINK.into()), DebuggingState::On, )) .with_children(|parent| { @@ -134,6 +137,7 @@ fn init_debug_ui(mut commands: Commands) { height: Val::Percent(100.0), flex_direction: FlexDirection::Column, padding: UiRect::all(Val::Px(10.0)), + overflow: Overflow::scroll_y(), ..default() }, BackgroundColor(PINK.with_alpha(0.9).into()), @@ -144,6 +148,7 @@ fn init_debug_ui(mut commands: Commands) { height: Val::Percent(100.0), flex_direction: FlexDirection::Column, padding: UiRect::all(Val::Px(10.0)), + overflow: Overflow::scroll_y(), ..default() }, BackgroundColor(ORANGE.with_alpha(0.9).into()), @@ -623,6 +628,32 @@ fn preview_monologue( } } +fn show_monologue_list( + trigger: Trigger>, + container: Query>, + children: Query<&Children>, + mut visibility: Query<&mut Visibility>, +) { + if let Ok(root) = container.get(trigger.target()) { + children.iter_descendants(root).for_each(|e| { + *visibility.get_mut(e).unwrap() = Visibility::Inherited; + }); + } +} + +fn hide_monologue_list( + trigger: Trigger>, + container: Query>, + children: Query<&Children>, + mut visibility: Query<&mut Visibility>, +) { + if let Ok(root) = container.get(trigger.target()) { + children.iter_descendants(root).for_each(|e| { + *visibility.get_mut(e).unwrap() = Visibility::Hidden; + }); + } +} + fn spawn_monologue_tree( trigger: Trigger>, tree_monologues: Query<&TreeMonologue, With