Fixed #11532
This commit is contained in:
@@ -239,10 +239,10 @@ public class Effect{
|
|||||||
|
|
||||||
Decal decal = Decal.create();
|
Decal decal = Decal.create();
|
||||||
decal.set(x, y);
|
decal.set(x, y);
|
||||||
decal.rotation(rotation);
|
decal.rotation = rotation;
|
||||||
decal.lifetime(lifetime);
|
decal.lifetime = lifetime;
|
||||||
decal.color().set(color);
|
decal.color.set(color);
|
||||||
decal.region(region);
|
decal.region = region;
|
||||||
decal.add();
|
decal.add();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ public class ModsDialog extends BaseDialog{
|
|||||||
private ObjectMap<String, TextureRegion> textureCache = new ObjectMap<>();
|
private ObjectMap<String, TextureRegion> textureCache = new ObjectMap<>();
|
||||||
|
|
||||||
private float modImportProgress;
|
private float modImportProgress;
|
||||||
|
private boolean cancelledImport;
|
||||||
private String searchtxt = "";
|
private String searchtxt = "";
|
||||||
private @Nullable Seq<ModListing> modList;
|
private @Nullable Seq<ModListing> modList;
|
||||||
private boolean orderDate = true;
|
private boolean orderDate = true;
|
||||||
@@ -643,9 +644,14 @@ public class ModsDialog extends BaseDialog{
|
|||||||
Floatc cons = len <= 0 ? f -> {} : p -> modImportProgress = p;
|
Floatc cons = len <= 0 ? f -> {} : p -> modImportProgress = p;
|
||||||
|
|
||||||
try(var stream = file.write(false)){
|
try(var stream = file.write(false)){
|
||||||
Streams.copyProgress(result.getResultAsStream(), stream, len, 4096, cons);
|
Streams.copyProgress(result.getResultAsStream(), stream, len, 4096, p -> {
|
||||||
|
if(cancelledImport) throw new RuntimeException("cancelled");
|
||||||
|
cons.get(p);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(cancelledImport) return;
|
||||||
|
|
||||||
var mod = mods.importMod(file);
|
var mod = mods.importMod(file);
|
||||||
mod.setRepo(repo);
|
mod.setRepo(repo);
|
||||||
file.delete();
|
file.delete();
|
||||||
@@ -659,6 +665,7 @@ public class ModsDialog extends BaseDialog{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}catch(Throwable e){
|
}catch(Throwable e){
|
||||||
|
if(cancelledImport) return;
|
||||||
modError(e);
|
modError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -673,13 +680,19 @@ public class ModsDialog extends BaseDialog{
|
|||||||
|
|
||||||
public void githubImportMod(String repo, boolean isJava, @Nullable String release){
|
public void githubImportMod(String repo, boolean isJava, @Nullable String release){
|
||||||
modImportProgress = 0f;
|
modImportProgress = 0f;
|
||||||
|
cancelledImport = false;
|
||||||
ui.loadfrag.show("@downloading");
|
ui.loadfrag.show("@downloading");
|
||||||
ui.loadfrag.setProgress(() -> modImportProgress);
|
ui.loadfrag.setProgress(() -> modImportProgress);
|
||||||
|
ui.loadfrag.setButton(() -> {
|
||||||
|
ui.loadfrag.hide();
|
||||||
|
cancelledImport = true;
|
||||||
|
});
|
||||||
|
|
||||||
if(isJava){
|
if(isJava){
|
||||||
githubImportJavaMod(repo, release);
|
githubImportJavaMod(repo, release);
|
||||||
}else{
|
}else{
|
||||||
Http.get(ghApi + "/repos/" + repo, res -> {
|
Http.get(ghApi + "/repos/" + repo, res -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
var json = Jval.read(res.getResultAsString());
|
var json = Jval.read(res.getResultAsString());
|
||||||
String mainBranch = json.getString("default_branch");
|
String mainBranch = json.getString("default_branch");
|
||||||
String language = json.getString("language", "<none>");
|
String language = json.getString("language", "<none>");
|
||||||
@@ -708,6 +721,7 @@ public class ModsDialog extends BaseDialog{
|
|||||||
private void githubImportJavaMod(String repo, @Nullable String release){
|
private void githubImportJavaMod(String repo, @Nullable String release){
|
||||||
//grab latest release
|
//grab latest release
|
||||||
Http.get(ghApi + "/repos/" + repo + "/releases/" + (release == null ? "latest" : release), res -> {
|
Http.get(ghApi + "/repos/" + repo + "/releases/" + (release == null ? "latest" : release), res -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
var json = Jval.read(res.getResultAsString());
|
var json = Jval.read(res.getResultAsString());
|
||||||
var assets = json.get("assets").asArray();
|
var assets = json.get("assets").asArray();
|
||||||
|
|
||||||
@@ -719,7 +733,10 @@ public class ModsDialog extends BaseDialog{
|
|||||||
//grab actual file
|
//grab actual file
|
||||||
var url = asset.getString("browser_download_url");
|
var url = asset.getString("browser_download_url");
|
||||||
|
|
||||||
Http.get(url, result -> handleMod(repo, result), this::importFail);
|
Http.get(url, result -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
|
handleMod(repo, result);
|
||||||
|
}, this::importFail);
|
||||||
}else{
|
}else{
|
||||||
throw new ArcRuntimeException("No JAR file found in releases. Make sure you have a valid jar file in the mod's latest Github Release.");
|
throw new ArcRuntimeException("No JAR file found in releases. Make sure you have a valid jar file in the mod's latest Github Release.");
|
||||||
}
|
}
|
||||||
@@ -729,10 +746,13 @@ public class ModsDialog extends BaseDialog{
|
|||||||
private void githubImportBranch(String branch, String repo, @Nullable String release){
|
private void githubImportBranch(String branch, String repo, @Nullable String release){
|
||||||
if(release != null) {
|
if(release != null) {
|
||||||
Http.get(ghApi + "/repos/" + repo + "/releases/" + release, res -> {
|
Http.get(ghApi + "/repos/" + repo + "/releases/" + release, res -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
String zipUrl = Jval.read(res.getResultAsString()).getString("zipball_url");
|
String zipUrl = Jval.read(res.getResultAsString()).getString("zipball_url");
|
||||||
Http.get(zipUrl, loc -> {
|
Http.get(zipUrl, loc -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
if(loc.getHeader("Location") != null){
|
if(loc.getHeader("Location") != null){
|
||||||
Http.get(loc.getHeader("Location"), result -> {
|
Http.get(loc.getHeader("Location"), result -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
handleMod(repo, result);
|
handleMod(repo, result);
|
||||||
}, this::importFail);
|
}, this::importFail);
|
||||||
}else{
|
}else{
|
||||||
@@ -742,8 +762,10 @@ public class ModsDialog extends BaseDialog{
|
|||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
Http.get(ghApi + "/repos/" + repo + "/zipball/" + branch, loc -> {
|
Http.get(ghApi + "/repos/" + repo + "/zipball/" + branch, loc -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
if(loc.getHeader("Location") != null){
|
if(loc.getHeader("Location") != null){
|
||||||
Http.get(loc.getHeader("Location"), result -> {
|
Http.get(loc.getHeader("Location"), result -> {
|
||||||
|
if(cancelledImport) return;
|
||||||
handleMod(repo, result);
|
handleMod(repo, result);
|
||||||
}, this::importFail);
|
}, this::importFail);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import arc.*;
|
|||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.input.*;
|
||||||
import arc.scene.*;
|
import arc.scene.*;
|
||||||
import arc.scene.actions.*;
|
import arc.scene.actions.*;
|
||||||
import arc.scene.event.*;
|
import arc.scene.event.*;
|
||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
|
import arc.util.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
|
|
||||||
@@ -17,6 +19,7 @@ public class LoadingFragment{
|
|||||||
private TextButton button;
|
private TextButton button;
|
||||||
private Bar bar;
|
private Bar bar;
|
||||||
private Label nameLabel;
|
private Label nameLabel;
|
||||||
|
private @Nullable Runnable cancelListener;
|
||||||
private float progValue;
|
private float progValue;
|
||||||
|
|
||||||
public void build(Group parent){
|
public void build(Group parent){
|
||||||
@@ -40,7 +43,16 @@ public class LoadingFragment{
|
|||||||
|
|
||||||
bar = t.add(new Bar()).pad(3).padTop(6).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", () -> {
|
||||||
|
if(cancelListener != null){
|
||||||
|
cancelListener.run();
|
||||||
|
}
|
||||||
|
}).pad(20).size(250f, 70f).visible(false).get();
|
||||||
|
button.keyDown(key -> {
|
||||||
|
if(cancelListener != null && (key == KeyCode.back || key == KeyCode.escape)){
|
||||||
|
cancelListener.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
table = t;
|
table = t;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -68,8 +80,8 @@ public class LoadingFragment{
|
|||||||
|
|
||||||
public void setButton(Runnable listener){
|
public void setButton(Runnable listener){
|
||||||
button.visible = true;
|
button.visible = true;
|
||||||
button.getListeners().remove(button.getListeners().size - 1);
|
button.requestKeyboard();
|
||||||
button.clicked(listener);
|
cancelListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text){
|
public void setText(String text){
|
||||||
@@ -83,6 +95,7 @@ public class LoadingFragment{
|
|||||||
|
|
||||||
public void show(String text){
|
public void show(String text){
|
||||||
button.visible = false;
|
button.visible = false;
|
||||||
|
cancelListener = null;
|
||||||
nameLabel.setColor(Color.white);
|
nameLabel.setColor(Color.white);
|
||||||
bar.visible = false;
|
bar.visible = false;
|
||||||
table.clearActions();
|
table.clearActions();
|
||||||
|
|||||||
Reference in New Issue
Block a user