generated from tipragot/rust
WIP: Adding the menu #110
|
@ -1,13 +1,14 @@
|
||||||
//! The main menu of the game.
|
//! The main menu of the game.
|
||||||
|
|
||||||
use bevnet::{Connection, SendTo, Uuid};
|
// use bevnet::{Connection, SendTo, Uuid};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_egui::{egui, EguiContexts};
|
// use bevy_egui::{egui, EguiContexts};
|
||||||
|
|
||||||
use crate::networking::connection::RequestJoin;
|
// use crate::networking::connection::RequestJoin;
|
||||||
use crate::networking::PlayerRank;
|
// use crate::networking::PlayerRank;
|
||||||
use crate::ui::hover::HoveredTexture;
|
use crate::ui::hover::HoveredTexture;
|
||||||
use crate::{CurrentScene, Player};
|
use crate::CurrentScene;
|
||||||
|
// use crate::Player;
|
||||||
|
|
||||||
/// The plugin for the menu.
|
/// The plugin for the menu.
|
||||||
pub struct MenuPlugin;
|
pub struct MenuPlugin;
|
||||||
|
@ -26,65 +27,65 @@ struct Host;
|
||||||
struct Join;
|
struct Join;
|
||||||
|
|
||||||
// Display the UI of the menu to host a game or join one.
|
// Display the UI of the menu to host a game or join one.
|
||||||
fn old_menu(
|
// fn old_menu(
|
||||||
mut ctx: EguiContexts,
|
// mut ctx: EguiContexts,
|
||||||
mut connection_string: Local<String>,
|
// mut connection_string: Local<String>,
|
||||||
mut next_scene: ResMut<NextState<CurrentScene>>,
|
// mut next_scene: ResMut<NextState<CurrentScene>>,
|
||||||
mut request_join: EventWriter<SendTo<RequestJoin>>,
|
// mut request_join: EventWriter<SendTo<RequestJoin>>,
|
||||||
mut name: Local<String>,
|
// mut name: Local<String>,
|
||||||
connection: Res<Connection>,
|
// connection: Res<Connection>,
|
||||||
mut commands: Commands,
|
// mut commands: Commands,
|
||||||
) {
|
// ) {
|
||||||
let Some(uuid) = connection.identifier() else {
|
// let Some(uuid) = connection.identifier() else {
|
||||||
return;
|
// return;
|
||||||
};
|
// };
|
||||||
|
|
||||||
egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
// egui::CentralPanel::default().show(ctx.ctx_mut(), |ui| {
|
||||||
ui.heading("Border Wars");
|
// ui.heading("Border Wars");
|
||||||
|
|
||||||
ui.separator();
|
// ui.separator();
|
||||||
|
|
||||||
ui.label("Name");
|
// ui.label("Name");
|
||||||
ui.text_edit_singleline(&mut *name);
|
// ui.text_edit_singleline(&mut *name);
|
||||||
|
|
||||||
ui.separator();
|
// ui.separator();
|
||||||
|
|
||||||
ui.label("Connect to an existing game:");
|
// ui.label("Connect to an existing game:");
|
||||||
ui.horizontal(|ui| {
|
// ui.horizontal(|ui| {
|
||||||
ui.label("Game ID: ");
|
// ui.label("Game ID: ");
|
||||||
ui.text_edit_singleline(&mut *connection_string);
|
// ui.text_edit_singleline(&mut *connection_string);
|
||||||
|
|
||||||
let Ok(game_id) = Uuid::parse_str(&connection_string) else {
|
// let Ok(game_id) = Uuid::parse_str(&connection_string) else {
|
||||||
return;
|
// return;
|
||||||
};
|
// };
|
||||||
|
|
||||||
if ui.button("Join").clicked() {
|
// if ui.button("Join").clicked() {
|
||||||
next_scene.set(CurrentScene::Lobby);
|
// next_scene.set(CurrentScene::Lobby);
|
||||||
request_join.send(SendTo(
|
// request_join.send(SendTo(
|
||||||
game_id,
|
// game_id,
|
||||||
RequestJoin(Player {
|
// RequestJoin(Player {
|
||||||
name: name.clone(),
|
// name: name.clone(),
|
||||||
rank: PlayerRank::Player,
|
// rank: PlayerRank::Player,
|
||||||
uuid,
|
// uuid,
|
||||||
color: rand::random::<(u8, u8, u8)>(),
|
// color: rand::random::<(u8, u8, u8)>(),
|
||||||
}),
|
// }),
|
||||||
));
|
// ));
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
ui.separator();
|
// ui.separator();
|
||||||
|
|
||||||
if ui.button("Create new game").clicked() {
|
// if ui.button("Create new game").clicked() {
|
||||||
next_scene.set(CurrentScene::Lobby);
|
// next_scene.set(CurrentScene::Lobby);
|
||||||
commands.spawn(Player {
|
// commands.spawn(Player {
|
||||||
name: name.clone(),
|
// name: name.clone(),
|
||||||
rank: PlayerRank::Admin,
|
// rank: PlayerRank::Admin,
|
||||||
uuid,
|
// uuid,
|
||||||
color: rand::random::<(u8, u8, u8)>(),
|
// color: rand::random::<(u8, u8, u8)>(),
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|||||||
/// A Component to identify menus entities.
|
/// A Component to identify menus entities.
|
||||||
/// In order to be able to remove them later.
|
/// In order to be able to remove them later.
|
||||||
|
@ -93,6 +94,7 @@ struct MenuEntity;
|
||||||
|
|
||||||
type TargetScene = crate::Scene;
|
type TargetScene = crate::Scene;
|
||||||
|
|
||||||
|
/// Create main element for the menu
|
||||||
fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
// Create the background.
|
// Create the background.
|
||||||
commands
|
commands
|
||||||
|
|
Loading…
Reference in a new issue
Put some comments to tell which élément you are creating