Skip to content

Commit

Permalink
Merge pull request #55 from Umatriz/loading_fix
Browse files Browse the repository at this point in the history
Automatically decide datapack path. Allow datapacks downloading in the vanilla profiles.
  • Loading branch information
Umatriz authored Jul 21, 2024
2 parents 0169cfa + 9ea90a7 commit 28c8e88
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 53 deletions.
96 changes: 54 additions & 42 deletions crates/client/src/views/mods_manager.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{
collections::{HashMap, HashSet},
path::PathBuf,
path::{Path, PathBuf},
sync::Arc,
};

use eframe::egui::{self, Button, Color32, ComboBox, Id, Image, Key, Layout, RichText, ScrollArea, SelectableLabel, Vec2};
use eframe::egui::{self, Button, Color32, ComboBox, Id, Image, Key, Layout, RichText, ScrollArea, Vec2};
use egui_infinite_scroll::{InfiniteScroll, LoadingState};
use egui_task_manager::{Caller, Task, TaskManager};
use nomi_core::{DOT_NOMI_DATA_PACKS_DIR, MINECRAFT_DIR};
Expand All @@ -19,7 +19,7 @@ use nomi_modding::{
Query,
};
use parking_lot::RwLock;
use tracing::debug;
use tracing::{debug, warn};

