diff --git a/core/assets/version.properties b/core/assets/version.properties index 5a97c8a4a9..e928c47511 100644 --- a/core/assets/version.properties +++ b/core/assets/version.properties @@ -1,7 +1,7 @@ #Autogenerated file. Do not modify. -#Thu Apr 12 17:21:29 EDT 2018 +#Fri Apr 13 20:03:26 EDT 2018 version=release -androidBuildCode=915 +androidBuildCode=917 name=Mindustry code=3.5 build=custom build diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index ec1fcb6ecc..1aacdbee56 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -159,7 +159,6 @@ public class Control extends Module{ hiscore = false; ui.hudfrag.updateItems(); - ui.hudfrag.updateWeapons(); ui.hudfrag.fadeRespawn(false); }); diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index 5eea259aca..6423ed307e 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -271,7 +271,6 @@ public class NetClient extends Module { state.inventory.removeItems(UpgradeRecipes.get(weapon)); control.upgrades().addWeapon(weapon); - ui.hudfrag.updateWeapons(); Effects.sound("purchase"); }); } diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 97be7d9bab..a853e80003 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -174,8 +174,7 @@ public class Renderer extends RendererModule{ camera.position.set(lastx - deltax, lasty - deltay, 0); - if(debug && !ui.chatfrag.chatOpen()) - record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't + } } @@ -506,7 +505,7 @@ public class Renderer extends RendererModule{ Draw.reset(); } - if(Inputs.keyDown("block_info") && target.block().fullDescription != null){ + if(Inputs.keyDown("block_info") && target.block().isAccessible()){ Draw.color(Colors.get("accent")); Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize); Draw.color(); diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index b03e954510..dd88a8d796 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -30,7 +30,7 @@ import io.anuke.ucore.util.Mathf; import java.util.Locale; -import static io.anuke.mindustry.Vars.control; +import static io.anuke.mindustry.Vars.*; import static io.anuke.ucore.scene.actions.Actions.*; public class UI extends SceneModule{ @@ -61,6 +61,8 @@ public class UI extends SceneModule{ public final LoadingFragment loadfrag = new LoadingFragment(); public final BlockConfigFragment configfrag = new BlockConfigFragment(); public final DebugFragment debugfrag = new DebugFragment(); + public final BlockInventoryFragment blockinvfrag = new BlockInventoryFragment(); + public final PlayerMenuFragment playermenufrag = new PlayerMenuFragment(); private Locale lastLocale; @@ -132,6 +134,9 @@ public class UI extends SceneModule{ act(); + if(debug && !ui.chatfrag.chatOpen()) + renderer.record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't + if(control.showCursor()) { Draw.color(); @@ -174,6 +179,8 @@ public class UI extends SceneModule{ chatfrag.build(); listfrag.build(); debugfrag.build(); + blockinvfrag.build(); + playermenufrag.build(); loadfrag.build(); build.end(); diff --git a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java index 322bc3ab7c..a7c412794a 100644 --- a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java +++ b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java @@ -1,11 +1,11 @@ package io.anuke.mindustry.editor; -import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.utils.ObjectMap; +import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.io.MapIO; import io.anuke.mindustry.io.MapTileData; @@ -15,7 +15,6 @@ import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.ColorMapper; import io.anuke.mindustry.world.ColorMapper.BlockPair; -import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Graphics; import io.anuke.ucore.core.Inputs; @@ -29,6 +28,7 @@ import io.anuke.ucore.scene.ui.*; import io.anuke.ucore.scene.ui.layout.Stack; import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.util.Bundles; +import io.anuke.ucore.util.Input; import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Strings; @@ -395,20 +395,20 @@ public class MapEditorDialog extends Dialog{ } //ctrl keys (undo, redo, save) - if(Inputs.keyDown(Keys.CONTROL_LEFT)){ - if(Inputs.keyTap(Keys.Z)){ + if(Inputs.keyDown(Input.CONTROL_LEFT)){ + if(Inputs.keyTap(Input.Z)){ view.undo(); } - if(Inputs.keyTap(Keys.Y)){ + if(Inputs.keyTap(Input.Y)){ view.redo(); } - if(Inputs.keyTap(Keys.S)){ + if(Inputs.keyTap(Input.S)){ saveDialog.save(); } - if(Inputs.keyTap(Keys.G)){ + if(Inputs.keyTap(Input.G)){ view.setGrid(!view.isGrid()); } } diff --git a/core/src/io/anuke/mindustry/editor/MapView.java b/core/src/io/anuke/mindustry/editor/MapView.java index a23bf2115c..59635ce320 100644 --- a/core/src/io/anuke/mindustry/editor/MapView.java +++ b/core/src/io/anuke/mindustry/editor/MapView.java @@ -1,6 +1,5 @@ package io.anuke.mindustry.editor; -import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Colors; import com.badlogic.gdx.graphics.g2d.Batch; @@ -25,6 +24,7 @@ import io.anuke.ucore.scene.event.InputListener; import io.anuke.ucore.scene.event.Touchable; import io.anuke.ucore.scene.ui.TextField; import io.anuke.ucore.scene.ui.layout.Unit; +import io.anuke.ucore.util.Input; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Tmp; @@ -156,7 +156,7 @@ public class MapView extends Element implements GestureListener{ super.act(delta); if(Core.scene.getKeyboardFocus() == null || !(Core.scene.getKeyboardFocus() instanceof TextField) && - !Inputs.keyDown(Keys.CONTROL_LEFT)) { + !Inputs.keyDown(Input.CONTROL_LEFT)) { float ax = Inputs.getAxis("move_x"); float ay = Inputs.getAxis("move_y"); offsetx -= ax * 15f / zoom; diff --git a/core/src/io/anuke/mindustry/entities/UnitInventory.java b/core/src/io/anuke/mindustry/entities/UnitInventory.java index d1690cba9a..f4c8fa5bba 100644 --- a/core/src/io/anuke/mindustry/entities/UnitInventory.java +++ b/core/src/io/anuke/mindustry/entities/UnitInventory.java @@ -7,4 +7,10 @@ public class UnitInventory { public final ItemStack item = new ItemStack(Item.getByID(0), 0); public final LiquidStack liquid = new LiquidStack(Liquid.getByID(0), 0); public float power = 0f; + + public void addItem(Item item, int amount){ + if(this.item.item != item) this.item.amount = 0; + this.item.item = item; + this.item.amount += amount; + } } diff --git a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java index 1f6870bfb7..4d5402a1ab 100644 --- a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java +++ b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java @@ -29,6 +29,7 @@ public class DefaultKeybinds { "chat_history_prev", Input.UP, "chat_history_next", Input.DOWN, "chat_scroll", new Axis(Input.SCROLL), + "item_withdraw", Input.SHIFT_LEFT, "console", Input.GRAVE, "weapon_1", Input.NUM_1, "weapon_2", Input.NUM_2, diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index 674a71f542..01eb101aba 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -91,7 +91,6 @@ public class DesktopInput extends InputHandler{ if(Inputs.keyTap("weapon_" + i)){ player.weaponLeft = player.weaponRight = control.upgrades().getWeapons().get(i - 1); if(Net.active()) NetEvents.handleWeaponSwitch(); - ui.hudfrag.updateWeapons(); } } @@ -99,15 +98,18 @@ public class DesktopInput extends InputHandler{ Tile target = cursor == null ? null : cursor.target(); boolean showCursor = false; - if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info") - && target.block().fullDescription != null){ + if(recipe == null && target != null && !ui.hasMouse() && Inputs.keyDown("block_info") && target.block().isAccessible()){ showCursor = true; if(Inputs.keyTap("select")){ - ui.hudfrag.blockfrag.showBlockInfo(target.block()); + ui.blockinvfrag.showFor(target); Cursors.restoreCursor(); } } + if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap("select")){ + ui.blockinvfrag.hide(); + } + if(target != null && target.block().isConfigurable(target)){ showCursor = true; } diff --git a/core/src/io/anuke/mindustry/io/versions/Save16.java b/core/src/io/anuke/mindustry/io/versions/Save16.java index b9bc62be41..9406d2dcdc 100644 --- a/core/src/io/anuke/mindustry/io/versions/Save16.java +++ b/core/src/io/anuke/mindustry/io/versions/Save16.java @@ -90,7 +90,6 @@ public class Save16 extends SaveFileVersion { control.upgrades().addWeapon(Upgrade.getByID(stream.readByte())); } - ui.hudfrag.updateWeapons(); }else{ byte b = stream.readByte(); for(int i = 0; i < b; i ++) stream.readByte(); diff --git a/core/src/io/anuke/mindustry/net/NetworkIO.java b/core/src/io/anuke/mindustry/net/NetworkIO.java index 757265cb16..079d0f2284 100644 --- a/core/src/io/anuke/mindustry/net/NetworkIO.java +++ b/core/src/io/anuke/mindustry/net/NetworkIO.java @@ -137,7 +137,6 @@ public class NetworkIO { } player.weaponLeft = player.weaponRight = control.upgrades().getWeapons().peek(); - ui.hudfrag.updateWeapons(); Entities.clear(); player.id = pid; diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java new file mode 100644 index 0000000000..325af9de30 --- /dev/null +++ b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java @@ -0,0 +1,190 @@ +package io.anuke.mindustry.ui.fragments; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Colors; +import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.Align; +import com.badlogic.gdx.utils.IntSet; +import io.anuke.mindustry.content.Liquids; +import io.anuke.mindustry.resource.Item; +import io.anuke.mindustry.world.Tile; +import io.anuke.ucore.core.Core; +import io.anuke.ucore.core.Graphics; +import io.anuke.ucore.core.Inputs; +import io.anuke.ucore.scene.actions.Actions; +import io.anuke.ucore.scene.event.HandCursorListener; +import io.anuke.ucore.scene.event.Touchable; +import io.anuke.ucore.scene.ui.Image; +import io.anuke.ucore.scene.ui.layout.Stack; +import io.anuke.ucore.scene.ui.layout.Table; +import io.anuke.ucore.util.Strings; + +import static io.anuke.mindustry.Vars.player; +import static io.anuke.mindustry.Vars.tilesize; + +public class BlockInventoryFragment implements Fragment { + private Table table; + private Tile tile; + + @Override + public void build() { + table = new Table(); + } + + public void showFor(Tile t){ + this.tile = t.target(); + if(tile == null || tile.entity == null || !tile.block().isAccessible()) return; + rebuild(); + } + + public void hide(){ + table.clear(); + table.remove(); + table.setTouchable(Touchable.disabled); + table.update(() -> {}); + tile = null; + } + + private void rebuild(){ + IntSet container = new IntSet(); + + table.clear(); + if(table.getParent() == null) Core.scene.add(table); + table.background("clear"); + table.setTouchable(Touchable.enabled); + table.update(() -> { + if(tile == null || tile.entity == null || !tile.block().isAccessible()){ + hide(); + }else { + updateTablePosition(); + if(tile.block().hasInventory) { + int[] items = tile.entity.inventory.items; + for (int i = 0; i < items.length; i++) { + if ((items[i] == 0) == container.contains(i)) { + rebuild(); + } + } + } + } + }); + + int cols = 3; + int row = 0; + + //table.label(() -> "[accent]"+tile.entity.inventory.totalItems() +"/"+ tile.block().itemCapacity).colspan(cols); + //table.row(); + table.margin(3f); + + if(tile.block().hasPower){ + Table t = new Table(); + t.left().bottom(); + t.label(() -> round(tile.entity.power.amount)).color(Color.DARK_GRAY); + t.row(); + t.label(() -> round(tile.entity.power.amount)).padTop(-22); + + Image image = new Image("icon-power"); + image.setColor(Colors.get("power")); + + Stack stack = new Stack(); + stack.add(image); + stack.add(t); + table.add(stack).size(16 * 2).space(6f); + + if (row++ % cols == cols - 1) table.row(); + } + + if(tile.block().hasLiquids){ + Table t = new Table(); + t.left().bottom(); + t.label(() -> round(tile.entity.liquid.amount)).color(Color.DARK_GRAY); + t.row(); + t.label(() -> round(tile.entity.liquid.amount)).padTop(-22); + + Image image = new Image("icon-liquid"); + image.setColor(tile.entity.liquid.liquid == Liquids.none ? Color.GRAY : tile.entity.liquid.liquid.color); + + Stack stack = new Stack(); + stack.add(image); + stack.add(t); + table.add(stack).size(16 * 2).space(6f); + + if (row++ % cols == cols - 1) table.row(); + } + + if(tile.block().hasInventory) { + int[] items = tile.entity.inventory.items; + + for (int i = 0; i < items.length; i++) { + final int f = i; + if (items[i] == 0) continue; + Item item = Item.getByID(i); + + container.add(i); + + Table t = new Table(); + t.left().bottom(); + + t.label(() -> round(items[f])).color(Color.DARK_GRAY); + t.row(); + t.label(() -> round(items[f])).padTop(-22); + + Stack stack = new Stack(); + stack.add(new Image(item.region)); + stack.add(t); + table.add(stack).size(16 * 2).space(6f); + stack.addListener(new HandCursorListener()); + stack.tapped(() -> { + if (items[f] > 0) { + int amount = Inputs.keyDown("item_withdraw") ? items[f] : 1; + items[f] -= amount; + Vector2 v = stack.localToStageCoordinates(new Vector2(stack.getWidth() / 2f, stack.getHeight() / 2f)); + Vector2 tv = Graphics.screen(player.x, player.y); + float tx = tv.x, ty = tv.y; + float dur = 40f / 60f; + + Image image = new Image(item.region); + image.setSize(32f, 32f); + image.setOrigin(Align.center); + image.setPosition(v.x, v.y, Align.center); + image.setTouchable(Touchable.disabled); + image.actions( + Actions.parallel( + Actions.moveToAligned(tx, ty, Align.center, dur, Interpolation.fade), + Actions.scaleTo(0.1f, 0.1f, dur, Interpolation.fade) + ), + Actions.call(() -> player.inventory.addItem(item, amount)), + Actions.removeActor() + ); + + Core.scene.add(image); + } + }); + + if (row++ % cols == cols - 1) table.row(); + } + } + + if(row == 0){ + table.add("[LIGHT_GRAY]"); + } + + updateTablePosition(); + } + + String round(float f){ + f = (int)f; + if(f >= 1000){ + return Strings.toFixed(f/1000, 1) + "k"; + }else{ + return (int)f+""; + } + } + + private void updateTablePosition(){ + Vector2 v = Graphics.screen(tile.drawx() + tile.block().size*tilesize/2f, tile.drawy() + tile.block().size*tilesize/2f); + table.pack(); + table.setPosition(v.x, v.y, Align.topLeft); + } + +} diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java index 9f7f316764..23182a040d 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java @@ -30,7 +30,7 @@ import io.anuke.ucore.util.Strings; import static io.anuke.mindustry.Vars.*; public class BlocksFragment implements Fragment{ - private Table desctable, itemtable, blocks, weapons; + private Table desctable, itemtable, blocks; private Stack stack = new Stack(); private boolean shown = true; private Recipe hoveredDescriptionRecipe; @@ -195,41 +195,10 @@ public class BlocksFragment implements Fragment{ end(); }}.right().bottom().uniformX(); - row(); - - if(!android) { - weapons = new table("button").margin(0).fillX().end().get(); - } - visible(() -> !state.is(State.menu) && shown); }}.end().get(); }}.end(); - - updateWeapons(); - } - - public void updateWeapons(){ - if(android) return; - - weapons.clearChildren(); - weapons.left(); - - ButtonGroup group = new ButtonGroup<>(); - - for(int i = 0; i < control.upgrades().getWeapons().size; i ++){ - Weapon weapon = control.upgrades().getWeapons().get(i); - weapons.addImageButton(weapon.name, "toggle", 8*3, () -> { - player.weaponLeft = player.weaponRight = weapon; - }).left().size(40f, 45f).padRight(-1).group(group); - } - - int idx = control.upgrades().getWeapons().indexOf(player.weaponLeft, true); - - if(idx != -1) - group.getButtons().get(idx).setChecked(true); - else if(group.getButtons().size > 0) - group.getButtons().get(0).setChecked(true); } public void toggle(boolean show, float t, Interpolation ip){ diff --git a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java index dd73be6517..1de8fa9a23 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java @@ -225,10 +225,6 @@ public class HudFragment implements Fragment{ public void updateItems(){ blockfrag.updateItems(); } - - public void updateWeapons(){ - blockfrag.updateWeapons(); - } public void fadeRespawn(boolean in){ respawntable.addAction(Actions.color(in ? new Color(0, 0, 0, 0.3f) : Color.CLEAR, 0.3f)); diff --git a/core/src/io/anuke/mindustry/ui/fragments/PlayerMenuFragment.java b/core/src/io/anuke/mindustry/ui/fragments/PlayerMenuFragment.java new file mode 100644 index 0000000000..80ba6f1d4b --- /dev/null +++ b/core/src/io/anuke/mindustry/ui/fragments/PlayerMenuFragment.java @@ -0,0 +1,9 @@ +package io.anuke.mindustry.ui.fragments; + +public class PlayerMenuFragment implements Fragment { + + @Override + public void build() { + + } +} diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 04d02e146f..4d3e9c1758 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -192,6 +192,10 @@ public class Block extends BaseBlock { } public void update(Tile tile){} + + public boolean isAccessible(){ + return (hasInventory && itemCapacity > 0) || hasLiquids || hasPower; + } public void onDestroyed(Tile tile){ float x = tile.worldx(), y = tile.worldy(); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java b/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java index 29b6d3e6e9..734cbc664b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/production/WeaponFactory.java @@ -114,7 +114,6 @@ public class WeaponFactory extends Block{ }else{ state.inventory.removeItems(requirements); control.upgrades().addWeapon(weapon); - ui.hudfrag.updateWeapons(); run.listen(); Effects.sound("purchase"); }