Search in sources :

Example 1 with TextButton

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);
        }
    }
}
Also used : TextButton(io.anuke.ucore.scene.ui.TextButton) Host(io.anuke.mindustry.net.Host)

Example 2 with TextButton

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();
    }
}
Also used : TextButton(io.anuke.ucore.scene.ui.TextButton) Version(io.anuke.mindustry.io.Version) MathUtils(com.badlogic.gdx.math.MathUtils) Strings(io.anuke.ucore.util.Strings) Array(com.badlogic.gdx.utils.Array) Platform(io.anuke.mindustry.io.Platform) Cell(io.anuke.ucore.scene.ui.layout.Cell) Bundles(io.anuke.ucore.util.Bundles) Settings(io.anuke.ucore.core.Settings) Vars.ui(io.anuke.mindustry.Vars.ui) Net(io.anuke.mindustry.net.Net) Color(com.badlogic.gdx.graphics.Color) Drawable(io.anuke.ucore.scene.style.Drawable) Vars.player(io.anuke.mindustry.Vars.player) Host(io.anuke.mindustry.net.Host) TextButton(io.anuke.ucore.scene.ui.TextButton) Dialog(io.anuke.ucore.scene.ui.Dialog) ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) Timers(io.anuke.ucore.core.Timers) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) Log(io.anuke.ucore.util.Log) Vars(io.anuke.mindustry.Vars) Table(io.anuke.ucore.scene.ui.layout.Table)

Example 3 with TextButton

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();
}
Also used : TextButton(io.anuke.ucore.scene.ui.TextButton) Strings(io.anuke.ucore.util.Strings) SaveIO(io.anuke.mindustry.io.SaveIO) Core(io.anuke.ucore.core.Core) Array(com.badlogic.gdx.utils.Array) Bundles(io.anuke.ucore.util.Bundles) IOException(java.io.IOException) TextButton(io.anuke.ucore.scene.ui.TextButton) Table(io.anuke.ucore.scene.ui.layout.Table) Timers(io.anuke.ucore.core.Timers) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) Log(io.anuke.ucore.util.Log) SaveSlot(io.anuke.mindustry.io.Saves.SaveSlot) Vars(io.anuke.mindustry.Vars) State(io.anuke.mindustry.core.GameState.State) Table(io.anuke.ucore.scene.ui.layout.Table) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) SaveSlot(io.anuke.mindustry.io.Saves.SaveSlot) IOException(java.io.IOException)

Example 4 with TextButton

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();
        }
    });
}
Also used : Version(io.anuke.mindustry.io.Version) MathUtils(com.badlogic.gdx.math.MathUtils) Strings(io.anuke.ucore.util.Strings) Array(com.badlogic.gdx.utils.Array) Platform(io.anuke.mindustry.io.Platform) Cell(io.anuke.ucore.scene.ui.layout.Cell) Bundles(io.anuke.ucore.util.Bundles) Settings(io.anuke.ucore.core.Settings) Vars.ui(io.anuke.mindustry.Vars.ui) Net(io.anuke.mindustry.net.Net) Color(com.badlogic.gdx.graphics.Color) Drawable(io.anuke.ucore.scene.style.Drawable) Vars.player(io.anuke.mindustry.Vars.player) Host(io.anuke.mindustry.net.Host) TextButton(io.anuke.ucore.scene.ui.TextButton) Dialog(io.anuke.ucore.scene.ui.Dialog) ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) Timers(io.anuke.ucore.core.Timers) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) Log(io.anuke.ucore.util.Log) Vars(io.anuke.mindustry.Vars) TextButton(io.anuke.ucore.scene.ui.TextButton) ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane)

Example 5 with TextButton

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);
}
Also used : TextButton(io.anuke.ucore.scene.ui.TextButton) Locale(java.util.Locale) Table(io.anuke.ucore.scene.ui.layout.Table) ButtonGroup(io.anuke.ucore.scene.ui.ButtonGroup) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane)

Aggregations

TextButton (io.anuke.ucore.scene.ui.TextButton)6 ScrollPane (io.anuke.ucore.scene.ui.ScrollPane)5 Table (io.anuke.ucore.scene.ui.layout.Table)5 Array (com.badlogic.gdx.utils.Array)3 Vars (io.anuke.mindustry.Vars)3 Host (io.anuke.mindustry.net.Host)3 Timers (io.anuke.ucore.core.Timers)3 Bundles (io.anuke.ucore.util.Bundles)3 Log (io.anuke.ucore.util.Log)3 Strings (io.anuke.ucore.util.Strings)3 Color (com.badlogic.gdx.graphics.Color)2 MathUtils (com.badlogic.gdx.math.MathUtils)2 Vars.player (io.anuke.mindustry.Vars.player)2 Vars.ui (io.anuke.mindustry.Vars.ui)2 Platform (io.anuke.mindustry.io.Platform)2 Version (io.anuke.mindustry.io.Version)2 Net (io.anuke.mindustry.net.Net)2 Settings (io.anuke.ucore.core.Settings)2 Drawable (io.anuke.ucore.scene.style.Drawable)2 ButtonGroup (io.anuke.ucore.scene.ui.ButtonGroup)2