Add the main menu #31

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

View file

@ -12,7 +12,7 @@ pub enum GameState {
/// When we are in the main menu.
#[default]
Menu,
/// The lobby where the host will wait for other players to join.
/// When we are in the lobby waiting for players.
Lobby,
/// When we play this wonderful game.
Game,

View file

@ -8,9 +8,7 @@ use crate::GameState;
/// The plugin for the menu.
pub struct MenuPlugin;
/// Implement a trait in order to transform the struc into a plugin.
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, 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.
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| {
ui.heading("Border Wars");
ui.separator();
ui.label("Connect to an existing game:");
ui.label("Connect to an existing game:");
ui.horizontal(|ui| {
ui.label("Game ID: ");
ui.text_edit_singleline(&mut *connection_string);
if ui.button("Join").clicked() {
println!("clicked");
next_state.set(GameState::Game);
}
});
ui.separator();
if ui.button("Create new game").clicked() {
println!("clicked");
next_state.set(GameState::Lobby);
}
});
}