diff --git a/life/src/main.rs b/life/src/main.rs index 08e0831..b9ae0a1 100644 --- a/life/src/main.rs +++ b/life/src/main.rs @@ -1,12 +1,12 @@ // TODO: // * Debug Panel // * Describe cell I am hovering over (Note, Octave, etc) -// * Count # of cells on the board // * Fix tiling repeating // * Negative coordinates should not mirror // * Fix randomly audio not working -// * space -> play/pause sim -// * m -> un/mute audio +// * On reset: pause +// * Show shadow of piece (same tile, just with alpha transparency) +// * UI: Swap buttons mutually exclusive instead of disabling #![allow(clippy::complexity)] // Only because of FromTemplat macros unfortunately... #![allow(dead_code)] @@ -89,9 +89,9 @@ fn main() { .add_systems( Update, ( - // TODO: Visualize audio play/mute buttons enable/disable + toggle_state_visible::.run_if(state_changed::), manage_interactive::, - // TODO Visualize simulation run/pause buttons enable/disable + toggle_state_visible::.run_if(state_changed::), manage_interactive::, update_note_interactivity, ), @@ -196,6 +196,43 @@ fn ui_button(button: UiButton) -> impl Scene { } } +fn ui_toggle_button((button_a, state_a): (UiButton, A), (button_b, state_b): (UiButton, B)) -> impl Scene { + bsn! { + @FeathersButton + Hovered + Node { + top: Val::Px(2.5), + left: Val::Px(2.5), + margin: UiRect::all(Val::Px(2.5)), + align_items: AlignItems::Center, + } + Children [ + Node { + align_self: AlignSelf::Center, + justify_self: JustifySelf::Center, + width: Val::Percent(100.0), + height: Val::Percent(100.0), + } + ImageNode { + image: HandleTemplate::Path(AssetPath::parse(button_a.icon())), + } + state_a + ToggleStateVisible, + Node { + align_self: AlignSelf::Center, + justify_self: JustifySelf::Center, + width: Val::Percent(100.0), + height: Val::Percent(100.0), + } + ImageNode { + image: HandleTemplate::Path(AssetPath::parse(button_b.icon())), + } + state_b + ToggleStateVisible, + ] + } +} + fn the_camera() -> impl Scene { bsn! { Camera2d @@ -362,11 +399,7 @@ fn primary_ui() -> impl Scene { Children [ ui_button(UiButton::Power) ActionSource(Action::Quit), - ui_button(UiButton::Pause) - SimulationPlayback::Pause - ActionSource(SimAction::Toggle), - ui_button(UiButton::Play) - SimulationPlayback::Run + ui_toggle_button((UiButton::Pause, bsn! { SimulationPlayback::Pause }), (UiButton::Play, bsn! { SimulationPlayback::Run })) ActionSource(SimAction::Toggle), ui_button(UiButton::Step) ActionSource(SimAction::Step), @@ -378,11 +411,7 @@ fn primary_ui() -> impl Scene { ActionSource(ZoomAction::ZoomOut), ui_button(UiButton::ZoomIn) ActionSource(ZoomAction::ZoomIn), - ui_button(UiButton::MuteAudio) - AudioPlayback::Mute - ActionSource(AudioAction::Toggle), - ui_button(UiButton::PlayAudio) - AudioPlayback::Play + ui_toggle_button((UiButton::MuteAudio, bsn! { AudioPlayback::Mute }), (UiButton::PlayAudio, bsn! { AudioPlayback::Play })) ActionSource(AudioAction::Toggle), ] ], @@ -1190,3 +1219,19 @@ fn update_note_interactivity( fn pause_simulation(mut next: ResMut>) { next.set(SimulationPlayback::Pause) } + +#[derive(Component, Debug, FromTemplate)] +struct ToggleStateVisible; + +fn toggle_state_visible( + mut q: Query<(&S, &mut Node), With>, + c: Res> +) { + q.iter_mut().for_each(|(s, mut node)| { + node.display = if s == c.get() { + Display::None + } else { + Display::Flex + }; + }) +}