Search in sources :

Example 1 with Table

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

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

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

the class MapEditorDialog method build.

public void build() {
    new table() {

        {
            float isize = 16 * 2f;
            aleft();
            new table() {

                {
                    defaults().growY().width(130f).padBottom(-6);
                    new imagebutton("icon-terrain", isize, () -> dialog.show()).text("$text.editor.generate");
                    row();
                    new imagebutton("icon-resize", isize, () -> resizeDialog.show()).text("$text.editor.resize").padTop(4f);
                    row();
                    new imagebutton("icon-load-map", isize, () -> loadDialog.show()).text("$text.editor.loadmap");
                    row();
                    new imagebutton("icon-save-map", isize, () -> saveDialog.show()).text("$text.editor.savemap");
                    row();
                    new imagebutton("icon-load-image", isize, () -> openFile.show()).text("$text.editor.loadimage");
                    row();
                    new imagebutton("icon-save-image", isize, () -> saveFile.show()).text("$text.editor.saveimage");
                    row();
                    new imagebutton("icon-back", isize, () -> {
                        if (!saved) {
                            ui.showConfirm("$text.confirm", "$text.editor.unsaved", MapEditorDialog.this::hide);
                        } else {
                            hide();
                        }
                    }).padBottom(0).text("$text.back");
                }
            }.left().growY().end();
            new table("button") {

                {
                    add(view).grow();
                }
            }.grow().end();
            new table() {

                {
                    Table tools = new Table("button");
                    tools.top();
                    tools.marginTop(0).marginBottom(6);
                    ButtonGroup<ImageButton> group = new ButtonGroup<>();
                    int i = 1;
                    tools.defaults().size(53f, 58f).padBottom(-6);
                    ImageButton undo = tools.addImageButton("icon-undo", 16 * 2f, () -> view.undo()).get();
                    ImageButton redo = tools.addImageButton("icon-redo", 16 * 2f, () -> view.redo()).get();
                    ImageButton grid = tools.addImageButton("icon-grid", "toggle", 16 * 2f, () -> view.setGrid(!view.isGrid())).get();
                    undo.setDisabled(() -> !view.getStack().canUndo());
                    redo.setDisabled(() -> !view.getStack().canRedo());
                    undo.update(() -> undo.getImage().setColor(undo.isDisabled() ? Color.GRAY : Color.WHITE));
                    redo.update(() -> redo.getImage().setColor(redo.isDisabled() ? Color.GRAY : Color.WHITE));
                    grid.update(() -> grid.setChecked(view.isGrid()));
                    for (EditorTool tool : EditorTool.values()) {
                        ImageButton button = new ImageButton("icon-" + tool.name(), "toggle");
                        button.clicked(() -> view.setTool(tool));
                        button.resizeImage(16 * 2f);
                        button.update(() -> button.setChecked(view.getTool() == tool));
                        group.add(button);
                        if (tool == EditorTool.pencil)
                            button.setChecked(true);
                        tools.add(button).padBottom(-6f);
                        if (i++ % 4 == 1)
                            tools.row();
                    }
                    add(tools).width(53 * 4).padBottom(-6);
                    row();
                    new table("button") {

                        {
                            margin(10f);
                            Slider slider = new Slider(0, MapEditor.brushSizes.length - 1, 1, false);
                            slider.moved(f -> editor.setBrushSize(MapEditor.brushSizes[(int) (float) f]));
                            new label(() -> Bundles.format("text.editor.brushsize", MapEditor.brushSizes[(int) slider.getValue()])).left();
                            row();
                            add(slider).growX().padTop(4f);
                        }
                    }.growX().padBottom(-6).end();
                    row();
                    new table("button") {

                        {
                            get().addCheck("$text.oregen", b -> editor.getMap().oreGen = b).update(c -> c.setChecked(editor.getMap().oreGen)).padTop(3).padBottom(3);
                        }
                    }.growX().padBottom(-6).end();
                    row();
                    addBlockSelection(get());
                    row();
                }
            }.right().growY().end();
        }
    }.grow().end();
}
Also used : Block(io.anuke.mindustry.world.Block) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table) FileHandle(com.badlogic.gdx.files.FileHandle) Map(io.anuke.mindustry.world.Map) Strings(io.anuke.ucore.util.Strings) Arrays(java.util.Arrays) Bundles(io.anuke.ucore.util.Bundles) io.anuke.ucore.scene.builders.imagebutton(io.anuke.ucore.scene.builders.imagebutton) Blocks(io.anuke.mindustry.world.blocks.Blocks) Texture(com.badlogic.gdx.graphics.Texture) FileChooser(io.anuke.mindustry.ui.dialogs.FileChooser) Graphics(io.anuke.ucore.core.Graphics) BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Table(io.anuke.ucore.scene.ui.layout.Table) Log(io.anuke.ucore.util.Log) Vars(io.anuke.mindustry.Vars) Inputs(io.anuke.ucore.core.Inputs) Core(io.anuke.ucore.core.Core) Pixmap(com.badlogic.gdx.graphics.Pixmap) Platform(io.anuke.mindustry.io.Platform) Pixmaps(io.anuke.ucore.graphics.Pixmaps) Color(com.badlogic.gdx.graphics.Color) ColorMapper(io.anuke.mindustry.world.ColorMapper) Draw(io.anuke.ucore.graphics.Draw) Element(io.anuke.ucore.scene.Element) io.anuke.ucore.scene.ui(io.anuke.ucore.scene.ui) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) Keys(com.badlogic.gdx.Input.Keys) io.anuke.ucore.scene.builders.build(io.anuke.ucore.scene.builders.build) SpecialBlocks(io.anuke.mindustry.world.blocks.SpecialBlocks) Timers(io.anuke.ucore.core.Timers) Table(io.anuke.ucore.scene.ui.layout.Table) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) io.anuke.ucore.scene.builders.imagebutton(io.anuke.ucore.scene.builders.imagebutton) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table)

