Search in sources :

Example 16 with Table

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

the class BlocksFragment method build.

public void build() {
    InputHandler input = control.input();
    new table() {

        {
            abottom();
            aright();
            visible(() -> !state.is(State.menu) && shown);
            blocks = new table() {

                {
                    itemtable = new Table("button");
                    itemtable.setVisible(() -> input.recipe == null && !state.mode.infiniteResources);
                    desctable = new Table("button");
                    desctable.setVisible(() -> hoveredDescriptionRecipe != null || input.recipe != null);
                    desctable.update(() -> {
                        // note: This is required because there is no direct connection between
                        // input.recipe and the description ui. If input.recipe gets set to null
                        // a proper cleanup of the ui elements is required.
                        boolean anyRecipeShown = input.recipe != null || hoveredDescriptionRecipe != null;
                        boolean descriptionTableClean = desctable.getChildren().size == 0;
                        boolean cleanupRequired = !anyRecipeShown && !descriptionTableClean;
                        if (cleanupRequired) {
                            desctable.clear();
                        }
                    });
                    stack.add(itemtable);
                    stack.add(desctable);
                    add(stack).fillX().uniformX();
                    row();
                    new table("pane") {

                        {
                            touchable(Touchable.enabled);
                            int rows = 4;
                            int maxcol = 0;
                            float size = 48;
                            Stack stack = new Stack();
                            ButtonGroup<ImageButton> group = new ButtonGroup<>();
                            Array<Recipe> recipes = new Array<>();
                            for (Section sec : Section.values()) {
                                recipes.clear();
                                Recipes.getBy(sec, recipes);
                                maxcol = Math.max((int) ((float) recipes.size / rows + 1), maxcol);
                            }
                            for (Section sec : Section.values()) {
                                recipes.clear();
                                Recipes.getBy(sec, recipes);
                                Table table = new Table();
                                ImageButton button = new ImageButton("icon-" + sec.name(), "toggle");
                                button.clicked(() -> {
                                    if (!table.isVisible() && input.recipe != null) {
                                        input.recipe = null;
                                    }
                                });
                                button.setName("sectionbutton" + sec.name());
                                add(button).growX().height(54).padLeft(-1).padTop(sec.ordinal() <= 2 ? -10 : -5);
                                button.getImageCell().size(40).padBottom(4).padTop(2);
                                group.add(button);
                                if (sec.ordinal() % 3 == 2 && sec.ordinal() > 0) {
                                    row();
                                }
                                table.margin(4);
                                table.top().left();
                                int i = 0;
                                for (Recipe r : recipes) {
                                    TextureRegion region = Draw.hasRegion(r.result.name() + "-icon") ? Draw.region(r.result.name() + "-icon") : Draw.region(r.result.name());
                                    ImageButton image = new ImageButton(region, "select");
                                    image.addListener(new ClickListener() {

                                        @Override
                                        public void enter(InputEvent event, float x, float y, int pointer, Element fromActor) {
                                            super.enter(event, x, y, pointer, fromActor);
                                            if (hoveredDescriptionRecipe != r) {
                                                hoveredDescriptionRecipe = r;
                                                updateRecipe(r);
                                            }
                                        }

                                        @Override
                                        public void exit(InputEvent event, float x, float y, int pointer, Element toActor) {
                                            super.exit(event, x, y, pointer, toActor);
                                            hoveredDescriptionRecipe = null;
                                            updateRecipe(input.recipe);
                                        }
                                    });
                                    image.clicked(() -> {
                                        // note: input.recipe only gets set here during a click.
                                        // during a hover only the visual description will be updated.
                                        boolean nothingSelectedYet = input.recipe == null;
                                        boolean selectedSomethingElse = !nothingSelectedYet && input.recipe != r;
                                        boolean shouldMakeSelection = nothingSelectedYet || selectedSomethingElse;
                                        if (shouldMakeSelection) {
                                            input.recipe = r;
                                            hoveredDescriptionRecipe = r;
                                            updateRecipe(r);
                                        } else {
                                            input.recipe = null;
                                            hoveredDescriptionRecipe = null;
                                            updateRecipe(null);
                                        }
                                    });
                                    table.add(image).size(size + 8);
                                    image.getImageCell().size(size);
                                    image.update(() -> {
                                        boolean canPlace = !control.tutorial().active() || control.tutorial().canPlace();
                                        boolean has = (state.inventory.hasItems(r.requirements)) && canPlace;
                                        image.setChecked(input.recipe == r);
                                        image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
                                        image.getImage().setColor(has ? Color.WHITE : Hue.lightness(0.33f));
                                    });
                                    if (i % rows == rows - 1)
                                        table.row();
                                    i++;
                                }
                                table.setVisible(button::isChecked);
                                stack.add(table);
                            }
                            row();
                            add(stack).colspan(Section.values().length);
                            margin(10f);
                            marginLeft(1f);
                            marginRight(1f);
                            end();
                        }
                    }.right().bottom().uniformX();
                    row();
                    if (!android) {
                        weapons = new table("button").margin(0).fillX().end().get();
                    }
                    visible(() -> !state.is(State.menu) && shown);
                }
            }.end().get();
        }
    }.end();
    updateWeapons();
}
Also used : InputHandler(io.anuke.mindustry.input.InputHandler) Table(io.anuke.ucore.scene.ui.layout.Table) Element(io.anuke.ucore.scene.Element) Stack(io.anuke.ucore.scene.ui.layout.Stack) Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputEvent(io.anuke.ucore.scene.event.InputEvent) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table) ClickListener(io.anuke.ucore.scene.event.ClickListener)

