add docstring
Some checks failed
Rust Checks / checks (push) Failing after 5s

This commit is contained in:
CoCo_Sol 2024-02-08 07:46:21 +01:00
parent 118065339c
commit dc43cec459

View file

@ -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::<Address>()
// 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<Address>, 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<Address>) {
// 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;