use super::demo_world::*;
use crate::{site::LoadSite, AppState, Autoload, WorkspaceLoader};
use bevy::{app::AppExit, prelude::*, window::PrimaryWindow};
use bevy_egui::{egui, EguiContexts};
fn egui_ui(
mut egui_context: EguiContexts,
mut _exit: EventWriter<AppExit>,
mut workspace_loader: WorkspaceLoader,
mut _app_state: ResMut<State<AppState>>,
autoload: Option<ResMut<Autoload>>,
primary_windows: Query<Entity, With<PrimaryWindow>>,
) {
if let Some(mut autoload) = autoload {
#[cfg(not(target_arch = "wasm32"))]
{
if let Some(filename) = autoload.filename.take() {
let _ = workspace_loader.load_from_path(filename);
}
}
return;
}
let Some(ctx) = primary_windows
.single()
.ok()
.and_then(|w| egui_context.try_ctx_for_entity_mut(w))
else {
return;
};
egui::Window::new("Welcome!")
.collapsible(false)
.resizable(false)
.title_bar(false)
.anchor(egui::Align2::CENTER_CENTER, egui::vec2(0., 0.))
.show(ctx, |ui| {
ui.heading("Welcome to The RMF Site Editor!");
ui.add_space(10.);
ui.horizontal(|ui| {
if ui.button("View demo map").clicked() {
workspace_loader
.load_site(async move { LoadSite::from_data(&demo_office(), None) });
}
if ui.button("Open a file").clicked() {
workspace_loader.load_from_dialog();
}
if ui.button("Create new file").clicked() {
workspace_loader.create_empty_from_dialog();
}
});
#[cfg(not(target_arch = "wasm32"))]
{
ui.add_space(20.);
ui.horizontal(|ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button("Exit").clicked() {
_exit.write(AppExit::Success);
}
});
});
}
});
}
pub struct MainMenuPlugin;
impl Plugin for MainMenuPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, egui_ui.run_if(in_state(AppState::MainMenu)));
}
}