Save/Load file picker dialog

This commit is contained in:
Tobias Berger 2022-11-09 11:55:59 +01:00
parent e7a8101a9e
commit 3e0000a649
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
8 changed files with 281 additions and 648218 deletions

237
Cargo.lock generated
View file

@ -18,6 +18,18 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330223a1aecc308757b9926e9391c9b47f8ef2dbd8aea9df88312aea18c5e8d6" checksum = "330223a1aecc308757b9926e9391c9b47f8ef2dbd8aea9df88312aea18c5e8d6"
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "adler32"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.6"
@ -92,6 +104,25 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "arboard"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc120354d1b5ec6d7aaf4876b602def75595937b5e15d356eb554ab5177e08bb"
dependencies = [
"clipboard-win",
"core-graphics 0.22.3",
"image 0.23.14",
"log",
"objc",
"objc-foundation",
"objc_id",
"parking_lot 0.12.1",
"thiserror",
"winapi",
"x11rb",
]
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.7.2" version = "0.7.2"
@ -301,8 +332,10 @@ version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d365761fd6a5c227b1f88f38b560287334accb69cfe938443e27615464edc897" checksum = "d365761fd6a5c227b1f88f38b560287334accb69cfe938443e27615464edc897"
dependencies = [ dependencies = [
"arboard",
"bevy", "bevy",
"egui", "egui",
"thread_local",
] ]
[[package]] [[package]]
@ -536,7 +569,7 @@ dependencies = [
"futures-lite", "futures-lite",
"hex", "hex",
"hexasphere", "hexasphere",
"image", "image 0.24.4",
"naga", "naga",
"once_cell", "once_cell",
"parking_lot 0.12.1", "parking_lot 0.12.1",
@ -848,6 +881,17 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "clipboard-win"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4ab1b92798304eedc095b53942963240037c0516452cb11aeba709d420b2219"
dependencies = [
"error-code",
"str-buf",
"winapi",
]
[[package]] [[package]]
name = "cocoa" name = "cocoa"
version = "0.24.1" version = "0.24.1"
@ -1008,6 +1052,15 @@ dependencies = [
"objc", "objc",
] ]
[[package]]
name = "crc32fast"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if 1.0.0",
]
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.6" version = "0.5.6"
@ -1079,6 +1132,16 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "deflate"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
dependencies = [
"adler32",
"byteorder",
]
[[package]] [[package]]
name = "dispatch" name = "dispatch"
version = "0.2.0" version = "0.2.0"
@ -1186,6 +1249,16 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "error-code"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21"
dependencies = [
"libc",
"str-buf",
]
[[package]] [[package]]
name = "euclid" name = "euclid"
version = "0.22.7" version = "0.22.7"
@ -1273,6 +1346,16 @@ dependencies = [
"byteorder", "byteorder",
] ]
[[package]]
name = "gethostname"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.8" version = "0.2.8"
@ -1470,6 +1553,22 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "image"
version = "0.23.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"num-iter",
"num-rational 0.3.2",
"num-traits",
"png",
"tiff",
]
[[package]] [[package]]
name = "image" name = "image"
version = "0.24.4" version = "0.24.4"
@ -1479,7 +1578,7 @@ dependencies = [
"bytemuck", "bytemuck",
"byteorder", "byteorder",
"color_quant", "color_quant",
"num-rational", "num-rational 0.4.1",
"num-traits", "num-traits",
] ]
@ -1529,6 +1628,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jpeg-decoder"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.60" version = "0.3.60"
@ -1652,6 +1757,25 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
dependencies = [
"adler32",
]
[[package]]
name = "miniz_oxide"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
dependencies = [
"adler",
"autocfg",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.5" version = "0.8.5"
@ -1801,6 +1925,28 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-iter"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-rational" name = "num-rational"
version = "0.4.1" version = "0.4.1"
@ -1862,6 +2008,17 @@ dependencies = [
"objc_exception", "objc_exception",
] ]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]] [[package]]
name = "objc_exception" name = "objc_exception"
version = "0.1.2" version = "0.1.2"
@ -1871,6 +2028,15 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.16.0" version = "1.16.0"
@ -1984,6 +2150,18 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "png"
version = "0.16.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
dependencies = [
"bitflags",
"crc32fast",
"deflate",
"miniz_oxide 0.3.7",
]
[[package]] [[package]]
name = "pp-rs" name = "pp-rs"
version = "0.2.1" version = "0.2.1"
@ -2263,6 +2441,12 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "str-buf"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
@ -2337,6 +2521,27 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "tiff"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437"
dependencies = [
"jpeg-decoder",
"miniz_oxide 0.4.4",
"weezl",
]
[[package]]
name = "tinyfiledialogs"
version = "3.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e25fa0bc43a6566e2cc6d7ac96df3fa5a57beba34445bead1b368ba8fe9ca568"
dependencies = [
"cc",
"libc",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.5.9" version = "0.5.9"
@ -2631,6 +2836,12 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "weezl"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.13.1" version = "0.13.1"
@ -2750,6 +2961,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "winapi-wsapoll"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
@ -2854,6 +3074,7 @@ dependencies = [
"bevy_egui", "bevy_egui",
"fxhash", "fxhash",
"planet", "planet",
"tinyfiledialogs",
] ]
[[package]] [[package]]
@ -2867,6 +3088,18 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "x11rb"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e99be55648b3ae2a52342f9a870c0e138709a3493261ce9b469afe6e4df6d8a"
dependencies = [
"gethostname",
"nix 0.22.3",
"winapi",
"winapi-wsapoll",
]
[[package]] [[package]]
name = "xcursor" name = "xcursor"
version = "0.3.4" version = "0.3.4"

