diff --git a/build.gradle b/build.gradle index 3094edfff4..ddde814c4a 100644 --- a/build.gradle +++ b/build.gradle @@ -59,7 +59,7 @@ project(":core") { dependencies { - compile fileTree(dir: '../core/lib', include: '*.jar') + // compile fileTree(dir: '../core/lib', include: '*.jar') compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx-ai:1.8.1" } diff --git a/core/assets/sprites/back.png b/core/assets/sprites/back.png index 1280a92827..9a2c29bc0f 100644 Binary files a/core/assets/sprites/back.png and b/core/assets/sprites/back.png differ diff --git a/core/assets/sprites/mindsutry.png b/core/assets/sprites/mindsutry.png deleted file mode 100644 index ff944819a8..0000000000 Binary files a/core/assets/sprites/mindsutry.png and /dev/null differ diff --git a/core/assets/sprites/mindustry.atlas b/core/assets/sprites/mindustry.atlas index 13f07673c3..7d9c3f89c7 100644 --- a/core/assets/sprites/mindustry.atlas +++ b/core/assets/sprites/mindustry.atlas @@ -1,5 +1,5 @@ -mindsutry.png +mindustry.png size: 256,32 format: RGBA8888 filter: Nearest,Nearest @@ -228,6 +228,13 @@ ironwall orig: 8, 8 offset: 0, 0 index: -1 +junction + rotate: false + xy: 178, 13 + size: 8, 8 + orig: 8, 8 + offset: 0, 0 + index: -1 laser rotate: false xy: 95, 7 @@ -251,7 +258,7 @@ machineturret index: -1 mech1 rotate: false - xy: 178, 13 + xy: 188, 13 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -265,7 +272,7 @@ megarepairturret index: -1 player rotate: false - xy: 188, 13 + xy: 198, 13 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -279,7 +286,7 @@ repairturret index: -1 router rotate: false - xy: 198, 13 + xy: 208, 13 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -307,77 +314,77 @@ sniperturret index: -1 steelconveyor rotate: false - xy: 208, 13 + xy: 218, 13 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 steelconveyormove rotate: false - xy: 218, 13 + xy: 228, 13 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 steelwall rotate: false - xy: 228, 13 + xy: 238, 13 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stone rotate: false - xy: 238, 13 + xy: 98, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stone1 rotate: false - xy: 98, 3 + xy: 108, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stone2 rotate: false - xy: 108, 3 + xy: 118, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stone3 rotate: false - xy: 118, 3 + xy: 128, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stoneblock rotate: false - xy: 128, 3 + xy: 138, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stonedrill rotate: false - xy: 138, 3 + xy: 148, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stonedrillhead rotate: false - xy: 138, 3 + xy: 148, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stonewall rotate: false - xy: 148, 3 + xy: 158, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -389,3 +396,17 @@ turret orig: 10, 10 offset: 0, 0 index: -1 +weapon-blaster + rotate: false + xy: 168, 3 + size: 8, 8 + orig: 8, 8 + offset: 0, 0 + index: -1 +weapon-trishot + rotate: false + xy: 178, 3 + size: 8, 8 + orig: 8, 8 + offset: 0, 0 + index: -1 diff --git a/core/assets/sprites/mindustry.png b/core/assets/sprites/mindustry.png new file mode 100644 index 0000000000..37617bc2d9 Binary files /dev/null and b/core/assets/sprites/mindustry.png differ diff --git a/core/assets/ui/uiskin.json b/core/assets/ui/uiskin.json index 44a8adcd37..ea3db6d49a 100644 --- a/core/assets/ui/uiskin.json +++ b/core/assets/ui/uiskin.json @@ -34,6 +34,8 @@ io.anuke.ucore.scene.ui.TextButton$TextButtonStyle: { }, io.anuke.ucore.scene.ui.ImageButton$ImageButtonStyle: { default: {down: button-down, up: button }, + static: {up: button }, + static-down: {up: button-down }, blue: {down: button-blue-down, up: button-blue }, toggle: {checked: button-down, down: button-down, up: button }, togglemap: {checked: button-map-down, down: button-map-down, up: button-map }, diff --git a/core/src/io/anuke/mindustry/GameState.java b/core/src/io/anuke/mindustry/GameState.java index 5894599b0f..f5d1a1e3c6 100644 --- a/core/src/io/anuke/mindustry/GameState.java +++ b/core/src/io/anuke/mindustry/GameState.java @@ -15,6 +15,12 @@ import io.anuke.ucore.util.Timers; public class GameState{ public static void reset(){ + for(Weapon weapon : Weapon.values()){ + weapons.put(weapon, weapon.unlocked); + } + + currentWeapon = Weapon.blaster; + wave = 1; wavetime = waveSpacing(); Entities.clear(); @@ -25,6 +31,7 @@ public class GameState{ spawnpoints.clear(); ui.updateItems(); + ui.updateWeapons(); } public static void play(){ diff --git a/core/src/io/anuke/mindustry/Input.java b/core/src/io/anuke/mindustry/Input.java index f59054cf07..06f23b0f8b 100644 --- a/core/src/io/anuke/mindustry/Input.java +++ b/core/src/io/anuke/mindustry/Input.java @@ -5,6 +5,7 @@ import static io.anuke.mindustry.Vars.*; import com.badlogic.gdx.Input.Buttons; import io.anuke.mindustry.ai.Pathfind; +import io.anuke.mindustry.entities.Weapon; import io.anuke.mindustry.resource.ItemStack; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Blocks; @@ -18,9 +19,32 @@ import io.anuke.ucore.util.Mathf; public class Input{ public static void doInput(){ - //player is dead if(player.health <= 0) return; + + if(Inputs.scrolled()){ + Weapon[] val = Weapon.values(); + int index = 0; + for(int i = 0; i < val.length; i ++) + if(val[i] == currentWeapon){ + index = i; + break; + } + + for(int i = 0; i < val.length; i ++){ + index += Inputs.scroll(); + if(index >= 0 && index < val.length){ + if(weapons.get(val[index])){ + currentWeapon = (val[index]); + break; + } + }else{ + break; + } + } + + ui.updateWeapons(); + } if(Inputs.keyUp("rotate")) rotation++; diff --git a/core/src/io/anuke/mindustry/Inventory.java b/core/src/io/anuke/mindustry/Inventory.java index c009d55a61..e3ba894e3d 100644 --- a/core/src/io/anuke/mindustry/Inventory.java +++ b/core/src/io/anuke/mindustry/Inventory.java @@ -39,4 +39,10 @@ public class Inventory{ items.put(req.item, items.get(req.item, 0)-req.amount); ui.updateItems(); } + + public static void removeItems(ItemStack... reqs){ + for(ItemStack req : reqs) + items.put(req.item, items.get(req.item, 0)-req.amount); + ui.updateItems(); + } } diff --git a/core/src/io/anuke/mindustry/Renderer.java b/core/src/io/anuke/mindustry/Renderer.java index 3a92f71e61..331dbcc36c 100644 --- a/core/src/io/anuke/mindustry/Renderer.java +++ b/core/src/io/anuke/mindustry/Renderer.java @@ -158,6 +158,7 @@ public class Renderer{ float offset = 7; float fraction = Mathf.clamp((float) health / maxhealth); + float w = (len * 2 * fraction); Draw.thickness(3f); Draw.color(Color.GRAY); @@ -166,7 +167,8 @@ public class Renderer{ Draw.color(Color.BLACK); Draw.line(x - len + 1, y - offset, x + len, y - offset); Draw.color(Color.RED); - Draw.line(x - len + 1, y - offset, x - len + (int)(len * 2 * fraction), y - offset); + if(w >= 1) + Draw.line(x - len + 1, y - offset, x - len + w, y - offset); Draw.clear(); } } diff --git a/core/src/io/anuke/mindustry/UI.java b/core/src/io/anuke/mindustry/UI.java index 57fcb6e1e4..7c1f2f5561 100644 --- a/core/src/io/anuke/mindustry/UI.java +++ b/core/src/io/anuke/mindustry/UI.java @@ -7,10 +7,11 @@ import java.util.function.BooleanSupplier; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.utils.Array; +import io.anuke.mindustry.entities.Weapon; import io.anuke.mindustry.resource.*; +import io.anuke.mindustry.ui.*; import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Settings; import io.anuke.ucore.graphics.Hue; @@ -25,12 +26,10 @@ import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.util.Timers; public class UI extends SceneModule{ - Table itemtable; + Table itemtable, weapontable; SettingsDialog prefs; KeybindDialog keys; - Dialog about, menu, restart, tutorial, levels; - //Texture conveyor = new Texture("sprites/conveyor.png"), conveyort = new Texture("sprites/conveyort.png"); - int selectedMap = 0; + Dialog about, menu, restart, tutorial, levels, upgrades; BooleanSupplier play = () -> { return playing; @@ -100,35 +99,16 @@ public class UI extends SceneModule{ @Override public void init(){ - ButtonGroup mapgroup = new ButtonGroup<>(); + //TODO oh my god just move these dialogs to different files - levels = new Dialog("Level Select"); - levels.addCloseButton(); - levels.getButtonTable().addButton("Play", ()->{ - levels.hide(); - World.loadMap(selectedMap); - GameState.play(); - }); + upgrades = new UpgradeDialog(); - for(int i = 0; i < maps.length; i ++){ - levels.content().add(maps[i]); - } - - levels.content().row(); - - for(int i = 0; i < maps.length; i ++){ - int index = i; - ImageButton image = new ImageButton(new TextureRegion(mapTextures[i]), "togglemap"); - mapgroup.add(image); - image.clicked(()->{ - selectedMap = index; - }); - image.getImageCell().size(150, 150); - levels.content().add(image).size(180); - } + levels = new LevelDialog(); prefs = new SettingsDialog(); + menu = new MenuDialog(); + prefs.sliderPref("difficulty", "Difficulty", 1, 0, 2, i -> { return i == 0 ? "Easy" : i == 1 ? "Normal" : "Hard"; }); @@ -143,25 +123,7 @@ public class UI extends SceneModule{ about = new TextDialog("About", aboutText); - tutorial = new TextDialog("Tutorial", tutorialText) - .setDialog(); - - tutorial.hidden(()->{ - playing = true; - paused = false; - }); - - tutorial.getButtonTable().addButton("OK", ()->{ - tutorial.hide(); - }); - - tutorial.content().pad(8); - - tutorial.content().row(); - tutorial.content().addCheck("Don't show again", b->{ - Settings.putBool("tutorial", !b); - Settings.save(); - }).padTop(4); + tutorial = new TutorialDialog(); restart = new Dialog("The core was destroyed.", "dialog"){ public Dialog show(Scene scene){ @@ -179,41 +141,9 @@ public class UI extends SceneModule{ GameState.reset(); }); - menu = new Dialog("Paused", "dialog"); - menu.content().addButton("Back", ()->{ - menu.hide(); - paused = false; - }).width(200); - - menu.content().row(); - menu.content().addButton("Settings", ()->{ - prefs.show(); - }).width(200); - - menu.content().row(); - menu.content().addButton("Controls", ()->{ - keys.show(); - }).width(200); - - menu.content().row(); - menu.content().addButton("Back to menu", ()->{ - new Dialog("Confirm", "dialog"){ - { - text("Are you sure you want to quit?"); - button("Ok", true); - button("Cancel", false); - } - - protected void result(Object object){ - if(object == Boolean.TRUE){ - menu.hide(); - paused = false; - playing = false; - } - } - }.show(scene); - - }).width(200); + weapontable = fill(); + weapontable.bottom(); + weapontable.setVisible(play); build.begin(scene); @@ -319,12 +249,6 @@ public class UI extends SceneModule{ table.add().size(size); } - - if(sec == Section.distribution){ - table.row(); - table.add().size(size); - } - table.setVisible(()->{ return button.isChecked(); }); @@ -337,7 +261,14 @@ public class UI extends SceneModule{ add(stack).colspan(3); get().pad(10f); - }}.right().bottom(); + end(); + }}.right().bottom().uniformX(); + + row(); + + new button("Upgrades", ()->{ + upgrades.show(); + }).uniformX().fillX(); get().setVisible(play); @@ -446,6 +377,46 @@ public class UI extends SceneModule{ build.end(); } + public void updateWeapons(){ + weapontable.clearChildren(); + + for(Weapon weapon : Weapon.values()){ + if(weapons.get(weapon) == Boolean.TRUE){ + ImageButton button = new ImageButton(Draw.region("weapon-"+weapon.name()), "static"); + button.getImageCell().size(40); + button.setDisabled(true); + if(weapon != currentWeapon) + button.setColor(Color.GRAY); + weapontable.add(button).size(48, 52); + + Table tiptable = new Table(); + String description = weapon.description; + + tiptable.background("button"); + tiptable.add("[PURPLE]" + weapon.name(), 0.75f).left().padBottom(2f); + + tiptable.row(); + tiptable.row(); + tiptable.add("[ORANGE]" + description).left(); + tiptable.pad(10f); + + Tooltip tip = new Tooltip(tiptable); + + tip.setInstant(true); + + button.addListener(tip); + } + } + } + + public void showPrefs(){ + prefs.show(); + } + + public void showControls(){ + keys.show(); + } + public void showMenu(){ menu.show(); } diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index 03c0f0b5b3..08ab27053d 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; import io.anuke.mindustry.entities.Player; +import io.anuke.mindustry.entities.Weapon; import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.Recipe; import io.anuke.mindustry.world.Tile; @@ -17,8 +18,8 @@ public class Vars{ public static final float respawntime = 60*4; public static final float wavespace = 20*60; public static final float enemyspawnspace = 65; - public static final float breakduration = 40; - public static boolean debug = false; + public static final float breakduration = 30; + public static boolean debug = true; public static final Vector2 vector = new Vector2(); @@ -28,6 +29,8 @@ public class Vars{ public static UI ui; public static final ObjectMap items = new ObjectMap<>(); + public static final ObjectMap weapons = new ObjectMap(); + public static Weapon currentWeapon; public static Player player; @@ -39,6 +42,7 @@ public class Vars{ public static int worldsize = 128; public static int pixsize = worldsize*tilesize; public static Tile[][] tiles = new Tile[worldsize][worldsize]; + public static Recipe recipe; public static int rotation; diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 80837b4ae0..495486585c 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -16,7 +16,6 @@ public class Player extends DestructibleEntity{ float speed = 1f; float rotation; float reload; - Weapon weapon = Weapon.blaster; public Player(){ hitsize = 5; @@ -74,14 +73,14 @@ public class Player extends DestructibleEntity{ boolean shooting = Inputs.buttonDown(Buttons.LEFT) && recipe == null && !ui.hasMouse(); if(shooting && reload <= 0){ - weapon.shoot(this); + currentWeapon.shoot(this); Sounds.play("shoot"); - reload = weapon.reload; + reload = currentWeapon.reload; } vector.limit(speed); - move(vector.x*delta, vector.y*delta); + move(vector.x*delta, vector.y*delta, 4); if(!shooting){ direction.add(vector.scl(delta)); diff --git a/core/src/io/anuke/mindustry/entities/Weapon.java b/core/src/io/anuke/mindustry/entities/Weapon.java index a330d30168..76a12f2f49 100644 --- a/core/src/io/anuke/mindustry/entities/Weapon.java +++ b/core/src/io/anuke/mindustry/entities/Weapon.java @@ -1,28 +1,54 @@ package io.anuke.mindustry.entities; +import io.anuke.mindustry.resource.Item; +import io.anuke.mindustry.resource.ItemStack; import io.anuke.ucore.entities.Entity; import io.anuke.ucore.util.Angles; public enum Weapon{ - blaster(15, BulletType.shot){ + blaster(15, BulletType.shot, "Shoots a slow, weak bullet."){ { unlocked = true; } + }, + trishot(15, BulletType.shot, "Shoots 3 bullets in a spread.", stack(Item.iron, 40)){ + + @Override + public void shoot(Player p){ + float ang = mouseAngle(p); + float space = 12; + + bullet(p, p.x, p.y, ang); + bullet(p, p.x, p.y, ang+space); + bullet(p, p.x, p.y, ang-space); + } }; public float reload; public BulletType type; public boolean unlocked; + public ItemStack[] requirements; + public String description = "no desc for you"; - private Weapon(float reload, BulletType type){ + private Weapon(float reload, BulletType type, String desc, ItemStack... requirements){ this.reload = reload; this.type = type; + this.requirements = requirements; + this.description = desc; } public void shoot(Player p){ - bullet(p, p.x, p.y); + bullet(p, p.x, p.y, mouseAngle(p)); } - void bullet(Entity owner, float x, float y){ - new Bullet(type, owner, x, y, Angles.mouseAngle(owner.x, owner.y)).add(); + float mouseAngle(Entity owner){ + return Angles.mouseAngle(owner.x, owner.y); + } + + void bullet(Entity owner, float x, float y, float angle){ + new Bullet(type, owner, x, y, angle).add(); + } + + private static ItemStack stack(Item item, int amount){ + return new ItemStack(item, amount); } } diff --git a/core/src/io/anuke/mindustry/resource/Recipe.java b/core/src/io/anuke/mindustry/resource/Recipe.java index 23bc101529..3d58fca099 100644 --- a/core/src/io/anuke/mindustry/resource/Recipe.java +++ b/core/src/io/anuke/mindustry/resource/Recipe.java @@ -16,6 +16,7 @@ public enum Recipe{ conveyor(distribution, ProductionBlocks.conveyor, stack(Item.stone, 1)), fastconveyor(distribution, ProductionBlocks.steelconveyor, stack(Item.steel, 1)), router(distribution, ProductionBlocks.router, stack(Item.stone, 3)), + junction(distribution, ProductionBlocks.junction, stack(Item.iron, 5)), turret(defense, WeaponBlocks.turret, stack(Item.stone, 6)), dturret(defense, WeaponBlocks.doubleturret, stack(Item.stone, 12)), diff --git a/core/src/io/anuke/mindustry/ui/LevelDialog.java b/core/src/io/anuke/mindustry/ui/LevelDialog.java new file mode 100644 index 0000000000..e128bfc7cf --- /dev/null +++ b/core/src/io/anuke/mindustry/ui/LevelDialog.java @@ -0,0 +1,48 @@ +package io.anuke.mindustry.ui; + +import static io.anuke.mindustry.Vars.*; + +import com.badlogic.gdx.graphics.g2d.TextureRegion; + +import io.anuke.mindustry.GameState; +import io.anuke.mindustry.World; +import io.anuke.ucore.scene.ui.ButtonGroup; +import io.anuke.ucore.scene.ui.Dialog; +import io.anuke.ucore.scene.ui.ImageButton; + +public class LevelDialog extends Dialog{ + private int selectedMap; + + public LevelDialog(){ + super("Level Select"); + setup(); + } + + void setup(){ + ButtonGroup mapgroup = new ButtonGroup<>(); + + addCloseButton(); + getButtonTable().addButton("Play", ()->{ + hide(); + World.loadMap(selectedMap); + GameState.play(); + }); + + for(int i = 0; i < maps.length; i ++){ + content().add(maps[i]); + } + + content().row(); + + for(int i = 0; i < maps.length; i ++){ + int index = i; + ImageButton image = new ImageButton(new TextureRegion(mapTextures[i]), "togglemap"); + mapgroup.add(image); + image.clicked(()->{ + selectedMap = index; + }); + image.getImageCell().size(150, 150); + content().add(image).size(180); + } + } +} diff --git a/core/src/io/anuke/mindustry/ui/MenuDialog.java b/core/src/io/anuke/mindustry/ui/MenuDialog.java new file mode 100644 index 0000000000..3775550fc2 --- /dev/null +++ b/core/src/io/anuke/mindustry/ui/MenuDialog.java @@ -0,0 +1,40 @@ +package io.anuke.mindustry.ui; + +import static io.anuke.mindustry.Vars.*; + +import io.anuke.ucore.scene.ui.ConfirmDialog; +import io.anuke.ucore.scene.ui.Dialog; + +public class MenuDialog extends Dialog{ + + public MenuDialog(){ + super("Paused", "dialog"); + setup(); + } + + void setup(){ + content().addButton("Back", ()->{ + hide(); + paused = false; + }).width(200); + + content().row(); + content().addButton("Settings", ()->{ + ui.showPrefs(); + }).width(200); + + content().row(); + content().addButton("Controls", ()->{ + ui.showControls(); + }).width(200); + + content().row(); + content().addButton("Back to menu", ()->{ + new ConfirmDialog("Confirm", "Are you sure you want to quit?", ()->{ + hide(); + paused = false; + playing = false; + }); + }).width(200); + } +} diff --git a/core/src/io/anuke/mindustry/ui/TutorialDialog.java b/core/src/io/anuke/mindustry/ui/TutorialDialog.java new file mode 100644 index 0000000000..9d44eff94c --- /dev/null +++ b/core/src/io/anuke/mindustry/ui/TutorialDialog.java @@ -0,0 +1,35 @@ +package io.anuke.mindustry.ui; + +import static io.anuke.mindustry.Vars.*; + +import io.anuke.ucore.core.Settings; +import io.anuke.ucore.scene.ui.TextDialog; + +public class TutorialDialog extends TextDialog{ + + public TutorialDialog(){ + super("Tutorial", tutorialText); + setup(); + } + + void setup(){ + setDialog(); + + hidden(()->{ + playing = true; + paused = false; + }); + + getButtonTable().addButton("OK", ()->{ + hide(); + }); + + content().pad(8); + + content().row(); + content().addCheck("Don't show again", b->{ + Settings.putBool("tutorial", !b); + Settings.save(); + }).padTop(4); + } +} diff --git a/core/src/io/anuke/mindustry/ui/UpgradeDialog.java b/core/src/io/anuke/mindustry/ui/UpgradeDialog.java new file mode 100644 index 0000000000..4f8a2e51a1 --- /dev/null +++ b/core/src/io/anuke/mindustry/ui/UpgradeDialog.java @@ -0,0 +1,119 @@ +package io.anuke.mindustry.ui; + +import static io.anuke.mindustry.Vars.*; + +import com.badlogic.gdx.graphics.Color; + +import io.anuke.mindustry.Inventory; +import io.anuke.mindustry.entities.Weapon; +import io.anuke.mindustry.resource.ItemStack; +import io.anuke.ucore.core.Draw; +import io.anuke.ucore.scene.event.Touchable; +import io.anuke.ucore.scene.ui.*; +import io.anuke.ucore.scene.ui.layout.Table; + +public class UpgradeDialog extends Dialog{ + + public UpgradeDialog() { + super("Upgrades"); + setup(); + } + + void setup(){ + addCloseButton(); + + hidden(()->{ + paused = false; + }); + shown(()->{ + paused = true; + }); + + getButtonTable().addButton("Ok", ()->{ + hide(); + }); + + Table weptab = new Table(); + weptab.background("button"); + weptab.pad(20); + + for(Weapon weapon : Weapon.values()){ + TextButton button = new TextButton(weapon.name()); + + Image img = new Image(Draw.region("weapon-"+weapon.name())); + button.add(img).size(8*5); + button.getCells().reverse(); + button.row(); + button.pack(); + + button.update(()->{ + + if(weapons.get(weapon) == Boolean.TRUE){ + button.setDisabled(true); + button.setColor(Color.GRAY); + button.setTouchable(Touchable.disabled); + }else{ + button.setColor(Color.WHITE); + button.setDisabled(false); + } + + button.setDisabled(!Inventory.hasItems(weapon.requirements)); + }); + + + weptab.add(button).width(160); + + Table tiptable = new Table(); + + Runnable run = ()->{ + tiptable.clearChildren(); + + String description = weapon.description; + + tiptable.background("button"); + tiptable.add("[PURPLE]" + weapon.name(), 0.75f).left().padBottom(2f); + + if(weapons.get(weapon) != Boolean.TRUE){ + ItemStack[] req = weapon.requirements; + for(ItemStack s : req){ + tiptable.row(); + int amount = Math.min(items.get(s.item, 0), s.amount); + tiptable.add( + (amount >= s.amount ? "[YELLOW]" : "[RED]") + +s.item + ": " + amount + " / " +s.amount, 0.5f).left(); + } + } + + tiptable.row(); + tiptable.add().size(10); + tiptable.row(); + tiptable.add("[ORANGE]" + description).left(); + tiptable.row(); + if(weapons.get(weapon) == Boolean.TRUE) + tiptable.add("[LIME]Purchased!").left(); + tiptable.pad(10f); + }; + + run.run(); + + Tooltip tip = new Tooltip(tiptable, run); + + tip.setInstant(true); + + button.addListener(tip); + + button.clicked(()->{ + Inventory.removeItems(weapon.requirements); + weapons.put(weapon, true); + ui.updateWeapons(); + run.run(); + }); + } + + content().add("Weapons"); + content().row(); + content().add(weptab); + content().row(); + } + +} diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index ee8a09a0f4..f06a26f0e0 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -36,11 +36,11 @@ public class Block{ return null; } - protected void handleItem(Tile tile, Item item, Tile source){ + public void handleItem(Tile tile, Item item, Tile source){ tile.entity.addItem(item, 1); } - public boolean accept(Item item){ + public boolean accept(Item item, Tile dest, Tile source){ return false; } @@ -62,7 +62,7 @@ public class Block{ for(int j = 0; j < 4; j ++){ Tile other = tiles[i]; - if(other != null && other.block().accept(item) + if(other != null && other.block().accept(item, other, tile) //don't output to things facing this thing && !(other.block().rotate && (other.rotation + 2) % 4 == i)){ @@ -98,7 +98,7 @@ public class Block{ if(todump != null && item != todump) continue; - if(tile.entity.hasItem(item) && other != null && other.block().accept(item) && + if(tile.entity.hasItem(item) && other != null && other.block().accept(item, other, tile) && //don't output to things facing this thing !(other.block().rotate && (other.rotation + 2) % 4 == i)){ other.block().handleItem(other, item, tile); @@ -119,7 +119,7 @@ public class Block{ */ protected boolean offloadDir(Tile tile, Item item){ Tile other = tile.getNearby()[tile.rotation]; - if(other != null && other.block().accept(item)){ + if(other != null && other.block().accept(item, other, tile)){ other.block().handleItem(other, item, tile); //other.entity.addCovey(item, ch == 1 ? 0.5f : ch ==2 ? 1f : 0f); return true; diff --git a/core/src/io/anuke/mindustry/world/blocks/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/Conveyor.java index fe8ba32bcc..6cd4704477 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/Conveyor.java @@ -64,7 +64,7 @@ public class Conveyor extends Block{ } @Override - public boolean accept(Item item){ + public boolean accept(Item item, Tile dest, Tile source){ return true; } @@ -74,7 +74,7 @@ public class Conveyor extends Block{ } @Override - protected void handleItem(Tile tile, Item item, Tile source){ + public void handleItem(Tile tile, Item item, Tile source){ int ch = Math.abs(source.relativeTo(tile.x, tile.y) - tile.rotation); int ang = ((source.relativeTo(tile.x, tile.y) - tile.rotation)); diff --git a/core/src/io/anuke/mindustry/world/blocks/Crafter.java b/core/src/io/anuke/mindustry/world/blocks/Crafter.java index 4443feaced..8a5516b75d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Crafter.java +++ b/core/src/io/anuke/mindustry/world/blocks/Crafter.java @@ -40,7 +40,7 @@ public class Crafter extends Block{ } @Override - public boolean accept(Item item){ + public boolean accept(Item item, Tile dest, Tile source){ return item == Item.iron || item == Item.coal; } } diff --git a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java index 36619d0abb..df18e8ac3c 100644 --- a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java @@ -17,12 +17,12 @@ public class ProductionBlocks{ } @Override - protected void handleItem(Tile tile, Item item, Tile source){ + public void handleItem(Tile tile, Item item, Tile source){ Inventory.addItem(item, 1); } @Override - public boolean accept(Item item){ + public boolean accept(Item item, Tile dest, Tile source){ return true; } }, @@ -44,14 +44,14 @@ public class ProductionBlocks{ @Override public void update(Tile tile){ - if(Timers.get(tile, 10) && tile.entity.totalItems() > 0){ + if(Timers.get(tile, 2) && tile.entity.totalItems() > 0){ tryDump(tile, tile.rotation++, null); tile.rotation %= 4; } } @Override - public boolean accept(Item item){ + public boolean accept(Item item, Tile dest, Tile source){ return true; } @@ -61,6 +61,37 @@ public class ProductionBlocks{ } }, + junction = new Block("junction"){ + { + update = true; + solid = true; + } + + @Override + public void handleItem(Tile tile, Item item, Tile source){ + int dir = source.relativeTo(tile.x, tile.y); + dir = (dir+4)%4; + Tile to = tile.getNearby()[dir]; + Timers.run(15, ()->{ + to.block().handleItem(to, item, tile); + }); + + } + + @Override + public boolean accept(Item item, Tile dest, Tile source){ + int dir = source.relativeTo(dest.x, dest.y); + dir = (dir+4)%4; + Tile to = dest.getNearby()[dir]; + return to != null && to.block() != junction && to.block().accept(item, dest, to); + } + + @Override + public String description(){ + return "Serves as a conveyor junction."; + } + }, + smelter = new Crafter("smelter"){{ health = 70; requirements = new Item[]{Item.coal, Item.iron}; diff --git a/core/src/io/anuke/mindustry/world/blocks/Turret.java b/core/src/io/anuke/mindustry/world/blocks/Turret.java index fbd538c513..4f2c3d2120 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/Turret.java @@ -64,7 +64,7 @@ public class Turret extends Block{ } @Override - public boolean accept(Item item){ + public boolean accept(Item item, Tile dest, Tile source){ return item == ammo; } diff --git a/html/src/io/anuke/mindustry/client/HtmlLauncher.java b/html/src/io/anuke/mindustry/client/HtmlLauncher.java index ea532df17f..a162763b88 100644 --- a/html/src/io/anuke/mindustry/client/HtmlLauncher.java +++ b/html/src/io/anuke/mindustry/client/HtmlLauncher.java @@ -3,12 +3,13 @@ package io.anuke.mindustry.client; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.backends.gwt.GwtApplication; import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration; -import io.anuke.mindustry.Mindustry; import com.google.gwt.dom.client.*; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.VerticalPanel; +import io.anuke.mindustry.Mindustry; + public class HtmlLauncher extends GwtApplication { static final int WIDTH = 800; static final int HEIGHT = 600;