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

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

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

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

Loading…
Cancel
Save