Added github import dialog

This commit is contained in:
Anuken 2019-10-13 17:14:35 -04:00
parent 53c842492a
commit bef8b905de
3 changed files with 29 additions and 25 deletions

View File

@ -338,6 +338,7 @@ public class UI implements ApplicationListener, Loadable{
}
public void showException(String text, Throwable exc){
loadfrag.hide();
new Dialog(""){{
String message = Strings.getFinalMesage(exc);

View File

@ -4,7 +4,6 @@ import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.io.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.mod.Mods.*;
@ -24,9 +23,35 @@ public class ModsDialog extends FloatingDialog{
() -> Core.net.openURI(reportIssueURL))
.size(250f, 64f);
buttons.row();
buttons.addImageTextButton("$mods.guide", Icon.wiki,
() -> Core.net.openURI(modGuideURL))
.size(280f, 64f);
.size(210f, 64f);
buttons.addImageTextButton("$mod.import.github", Icon.github, () -> {
ui.showTextInput("$mod.import.github", "", "Anuken/ExampleMod", text -> {
ui.loadfrag.show();
Core.net.httpGet("http://api.github.com/repos/" + text + "/zipball/master", loc -> {
Core.net.httpGet(loc.getHeader("Location"), result -> {
try{
Streams.copyStream(result.getResultAsStream(), modDirectory.child(text.replace("/", "") + ".zip").write(false));
Core.app.post(() -> {
try{
mods.reloadContent();
setup();
ui.loadfrag.hide();
}catch(Exception e){
ui.showException(e);
}
});
}catch(Exception e){
ui.showException(e);
}
}, t -> Core.app.post(() -> ui.showException(t)));
}, t -> Core.app.post(() -> ui.showException(t)));
});
}).size(250f, 64f);
shown(this::setup);
@ -120,27 +145,5 @@ public class ModsDialog extends FloatingDialog{
}
});
}).margin(12f).width(500f);
//not well tested currently
if(Version.build == -1){
cont.row();
cont.addImageTextButton("$mod.import.github", Icon.github, () -> {
ui.showTextInput("$mod.import.github", "", "Anuken/ExampleMod", text -> {
Core.net.httpGet("http://api.github.com/repos/" + text + "/zipball/master", loc -> {
Core.net.httpGet(loc.getHeader("Location"), result -> {
try{
Streams.copyStream(result.getResultAsStream(), modDirectory.child(text.replace("/", "") + ".zip").write(false));
ui.loadAnd(() -> {
mods.reloadContent();
});
}catch(Exception e){
ui.showException(e);
}
}, ui::showException);
}, ui::showException);
});
}).margin(12f).width(500f);
}
}
}

View File

@ -216,7 +216,7 @@ public class TechTreeDialog extends FloatingDialog{
addListener(new InputListener(){
@Override
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY){
setScale(Mathf.clamp(getScaleX() - amountY / 100f, 0.2f, 1f));
setScale(Mathf.clamp(getScaleX() - amountY / 40f, 0.2f, 1f));
setOrigin(Align.center);
setTransform(true);
return true;