From 1d257c1a35003133cd3e46da2650eb51d4bda282 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 31 Jul 2021 10:58:09 -0400 Subject: [PATCH] Mod import progress bar --- core/assets/bundles/bundle.properties | 4 +--- core/src/mindustry/ui/Bar.java | 4 +++- core/src/mindustry/ui/dialogs/ModsDialog.java | 13 +++++++++++-- .../src/mindustry/ui/fragments/LoadingFragment.java | 2 +- gradle.properties | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 49674781a9..91efc5028d 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -317,7 +317,7 @@ data.invalid = This isn't valid game data. data.import.confirm = Importing external data will overwrite[scarlet] all[] your current game data.\n[accent]This cannot be undone![]\n\nOnce the data is imported, your game will exit immediately. quit.confirm = Are you sure you want to quit? loading = [accent]Loading... -reloading = [accent]Reloading Mods... +downloading = [accent]Downloading... saving = [accent]Saving... respawn = [accent][[{0}][] to respawn in core cancelbuilding = [accent][[{0}][] to clear plan @@ -1103,7 +1103,6 @@ unit.reign.name = Reign unit.vela.name = Vela unit.corvus.name = Corvus -block.resupply-point.name = Resupply Point block.parallax.name = Parallax block.cliff.name = Cliff block.sand-boulder.name = Sand Boulder @@ -1407,7 +1406,6 @@ liquid.oil.description = Used in advanced material production and as incendiary liquid.cryofluid.description = Used as coolant in reactors, turrets and factories. block.derelict = [lightgray] Derelict -block.resupply-point.description = Resupplies nearby units with copper ammunition. Not compatible with units that require battery power. block.armored-conveyor.description = Moves items forward. Does not accept inputs from the sides. block.illuminator.description = Emits light. block.message.description = Stores a message for communication between allies. diff --git a/core/src/mindustry/ui/Bar.java b/core/src/mindustry/ui/Bar.java index 6bab3a146d..56760a6673 100644 --- a/core/src/mindustry/ui/Bar.java +++ b/core/src/mindustry/ui/Bar.java @@ -107,8 +107,10 @@ public class Bar extends Element{ } Draw.colorl(0.1f); + Draw.alpha(parentAlpha); bar.draw(x, y, width, height); Draw.color(color, blinkColor, blink); + Draw.alpha(parentAlpha); Drawable top = Tex.barTop; float topWidth = width * value; @@ -128,7 +130,7 @@ public class Bar extends Element{ GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new); lay.setText(font, name); - font.setColor(Color.white); + font.setColor(1f, 1f, 1f, parentAlpha); font.draw(name, x + width / 2f - lay.width / 2f, y + height / 2f + lay.height / 2f + 1); Pools.free(lay); diff --git a/core/src/mindustry/ui/dialogs/ModsDialog.java b/core/src/mindustry/ui/dialogs/ModsDialog.java index abad12a00a..578652fa7b 100644 --- a/core/src/mindustry/ui/dialogs/ModsDialog.java +++ b/core/src/mindustry/ui/dialogs/ModsDialog.java @@ -36,6 +36,7 @@ import static mindustry.Vars.*; public class ModsDialog extends BaseDialog{ private ObjectMap textureCache = new ObjectMap<>(); + private float modImportProgress; private String searchtxt = ""; private @Nullable Seq modList; private boolean orderDate = false; @@ -488,11 +489,16 @@ public class ModsDialog extends BaseDialog{ private void handleMod(String repo, HttpResponse result){ try{ Fi file = tmpDirectory.child(repo.replace("/", "") + ".zip"); - Streams.copy(result.getResultAsStream(), file.write(false)); + long len = result.getContentLength(); + Floatc cons = len <= 0 ? f -> {} : p -> modImportProgress = p; + + Streams.copyProgress(result.getResultAsStream(), file.write(false), len, 4096, cons); + var mod = mods.importMod(file); mod.setRepo(repo); file.delete(); Core.app.post(() -> { + try{ setup(); ui.loadfrag.hide(); @@ -510,10 +516,13 @@ public class ModsDialog extends BaseDialog{ } private void githubImportMod(String repo, boolean isJava){ + modImportProgress = 0f; + ui.loadfrag.show("@downloading"); + ui.loadfrag.setProgress(() -> modImportProgress); + if(isJava){ githubImportJavaMod(repo); }else{ - ui.loadfrag.show(); Http.get(ghApi + "/repos/" + repo, res -> { var json = Jval.read(res.getResultAsString()); String mainBranch = json.getString("default_branch"); diff --git a/core/src/mindustry/ui/fragments/LoadingFragment.java b/core/src/mindustry/ui/fragments/LoadingFragment.java index 902e6ea3ca..a5ab8eeff7 100644 --- a/core/src/mindustry/ui/fragments/LoadingFragment.java +++ b/core/src/mindustry/ui/fragments/LoadingFragment.java @@ -38,7 +38,7 @@ public class LoadingFragment extends Fragment{ text("@loading"); - bar = t.add(new Bar()).pad(3).size(500f, 40f).visible(false).get(); + bar = t.add(new Bar()).pad(3).padTop(6).size(500f, 40f).visible(false).get(); t.row(); button = t.button("@cancel", () -> {}).pad(20).size(250f, 70f).visible(false).get(); table = t; diff --git a/gradle.properties b/gradle.properties index 10c50bb31f..3a906d66ae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,4 +8,4 @@ kapt.include.compile.classpath=false kotlin.stdlib.default.dependency=false #needed for android compilation android.useAndroidX=true -archash=94dd6bbd29ea8e71daffaabb530bb7697017d66d +archash=8d15f16848ae0b2a94e38e63be965fdeb9e51f54