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

@ -1,14 +1,11 @@
/// TODO:
/// * Text box w/ clear button
/// * Button color management
/// * Move code to submodules
/// * Text box w/ "reset" button
/// * Generic Minimize/Close Components
/// * Title bar w/ min/close controls
/// * Notice/Warning/Error Popups
/// * Textbox (ReadOnly)
/// * Textbox (ReadWrite)
///
/// BUGS:
/// * Active::Multi (ex: Audio) vs Active::Single (ex: Assets, Gltf) for different tabs
/// * Move code to submodules
///
use bevy::{
asset::Asset,
@ -37,6 +34,7 @@ impl Plugin for GameUiPlugin {
(
init_titles,
manage_button_interaction,
manage_select_active,
manage_cursor,
manage_scroll,
manage_collapse_active,
@ -66,6 +64,21 @@ mod title {
commands
.entity(entity)
.despawn_descendants()
.with_children(|parent| {
parent
.spawn((
NodeBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
border: UiRect::all(Val::Px(1.0)),
flex_direction: FlexDirection::Row,
..default()
},
..default()
},
Sorting(0),
))
.with_children(|parent| {
parent.spawn(TextBundle {
text: Text {
@ -96,6 +109,7 @@ mod title {
});
});
});
});
}
}
@ -110,27 +124,20 @@ mod collapse {
pub fn manage_collapse_active(
events: Query<
(Entity, Option<&Active>, &Parent, &Interaction),
(Entity, Option<&Active>, &Interaction),
(Changed<Interaction>, With<Button>, With<Collapse>),
>,
mut commands: Commands,
active_children: Query<&Children>,
) {
events
.iter()
.filter(|(_, _, _, &interaction)| interaction == Interaction::Pressed)
.for_each(|(entity, active, parent, _)| {
.filter(|(_, _, &interaction)| interaction == Interaction::Pressed)
.for_each(|(entity, active, _)| {
match active {
Some(_) => {
commands.entity(entity).remove::<Active>();
}
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
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::*;
@ -318,7 +354,6 @@ mod sort {
} else if ord_a < ord_b {
Ordering::Less
} else {
info!("Equal");
Ordering::Equal
}
}

Loading…
Cancel
Save