Stableish before title bar rework

main
Elijah Voigt 2 years ago
parent 0d374dc45e
commit b26517e721

@ -35,7 +35,6 @@ use bevy::{
asset::{Asset, Assets}, asset::{Asset, Assets},
asset::{AssetLoader, LoadContext, LoadedAsset}, asset::{AssetLoader, LoadContext, LoadedAsset},
audio::PlaybackMode, audio::PlaybackMode,
ecs::system::EntityCommands,
gltf::Gltf, gltf::Gltf,
prelude::*, prelude::*,
utils::BoxedFuture, utils::BoxedFuture,
@ -101,18 +100,12 @@ pub struct TabRoot;
#[derive(Debug, Component)] #[derive(Debug, Component)]
pub struct LevelRoot; pub struct LevelRoot;
#[derive(Debug, Component)]
pub enum Minimize {
Open,
Closed,
}
#[derive(Debug, Component)] #[derive(Debug, Component)]
pub struct EditorCamera; pub struct EditorCamera;
fn initialize_ui(mut commands: Commands) { fn initialize_ui(mut commands: Commands) {
// Empty entity for populating the level being edited // Empty entity for populating the level being edited
commands.spawn(LevelRoot); commands.spawn((TransformBundle { ..default() }, LevelRoot));
commands.spawn(( commands.spawn((
Camera3dBundle { ..default() }, Camera3dBundle { ..default() },
@ -130,7 +123,7 @@ fn initialize_ui(mut commands: Commands) {
}; };
commands commands
.spawn(NodeBundle { .spawn((NodeBundle {
style: Style { style: Style {
border: UiRect::all(Val::Px(1.0)), border: UiRect::all(Val::Px(1.0)),
margin: UiRect::all(Val::Px(5.0)), margin: UiRect::all(Val::Px(5.0)),
@ -142,7 +135,7 @@ fn initialize_ui(mut commands: Commands) {
background_color: Color::WHITE.into(), background_color: Color::WHITE.into(),
border_color: Color::BLACK.into(), border_color: Color::BLACK.into(),
..default() ..default()
}) },))
.with_children(|parent| { .with_children(|parent| {
// HACK: This is super janky but I think we need it like this for UI layout rules // HACK: This is super janky but I think we need it like this for UI layout rules
let mut content_containers: Vec<(String, Entity)> = Vec::new(); let mut content_containers: Vec<(String, Entity)> = Vec::new();
@ -171,31 +164,37 @@ fn initialize_ui(mut commands: Commands) {
"Font", "Font",
parent, parent,
&base_style, &base_style,
ui::Select::Single,
)); ));
content_containers.push(spawn_tab_container::<AudioWidget>( content_containers.push(spawn_tab_container::<AudioWidget>(
"Audio", "Audio",
parent, parent,
&base_style, &base_style,
ui::Select::Multi,
)); ));
content_containers.push(spawn_tab_container::<GltfWidget>( content_containers.push(spawn_tab_container::<GltfWidget>(
"Gltf", "Gltf",
parent, parent,
&base_style, &base_style,
ui::Select::Single,
)); ));
content_containers.push(spawn_tab_container::<SceneWidget>( content_containers.push(spawn_tab_container::<SceneWidget>(
"Scene", "Scene",
parent, parent,
&base_style, &base_style,
ui::Select::Single,
)); ));
content_containers.push(spawn_tab_container::<AnimationWidget>( content_containers.push(spawn_tab_container::<AnimationWidget>(
"Animation", "Animation",
parent, parent,
&base_style, &base_style,
ui::Select::Multi,
)); ));
content_containers.push(spawn_tab_container::<CameraWidget>( content_containers.push(spawn_tab_container::<CameraWidget>(
"Camera", "Camera",
parent, parent,
&base_style, &base_style,
ui::Select::Single,
)); ));
}); });
@ -216,6 +215,7 @@ fn initialize_ui(mut commands: Commands) {
..default() ..default()
}, },
ui::Sorting(1), ui::Sorting(1),
ui::Select::Single,
)) ))
.with_children(|parent| { .with_children(|parent| {
let b = ButtonBundle { let b = ButtonBundle {
@ -244,6 +244,7 @@ fn spawn_tab_container<T: Default + Component>(
title: &'static str, title: &'static str,
parent: &mut ChildBuilder, parent: &mut ChildBuilder,
base_style: &Style, base_style: &Style,
select: ui::Select,
) -> (String, Entity) { ) -> (String, Entity) {
( (
title.into(), title.into(),
@ -267,6 +268,7 @@ fn spawn_tab_container<T: Default + Component>(
T::default(), T::default(),
ui::Scroll, ui::Scroll,
Interaction::default(), Interaction::default(),
select,
)) ))
.id(), .id(),
) )
@ -567,28 +569,19 @@ mod gltf {
pub fn manage_active_gltf( pub fn manage_active_gltf(
events: Query< events: Query<
(Entity, &Parent, &Interaction, Option<&ui::Active>), (Entity, &Interaction, Option<&ui::Active>),
(With<Button>, Changed<Interaction>), (With<Button>, Changed<Interaction>),
>, >,
children: Query<&Children, With<ui::Active>>,
mut commands: Commands, mut commands: Commands,
) { ) {
events events
.iter() .iter()
.filter(|(_, _, &interaction, _)| interaction == Interaction::Pressed) .filter(|(_, &interaction, _)| interaction == Interaction::Pressed)
.for_each(|(entity, parent, _, active_ish)| match active_ish { .for_each(|(entity, _, active_ish)| match active_ish {
Some(_) => { Some(_) => {
commands.entity(entity).remove::<ui::Active>(); commands.entity(entity).remove::<ui::Active>();
} }
None => { None => {
if let Ok(childs) = children.get(parent.get()) {
childs
.iter()
.filter(|&child| *child != entity)
.for_each(|&child| {
commands.entity(child).remove::<ui::Active>();
});
}
commands.entity(entity).insert(ui::Active); commands.entity(entity).insert(ui::Active);
} }
}); });
@ -934,12 +927,12 @@ mod monologues {
// TODO: Load .txt files for monologues // TODO: Load .txt files for monologues
pub fn texts_ui( pub fn texts_ui(
mut events: EventReader<AssetEvent<Monologue>>, mut events: EventReader<AssetEvent<Monologue>>,
mut commands: Commands, mut _commands: Commands,
widget: Query<Entity, With<MonologueWidget>>, _widget: Query<Entity, With<MonologueWidget>>,
current: Query<(Entity, &ui::TargetAsset<Monologue>)>, _current: Query<(Entity, &ui::TargetAsset<Monologue>)>,
server: Res<AssetServer>, _server: Res<AssetServer>,
) { ) {
events.iter().for_each(|event| { events.iter().for_each(|_event| {
info!("Loading monologue"); info!("Loading monologue");
}) })
} }

@ -1,14 +1,11 @@
/// TODO: /// TODO:
/// * Text box w/ clear button /// * Text box w/ "reset" button
/// * Button color management
/// * Move code to submodules
/// * Generic Minimize/Close Components /// * Generic Minimize/Close Components
/// * Title bar w/ min/close controls
/// * Notice/Warning/Error Popups /// * Notice/Warning/Error Popups
/// * Textbox (ReadOnly) /// * Textbox (ReadOnly)
/// * Textbox (ReadWrite) /// * Textbox (ReadWrite)
/// /// * Move code to submodules
/// BUGS:
/// * Active::Multi (ex: Audio) vs Active::Single (ex: Assets, Gltf) for different tabs
/// ///
use bevy::{ use bevy::{
asset::Asset, asset::Asset,
@ -37,6 +34,7 @@ impl Plugin for GameUiPlugin {
( (
init_titles, init_titles,
manage_button_interaction, manage_button_interaction,
manage_select_active,
manage_cursor, manage_cursor,
manage_scroll, manage_scroll,
manage_collapse_active, manage_collapse_active,
@ -67,33 +65,49 @@ mod title {
.entity(entity) .entity(entity)
.despawn_descendants() .despawn_descendants()
.with_children(|parent| { .with_children(|parent| {
parent.spawn(TextBundle { parent
text: Text { .spawn((
sections: vec![ NodeBundle {
TextSection { style: Style {
value: name.clone(), padding: UiRect::all(Val::Px(5.0)),
style: TextStyle { margin: UiRect::all(Val::Px(5.0)),
color: Color::BLACK, border: UiRect::all(Val::Px(1.0)),
..default() flex_direction: FlexDirection::Row,
}, ..default()
}, },
TextSection { ..default()
value: note.clone().unwrap_or(String::new()), },
style: TextStyle { Sorting(0),
color: Color::BLACK, ))
..default() .with_children(|parent| {
}, parent.spawn(TextBundle {
text: Text {
sections: vec![
TextSection {
value: name.clone(),
style: TextStyle {
color: Color::BLACK,
..default()
},
},
TextSection {
value: note.clone().unwrap_or(String::new()),
style: TextStyle {
color: Color::BLACK,
..default()
},
},
],
..default()
}, },
], style: Style {
..default() margin: UiRect::all(Val::Px(5.0)),
}, padding: UiRect::all(Val::Px(5.0)),
style: Style { ..default()
margin: UiRect::all(Val::Px(5.0)), },
padding: UiRect::all(Val::Px(5.0)), ..default()
..default() });
}, });
..default()
});
}); });
}); });
} }
@ -110,27 +124,20 @@ mod collapse {
pub fn manage_collapse_active( pub fn manage_collapse_active(
events: Query< events: Query<
(Entity, Option<&Active>, &Parent, &Interaction), (Entity, Option<&Active>, &Interaction),
(Changed<Interaction>, With<Button>, With<Collapse>), (Changed<Interaction>, With<Button>, With<Collapse>),
>, >,
mut commands: Commands, mut commands: Commands,
active_children: Query<&Children>,
) { ) {
events events
.iter() .iter()
.filter(|(_, _, _, &interaction)| interaction == Interaction::Pressed) .filter(|(_, _, &interaction)| interaction == Interaction::Pressed)
.for_each(|(entity, active, parent, _)| { .for_each(|(entity, active, _)| {
match active { match active {
Some(_) => { Some(_) => {
commands.entity(entity).remove::<Active>(); commands.entity(entity).remove::<Active>();
} }
None => { None => {
// Set all other buttons to inactive
if let Ok(children) = active_children.get(parent.get()) {
children.iter().for_each(|child| {
commands.entity(*child).remove::<Active>();
});
}
// Set this butotn to active // Set this butotn to active
commands.entity(entity).insert(Active); commands.entity(entity).insert(Active);
} }
@ -228,6 +235,35 @@ mod buttons {
} }
}) })
} }
/// Marks a container node as having single- or multi-active components
#[derive(Debug, Component)]
pub enum Select {
Multi,
Single,
}
pub fn manage_select_active(
events: Query<(Entity, &Parent), Added<Active>>,
children: Query<(&Select, &Children)>,
mut commands: Commands,
) {
events.iter().for_each(|(entity, parent)| {
if let Ok((select, childs)) = children.get(parent.get()) {
match select {
Select::Single => {
childs
.iter()
.filter(|&child| *child != entity)
.for_each(|&child| {
commands.entity(child).remove::<Active>();
})
}
Select::Multi => (),
}
}
});
}
} }
pub use scroll::*; pub use scroll::*;
@ -318,7 +354,6 @@ mod sort {
} else if ord_a < ord_b { } else if ord_a < ord_b {
Ordering::Less Ordering::Less
} else { } else {
info!("Equal");
Ordering::Equal Ordering::Equal
} }
} }

Loading…
Cancel
Save