Search in sources :

Example 1 with ImageButton

use of io.anuke.ucore.scene.ui.ImageButton in project Mindustry by Anuken.

the class WeaponFactory method buildTable.

@Override
public void buildTable(Tile tile, Table table) {
    int i = 0;
    Table content = new Table();
    for (Upgrade upgrade : Upgrade.getAllUpgrades()) {
        if (!(upgrade instanceof Weapon))
            continue;
        Weapon weapon = (Weapon) upgrade;
        ItemStack[] requirements = UpgradeRecipes.get(weapon);
        Table tiptable = new Table();
        Listenable run = () -> {
            tiptable.clearChildren();
            String description = weapon.description;
            tiptable.background("pane");
            tiptable.add("[orange]" + weapon.localized(), 0.5f).left().padBottom(2f);
            Table reqtable = new Table();
            tiptable.row();
            tiptable.add(reqtable).left();
            if (!control.upgrades().hasWeapon(weapon)) {
                for (ItemStack s : requirements) {
                    int amount = Math.min(state.inventory.getAmount(s.item), s.amount);
                    reqtable.addImage(s.item.region).padRight(3).size(8 * 2);
                    reqtable.add((amount >= s.amount ? "" : "[RED]") + amount + " / " + s.amount, 0.5f).left();
                    reqtable.row();
                }
            }
            tiptable.row();
            tiptable.add().size(4);
            tiptable.row();
            tiptable.add("[gray]" + description).left();
            tiptable.row();
            if (control.upgrades().hasWeapon(weapon)) {
                tiptable.add("$text.purchased").padTop(4).left();
            }
            tiptable.margin(8f);
        };
        run.listen();
        Tooltip<Table> tip = new Tooltip<>(tiptable, run);
        tip.setInstant(true);
        ImageButton button = content.addImageButton("white", 8 * 4, () -> {
            if (Net.client()) {
                NetEvents.handleUpgrade(weapon);
            } else {
                state.inventory.removeItems(requirements);
                control.upgrades().addWeapon(weapon);
                ui.hudfrag.updateWeapons();
                run.listen();
                Effects.sound("purchase");
            }
        }).size(49f, 54f).padBottom(-5).get();
        button.setDisabled(() -> control.upgrades().hasWeapon(weapon) || !state.inventory.hasItems(requirements));
        button.getStyle().imageUp = new TextureRegionDrawable(Draw.region(weapon.name));
        button.addListener(tip);
        if (++i % 3 == 0) {
            content.row();
        }
    }
    table.add(content).padTop(140f);
}
Also used : ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) Tooltip(io.anuke.ucore.scene.ui.Tooltip) TextureRegionDrawable(io.anuke.ucore.scene.style.TextureRegionDrawable) ItemStack(io.anuke.mindustry.resource.ItemStack) Upgrade(io.anuke.mindustry.resource.Upgrade) Weapon(io.anuke.mindustry.resource.Weapon) Listenable(io.anuke.ucore.function.Listenable)

Example 2 with ImageButton

use of io.anuke.ucore.scene.ui.ImageButton in project Mindustry by Anuken.

the class Sorter method buildTable.

@Override
public void buildTable(Tile tile, Table table) {
    SorterEntity entity = tile.entity();
    Array<Item> items = Item.getAllItems();
    ButtonGroup<ImageButton> group = new ButtonGroup<>();
    Table cont = new Table();
    cont.margin(4);
    cont.marginBottom(5);
    cont.add().colspan(4).height(105f);
    cont.row();
    for (int i = 0; i < items.size; i++) {
        final int f = i;
        ImageButton button = cont.addImageButton("white", "toggle", 24, () -> {
            entity.sortItem = items.get(f);
            setConfigure(tile, (byte) f);
        }).size(38, 42).padBottom(-5.1f).group(group).get();
        button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(items.get(i).region));
        button.setChecked(entity.sortItem.id == f);
        if (i % 4 == 3) {
            cont.row();
        }
    }
    table.add(cont);
}
Also used : Item(io.anuke.mindustry.resource.Item) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) ButtonGroup(io.anuke.ucore.scene.ui.ButtonGroup) TextureRegionDrawable(io.anuke.ucore.scene.style.TextureRegionDrawable)

Example 3 with ImageButton

use of io.anuke.ucore.scene.ui.ImageButton in project Mindustry by Anuken.

the class PausedDialog method setup.

