From 857b76980bff1100bc418023cebe58e3fa5f6ba5 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 30 May 2018 23:51:42 -0400 Subject: [PATCH] Fixed shaky camera, many other small bugs --- core/src/io/anuke/mindustry/core/Renderer.java | 16 +++------------- core/src/io/anuke/mindustry/entities/Player.java | 12 +++++++++++- .../io/anuke/mindustry/game/ContentDatabase.java | 13 ++++++++++++- core/src/io/anuke/mindustry/game/EventType.java | 5 +++++ .../mindustry/graphics/OverlayRenderer.java | 2 +- .../io/anuke/mindustry/input/AndroidInput.java | 13 +++---------- .../io/anuke/mindustry/input/DesktopInput.java | 13 +++++++++---- .../io/anuke/mindustry/input/InputHandler.java | 13 +++++++++++-- .../mindustry/ui/fragments/BlocksFragment.java | 1 + core/src/io/anuke/mindustry/world/Block.java | 9 ++++++++- .../mindustry/world/blocks/types/BuildBlock.java | 9 ++++++++- .../world/blocks/types/defense/Door.java | 11 +++++++++-- 12 files changed, 81 insertions(+), 36 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index d6d16587df..2bff710d30 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -146,19 +146,9 @@ public class Renderer extends RendererModule{ if(state.is(State.menu)){ Graphics.clear(Color.BLACK); }else{ - boolean smoothcam = Settings.getBool("smoothcam"); - Vector2 position = averagePosition(); - if(!smoothcam){ - setCamera(position.x, position.y); - }else{ - smoothCamera(position.x, position.y, mobile ? 0.3f : 0.14f); - } - - if(Settings.getBool("pixelate") && players.length == 1) { - limitCamera(4f, position.x, position.y); - } + setCamera(position.x, position.y); float prex = camera.position.x, prey = camera.position.y; updateShake(0.75f); @@ -168,7 +158,7 @@ public class Renderer extends RendererModule{ float lastx = camera.position.x, lasty = camera.position.y; - if(snapCamera && smoothcam && Settings.getBool("pixelate")){ + if(snapCamera){ camera.position.set((int) camera.position.x, (int) camera.position.y, 0); } @@ -259,7 +249,7 @@ public class Renderer extends RendererModule{ Shaders.outline.color.set(team.color); Graphics.beginShaders(Shaders.outline); - Graphics.shader(Shaders.mix, false); + Graphics.shader(Shaders.mix, true); Entities.draw(unitGroups[team.ordinal()], u -> u.isFlying() == flying); Entities.draw(playerGroup, p -> p.isFlying() == flying && p.team == team); Graphics.shader(); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index a4104fffa1..3f15e0e55c 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -145,7 +145,7 @@ public class Player extends Unit implements BlockBuilder { public void drawSmooth(){ if((debug && (!showPlayer || !showUI)) || dead) return; - boolean snap = snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal; + boolean snap = snapCamera && isLocal; String mname = mech.name; @@ -407,6 +407,16 @@ public class Player extends Unit implements BlockBuilder { rotation = Mathf.slerpDelta(rotation, targetAngle, 0.1f); } + @Override + public Player set(float x, float y){ + this.x = x; + this.y = y; + if(mobile && !isLocal){ + Core.camera.position.set(x, y, 0f); + } + return this; + } + @Override public boolean acceptsAmmo(Item item) { return weapon.getAmmoType(item) != null && inventory.canAcceptAmmo(weapon.getAmmoType(item)); diff --git a/core/src/io/anuke/mindustry/game/ContentDatabase.java b/core/src/io/anuke/mindustry/game/ContentDatabase.java index e1f1efa132..567e934719 100644 --- a/core/src/io/anuke/mindustry/game/ContentDatabase.java +++ b/core/src/io/anuke/mindustry/game/ContentDatabase.java @@ -4,6 +4,8 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap.Entry; import com.badlogic.gdx.utils.ObjectSet; +import io.anuke.mindustry.game.EventType.UnlockEvent; +import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Settings; public class ContentDatabase { @@ -29,9 +31,18 @@ public class ContentDatabase { unlocked.put(content.getContentTypeName(), new ObjectSet<>()); } - return unlocked.get(content.getContentTypeName()).add(content.getContentName()); + boolean ret = unlocked.get(content.getContentTypeName()).add(content.getContentName()); + + //fire unlock event so other classes can use it + if(ret){ + Events.fire(UnlockEvent.class, content); + } + + return ret; } + //saving/loading currently disabled for testing. + private void load(){ ObjectMap> result = Settings.getJson("content-database", ObjectMap.class); diff --git a/core/src/io/anuke/mindustry/game/EventType.java b/core/src/io/anuke/mindustry/game/EventType.java index d8f1615b68..812e5eec01 100644 --- a/core/src/io/anuke/mindustry/game/EventType.java +++ b/core/src/io/anuke/mindustry/game/EventType.java @@ -37,4 +37,9 @@ public class EventType { public interface StateChangeEvent extends Event{ void handle(State from, State to); } + + public interface UnlockEvent extends Event{ + void handle(Content content); + } } + diff --git a/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java b/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java index 39ace9e4df..eabea94d02 100644 --- a/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java @@ -151,7 +151,7 @@ public class OverlayRenderer { float x = unit.getDrawPosition().x; float y = unit.getDrawPosition().y; - if(unit == players[0] && players.length == 1 && snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")) { + if(unit == players[0] && players.length == 1 && snapCamera) { x = (int)x; y = (int)y; } diff --git a/core/src/io/anuke/mindustry/input/AndroidInput.java b/core/src/io/anuke/mindustry/input/AndroidInput.java index 3260bfd04f..8a448066c7 100644 --- a/core/src/io/anuke/mindustry/input/AndroidInput.java +++ b/core/src/io/anuke/mindustry/input/AndroidInput.java @@ -19,8 +19,6 @@ import io.anuke.mindustry.input.PlaceUtils.NormalizeResult; import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; -import io.anuke.mindustry.world.blocks.types.BuildBlock; -import io.anuke.mindustry.world.blocks.types.BuildBlock.BuildEntity; import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Graphics; @@ -267,14 +265,9 @@ public class AndroidInput extends InputHandler implements GestureListener{ //only begin selecting if the tapped block is a request selecting = hasRequest(cursor) && isPlacing(); - Tile linked = cursor.target(); - - //when tapping a build block, select it - if(linked.block() instanceof BuildBlock){ - BuildEntity entity = linked.entity(); - player.replaceBuilding(linked.x, linked.y, linked.getRotation(), entity.recipe); - }else if(pointer == 0 && !selecting){ - tileTapped(cursor); + //call tap events + if(pointer == 0 && !selecting){ + tileTapped(cursor.target()); } return false; diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index 325207fd5e..cbf2649b8b 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -145,7 +145,7 @@ public class DesktopInput extends InputHandler{ Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY()); - if(cursor != null && cursor.block().isConfigurable(cursor)){ + if(cursor != null && cursor.target().block().isCursor(cursor.target())){ handCursor = true; } @@ -165,7 +165,6 @@ public class DesktopInput extends InputHandler{ if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false; Tile cursor = tileAt(screenX, screenY); - if(cursor == null) return false; if(button == Buttons.LEFT) { //left = begin placing @@ -174,7 +173,10 @@ public class DesktopInput extends InputHandler{ selectY = cursor.y; mode = placing; } else { - tileTapped(cursor); + //only begin shooting if there's no cursor event + if(!tileTapped(cursor) && player.getPlaceQueue().size == 0){ + shooting = true; + } } }else if(button == Buttons.RIGHT){ //right = begin breaking selectX = cursor.x; @@ -190,6 +192,10 @@ public class DesktopInput extends InputHandler{ @Override public boolean touchUp (int screenX, int screenY, int pointer, int button) { + if(button == Buttons.LEFT){ + shooting = false; + } + if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false; Tile cursor = tileAt(screenX, screenY); @@ -199,7 +205,6 @@ public class DesktopInput extends InputHandler{ return false; } - if(mode == placing){ //touch up while placing, place everything in selection NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength); diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index d9b5bca26c..8176d41bb3 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -82,10 +82,14 @@ public abstract class InputHandler extends InputAdapter{ } /**Handles tile tap events that are not platform specific.*/ - public void tileTapped(Tile tile){ + public boolean tileTapped(Tile tile){ + tile = tile.target(); + + boolean consumed = false; //check if tapped block is configurable if(tile.block().isConfigurable(tile)){ + consumed = true; if((!frag.config.isShown() //if the config fragment is hidden, show //alternatively, the current selected block can 'agree' to switch config tiles || frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile))) { @@ -95,13 +99,18 @@ public abstract class InputHandler extends InputAdapter{ }else if(!frag.config.hasConfigMouse()){ //make sure a configuration fragment isn't on the cursor //then, if it's shown and the current block 'agrees' to hide, hide it. if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile)) { + consumed = true; frag.config.hideConfig(); } } //TODO network event! //call tapped event - tile.block().tapped(tile, player); + if(tile.block().tapped(tile, player)){ + consumed = true; + } + + return consumed; } //utility methods diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java index c2f3d8a60f..c4f5a81e46 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java @@ -102,6 +102,7 @@ public class BlocksFragment implements Fragment{ }}.end(); } + /**Rebuilds the whole placement menu, attempting to preserve previous state.*/ void rebuild(){ selectTable.clear(); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 0a590abbb2..1cd5c761aa 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -158,7 +158,14 @@ public class Block extends BaseBlock implements Content{ public void load(){} /**Called when the block is tapped.*/ - public void tapped(Tile tile, Player player){} + public boolean tapped(Tile tile, Player player){ + return false; + } + + /**Returns whether or not a hand cursor should be shown over this block.*/ + public boolean isCursor(Tile tile){ + return isConfigurable(tile); + } /**Called when this block is tapped to build a UI on the table. * {@link #isConfigurable(Tile)} able} must return true for this to be called.*/ diff --git a/core/src/io/anuke/mindustry/world/blocks/types/BuildBlock.java b/core/src/io/anuke/mindustry/world/blocks/types/BuildBlock.java index 9b93a66849..0e2e7f7ffe 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/BuildBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/BuildBlock.java @@ -34,11 +34,18 @@ public class BuildBlock extends Block { } @Override - public void tapped(Tile tile, Player player) { + public boolean tapped(Tile tile, Player player) { BuildEntity entity = tile.entity(); player.clearBuilding(); player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.getRotation(), entity.recipe)); + + return true; + } + + @Override + public boolean isCursor(Tile tile) { + return true; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java b/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java index d4db70aa9b..e217e6a5bd 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/defense/Door.java @@ -40,6 +40,11 @@ public class Door extends Wall{ Draw.rect(name + "-open", tile.drawx(), tile.drawy()); } } + + @Override + public boolean isCursor(Tile tile){ + return true; + } @Override public boolean isSolidFor(Tile tile){ @@ -48,11 +53,11 @@ public class Door extends Wall{ } @Override - public void tapped(Tile tile, Player player){ + public boolean tapped(Tile tile, Player player){ DoorEntity entity = tile.entity(); if(anyEntities(tile) && entity.open){ - return; + return true; } entity.open = !entity.open; @@ -61,6 +66,8 @@ public class Door extends Wall{ }else{ Effects.effect(openfx, tile.drawx(), tile.drawy()); } + + return true; } boolean anyEntities(Tile tile){