monologues and fonts refactor. now I just need to do scenes and animations...

main
Elijah Voigt 2 years ago
parent 4495be1cd9
commit 0a56361168

@ -116,7 +116,7 @@ fn main() {
sync_monologue_font,
),
)
.add_systems(Update, (fonts_ui, set_active_font))
.add_systems(Update, (fonts_ui, ui_control_font, sync_font))
.add_systems(Startup, reload_assets)
.add_systems(
Update,

@ -61,11 +61,50 @@ pub fn fonts_ui(
});
}
pub fn set_active_font(
events: Query<&ui::TargetAsset<Font>, Added<ui::Active>>,
pub fn ui_control_font(
events: Query<
(&Interaction, &ui::TargetAsset<Font>, Option<&ui::Active>),
(With<Button>, Changed<Interaction>),
>,
mut font: ResMut<FontInfo>,
) {
events
.iter()
.for_each(|ui::TargetAsset { handle }| font.default = Some(handle.clone()));
.filter_map(
|(interaction, ui::TargetAsset { handle }, active)| match interaction {
Interaction::Pressed => Some((handle, active)),
_ => None,
},
)
.for_each(|(handle, active)| match active {
Some(_) => font.default = None,
None => font.default = Some(handle.clone()),
});
}
pub fn sync_font(
query: Query<(Entity, &ui::TargetAsset<Font>)>,
font: Res<FontInfo>,
mut commands: Commands,
) {
if font.is_changed() || font.is_added() {
match &font.default {
Some(current_handle) => {
query
.iter()
.for_each(|(entity, ui::TargetAsset { handle })| {
if *handle == *current_handle {
commands.entity(entity).insert(ui::Active);
} else {
commands.entity(entity).remove::<ui::Active>();
}
});
}
None => {
query.iter().for_each(|(entity, _)| {
commands.entity(entity).remove::<ui::Active>();
});
}
}
}
}

Loading…
Cancel
Save