Change structure of menus
Some checks failed
Rust Checks / checks (push) Failing after 5s

This commit is contained in:
CoCo_Sol 2024-02-10 10:02:11 +01:00
parent 9dee5ad781
commit a9d5451787
6 changed files with 71 additions and 5 deletions

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./crates/border-wars/Cargo.toml"
]
}

View file

@ -2,7 +2,7 @@
use bevy::prelude::*;
pub mod menu;
pub mod menus;
/// The state of the game.
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]

View file

@ -1,13 +1,13 @@
//! The main entry point of the game.
use bevy::prelude::*;
use border_wars::menu::MenuPlugin;
use border_wars::menus::MenusPlugin;
use border_wars::GameState;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_state::<GameState>()
.add_plugins(MenuPlugin)
.add_plugins(MenusPlugin)
.run();
}

View file

@ -0,0 +1,43 @@
//! The lobby menu of the game.
use bevy::prelude::*;
use bevy_egui::{EguiContexts, egui};
use crate::GameState;
/// The plugin for the lobby.
pub struct LobbyPlugin;
impl Plugin for LobbyPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
lobby_ui.run_if(state_exists_and_equals(GameState::Lobby)),
);
}
}
/// Display the UI of the menu to host a game or join one.
fn lobby_ui(
mut ctx: EguiContexts,
mut next_state: ResMut<NextState<GameState>>,
) {
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
ui.heading("Border Wars");
ui.separator();
ui.label("Game created");
ui.horizontal(|ui| {
ui.label("Game ID: ");
ui.label("connection_string");
});
ui.separator();
if ui.button("Run the game").clicked() {
next_state.set(GameState::Game);
// TODO: run the game
}
});
}

View file

@ -1,7 +1,7 @@
//! The main menu of the game.
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use bevy_egui::{egui, EguiContexts};
use crate::GameState;
@ -10,7 +10,7 @@ pub struct MenuPlugin;
impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(EguiPlugin).add_systems(
app.add_systems(
Update,
menu_ui.run_if(state_exists_and_equals(GameState::Menu)),
);

View file

@ -0,0 +1,18 @@
//! All the menu's programme.
use bevy::prelude::*;
use bevy_egui::EguiPlugin;
pub mod lobby;
pub mod menu;
/// The plugin for all menus.
pub struct MenusPlugin;
impl Plugin for MenusPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(EguiPlugin)
.add_plugins(lobby::LobbyPlugin)
.add_plugins(menu::MenuPlugin);
}
}