use of io.anuke.ucore.scene.ui.TextButton in project Mindustry by Anuken.
the class JoinDialog method addLocalHosts.
void addLocalHosts(Array<Host> array) {
local.clear();
if (array.size == 0) {
local.add("$text.hosts.none").pad(10f);
local.add().growX();
local.addImageButton("icon-loading", 16 * 2f, this::refreshLocal).pad(-10f).padLeft(0).padTop(-6).size(70f, 74f);
} else {
for (Host a : array) {
TextButton button = local.addButton("[accent]" + a.name, "clear", () -> {
connect(a.address, Vars.port);
}).width(w).height(80f).pad(4f).get();
button.left();
button.row();
button.add("[lightgray]" + (a.players != 1 ? Bundles.format("text.players", a.players) : Bundles.format("text.players.single", a.players)));
button.row();
button.add("[lightgray]" + a.address).pad(4).left();
local.row();
local.background((Drawable) null);
}
}
}
use of io.anuke.ucore.scene.ui.TextButton in project Mindustry by Anuken.
the class JoinDialog method setupRemote.
void setupRemote() {
remote.clear();
for (Server server : servers) {
// why are java lambdas this bad
TextButton[] buttons = { null };
TextButton button = buttons[0] = remote.addButton("[accent]" + server.ip, "clear", () -> {
if (!buttons[0].childrenPressed())
connect(server.ip, Vars.port);
}).width(w).height(150f).pad(4f).get();
button.getLabel().setWrap(true);
Table inner = new Table();
button.clearChildren();
button.add(inner).growX();
inner.add(button.getLabel()).growX();
inner.addImageButton("icon-loading", "empty", 16 * 2, () -> {
refreshServer(server);
}).margin(3f).padTop(6f).top().right();
inner.addImageButton("icon-pencil", "empty", 16 * 2, () -> {
renaming = server;
add.show();
}).margin(3f).padTop(6f).top().right();
inner.addImageButton("icon-trash-16", "empty", 16 * 2, () -> {
ui.showConfirm("$text.confirm", "$text.server.delete", () -> {
servers.removeValue(server, true);
saveServers();
setupRemote();
refreshRemote();
});
}).margin(3f).pad(6).top().right();
button.row();
server.content = button.table(t -> {
}).grow().get();
remote.row();
}
}
use of io.anuke.ucore.scene.ui.TextButton in project Mindustry by Anuken.
the class LoadDialog method setup.
protected void setup() {
content().clear();
slots = new Table();
pane = new ScrollPane(slots, "clear-black");
pane.setFadeScrollBars(false);
pane.setScrollingDisabled(true, false);
slots.marginRight(24);
Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
Array<SaveSlot> array = control.getSaves().getSaveSlots();
for (SaveSlot slot : array) {
TextButton button = new TextButton("[accent]" + slot.getName(), "clear");
button.getLabelCell().growX().left();
button.getLabelCell().padBottom(8f);
button.getLabelCell().top().left().growX();
button.defaults().left();
button.table(t -> {
t.right();
t.addImageButton("icon-floppy", "emptytoggle", 14 * 3, () -> {
slot.setAutosave(!slot.isAutosave());
}).checked(slot.isAutosave()).right();
t.addImageButton("icon-trash", "empty", 14 * 3, () -> {
ui.showConfirm("$text.confirm", "$text.save.delete.confirm", () -> {
slot.delete();
setup();
});
}).size(14 * 3).right();
t.addImageButton("icon-pencil-small", "empty", 14 * 3, () -> {
ui.showTextInput("$text.save.rename", "$text.save.rename.text", slot.getName(), text -> {
slot.setName(text);
setup();
});
}).size(14 * 3).right();
if (!gwt) {
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
new FileChooser("$text.save.export", false, file -> {
try {
slot.exportFile(file);
setup();
} catch (IOException e) {
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
}
}).show();
}).size(14 * 3).right();
}
}).padRight(-10).growX();
String color = "[lightgray]";
button.defaults().padBottom(3);
button.row();
button.add(Bundles.format("text.save.map", color + slot.getMap().localized()));
button.row();
button.add(Bundles.get("text.level.mode") + " " + color + slot.getMode());
button.row();
button.add(Bundles.format("text.save.wave", color + slot.getWave()));
button.row();
button.add(Bundles.format("text.save.difficulty", color + slot.getDifficulty()));
button.row();
button.label(() -> Bundles.format("text.save.autosave", color + Bundles.get(slot.isAutosave() ? "text.on" : "text.off")));
button.row();
button.add();
button.add(Bundles.format("text.save.date", color + slot.getDate()));
button.row();
modifyButton(button, slot);
slots.add(button).uniformX().fillX().pad(4).padRight(-4).margin(10f).marginLeft(20f).marginRight(20f);
slots.row();
}
content().add(pane);
addSetup();
}
use of io.anuke.ucore.scene.ui.TextButton in project Mindustry by Anuken.
the class JoinDialog method setup.
void setup() {
hosts.clear();
hosts.add(remote).growX();
hosts.row();
hosts.add(local).width(w);
ScrollPane pane = new ScrollPane(hosts, "clear");
pane.setFadeScrollBars(false);
pane.setScrollingDisabled(true, false);
setupRemote();
refreshRemote();
content().clear();
content().table(t -> {
t.add("$text.name").padRight(10);
t.addField(Settings.getString("name"), text -> {
if (text.isEmpty())
return;
Vars.player.name = text;
Settings.put("name", text);
Settings.save();
}).grow().pad(8).get().setMaxLength(40);
ImageButton button = t.addImageButton("white", 40, () -> {
new ColorPickDialog().show(color -> {
player.color.set(color);
Settings.putInt("color", Color.rgba8888(color));
Settings.save();
});
}).size(50f, 54f).get();
button.update(() -> button.getStyle().imageUpColor = player.getColor());
}).width(w).height(70f).pad(4);
content().row();
content().add(pane).width(w + 34).pad(0);
content().row();
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14 * 3, () -> {
renaming = null;
add.show();
}).marginLeft(6).width(w).height(80f).update(button -> {
float pw = w;
float pad = 0f;
if (pane.getChildren().first().getPrefHeight() > pane.getHeight()) {
pw = w + 30;
pad = 6;
}
Cell<TextButton> cell = ((Table) pane.getParent()).getCell(button);
if (!MathUtils.isEqual(cell.getMinWidth(), pw)) {
cell.width(pw);
cell.padLeft(pad);
pane.getParent().invalidateHierarchy();
}
});
}
use of io.anuke.ucore.scene.ui.TextButton in project Mindustry by Anuken.
the class LanguageDialog method setup.
private void setup() {
Table langs = new Table();
langs.marginRight(24f).marginLeft(24f);
ScrollPane pane = new ScrollPane(langs, "clear");
pane.setFadeScrollBars(false);
ButtonGroup<TextButton> group = new ButtonGroup<>();
for (Locale loc : locales) {
TextButton button = new TextButton(Platform.instance.getLocaleName(loc), "toggle");
button.setChecked(ui.getLocale().equals(loc));
button.clicked(() -> {
if (ui.getLocale().equals(loc))
return;
Settings.putString("locale", loc.toString());
Settings.save();
Log.info("Setting locale: {0}", loc.toString());
ui.showInfo("$text.language.restart");
});
langs.add(button).group(group).update(t -> {
t.setChecked(loc.equals(ui.getLocale()));
}).size(400f, 60f).row();
}
content().add(pane);
}
Aggregations