Search in sources :

Example 1 with TextureRegionDrawable

use of io.anuke.ucore.scene.style.TextureRegionDrawable 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);
}
Also used : ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) Tooltip(io.anuke.ucore.scene.ui.Tooltip) TextureRegionDrawable(io.anuke.ucore.scene.style.TextureRegionDrawable) ItemStack(io.anuke.mindustry.resource.ItemStack) Upgrade(io.anuke.mindustry.resource.Upgrade) Weapon(io.anuke.mindustry.resource.Weapon) Listenable(io.anuke.ucore.function.Listenable)

Example 2 with TextureRegionDrawable

use of io.anuke.ucore.scene.style.TextureRegionDrawable 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);
}
Also used : Item(io.anuke.mindustry.resource.Item) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(io.anuke.ucore.scene.ui.ImageButton) Table(io.anuke.ucore.scene.ui.layout.Table) ButtonGroup(io.anuke.ucore.scene.ui.ButtonGroup) TextureRegionDrawable(io.anuke.ucore.scene.style.TextureRegionDrawable)

Aggregations

TextureRegionDrawable (io.anuke.ucore.scene.style.TextureRegionDrawable)2 ImageButton (io.anuke.ucore.scene.ui.ImageButton)2 Table (io.anuke.ucore.scene.ui.layout.Table)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Item (io.anuke.mindustry.resource.Item)1 ItemStack (io.anuke.mindustry.resource.ItemStack)1 Upgrade (io.anuke.mindustry.resource.Upgrade)1 Weapon (io.anuke.mindustry.resource.Weapon)1 Listenable (io.anuke.ucore.function.Listenable)1 ButtonGroup (io.anuke.ucore.scene.ui.ButtonGroup)1 Tooltip (io.anuke.ucore.scene.ui.Tooltip)1