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