void setup() {
    update(() -> {
        if (state.is(State.menu) && isShown()) {
            hide();
        }
    });
    shown(() -> {
        wasPaused = state.is(State.paused);
        if (!Net.active())
            state.set(State.paused);
    });
    if (!android) {
        content().defaults().width(220).height(50);
        content().addButton("$text.back", () -> {
            hide();
            if ((!wasPaused || Net.active()) && !state.is(State.menu))
                state.set(State.playing);
        });
        content().row();
        content().addButton("$text.settings", ui.settings::show);
        content().row();
        content().addButton("$text.savegame", () -> {
            save.show();
        }).disabled(b -> world.getMap().id == -1);
        content().row();
        content().addButton("$text.loadgame", () -> {
            load.show();
        }).disabled(b -> Net.active());
        content().row();
        if (!gwt) {
            content().addButton("$text.hostserver", () -> {
                ui.host.show();
            }).disabled(b -> Net.active());
        }
        content().row();
        content().addButton("$text.quit", () -> {
            ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
                if (Net.client())
                    netClient.disconnectQuietly();
                runExitSave();
                hide();
            });
        });
    } else {
        build.begin(content());
        PressGroup group = new PressGroup();
        content().defaults().size(120f).pad(5);
        float isize = 14f * 4;
        new imagebutton("icon-play-2", isize, () -> {
            hide();
            if (!wasPaused && !state.is(State.menu))
                state.set(State.playing);
        }).text("$text.back").padTop(4f);
        new imagebutton("icon-tools", isize, ui.settings::show).text("$text.settings").padTop(4f);
        imagebutton sa = new imagebutton("icon-save", isize, save::show);
        sa.text("$text.save").padTop(4f);
        sa.cell.disabled(b -> world.getMap().id == -1);
        content().row();
        imagebutton lo = new imagebutton("icon-load", isize, load::show);
        lo.text("$text.load").padTop(4f);
        lo.cell.disabled(b -> Net.active());
        imagebutton ho = new imagebutton("icon-host", isize, () -> {
            ui.host.show();
        });
        ho.text("$text.host").padTop(4f);
        ho.cell.disabled(b -> Net.active());
        new imagebutton("icon-quit", isize, () -> {
            ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
                if (Net.client())
                    netClient.disconnectQuietly();
                runExitSave();
                hide();
            });
        }).text("Quit").padTop(4f);
        for (Element e : content().getChildren()) {
            if (e instanceof ImageButton) {
                group.add((ImageButton) e);
            }
        }
        build.end();
    }
}
Also used : ImageButton(io.anuke.ucore.scene.ui.ImageButton) PressGroup(io.anuke.mindustry.ui.PressGroup) Element(io.anuke.ucore.scene.Element) io.anuke.ucore.scene.builders.imagebutton(io.anuke.ucore.scene.builders.imagebutton)

Example 4 with ImageButton

use of io.anuke.ucore.scene.ui.ImageButton in project Mindustry by Anuken.

the class ColorPickDialog method build.

private void build() {
    Table table = new Table();
    content().add(table);
    for (int i = 0; i < playerColors.length; i++) {
        Color color = playerColors[i];
        ImageButton button = table.addImageButton("white", "toggle", 34, () -> {
            cons.accept(color);
            hide();
        }).size(44, 48).pad(0).padBottom(-5.1f).get();
        button.setChecked(player.getColor().equals(color));
        button.getStyle().imageUpColor = color;
        if (i % 4 == 3) {
            table.row();
        }
    }
}
Also used : ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) Color(com.badlogic.gdx.graphics.Color)

Example 5 with ImageButton

use of io.anuke.ucore.scene.ui.ImageButton 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)

Aggregations

ImageButton (io.anuke.ucore.scene.ui.ImageButton)8 Table (io.anuke.ucore.scene.ui.layout.Table)7 Color (com.badlogic.gdx.graphics.Color)4 Vars (io.anuke.mindustry.Vars)3 io.anuke.ucore.scene.builders.imagebutton (io.anuke.ucore.scene.builders.imagebutton)3 ButtonGroup (io.anuke.ucore.scene.ui.ButtonGroup)3 Bundles (io.anuke.ucore.util.Bundles)3 Interpolation (com.badlogic.gdx.math.Interpolation)2 State (io.anuke.mindustry.core.GameState.State)2 Net (io.anuke.mindustry.net.Net)2 Core (io.anuke.ucore.core.Core)2 Settings (io.anuke.ucore.core.Settings)2 Actions (io.anuke.ucore.scene.actions.Actions)2 io.anuke.ucore.scene.builders.label (io.anuke.ucore.scene.builders.label)2 io.anuke.ucore.scene.builders.table (io.anuke.ucore.scene.builders.table)2 Touchable (io.anuke.ucore.scene.event.Touchable)2 TextureRegionDrawable (io.anuke.ucore.scene.style.TextureRegionDrawable)2 Label (io.anuke.ucore.scene.ui.Label)2 Gdx (com.badlogic.gdx.Gdx)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1