use of io.anuke.ucore.scene.ui.layout.Stack in project Mindustry by Anuken.
the class LevelDialog method setup.
void setup() {
Table maps = new Table();
pane = new ScrollPane(maps);
pane.setFadeScrollBars(false);
int maxwidth = 4;
Table selmode = new Table();
ButtonGroup<TextButton> group = new ButtonGroup<>();
selmode.add("$text.level.mode").padRight(15f);
for (GameMode mode : GameMode.values()) {
TextButton[] b = { null };
b[0] = Elements.newButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode);
b[0].update(() -> b[0].setChecked(state.mode == mode));
group.add(b[0]);
selmode.add(b[0]).size(130f, 54f);
}
selmode.addButton("?", this::displayGameModeHelp).size(50f, 54f).padLeft(18f);
content().add(selmode);
content().row();
Difficulty[] ds = Difficulty.values();
float s = 50f;
Table sdif = new Table();
sdif.add("$setting.difficulty.name").padRight(15f);
sdif.defaults().height(s + 4);
sdif.addImageButton("icon-arrow-left", 10 * 3, () -> {
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
}).width(s);
sdif.addButton("", () -> {
}).update(t -> {
t.setText(state.difficulty.toString());
t.setTouchable(Touchable.disabled);
}).width(180f);
sdif.addImageButton("icon-arrow-right", 10 * 3, () -> {
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() + 1, ds.length)]);
}).width(s);
content().add(sdif);
content().row();
int i = 0;
for (Map map : world.maps().list()) {
if (!map.visible && !debug)
continue;
if (i % maxwidth == 0) {
maps.row();
}
Table inset = new Table("pane-button");
inset.add("[accent]" + Bundles.get("map." + map.name + ".name", map.name)).pad(3f);
inset.row();
inset.label((() -> {
try {
return Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name));
} catch (Exception e) {
Settings.defaults("hiscore" + map.name, 1);
return Bundles.format("text.level.highscore", 0);
}
})).pad(3f);
inset.pack();
float images = 154f;
Stack stack = new Stack();
Image back = new Image("white");
back.setColor(map.backgroundColor);
ImageButton image = new ImageButton(new TextureRegion(map.texture), "togglemap");
image.row();
image.add(inset).width(images + 6);
TextButton[] delete = new TextButton[1];
if (map.custom) {
image.row();
delete[0] = image.addButton("Delete", () -> {
Timers.run(1f, () -> {
ui.showConfirm("$text.level.delete.title", Bundles.format("text.level.delete", Bundles.get("map." + map.name + ".name", map.name)), () -> {
world.maps().removeMap(map);
reload();
Core.scene.setScrollFocus(pane);
});
});
}).width(images + 16).padBottom(-10f).grow().get();
}
Vector2 hit = new Vector2();
image.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
image.localToStageCoordinates(hit.set(x, y));
if (delete[0] != null && (delete[0].getClickListener().isOver() || delete[0].getClickListener().isPressed() || (Core.scene.hit(hit.x, hit.y, true) != null && Core.scene.hit(hit.x, hit.y, true).isDescendantOf(delete[0])))) {
return;
}
selectedMap = map;
hide();
control.playMap(selectedMap);
}
});
image.getImageCell().size(images);
stack.add(back);
stack.add(image);
maps.add(stack).width(170).top().pad(4f);
maps.marginRight(26);
i++;
}
content().add(pane).uniformX();
shown(() -> {
// this is necessary for some reason?
Timers.run(2f, () -> {
Core.scene.setScrollFocus(pane);
});
});
}
use of io.anuke.ucore.scene.ui.layout.Stack 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.ui.layout.Stack 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