Search in sources :

Example 1 with BorderImage

use of io.anuke.mindustry.ui.BorderImage 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 BorderImage

use of io.anuke.mindustry.ui.BorderImage 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)

Aggregations

BorderImage (io.anuke.mindustry.ui.BorderImage)2 ScrollPane (io.anuke.ucore.scene.ui.ScrollPane)2 Table (io.anuke.ucore.scene.ui.layout.Table)2 Vars (io.anuke.mindustry.Vars)1 State (io.anuke.mindustry.core.GameState.State)1 Player (io.anuke.mindustry.entities.Player)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 Map (io.anuke.mindustry.world.Map)1 Inputs (io.anuke.ucore.core.Inputs)1 Draw (io.anuke.ucore.graphics.Draw)1 Element (io.anuke.ucore.scene.Element)1 io.anuke.ucore.scene.builders.button (io.anuke.ucore.scene.builders.button)1 io.anuke.ucore.scene.builders.label (io.anuke.ucore.scene.builders.label)1 io.anuke.ucore.scene.builders.table (io.anuke.ucore.scene.builders.table)1 Touchable (io.anuke.ucore.scene.event.Touchable)1 ButtonGroup (io.anuke.ucore.scene.ui.ButtonGroup)1