feat(content): add datapack discovery and world installs
This commit is contained in:
1 parent
a98426e22a
commit
7986bab3a7
27 files changed
+1138
-119
No files matched your search
@@ -30,7 +30,10 @@ pub struct App {
|
||||
pub(super) resource_packs_discovery_state: widgets::content::DiscoveryState,
|
||||
pub(super) shaders_state: widgets::content::list::ContentListState,
|
||||
pub(super) shaders_discovery_state: widgets::content::DiscoveryState,
|
||||
pub(super) datapacks_discovery_state: widgets::content::DiscoveryState,
|
||||
pub(super) worlds_state: widgets::content::list::ContentListState,
|
||||
pub(super) world_datapacks_state: widgets::content::list::ContentListState,
|
||||
pub(super) open_world_datapacks: Option<(String, PathBuf)>,
|
||||
pub(super) world_quick_play_support: Option<(String, String, bool)>,
|
||||
pub(super) screenshots_state: widgets::screenshots_grid::ScreenshotsState,
|
||||
pub(super) logs_state: widgets::logs_viewer::LogsState,
|
||||
@@ -117,11 +120,13 @@ impl App {
|
||||
let mut mods_state = widgets::content::list::ContentListState::default();
|
||||
let mut resource_packs_state = widgets::content::list::ContentListState::default();
|
||||
let mut shaders_state = widgets::content::list::ContentListState::default();
|
||||
let mut world_datapacks_state = widgets::content::list::ContentListState::default();
|
||||
let provider_icon_client = crate::net::HttpClient::new();
|
||||
for state in [
|
||||
&mut mods_state,
|
||||
&mut resource_packs_state,
|
||||
&mut shaders_state,
|
||||
&mut world_datapacks_state,
|
||||
] {
|
||||
state.enable_provider_icons(manager.meta_dir.clone(), provider_icon_client.clone());
|
||||
}
|
||||
@@ -145,7 +150,12 @@ impl App {
|
||||
shaders_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::instance::ContentKind::Shader,
|
||||
),
|
||||
datapacks_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::instance::ContentKind::DataPack,
|
||||
),
|
||||
worlds_state: widgets::content::list::ContentListState::default(),
|
||||
world_datapacks_state,
|
||||
open_world_datapacks: None,
|
||||
world_quick_play_support: None,
|
||||
logs_state: widgets::logs_viewer::LogsState::default(),
|
||||
account_state: widgets::account::AccountState::default(),
|
||||
|
||||
@@ -68,6 +68,29 @@ impl App {
|
||||
discovery.list.request_image_loads(&self.picker);
|
||||
discovery.list.drain_image_loads(&self.picker);
|
||||
}
|
||||
self.datapacks_discovery_state.drain_pending();
|
||||
if self.focused == FocusedArea::Content {
|
||||
orphan_cleanup =
|
||||
orphan_cleanup.or_else(|| self.datapacks_discovery_state.take_orphan_cleanup());
|
||||
}
|
||||
self.datapacks_discovery_state.list.drain_pending();
|
||||
self.datapacks_discovery_state
|
||||
.list
|
||||
.request_image_loads(&self.picker);
|
||||
self.datapacks_discovery_state
|
||||
.list
|
||||
.drain_image_loads(&self.picker);
|
||||
if let Some(popup) = self.datapacks_discovery_state.version_popup.as_mut() {
|
||||
popup.worlds.request_image_loads(&self.picker);
|
||||
popup.worlds.drain_image_loads(&self.picker);
|
||||
}
|
||||
local_streamed |= self.world_datapacks_state.drain_pending();
|
||||
let update = self.world_datapacks_state.drain_watcher();
|
||||
content_changed |= update.requires_reconcile;
|
||||
toggles.extend(update.toggles);
|
||||
self.world_datapacks_state.drain_provider_icons();
|
||||
self.world_datapacks_state.request_image_loads(&self.picker);
|
||||
self.world_datapacks_state.drain_image_loads(&self.picker);
|
||||
if let Some(paths) = orphan_cleanup {
|
||||
widgets::popups::confirm::set_pending_orphan_dependencies(paths);
|
||||
self.focused = FocusedArea::ConfirmDelete;
|
||||
@@ -163,6 +186,7 @@ impl App {
|
||||
&self.mods_discovery_state,
|
||||
&self.resource_packs_discovery_state,
|
||||
&self.shaders_discovery_state,
|
||||
&self.datapacks_discovery_state,
|
||||
]
|
||||
.iter()
|
||||
.filter(|state| state.version_popup.is_some())
|
||||
@@ -212,6 +236,8 @@ impl App {
|
||||
.refresh_installed_manifest(&manifest, &minecraft_dir);
|
||||
self.shaders_discovery_state
|
||||
.refresh_installed_manifest(&manifest, &minecraft_dir);
|
||||
self.datapacks_discovery_state
|
||||
.refresh_installed_manifest(&manifest, &minecraft_dir);
|
||||
self.content_manifest = Some((instance_name, manifest));
|
||||
!complete
|
||||
}
|
||||
@@ -234,6 +260,7 @@ impl App {
|
||||
&mut self.mods_discovery_state,
|
||||
&mut self.resource_packs_discovery_state,
|
||||
&mut self.shaders_discovery_state,
|
||||
&mut self.datapacks_discovery_state,
|
||||
] {
|
||||
discovery.refresh_installed_manifest(
|
||||
&crate::instance::ContentManifest::default(),
|
||||
@@ -301,12 +328,24 @@ impl App {
|
||||
&minecraft_dir,
|
||||
crate::instance::ContentKind::Shader,
|
||||
);
|
||||
self.world_datapacks_state.apply_manifest(
|
||||
&result.manifest,
|
||||
&minecraft_dir,
|
||||
crate::instance::ContentKind::DataPack,
|
||||
);
|
||||
self.mods_discovery_state
|
||||
.refresh_installed_manifest(&result.manifest, &minecraft_dir);
|
||||
self.resource_packs_discovery_state
|
||||
.refresh_installed_manifest(&result.manifest, &minecraft_dir);
|
||||
self.shaders_discovery_state
|
||||
.refresh_installed_manifest(&result.manifest, &minecraft_dir);
|
||||
self.datapacks_discovery_state
|
||||
.refresh_installed_manifest(&result.manifest, &minecraft_dir);
|
||||
for world in &mut self.worlds_state.entries {
|
||||
if let Some(details) = world.world_details.as_mut() {
|
||||
details.datapacks = crate::instance::content::worlds::datapack_names(&world.path);
|
||||
}
|
||||
}
|
||||
self.content_manifest = Some((result.instance_name, result.manifest));
|
||||
}
|
||||
|
||||
@@ -337,6 +376,11 @@ impl App {
|
||||
&minecraft_dir,
|
||||
crate::instance::ContentKind::Shader,
|
||||
);
|
||||
self.world_datapacks_state.apply_manifest(
|
||||
manifest,
|
||||
&minecraft_dir,
|
||||
crate::instance::ContentKind::DataPack,
|
||||
);
|
||||
}
|
||||
|
||||
fn ensure_provider_conflict_popup(&mut self) {
|
||||
|
||||
+113
-19
@@ -306,6 +306,30 @@ impl App {
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
let selecting_world = self
|
||||
.active_discovery_state_mut()
|
||||
.and_then(|state| state.version_popup.as_ref())
|
||||
.is_some_and(|popup| popup.selecting_world);
|
||||
if selecting_world {
|
||||
let minecraft_dir = self.instances_state.selected_instance().map(|instance| {
|
||||
crate::storage::InstancePaths::new(
|
||||
self.instance_manager.instances_dir.join(&instance.name),
|
||||
)
|
||||
.minecraft()
|
||||
});
|
||||
let manifest = self
|
||||
.content_manifest
|
||||
.as_ref()
|
||||
.map(|(_, manifest)| manifest.clone());
|
||||
if let Some(minecraft_dir) = minecraft_dir
|
||||
&& self.active_discovery_state_mut().is_some_and(|state| {
|
||||
state.select_world(manifest.as_ref(), &minecraft_dir)
|
||||
})
|
||||
{
|
||||
self.spawn_active_discovery_dependencies();
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
let confirming = self
|
||||
.active_discovery_state_mut()
|
||||
.and_then(|state| state.version_popup.as_ref())
|
||||
@@ -313,10 +337,13 @@ impl App {
|
||||
if confirming {
|
||||
self.spawn_active_discovery_install();
|
||||
} else {
|
||||
let resolve_dependencies = self
|
||||
.active_discovery_state_mut()
|
||||
.is_some_and(|state| state.kind == crate::instance::ContentKind::Mod);
|
||||
if resolve_dependencies {
|
||||
let kind = self.active_discovery_state_mut().map(|state| state.kind);
|
||||
if kind == Some(crate::instance::ContentKind::DataPack) {
|
||||
let worlds = self.worlds_state.entries.clone();
|
||||
if let Some(state) = self.active_discovery_state_mut() {
|
||||
state.begin_world_selection(worlds);
|
||||
}
|
||||
} else if kind == Some(crate::instance::ContentKind::Mod) {
|
||||
self.spawn_active_discovery_dependencies();
|
||||
} else if let Some(state) = self.active_discovery_state_mut() {
|
||||
state.begin_confirmation();
|
||||
@@ -366,6 +393,36 @@ impl App {
|
||||
return Ok(());
|
||||
}
|
||||
} else if self.content_tab == widgets::content::ContentTab::Worlds {
|
||||
if self.open_world_datapacks.is_some() {
|
||||
if matches!(key_event.code, KeyCode::Esc | KeyCode::Char('h'))
|
||||
&& !self.world_datapacks_state.search.active
|
||||
{
|
||||
self.open_world_datapacks = None;
|
||||
return Ok(());
|
||||
}
|
||||
if key_event.code == KeyCode::Char('d')
|
||||
&& !self.world_datapacks_state.search.active
|
||||
{
|
||||
if let Some(pending) = self.world_datapacks_state.pending_delete() {
|
||||
self.confirm_content_delete(pending);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if widgets::content::list::handle_key_no_toggle(
|
||||
&key_event,
|
||||
&mut self.world_datapacks_state,
|
||||
) {
|
||||
return Ok(());
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if key_event.code == KeyCode::Enter && !self.worlds_state.search.active {
|
||||
self.open_world_datapacks = self
|
||||
.worlds_state
|
||||
.selected_entry()
|
||||
.map(|entry| (entry.name.clone(), entry.path.clone()));
|
||||
return Ok(());
|
||||
}
|
||||
if key_event.code == KeyCode::Char('q') && !self.worlds_state.search.active {
|
||||
if self.selected_instance_supports_quick_play() {
|
||||
let instance = self.instances_state.selected_instance().cloned();
|
||||
@@ -585,15 +642,30 @@ impl App {
|
||||
}
|
||||
KeyCode::Tab if self.focused == FocusedArea::Content => {
|
||||
self.content_mode = self.content_mode.toggle();
|
||||
if self.content_mode == widgets::content::ContentMode::Discover
|
||||
&& !matches!(
|
||||
self.content_tab,
|
||||
self.content_tab = match (self.content_mode, self.content_tab) {
|
||||
(
|
||||
widgets::content::ContentMode::Installed,
|
||||
widgets::content::ContentTab::DataPacks,
|
||||
) => widgets::content::ContentTab::Worlds,
|
||||
(
|
||||
widgets::content::ContentMode::Discover,
|
||||
widgets::content::ContentTab::Worlds,
|
||||
) => widgets::content::ContentTab::DataPacks,
|
||||
(widgets::content::ContentMode::Discover, tab)
|
||||
if !matches!(
|
||||
tab,
|
||||
widgets::content::ContentTab::Mods
|
||||
| widgets::content::ContentTab::ResourcePacks
|
||||
| widgets::content::ContentTab::Shaders
|
||||
| widgets::content::ContentTab::DataPacks
|
||||
) =>
|
||||
{
|
||||
widgets::content::ContentTab::Mods
|
||||
| widgets::content::ContentTab::ResourcePacks
|
||||
| widgets::content::ContentTab::Shaders
|
||||
)
|
||||
{
|
||||
self.content_tab = widgets::content::ContentTab::Mods;
|
||||
}
|
||||
(_, tab) => tab,
|
||||
};
|
||||
if self.content_mode == widgets::content::ContentMode::Discover {
|
||||
self.open_world_datapacks = None;
|
||||
}
|
||||
self.ensure_active_discovery_loaded();
|
||||
}
|
||||
@@ -725,6 +797,7 @@ impl App {
|
||||
Some(&mut self.resource_packs_discovery_state)
|
||||
}
|
||||
widgets::content::ContentTab::Shaders => Some(&mut self.shaders_discovery_state),
|
||||
widgets::content::ContentTab::DataPacks => Some(&mut self.datapacks_discovery_state),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -990,16 +1063,14 @@ impl App {
|
||||
let Some(request) = state.begin_install() else {
|
||||
return;
|
||||
};
|
||||
let destination = self
|
||||
.instance_manager
|
||||
.instances_dir
|
||||
.join(&instance.name)
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join(kind.directory());
|
||||
let instances_dir = self.instance_manager.instances_dir.clone();
|
||||
let instance_paths = crate::storage::InstancePaths::new(instances_dir.join(&instance.name));
|
||||
let manifest_path = instance_paths.content_manifest();
|
||||
let minecraft_dir = instance_paths.minecraft();
|
||||
let destination = match (&request.target_world, kind) {
|
||||
(Some((_, world)), crate::instance::ContentKind::DataPack) => world.join("datapacks"),
|
||||
_ => minecraft_dir.join(kind.directory()),
|
||||
};
|
||||
tokio::spawn(async move {
|
||||
let action = if request.installed_path.is_some() {
|
||||
format!("Changing {} version", request.project_title)
|
||||
@@ -1010,6 +1081,14 @@ impl App {
|
||||
progress.set_sub_action(&request.version.version_number);
|
||||
let client = crate::net::HttpClient::new();
|
||||
let result = async {
|
||||
if kind == crate::instance::ContentKind::DataPack
|
||||
&& (request.target_world.is_none()
|
||||
|| !destination.starts_with(minecraft_dir.join("saves")))
|
||||
{
|
||||
return Err(crate::net::NetError::Parse(
|
||||
"Invalid datapack target world".to_owned(),
|
||||
));
|
||||
}
|
||||
tokio::fs::create_dir_all(&destination)
|
||||
.await
|
||||
.map_err(crate::net::NetError::from)?;
|
||||
@@ -1020,7 +1099,6 @@ impl App {
|
||||
®istry,
|
||||
&manifest_path,
|
||||
&minecraft_dir,
|
||||
&destination,
|
||||
plan,
|
||||
request.request_id,
|
||||
)
|
||||
@@ -1446,6 +1524,7 @@ impl App {
|
||||
self.mods_state.remove_path(path);
|
||||
self.resource_packs_state.remove_path(path);
|
||||
self.shaders_state.remove_path(path);
|
||||
self.world_datapacks_state.remove_path(path);
|
||||
self.worlds_state.remove_path(path);
|
||||
self.screenshots_state.remove_path(path);
|
||||
self.logs_state.remove_path(path);
|
||||
@@ -1453,6 +1532,21 @@ impl App {
|
||||
self.resource_packs_discovery_state
|
||||
.clear_installed_path(path);
|
||||
self.shaders_discovery_state.clear_installed_path(path);
|
||||
self.datapacks_discovery_state.clear_installed_path(path);
|
||||
if path
|
||||
.parent()
|
||||
.and_then(std::path::Path::file_name)
|
||||
.is_some_and(|name| name == "datapacks")
|
||||
&& let Some(world_path) = path.parent().and_then(std::path::Path::parent)
|
||||
&& let Some(world) = self
|
||||
.worlds_state
|
||||
.entries
|
||||
.iter_mut()
|
||||
.find(|world| world.path == world_path)
|
||||
&& let Some(details) = world.world_details.as_mut()
|
||||
{
|
||||
details.datapacks = crate::instance::content::worlds::datapack_names(world_path);
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_content_path_from_manifest(&mut self, path: &std::path::Path) {
|
||||
|
||||
@@ -61,6 +61,23 @@ impl App {
|
||||
&mut self.throbber_state,
|
||||
);
|
||||
let world_quick_play_supported = self.selected_instance_supports_quick_play();
|
||||
if let Some((_, world)) = self.open_world_datapacks.as_ref() {
|
||||
let valid = self
|
||||
.instances_state
|
||||
.selected_instance()
|
||||
.is_some_and(|instance| {
|
||||
world.starts_with(
|
||||
crate::storage::InstancePaths::new(
|
||||
self.instance_manager.instances_dir.join(&instance.name),
|
||||
)
|
||||
.minecraft()
|
||||
.join("saves"),
|
||||
)
|
||||
});
|
||||
if !valid {
|
||||
self.open_world_datapacks = None;
|
||||
}
|
||||
}
|
||||
if load_content {
|
||||
widgets::content::render(
|
||||
frame,
|
||||
@@ -75,7 +92,10 @@ impl App {
|
||||
&mut self.resource_packs_discovery_state,
|
||||
&mut self.shaders_state,
|
||||
&mut self.shaders_discovery_state,
|
||||
&mut self.datapacks_discovery_state,
|
||||
&mut self.worlds_state,
|
||||
&mut self.world_datapacks_state,
|
||||
self.open_world_datapacks.as_ref(),
|
||||
&mut self.screenshots_state,
|
||||
&mut self.logs_state,
|
||||
&self.instance_manager.instances_dir,
|
||||
|
||||
@@ -65,7 +65,12 @@ impl UiHarness {
|
||||
shaders_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::instance::ContentKind::Shader,
|
||||
),
|
||||
datapacks_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::instance::ContentKind::DataPack,
|
||||
),
|
||||
worlds_state: widgets::content::ContentListState::default(),
|
||||
world_datapacks_state: widgets::content::ContentListState::default(),
|
||||
open_world_datapacks: None,
|
||||
world_quick_play_support: None,
|
||||
screenshots_state: {
|
||||
let mut state = widgets::screenshots_grid::ScreenshotsState::default();
|
||||
|
||||
@@ -192,11 +192,79 @@ fn version_popup_switches_to_the_other_provider() {
|
||||
.push(project_entry(project("sodium"), None));
|
||||
state.list.list_state.selected = Some(0);
|
||||
let first = state.begin_versions().unwrap();
|
||||
assert_eq!(first.provider, "modrinth");
|
||||
state.version_popup.as_mut().unwrap().loading = false;
|
||||
let second = state.switch_version_source().unwrap();
|
||||
assert_eq!(second.provider, "curseforge");
|
||||
assert_eq!(state.version_popup.as_ref().unwrap().provider, "curseforge");
|
||||
assert_ne!(second.provider, first.provider);
|
||||
assert_eq!(
|
||||
state.version_popup.as_ref().unwrap().provider,
|
||||
second.provider
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn datapack_versions_select_a_world_before_dependency_resolution() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let minecraft = temp.path().join("minecraft");
|
||||
let world_path = minecraft.join("saves/world-folder");
|
||||
std::fs::create_dir_all(world_path.join("datapacks")).unwrap();
|
||||
let installed = world_path.join("datapacks/project.zip");
|
||||
std::fs::write(&installed, b"zip").unwrap();
|
||||
|
||||
let mut state = DiscoveryState::new(ContentKind::DataPack);
|
||||
state
|
||||
.list
|
||||
.entries
|
||||
.push(project_entry(project("project"), Some(installed.clone())));
|
||||
state.list.list_state.selected = Some(0);
|
||||
let request = state.begin_versions().unwrap();
|
||||
let mut datapack_version = version("1.0.0");
|
||||
datapack_version.loaders = vec!["datapack".to_owned()];
|
||||
DiscoveryState::push_action_result(
|
||||
&request.pending,
|
||||
DiscoveryActionResult::Versions {
|
||||
request_id: request.request_id,
|
||||
project_id: request.project_id,
|
||||
result: Ok(vec![datapack_version]),
|
||||
},
|
||||
);
|
||||
state.drain_pending();
|
||||
|
||||
let world = crate::instance::scan_one_world(&world_path, "world-folder", true);
|
||||
assert!(state.begin_world_selection(vec![world]));
|
||||
let mut manifest = crate::instance::ContentManifest::default();
|
||||
manifest.upsert(crate::instance::ContentFileRecord {
|
||||
relative_path: PathBuf::from("saves/world-folder/datapacks/project.zip"),
|
||||
kind: ContentKind::DataPack,
|
||||
enabled: true,
|
||||
fingerprint: crate::instance::FileFingerprint {
|
||||
size: 3,
|
||||
modified_ns: 1,
|
||||
hashes: Default::default(),
|
||||
},
|
||||
resolution: crate::instance::Resolution::Resolved {
|
||||
project: crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "project".to_owned(),
|
||||
version_id: "old".to_owned(),
|
||||
},
|
||||
},
|
||||
provider_aliases: Vec::new(),
|
||||
required_dependencies: Vec::new(),
|
||||
automatic_dependency: false,
|
||||
cleanup_eligible: false,
|
||||
});
|
||||
|
||||
assert!(state.select_world(Some(&manifest), &minecraft));
|
||||
let dependency = state.begin_dependency_resolution().unwrap();
|
||||
assert_eq!(dependency.root.kind, ContentKind::DataPack);
|
||||
assert_eq!(
|
||||
dependency.root.target_world.as_deref(),
|
||||
Some(world_path.as_path())
|
||||
);
|
||||
assert_eq!(
|
||||
dependency.root.installed_path.as_deref(),
|
||||
Some(installed.as_path())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -354,6 +422,8 @@ fn project_page_loads_for_the_selected_discovery_entry() {
|
||||
icon_url: None,
|
||||
categories: Vec::new(),
|
||||
additional_categories: Vec::new(),
|
||||
project_type: "mod".to_owned(),
|
||||
loaders: Vec::new(),
|
||||
}),
|
||||
},
|
||||
);
|
||||
@@ -521,6 +591,8 @@ fn dependency_resolution_opens_the_existing_confirmation() {
|
||||
title: "Project".to_owned(),
|
||||
version: root_version,
|
||||
installed_path: None,
|
||||
kind: crate::instance::ContentKind::Mod,
|
||||
destination: std::path::PathBuf::from("mods"),
|
||||
provider_aliases: Vec::new(),
|
||||
required_dependencies: Vec::new(),
|
||||
automatic_dependency: false,
|
||||
|
||||
@@ -17,7 +17,7 @@ use super::{
|
||||
ContentListState, WatcherEventHandling, available_description_width, description_text_width,
|
||||
diff_directory, diff_event_paths, ellipsize, load_provider_metadata, read_dir_stems,
|
||||
right_aligned_footer_spans, square_icon_columns, title_suffix_spans, watcher_event_handling,
|
||||
world_game_mode_color,
|
||||
world_descriptions, world_game_mode_color,
|
||||
};
|
||||
|
||||
fn entry(name: &str) -> ContentEntry {
|
||||
@@ -40,6 +40,22 @@ fn entry(name: &str) -> ContentEntry {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn world_cards_preview_up_to_three_datapacks() {
|
||||
let lines = world_descriptions(&WorldDetails {
|
||||
game_mode: None,
|
||||
last_played: None,
|
||||
minecraft_version: Some("1.21.1".to_owned()),
|
||||
size: Some("4.0 MB".to_owned()),
|
||||
datapacks: ["A", "B", "C", "D"]
|
||||
.into_iter()
|
||||
.map(str::to_owned)
|
||||
.collect(),
|
||||
});
|
||||
|
||||
assert_eq!(lines, ["1.21.1 • 4.0 MB", "• A", "• B", "• C", "+1 more"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggling_a_selected_entry_renames_and_updates_it() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
@@ -363,9 +379,10 @@ fn provider_icons_are_requested_only_for_visible_missing_icons() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn embedded_icons_do_not_request_provider_fallbacks() {
|
||||
fn complete_local_pack_metadata_does_not_request_provider_fallbacks() {
|
||||
let mut state = ContentListState::default();
|
||||
let mut visible = entry("Visible");
|
||||
visible.description = "Local description".to_owned();
|
||||
visible.icon_bytes = Some(vec![1, 2, 3]);
|
||||
visible.icon_lines = Some(crate::instance::content::fallback_icon());
|
||||
visible.provider_project = Some(crate::instance::ProviderProject {
|
||||
@@ -457,6 +474,7 @@ fn multiline_rendering_uses_the_space_beside_large_icons() {
|
||||
last_played: None,
|
||||
minecraft_version: Some("1.21.1".to_owned()),
|
||||
size: Some("2.0 MB".to_owned()),
|
||||
datapacks: Vec::new(),
|
||||
});
|
||||
world.icon_lines = Some(crate::instance::content::fallback_icon_large());
|
||||
let mut state = ContentListState::default();
|
||||
@@ -647,6 +665,8 @@ async fn provider_metadata_loads_from_cache_without_network() {
|
||||
icon_url: None,
|
||||
categories: Vec::new(),
|
||||
additional_categories: Vec::new(),
|
||||
project_type: "mod".to_owned(),
|
||||
loaders: Vec::new(),
|
||||
})
|
||||
.unwrap(),
|
||||
)
|
||||
|
||||
@@ -9,14 +9,18 @@ fn mode_labels_have_the_same_rendered_width() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_navigation_only_cycles_downloadable_tabs() {
|
||||
fn discovery_navigation_includes_datapacks() {
|
||||
assert_eq!(
|
||||
ContentTab::Shaders.next_for_mode(ContentMode::Discover),
|
||||
ContentTab::DataPacks
|
||||
);
|
||||
assert_eq!(
|
||||
ContentTab::DataPacks.next_for_mode(ContentMode::Discover),
|
||||
ContentTab::Mods
|
||||
);
|
||||
assert_eq!(
|
||||
ContentTab::Mods.previous_for_mode(ContentMode::Discover),
|
||||
ContentTab::Shaders
|
||||
ContentTab::DataPacks
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,8 +52,11 @@ fn discovery_version_rows_only_show_the_version_number() {
|
||||
|
||||
#[test]
|
||||
fn discovery_confirmation_popup_fits_its_summary() {
|
||||
assert_eq!(version_popup_height(false, None), VERSION_POPUP_HEIGHT);
|
||||
assert_eq!(version_popup_height(true, None), 6);
|
||||
assert_eq!(
|
||||
version_popup_height(false, None, false),
|
||||
VERSION_POPUP_HEIGHT
|
||||
);
|
||||
assert_eq!(version_popup_height(true, None, false), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -92,6 +92,9 @@ pub struct VersionPopupState {
|
||||
pub minecraft_versions: Vec<String>,
|
||||
pub selected_minecraft_version: Option<String>,
|
||||
pub selecting_minecraft_version: bool,
|
||||
pub selecting_world: bool,
|
||||
pub worlds: ContentListState,
|
||||
pub target_world: Option<(String, PathBuf)>,
|
||||
pub versions: Vec<VersionInfo>,
|
||||
pub selected: usize,
|
||||
pub loading: bool,
|
||||
@@ -138,6 +141,8 @@ impl VersionPopupState {
|
||||
fn item_count(&self) -> usize {
|
||||
if self.selecting_minecraft_version {
|
||||
self.minecraft_versions.len()
|
||||
} else if self.selecting_world {
|
||||
self.worlds.filtered_indices().len()
|
||||
} else {
|
||||
self.visible_versions().count()
|
||||
}
|
||||
@@ -180,6 +185,7 @@ pub struct InstallRequest {
|
||||
pub version: VersionInfo,
|
||||
pub installed_path: Option<PathBuf>,
|
||||
pub dependency_plan: Option<crate::instance::content::dependencies::DependencyPlan>,
|
||||
pub target_world: Option<(String, PathBuf)>,
|
||||
pub pending: PendingActions,
|
||||
}
|
||||
|
||||
@@ -413,7 +419,9 @@ impl DiscoveryState {
|
||||
.selected
|
||||
.and_then(|selected| filtered.get(selected))?;
|
||||
let entry = self.list.entries.get(*index)?;
|
||||
let installed_path = entry.installed_path.clone();
|
||||
let installed_path = (self.kind != ContentKind::DataPack)
|
||||
.then(|| entry.installed_path.clone())
|
||||
.flatten();
|
||||
let mut sources = self
|
||||
.sources
|
||||
.get(&entry.file_stem)
|
||||
@@ -436,6 +444,9 @@ impl DiscoveryState {
|
||||
minecraft_versions: Vec::new(),
|
||||
selected_minecraft_version: None,
|
||||
selecting_minecraft_version: self.modpacks,
|
||||
selecting_world: false,
|
||||
worlds: ContentListState::default(),
|
||||
target_world: None,
|
||||
versions: Vec::new(),
|
||||
selected: 0,
|
||||
loading: true,
|
||||
@@ -456,7 +467,7 @@ impl DiscoveryState {
|
||||
pub fn switch_version_source(&mut self) -> Option<VersionsRequest> {
|
||||
let selecting_minecraft_version = self.modpacks;
|
||||
let popup = self.version_popup.as_mut()?;
|
||||
if popup.loading || popup.installing || popup.sources.len() < 2 {
|
||||
if popup.loading || popup.installing || popup.selecting_world || popup.sources.len() < 2 {
|
||||
return None;
|
||||
}
|
||||
popup.source_index = (popup.source_index + 1) % popup.sources.len();
|
||||
@@ -468,6 +479,9 @@ impl DiscoveryState {
|
||||
popup.minecraft_versions.clear();
|
||||
popup.selected_minecraft_version = None;
|
||||
popup.selecting_minecraft_version = selecting_minecraft_version;
|
||||
popup.selecting_world = false;
|
||||
popup.worlds = ContentListState::default();
|
||||
popup.target_world = None;
|
||||
popup.versions.clear();
|
||||
popup.selected = 0;
|
||||
popup.loading = true;
|
||||
@@ -639,6 +653,7 @@ impl DiscoveryState {
|
||||
version,
|
||||
installed_path: popup.installed_path.clone(),
|
||||
dependency_plan: popup.dependency_plan.clone(),
|
||||
target_world: popup.target_world.clone(),
|
||||
pending: self.pending_actions.clone(),
|
||||
};
|
||||
self.version_popup = None;
|
||||
@@ -652,6 +667,7 @@ impl DiscoveryState {
|
||||
if popup.loading
|
||||
|| popup.installing
|
||||
|| popup.selecting_minecraft_version
|
||||
|| popup.selecting_world
|
||||
|| popup.selected_version().is_none()
|
||||
{
|
||||
return false;
|
||||
@@ -661,7 +677,66 @@ impl DiscoveryState {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn begin_world_selection(&mut self, worlds: Vec<ContentEntry>) -> bool {
|
||||
let Some(popup) = self.version_popup.as_mut() else {
|
||||
return false;
|
||||
};
|
||||
if self.kind != ContentKind::DataPack
|
||||
|| popup.loading
|
||||
|| popup.installing
|
||||
|| popup.confirming
|
||||
|| popup.selected_version().is_none()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
popup.worlds = ContentListState::default();
|
||||
popup.worlds.entries = worlds;
|
||||
popup
|
||||
.worlds
|
||||
.list_state
|
||||
.select((!popup.worlds.entries.is_empty()).then_some(0));
|
||||
popup.selecting_world = true;
|
||||
popup.target_world = None;
|
||||
popup.installed_path = None;
|
||||
popup.dependency_plan = None;
|
||||
popup.error = None;
|
||||
true
|
||||
}
|
||||
|
||||
pub fn select_world(
|
||||
&mut self,
|
||||
manifest: Option<&crate::instance::ContentManifest>,
|
||||
minecraft_dir: &std::path::Path,
|
||||
) -> bool {
|
||||
let Some(popup) = self.version_popup.as_mut() else {
|
||||
return false;
|
||||
};
|
||||
if !popup.selecting_world || popup.loading || popup.installing {
|
||||
return false;
|
||||
}
|
||||
let Some(world) = popup.worlds.selected_entry() else {
|
||||
return false;
|
||||
};
|
||||
let world_name = world.name.clone();
|
||||
let world_path = world.path.clone();
|
||||
popup.installed_path = manifest.and_then(|manifest| {
|
||||
popup.sources.iter().find_map(|source| {
|
||||
manifest.resolved_project_path_under(
|
||||
&source.provider,
|
||||
&source.project_id,
|
||||
minecraft_dir,
|
||||
&world_path.join("datapacks"),
|
||||
)
|
||||
})
|
||||
});
|
||||
popup.target_world = Some((world_name, world_path));
|
||||
popup.selecting_world = false;
|
||||
popup.error = None;
|
||||
true
|
||||
}
|
||||
|
||||
pub fn begin_dependency_resolution(&mut self) -> Option<DependencyRequest> {
|
||||
let kind = self.kind;
|
||||
let popup = self.version_popup.as_mut()?;
|
||||
if popup.loading
|
||||
|| popup.installing
|
||||
@@ -683,6 +758,8 @@ impl DiscoveryState {
|
||||
title: popup.project_title.clone(),
|
||||
version,
|
||||
installed_path: popup.installed_path.clone(),
|
||||
kind,
|
||||
target_world: popup.target_world.as_ref().map(|(_, path)| path.clone()),
|
||||
},
|
||||
pending: self.pending_actions.clone(),
|
||||
})
|
||||
@@ -984,6 +1061,8 @@ impl DiscoveryState {
|
||||
pub fn empty_text(&self) -> &str {
|
||||
self.error.as_deref().unwrap_or(if self.modpacks {
|
||||
"No modpacks found."
|
||||
} else if self.kind == ContentKind::DataPack {
|
||||
"No datapacks found."
|
||||
} else {
|
||||
"No projects found."
|
||||
})
|
||||
@@ -1022,6 +1101,21 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut DiscoveryState) -> bool {
|
||||
&& !popup.installing
|
||||
{
|
||||
popup.confirming = false;
|
||||
if popup.target_world.is_some() {
|
||||
popup.selecting_world = true;
|
||||
}
|
||||
popup.error = None;
|
||||
return true;
|
||||
}
|
||||
if popup.selecting_world
|
||||
&& matches!(key_event.code, KeyCode::Left | KeyCode::Char('h'))
|
||||
&& !popup.loading
|
||||
&& !popup.installing
|
||||
{
|
||||
popup.selecting_world = false;
|
||||
popup.target_world = None;
|
||||
popup.installed_path = None;
|
||||
popup.dependency_plan = None;
|
||||
popup.error = None;
|
||||
return true;
|
||||
}
|
||||
@@ -1046,6 +1140,9 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut DiscoveryState) -> bool {
|
||||
}
|
||||
match key_event.code {
|
||||
KeyCode::Esc if !popup.installing => state.version_popup = None,
|
||||
_ if popup.selecting_world => {
|
||||
super::list::handle_key_no_toggle(key_event, &mut popup.worlds);
|
||||
}
|
||||
KeyCode::Char('j') | KeyCode::Down
|
||||
if !popup.loading && !popup.installing && !popup.confirming =>
|
||||
{
|
||||
|
||||
@@ -423,9 +423,8 @@ impl ContentListState {
|
||||
if visible_height == 0 {
|
||||
continue;
|
||||
}
|
||||
if entry.icon_bytes.is_none()
|
||||
if (entry.icon_bytes.is_none() || entry.description.trim().is_empty())
|
||||
&& let Some(project) = entry.provider_project.clone()
|
||||
&& project.provider == "modrinth"
|
||||
{
|
||||
projects.push(project);
|
||||
}
|
||||
@@ -1558,12 +1557,10 @@ pub fn render(
|
||||
theme.text()
|
||||
});
|
||||
|
||||
let world_summary = world_details
|
||||
.map(world_summary)
|
||||
.filter(|line| !line.is_empty());
|
||||
let world_descriptions = world_details.map(world_descriptions);
|
||||
let has_icon = icon_pixels.is_some();
|
||||
let mut descriptions = if let Some(summary) = world_summary.as_deref() {
|
||||
vec![summary]
|
||||
let mut descriptions = if let Some(lines) = world_descriptions.as_ref() {
|
||||
lines.iter().map(String::as_str).collect()
|
||||
} else {
|
||||
metadata
|
||||
.map(|metadata| {
|
||||
@@ -2101,13 +2098,28 @@ fn world_game_mode_color(mode: WorldGameMode) -> Color {
|
||||
}
|
||||
}
|
||||
|
||||
fn world_summary(details: &WorldDetails) -> String {
|
||||
match (&details.minecraft_version, &details.size) {
|
||||
fn world_descriptions(details: &WorldDetails) -> Vec<String> {
|
||||
let summary = match (&details.minecraft_version, &details.size) {
|
||||
(Some(version), Some(size)) => format!("{version} • {size}"),
|
||||
(Some(version), None) => version.clone(),
|
||||
(None, Some(size)) => size.clone(),
|
||||
(None, None) => String::new(),
|
||||
};
|
||||
let mut lines = Vec::with_capacity(5);
|
||||
if !summary.is_empty() {
|
||||
lines.push(summary);
|
||||
}
|
||||
lines.extend(
|
||||
details
|
||||
.datapacks
|
||||
.iter()
|
||||
.take(3)
|
||||
.map(|name| format!("• {name}")),
|
||||
);
|
||||
if details.datapacks.len() > 3 {
|
||||
lines.push(format!("+{} more", details.datapacks.len() - 3));
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
fn title_suffix_spans(
|
||||
|
||||
+166
-11
@@ -4,7 +4,7 @@
|
||||
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::{Alignment, Constraint, Layout, Rect},
|
||||
layout::{Alignment, Constraint, Layout, Margin, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, ListItem, Paragraph, Widget, Wrap},
|
||||
@@ -37,6 +37,7 @@ pub enum ContentTab {
|
||||
Mods,
|
||||
ResourcePacks,
|
||||
Shaders,
|
||||
DataPacks,
|
||||
Screenshots,
|
||||
Worlds,
|
||||
Logs,
|
||||
@@ -56,6 +57,7 @@ impl ContentTab {
|
||||
ContentTab::Mods,
|
||||
ContentTab::ResourcePacks,
|
||||
ContentTab::Shaders,
|
||||
ContentTab::DataPacks,
|
||||
];
|
||||
|
||||
pub fn label(self) -> &'static str {
|
||||
@@ -63,6 +65,7 @@ impl ContentTab {
|
||||
ContentTab::Mods => "Mods",
|
||||
ContentTab::ResourcePacks => "Resource Packs",
|
||||
ContentTab::Shaders => "Shaders",
|
||||
ContentTab::DataPacks => "Datapacks",
|
||||
ContentTab::Screenshots => "Screenshots",
|
||||
ContentTab::Worlds => "Worlds",
|
||||
ContentTab::Logs => "Logs",
|
||||
@@ -160,7 +163,10 @@ pub fn render(
|
||||
resource_packs_discovery_state: &mut DiscoveryState,
|
||||
shaders_state: &mut super::list::ContentListState,
|
||||
shaders_discovery_state: &mut DiscoveryState,
|
||||
datapacks_discovery_state: &mut DiscoveryState,
|
||||
worlds_state: &mut super::list::ContentListState,
|
||||
world_datapacks_state: &mut super::list::ContentListState,
|
||||
open_world_datapacks: Option<&(String, std::path::PathBuf)>,
|
||||
screenshots_state: &mut crate::tui::widgets::screenshots_grid::ScreenshotsState,
|
||||
logs_state: &mut crate::tui::widgets::logs_viewer::LogsState,
|
||||
instances_dir: &std::path::Path,
|
||||
@@ -216,6 +222,10 @@ pub fn render(
|
||||
shaders_discovery_state.search.title_line()
|
||||
}
|
||||
ContentTab::Shaders => shaders_state.search.title_line(),
|
||||
ContentTab::DataPacks => datapacks_discovery_state.search.title_line(),
|
||||
ContentTab::Worlds if open_world_datapacks.is_some() => {
|
||||
world_datapacks_state.search.title_line()
|
||||
}
|
||||
ContentTab::Worlds => worlds_state.search.title_line(),
|
||||
ContentTab::Screenshots => screenshots_state.search.title_line(),
|
||||
ContentTab::Logs => {
|
||||
@@ -257,12 +267,14 @@ pub fn render(
|
||||
ContentTab::Mods => mods_discovery_state.selected_is_installed(),
|
||||
ContentTab::ResourcePacks => resource_packs_discovery_state.selected_is_installed(),
|
||||
ContentTab::Shaders => shaders_discovery_state.selected_is_installed(),
|
||||
ContentTab::DataPacks => false,
|
||||
_ => false,
|
||||
};
|
||||
let discovery_page_open = match tab {
|
||||
ContentTab::Mods => mods_discovery_state.project_page_open(),
|
||||
ContentTab::ResourcePacks => resource_packs_discovery_state.project_page_open(),
|
||||
ContentTab::Shaders => shaders_discovery_state.project_page_open(),
|
||||
ContentTab::DataPacks => datapacks_discovery_state.project_page_open(),
|
||||
_ => false,
|
||||
};
|
||||
let discovery_unavailable = mode == ContentMode::Discover
|
||||
@@ -274,6 +286,9 @@ pub fn render(
|
||||
ContentTab::Shaders => shaders_discovery_state
|
||||
.unavailable_message(instance)
|
||||
.is_some(),
|
||||
ContentTab::DataPacks => datapacks_discovery_state
|
||||
.unavailable_message(instance)
|
||||
.is_some(),
|
||||
_ => false,
|
||||
});
|
||||
|
||||
@@ -320,8 +335,16 @@ pub fn render(
|
||||
("/", " search"),
|
||||
("Tab", " discover"),
|
||||
],
|
||||
(ContentMode::Installed, ContentTab::Worlds) if open_world_datapacks.is_some() => &[
|
||||
("j/k", " navigate"),
|
||||
("d", " delete"),
|
||||
("Shift+Enter", " open dir"),
|
||||
("h/Esc", " back"),
|
||||
("/", " search"),
|
||||
],
|
||||
(ContentMode::Installed, ContentTab::Worlds) if world_quick_play_supported => &[
|
||||
("j/k", " navigate"),
|
||||
("Enter", " datapacks"),
|
||||
("q", " quick launch"),
|
||||
("d", " delete"),
|
||||
("Shift+⏎", " open dir"),
|
||||
@@ -331,12 +354,14 @@ pub fn render(
|
||||
],
|
||||
(ContentMode::Installed, ContentTab::Worlds) => &[
|
||||
("j/k", " navigate"),
|
||||
("Enter", " datapacks"),
|
||||
("d", " delete"),
|
||||
("Shift+⏎", " open dir"),
|
||||
("h/l", " tabs"),
|
||||
("/", " search"),
|
||||
("Tab", " discover"),
|
||||
],
|
||||
(ContentMode::Installed, ContentTab::DataPacks) => &[],
|
||||
(ContentMode::Installed, ContentTab::Screenshots) => &[
|
||||
("Shift+HJKL", " grid"),
|
||||
("⏎", " open"),
|
||||
@@ -418,9 +443,46 @@ pub fn render(
|
||||
return;
|
||||
}
|
||||
|
||||
if tab == ContentTab::DataPacks {
|
||||
if let Some(instance) = instance {
|
||||
if worlds_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let saves = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("saves");
|
||||
worlds_state.start_load(
|
||||
&saves,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_world,
|
||||
"",
|
||||
);
|
||||
worlds_state.watch_dir(saves);
|
||||
}
|
||||
render_discovery(
|
||||
frame,
|
||||
content_area,
|
||||
datapacks_discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching datapacks...",
|
||||
picker,
|
||||
);
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// lazy-load: only scan when switching to an instance that hasn't been loaded yet
|
||||
match tab {
|
||||
ContentTab::Mods | ContentTab::ResourcePacks | ContentTab::Shaders => unreachable!(),
|
||||
ContentTab::Mods
|
||||
| ContentTab::ResourcePacks
|
||||
| ContentTab::Shaders
|
||||
| ContentTab::DataPacks => unreachable!(),
|
||||
ContentTab::Logs => {
|
||||
if let Some(instance) = instance {
|
||||
if logs_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
@@ -461,6 +523,31 @@ pub fn render(
|
||||
}
|
||||
ContentTab::Worlds => {
|
||||
if let Some(instance) = instance {
|
||||
if let Some((world_name, world_path)) = open_world_datapacks {
|
||||
let cache_key = format!("{}:{world_name}", instance.name);
|
||||
let content_dir = world_path.join("datapacks");
|
||||
if world_datapacks_state.loaded_for.as_deref() != Some(cache_key.as_str()) {
|
||||
world_datapacks_state.start_load(
|
||||
&content_dir,
|
||||
&cache_key,
|
||||
crate::instance::scan_one_datapack,
|
||||
".zip",
|
||||
);
|
||||
world_datapacks_state.watch_dir(content_dir);
|
||||
}
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
world_datapacks_state,
|
||||
is_focused,
|
||||
"Loading datapacks...",
|
||||
"No datapacks installed.",
|
||||
picker,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if worlds_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
@@ -627,19 +714,32 @@ fn render_discovery_body(
|
||||
);
|
||||
}
|
||||
if state.version_popup.is_some() {
|
||||
render_version_popup(frame, area, state);
|
||||
render_version_popup(frame, area, state, picker);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
let Some(popup) = state.version_popup.as_ref() else {
|
||||
fn render_version_popup(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
state: &mut DiscoveryState,
|
||||
picker: &ratatui_image::picker::Picker,
|
||||
) {
|
||||
let Some(popup) = state.version_popup.as_mut() else {
|
||||
return;
|
||||
};
|
||||
if popup.selecting_world {
|
||||
render_world_picker(frame, area, popup, picker);
|
||||
return;
|
||||
}
|
||||
let popup_area = area.centered(
|
||||
Constraint::Percentage(50),
|
||||
Constraint::Length(
|
||||
version_popup_height(popup.confirming, popup.dependency_plan.as_ref())
|
||||
.min(area.height.saturating_sub(2)),
|
||||
version_popup_height(
|
||||
popup.confirming,
|
||||
popup.dependency_plan.as_ref(),
|
||||
popup.target_world.is_some(),
|
||||
)
|
||||
.min(area.height.saturating_sub(2)),
|
||||
),
|
||||
);
|
||||
let theme = THEME.as_ref();
|
||||
@@ -669,6 +769,7 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
.unwrap_or_else(|| "Unknown".to_owned());
|
||||
let replacing = popup.installed_path.is_some();
|
||||
let provider_label = popup.provider_label().to_owned();
|
||||
let target_world = popup.target_world.as_ref().map(|(name, _)| name.clone());
|
||||
let dependency_installs = popup
|
||||
.dependency_plan
|
||||
.as_ref()
|
||||
@@ -727,7 +828,7 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
crate::tui::widgets::popups::keybind_line(&keybinds)
|
||||
};
|
||||
|
||||
let popup = crate::tui::widgets::popups::base::PopupFrame {
|
||||
let popup_frame = crate::tui::widgets::popups::base::PopupFrame {
|
||||
title: styled_title(&title, false),
|
||||
border_color: theme.accent(),
|
||||
bg: Some(theme.surface()),
|
||||
@@ -766,6 +867,9 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
("Loader", loaders.as_str()),
|
||||
("Released", release_date.as_str()),
|
||||
];
|
||||
if let Some(world) = target_world.as_deref() {
|
||||
rows.push(("World", world));
|
||||
}
|
||||
if !dependency_installs.is_empty() {
|
||||
rows.push(("Also installs", dependency_installs.as_str()));
|
||||
}
|
||||
@@ -796,20 +900,70 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
}
|
||||
}),
|
||||
};
|
||||
frame.render_widget(popup, popup_area);
|
||||
frame.render_widget(popup_frame, popup_area);
|
||||
}
|
||||
|
||||
fn render_world_picker(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
popup: &mut super::discovery::VersionPopupState,
|
||||
picker: &ratatui_image::picker::Picker,
|
||||
) {
|
||||
let popup_area = area.centered(
|
||||
Constraint::Percentage(50),
|
||||
Constraint::Length(VERSION_POPUP_HEIGHT.min(area.height.saturating_sub(2))),
|
||||
);
|
||||
let theme = THEME.as_ref();
|
||||
let title = popup.title();
|
||||
let provider_label = popup.provider_label().to_owned();
|
||||
let frame_widget = crate::tui::widgets::popups::base::PopupFrame {
|
||||
title: styled_title(&title, false),
|
||||
border_color: theme.accent(),
|
||||
bg: Some(theme.surface()),
|
||||
keybinds: Some(crate::tui::widgets::popups::keybind_line(&[
|
||||
("j/k", " navigate"),
|
||||
("Enter", " continue"),
|
||||
("h", " back"),
|
||||
("Esc", " close"),
|
||||
])),
|
||||
search_line: Some(
|
||||
Line::from(Span::styled(
|
||||
format!(" {provider_label} "),
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
))
|
||||
.alignment(Alignment::Right),
|
||||
),
|
||||
content: Box::new(|_, _| {}),
|
||||
};
|
||||
frame.render_widget(frame_widget, popup_area);
|
||||
super::list::render(
|
||||
frame,
|
||||
popup_area.inner(Margin::new(1, 1)),
|
||||
&mut popup.worlds,
|
||||
true,
|
||||
"Loading worlds...",
|
||||
"No worlds available.",
|
||||
picker,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
fn version_popup_height(
|
||||
confirming: bool,
|
||||
plan: Option<&crate::instance::content::dependencies::DependencyPlan>,
|
||||
has_world: bool,
|
||||
) -> u16 {
|
||||
if !confirming {
|
||||
return VERSION_POPUP_HEIGHT;
|
||||
}
|
||||
let Some(plan) = plan else {
|
||||
return 6;
|
||||
return 6 + u16::from(has_world);
|
||||
};
|
||||
6 + u16::from(plan.dependency_installs().next().is_some())
|
||||
6 + u16::from(has_world)
|
||||
+ u16::from(plan.dependency_installs().next().is_some())
|
||||
+ u16::from(plan.dependency_replacements().next().is_some())
|
||||
+ u16::from(plan.optional_dependencies > 0)
|
||||
}
|
||||
@@ -831,6 +985,7 @@ fn confirmation_loaders(loaders: &[String]) -> String {
|
||||
"neoforge" => "NeoForge",
|
||||
"quilt" => "Quilt",
|
||||
"minecraft" => "Minecraft",
|
||||
"datapack" => "Datapack",
|
||||
other => other,
|
||||
})
|
||||
.map(str::to_owned)
|
||||
|
||||
Reference in new issue
Block a user