Search in sources :

Example 1 with Element

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

use of io.anuke.ucore.scene.Element 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 3 with Element

use of io.anuke.ucore.scene.Element 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

Element (io.anuke.ucore.scene.Element)3 io.anuke.ucore.scene.builders.table (io.anuke.ucore.scene.builders.table)2 Stack (io.anuke.ucore.scene.ui.layout.Stack)2 Table (io.anuke.ucore.scene.ui.layout.Table)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Array (com.badlogic.gdx.utils.Array)1 Vars (io.anuke.mindustry.Vars)1 State (io.anuke.mindustry.core.GameState.State)1 Player (io.anuke.mindustry.entities.Player)1 InputHandler (io.anuke.mindustry.input.InputHandler)1 Net (io.anuke.mindustry.net.Net)1 NetConnection (io.anuke.mindustry.net.NetConnection)1 NetEvents (io.anuke.mindustry.net.NetEvents)1 AdminAction (io.anuke.mindustry.net.Packets.AdminAction)1 KickReason (io.anuke.mindustry.net.Packets.KickReason)1 BorderImage (io.anuke.mindustry.ui.BorderImage)1 PressGroup (io.anuke.mindustry.ui.PressGroup)1 Inputs (io.anuke.ucore.core.Inputs)1 Draw (io.anuke.ucore.graphics.Draw)1 io.anuke.ucore.scene.builders.button (io.anuke.ucore.scene.builders.button)1