player window

This commit is contained in:
sharlottes
2022-04-12 23:42:12 +09:00
parent d04b8aae88
commit 04b6c514d1
3 changed files with 119 additions and 2 deletions

View File

@@ -17,13 +17,15 @@ public class HUDFragment extends Fragment{
t.add(new TaskbarTable( t.add(new TaskbarTable(
unitTable, unitTable,
waveTable, waveTable,
coreTable coreTable,
playerTable
)).visible(TaskbarTable.visibility); )).visible(TaskbarTable.visibility);
// windows (totally not a copyright violation) // windows (totally not a copyright violation)
t.add(unitTable).size(250f).visible(false); t.add(unitTable).size(250f).visible(false);
t.add(waveTable).size(250f).visible(false); t.add(waveTable).size(250f).visible(false);
t.add(coreTable).size(250f).visible(false); t.add(coreTable).size(250f).visible(false);
t.add(playerTable).size(250f).visible(false);
t.update(()->{ t.update(()->{
for (Element child : t.getChildren()) { for (Element child : t.getChildren()) {

View File

@@ -0,0 +1,114 @@
package UnitInfo.ui.windows;
import UnitInfo.ui.OverScrollPane;
import UnitInfo.ui.Updatable;
import arc.Core;
import arc.graphics.Color;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Lines;
import arc.math.geom.Vec2;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.scene.utils.Elem;
import arc.struct.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.ui.*;
import static mindustry.Vars.*;
public class PlayerDisplay extends WindowTable implements Updatable {
Vec2 scrollPos = new Vec2(0, 0);
TextField search;
float heat;
public PlayerDisplay() {
super("Player Display", Icon.players, t -> {});
}
@Override
public void build() {
scrollPos = new Vec2(0, 0);
search = Elem.newField(null, f->{});
search.setMessageText(Core.bundle.get("players.search"));
top();
topBar();
table(Styles.black8, table -> {
table.label(()-> Core.bundle.format(Groups.player.size() == 1 ? "players.single" : "players", Groups.player.size())).row();
table.add(search).growX().pad(8).name("search").maxTextLength(maxNameLength).row();
table.add(new OverScrollPane(rebuild(), Styles.nonePane, scrollPos).disableScroll(true, false)).grow().name("player-pane");
}).top().right().grow().get().parent = null;
resizeButton();
}
@Override
public void update() {
heat += Time.delta;
if(heat >= 60f) {
heat = 0f;
ScrollPane pane = find("player-pane");
pane.setWidget(rebuild());
}
}
public Table rebuild(){
return new Table(table -> {
float h = 74f;
ImageButton.ImageButtonStyle ustyle = new ImageButton.ImageButtonStyle(){{
down = Styles.none;
up = Styles.none;
imageDownColor = Pal.accent;
imageUpColor = Color.white;
imageOverColor = Color.lightGray;
}};
Seq<Player> players = Groups.player.copy(new Seq<>());
players.sort(Structs.comps(Structs.comparing(Player::team), Structs.comparingBool(p -> !p.admin)));
if(search.getText().length() > 0){
players.filter(p -> Strings.stripColors(p.name().toLowerCase()).contains(search.getText().toLowerCase()));
}
if(players.isEmpty()){
table.add(Core.bundle.format("players.notfound")).center();
return;
}
for(Player user : players){
table.table(userTable-> {
userTable.left().margin(5).marginBottom(10);
Table table1 = new Table(){
@Override
public void draw(){
super.draw();
Draw.color(Pal.gray);
Draw.alpha(parentAlpha);
Lines.stroke(Scl.scl(4f));
Lines.rect(x, y, width, height);
Draw.reset();
}
};
table1.margin(8);
table1.add(new Image(user.icon()).setScaling(Scaling.bounded)).grow();
userTable.add(table1).size(h).name(user.name()); //unit icon
userTable.labelWrap(user.name()).color(user.color()).width(170f).pad(10); //name
userTable.image(Icon.admin).padRight(5).visible(()->user.admin);; //admin
userTable.button(Icon.hammer, ustyle, () -> { //vote kick
ui.showConfirm("@confirm", Core.bundle.format("confirmvotekick", user.name()), () -> {
Call.sendChatMessage("/votekick " + user.name());
});
}).right().visible(()->user.team()==player.team()&&user!=player&&!user.admin);
}).padBottom(-6).maxHeight(h + 14).row();
table.image().height(4f).color(state.rules.pvp ? user.team().color : Pal.gray).growX().row();
}
});
}
}

View File

@@ -2,11 +2,12 @@ package UnitInfo.ui.windows;
public class WindowTables { public class WindowTables {
public static WindowTable public static WindowTable
unitTable, waveTable, coreTable; unitTable, waveTable, coreTable, playerTable;
public static void init() { public static void init() {
unitTable = new UnitDisplay(); unitTable = new UnitDisplay();
waveTable = new WaveDisplay(); waveTable = new WaveDisplay();
coreTable = new CoreDisplay(); coreTable = new CoreDisplay();
playerTable = new PlayerDisplay();
} }
} }