diff --git a/crates/border-wars/src/menu.rs b/crates/border-wars/src/menu.rs index 4dd0afe..f3a387c 100644 --- a/crates/border-wars/src/menu.rs +++ b/crates/border-wars/src/menu.rs @@ -3,81 +3,44 @@ use bevy::prelude::*; use bevy_egui::{egui, EguiContexts, EguiPlugin}; -/// A struc to store the address and if the game is being hosted or joined. -#[derive(Default, Resource)] -struct Address { - /// If the game is being hosted or joined. - /// True => Host, False => Join - host: bool, - /// The IP of the game. - /// The string you will share to connect to the game. - ip: String, -} - /// The plugin for the menu. pub struct MenuPlugin; /// Implement a trait in order to transform the struc into a plugin. impl Plugin for MenuPlugin { - /// The fonction that been called when the plugin is added to the app. + /// A function that is called when the plugin is added to the application. fn build(&self, app: &mut App) { app.add_plugins(EguiPlugin) - .init_resource::
() .add_systems(Update, ui_connect_button) .add_systems(Update, ui_host_button); } } -/// The creation of the connection window. -/// example: -/// ``` -/// App::new() -/// .add_plugins(DefaultPlugins) -/// .add_plugins(EguiPlugin) -/// .add_systems(Update, ui_connect_button); -/// ``` -fn ui_connect_button(mut address: ResMut
, mut egui_ctx: EguiContexts) { - // Create the window +/// Display a connect window, with a button to join a game and an input to enter the address. +fn ui_connect_button(mut ctx: EguiContexts, mut connection_string: Local) { egui::Window::new("Connect") .default_width(400.0) - .show(egui_ctx.ctx_mut(), |ui| { - // Create the text + .show(ctx.ctx_mut(), |ui| { ui.heading("Please enter the password of the game: "); ui.horizontal(|ui| { ui.label("Address: "); - // Create the input - ui.text_edit_singleline(&mut address.ip); + ui.text_edit_singleline(&mut *connection_string); - // Create the join button - let button = ui.button("Join"); - if button.clicked() { - address.host = false; - // TODO: Join the game + if ui.button("Join").clicked() { + println!("clicked"); } }); }); } -/// The creation of the host window. -/// example: -/// ``` -/// App::new() -/// .add_plugins(DefaultPlugins) -/// .add_plugins(EguiPlugin) -/// .add_systems(Update, ui_host_button); -fn ui_host_button(mut egui_ctx: EguiContexts, mut address: ResMut
) { - // Create the window +/// Display an host window, with a button to create a new game. +fn ui_host_button(mut ctx: EguiContexts) { egui::Window::new("Host") .default_width(400.0) - .show(egui_ctx.ctx_mut(), |ui| { - // Create a button to create a new game - let button = ui.button("Create new game"); - - // Create the host button - if button.clicked() { + .show(ctx.ctx_mut(), |ui| { + if ui.button("Create new game").clicked() { println!("clicked"); - address.host = true; } }); }