From a58151ee522b2726b7be4f8adacfba1355250af6 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Mon, 20 Nov 2023 22:23:11 -0800 Subject: [PATCH] Very simple 2d/3d toggle button It's buggy as hell, but it works. Improvements come with icing. --- .gitignore | 3 ++ assets/images/2d-icon.png | 3 ++ assets/images/3d-icon.png | 3 ++ shell.nix | 1 + src/display3d.rs | 15 ++++--- src/main.rs | 23 ++-------- src/menu.rs | 4 +- src/ui.rs | 88 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 110 insertions(+), 30 deletions(-) create mode 100644 assets/images/2d-icon.png create mode 100644 assets/images/3d-icon.png create mode 100644 src/ui.rs diff --git a/.gitignore b/.gitignore index f6fdfbf..37ffd44 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ **/*.ini trace-*.json + +*.blend +*.blend1 diff --git a/assets/images/2d-icon.png b/assets/images/2d-icon.png new file mode 100644 index 0000000..642e2ae --- /dev/null +++ b/assets/images/2d-icon.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61ead1f31c0b9279a50023b85c7bebef3e8326e48227523ebbd0a565979207cd +size 1015 diff --git a/assets/images/3d-icon.png b/assets/images/3d-icon.png new file mode 100644 index 0000000..d5655be --- /dev/null +++ b/assets/images/3d-icon.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:795ce33bac5563f6d12cd0530cd8b5f47f26b43bceb83286b12853176227a567 +size 1127 diff --git a/shell.nix b/shell.nix index 7d9e16f..677059e 100644 --- a/shell.nix +++ b/shell.nix @@ -18,6 +18,7 @@ mkShell rec { vulkan-loader # Rendering xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature libxkbcommon wayland # To use the wayland feature + gimp ]; LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; diff --git a/src/display3d.rs b/src/display3d.rs index c9a78b3..6b603a3 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -1,9 +1,3 @@ -// TODO: Camera Animations -// Intro animation -// Turn changing animations -// TODO: Pickup/put-down sound in 3d -// TODO: Background during menu - use crate::{ game::{Board, BoardIndex, Piece, Side}, prelude::*, @@ -65,7 +59,9 @@ impl Plugin for Display3dPlugin { ( activate::, set_piece_texture, - opening_animation.run_if(run_once()), + opening_animation + .run_if(run_once()) + .run_if(in_state(GameState::Play)), ), ) .add_systems(OnExit(DisplayState::Display3d), deactivate::) @@ -74,6 +70,9 @@ impl Plugin for Display3dPlugin { ( activate::.run_if(in_state(DisplayState::Display3d)), set_piece_texture, + opening_animation + .run_if(run_once()) + .run_if(in_state(DisplayState::Display3d)), ), ); } @@ -209,7 +208,7 @@ fn hydrate_camera( let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content"); // Set it to the default position by starting the initial animation if let Ok(mut player) = players.get_mut(entity) { - info!("Animations: {:?}", gltf.named_animations.keys()); + debug!("Animations: {:?}", gltf.named_animations.keys()); // GameCamIntro1, GameCamIntro2, GameCamSide1>2, GameCamSide2>1 let animation = match state.get() { game::TurnState::SideA => gltf.named_animations.get("GameCamIntro1"), diff --git a/src/main.rs b/src/main.rs index 5ce6fea..e8cb4a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod hit; mod loading; mod menu; mod prelude; +mod ui; use std::time::Duration; @@ -40,7 +41,6 @@ fn main() { app.add_systems( Update, ( - toggle_display_mode.run_if(on_event::()), // TODO: Run this other times too so we ensure a camera is always active toggle_display_camera.run_if(state_changed::()), toggle_display_camera.run_if(state_changed::()), @@ -70,6 +70,7 @@ fn main() { app.add_plugins(loading::LoadingPlugin); app.add_plugins(menu::MenuPlugin); app.add_plugins(audio::AudioPlugin); + app.add_plugins(ui::UiPlugin); app.run(); } @@ -83,7 +84,7 @@ pub enum GameState { } #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States, Component)] -pub enum DisplayState { +pub(crate) enum DisplayState { #[default] Display2d, Display3d, @@ -141,24 +142,6 @@ fn debug_state(state: Res>) { info!("State change {:?}", *state); } -fn toggle_display_mode( - mut events: EventReader, - display_state: Res>, - mut next_state: ResMut>, -) { - events - .iter() - .filter( - |KeyboardInput { - key_code, state, .. - }| (*key_code, *state) == (Some(KeyCode::Space), ButtonState::Pressed), - ) - .for_each(|_| match display_state.get() { - DisplayState::Display2d => next_state.set(DisplayState::Display3d), - DisplayState::Display3d => next_state.set(DisplayState::Display2d), - }) -} - fn toggle_display_camera( state: Res>, mut cameras: Query<(&mut Camera, &DisplayState)>, diff --git a/src/menu.rs b/src/menu.rs index d08fff4..eb429c6 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -160,7 +160,7 @@ fn handle_menu_quit( fn interactive_button( mut events: Query<(&mut BackgroundColor, &Interaction), (With