Example 4 with Table

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

the class LevelDialog method displayGameModeHelp.

private void displayGameModeHelp() {
    FloatingDialog d = new FloatingDialog(Bundles.get("mode.text.help.title"));
    d.setFillParent(false);
    Table table = new Table();
    table.defaults().pad(1f);
    ScrollPane pane = new ScrollPane(table, "clear");
    pane.setFadeScrollBars(false);
    table.row();
    for (GameMode mode : GameMode.values()) {
        table.labelWrap("[accent]" + mode.toString() + ":[] [lightgray]" + mode.description()).width(600f);
        table.row();
    }
    d.content().add(pane);
    d.buttons().addButton("$text.ok", d::hide).size(110, 50).pad(10f);
    d.show();
}
Also used : GameMode(io.anuke.mindustry.game.GameMode) Table(io.anuke.ucore.scene.ui.layout.Table)

Example 5 with Table

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

the class LevelDialog method setup.

void setup() {
    Table maps = new Table();
    pane = new ScrollPane(maps);
    pane.setFadeScrollBars(false);
    int maxwidth = 4;
    Table selmode = new Table();
    ButtonGroup<TextButton> group = new ButtonGroup<>();
    selmode.add("$text.level.mode").padRight(15f);
    for (GameMode mode : GameMode.values()) {
        TextButton[] b = { null };
        b[0] = Elements.newButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode);
        b[0].update(() -> b[0].setChecked(state.mode == mode));
        group.add(b[0]);
        selmode.add(b[0]).size(130f, 54f);
    }
    selmode.addButton("?", this::displayGameModeHelp).size(50f, 54f).padLeft(18f);
    content().add(selmode);
    content().row();
    Difficulty[] ds = Difficulty.values();
    float s = 50f;
    Table sdif = new Table();
    sdif.add("$setting.difficulty.name").padRight(15f);
    sdif.defaults().height(s + 4);
    sdif.addImageButton("icon-arrow-left", 10 * 3, () -> {
        state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
    }).width(s);
    sdif.addButton("", () -> {
    }).update(t -> {
        t.setText(state.difficulty.toString());
        t.setTouchable(Touchable.disabled);
    }).width(180f);
    sdif.addImageButton("icon-arrow-right", 10 * 3, () -> {
        state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() + 1, ds.length)]);
    }).width(s);
    content().add(sdif);
    content().row();
    int i = 0;
    for (Map map : world.maps().list()) {
        if (!map.visible && !debug)
            continue;
        if (i % maxwidth == 0) {
            maps.row();
        }
        Table inset = new Table("pane-button");
        inset.add("[accent]" + Bundles.get("map." + map.name + ".name", map.name)).pad(3f);
        inset.row();
        inset.label((() -> {
            try {
                return Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name));
            } catch (Exception e) {
                Settings.defaults("hiscore" + map.name, 1);
                return Bundles.format("text.level.highscore", 0);
            }
        })).pad(3f);
        inset.pack();
        float images = 154f;
        Stack stack = new Stack();
        Image back = new Image("white");
        back.setColor(map.backgroundColor);
        ImageButton image = new ImageButton(new TextureRegion(map.texture), "togglemap");
        image.row();
        image.add(inset).width(images + 6);
        TextButton[] delete = new TextButton[1];
        if (map.custom) {
            image.row();
            delete[0] = image.addButton("Delete", () -> {
                Timers.run(1f, () -> {
                    ui.showConfirm("$text.level.delete.title", Bundles.format("text.level.delete", Bundles.get("map." + map.name + ".name", map.name)), () -> {
                        world.maps().removeMap(map);
                        reload();
                        Core.scene.setScrollFocus(pane);
                    });
                });
            }).width(images + 16).padBottom(-10f).grow().get();
        }
        Vector2 hit = new Vector2();
        image.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                image.localToStageCoordinates(hit.set(x, y));
                if (delete[0] != null && (delete[0].getClickListener().isOver() || delete[0].getClickListener().isPressed() || (Core.scene.hit(hit.x, hit.y, true) != null && Core.scene.hit(hit.x, hit.y, true).isDescendantOf(delete[0])))) {
                    return;
                }
                selectedMap = map;
                hide();
                control.playMap(selectedMap);
            }
        });
        image.getImageCell().size(images);
        stack.add(back);
        stack.add(image);
        maps.add(stack).width(170).top().pad(4f);
        maps.marginRight(26);
        i++;
    }
    content().add(pane).uniformX();
    shown(() -> {
        // this is necessary for some reason?
        Timers.run(2f, () -> {
            Core.scene.setScrollFocus(pane);
        });
    });
}
Also used : Map(io.anuke.mindustry.world.Map) Core(io.anuke.ucore.core.Core) Bundles(io.anuke.ucore.util.Bundles) Settings(io.anuke.ucore.core.Settings) Stack(io.anuke.ucore.scene.ui.layout.Stack) Elements(io.anuke.ucore.scene.utils.Elements) InputEvent(io.anuke.ucore.scene.event.InputEvent) ClickListener(io.anuke.ucore.scene.event.ClickListener) io.anuke.ucore.scene.ui(io.anuke.ucore.scene.ui) Vector2(com.badlogic.gdx.math.Vector2) GameMode(io.anuke.mindustry.game.GameMode) Table(io.anuke.ucore.scene.ui.layout.Table) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Difficulty(io.anuke.mindustry.game.Difficulty) Mathf(io.anuke.ucore.util.Mathf) Timers(io.anuke.ucore.core.Timers) Vars(io.anuke.mindustry.Vars) Touchable(io.anuke.ucore.scene.event.Touchable) Table(io.anuke.ucore.scene.ui.layout.Table) Difficulty(io.anuke.mindustry.game.Difficulty) Stack(io.anuke.ucore.scene.ui.layout.Stack) GameMode(io.anuke.mindustry.game.GameMode) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Vector2(com.badlogic.gdx.math.Vector2) InputEvent(io.anuke.ucore.scene.event.InputEvent) Map(io.anuke.mindustry.world.Map) ClickListener(io.anuke.ucore.scene.event.ClickListener)

Aggregations

Table (io.anuke.ucore.scene.ui.layout.Table)29 ScrollPane (io.anuke.ucore.scene.ui.ScrollPane)11 Vars (io.anuke.mindustry.Vars)9 Bundles (io.anuke.ucore.util.Bundles)9 ImageButton (io.anuke.ucore.scene.ui.ImageButton)8 io.anuke.ucore.scene.builders.table (io.anuke.ucore.scene.builders.table)7 Color (com.badlogic.gdx.graphics.Color)6 io.anuke.ucore.scene.builders.label (io.anuke.ucore.scene.builders.label)6 State (io.anuke.mindustry.core.GameState.State)5 Net (io.anuke.mindustry.net.Net)5 Core (io.anuke.ucore.core.Core)5 Timers (io.anuke.ucore.core.Timers)5 Touchable (io.anuke.ucore.scene.event.Touchable)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 Settings (io.anuke.ucore.core.Settings)4 ButtonGroup (io.anuke.ucore.scene.ui.ButtonGroup)4 TextButton (io.anuke.ucore.scene.ui.TextButton)4 Log (io.anuke.ucore.util.Log)4 Strings (io.anuke.ucore.util.Strings)4 Array (com.badlogic.gdx.utils.Array)3