|
|
|
|
@ -33,12 +33,13 @@ impl Plugin for GameUiPlugin {
|
|
|
|
|
Update,
|
|
|
|
|
(
|
|
|
|
|
init_titles,
|
|
|
|
|
manage_titles,
|
|
|
|
|
manage_button_interaction,
|
|
|
|
|
manage_select_active,
|
|
|
|
|
manage_cursor,
|
|
|
|
|
manage_scroll,
|
|
|
|
|
manage_collapse_active,
|
|
|
|
|
manage_collapse_hiding,
|
|
|
|
|
manage_collapse_active,
|
|
|
|
|
show_child_number,
|
|
|
|
|
manage_sort,
|
|
|
|
|
),
|
|
|
|
|
@ -50,48 +51,48 @@ pub use title::*;
|
|
|
|
|
mod title {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component, Default)]
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct Title {
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub note: Option<String>,
|
|
|
|
|
pub text: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct Note {
|
|
|
|
|
pub text: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct TitleText;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct Minimize {
|
|
|
|
|
pub target: Entity,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn init_titles(
|
|
|
|
|
events: Query<(Entity, &Title), Or<(Changed<Title>, Added<Title>)>>,
|
|
|
|
|
events: Query<(Entity, &Title, Option<&Note>, Option<&Minimize>), Added<Title>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
events.for_each(|(entity, Title { name, note })| {
|
|
|
|
|
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 {
|
|
|
|
|
events.for_each(|(entity, title, note, minimize)| {
|
|
|
|
|
commands.entity(entity).with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
TextBundle {
|
|
|
|
|
text: Text {
|
|
|
|
|
sections: vec![
|
|
|
|
|
TextSection {
|
|
|
|
|
value: name.clone(),
|
|
|
|
|
value: title.text.clone(),
|
|
|
|
|
style: TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
TextSection {
|
|
|
|
|
value: note.clone().unwrap_or(String::new()),
|
|
|
|
|
value: note
|
|
|
|
|
.unwrap_or(&Note {
|
|
|
|
|
text: String::new(),
|
|
|
|
|
})
|
|
|
|
|
.text
|
|
|
|
|
.clone(),
|
|
|
|
|
style: TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
..default()
|
|
|
|
|
@ -106,11 +107,68 @@ mod title {
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
Sorting(0),
|
|
|
|
|
TitleText,
|
|
|
|
|
));
|
|
|
|
|
if let Some(target) = minimize {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
border: UiRect::all(Val::Px(1.0)),
|
|
|
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
right: Val::Px(0.0),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::WHITE.into(),
|
|
|
|
|
border_color: Color::BLACK.into(),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
Collapse {
|
|
|
|
|
target: target.target,
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn manage_titles(
|
|
|
|
|
events: Query<(&Title, Option<&Note>, &Children), Changed<Title>>,
|
|
|
|
|
mut texts: Query<&mut Text, With<TitleText>>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|(title, note, children)| {
|
|
|
|
|
children.iter().for_each(|child| {
|
|
|
|
|
if let Ok(mut text) = texts.get_mut(*child) {
|
|
|
|
|
*text = Text {
|
|
|
|
|
sections: vec![
|
|
|
|
|
TextSection {
|
|
|
|
|
value: title.text.clone(),
|
|
|
|
|
style: TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
TextSection {
|
|
|
|
|
value: note
|
|
|
|
|
.unwrap_or(&Note {
|
|
|
|
|
text: String::new(),
|
|
|
|
|
})
|
|
|
|
|
.text
|
|
|
|
|
.clone(),
|
|
|
|
|
style: TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
..default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub use collapse::*;
|
|
|
|
|
@ -171,22 +229,26 @@ mod collapse {
|
|
|
|
|
|
|
|
|
|
pub fn show_child_number(
|
|
|
|
|
events: Query<(Entity, &Children), (Changed<Children>, With<Node>)>,
|
|
|
|
|
mut tabs: Query<(&Collapse, &mut Title)>,
|
|
|
|
|
mut tabs: Query<(Entity, &Collapse)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
// Any time a widget changes
|
|
|
|
|
events.iter().for_each(|(entity, children)| {
|
|
|
|
|
// Find any tabs which have this as a target
|
|
|
|
|
tabs.iter_mut()
|
|
|
|
|
.find_map(|(collapse, title)| {
|
|
|
|
|
.find_map(|(button, collapse)| {
|
|
|
|
|
if entity == collapse.target {
|
|
|
|
|
Some(title)
|
|
|
|
|
Some(button)
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.for_each(|title| {
|
|
|
|
|
title.note = Some(format!("({})", children.len().saturating_sub(1)))
|
|
|
|
|
.iter()
|
|
|
|
|
.for_each(|button| {
|
|
|
|
|
let num_children = children.len();
|
|
|
|
|
commands.entity(*button).insert(Note {
|
|
|
|
|
text: format!("({})", num_children),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|