Search in sources :

Example 1 with Draw

use of io.anuke.ucore.graphics.Draw 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)

Aggregations

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 BorderImage (io.anuke.mindustry.ui.BorderImage)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 ScrollPane (io.anuke.ucore.scene.ui.ScrollPane)1 Stack (io.anuke.ucore.scene.ui.layout.Stack)1 Table (io.anuke.ucore.scene.ui.layout.Table)1 Bundles (io.anuke.ucore.util.Bundles)1