generated from tipragot/rust
Add the main menu #31
|
@ -1,14 +1,19 @@
|
||||||
//! The file that contains utility functions, enums, structs of the game.
|
//! The file that contains utility functions, enums, structs of the game.
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
|
|
||||||
|
/// The state of the game.
|
||||||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
||||||
pub enum GameState {
|
pub enum GameState {
|
||||||
|
/// The main menu.
|
||||||
#[default]
|
#[default]
|
||||||
Menu,
|
Menu,
|
||||||
|
/// The lobby where the host will wait for other players to join.
|
||||||
Lobby,
|
Lobby,
|
||||||
|
/// The game.
|
||||||
Game,
|
Game,
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,8 @@ pub struct MenuPlugin;
|
||||||
impl Plugin for MenuPlugin {
|
impl Plugin for MenuPlugin {
|
||||||
/// A function that is called when the plugin is added to the application.
|
/// A function that is called when the plugin is added to the application.
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_plugins(EguiPlugin).add_systems(
|
app.add_plugins(EguiPlugin)
|
||||||
Update,
|
.add_systems(Update, menu_ui.run_if(in_state(GameState::Menu)));
|
||||||
(ui_connect_window, ui_host_window).run_if(in_state(GameState::Menu)),
|
|
||||||
);
|
|
||||||
println!("{:?}", app.world.resource::<State<GameState>>());
|
println!("{:?}", app.world.resource::<State<GameState>>());
|
||||||
app.add_plugins(EguiPlugin).add_systems(
|
app.add_plugins(EguiPlugin).add_systems(
|
||||||
Update,
|
Update,
|
||||||
|
@ -24,7 +22,7 @@ impl Plugin for MenuPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Display a window, with a button to join a game and an input to enter
|
/// Display a window, with a button to join a game and an input to enter
|
||||||
/// the address or create a new game.
|
/// TODO
|
||||||
fn menu_ui(mut ctx: EguiContexts, mut connection_string: Local<String>) {
|
fn menu_ui(mut ctx: EguiContexts, mut connection_string: Local<String>) {
|
||||||
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
||||||
ui.heading("Border Wars");
|
ui.heading("Border Wars");
|
||||||
|
|
Loading…
Reference in a new issue