use crate::{
collections::{DependenciesCollection, ModsDownloadingCollection, ProjectCollection, ProjectVersionsCollection},
Expand Down Expand Up @@ -190,24 +190,26 @@ impl View for ModManager<'_> {
egui::TopBottomPanel::top("mod_manager_top_panel").show_inside(ui, |ui| {
ui.horizontal(|ui| {
for project_type in ProjectType::iter().filter(|t| !matches!(t, ProjectType::Plugin)) {
if matches!(project_type, ProjectType::Modpack) {
ui.add_enabled(
false,
SelectableLabel::new(false, capitalize_first_letters_whitespace_split(project_type.as_str())),
)
.on_disabled_hover_text("Support for modpacks coming soon!");
continue;
}
let enabled = {
(self.profile.read().profile.loader().is_fabric() || matches!(project_type, ProjectType::DataPack))
&& !matches!(project_type, ProjectType::Modpack)
};

let response = ui.selectable_value(
&mut self.mod_manager_state.current_project_type,
project_type,
capitalize_first_letters_whitespace_split(project_type.as_str()),
);
ui.add_enabled_ui(enabled, |ui| {
let mut response = ui.selectable_value(
&mut self.mod_manager_state.current_project_type,
project_type,
capitalize_first_letters_whitespace_split(project_type.as_str()),
);

if response.clicked() {
self.mod_manager_state.clear_filter()
}
if matches!(project_type, ProjectType::Modpack) {
response = response.on_hover_text("Support for modpacks coming soon!");
}

if response.clicked() {
self.mod_manager_state.clear_filter()
}
});
}

match self.mod_manager_state.current_project_type {
Expand Down Expand Up @@ -428,7 +430,9 @@ impl View for ModManager<'_> {

ui.style_mut().url_in_tooltip = true;

egui::CollapsingHeader::new("Full description").default_open(true).show(ui, |ui| ui.markdown_ui(Id::new("mod_full_description_markdown"), project.body.as_str()));
egui::CollapsingHeader::new("Full description")
.default_open(true)
.show(ui, |ui| ui.markdown_ui(Id::new("mod_full_description_markdown"), project.body.as_str()));

ui.separator();

Expand All @@ -442,7 +446,11 @@ impl View for ModManager<'_> {
.show_ui(ui, |ui| {
for version in &self.mod_manager_state.current_versions {
let response = ui
.selectable_value(&mut self.mod_manager_state.selected_version, Some(version.clone()), version.name.clone())
.selectable_value(
&mut self.mod_manager_state.selected_version,
Some(version.clone()),
version.name.clone(),
)
.on_hover_text(version.version_number.clone());

if response.clicked() {
Expand All @@ -451,16 +459,6 @@ impl View for ModManager<'_> {
}
});

if self.mod_manager_state.is_datapack {
ui.horizontal(|ui| {
ui.heading("ℹ").on_hover_text("While downloading data packs you need to select where it will be downloaded. Because usually data packs are presented as a mods and as a data packs.\nTo understand what are you downloading take a look at the version name in the select menu.\nAdditional information is shown if the variant is hovered.").on_hover_text("If the data pack requires dependencies it is recommended to install them manually.");
ComboBox::from_id_source("select_path").selected_text(format!("{:?}", self.mod_manager_state.data_pack_path)).show_ui(ui, |ui| {
ui.selectable_value(&mut self.mod_manager_state.data_pack_path, DataPackDownloadDirectory::Mods, "Mods directory");
ui.selectable_value(&mut self.mod_manager_state.data_pack_path, DataPackDownloadDirectory::DataPacks, "Data packs directory").on_hover_text("Can be accessed via Open -> Data Packs in the top menu.");
});
});
}

let is_dependencies_loaded = self.task_manager.get_collection::<DependenciesCollection>().tasks().is_empty();

if !is_dependencies_loaded {
Expand Down Expand Up @@ -520,12 +518,13 @@ impl View for ModManager<'_> {
.on_hover_text("This version is featured by the author");
}

let response = ui.selectable_value(&mut val.version, Some(version.clone()), version.name.clone())
let response = ui
.selectable_value(&mut val.version, Some(version.clone()), version.name.clone())
.on_hover_text(version.version_number.clone());

if response.clicked() {
get_dependencies(self.task_manager, &self.profile, version);
}
if response.clicked() {
get_dependencies(self.task_manager, &self.profile, version);
}
});
}
});
Expand Down Expand Up @@ -583,24 +582,37 @@ impl View for ModManager<'_> {

let _ = self.profiles_config.update_config().report_error();
let is_data_pack = self.mod_manager_state.is_datapack;
let data_pack_dir = self.mod_manager_state.data_pack_path.as_path_buf(profile.read().profile.id);
let profile_id = {
let lock = profile.read();
lock.profile.id
};
let download_mod = Task::new(
"Download mods",
Caller::progressing(move |progress| async move {
let mut versions_with_paths = Vec::new();

for (name, version) in versions {
let path = if is_data_pack {
data_pack_dir.clone()
version
.files
.first()
.map(|f| &f.filename)
.and_then(|f| Path::new(f).extension())
.map(|ext| match ext {
ext if ext.eq_ignore_ascii_case("jar") => DataPackDownloadDirectory::Mods,
ext if ext.eq_ignore_ascii_case("zip") => DataPackDownloadDirectory::DataPacks,
_ => {
warn!("Unknown datapack file extension. Using DataPacks directory.");
DataPackDownloadDirectory::DataPacks
}
})
.unwrap_or(DataPackDownloadDirectory::DataPacks)
.as_path_buf(profile_id)
} else {
directory_from_project_type(project_type, profile.read().profile.id)
};

let data = (
version,
path,
name,
);
let data = (version, path, name);
versions_with_paths.push(data);
}

Expand Down
18 changes: 7 additions & 11 deletions crates/client/src/views/profile_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,15 @@ impl View for ProfileInfo<'_> {
open_directory_native(path).report_error();
}
}

if ui
.button("Browse mods")
.on_disabled_hover_text("Profile must have a mod loader.")
.clicked()
{
let kind = TabKind::Mods {
profile: self.profile.clone(),
};
self.tabs_state.0.insert(kind.id(), kind);
}
});

if ui.button("Browse mods").clicked() {
let kind = TabKind::Mods {
profile: self.profile.clone(),
};
self.tabs_state.0.insert(kind.id(), kind);
}

egui::ScrollArea::vertical().min_scrolled_width(ui.available_width()).show(ui, |ui| {
let (mut vec, profile_id) = {
let profile = &mut self.profile.write();
Expand Down

0 comments on commit 28c8e88

Please sign in to comment.