WIP: Add a main menu
Some checks failed
Rust Checks / checks (push) Failing after 10m41s

This commit is contained in:
CoCo_Sol 2024-02-08 07:27:52 +01:00
parent 7ce491aee1
commit 118065339c
5 changed files with 4245 additions and 2 deletions

4179
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,3 +8,7 @@ authors = ["CoCoSol"]
[lints] [lints]
workspace = true workspace = true
[dependencies]
bevy = "0.12.1"
bevy_egui = "0.24.0"

Binary file not shown.

View file

@ -1,5 +1,12 @@
//! A simple program that prints "Hello, world!" to the terminal. //! The main entry point of the game.
use bevy::prelude::*;
mod menu;
use menu::MenuPlugin;
fn main() { fn main() {
println!("Hello, world!"); App::new()
.add_plugins(DefaultPlugins)
.add_plugins(MenuPlugin)
.run();
} }

View file

@ -0,0 +1,53 @@
//! The main menu of the game.
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
#[derive(Default, Resource)]
struct Address {
host: bool,
ip: String,
}
pub struct MenuPlugin;
impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(EguiPlugin)
.init_resource::<Address>()
.add_systems(Update, ui_connect_button)
.add_systems(Update, ui_host_button);
}
}
fn ui_connect_button(mut address: ResMut<Address>, mut egui_ctx: EguiContexts) {
// text edit
egui::Window::new("Connect")
.default_width(400.0)
.show(egui_ctx.ctx_mut(), |ui| {
ui.heading("Please enter the password of the game: ");
ui.horizontal(|ui| {
ui.label("Address: ");
ui.text_edit_singleline(&mut address.ip);
let button = ui.button("Join");
if button.clicked() {
println!("clicked: {}", address.ip);
address.host = false;
}
});
});
}
fn ui_host_button(mut egui_ctx: EguiContexts, mut address: ResMut<Address>) {
// text edit
egui::Window::new("Host")
.default_width(400.0)
.show(egui_ctx.ctx_mut(), |ui| {
let button = ui.button("Create new game");
if button.clicked() {
println!("clicked");
address.host = true;
}
});
}