use of io.anuke.ucore.scene.ui.ImageButton in project Mindustry by Anuken.
the class WeaponFactory method buildTable.
@Override
public void buildTable(Tile tile, Table table) {
int i = 0;
Table content = new Table();
for (Upgrade upgrade : Upgrade.getAllUpgrades()) {
if (!(upgrade instanceof Weapon))
continue;
Weapon weapon = (Weapon) upgrade;
ItemStack[] requirements = UpgradeRecipes.get(weapon);
Table tiptable = new Table();
Listenable run = () -> {
tiptable.clearChildren();
String description = weapon.description;
tiptable.background("pane");
tiptable.add("[orange]" + weapon.localized(), 0.5f).left().padBottom(2f);
Table reqtable = new Table();
tiptable.row();
tiptable.add(reqtable).left();
if (!control.upgrades().hasWeapon(weapon)) {
for (ItemStack s : requirements) {
int amount = Math.min(state.inventory.getAmount(s.item), s.amount);
reqtable.addImage(s.item.region).padRight(3).size(8 * 2);
reqtable.add((amount >= s.amount ? "" : "[RED]") + amount + " / " + s.amount, 0.5f).left();
reqtable.row();
}
}
tiptable.row();
tiptable.add().size(4);
tiptable.row();
tiptable.add("[gray]" + description).left();
tiptable.row();
if (control.upgrades().hasWeapon(weapon)) {
tiptable.add("$text.purchased").padTop(4).left();
}
tiptable.margin(8f);
};
run.listen();
Tooltip<Table> tip = new Tooltip<>(tiptable, run);
tip.setInstant(true);
ImageButton button = content.addImageButton("white", 8 * 4, () -> {
if (Net.client()) {
NetEvents.handleUpgrade(weapon);
} else {
state.inventory.removeItems(requirements);
control.upgrades().addWeapon(weapon);
ui.hudfrag.updateWeapons();
run.listen();
Effects.sound("purchase");
}
}).size(49f, 54f).padBottom(-5).get();
button.setDisabled(() -> control.upgrades().hasWeapon(weapon) || !state.inventory.hasItems(requirements));
button.getStyle().imageUp = new TextureRegionDrawable(Draw.region(weapon.name));
button.addListener(tip);
if (++i % 3 == 0) {
content.row();
}
}
table.add(content).padTop(140f);
}
use of io.anuke.ucore.scene.ui.ImageButton in project Mindustry by Anuken.
the class Sorter method buildTable.
@Override
public void buildTable(Tile tile, Table table) {
SorterEntity entity = tile.entity();
Array<Item> items = Item.getAllItems();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Table cont = new Table();
cont.margin(4);
cont.marginBottom(5);
cont.add().colspan(4).height(105f);
cont.row();
for (int i = 0; i < items.size; i++) {
final int f = i;
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> {
entity.sortItem = items.get(f);
setConfigure(tile, (byte) f);
}).size(38, 42).padBottom(-5.1f).group(group).get();
button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(items.get(i).region));
button.setChecked(entity.sortItem.id == f);
if (i % 4 == 3) {
cont.row();
}
}
table.add(cont);
}
use of io.anuke.ucore.scene.ui.ImageButton 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.ui.ImageButton in project Mindustry by Anuken.
the class ColorPickDialog method build.
private void build() {
Table table = new Table();
content().add(table);
for (int i = 0; i < playerColors.length; i++) {
Color color = playerColors[i];
ImageButton button = table.addImageButton("white", "toggle", 34, () -> {
cons.accept(color);
hide();
}).size(44, 48).pad(0).padBottom(-5.1f).get();
button.setChecked(player.getColor().equals(color));
button.getStyle().imageUpColor = color;
if (i % 4 == 3) {
table.row();
}
}
}
use of io.anuke.ucore.scene.ui.ImageButton in project Mindustry by Anuken.
the class JoinDialog method setup.
void setup() {
hosts.clear();
hosts.add(remote).growX();
hosts.row();
hosts.add(local).width(w);
ScrollPane pane = new ScrollPane(hosts, "clear");
pane.setFadeScrollBars(false);
pane.setScrollingDisabled(true, false);
setupRemote();
refreshRemote();
content().clear();
content().table(t -> {
t.add("$text.name").padRight(10);
t.addField(Settings.getString("name"), text -> {
if (text.isEmpty())
return;
Vars.player.name = text;
Settings.put("name", text);
Settings.save();
}).grow().pad(8).get().setMaxLength(40);
ImageButton button = t.addImageButton("white", 40, () -> {
new ColorPickDialog().show(color -> {
player.color.set(color);
Settings.putInt("color", Color.rgba8888(color));
Settings.save();
});
}).size(50f, 54f).get();
button.update(() -> button.getStyle().imageUpColor = player.getColor());
}).width(w).height(70f).pad(4);
content().row();
content().add(pane).width(w + 34).pad(0);
content().row();
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14 * 3, () -> {
renaming = null;
add.show();
}).marginLeft(6).width(w).height(80f).update(button -> {
float pw = w;
float pad = 0f;
if (pane.getChildren().first().getPrefHeight() > pane.getHeight()) {
pw = w + 30;
pad = 6;
}
Cell<TextButton> cell = ((Table) pane.getParent()).getCell(button);
if (!MathUtils.isEqual(cell.getMinWidth(), pw)) {
cell.width(pw);
cell.padLeft(pad);
pane.getParent().invalidateHierarchy();
}
});
}
Aggregations