From dc43cec45920e967e927a9844312af386708c0fd Mon Sep 17 00:00:00 2001 From: CoCoSol007 Date: Thu, 8 Feb 2024 07:46:21 +0100 Subject: [PATCH] add docstring --- crates/border-wars/src/menu.rs | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/crates/border-wars/src/menu.rs b/crates/border-wars/src/menu.rs index aee3377..57451c9 100644 --- a/crates/border-wars/src/menu.rs +++ b/crates/border-wars/src/menu.rs @@ -3,48 +3,80 @@ 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. fn build(&self, app: &mut App) { app.add_plugins(EguiPlugin) + // Add the resource .init_resource::
() + // Add systems for the UI. .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(MenuPlugin); // .add_systems(Update, ui_connect_button) +/// ``` fn ui_connect_button(mut address: ResMut
, mut egui_ctx: EguiContexts) { - // text edit + // Create the window egui::Window::new("Connect") .default_width(400.0) .show(egui_ctx.ctx_mut(), |ui| { + // Create the text 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); + + // Create the join button let button = ui.button("Join"); if button.clicked() { - println!("clicked: {}", address.ip); address.host = false; + // TODO: Join the game } }); }); } +/// The creation of the host window. +/// example: +/// ``` +/// App::new() +/// .add_plugins(DefaultPlugins) +/// .add_plugins(MenuPlugin); // .add_systems(Update, ui_host_button) +/// ``` fn ui_host_button(mut egui_ctx: EguiContexts, mut address: ResMut
) { - // text edit + // Create the window egui::Window::new("Host") .default_width(400.0) .show(egui_ctx.ctx_mut(), |ui| { + + // Create the text let button = ui.button("Create new game"); + + // Create the host button if button.clicked() { println!("clicked"); address.host = true;