From 26b66f9bdbd3a77b32f10f3cb350a9a737d5f012 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 3 Sep 2023 22:02:02 -0400 Subject: [PATCH] Fixed empty admin menu --- .../ui/fragments/PlayerListFragment.java | 193 +++++++++--------- 1 file changed, 94 insertions(+), 99 deletions(-) diff --git a/core/src/mindustry/ui/fragments/PlayerListFragment.java b/core/src/mindustry/ui/fragments/PlayerListFragment.java index da58519de85f..9286aab19502 100644 --- a/core/src/mindustry/ui/fragments/PlayerListFragment.java +++ b/core/src/mindustry/ui/fragments/PlayerListFragment.java @@ -75,6 +75,8 @@ public void build(Group parent){ } public void rebuild(){ + boolean allowTeamSwitch = !state.isCampaign() && (state.rules.pvp || state.rules.infiniteResources); + content.clear(); float h = 50f; @@ -141,15 +143,6 @@ public void draw(){ button.image(Icon.admin).visible(() -> user.admin && !(!user.isLocal() && net.server())).padRight(5).get().updateVisibility(); - var style = new ImageButtonStyle(){{ - down = Styles.none; - up = Styles.none; - imageCheckedColor = Pal.accent; - imageDownColor = Pal.accent; - imageUpColor = Color.white; - imageOverColor = Color.lightGray; - }}; - var ustyle = new ImageButtonStyle(){{ down = Styles.none; up = Styles.none; @@ -161,96 +154,98 @@ public void draw(){ if(net.server() || (player.admin && (!user.admin || user == player))){ button.add().growY(); - button.button(Icon.menu, ustyle, () -> { - var dialog = new BaseDialog(user.coloredName()); - - dialog.title.setColor(Color.white); - dialog.titleTable.remove(); - - dialog.closeOnBack(); - - var bstyle = Styles.defaultt; - - dialog.cont.add(user.coloredName()).row(); - dialog.cont.image(Tex.whiteui, Pal.accent).fillX().height(3f).pad(4f).row(); - - dialog.cont.pane(t -> { - t.defaults().size(220f, 55f).pad(3f); - - if(user != player){ - t.button("@player.ban", Icon.hammer, bstyle, () -> { - ui.showConfirm("@confirm", Core.bundle.format("confirmban", user.name()), () -> Call.adminRequest(user, AdminAction.ban, null)); - dialog.hide(); - }).row(); - - t.button("@player.kick", Icon.cancel, bstyle, () -> { - ui.showConfirm("@confirm", Core.bundle.format("confirmkick", user.name()), () -> Call.adminRequest(user, AdminAction.kick, null)); - dialog.hide(); - }).row(); - - t.button("@player.trace", Icon.zoom, bstyle, () -> { - Call.adminRequest(user, AdminAction.trace, null); - dialog.hide(); - }).row(); - } - - //there's generally no reason to team switch outside PvP or sandbox, and it's basically an easy way to cheat - if(!state.isCampaign() && (state.rules.pvp || state.rules.infiniteResources)){ - t.button("@player.team", Icon.redo, bstyle, () -> { - var teamSelect = new BaseDialog(Core.bundle.get("player.team") + ": " + user.name); - teamSelect.setFillParent(false); - - var group = new ButtonGroup<>(); - - int i = 0; - - for(Team team : Team.baseTeams){ - var b = new ImageButton(Tex.whiteui, Styles.clearNoneTogglei); - b.margin(4f); - b.getImageCell().grow(); - b.getStyle().imageUpColor = team.color; - b.clicked(() -> { - Call.adminRequest(user, AdminAction.switchTeam, team); - teamSelect.hide(); - }); - teamSelect.cont.add(b).size(50f).checked(a -> user.team() == team).group(group); - - if(i++ % 3 == 2) teamSelect.cont.row(); - } - - teamSelect.addCloseButton(); - teamSelect.show(); - - dialog.hide(); - }).row(); - } - - if(!net.client() && !user.isLocal()){ - t.button("@player.admin", Icon.admin, Styles.togglet, () -> { - dialog.hide(); - String id = user.uuid(); - - if(user.admin){ - ui.showConfirm("@confirm", Core.bundle.format("confirmunadmin", user.name()), () -> { - netServer.admins.unAdminPlayer(id); - user.admin = false; - }); - }else{ - ui.showConfirm("@confirm", Core.bundle.format("confirmadmin", user.name()), () -> { - netServer.admins.adminPlayer(id, user.usid()); - user.admin = true; - }); - } - }).checked(b -> user.admin).row(); - } - }).row(); - - dialog.cont.button("@back", Icon.left, dialog::hide).padTop(-1f).size(220f, 55f); - - dialog.show(); - - - }).size(h); + if(allowTeamSwitch || user != player){ + button.button(Icon.menu, ustyle, () -> { + var dialog = new BaseDialog(user.coloredName()); + + dialog.title.setColor(Color.white); + dialog.titleTable.remove(); + + dialog.closeOnBack(); + + var bstyle = Styles.defaultt; + + dialog.cont.add(user.coloredName()).row(); + dialog.cont.image(Tex.whiteui, Pal.accent).fillX().height(3f).pad(4f).row(); + + dialog.cont.pane(t -> { + t.defaults().size(220f, 55f).pad(3f); + + if(user != player){ + t.button("@player.ban", Icon.hammer, bstyle, () -> { + ui.showConfirm("@confirm", Core.bundle.format("confirmban", user.name()), () -> Call.adminRequest(user, AdminAction.ban, null)); + dialog.hide(); + }).row(); + + t.button("@player.kick", Icon.cancel, bstyle, () -> { + ui.showConfirm("@confirm", Core.bundle.format("confirmkick", user.name()), () -> Call.adminRequest(user, AdminAction.kick, null)); + dialog.hide(); + }).row(); + + t.button("@player.trace", Icon.zoom, bstyle, () -> { + Call.adminRequest(user, AdminAction.trace, null); + dialog.hide(); + }).row(); + } + + //there's generally no reason to team switch outside PvP or sandbox, and it's basically an easy way to cheat + if(allowTeamSwitch){ + t.button("@player.team", Icon.redo, bstyle, () -> { + var teamSelect = new BaseDialog(Core.bundle.get("player.team") + ": " + user.name); + teamSelect.setFillParent(false); + + var group = new ButtonGroup<>(); + + int i = 0; + + for(Team team : Team.baseTeams){ + var b = new ImageButton(Tex.whiteui, Styles.clearNoneTogglei); + b.margin(4f); + b.getImageCell().grow(); + b.getStyle().imageUpColor = team.color; + b.clicked(() -> { + Call.adminRequest(user, AdminAction.switchTeam, team); + teamSelect.hide(); + }); + teamSelect.cont.add(b).size(50f).checked(a -> user.team() == team).group(group); + + if(i++ % 3 == 2) teamSelect.cont.row(); + } + + teamSelect.addCloseButton(); + teamSelect.show(); + + dialog.hide(); + }).row(); + } + + if(!net.client() && !user.isLocal()){ + t.button("@player.admin", Icon.admin, Styles.togglet, () -> { + dialog.hide(); + String id = user.uuid(); + + if(user.admin){ + ui.showConfirm("@confirm", Core.bundle.format("confirmunadmin", user.name()), () -> { + netServer.admins.unAdminPlayer(id); + user.admin = false; + }); + }else{ + ui.showConfirm("@confirm", Core.bundle.format("confirmadmin", user.name()), () -> { + netServer.admins.adminPlayer(id, user.usid()); + user.admin = true; + }); + } + }).checked(b -> user.admin).row(); + } + }).row(); + + dialog.cont.button("@back", Icon.left, dialog::hide).padTop(-1f).size(220f, 55f); + + dialog.show(); + + + }).size(h); + } }else if(!user.isLocal() && !user.admin && net.client() && Groups.player.size() >= 3 && player.team() == user.team()){ //votekick button.add().growY();