generated from tipragot/rust
Adding a lobby scene #34
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"rust-analyzer.linkedProjects": [
|
||||||
|
"./crates/border-wars/Cargo.toml"
|
||||||
|
]
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
pub mod menu;
|
pub mod menus;
|
||||||
|
|
||||||
/// The state of the game.
|
/// The state of the game.
|
||||||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
//! The main entry point of the game.
|
//! The main entry point of the game.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use border_wars::menu::MenuPlugin;
|
use border_wars::menus::MenusPlugin;
|
||||||
use border_wars::GameState;
|
use border_wars::GameState;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_state::<GameState>()
|
.add_state::<GameState>()
|
||||||
.add_plugins(MenuPlugin)
|
.add_plugins(MenusPlugin)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
43
crates/border-wars/src/menus/lobby.rs
Normal file
43
crates/border-wars/src/menus/lobby.rs
Normal 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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
//! The main menu of the game.
|
//! The main menu of the game.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_egui::{egui, EguiContexts, EguiPlugin};
|
use bevy_egui::{egui, EguiContexts};
|
||||||
|
|
||||||
use crate::GameState;
|
use crate::GameState;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ pub struct MenuPlugin;
|
||||||
|
|
||||||
impl Plugin for MenuPlugin {
|
impl Plugin for MenuPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_plugins(EguiPlugin).add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
menu_ui.run_if(state_exists_and_equals(GameState::Menu)),
|
menu_ui.run_if(state_exists_and_equals(GameState::Menu)),
|
||||||
);
|
);
|
18
crates/border-wars/src/menus/mod.rs
Normal file
18
crates/border-wars/src/menus/mod.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue