Refactoring of functional package
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
@@ -14,12 +15,12 @@ import io.anuke.mindustry.gen.*;
|
||||
public class Bar extends Element{
|
||||
private static Rectangle scissor = new Rectangle();
|
||||
|
||||
private FloatProvider fraction;
|
||||
private Floatp fraction;
|
||||
private String name = "";
|
||||
private float value, lastValue, blink;
|
||||
private Color blinkColor = new Color();
|
||||
|
||||
public Bar(String name, Color color, FloatProvider fraction){
|
||||
public Bar(String name, Color color, Floatp fraction){
|
||||
this.fraction = fraction;
|
||||
this.name = Core.bundle.get(name);
|
||||
this.blinkColor.set(color);
|
||||
@@ -27,7 +28,7 @@ public class Bar extends Element{
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
public Bar(Supplier<String> name, Supplier<Color> color, FloatProvider fraction){
|
||||
public Bar(Prov<String> name, Prov<Color> color, Floatp fraction){
|
||||
this.fraction = fraction;
|
||||
lastValue = value = Mathf.clamp(fraction.get());
|
||||
update(() -> {
|
||||
@@ -45,7 +46,7 @@ public class Bar extends Element{
|
||||
this.value = lastValue = blink = value;
|
||||
}
|
||||
|
||||
public void set(Supplier<String> name, FloatProvider fraction, Color color){
|
||||
public void set(Prov<String> name, Floatp fraction, Color color){
|
||||
this.fraction = fraction;
|
||||
this.lastValue = fraction.get();
|
||||
this.blinkColor.set(color);
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.anuke.mindustry.ui;
|
||||
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.function.Function;
|
||||
import io.anuke.arc.func.Func;
|
||||
|
||||
/**
|
||||
* A low-garbage way to format bundle strings.
|
||||
@@ -11,13 +11,13 @@ public class IntFormat{
|
||||
private final StringBuilder builder = new StringBuilder();
|
||||
private final String text;
|
||||
private int lastValue = Integer.MIN_VALUE;
|
||||
private Function<Integer, String> converter = String::valueOf;
|
||||
private Func<Integer, String> converter = String::valueOf;
|
||||
|
||||
public IntFormat(String text){
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public IntFormat(String text, Function<Integer, String> converter){
|
||||
public IntFormat(String text, Func<Integer, String> converter){
|
||||
this.text = text;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.arc.function.BooleanProvider;
|
||||
import io.anuke.arc.func.Boolp;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.Element;
|
||||
import io.anuke.arc.scene.ui.Image;
|
||||
@@ -9,9 +9,9 @@ import io.anuke.arc.scene.ui.layout.Scl;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
|
||||
public class ReqImage extends Stack{
|
||||
private final BooleanProvider valid;
|
||||
private final Boolp valid;
|
||||
|
||||
public ReqImage(Element image, BooleanProvider valid){
|
||||
public ReqImage(Element image, Boolp valid){
|
||||
this.valid = valid;
|
||||
add(image);
|
||||
add(new Element(){
|
||||
@@ -30,7 +30,7 @@ public class ReqImage extends Stack{
|
||||
});
|
||||
}
|
||||
|
||||
public ReqImage(TextureRegion region, BooleanProvider valid){
|
||||
public ReqImage(TextureRegion region, Boolp valid){
|
||||
this(new Image(region), valid);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.input.*;
|
||||
@@ -11,7 +12,7 @@ import io.anuke.mindustry.ui.*;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ColorPickDialog extends Dialog{
|
||||
private Consumer<Color> cons;
|
||||
private Cons<Color> cons;
|
||||
|
||||
public ColorPickDialog(){
|
||||
super("");
|
||||
@@ -26,7 +27,7 @@ public class ColorPickDialog extends Dialog{
|
||||
Color color = playerColors[i];
|
||||
|
||||
ImageButton button = table.addImageButton(Tex.whiteui, Styles.clearTogglei, 34, () -> {
|
||||
cons.accept(color);
|
||||
cons.get(color);
|
||||
hide();
|
||||
}).size(48).get();
|
||||
button.setChecked(player.color.equals(color));
|
||||
@@ -44,7 +45,7 @@ public class ColorPickDialog extends Dialog{
|
||||
|
||||
}
|
||||
|
||||
public void show(Consumer<Color> cons){
|
||||
public void show(Cons<Color> cons){
|
||||
this.cons = cons;
|
||||
show();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.scene.style.*;
|
||||
@@ -23,7 +24,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class CustomRulesDialog extends FloatingDialog{
|
||||
private Table main;
|
||||
private Rules rules;
|
||||
private Supplier<Rules> resetter;
|
||||
private Prov<Rules> resetter;
|
||||
private LoadoutDialog loadoutDialog;
|
||||
private FloatingDialog banDialog;
|
||||
|
||||
@@ -108,7 +109,7 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
}).size(300f, 64f);
|
||||
}
|
||||
|
||||
public void show(Rules rules, Supplier<Rules> resetter){
|
||||
public void show(Rules rules, Prov<Rules> resetter){
|
||||
this.rules = rules;
|
||||
this.resetter = resetter;
|
||||
show();
|
||||
@@ -173,16 +174,16 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
number("$rules.enemycorebuildradius", f -> rules.enemyCoreBuildRadius = f * tilesize, () -> Math.min(rules.enemyCoreBuildRadius / tilesize, 200));
|
||||
}
|
||||
|
||||
void number(String text, FloatConsumer cons, FloatProvider prov){
|
||||
void number(String text, Floatc cons, Floatp prov){
|
||||
number(text, false, cons, prov, () -> true);
|
||||
}
|
||||
|
||||
void number(String text, boolean integer, FloatConsumer cons, FloatProvider prov, BooleanProvider condition){
|
||||
void number(String text, boolean integer, Floatc cons, Floatp prov, Boolp condition){
|
||||
main.table(t -> {
|
||||
t.left();
|
||||
t.add(text).left().padRight(5)
|
||||
.update(a -> a.setColor(condition.get() ? Color.white : Color.gray));
|
||||
Vars.platform.addDialog(t.addField((integer ? (int)prov.get() : prov.get()) + "", s -> cons.accept(Strings.parseFloat(s)))
|
||||
Vars.platform.addDialog(t.addField((integer ? (int)prov.get() : prov.get()) + "", s -> cons.get(Strings.parseFloat(s)))
|
||||
.padRight(100f)
|
||||
.update(a -> a.setDisabled(!condition.get()))
|
||||
.valid(Strings::canParsePositiveFloat).width(120f).left().get());
|
||||
@@ -190,11 +191,11 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
main.row();
|
||||
}
|
||||
|
||||
void check(String text, BooleanConsumer cons, BooleanProvider prov){
|
||||
void check(String text, Boolc cons, Boolp prov){
|
||||
check(text, cons, prov, () -> true);
|
||||
}
|
||||
|
||||
void check(String text, BooleanConsumer cons, BooleanProvider prov, BooleanProvider condition){
|
||||
void check(String text, Boolc cons, Boolp prov, Boolp condition){
|
||||
main.addCheck(text, cons).checked(prov.get()).update(a -> a.setDisabled(!condition.get())).padRight(100f).get().left();
|
||||
main.row();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
@@ -234,10 +235,10 @@ public class DeployDialog extends FloatingDialog{
|
||||
if(zone.unlocked() && !hidden(zone)){
|
||||
button.labelWrap(zone.localizedName()).style(Styles.outlineLabel).width(140).growX().get().setAlignment(Align.center);
|
||||
}else{
|
||||
Consumer<Element> flasher = zone.canUnlock() && !hidden(zone) ? e -> e.update(() -> e.getColor().set(Color.white).lerp(Pal.accent, Mathf.absin(3f, 1f))) : e -> {};
|
||||
flasher.accept(button.addImage(Icon.locked).get());
|
||||
Cons<Element> flasher = zone.canUnlock() && !hidden(zone) ? e -> e.update(() -> e.getColor().set(Color.white).lerp(Pal.accent, Mathf.absin(3f, 1f))) : e -> {};
|
||||
flasher.get(button.addImage(Icon.locked).get());
|
||||
button.row();
|
||||
flasher.accept(button.add("$locked").get());
|
||||
flasher.get(button.add("$locked").get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.anuke.mindustry.ui.dialogs;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.scene.event.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
@@ -27,11 +27,11 @@ public class FileChooser extends FloatingDialog{
|
||||
private TextField navigation, filefield;
|
||||
private TextButton ok;
|
||||
private FileHistory stack = new FileHistory();
|
||||
private Predicate<FileHandle> filter;
|
||||
private Consumer<FileHandle> selectListener;
|
||||
private Boolf<FileHandle> filter;
|
||||
private Cons<FileHandle> selectListener;
|
||||
private boolean open;
|
||||
|
||||
public FileChooser(String title, Predicate<FileHandle> filter, boolean open, Consumer<FileHandle> result){
|
||||
public FileChooser(String title, Boolf<FileHandle> filter, boolean open, Cons<FileHandle> result){
|
||||
super(title);
|
||||
setFillParent(true);
|
||||
this.open = open;
|
||||
@@ -64,7 +64,7 @@ public class FileChooser extends FloatingDialog{
|
||||
ok.clicked(() -> {
|
||||
if(ok.isDisabled()) return;
|
||||
if(selectListener != null)
|
||||
selectListener.accept(directory.child(filefield.getText()));
|
||||
selectListener.get(directory.child(filefield.getText()));
|
||||
hide();
|
||||
});
|
||||
|
||||
@@ -212,7 +212,7 @@ public class FileChooser extends FloatingDialog{
|
||||
group.setMinCheckCount(0);
|
||||
|
||||
for(FileHandle file : names){
|
||||
if(!file.isDirectory() && !filter.test(file)) continue; //skip non-filtered files
|
||||
if(!file.isDirectory() && !filter.get(file)) continue; //skip non-filtered files
|
||||
|
||||
String filename = file.name();
|
||||
|
||||
|
||||
@@ -29,41 +29,40 @@ public class ModsDialog extends FloatingDialog{
|
||||
|
||||
buttons.addImageTextButton("$mods.guide", Icon.wiki,
|
||||
() -> Core.net.openURI(modGuideURL))
|
||||
.size(android ? 210f + 250f + 10f : 210, 64f).colspan(android ? 2 : 1);
|
||||
.size(210, 64f).colspan(android ? 2 : 1);
|
||||
|
||||
if(!android){
|
||||
buttons.addImageTextButton("$mod.import.github", Icon.github, () -> {
|
||||
ui.showTextInput("$mod.import.github", "", 64, "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 -> {
|
||||
if(result.getStatus() != HttpStatus.OK){
|
||||
ui.showErrorMessage(Core.bundle.format("connectfail", result.getStatus()));
|
||||
ui.loadfrag.hide();
|
||||
}else{
|
||||
try{
|
||||
FileHandle file = tmpDirectory.child(text.replace("/", "") + ".zip");
|
||||
Streams.copyStream(result.getResultAsStream(), file.write(false));
|
||||
mods.importMod(file);
|
||||
file.delete();
|
||||
Core.app.post(() -> {
|
||||
try{
|
||||
mods.reloadContent();
|
||||
setup();
|
||||
ui.loadfrag.hide();
|
||||
}catch(Throwable e){
|
||||
ui.showException(e);
|
||||
}
|
||||
});
|
||||
}catch(Throwable e){
|
||||
ui.showException(e);
|
||||
}
|
||||
buttons.addImageTextButton("$mod.import.github", Icon.github, () -> {
|
||||
ui.showTextInput("$mod.import.github", "", 64, "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 -> {
|
||||
if(result.getStatus() != HttpStatus.OK){
|
||||
ui.showErrorMessage(Core.bundle.format("connectfail", result.getStatus()));
|
||||
ui.loadfrag.hide();
|
||||
}else{
|
||||
try{
|
||||
FileHandle file = tmpDirectory.child(text.replace("/", "") + ".zip");
|
||||
Streams.copyStream(result.getResultAsStream(), file.write(false));
|
||||
mods.importMod(file);
|
||||
file.delete();
|
||||
Core.app.post(() -> {
|
||||
try{
|
||||
mods.reloadContent();
|
||||
setup();
|
||||
ui.loadfrag.hide();
|
||||
}catch(Throwable e){
|
||||
ui.showException(e);
|
||||
}
|
||||
});
|
||||
}catch(Throwable e){
|
||||
modError(e);
|
||||
}
|
||||
}, t -> Core.app.post(() -> ui.showException(t)));
|
||||
}, t -> Core.app.post(() -> ui.showException(t)));
|
||||
});
|
||||
}).size(250f, 64f);
|
||||
}
|
||||
}
|
||||
}, t -> Core.app.post(() -> modError(t)));
|
||||
}, t -> Core.app.post(() -> modError(t)));
|
||||
});
|
||||
}).size(250f, 64f);
|
||||
|
||||
|
||||
shown(this::setup);
|
||||
|
||||
@@ -87,6 +86,16 @@ public class ModsDialog extends FloatingDialog{
|
||||
}));
|
||||
}
|
||||
|
||||
void modError(Throwable error){
|
||||
ui.loadfrag.hide();
|
||||
|
||||
if(Strings.getCauses(error).contains(t -> t.getMessage() != null && t.getMessage().contains("SSL"))){
|
||||
ui.showErrorMessage("$feature.unsupported");
|
||||
}else{
|
||||
ui.showException(error);
|
||||
}
|
||||
}
|
||||
|
||||
void setup(){
|
||||
cont.clear();
|
||||
cont.defaults().width(520f).pad(4);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import io.anuke.annotations.Annotations.*;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.input.*;
|
||||
@@ -130,7 +131,7 @@ public class BlockInventoryFragment extends Fragment{
|
||||
|
||||
container.add(i);
|
||||
|
||||
BooleanProvider canPick = () -> player.acceptsItem(item) && !state.isPaused();
|
||||
Boolp canPick = () -> player.acceptsItem(item) && !state.isPaused();
|
||||
|
||||
HandCursorListener l = new HandCursorListener();
|
||||
l.setEnabled(canPick);
|
||||
@@ -203,7 +204,7 @@ public class BlockInventoryFragment extends Fragment{
|
||||
table.setPosition(v.x, v.y, Align.topLeft);
|
||||
}
|
||||
|
||||
private Element itemImage(TextureRegion region, Supplier<CharSequence> text){
|
||||
private Element itemImage(TextureRegion region, Prov<CharSequence> text){
|
||||
Stack stack = new Stack();
|
||||
|
||||
Table t = new Table().left().bottom();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.arc.func.*;
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.scene.Group;
|
||||
@@ -36,7 +37,7 @@ public class LoadingFragment extends Fragment{
|
||||
});
|
||||
}
|
||||
|
||||
public void setProgress(FloatProvider progress){
|
||||
public void setProgress(Floatp progress){
|
||||
bar.reset(0f);
|
||||
bar.visible(true);
|
||||
bar.set(() -> ((int)(progress.get() * 100) + "%"), progress, Pal.accent);
|
||||
|
||||
Reference in New Issue
Block a user