collapsing ui elements in game of life

main
Elijah Voigt 2 days ago
parent 41bbc6b973
commit 4f84c4cc86

16
life/Cargo.lock generated

@ -3324,6 +3324,14 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "life"
version = "0.1.0"
dependencies = [
"bevy",
"engine",
]
[[package]] [[package]]
name = "linebender_resource_handle" name = "linebender_resource_handle"
version = "0.1.1" version = "0.1.1"
@ -4212,14 +4220,6 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5" checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5"
[[package]]
name = "prototypes"
version = "0.1.0"
dependencies = [
"bevy",
"engine",
]
[[package]] [[package]]
name = "pxfm" name = "pxfm"
version = "0.1.29" version = "0.1.29"

@ -1,5 +1,5 @@
[package] [package]
name = "prototypes" name = "life"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"

@ -15,8 +15,7 @@ impl Plugin for GameActionsPlugin {
.bind(ZoomAction::Zoom, [Binding::Scroll]) .bind(ZoomAction::Zoom, [Binding::Scroll])
.bind(ZoomAction::ZoomIn, [Binding::Key(KeyCode::Equal)]) .bind(ZoomAction::ZoomIn, [Binding::Key(KeyCode::Equal)])
.bind(ZoomAction::ZoomOut, [Binding::Key(KeyCode::Minus)]), .bind(ZoomAction::ZoomOut, [Binding::Key(KeyCode::Minus)]),
ActionsPlugin::<Action>::new() ActionsPlugin::<Action>::new().bind(Action::Quit, [Binding::Key(KeyCode::Escape)]),
.bind(Action::Quit, [Binding::Key(KeyCode::Escape)]),
)); ));
} }
} }
@ -99,7 +98,7 @@ pub(crate) enum ZoomAction {
#[action_handler(ZoomAction::zoom_out)] #[action_handler(ZoomAction::zoom_out)]
ZoomOut, ZoomOut,
#[default] #[default]
None None,
} }
#[derive(Copy, Clone, Eq, PartialEq, Hash, GameAction, Default)] #[derive(Copy, Clone, Eq, PartialEq, Hash, GameAction, Default)]

