From 09bc5bfaba8d1888694c8acc8cedc68e29fb3ff6 Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Tue, 1 Aug 2023 06:27:34 +0200 Subject: [PATCH 1/2] Add links to Bevy and GitHub source --- Cargo.lock | 103 ++++++++++++++++ Cargo.toml | 1 + assets/textures/bevy_small.png | Bin 0 -> 842 bytes assets/textures/made_with_bevy.png | Bin 0 -> 2435 bytes src/loading.rs | 6 +- src/menu.rs | 184 +++++++++++++++++++++++------ src/player.rs | 2 +- 7 files changed, 258 insertions(+), 38 deletions(-) create mode 100644 assets/textures/bevy_small.png create mode 100644 assets/textures/made_with_bevy.png diff --git a/Cargo.lock b/Cargo.lock index 22a0da7..924e8ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -520,6 +520,7 @@ dependencies = [ "embed-resource", "image", "rand", + "webbrowser", "winit", ] @@ -1563,6 +1564,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + [[package]] name = "fsevent-sys" version = "4.1.0" @@ -1815,6 +1825,25 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "image" version = "0.24.6" @@ -1921,6 +1950,22 @@ dependencies = [ "walkdir", ] +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", + "windows-sys 0.45.0", +] + [[package]] name = "jni-sys" version = "0.3.0" @@ -3093,6 +3138,21 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "toml" version = "0.5.11" @@ -3208,12 +3268,27 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.10" @@ -3226,6 +3301,17 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "url" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "uuid" version = "1.4.0" @@ -3377,6 +3463,23 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webbrowser" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd222aa310eb7532e3fd427a5d7db7e44bc0b0cf1c1e21139c345325511a85b6" +dependencies = [ + "core-foundation", + "home", + "jni 0.21.1", + "log", + "ndk-context", + "objc", + "raw-window-handle", + "url", + "web-sys", +] + [[package]] name = "wgpu" version = "0.16.2" diff --git a/Cargo.toml b/Cargo.toml index 8eedd54..e1b469f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ bevy = { version = "0.11", default-features = false, features = [ bevy_kira_audio = { version = "0.16" } bevy_asset_loader = { version = "0.17" } rand = { version = "0.8.3" } +webbrowser = { version = "0.8", features = ["hardened"] } # keep the following in sync with Bevy's dependencies winit = { version = "0.28", default-features = false } diff --git a/assets/textures/bevy_small.png b/assets/textures/bevy_small.png new file mode 100644 index 0000000000000000000000000000000000000000..ad208fb2c3f6772d411b623eda2720b6198241e9 GIT binary patch literal 842 zcmV-Q1GW5#P)kdg0009KNkl?OrLbPqv(&(iEl36nmcpQ7-L$$1b{p)bT?o~PHdq%0L39&E zy9u$N(PCR&ge$1UhOV5+e`gn4>PAcRD7oXic5%+pb9T-#pPT>x_dL({;dy^T3Q#QS zp#64hP=$n11Nxi~rt)<|xzDhsCf#0ES-@`6mrljwE5!}ODx7dssp7QgBX0-Ef(BxZ z&S>%f^oK*ijXVRfcHgVbkMMar#C?~`p3oUw%`p&b^m9JE&711M4LulgCnFlyk@6yx zj{Qo$^Hn}mhkg%f1WUg1@p>S8gCt?XoGcXkYwAFcAJd!#m)FHD-VLWbh&351l=)Nk zfjK2gkIfY7T+!6!(sH^lXfSRBVTqGEHwhsl;}J^oR8oc6QYX$sEqCK@~2ku`G!S4{|Z$ykx-*XkQL{#aWN})vA!+jHt2I zy`*#DU`lTx_yNbVUQ50)?+5eB{bd9bu3PC1rVEU7$cwtPWHr^_PWw}pDCS)>n>EfM zLYm+A2Bn_XCgurSvg&@zFRo}1!lH4*W-`JL;>T9jR@!B)?>La<^px9%T@X)qV5KDq ztLq9w_6D;#OSPl6U4;b+6NXYNqd4U*)#7WtD7-7P*4Hu>T=k5hO~HqBWZ;x!U5m+@ z)5`71<`p+#i%u5&scTO9Q4+IgQeW@!KQ~&?~ literal 0 HcmV?d00001 diff --git a/assets/textures/made_with_bevy.png b/assets/textures/made_with_bevy.png new file mode 100644 index 0000000000000000000000000000000000000000..731a545954d186cea04c0f7534175e0a2ebddc50 GIT binary patch literal 2435 zcmV-}34Hd6P)IfG)Axjn{TjNbLf!_yY7mKN@4;Y!EdJ^RDY(>xr#wm8v} z+$U*r{eGYO{(65t@Av2Py+hcI{Y_vMa5WGFihz?q8_*2w0sb9{L^2Z{ zSIHmkKU)8^Y17!YZ5vfpRUAEf6tCBdZQCT1NqT#G*|cdBy}iB8<4*$j zL?V$<<)9#c+>;LcB49@@@BzZ%FjZAm0PNehkM{O<%FD~CtgNJ@q=ZBw;eLEIaO)S! z0Gg^RK!Ir)>5DM7$Fz*pr|qAF4)6oux6c2?#l_Ut)>2zrOHok~sZ@%(x;hpwUJQV3 z+bGH>Ft)X|@$S3tQc_YvYilb_O-+s@n2MszZ)s^6%AU{TIw%$RI#3S$a9YnO=+spGCet$B&+1zs^Hu>X$8pYjDXnb4anhLV@%ZNj z{@l59J+fx}en0EiuV>-Hg_M<*jevY!1iRV~A3jWVbv1o`eJonEh-5O!tFOKapxL(l zEnsI(2{0|g0=j{Rfje`o@gZO%@W+XOFZPN!+Gj2|;-ohLAGrWsBp(j}M}R5gj9~*W z0XN9Aj{=WL_W@1Sul~FoKv9%019Jf4@i>i*jT|^|fPsO534MRgoH-;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8q_MG)OeRBVX(=9$hl2+X($Uc|LPWs)NF*|JAvr+a{(s+0&LtE*%7?Ad6VhR^340e*ORn2wGPnwy(Bbm$O)KmbKi7#tkLvMi_e zN2;v#qk*4yfQxS*Nbb;or@+gndhVjQ?I>26!6?+qT^p zjYh|noxB8GA~tvK+^LG9+`{>, #[asset(path = "textures/bevy.png")] - pub texture_bevy: Handle, + pub bevy: Handle, + #[asset(path = "textures/made_with_bevy.png")] + pub made_with_bevy: Handle, } diff --git a/src/menu.rs b/src/menu.rs index e17ecec..7b0a6f4 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -1,4 +1,4 @@ -use crate::loading::FontAssets; +use crate::loading::{FontAssets, TextureAssets}; use crate::GameState; use bevy::prelude::*; @@ -8,14 +8,13 @@ pub struct MenuPlugin; /// The menu is only drawn during the State `GameState::Menu` and is removed when that state is exited impl Plugin for MenuPlugin { fn build(&self, app: &mut App) { - app.init_resource::() - .add_systems(OnEnter(GameState::Menu), setup_menu) + app.add_systems(OnEnter(GameState::Menu), setup_menu) .add_systems(Update, click_play_button.run_if(in_state(GameState::Menu))) .add_systems(OnExit(GameState::Menu), cleanup_menu); } } -#[derive(Resource)] +#[derive(Component)] struct ButtonColors { normal: Color, hovered: Color, @@ -30,49 +29,162 @@ impl Default for ButtonColors { } } -fn setup_menu( - mut commands: Commands, - font_assets: Res, - button_colors: Res, -) { +#[derive(Component)] +struct Menu; + +fn setup_menu(mut commands: Commands, font_assets: Res, textures: Res) { commands.spawn(Camera2dBundle::default()); commands - .spawn(ButtonBundle { - style: Style { - width: Val::Px(120.0), - height: Val::Px(50.0), - margin: UiRect::all(Val::Auto), - justify_content: JustifyContent::Center, - align_items: AlignItems::Center, - ..Default::default() - }, - background_color: button_colors.normal.into(), - ..Default::default() - }) - .with_children(|parent| { - parent.spawn(TextBundle::from_section( - "Play", - TextStyle { - font: font_assets.fira_sans.clone(), - font_size: 40.0, - color: Color::rgb(0.9, 0.9, 0.9), + .spawn(( + NodeBundle { + style: Style { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + flex_direction: FlexDirection::Column, + align_items: AlignItems::Center, + justify_content: JustifyContent::Center, + ..default() }, - )); + ..default() + }, + Menu, + )) + .with_children(|children| { + children + .spawn(( + ButtonBundle { + style: Style { + width: Val::Px(140.0), + height: Val::Px(50.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + ..Default::default() + }, + background_color: Color::rgb(0.15, 0.15, 0.15).into(), + ..Default::default() + }, + ButtonColors { + normal: Color::rgb(0.15, 0.15, 0.15), + hovered: Color::rgb(0.25, 0.25, 0.25), + }, + ChangeState(GameState::Playing), + )) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Play", + TextStyle { + font: font_assets.fira_sans.clone(), + font_size: 40.0, + color: Color::rgb(0.9, 0.9, 0.9), + }, + )); + }); + children + .spawn(( + ButtonBundle { + style: Style { + width: Val::Px(140.0), + height: Val::Px(50.0), + justify_content: JustifyContent::SpaceAround, + align_items: AlignItems::Center, + margin: UiRect { + top: Val::Px(25.), + ..default() + }, + ..Default::default() + }, + background_color: Color::NONE.into(), + ..Default::default() + }, + ButtonColors { + normal: Color::NONE, + hovered: Color::rgb(0.25, 0.25, 0.25), + }, + OpenLink("https://bevyengine.org"), + )) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Made with Bevy", + TextStyle { + font: font_assets.fira_sans.clone(), + font_size: 20.0, + color: Color::rgb(0.9, 0.9, 0.9), + }, + )); + parent.spawn(ImageBundle { + image: textures.bevy_small.clone().into(), + ..default() + }); + }); + children + .spawn(( + ButtonBundle { + style: Style { + width: Val::Px(140.0), + height: Val::Px(50.0), + justify_content: JustifyContent::SpaceAround, + align_items: AlignItems::Center, + margin: UiRect { + top: Val::Px(5.), + ..default() + }, + ..Default::default() + }, + background_color: Color::NONE.into(), + ..Default::default() + }, + ButtonColors { + normal: Color::NONE, + hovered: Color::rgb(0.25, 0.25, 0.25), + }, + OpenLink("https://github.com/NiklasEi/bevy_game_template"), + )) + .with_children(|parent| { + parent.spawn(TextBundle::from_section( + "Open source", + TextStyle { + font: font_assets.fira_sans.clone(), + font_size: 20.0, + color: Color::rgb(0.9, 0.9, 0.9), + }, + )); + parent.spawn(ImageBundle { + image: textures.bevy_small.clone().into(), + ..default() + }); + }); }); } +#[derive(Component)] +struct ChangeState(GameState); + +#[derive(Component)] +struct OpenLink(&'static str); + fn click_play_button( - button_colors: Res, - mut state: ResMut>, + mut next_state: ResMut>, mut interaction_query: Query< - (&Interaction, &mut BackgroundColor), + ( + &Interaction, + &mut BackgroundColor, + &ButtonColors, + Option<&ChangeState>, + Option<&OpenLink>, + ), (Changed, With