use of io.anuke.ucore.scene.ui.layout.Table 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.layout.Table 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.layout.Table in project Mindustry by Anuken.
the class MapEditorDialog method build.
public void build() {
new table() {
{
float isize = 16 * 2f;
aleft();
new table() {
{
defaults().growY().width(130f).padBottom(-6);
new imagebutton("icon-terrain", isize, () -> dialog.show()).text("$text.editor.generate");
row();
new imagebutton("icon-resize", isize, () -> resizeDialog.show()).text("$text.editor.resize").padTop(4f);
row();
new imagebutton("icon-load-map", isize, () -> loadDialog.show()).text("$text.editor.loadmap");
row();
new imagebutton("icon-save-map", isize, () -> saveDialog.show()).text("$text.editor.savemap");
row();
new imagebutton("icon-load-image", isize, () -> openFile.show()).text("$text.editor.loadimage");
row();
new imagebutton("icon-save-image", isize, () -> saveFile.show()).text("$text.editor.saveimage");
row();
new imagebutton("icon-back", isize, () -> {
if (!saved) {
ui.showConfirm("$text.confirm", "$text.editor.unsaved", MapEditorDialog.this::hide);
} else {
hide();
}
}).padBottom(0).text("$text.back");
}
}.left().growY().end();
new table("button") {
{
add(view).grow();
}
}.grow().end();
new table() {
{
Table tools = new Table("button");
tools.top();
tools.marginTop(0).marginBottom(6);
ButtonGroup<ImageButton> group = new ButtonGroup<>();
int i = 1;
tools.defaults().size(53f, 58f).padBottom(-6);
ImageButton undo = tools.addImageButton("icon-undo", 16 * 2f, () -> view.undo()).get();
ImageButton redo = tools.addImageButton("icon-redo", 16 * 2f, () -> view.redo()).get();
ImageButton grid = tools.addImageButton("icon-grid", "toggle", 16 * 2f, () -> view.setGrid(!view.isGrid())).get();
undo.setDisabled(() -> !view.getStack().canUndo());
redo.setDisabled(() -> !view.getStack().canRedo());
undo.update(() -> undo.getImage().setColor(undo.isDisabled() ? Color.GRAY : Color.WHITE));
redo.update(() -> redo.getImage().setColor(redo.isDisabled() ? Color.GRAY : Color.WHITE));
grid.update(() -> grid.setChecked(view.isGrid()));
for (EditorTool tool : EditorTool.values()) {
ImageButton button = new ImageButton("icon-" + tool.name(), "toggle");
button.clicked(() -> view.setTool(tool));
button.resizeImage(16 * 2f);
button.update(() -> button.setChecked(view.getTool() == tool));
group.add(button);
if (tool == EditorTool.pencil)
button.setChecked(true);
tools.add(button).padBottom(-6f);
if (i++ % 4 == 1)
tools.row();
}
add(tools).width(53 * 4).padBottom(-6);
row();
new table("button") {
{
margin(10f);
Slider slider = new Slider(0, MapEditor.brushSizes.length - 1, 1, false);
slider.moved(f -> editor.setBrushSize(MapEditor.brushSizes[(int) (float) f]));
new label(() -> Bundles.format("text.editor.brushsize", MapEditor.brushSizes[(int) slider.getValue()])).left();
row();
add(slider).growX().padTop(4f);
}
}.growX().padBottom(-6).end();
row();
new table("button") {
{
get().addCheck("$text.oregen", b -> editor.getMap().oreGen = b).update(c -> c.setChecked(editor.getMap().oreGen)).padTop(3).padBottom(3);
}
}.growX().padBottom(-6).end();
row();
addBlockSelection(get());
row();
}
}.right().growY().end();
}
}.grow().end();
}
use of io.anuke.ucore.scene.ui.layout.Table in project Mindustry by Anuken.
the class LevelDialog method displayGameModeHelp.
private void displayGameModeHelp() {
FloatingDialog d = new FloatingDialog(Bundles.get("mode.text.help.title"));
d.setFillParent(false);
Table table = new Table();
table.defaults().pad(1f);
ScrollPane pane = new ScrollPane(table, "clear");
pane.setFadeScrollBars(false);
table.row();
for (GameMode mode : GameMode.values()) {
table.labelWrap("[accent]" + mode.toString() + ":[] [lightgray]" + mode.description()).width(600f);
table.row();
}
d.content().add(pane);
d.buttons().addButton("$text.ok", d::hide).size(110, 50).pad(10f);
d.show();
}
use of io.anuke.ucore.scene.ui.layout.Table 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);
});
});
}
Aggregations