Skip to content

Commit

Permalink
Fixed empty admin menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Sep 4, 2023
1 parent 5548e72 commit 26b66f9
Showing 1 changed file with 94 additions and 99 deletions.
193 changes: 94 additions & 99 deletions core/src/mindustry/ui/fragments/PlayerListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down

0 comments on commit 26b66f9

Please sign in to comment.