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

@@ -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);

View File

@@ -36,6 +36,7 @@ import static mindustry.Vars.*;
public class ModsDialog extends BaseDialog{
private ObjectMap<String, TextureRegion> textureCache = new ObjectMap<>();
private float modImportProgress;
private String searchtxt = "";
private @Nullable Seq<ModListing> 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");

View File

@@ -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;