From 6abd0f0c87e34f00064a7cb2f96df4c7ba252ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Wed, 14 Feb 2024 01:49:11 +0100 Subject: [PATCH] WIP - Beggining of the menu ui, setup nodes --- Cargo.lock | 10 +++ Cargo.toml | 8 ++ crates/border-wars/Cargo.toml | 4 +- crates/border-wars/src/scenes/menu.rs | 124 ++++++++++++++++++++------ 4 files changed, 115 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f17b55..89e6897 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -442,6 +442,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4bc7e09282a82a48d70ade0c4c1154b0fd7882a735a39c66766a5d0f4718ea9" dependencies = [ + "bevy_dylib", "bevy_internal", ] @@ -617,6 +618,15 @@ dependencies = [ "sysinfo", ] +[[package]] +name = "bevy_dylib" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45b99001eb4837c78d9c63cc8b32fda61ea96b194a2cda54b569aeee69a9853c" +dependencies = [ + "bevy_internal", +] + [[package]] name = "bevy_ecs" version = "0.12.1" diff --git a/Cargo.toml b/Cargo.toml index b174bb5..5a60f17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,11 @@ missing_docs_in_private_items = "warn" unwrap_in_result = "warn" unwrap_used = "warn" nursery = "warn" + +# Enable a small amount of optimization in debug mode +[profile.dev] +opt-level = 1 + +# Enable high optimizations for dependencies (incl. Bevy), but not for our code: +[profile.dev.package."*"] +opt-level = 3 diff --git a/crates/border-wars/Cargo.toml b/crates/border-wars/Cargo.toml index 19f39d9..2a58d57 100644 --- a/crates/border-wars/Cargo.toml +++ b/crates/border-wars/Cargo.toml @@ -11,5 +11,5 @@ authors = ["CoCoSol"] workspace = true [dependencies] -bevy = "0.12.1" -bevy_egui = "0.24.0" +bevy = { version = "0.12.1", features = ["dynamic_linking"] } +bevy_egui = "0.24.0" \ No newline at end of file diff --git a/crates/border-wars/src/scenes/menu.rs b/crates/border-wars/src/scenes/menu.rs index c5c84c7..3018351 100644 --- a/crates/border-wars/src/scenes/menu.rs +++ b/crates/border-wars/src/scenes/menu.rs @@ -1,7 +1,6 @@ //! The main menu of the game. use bevy::prelude::*; -use bevy_egui::{egui, EguiContexts}; use crate::CurrentScene; @@ -10,36 +9,103 @@ pub struct MenuPlugin; impl Plugin for MenuPlugin { fn build(&self, app: &mut App) { - app.add_systems(Update, menu_ui.run_if(in_state(CurrentScene::Menu))); + app.add_systems(Startup, menu_ui.run_if(in_state(CurrentScene::Menu))); } } /// Display the UI of the menu to host a game or join one. -fn menu_ui( - mut ctx: EguiContexts, - mut connection_string: Local, - mut next_scene: ResMut>, -) { - egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| { - ui.heading("Border Wars"); - - ui.separator(); - - ui.label("Connect to an existing game:"); - ui.horizontal(|ui| { - ui.label("Game ID: "); - ui.text_edit_singleline(&mut *connection_string); - - if ui.button("Join").clicked() { - next_scene.set(CurrentScene::Game); - // TODO: connect to the game - } +fn menu_ui(mut commands: Commands) { + commands.spawn(Camera2dBundle::default()); + // Green + commands + .spawn(NodeBundle { + style: Style { + margin: UiRect { + left: (Val::Auto), + right: (Val::Auto), + top: (Val::Px(0.)), + bottom: (Val::Px(0.)), + }, + width: Val::Percent(55.), + height: Val::Percent(100.), + flex_direction: FlexDirection::Column, + ..default() + }, + ..default() + }) + // Text + .with_children(|parent| { + parent.spawn( + NodeBundle{ + style: Style { + margin: UiRect { + left: (Val::Auto), + right: (Val::Auto), + top: (Val::Percent(5.)), + bottom: (Val::Percent(15.)), + }, + width: Val::Percent(90.), + height: Val::Percent(25.), + ..default() + }, + background_color: BackgroundColor(Color::RED), + ..default() + } + + ); + }) + // BLUE + .with_children(|parent| { + parent + .spawn(NodeBundle { + style: Style { + flex_direction: FlexDirection::Column, + margin: UiRect { + left: (Val::Auto), + right: (Val::Auto), + top: (Val::Auto), + bottom: (Val::Percent(5.)), + }, + width: Val::Percent(85.), + height: Val::Percent(70.), + ..default() + }, + ..default() + }) + // YELLOW_GREEN 1 + .with_children(|parent| { + parent.spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Percent(45.), + margin: UiRect { + left: (Val::Auto), + right: (Val::Auto), + top: (Val::Auto), + bottom: (Val::Auto), + }, + ..default() + }, + background_color: BackgroundColor(Color::YELLOW_GREEN), + ..default() + }); + }) + // YELLOW_GREEN 2 + .with_children(|parent| { + parent.spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Percent(45.), + margin: UiRect { + left: (Val::Auto), + right: (Val::Auto), + top: (Val::Auto), + bottom: (Val::Auto), + }, + ..default() + }, + background_color: BackgroundColor(Color::YELLOW_GREEN), + ..default() + }); + }); }); - - ui.separator(); - - if ui.button("Create new game").clicked() { - next_scene.set(CurrentScene::Lobby); - // TODO: create a new game - } - }); }