Search in sources :

Example 1 with Stack

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

Example 2 with Stack

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

the class PlayerListFragment method rebuild.

public void rebuild() {
    content.clear();
    float h = 74f;
    for (Player player : playerGroup.all()) {
        NetConnection connection = gwt ? null : Net.getConnection(player.clientid);
        if (connection == null && Net.server() && !player.isLocal)
            continue;
        Table button = new Table("button");
        button.left();
        button.margin(5).marginBottom(10);
        Stack stack = new Stack();
        BorderImage image = new BorderImage(Draw.region(player.isAndroid ? "ship-standard" : "mech-standard-icon"), 3f);
        stack.add(image);
        if (!player.isAndroid) {
            stack.add(new Element() {

                public void draw() {
                    float s = getWidth() / 12f;
                    for (int i : Mathf.signs) {
                        Draw.rect((i < 0 ? player.weaponLeft.name : player.weaponRight.name) + "-equip", x + s * 6 + i * 3 * s, y + s * 6 + 2 * s, -8 * s * i, 8 * s);
                    }
                }
            });
        }
        button.add(stack).size(h);
        button.labelWrap("[#" + player.getColor().toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
        button.add().grow();
        button.addImage("icon-admin").size(14 * 2).visible(() -> player.isAdmin && !(!player.isLocal && Net.server())).padRight(5);
        if ((Net.server() || Vars.player.isAdmin) && !player.isLocal && (!player.isAdmin || Net.server())) {
            button.add().growY();
            float bs = (h + 14) / 2f;
            button.table(t -> {
                t.defaults().size(bs - 1, bs + 3);
                t.addImageButton("icon-ban", 14 * 2, () -> {
                    ui.showConfirm("$text.confirm", "$text.confirmban", () -> {
                        if (Net.server()) {
                            netServer.admins.banPlayerIP(connection.address);
                            netServer.kick(player.clientid, KickReason.banned);
                        } else {
                            NetEvents.handleAdministerRequest(player, AdminAction.ban);
                        }
                    });
                }).padBottom(-5.1f);
                t.addImageButton("icon-cancel", 14 * 2, () -> {
                    if (Net.server()) {
                        netServer.kick(player.clientid, KickReason.kick);
                    } else {
                        NetEvents.handleAdministerRequest(player, AdminAction.kick);
                    }
                }).padBottom(-5.1f);
                t.row();
                t.addImageButton("icon-admin", "toggle", 14 * 2, () -> {
                    if (Net.client())
                        return;
                    String id = netServer.admins.getTrace(connection.address).uuid;
                    if (netServer.admins.isAdmin(id, connection.address)) {
                        ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
                            netServer.admins.unAdminPlayer(id);
                            NetEvents.handleAdminSet(player, false);
                        });
                    } else {
                        ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> {
                            netServer.admins.adminPlayer(id, connection.address);
                            NetEvents.handleAdminSet(player, true);
                        });
                    }
                }).update(b -> {
                    b.setChecked(player.isAdmin);
                    b.setDisabled(Net.client());
                }).get().setTouchable(() -> Net.client() ? Touchable.disabled : Touchable.enabled);
                t.addImageButton("icon-zoom-small", 14 * 2, () -> NetEvents.handleTraceRequest(player));
            }).padRight(12).padTop(-5).padLeft(0).padBottom(-10).size(bs + 10f, bs);
        }
        content.add(button).padBottom(-6).width(350f).maxHeight(h + 14);
        content.row();
    }
    content.marginBottom(5);
}
Also used : Player(io.anuke.mindustry.entities.Player) KickReason(io.anuke.mindustry.net.Packets.KickReason) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table) io.anuke.ucore.scene.builders.button(io.anuke.ucore.scene.builders.button) Bundles(io.anuke.ucore.util.Bundles) Stack(io.anuke.ucore.scene.ui.layout.Stack) Net(io.anuke.mindustry.net.Net) AdminAction(io.anuke.mindustry.net.Packets.AdminAction) NetEvents(io.anuke.mindustry.net.NetEvents) BorderImage(io.anuke.mindustry.ui.BorderImage) Draw(io.anuke.ucore.graphics.Draw) Element(io.anuke.ucore.scene.Element) NetConnection(io.anuke.mindustry.net.NetConnection) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) Table(io.anuke.ucore.scene.ui.layout.Table) Mathf(io.anuke.ucore.util.Mathf) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) Vars(io.anuke.mindustry.Vars) State(io.anuke.mindustry.core.GameState.State) Inputs(io.anuke.ucore.core.Inputs) Touchable(io.anuke.ucore.scene.event.Touchable) Player(io.anuke.mindustry.entities.Player) NetConnection(io.anuke.mindustry.net.NetConnection) Table(io.anuke.ucore.scene.ui.layout.Table) Element(io.anuke.ucore.scene.Element) BorderImage(io.anuke.mindustry.ui.BorderImage) Stack(io.anuke.ucore.scene.ui.layout.Stack)

Example 3 with Stack

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

Aggregations

Stack (io.anuke.ucore.scene.ui.layout.Stack)3 Table (io.anuke.ucore.scene.ui.layout.Table)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 Vars (io.anuke.mindustry.Vars)2 Element (io.anuke.ucore.scene.Element)2 io.anuke.ucore.scene.builders.table (io.anuke.ucore.scene.builders.table)2 ClickListener (io.anuke.ucore.scene.event.ClickListener)2 InputEvent (io.anuke.ucore.scene.event.InputEvent)2 Touchable (io.anuke.ucore.scene.event.Touchable)2 Bundles (io.anuke.ucore.util.Bundles)2 Mathf (io.anuke.ucore.util.Mathf)2 Vector2 (com.badlogic.gdx.math.Vector2)1 Array (com.badlogic.gdx.utils.Array)1 State (io.anuke.mindustry.core.GameState.State)1 Player (io.anuke.mindustry.entities.Player)1 Difficulty (io.anuke.mindustry.game.Difficulty)1 GameMode (io.anuke.mindustry.game.GameMode)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 Net (io.anuke.mindustry.net.Net)1 NetConnection (io.anuke.mindustry.net.NetConnection)1