Search in sources :

Example 1 with ButtonGroup

use of io.anuke.ucore.scene.ui.ButtonGroup 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 2 with ButtonGroup

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

Example 3 with ButtonGroup

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

the class MapLoadDialog method rebuild.

public void rebuild() {
    content().clear();
    selected = world.maps().getMap(0);
    ButtonGroup<TextButton> group = new ButtonGroup<>();
    int maxcol = 3;
    int i = 0;
    Table table = new Table();
    table.defaults().size(200f, 90f).pad(4f);
    table.margin(10f);
    ScrollPane pane = new ScrollPane(table, "horizontal");
    pane.setFadeScrollBars(false);
    for (Map map : world.maps().list()) {
        if (!map.visible)
            continue;
        TextButton button = new TextButton(map.localized(), "toggle");
        button.add(new BorderImage(map.texture, 2f)).size(16 * 4f);
        button.getCells().reverse();
        button.clicked(() -> selected = map);
        button.getLabelCell().grow().left().padLeft(5f);
        group.add(button);
        table.add(button);
        if (++i % maxcol == 0)
            table.row();
    }
    content().add("$text.editor.loadmap");
    content().row();
    content().add(pane);
}
Also used : TextButton(io.anuke.ucore.scene.ui.TextButton) Table(io.anuke.ucore.scene.ui.layout.Table) ButtonGroup(io.anuke.ucore.scene.ui.ButtonGroup) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) Map(io.anuke.mindustry.world.Map) BorderImage(io.anuke.mindustry.ui.BorderImage)

Example 4 with ButtonGroup

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

the class Teleporter method buildTable.

@Override
public void buildTable(Tile tile, Table table) {
    TeleporterEntity entity = tile.entity();
    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 < colors; i++) {
        final int f = i;
        ImageButton button = cont.addImageButton("white", "toggle", 24, () -> {
            lastColor = (byte) f;
            setConfigure(tile, (byte) f);
        }).size(34, 38).padBottom(-5.1f).group(group).get();
        button.getStyle().imageUpColor = colorArray[f];
        button.setChecked(entity.color == f);
        if (i % 4 == 3) {
            cont.row();
        }
    }
    table.add(cont);
}
Also used : ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) ButtonGroup(io.anuke.ucore.scene.ui.ButtonGroup)

Example 5 with ButtonGroup

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

the class PlacementFragment method build.

