generated from tipragot/rust
Change of file structure for scenes #38
|
@ -6,7 +6,7 @@ pub mod scenes;
|
||||||
|
|
||||||
/// 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)]
|
||||||
pub enum GameState {
|
pub enum CurrentScene {
|
||||||
/// When we are in the main menu.
|
/// When we are in the main menu.
|
||||||
#[default]
|
#[default]
|
||||||
Menu,
|
Menu,
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use border_wars::scenes::ScenesPlugin;
|
use border_wars::scenes::ScenesPlugin;
|
||||||
use border_wars::GameState;
|
use border_wars::CurrentScene;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_state::<GameState>()
|
.add_state::<CurrentScene>()
|
||||||
.add_plugins(ScenesPlugin)
|
.add_plugins(ScenesPlugin)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_egui::{egui, EguiContexts};
|
use bevy_egui::{egui, EguiContexts};
|
||||||
|
|
||||||
use crate::GameState;
|
use crate::CurrentScene;
|
||||||
|
|
||||||
/// The plugin for the menu.
|
/// The plugin for the menu.
|
||||||
pub struct MenuPlugin;
|
pub struct MenuPlugin;
|
||||||
|
@ -12,7 +12,7 @@ impl Plugin for MenuPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.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(CurrentScene::Menu)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ impl Plugin for MenuPlugin {
|
||||||
fn menu_ui(
|
fn menu_ui(
|
||||||
mut ctx: EguiContexts,
|
mut ctx: EguiContexts,
|
||||||
mut connection_string: Local<String>,
|
mut connection_string: Local<String>,
|
||||||
mut next_state: ResMut<NextState<GameState>>,
|
mut next_state: ResMut<NextState<CurrentScene>>,
|
||||||
) {
|
) {
|
||||||
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
||||||
ui.heading("Border Wars");
|
ui.heading("Border Wars");
|
||||||
|
@ -33,7 +33,7 @@ fn menu_ui(
|
||||||
ui.text_edit_singleline(&mut *connection_string);
|
ui.text_edit_singleline(&mut *connection_string);
|
||||||
|
|
||||||
if ui.button("Join").clicked() {
|
if ui.button("Join").clicked() {
|
||||||
next_state.set(GameState::Game);
|
next_state.set(CurrentScene::Game);
|
||||||
// TODO: connect to the game
|
// TODO: connect to the game
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -41,7 +41,7 @@ fn menu_ui(
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
if ui.button("Create new game").clicked() {
|
if ui.button("Create new game").clicked() {
|
||||||
next_state.set(GameState::Lobby);
|
next_state.set(CurrentScene::Lobby);
|
||||||
// TODO: create a new game
|
// TODO: create a new game
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue