use of io.anuke.mindustry.resource.ItemStack 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.mindustry.resource.ItemStack in project Mindustry by Anuken.
the class Placement method breakBlock.
/**
*Returns block type that was broken, or null if unsuccesful.
*/
public static Block breakBlock(int x, int y, boolean effect, boolean sound) {
Tile tile = world.tile(x, y);
if (tile == null)
return null;
Block block = tile.isLinked() ? tile.getLinked().block() : tile.block();
Recipe result = Recipes.getByResult(block);
if (result != null) {
for (ItemStack stack : result.requirements) {
state.inventory.addItem(stack.item, (int) (stack.amount * breakDropAmount));
}
}
if (tile.block().drops != null) {
state.inventory.addItem(tile.block().drops.item, tile.block().drops.amount);
}
if (sound)
threads.run(() -> Effects.sound("break", x * tilesize, y * tilesize));
if (!tile.block().isMultiblock() && !tile.isLinked()) {
tile.setBlock(Blocks.air);
if (effect)
Effects.effect(Fx.breakBlock, tile.worldx(), tile.worldy());
} else {
Tile target = tile.isLinked() ? tile.getLinked() : tile;
Array<Tile> removals = target.getLinkedTiles();
for (Tile toremove : removals) {
// note that setting a new block automatically unlinks it
toremove.setBlock(Blocks.air);
if (effect)
Effects.effect(Fx.breakBlock, toremove.worldx(), toremove.worldy());
}
}
return block;
}
Aggregations