Add open dialogs for environments and maps

This commit is contained in:
Tad Hardesty 2018-08-28 21:49:32 -07:00
parent 238d398da2
commit 6df98210c9
3 changed files with 61 additions and 13 deletions

16
Cargo.lock generated
View file

@ -380,6 +380,11 @@ name = "futures"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gcc"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "getopts"
version = "0.2.18"
@ -745,6 +750,14 @@ dependencies = [
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nfd"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nix"
version = "0.11.0"
@ -1120,6 +1133,7 @@ dependencies = [
"imgui-gfx-renderer 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
"lodepng 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ndarray 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"nfd 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1545,6 +1559,7 @@ dependencies = [
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "884dbe32a6ae4cd7da5c6db9b78114449df9953b8d490c9d7e1b51720b922c62"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797"
"checksum gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7d7ce0c1f747245342a73453fdb098ea0764c430421fbc4d98cdc8ef8ede4834"
"checksum gfx_core 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d85039b7bda0348fee728e6787876138839ced69650129ab65aee7ee58fc6367"
@ -1585,6 +1600,7 @@ dependencies = [
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum ndarray 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0e3d24c5ba54015d7d5203ca6f00d4cc16c71042bf7f7be26f091236f390a16a"
"checksum nfd 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8e752e3c216bc8a491c5b59fa46da10f1379ae450b19ac688e07f4bb55042e98"
"checksum nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d37e713a259ff641624b6cb20e3b12b2952313ba36b6823c0f16e6cfd9e5de17"
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
"checksum num-complex 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "b288631d7878aaf59442cffd36910ea604ecd7745c36054328595114001c9656"

View file

@ -18,3 +18,4 @@ imgui = "0.0.20"
imgui-gfx-renderer = "0.0.20"
lodepng = "2.1.5"
ndarray = "0.11.1"
nfd = "0.0.4"

View file

@ -9,6 +9,7 @@ extern crate gfx_device_gl;
extern crate imgui_gfx_renderer;
extern crate lodepng;
extern crate ndarray;
extern crate nfd;
extern crate dreammaker as dm;
extern crate dmm_tools;
@ -155,32 +156,26 @@ impl EditorScene {
ui.main_menu_bar(|| {
ui.menu(im_str!("File")).build(|| {
ui.menu_item(im_str!("Open environment"))
if ui.menu_item(im_str!("Open environment"))
.shortcut(im_str!("Ctrl+Shift+O"))
.enabled(false)
.build();
.build() { self.open_environment(); }
ui.menu(im_str!("Recent environments")).enabled(false).build(|| {
// TODO
});
if ui.menu_item(im_str!("Update environment"))
.shortcut(im_str!("Ctrl+U"))
.build()
{
self.reload_objtree();
}
.build() { self.reload_objtree(); }
ui.separator();
ui.menu_item(im_str!("New"))
.shortcut(im_str!("Ctrl+N"))
.enabled(false)
.build();
ui.menu_item(im_str!("Open"))
if ui.menu_item(im_str!("Open"))
.shortcut(im_str!("Ctrl+O"))
.enabled(false)
.build();
ui.menu_item(im_str!("Close"))
.build() { self.open_map(); }
if ui.menu_item(im_str!("Close"))
.shortcut(im_str!("Ctrl+W"))
.enabled(false)
.build();
.build() { self.close_map(); }
ui.separator();
ui.menu_item(im_str!("Save"))
.shortcut(im_str!("Ctrl+S"))
@ -432,7 +427,10 @@ impl EditorScene {
}
match (ctrl, shift, alt, key) {
// File
k!(Ctrl + Shift + O) => self.open_environment(),
k!(Ctrl + U) => self.reload_objtree(),
k!(Ctrl + O) => self.open_map(),
k!(Ctrl + W) => self.close_map(),
// Layers
k!(Ctrl + Key1) => self.toggle_layer(1),
k!(Ctrl + Key2) => self.toggle_layer(2),
@ -456,6 +454,12 @@ impl EditorScene {
}
}
fn open_environment(&mut self) {
if let Ok(nfd::Response::Okay(fname)) = nfd::open_file_dialog(Some("dme"), None) {
self.load_environment(fname.into());
}
}
fn load_environment(&mut self, path: PathBuf) {
self.environment = Some(path.to_owned());
self.tasks.push(Task::spawn(format!("Loading {}", path.display()), move || {
@ -464,6 +468,33 @@ impl EditorScene {
}));
}
fn open_map(&mut self) {
match nfd::open_file_multiple_dialog(Some("dmm"), None) {
Ok(nfd::Response::Okay(fname)) => {
self.load_map(fname.into());
}
Ok(nfd::Response::OkayMultiple(fnames)) => {
for each in fnames {
// TODO: order these?
self.load_map(each.into());
}
}
_ => {}
}
}
fn load_map(&mut self, path: PathBuf) {
self.tasks.push(Task::spawn(format!("Loading {}", path.display()), move || {
let map = Map::from_file(&path)?;
Ok(TaskResult::Map(map))
}));
}
fn close_map(&mut self) {
// TODO: prompt to save if dirty
self.maps.remove(self.map_current);
}
fn toggle_layer(&mut self, which: usize) {
// TODO: make this faster
self.map_renderer.layers[which] = !self.map_renderer.layers[which];