Unmet dependencies dialog + auto import

This commit is contained in:
MEEPofFaith
2024-04-16 11:36:59 -07:00
parent b8c6781004
commit 331fd2e803
4 changed files with 53 additions and 2 deletions

View File

@@ -183,6 +183,9 @@ mod.preview.missing = Before publishing this mod in the workshop, you must add a
mod.folder.missing = Only mods in folder form can be published on the workshop.\nTo convert any mod into a folder, simply unzip its file into a folder and delete the old zip, then restart your game or reload your mods.
mod.scripts.disable = Your device does not support mods with scripts. You must disable these mods to play the game.
mod.dependencies.error = [scarlet]Mods are missing dependencies
mod.dependencies.download = Download
about.button = About
name = Name:
noname = Pick a[accent] player name[] first.

View File

@@ -2,7 +2,7 @@ package mindustry.mod;
/** Mod listing as a data class. */
public class ModListing{
public String repo, name, subtitle, author, lastUpdated, description, minGameVersion;
public String repo, name, modName, subtitle, author, lastUpdated, description, minGameVersion;
public boolean hasScripts, hasJava;
public String[] contentTypes = {};
public int stars;
@@ -12,6 +12,7 @@ public class ModListing{
return "ModListing{" +
"repo='" + repo + '\'' +
", name='" + name + '\'' +
", modName='" + modName + '\'' +
", author='" + author + '\'' +
", lastUpdated='" + lastUpdated + '\'' +
", description='" + description + '\'' +

View File

@@ -609,7 +609,6 @@ public class Mods implements Loadable{
if(mods.contains(LoadedMod::hasContentErrors)){
ui.loadfrag.hide();
new Dialog(""){{
setFillParent(true);
cont.margin(15);
cont.add("@error.title");
@@ -647,6 +646,46 @@ public class Mods implements Loadable{
cont.button("@ok", this::hide).size(300, 50);
}}.show();
}
//show list of missing dependencies
if(mods.contains(LoadedMod::hasUnmetDependencies)){
ui.loadfrag.hide();
new Dialog(""){{
setFillParent(true);
cont.margin(15);
cont.add("@mod.dependencies.error");
cont.row();
cont.image().width(300f).pad(2).colspan(2).height(4f).color(Color.scarlet);
cont.row();
cont.pane(p -> {
mods.each(LoadedMod::hasUnmetDependencies, mod -> {
p.add(mod.name).wrap().growX().left().get().setAlignment(Align.left);
p.row();
p.table(d -> {
mod.missingDependencies.each(dep -> {
d.add(" - " + dep).wrap().growX().left().get().setAlignment(Align.left);
d.row();
});
}).growX();
p.row();
});
}).fillX();
cont.row();
cont.table(b -> {
b.button("@ok", this::hide).size(150, 50);
b.button("@mod.dependencies.download", () -> {
hide();
Seq<String> missingDeps = new Seq<>();
mods.each(m -> m.enabled() && m.hasUnmetDependencies(), mod -> {
mod.missingDependencies.each(missingDeps::addUnique);
});
ui.mods.importDependencies(missingDeps);
}).size(150, 50);
});
}}.show();
}
}
public boolean hasContentErrors(){

View File

@@ -673,6 +673,14 @@ public class ModsDialog extends BaseDialog{
}
}
public void importDependencies(Seq<String> dependencies){
getModList(listings -> {
listings.each(l -> dependencies.contains(l.modName), l -> {
githubImportMod(l.repo, l.hasJava);
});
});
}
private void githubImportJavaMod(String repo, @Nullable String release){
//grab latest release
Http.get(ghApi + "/repos/" + repo + "/releases/" + (release == null ? "latest" : release), res -> {