Search in sources :

Example 1 with Weapon

use of io.anuke.mindustry.resource.Weapon 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 Weapon

use of io.anuke.mindustry.resource.Weapon in project Mindustry by Anuken.

the class Player method drawSmooth.

@Override
public void drawSmooth() {
    if ((debug && (!showPlayer || !showUI)) || (isAndroid && isLocal) || dead)
        return;
    boolean snap = snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal;
    String part = isAndroid ? "ship" : "mech";
    Shaders.outline.color.set(getColor());
    Shaders.outline.lighten = 0f;
    Shaders.outline.region = Draw.region(part + "-" + mech.name);
    Shaders.outline.apply();
    if (!isAndroid) {
        for (int i : Mathf.signs) {
            Weapon weapon = i < 0 ? weaponLeft : weaponRight;
            tr.trns(angle - 90, 3 * i, 2);
            float w = i > 0 ? -8 : 8;
            if (snap) {
                Draw.rect(weapon.name + "-equip", (int) x + tr.x, (int) y + tr.y, w, 8, angle - 90);
            } else {
                Draw.rect(weapon.name + "-equip", x + tr.x, y + tr.y, w, 8, angle - 90);
            }
        }
    }
    if (snap) {
        Draw.rect(part + "-" + mech.name, (int) x, (int) y, angle - 90);
    } else {
        Draw.rect(part + "-" + mech.name, x, y, angle - 90);
    }
    Graphics.flush();
}
Also used : Weapon(io.anuke.mindustry.resource.Weapon)

Aggregations

Weapon (io.anuke.mindustry.resource.Weapon)2 ItemStack (io.anuke.mindustry.resource.ItemStack)1 Upgrade (io.anuke.mindustry.resource.Upgrade)1 Listenable (io.anuke.ucore.function.Listenable)1 TextureRegionDrawable (io.anuke.ucore.scene.style.TextureRegionDrawable)1 ImageButton (io.anuke.ucore.scene.ui.ImageButton)1 Tooltip (io.anuke.ucore.scene.ui.Tooltip)1 Table (io.anuke.ucore.scene.ui.layout.Table)1