public void build() {
    if (!android)
        return;
    InputHandler input = control.input();
    float s = 50f;
    float translation = Unit.dp.scl(58f);
    new table() {

        {
            visible(() -> !state.is(State.menu));
            abottom();
            aleft();
            ButtonGroup<ImageButton> placeGroup = new ButtonGroup<>();
            ButtonGroup<ImageButton> breakGroup = new ButtonGroup<>();
            update(t -> {
                if ((input.recipe == null) == placing) {
                    float i = 0.1f;
                    Interpolation n = Interpolation.pow3Out;
                    if (input.recipe == null) {
                        placing = false;
                        container.clearActions();
                        container.actions(Actions.translateBy(0, -(container.getTranslation().y + translation), i, n));
                        if (!input.lastBreakMode.both)
                            input.placeMode = input.lastBreakMode;
                    } else {
                        placing = true;
                        container.clearActions();
                        container.actions(Actions.translateBy(0, -(container.getTranslation().y), i, n));
                        input.placeMode = input.lastPlaceMode;
                    }
                }
                if (!input.placeMode.delete) {
                    placeGroup.setMinCheckCount(1);
                    for (ImageButton button : placeGroup.getButtons()) {
                        if (button.getName().equals(input.placeMode.name())) {
                            button.setChecked(true);
                            break;
                        }
                    }
                } else {
                    placeGroup.setMinCheckCount(0);
                    for (ImageButton button : placeGroup.getButtons()) button.setChecked(false);
                }
                if (input.placeMode.delete || input.breakMode.both) {
                    PlaceMode mode = input.breakMode;
                    breakGroup.setMinCheckCount(1);
                    for (ImageButton button : breakGroup.getButtons()) {
                        if (button.getName().equals(mode.name())) {
                            button.setChecked(true);
                            break;
                        }
                    }
                } else {
                    breakGroup.setMinCheckCount(0);
                    for (ImageButton button : breakGroup.getButtons()) button.setChecked(false);
                }
            });
            container = new table() {

                {
                    modelabel = new label("").get();
                    row();
                    // break menu
                    new table() {

                        {
                            abottom();
                            aleft();
                            height(s + 5 + 4);
                            next = new table("pane") {

                                {
                                    margin(5f);
                                    defaults().padBottom(-5.5f);
                                    new imagebutton("icon-arrow-right", 10 * 3, () -> {
                                        toggle(!shown);
                                    }).update(l -> l.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-left" : "icon-" + input.breakMode.name())).size(s, s + 4);
                                }
                            }.end().get();
                            breaktable = new table("pane") {

                                {
                                    visible(() -> shown);
                                    margin(5f);
                                    marginLeft(-(Unit.dp.scl(1f) - 1f) * 2.5f);
                                    touchable(Touchable.enabled);
                                    aleft();
                                    defaults().size(s, s + 4);
                                    for (PlaceMode mode : PlaceMode.values()) {
                                        if (!mode.shown || !mode.delete)
                                            continue;
                                        defaults().padBottom(-5.5f);
                                        ImageButton button = new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
                                            control.input().resetCursor();
                                            input.breakMode = mode;
                                            input.lastBreakMode = mode;
                                            if (!mode.both) {
                                                input.placeMode = mode;
                                            } else {
                                                input.placeMode = input.lastPlaceMode;
                                            }
                                            modeText(Bundles.format("text.mode.break", mode.toString()));
                                        }).group(breakGroup).get();
                                        button.setName(mode.name());
                                        button.released(() -> {
                                            // TODO hack
                                            if (mode == PlaceMode.areaDelete) {
                                                ((AndroidInput) input).placing = false;
                                            }
                                        });
                                    }
                                }
                            }.end().get();
                            breaktable.getParent().swapActor(breaktable, next);
                            breaktable.getTranslation().set(-breaktable.getPrefWidth(), 0);
                        }
                    }.end().get();
                    row();
                    // place menu
                    new table() {

                        {
                            touchable(Touchable.enabled);
                            aleft();
                            new table("pane") {

                                {
                                    margin(5f);
                                    aleft();
                                    defaults().size(s, s + 4).padBottom(-5.5f);
                                    Color color = Color.GRAY;
                                    new imagebutton("icon-cancel", 14 * 3, () -> {
                                        input.recipe = null;
                                    }).imageColor(color).visible(() -> input.recipe != null);
                                    for (PlaceMode mode : PlaceMode.values()) {
                                        if (!mode.shown || mode.delete)
                                            continue;
                                        new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
                                            control.input().resetCursor();
                                            input.placeMode = mode;
                                            input.lastPlaceMode = mode;
                                            modeText(Bundles.format("text.mode.place", mode.toString()));
                                        }).group(placeGroup).get().setName(mode.name());
                                    }
                                    new imagebutton("icon-arrow", 14 * 3, () -> {
                                        input.rotation = Mathf.mod(input.rotation + 1, 4);
                                    }).imageColor(color).visible(() -> input.recipe != null).update(image -> {
                                        image.getImage().setRotation(input.rotation * 90);
                                        image.getImage().setOrigin(Align.center);
                                    });
                                }
                            }.left().end();
                        }
                    }.left().end();
                }
            }.end().get();
            container.setTranslation(0, -translation);
        }
    }.end();
}
Also used : io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table) Core(io.anuke.ucore.core.Core) Bundles(io.anuke.ucore.util.Bundles) AndroidInput(io.anuke.mindustry.input.AndroidInput) io.anuke.ucore.scene.builders.imagebutton(io.anuke.ucore.scene.builders.imagebutton) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) InputHandler(io.anuke.mindustry.input.InputHandler) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) Label(io.anuke.ucore.scene.ui.Label) PlaceMode(io.anuke.mindustry.input.PlaceMode) ButtonGroup(io.anuke.ucore.scene.ui.ButtonGroup) ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) Actions(io.anuke.ucore.scene.actions.Actions) Interpolation(com.badlogic.gdx.math.Interpolation) Unit(io.anuke.ucore.scene.ui.layout.Unit) Mathf(io.anuke.ucore.util.Mathf) Vars(io.anuke.mindustry.Vars) State(io.anuke.mindustry.core.GameState.State) Touchable(io.anuke.ucore.scene.event.Touchable) InputHandler(io.anuke.mindustry.input.InputHandler) Color(com.badlogic.gdx.graphics.Color) PlaceMode(io.anuke.mindustry.input.PlaceMode) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) AndroidInput(io.anuke.mindustry.input.AndroidInput) Interpolation(com.badlogic.gdx.math.Interpolation) ImageButton(io.anuke.ucore.scene.ui.ImageButton) ButtonGroup(io.anuke.ucore.scene.ui.ButtonGroup) io.anuke.ucore.scene.builders.imagebutton(io.anuke.ucore.scene.builders.imagebutton) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table)

Aggregations

ButtonGroup (io.anuke.ucore.scene.ui.ButtonGroup)5 Table (io.anuke.ucore.scene.ui.layout.Table)5 ImageButton (io.anuke.ucore.scene.ui.ImageButton)3 ScrollPane (io.anuke.ucore.scene.ui.ScrollPane)2 TextButton (io.anuke.ucore.scene.ui.TextButton)2 Color (com.badlogic.gdx.graphics.Color)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Interpolation (com.badlogic.gdx.math.Interpolation)1 Align (com.badlogic.gdx.utils.Align)1 Vars (io.anuke.mindustry.Vars)1 State (io.anuke.mindustry.core.GameState.State)1 AndroidInput (io.anuke.mindustry.input.AndroidInput)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 PlaceMode (io.anuke.mindustry.input.PlaceMode)1 Item (io.anuke.mindustry.resource.Item)1 BorderImage (io.anuke.mindustry.ui.BorderImage)1 Map (io.anuke.mindustry.world.Map)1 Core (io.anuke.ucore.core.Core)1 Actions (io.anuke.ucore.scene.actions.Actions)1 io.anuke.ucore.scene.builders.imagebutton (io.anuke.ucore.scene.builders.imagebutton)1