Add the main menu #31

Merged
CoCo_Sol merged 25 commits from main-menu into main 2024-02-09 23:42:37 +00:00
3 changed files with 25 additions and 4 deletions
Showing only changes of commit 8e8105ce44 - Show all commits

View file

@ -0,0 +1,12 @@
//! The file that contains utility functions, enums, structs of the game.
use bevy::prelude::*;
use std::default::Default;
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
pub enum GameState {
#[default]
Menu,
Lobby,
Game,
}

View file

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

View file

@ -2,6 +2,7 @@
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use border_wars::GameState;
/// The plugin for the menu.
pub struct MenuPlugin;
@ -10,14 +11,19 @@ pub struct MenuPlugin;
impl Plugin for MenuPlugin {
/// A function that is called when the plugin is added to the application.
fn build(&self, app: &mut App) {
app.add_plugins(EguiPlugin)
.add_systems(Update, ui_connect_window)
.add_systems(Update, ui_host_window);
app.add_plugins(EguiPlugin).add_systems(Update,(
ui_connect_window.run_if(state_exists_and_equals(GameState::Menu)),
ui_host_window.run_if(state_exists_and_equals(GameState::Menu)),
));
}
}
/// Display a connect window, with a button to join a game and an input to enter
/// the address.
fn ui_connect_window(mut ctx: EguiContexts, mut connection_string: Local<String>) {
fn ui_connect_window(
mut ctx: EguiContexts,
mut connection_string: Local<String>,
mut state: ResMut<State<GameState>>,
) {
egui::Window::new("Connect")
.default_width(400.0)
.show(ctx.ctx_mut(), |ui| {