generated from tipragot/rust
Add the main menu #31
|
@ -12,7 +12,7 @@ pub enum GameState {
|
||||||
/// When we are in the main menu.
|
/// When we are in the main menu.
|
||||||
#[default]
|
#[default]
|
||||||
Menu,
|
Menu,
|
||||||
/// The lobby where the host will wait for other players to join.
|
/// When we are in the lobby waiting for players.
|
||||||
Lobby,
|
Lobby,
|
||||||
/// When we play this wonderful game.
|
/// When we play this wonderful game.
|
||||||
Game,
|
Game,
|
||||||
|
|
|
@ -8,9 +8,7 @@ use crate::GameState;
|
||||||
/// The plugin for the menu.
|
/// The plugin for the menu.
|
||||||
pub struct MenuPlugin;
|
pub struct MenuPlugin;
|
||||||
|
|
||||||
/// Implement a trait in order to transform the struc into a plugin.
|
|
||||||
impl Plugin for MenuPlugin {
|
impl Plugin for MenuPlugin {
|
||||||
/// 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)
|
app.add_plugins(EguiPlugin)
|
||||||
.add_systems(Update, menu_ui.run_if(in_state(GameState::Menu)));
|
.add_systems(Update, menu_ui.run_if(in_state(GameState::Menu)));
|
||||||
|
@ -22,25 +20,27 @@ impl Plugin for MenuPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Display the UI of the menu to host a game or join one.
|
/// Display the UI of the menu to host a game or join one.
|
||||||
fn menu_ui(mut ctx: EguiContexts, mut connection_string: Local<String>) {
|
fn menu_ui(mut ctx: EguiContexts, mut connection_string: Local<String>, mut next_state: ResMut<NextState<GameState>>) {
|
||||||
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
||||||
ui.heading("Border Wars");
|
ui.heading("Border Wars");
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.label("Connect to an existing game:");
|
|
||||||
|
|
||||||
|
ui.label("Connect to an existing game:");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Game ID: ");
|
ui.label("Game ID: ");
|
||||||
ui.text_edit_singleline(&mut *connection_string);
|
ui.text_edit_singleline(&mut *connection_string);
|
||||||
|
|
||||||
if ui.button("Join").clicked() {
|
if ui.button("Join").clicked() {
|
||||||
println!("clicked");
|
next_state.set(GameState::Game);
|
||||||
}
|
}
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
|
|||||||
});
|
});
|
||||||
|
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
tipragot
commented
You should use a local resource instead. You should use a local resource instead.
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
if ui.button("Create new game").clicked() {
|
if ui.button("Create new game").clicked() {
|
||||||
println!("clicked");
|
next_state.set(GameState::Lobby);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue
This example does not use the function.