View file

@ -27,7 +27,7 @@ codegen-units = 1
# bevy/trace_chrome for tracing by function # bevy/trace_chrome for tracing by function
# https://github.com/bevyengine/bevy/blob/main/docs/profiling.md # https://github.com/bevyengine/bevy/blob/main/docs/profiling.md
logging = ["planet/logging"] logging = ["planet/logging"]
render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/x11", "bevy/wayland", "bevy/render", "planet/render", "dep:fxhash", "dep:bevy_egui"] render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/x11", "bevy/wayland", "bevy/render", "planet/render", "dep:fxhash", "dep:bevy_egui", "dep:tinyfiledialogs"]
default = ["render", "logging"] default = ["render", "logging"]
[dependencies.planet] [dependencies.planet]
@ -46,4 +46,8 @@ optional = true
version = "0.16.1" version = "0.16.1"
optional = true optional = true
default-features = false default-features = false
# features = ["manage_clipboard"] # In the future, when I add text input. features = ["manage_clipboard"]
[dependencies.tinyfiledialogs]
version = "3.9.1"
optional = true

648203
planet.ron

File diff suppressed because it is too large Load diff

View file

@ -18,6 +18,7 @@ use {
pub(crate) trait WindowSystem: SystemParam { pub(crate) trait WindowSystem: SystemParam {
fn draw_contents(world: &mut World, state: &mut SystemState<Self>, ui: &mut Ui); fn draw_contents(world: &mut World, state: &mut SystemState<Self>, ui: &mut Ui);
fn name() -> &'static str; fn name() -> &'static str;
fn resizable() -> bool;
} }
pub(crate) fn render_windows(world: &mut World, ctx: &Context) { pub(crate) fn render_windows(world: &mut World, ctx: &Context) {
@ -64,7 +65,7 @@ fn window<S: 'static + WindowSystem>(world: &mut World, ctx: &Context) {
let mut still_open = true; let mut still_open = true;
Window::new(S::name()) Window::new(S::name())
.resizable(false) .resizable(S::resizable())
.open(&mut still_open) .open(&mut still_open)
.title_bar(true) .title_bar(true)
.show(ctx, |ui| { .show(ctx, |ui| {

View file

@ -26,22 +26,34 @@ impl WindowSystem for SaveLoad<'_, '_> {
world.resource_scope(|world, mut should_redraw: Mut<ShouldRedraw>| { world.resource_scope(|world, mut should_redraw: Mut<ShouldRedraw>| {
let mut state = state.get_mut(world); let mut state = state.get_mut(world);
// TODO: Real file selection dialog.
ui.text_edit_singleline(&mut *state.file_name);
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.button("Save").clicked() { if ui.button("Save").clicked() {
if let Err(err) = world_manager.save_world(&*state.file_name) { if let Some(path) = tinyfiledialogs::save_file_dialog_with_filter(
// TODO: Error popup "Save world",
error!("Failed to save: {err:#?}"); state.file_name.as_str(),
&["*.rsplnt", "*.ron"],
"World file",
) {
if let Err(err) = world_manager.save_world(&path) {
// TODO: Error popup
error!("Failed to save: {err:#?}");
}
*state.file_name = path;
} }
} }
if ui.button("Load").clicked() { if ui.button("Load").clicked() {
if let Err(err) = world_manager.load_world(&*state.file_name) { if let Some(path) = tinyfiledialogs::open_file_dialog(
// TODO: Error popup "World file",
error!("Failed to load: {err:#?}"); state.file_name.as_str(),
Some((&["*.ron", "*.rsplnt"], "*.ron,*.rsplnt")),
) {
if let Err(err) = world_manager.load_world(&path) {
// TODO: Error popup
error!("Failed to load: {err:#?}");
}
*state.file_name = path;
should_redraw.0 = true;
} }
should_redraw.0 = true;
} }
}); });
}); });
@ -51,4 +63,8 @@ impl WindowSystem for SaveLoad<'_, '_> {
fn name() -> &'static str { fn name() -> &'static str {
"Save/Load world" "Save/Load world"
} }
fn resizable() -> bool {
true
}
} }

View file

@ -67,4 +67,8 @@ impl WindowSystem for TileInfo<'_, '_> {
fn name() -> &'static str { fn name() -> &'static str {
"Tile Info" "Tile Info"
} }
fn resizable() -> bool {
false
}
} }

View file

@ -37,4 +37,8 @@ impl WindowSystem for WorldOverlaySelection<'_, '_> {
fn name() -> &'static str { fn name() -> &'static str {
"Overlay Selection" "Overlay Selection"
} }
fn resizable() -> bool {
false
}
} }

View file

@ -37,4 +37,8 @@ impl WindowSystem for WorldViewSelection<'_, '_> {
fn name() -> &'static str { fn name() -> &'static str {
"View Selection" "View Selection"
} }
fn resizable() -> bool {
false
}
} }