Mod import progress bar

This commit is contained in:
Anuken
2021-07-31 10:58:09 -04:00
parent ef92236cb4
commit 1d257c1a35
5 changed files with 17 additions and 8 deletions

View File

@@ -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. 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? quit.confirm = Are you sure you want to quit?
loading = [accent]Loading... loading = [accent]Loading...
reloading = [accent]Reloading Mods... downloading = [accent]Downloading...
saving = [accent]Saving... saving = [accent]Saving...
respawn = [accent][[{0}][] to respawn in core respawn = [accent][[{0}][] to respawn in core
cancelbuilding = [accent][[{0}][] to clear plan cancelbuilding = [accent][[{0}][] to clear plan
@@ -1103,7 +1103,6 @@ unit.reign.name = Reign
unit.vela.name = Vela unit.vela.name = Vela
unit.corvus.name = Corvus unit.corvus.name = Corvus
block.resupply-point.name = Resupply Point
block.parallax.name = Parallax block.parallax.name = Parallax
block.cliff.name = Cliff block.cliff.name = Cliff
block.sand-boulder.name = Sand Boulder 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. liquid.cryofluid.description = Used as coolant in reactors, turrets and factories.
block.derelict = [lightgray] Derelict 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.armored-conveyor.description = Moves items forward. Does not accept inputs from the sides.
block.illuminator.description = Emits light. block.illuminator.description = Emits light.
block.message.description = Stores a message for communication between allies. block.message.description = Stores a message for communication between allies.

View File

@@ -107,8 +107,10 @@ public class Bar extends Element{
} }
Draw.colorl(0.1f); Draw.colorl(0.1f);
Draw.alpha(parentAlpha);
bar.draw(x, y, width, height); bar.draw(x, y, width, height);
Draw.color(color, blinkColor, blink); Draw.color(color, blinkColor, blink);
Draw.alpha(parentAlpha);
Drawable top = Tex.barTop; Drawable top = Tex.barTop;
float topWidth = width * value; float topWidth = width * value;
@@ -128,7 +130,7 @@ public class Bar extends Element{
GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new); GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
lay.setText(font, name); 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); font.draw(name, x + width / 2f - lay.width / 2f, y + height / 2f + lay.height / 2f + 1);
Pools.free(lay); Pools.free(lay);

View File

@@ -36,6 +36,7 @@ import static mindustry.Vars.*;
public class ModsDialog extends BaseDialog{ public class ModsDialog extends BaseDialog{
private ObjectMap<String, TextureRegion> textureCache = new ObjectMap<>(); private ObjectMap<String, TextureRegion> textureCache = new ObjectMap<>();
private float modImportProgress;
private String searchtxt = ""; private String searchtxt = "";
private @Nullable Seq<ModListing> modList; private @Nullable Seq<ModListing> modList;
private boolean orderDate = false; private boolean orderDate = false;
@@ -488,11 +489,16 @@ public class ModsDialog extends BaseDialog{
private void handleMod(String repo, HttpResponse result){ private void handleMod(String repo, HttpResponse result){
try{ try{
Fi file = tmpDirectory.child(repo.replace("/", "") + ".zip"); 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); var mod = mods.importMod(file);
mod.setRepo(repo); mod.setRepo(repo);
file.delete(); file.delete();
Core.app.post(() -> { Core.app.post(() -> {
try{ try{
setup(); setup();
ui.loadfrag.hide(); ui.loadfrag.hide();
@@ -510,10 +516,13 @@ public class ModsDialog extends BaseDialog{
} }
private void githubImportMod(String repo, boolean isJava){ private void githubImportMod(String repo, boolean isJava){
modImportProgress = 0f;
ui.loadfrag.show("@downloading");
ui.loadfrag.setProgress(() -> modImportProgress);
if(isJava){ if(isJava){
githubImportJavaMod(repo); githubImportJavaMod(repo);
}else{ }else{
ui.loadfrag.show();
Http.get(ghApi + "/repos/" + repo, res -> { Http.get(ghApi + "/repos/" + repo, res -> {
var json = Jval.read(res.getResultAsString()); var json = Jval.read(res.getResultAsString());
String mainBranch = json.getString("default_branch"); String mainBranch = json.getString("default_branch");

View File

@@ -38,7 +38,7 @@ public class LoadingFragment extends Fragment{
text("@loading"); 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(); t.row();
button = t.button("@cancel", () -> {}).pad(20).size(250f, 70f).visible(false).get(); button = t.button("@cancel", () -> {}).pad(20).size(250f, 70f).visible(false).get();
table = t; table = t;

View File

@@ -8,4 +8,4 @@ kapt.include.compile.classpath=false
kotlin.stdlib.default.dependency=false kotlin.stdlib.default.dependency=false
#needed for android compilation #needed for android compilation
android.useAndroidX=true android.useAndroidX=true
archash=94dd6bbd29ea8e71daffaabb530bb7697017d66d archash=8d15f16848ae0b2a94e38e63be965fdeb9e51f54