@ -1,13 +1,14 @@
// TODO: // TODO:
// * Fix randomly audio not working // * Fix randomly audio not working
// * Lock down system scheduling/run_if conditions // * Lock down system scheduling/run_if conditions
// * Fix tiling repeating
// * Negative coordinates should not mirror
// * UI widget explaining rules/hotkeys // * UI widget explaining rules/hotkeys
// * Show shadow of piece (same tile, just with alpha transparency) // * Show shadow of piece (same tile, just with alpha transparency)
// * Start with an interesting pattern // * Start with an interesting pattern
// * UI minimize widgets // * UI minimize widgets
// * Add "follow action" that adjusts camera to zoom in/out/move to see everything
// * Make click and drag feel better // * Make click and drag feel better
// * Add arrow keys to move around
// * web/wasm build
#![allow(clippy::complexity)] #![allow(clippy::complexity)]
// Only because of FromTemplat macros unfortunately... // Only because of FromTemplat macros unfortunately...
#![allow(dead_code)] #![allow(dead_code)]
@ -37,6 +38,8 @@ fn main() {
.insert_resource(UiTheme(create_light_theme())) .insert_resource(UiTheme(create_light_theme()))
.init_state::<SimulationPlayback>() .init_state::<SimulationPlayback>()
.init_state::<AudioPlayback>() .init_state::<AudioPlayback>()
.init_state::<DebugUi>()
.init_state::<MainUi>()
.add_message::<Lifecycle>() .add_message::<Lifecycle>()
.add_systems( .add_systems(
Startup, Startup,
@ -92,9 +95,12 @@ fn main() {
.add_systems( .add_systems(
Update, Update,
( (
toggle_state_visible::<SimulationPlayback>.run_if(state_changed::<SimulationPlayback>), toggle_state_visible::<SimulationPlayback>
.run_if(state_changed::<SimulationPlayback>),
manage_interactive::<SimulationPlayback>, manage_interactive::<SimulationPlayback>,
toggle_state_visible::<AudioPlayback>.run_if(state_changed::<AudioPlayback>), toggle_state_visible::<AudioPlayback>.run_if(state_changed::<AudioPlayback>),
toggle_state_visible::<DebugUi>.run_if(state_changed::<DebugUi>),
toggle_state_visible::<MainUi>.run_if(state_changed::<MainUi>),
manage_interactive::<AudioPlayback>, manage_interactive::<AudioPlayback>,
update_note_interactivity, update_note_interactivity,
), ),
@ -118,6 +124,20 @@ enum DebugInfo {
Empty, Empty,
} }
#[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component, FromTemplate)]
enum DebugUi {
#[default]
Visible,
Hidden,
}
#[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component, FromTemplate)]
enum MainUi {
#[default]
Visible,
Hidden,
}
#[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component, FromTemplate)] #[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component, FromTemplate)]
enum AudioPlayback { enum AudioPlayback {
#[default] #[default]
@ -200,7 +220,10 @@ fn ui_button(button: UiButton) -> impl Scene {
} }
} }
fn ui_toggle_button<A: Scene, B: Scene>((button_a, state_a): (UiButton, A), (button_b, state_b): (UiButton, B)) -> impl Scene { fn ui_toggle_button<A: Scene, B: Scene>(
(button_a, state_a): (UiButton, A),
(button_b, state_b): (UiButton, B),
) -> impl Scene {
bsn! { bsn! {
@FeathersButton @FeathersButton
Hovered Hovered
@ -289,21 +312,33 @@ fn the_ui() -> impl Scene {
} }
fn debug_ui() -> impl Scene { fn debug_ui() -> impl Scene {
fn toggle_debug_ui(
_: On<Pointer<Click>>,
mut next: ResMut<NextState<DebugUi>>,
curr: Res<State<DebugUi>>,
) {
next.set(match curr.get() {
DebugUi::Hidden => DebugUi::Visible,
DebugUi::Visible => DebugUi::Hidden,
});
}
bsn! { bsn! {
Node { Node {
justify_self: JustifySelf::End, justify_self: JustifySelf::End,
display: Display::Flex, display: Display::Flex,
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
} }
// TODO: Toggle visibility when debugging disabled
pane() pane()
Transform Transform
Children [ Children [
pane_header() pane_header()
on(toggle_debug_ui)
Children [ Children [
Text("Debug Info") ThemedText, Text("Debug Info") ThemedText,
], ],
pane_body() pane_body()
DebugUi::Visible
ToggleStateVisible
Children [ Children [
subpane() subpane()
Node { Node {
@ -387,6 +422,17 @@ fn primary_ui() -> impl Scene {
} }
} }
fn toggle_main_ui(
_: On<Pointer<Click>>,
mut next: ResMut<NextState<MainUi>>,
curr: Res<State<MainUi>>,
) {
next.set(match curr.get() {
MainUi::Hidden => MainUi::Visible,
MainUi::Visible => MainUi::Hidden,
});
}
bsn! { bsn! {
Node { Node {
display: Display::Flex, display: Display::Flex,
@ -397,10 +443,14 @@ fn primary_ui() -> impl Scene {
pane() pane()
Children [ Children [
pane_header() pane_header()
on(toggle_main_ui)
// todo: toggle main ui
Children [ Children [
Text("Conways Game of Life With Sound") ThemedText, Text("Conways Game of Life With Sound") ThemedText,
], ],
pane_body() pane_body()
MainUi::Visible
ToggleStateVisible
Children [ Children [
subpane() subpane()
Node { Node {
@ -1269,7 +1319,7 @@ struct ToggleStateVisible;
fn toggle_state_visible<S: States + Component>( fn toggle_state_visible<S: States + Component>(
mut q: Query<(&S, &mut Node), With<ToggleStateVisible>>, mut q: Query<(&S, &mut Node), With<ToggleStateVisible>>,
c: Res<State<S>> c: Res<State<S>>,
) { ) {
q.iter_mut().for_each(|(s, mut node)| { q.iter_mut().for_each(|(s, mut node)| {
node.display = if s == c.get() { node.display = if s == c.get() {

Loading…
Cancel
Save