Example 17 with Table

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

the class BansDialog method setup.

private void setup() {
    content().clear();
    if (gwt)
        return;
    float w = 400f, h = 80f;
    Table table = new Table();
    ScrollPane pane = new ScrollPane(table, "clear");
    pane.setFadeScrollBars(false);
    if (netServer.admins.getBanned().size == 0) {
        table.add("$text.server.bans.none");
    }
    for (PlayerInfo info : netServer.admins.getBanned()) {
        Table res = new Table("button");
        res.margin(14f);
        res.labelWrap("IP: [LIGHT_GRAY]" + info.lastIP + "\n[]Name: [LIGHT_GRAY]" + info.lastName).width(w - h - 24f);
        res.add().growX();
        res.addImageButton("icon-cancel", 14 * 3, () -> {
            ui.showConfirm("$text.confirm", "$text.confirmunban", () -> {
                netServer.admins.unbanPlayerID(info.id);
                setup();
            });
        }).size(h).pad(-14f);
        table.add(res).width(w).height(h);
        table.row();
    }
    content().add(pane);
}
Also used : Table(io.anuke.ucore.scene.ui.layout.Table) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) PlayerInfo(io.anuke.mindustry.net.Administration.PlayerInfo)

Example 18 with Table

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

the class ChangelogDialog method setup.

void setup() {
    Table table = new Table();
    ScrollPane pane = new ScrollPane(table, "clear");
    content().clear();
    content().add(pane).grow();
    if (versions == null) {
        table.add("$text.changelog.error");
        if (Vars.android) {
            table.row();
            table.add("$text.changelog.error.android").padTop(8);
        }
    } else {
        for (VersionInfo info : versions) {
            Table in = new Table("clear");
            in.top().left().margin(10);
            in.add("[accent]" + info.name);
            if (info.build == Version.build) {
                in.row();
                in.add("$text.changelog.current");
            } else if (info == versions.first()) {
                in.row();
                in.add("$text.changelog.latest");
            }
            in.row();
            in.labelWrap("[lightgray]" + info.description).width(vw - 20).padTop(12);
            table.add(in).width(vw).pad(8).row();
        }
        int lastid = Settings.getInt("lastBuild");
        if (lastid != 0 && versions.peek().build > lastid) {
            Settings.putInt("lastBuild", versions.peek().build);
            Settings.save();
            show();
        }
    }
}
Also used : VersionInfo(io.anuke.mindustry.io.Changelogs.VersionInfo) Table(io.anuke.ucore.scene.ui.layout.Table) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane)

Example 19 with Table

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

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

the class FileChooser method setupWidgets.

private void setupWidgets() {
    getCell(content()).maxWidth(Gdx.graphics.getWidth() / Unit.dp.scl(2f));
    content().margin(-10);
    Table content = new Table();
    filefield = new TextField();
    filefield.setOnlyFontChars(false);
    if (!open)
        Platform.instance.addDialog(filefield);
    filefield.setDisabled(open);
    ok = new TextButton(open ? "$text.load" : "$text.save");
    ok.clicked(() -> {
        if (ok.isDisabled())
            return;
        if (selectListener != null)
            selectListener.accept(directory.child(filefield.getText()));
        hide();
    });
    filefield.changed(() -> {
        ok.setDisabled(filefield.getText().replace(" ", "").isEmpty());
    });
    filefield.change();
    TextButton cancel = new TextButton("$text.cancel");
    cancel.clicked(this::hide);
    navigation = new TextField("");
    navigation.setTouchable(Touchable.disabled);
    files = new Table();
    pane = new ScrollPane(files) {

        public float getPrefHeight() {
            return Gdx.graphics.getHeight();
        }
    };
    pane.setOverscroll(false, false);
    pane.setFadeScrollBars(false);
    updateFiles(true);
    Table icontable = new Table();
    float isize = 14 * 2;
    ImageButton up = new ImageButton("icon-folder-parent");
    up.resizeImage(isize);
    up.clicked(() -> {
        directory = directory.parent();
        updateFiles(true);
    });
    ImageButton back = new ImageButton("icon-arrow-left");
    back.resizeImage(isize);
    ImageButton forward = new ImageButton("icon-arrow-right");
    forward.resizeImage(isize);
    forward.clicked(() -> stack.forward());
    back.clicked(() -> stack.back());
    ImageButton home = new ImageButton("icon-home");
    home.resizeImage(isize);
    home.clicked(() -> {
        directory = homeDirectory;
        updateFiles(true);
    });
    icontable.defaults().height(50).growX().uniform();
    icontable.add(home);
    icontable.add(back);
    icontable.add(forward);
    icontable.add(up);
    Table fieldcontent = new Table();
    fieldcontent.bottom().left().add(new Label("File Name:"));
    fieldcontent.add(filefield).height(40f).fillX().expandX().padLeft(10f);
    Table buttons = new Table();
    buttons.defaults().growX().height(50);
    buttons.add(cancel);
    buttons.add(ok);
    content.top().left();
    content.add(icontable).expandX().fillX();
    content.row();
    content.center().add(pane).width(Gdx.graphics.getWidth() / Unit.dp.scl(2)).colspan(3).grow();
    content.row();
    if (!open) {
        content.bottom().left().add(fieldcontent).colspan(3).grow().padTop(-2).padBottom(2);
        content.row();
    }
    content.add(buttons).growX();
    content().add(content);
}
Also used : Table(io.anuke.ucore.scene.ui.layout.Table)

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