From cacda7fc2b3272de36530132d8c8df788b634b79 Mon Sep 17 00:00:00 2001 From: fluo10 Date: Mon, 16 Jun 2025 08:36:10 +0900 Subject: [PATCH] Add beby menu --- .gitattributes | 1 + .../playful/textures/Game Icons/exitRight.png | 3 + .../playful/textures/Game Icons/right.png | 3 + .../playful/textures/Game Icons/wrench.png | 3 + examples/core/src/ui/playful/mod.rs | 51 +- .../core/src/ui/playful/plugins/loading.rs | 59 +++ .../core/src/ui/playful/plugins/main_menu.rs | 475 ++++++++++++++++++ .../core/src/ui/playful/plugins/main_view.rs | 113 +++++ examples/core/src/ui/playful/plugins/mod.rs | 3 + examples/core/src/ui/playful/themes/dark.rs | 7 + examples/core/src/ui/playful/themes/light.rs | 4 + examples/core/src/ui/playful/themes/mod.rs | 12 + 12 files changed, 731 insertions(+), 3 deletions(-) create mode 100644 examples/core/assets/playful/textures/Game Icons/exitRight.png create mode 100644 examples/core/assets/playful/textures/Game Icons/right.png create mode 100644 examples/core/assets/playful/textures/Game Icons/wrench.png create mode 100644 examples/core/src/ui/playful/plugins/loading.rs create mode 100644 examples/core/src/ui/playful/plugins/main_menu.rs create mode 100644 examples/core/src/ui/playful/plugins/main_view.rs create mode 100644 examples/core/src/ui/playful/plugins/mod.rs create mode 100644 examples/core/src/ui/playful/themes/dark.rs create mode 100644 examples/core/src/ui/playful/themes/light.rs create mode 100644 examples/core/src/ui/playful/themes/mod.rs diff --git a/.gitattributes b/.gitattributes index 361484f..b1b4e57 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.ico filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/examples/core/assets/playful/textures/Game Icons/exitRight.png b/examples/core/assets/playful/textures/Game Icons/exitRight.png new file mode 100644 index 0000000..4eca3e6 --- /dev/null +++ b/examples/core/assets/playful/textures/Game Icons/exitRight.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8019d1ef164aa32e14bcfbbcd9b2f254d888345a92ca95c3ea22f1849bb71c5 +size 384 diff --git a/examples/core/assets/playful/textures/Game Icons/right.png b/examples/core/assets/playful/textures/Game Icons/right.png new file mode 100644 index 0000000..24eab8d --- /dev/null +++ b/examples/core/assets/playful/textures/Game Icons/right.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fce29186a6ffe086346d226195a0649cde399b788dd209922296f07384291f0f +size 368 diff --git a/examples/core/assets/playful/textures/Game Icons/wrench.png b/examples/core/assets/playful/textures/Game Icons/wrench.png new file mode 100644 index 0000000..fd088a2 --- /dev/null +++ b/examples/core/assets/playful/textures/Game Icons/wrench.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e35bb231745af12133f764ebec22574996dee16cd5543f13c7045b08e26aaf2 +size 637 diff --git a/examples/core/src/ui/playful/mod.rs b/examples/core/src/ui/playful/mod.rs index 6d6cdd9..72144ca 100644 --- a/examples/core/src/ui/playful/mod.rs +++ b/examples/core/src/ui/playful/mod.rs @@ -1,11 +1,56 @@ +mod plugins; +pub mod themes; + use bevy::prelude::*; -pub fn hello_world_system() { - println!("hello world"); +#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)] +enum AppState { + #[default] + Loading, + MainView, + Menu, + List, + Graph +} + +#[derive(Resource, Debug, Component, PartialEq, Eq, Clone, Copy)] +enum DisplayQuality { + Low, + Medium, + High, +} + +#[derive(Resource, Debug, Component, PartialEq, Eq, Clone, Copy)] +struct Volume(u32); + +#[derive(Resource, Debug, Component, PartialEq, Eq, Clone, Copy)] +enum ViewerMode { + PokerTip2D, + PokerTip3D, } pub fn run_playful_app() { App::new() - .add_systems(Update, hello_world_system) + .add_plugins(DefaultPlugins) + .insert_resource(DisplayQuality::Medium) + .insert_resource(Volume(7)) + .insert_resource(ViewerMode::PokerTip2D) + .init_state::() + .add_systems(Startup, setup) + .add_plugins((plugins::loading::loading_plugin, plugins::main_menu::menu_plugin, plugins::main_view::main_view_plugin)) .run(); + +} + +fn setup(mut commands: Commands) { + commands.spawn(Camera2d); +} + + + +// Generic system that takes a component as a parameter, and will despawn all entities with that component +fn despawn_screen(to_despawn: Query>, mut commands: Commands) { + for entity in &to_despawn { + commands.entity(entity).despawn(); + } } \ No newline at end of file diff --git a/examples/core/src/ui/playful/plugins/loading.rs b/examples/core/src/ui/playful/plugins/loading.rs new file mode 100644 index 0000000..378617a --- /dev/null +++ b/examples/core/src/ui/playful/plugins/loading.rs @@ -0,0 +1,59 @@ +use bevy::prelude::*; + +use crate::ui::playful::{despawn_screen, AppState}; + +// This plugin will display a splash screen with Bevy logo for 1 second before switching to the menu +pub fn loading_plugin(app: &mut App) { + // As this plugin is managing the splash screen, it will focus on the state `GameState::Splash` + app + // When entering the state, spawn everything needed for this screen + .add_systems(OnEnter(AppState::Loading), loading_setup) + // While in this state, run the `countdown` system + .add_systems(Update, countdown.run_if(in_state(AppState::Loading))) + // When exiting the state, despawn everything that was spawned for this screen + .add_systems(OnExit(AppState::Loading), despawn_screen::); +} + +// Tag component used to tag entities added on the splash screen +#[derive(Component)] +struct OnLoadingScreen; + +// Newtype to use a `Timer` for this screen as a resource +#[derive(Resource, Deref, DerefMut)] +struct LoadingTimer(Timer); + +fn loading_setup(mut commands: Commands, asset_server: Res) { + //let icon = asset_server.load("textures/Game Icons/wrench.png"); + // Display the logo + commands.spawn(( + Node { + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + width: Val::Percent(100.0), + height: Val::Percent(100.0), + ..default() + }, + OnLoadingScreen, + children![( + //ImageNode::new(icon), + Node { + // This will set the logo to be 200px wide, and auto adjust its height + width: Val::Px(200.0), + ..default() + }, + )], + )); + // Insert the timer as a resource + commands.insert_resource(LoadingTimer(Timer::from_seconds(1.0, TimerMode::Once))); +} + +// Tick the timer, and change state when finished +fn countdown( + mut game_state: ResMut>, + time: Res