This commit is contained in:
1 parent
d038cf3670
commit
ba59f57a5a
11 files changed
+466
-156
No files matched your search
@@ -8,6 +8,7 @@ use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
use egui_phosphor_icons::icons;
|
||||
use shared::{SceneComposition, SubsceneReference};
|
||||
|
||||
use crate::native_dialog::NativeDialogBroker;
|
||||
use crate::scene_io::{ComposedSceneMember, SceneIo, SceneIoRequest};
|
||||
use crate::selection::SelectedEntity;
|
||||
|
||||
@@ -195,19 +196,47 @@ fn composition_menu(
|
||||
|
||||
ui.separator();
|
||||
if ui
|
||||
.add_enabled(editing, egui::Button::new("Add Subscene..."))
|
||||
.add_enabled(
|
||||
editing && !world.resource::<NativeDialogBroker>().is_pending(),
|
||||
egui::Button::new("Add Subscene..."),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
match choose_subscene(world, &composition) {
|
||||
Ok(Some(reference)) => {
|
||||
composition.subscenes.push(reference);
|
||||
changed = true;
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(error) => world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status(format!("Add subscene failed: {error}")),
|
||||
}
|
||||
let project_root =
|
||||
PathBuf::from(&world.resource::<crate::project_io::ProjectWorkspace>().root);
|
||||
let directory = project_root.join("assets/levels");
|
||||
let result = world.resource::<NativeDialogBroker>().request(
|
||||
move || {
|
||||
rfd::FileDialog::new()
|
||||
.set_directory(directory)
|
||||
.add_filter("Bevy scene", &["scn.ron", "ron"])
|
||||
.pick_file()
|
||||
},
|
||||
move |world, path| {
|
||||
let Some(path) = path else {
|
||||
world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status("Add subscene cancelled");
|
||||
return;
|
||||
};
|
||||
let current = world.resource::<SceneComposition>().clone();
|
||||
match validate_subscene_choice(&project_root, ¤t, path) {
|
||||
Ok(reference) => {
|
||||
let mut updated = current;
|
||||
updated.subscenes.push(reference);
|
||||
crate::history::set_scene_composition_with_history(world, updated);
|
||||
world.resource_mut::<SceneIo>().set_status("Subscene added");
|
||||
}
|
||||
Err(error) => world
|
||||
.resource_mut::<SceneIo>()
|
||||
.set_status(format!("Add subscene failed: {error}")),
|
||||
}
|
||||
},
|
||||
);
|
||||
world.resource_mut::<SceneIo>().set_status(match result {
|
||||
Ok(()) => "Choose a scene to compose".into(),
|
||||
Err(error) => format!("Add subscene unavailable: {error}"),
|
||||
});
|
||||
}
|
||||
|
||||
if changed {
|
||||
@@ -218,20 +247,14 @@ fn composition_menu(
|
||||
}
|
||||
}
|
||||
|
||||
fn choose_subscene(
|
||||
world: &World,
|
||||
fn validate_subscene_choice(
|
||||
project_root: &Path,
|
||||
composition: &SceneComposition,
|
||||
) -> Result<Option<SubsceneReference>, String> {
|
||||
let project_root = PathBuf::from(&world.resource::<crate::project_io::ProjectWorkspace>().root)
|
||||
path: PathBuf,
|
||||
) -> Result<SubsceneReference, String> {
|
||||
let project_root = project_root
|
||||
.canonicalize()
|
||||
.map_err(|error| format!("could not resolve project root: {error}"))?;
|
||||
let Some(path) = rfd::FileDialog::new()
|
||||
.set_directory(project_root.join("assets/levels"))
|
||||
.add_filter("Bevy scene", &["scn.ron", "ron"])
|
||||
.pick_file()
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let path = path
|
||||
.canonicalize()
|
||||
.map_err(|error| format!("could not resolve {}: {error}", path.display()))?;
|
||||
@@ -251,12 +274,12 @@ fn choose_subscene(
|
||||
{
|
||||
return Err(format!("{relative} is already composed"));
|
||||
}
|
||||
Ok(Some(SubsceneReference {
|
||||
Ok(SubsceneReference {
|
||||
id: uuid::Uuid::new_v4().to_string(),
|
||||
path: relative,
|
||||
visible: true,
|
||||
locked: true,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
fn focus_subscene(world: &mut World, selected: &mut SelectedEntities, reference_id: &str) {
|
||||
|
||||
Reference in new issue
Block a user