use of io.anuke.ucore.scene.Element 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);
}
use of io.anuke.ucore.scene.Element in project Mindustry by Anuken.
the class PausedDialog method setup.
void setup() {
update(() -> {
if (state.is(State.menu) && isShown()) {
hide();
}
});
shown(() -> {
wasPaused = state.is(State.paused);
if (!Net.active())
state.set(State.paused);
});
if (!android) {
content().defaults().width(220).height(50);
content().addButton("$text.back", () -> {
hide();
if ((!wasPaused || Net.active()) && !state.is(State.menu))
state.set(State.playing);
});
content().row();
content().addButton("$text.settings", ui.settings::show);
content().row();
content().addButton("$text.savegame", () -> {
save.show();
}).disabled(b -> world.getMap().id == -1);
content().row();
content().addButton("$text.loadgame", () -> {
load.show();
}).disabled(b -> Net.active());
content().row();
if (!gwt) {
content().addButton("$text.hostserver", () -> {
ui.host.show();
}).disabled(b -> Net.active());
}
content().row();
content().addButton("$text.quit", () -> {
ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
if (Net.client())
netClient.disconnectQuietly();
runExitSave();
hide();
});
});
} else {
build.begin(content());
PressGroup group = new PressGroup();
content().defaults().size(120f).pad(5);
float isize = 14f * 4;
new imagebutton("icon-play-2", isize, () -> {
hide();
if (!wasPaused && !state.is(State.menu))
state.set(State.playing);
}).text("$text.back").padTop(4f);
new imagebutton("icon-tools", isize, ui.settings::show).text("$text.settings").padTop(4f);
imagebutton sa = new imagebutton("icon-save", isize, save::show);
sa.text("$text.save").padTop(4f);
sa.cell.disabled(b -> world.getMap().id == -1);
content().row();
imagebutton lo = new imagebutton("icon-load", isize, load::show);
lo.text("$text.load").padTop(4f);
lo.cell.disabled(b -> Net.active());
imagebutton ho = new imagebutton("icon-host", isize, () -> {
ui.host.show();
});
ho.text("$text.host").padTop(4f);
ho.cell.disabled(b -> Net.active());
new imagebutton("icon-quit", isize, () -> {
ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
if (Net.client())
netClient.disconnectQuietly();
runExitSave();
hide();
});
}).text("Quit").padTop(4f);
for (Element e : content().getChildren()) {
if (e instanceof ImageButton) {
group.add((ImageButton) e);
}
}
build.end();
}
}
use of io.anuke.ucore.scene.Element in project Mindustry by Anuken.
the class BlocksFragment method build.
public void build() {
InputHandler input = control.input();
new table() {
{
abottom();
aright();
visible(() -> !state.is(State.menu) && shown);
blocks = new table() {
{
itemtable = new Table("button");
itemtable.setVisible(() -> input.recipe == null && !state.mode.infiniteResources);
desctable = new Table("button");
desctable.setVisible(() -> hoveredDescriptionRecipe != null || input.recipe != null);
desctable.update(() -> {
// note: This is required because there is no direct connection between
// input.recipe and the description ui. If input.recipe gets set to null
// a proper cleanup of the ui elements is required.
boolean anyRecipeShown = input.recipe != null || hoveredDescriptionRecipe != null;
boolean descriptionTableClean = desctable.getChildren().size == 0;
boolean cleanupRequired = !anyRecipeShown && !descriptionTableClean;
if (cleanupRequired) {
desctable.clear();
}
});
stack.add(itemtable);
stack.add(desctable);
add(stack).fillX().uniformX();
row();
new table("pane") {
{
touchable(Touchable.enabled);
int rows = 4;
int maxcol = 0;
float size = 48;
Stack stack = new Stack();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Array<Recipe> recipes = new Array<>();
for (Section sec : Section.values()) {
recipes.clear();
Recipes.getBy(sec, recipes);
maxcol = Math.max((int) ((float) recipes.size / rows + 1), maxcol);
}
for (Section sec : Section.values()) {
recipes.clear();
Recipes.getBy(sec, recipes);
Table table = new Table();
ImageButton button = new ImageButton("icon-" + sec.name(), "toggle");
button.clicked(() -> {
if (!table.isVisible() && input.recipe != null) {
input.recipe = null;
}
});
button.setName("sectionbutton" + sec.name());
add(button).growX().height(54).padLeft(-1).padTop(sec.ordinal() <= 2 ? -10 : -5);
button.getImageCell().size(40).padBottom(4).padTop(2);
group.add(button);
if (sec.ordinal() % 3 == 2 && sec.ordinal() > 0) {
row();
}
table.margin(4);
table.top().left();
int i = 0;
for (Recipe r : recipes) {
TextureRegion region = Draw.hasRegion(r.result.name() + "-icon") ? Draw.region(r.result.name() + "-icon") : Draw.region(r.result.name());
ImageButton image = new ImageButton(region, "select");
image.addListener(new ClickListener() {
@Override
public void enter(InputEvent event, float x, float y, int pointer, Element fromActor) {
super.enter(event, x, y, pointer, fromActor);
if (hoveredDescriptionRecipe != r) {
hoveredDescriptionRecipe = r;
updateRecipe(r);
}
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Element toActor) {
super.exit(event, x, y, pointer, toActor);
hoveredDescriptionRecipe = null;
updateRecipe(input.recipe);
}
});
image.clicked(() -> {
// note: input.recipe only gets set here during a click.
// during a hover only the visual description will be updated.
boolean nothingSelectedYet = input.recipe == null;
boolean selectedSomethingElse = !nothingSelectedYet && input.recipe != r;
boolean shouldMakeSelection = nothingSelectedYet || selectedSomethingElse;
if (shouldMakeSelection) {
input.recipe = r;
hoveredDescriptionRecipe = r;
updateRecipe(r);
} else {
input.recipe = null;
hoveredDescriptionRecipe = null;
updateRecipe(null);
}
});
table.add(image).size(size + 8);
image.getImageCell().size(size);
image.update(() -> {
boolean canPlace = !control.tutorial().active() || control.tutorial().canPlace();
boolean has = (state.inventory.hasItems(r.requirements)) && canPlace;
image.setChecked(input.recipe == r);
image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
image.getImage().setColor(has ? Color.WHITE : Hue.lightness(0.33f));
});
if (i % rows == rows - 1)
table.row();
i++;
}
table.setVisible(button::isChecked);
stack.add(table);
}
row();
add(stack).colspan(Section.values().length);
margin(10f);
marginLeft(1f);
marginRight(1f);
end();
}
}.right().bottom().uniformX();
row();
if (!android) {
weapons = new table("button").margin(0).fillX().end().get();
}
visible(() -> !state.is(State.menu) && shown);
}
}.end().get();
}
}.end();
updateWeapons();
}
Aggregations