Fixed player mech icon clip / Added kick confirmation

This commit is contained in:
Anuken
2018-09-04 17:42:56 -04:00
parent 9a5495d8b2
commit 7b90544d91
2 changed files with 32 additions and 39 deletions

View File

@@ -125,6 +125,7 @@ text.server.outdated.client=[crimson]Outdated Client![]
text.server.version=[lightgray]Version: {0} {1} text.server.version=[lightgray]Version: {0} {1}
text.server.custombuild=[yellow]Custom Build text.server.custombuild=[yellow]Custom Build
text.confirmban=Are you sure you want to ban this player? text.confirmban=Are you sure you want to ban this player?
text.confirmkick=Are you sure you want to kick this player?
text.confirmunban=Are you sure you want to unban this player? text.confirmunban=Are you sure you want to unban this player?
text.confirmadmin=Are you sure you want to make this player an admin? text.confirmadmin=Are you sure you want to make this player an admin?
text.confirmunadmin=Are you sure you want to remove admin status from this player? text.confirmunadmin=Are you sure you want to remove admin status from this player?

View File

@@ -1,19 +1,21 @@
package io.anuke.mindustry.ui.fragments; package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.graphics.g2d.Batch;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetConnection; import io.anuke.mindustry.net.NetConnection;
import io.anuke.mindustry.net.Packets.AdminAction; import io.anuke.mindustry.net.Packets.AdminAction;
import io.anuke.mindustry.ui.BorderImage; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.scene.Group; import io.anuke.ucore.scene.Group;
import io.anuke.ucore.scene.event.Touchable; import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.Image; import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.layout.Stack;
import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Bundles; import io.anuke.ucore.util.Bundles;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
@@ -21,7 +23,6 @@ import static io.anuke.mindustry.Vars.*;
public class PlayerListFragment extends Fragment{ public class PlayerListFragment extends Fragment{
private boolean visible = false; private boolean visible = false;
private Table content = new Table().marginRight(13f).marginLeft(13f); private Table content = new Table().marginRight(13f).marginLeft(13f);
private ObjectMap<Player, Boolean> checkmap = new ObjectMap<>();
@Override @Override
public void build(Group parent){ public void build(Group parent){
@@ -30,24 +31,11 @@ public class PlayerListFragment extends Fragment{
cont.update(() -> { cont.update(() -> {
if(!(Net.active() && !state.is(State.menu))){ if(!(Net.active() && !state.is(State.menu))){
visible = false; visible = false;
return;
} }
boolean rebuild = false;
for(Player player : playerGroup.all()){ if(visible && Timers.get("player-list-rebuild", 20)){
if(!checkmap.containsKey(player) || checkmap.get(player, false) != player.isAdmin){
rebuild = true;
}
}
for(Player player : checkmap.keys()){
if(!player.isAdded()){
rebuild = true;
}
}
if(rebuild){
rebuild(); rebuild();
checkmap.clear();
for(Player player : playerGroup.all()){
checkmap.put(player, player.isAdmin);
}
} }
}); });
@@ -86,14 +74,21 @@ public class PlayerListFragment extends Fragment{
button.left(); button.left();
button.margin(5).marginBottom(10); button.margin(5).marginBottom(10);
Stack stack = new Stack(); Table table = new Table(){
BorderImage image = new BorderImage(Draw.region(player.mech.name), 3f); @Override
public void draw(Batch batch, float parentAlpha){
super.draw(batch, parentAlpha);
Draw.color(Palette.accent);
Draw.alpha(parentAlpha);
Lines.stroke(Unit.dp.scl(3f));
Lines.rect(x, y, width, height);
Draw.reset();
}
};
table.margin(8);
table.add(new Image(player.mech.iconRegion)).grow();
stack.add(image); button.add(table).size(h);
stack.add(new Image(player.mech.iconRegion));
button.add(stack).size(h);
button.labelWrap("[#" + player.color.toString().toUpperCase() + "]" + player.name).width(170f).pad(10); button.labelWrap("[#" + player.color.toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
button.add().grow(); button.add().grow();
@@ -106,13 +101,11 @@ public class PlayerListFragment extends Fragment{
button.table(t -> { button.table(t -> {
t.defaults().size(bs - 1, bs + 3); t.defaults().size(bs - 1, bs + 3);
//TODO requests.
t.addImageButton("icon-ban", 14 * 2, () -> { t.addImageButton("icon-ban", 14 * 2,
ui.showConfirm("$text.confirm", "$text.confirmban", () -> Call.onAdminRequest(player, AdminAction.ban)); () -> ui.showConfirm("$text.confirm", "$text.confirmban", () -> Call.onAdminRequest(player, AdminAction.ban))).padBottom(-5.1f);
}).padBottom(-5.1f); t.addImageButton("icon-cancel", 14 * 2,
() -> ui.showConfirm("$text.confirm", "$text.confirmkick", () -> Call.onAdminRequest(player, AdminAction.kick))).padBottom(-5.1f);
t.addImageButton("icon-cancel", 14 * 2, () -> Call.onAdminRequest(player, AdminAction.kick)).padBottom(-5.1f);
t.row(); t.row();
@@ -122,13 +115,9 @@ public class PlayerListFragment extends Fragment{
String id = netServer.admins.getTraceByID(player.uuid).uuid; String id = netServer.admins.getTraceByID(player.uuid).uuid;
if(netServer.admins.isAdmin(id, connection.address)){ if(netServer.admins.isAdmin(id, connection.address)){
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> { ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> netServer.admins.unAdminPlayer(id));
netServer.admins.unAdminPlayer(id);
});
}else{ }else{
ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> { ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> netServer.admins.adminPlayer(id, player.usid));
netServer.admins.adminPlayer(id, player.usid);
});
} }
}).update(b -> { }).update(b -> {
b.setChecked(player.isAdmin); b.setChecked(player.isAdmin);
@@ -151,6 +140,9 @@ public class PlayerListFragment extends Fragment{
public void toggle(){ public void toggle(){
visible = !visible; visible = !visible;
if(visible){
rebuild();
}
} }
} }