WIP - Beggining of the menu ui, setup nodes
Some checks failed
Rust Checks / checks (push) Failing after 18s

This commit is contained in:
Raphaël 2024-02-14 01:49:11 +01:00
parent ba14642981
commit 6abd0f0c87
4 changed files with 115 additions and 31 deletions

10
Cargo.lock generated
View file

@ -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"

View file

@ -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

View file

@ -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"

View file

@ -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<String>,
mut next_scene: ResMut<NextState<CurrentScene>>,
) {
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
}
});
}