Merge pull request #2618 from ludovic111/feat/launcher-export-ui
🤖 Agent: launcher-features-1: base main, merge-tree clean against main, CI verify + launcher green; queued.
This commit is contained in:
@@ -83,6 +83,15 @@ The opening, then Play ([clip](docs/opening.webm)):
|
||||
instance plays the launcher's version, which follows updates, unless the Play page's version
|
||||
picker keeps it on another installed one (to keep an old world on the version it was made
|
||||
with); picking the version marked "follows updates" lets it follow again.
|
||||
- **Export**: Home's Instance row has **Export…**: the selected instance (or a port) as a `.mrpack`
|
||||
(Modrinth's modpack format: resource packs the browser installed from Modrinth are listed by
|
||||
their download, the rest is in `overrides/`) or a `.zip` of the game folder's layout, with the
|
||||
worlds switched on. It is written to `exports/` in the launcher's data folder (**Show in
|
||||
folder**). Only settings (options.txt, horizon-*.txt, servers.dat), resource and shader packs,
|
||||
`horizon-mods/` and `config/` go in: never logs, screenshots, backups, caches or account files;
|
||||
a world goes without `playerdata/`, `stats/` and `advancements/`, and its level.dat without the
|
||||
player's UUID. `horizon-launcher instance export [<instance>] [--format mrpack|zip] [--world
|
||||
<w>]… [--out <file>]`.
|
||||
- **Worlds**: Home lists the selected instance's worlds (picture, mode, version, last played,
|
||||
size). **Back up** zips one into the instance's `backups/` as the game's Make Backup does
|
||||
(`<date>_<time>_<folder>.zip`); **Copy** puts "<name> (1)" beside it; **Delete** moves it to the
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
//! Export… on Home's Instance row: the selected instance as a `.mrpack` or a `.zip`, with the
|
||||
//! worlds the player switches on, written to the launcher's `exports/` folder
|
||||
//! (`horizon_launcher::export`).
|
||||
use super::*;
|
||||
use horizon_launcher::export::{self, Format};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub(super) struct ExportPanel {
|
||||
/// The instance it is for: picking another closes it.
|
||||
instance: String,
|
||||
format: Format,
|
||||
/// The instance's worlds (folder, name) and whether each goes in.
|
||||
worlds: Vec<(String, String, bool)>,
|
||||
busy: bool,
|
||||
/// The file written, or why not.
|
||||
done: Option<Result<(String, PathBuf), String>>,
|
||||
}
|
||||
|
||||
impl Launcher {
|
||||
pub(super) fn toggle_export(&mut self) {
|
||||
if self.export.take().is_some() {
|
||||
return;
|
||||
}
|
||||
let Some(i) = self.selected_instance() else {
|
||||
return;
|
||||
};
|
||||
let worlds = horizon_launcher::worlds::list(&i.home)
|
||||
.into_iter()
|
||||
.map(|w| (w.folder, w.name, false))
|
||||
.collect();
|
||||
self.export = Some(ExportPanel {
|
||||
instance: i.id.clone(),
|
||||
format: Format::Mrpack,
|
||||
worlds,
|
||||
busy: false,
|
||||
done: None,
|
||||
});
|
||||
}
|
||||
|
||||
fn run_export(&mut self, cx: &mut Context<Self>) {
|
||||
let Some(i) = self.selected_instance().cloned() else {
|
||||
return;
|
||||
};
|
||||
let Some(panel) = self.export.as_mut().filter(|p| !p.busy) else {
|
||||
return;
|
||||
};
|
||||
panel.busy = true;
|
||||
panel.done = None;
|
||||
let format = panel.format;
|
||||
let worlds: Vec<String> = panel
|
||||
.worlds
|
||||
.iter()
|
||||
.filter(|w| w.2)
|
||||
.map(|w| w.0.clone())
|
||||
.collect();
|
||||
let task = cx.background_executor().spawn(async move {
|
||||
let linked = match format {
|
||||
Format::Mrpack => export::linkable(&i.home, &export::from_modrinth),
|
||||
Format::Zip => Vec::new(),
|
||||
};
|
||||
let out = export::free_path(&backend::data_dir().join("exports"), &i.name, format);
|
||||
export::export(&i.home, &i.name, format, &worlds, &linked, &out).map(|done| {
|
||||
let linked = match done.linked {
|
||||
0 => String::new(),
|
||||
n => format!(", {n} listed by their Modrinth download"),
|
||||
};
|
||||
let file = done.path.file_name().unwrap_or_default().to_string_lossy();
|
||||
(
|
||||
format!("Exported {file}: {} files{linked}.", done.copied),
|
||||
done.path,
|
||||
)
|
||||
})
|
||||
});
|
||||
cx.spawn(async move |this, cx| {
|
||||
let done = task.await;
|
||||
let _ = this.update(cx, |this, cx| {
|
||||
if let Some(panel) = &mut this.export {
|
||||
panel.busy = false;
|
||||
panel.done = Some(done);
|
||||
}
|
||||
cx.notify();
|
||||
});
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
/// The panel under the Instance row, while it is open.
|
||||
pub(super) fn export_panel(&mut self, cx: &mut Context<Self>) -> Option<Div> {
|
||||
let t = self.theme;
|
||||
let selected = self.selected_instance()?.id.clone();
|
||||
if self.export.as_ref()?.instance != selected {
|
||||
self.export = None;
|
||||
return None;
|
||||
}
|
||||
let panel = self.export.as_ref()?;
|
||||
let formats = [(Format::Mrpack, ".mrpack"), (Format::Zip, ".zip")];
|
||||
let mut pick = div().flex().items_center().gap(px(6.));
|
||||
for (format, label) in formats {
|
||||
let on = panel.format == format;
|
||||
pick = pick.child(
|
||||
button(
|
||||
SharedString::from(format!("export-{}", format.extension())),
|
||||
label,
|
||||
if on { Kind::Secondary } else { Kind::Ghost },
|
||||
&t,
|
||||
)
|
||||
.when(on, |b| b.border_color(t.accent))
|
||||
.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
|
||||
if let Some(p) = &mut this.export {
|
||||
p.format = format;
|
||||
}
|
||||
cx.notify();
|
||||
})),
|
||||
);
|
||||
}
|
||||
let about = match panel.format {
|
||||
Format::Mrpack => {
|
||||
"Modrinth's modpack format: resource packs from Modrinth are listed by their \
|
||||
download, the rest is carried in it."
|
||||
}
|
||||
Format::Zip => "The game folder's own layout, zipped.",
|
||||
};
|
||||
let mut worlds = div().flex().flex_col().gap(px(6.));
|
||||
if panel.worlds.is_empty() {
|
||||
worlds = worlds.child(
|
||||
text(theme::CAPTION)
|
||||
.text_color(t.muted)
|
||||
.child("No worlds to put in."),
|
||||
);
|
||||
}
|
||||
for (n, (_, name, on)) in panel.worlds.iter().enumerate() {
|
||||
worlds = worlds.child(
|
||||
div()
|
||||
.id(SharedString::from(format!("export-world-{n}")))
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(10.))
|
||||
.cursor_pointer()
|
||||
.child(switch(
|
||||
SharedString::from(format!("export-world-switch-{n}")),
|
||||
*on,
|
||||
&t,
|
||||
))
|
||||
.child(
|
||||
text(theme::LABEL)
|
||||
.text_color(t.ink_soft)
|
||||
.child(name.clone()),
|
||||
)
|
||||
.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
|
||||
if let Some(w) = this.export.as_mut().and_then(|p| p.worlds.get_mut(n)) {
|
||||
w.2 = !w.2;
|
||||
}
|
||||
cx.notify();
|
||||
})),
|
||||
);
|
||||
}
|
||||
let go = button("export-run", "Export", Kind::Secondary, &t);
|
||||
let go = match panel.busy {
|
||||
true => disabled(go),
|
||||
false => go.on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
|
||||
this.run_export(cx);
|
||||
cx.notify();
|
||||
})),
|
||||
};
|
||||
let result = match &panel.done {
|
||||
Some(Ok((said, path))) => {
|
||||
let path = path.clone();
|
||||
Some(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(10.))
|
||||
.child(text(theme::CAPTION).text_color(t.muted).child(said.clone()))
|
||||
.child(
|
||||
button("export-show", "Show in folder", Kind::Ghost, &t)
|
||||
.on_click(move |_, _, cx| cx.reveal_path(&path)),
|
||||
),
|
||||
)
|
||||
}
|
||||
Some(Err(e)) => Some(div().child(notice(e.clone(), &t))),
|
||||
None => None,
|
||||
};
|
||||
Some(
|
||||
plate(&t)
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap(px(12.))
|
||||
.px(px(14.))
|
||||
.py(px(12.))
|
||||
.ml(px(40.))
|
||||
.child(caps("Export to share").text_color(t.muted))
|
||||
.child(pick)
|
||||
.child(text(theme::CAPTION).text_color(t.muted).child(about))
|
||||
.child(caps("Worlds").text_color(t.muted))
|
||||
.child(worlds)
|
||||
.child(text(theme::CAPTION).text_color(t.muted).child(
|
||||
"Settings, packs and Horizon mods go in; logs, screenshots, backups and \
|
||||
your account never do. Worlds go without their per-player files.",
|
||||
))
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(10.))
|
||||
.child(go)
|
||||
.when(panel.busy, |d| {
|
||||
d.child(text(theme::CAPTION).text_color(t.muted).child("Exporting…"))
|
||||
}),
|
||||
)
|
||||
.children(result),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -541,7 +541,8 @@ impl Launcher {
|
||||
)
|
||||
}
|
||||
|
||||
/// The Play page's row for the selected instance: its folder, and changing or copying it.
|
||||
/// The Play page's row for the selected instance: its folder, and changing, copying or
|
||||
/// exporting it.
|
||||
pub(super) fn instance_row(&mut self, n: usize, cx: &mut Context<Self>) -> Option<Div> {
|
||||
let t = self.theme;
|
||||
let instance = self.selected_instance()?.clone();
|
||||
@@ -573,6 +574,22 @@ impl Launcher {
|
||||
},
|
||||
)),
|
||||
)
|
||||
.child(
|
||||
button(
|
||||
"instance-export",
|
||||
if self.export.is_some() {
|
||||
"Close export"
|
||||
} else {
|
||||
"Export…"
|
||||
},
|
||||
Kind::Ghost,
|
||||
&t,
|
||||
)
|
||||
.on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
|
||||
this.toggle_export();
|
||||
cx.notify();
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
button("instance-folder", "Open folder", Kind::Ghost, &t).on_click(
|
||||
move |_, _, cx| {
|
||||
|
||||
@@ -12,6 +12,7 @@ mod collection;
|
||||
mod console;
|
||||
mod cull;
|
||||
mod datapacks_page;
|
||||
mod export_page;
|
||||
mod game_tools;
|
||||
mod instances_page;
|
||||
mod internet;
|
||||
@@ -241,6 +242,7 @@ struct Launcher {
|
||||
screenshots: screenshots_page::Screenshots,
|
||||
game_packs: packs_page::Packs,
|
||||
world_packs: datapacks_page::WorldPacks,
|
||||
export: Option<export_page::ExportPanel>,
|
||||
/// The name the game made up for an offline player (`horizon-player.txt`), for the top bar.
|
||||
offline_name: Option<String>,
|
||||
/// The player's servers, for the sidebar until the Servers page has read them.
|
||||
@@ -405,6 +407,7 @@ impl Launcher {
|
||||
screenshots: screenshots_page::Screenshots::default(),
|
||||
game_packs: packs_page::Packs::default(),
|
||||
world_packs: datapacks_page::WorldPacks::default(),
|
||||
export: None,
|
||||
offline_name: offline_name(),
|
||||
side_servers: horizon_launcher::servers::list(),
|
||||
art: art::Art::default(),
|
||||
@@ -2109,6 +2112,7 @@ impl Launcher {
|
||||
.flex_col()
|
||||
.child(section_title("Ready to play", "check", &t).mb(px(12.)))
|
||||
.children(self.instance_row(1, cx))
|
||||
.children(self.export_panel(cx))
|
||||
.child(index_row(
|
||||
2,
|
||||
"Resources",
|
||||
|
||||
Reference in New Issue
Block a user