Fixed shaky camera, many other small bugs

This commit is contained in:
Anuken
2018-05-30 23:51:42 -04:00
parent fae7bfa8c5
commit 857b76980b
12 changed files with 81 additions and 36 deletions

View File

@@ -146,19 +146,9 @@ public class Renderer extends RendererModule{
if(state.is(State.menu)){ if(state.is(State.menu)){
Graphics.clear(Color.BLACK); Graphics.clear(Color.BLACK);
}else{ }else{
boolean smoothcam = Settings.getBool("smoothcam");
Vector2 position = averagePosition(); Vector2 position = averagePosition();
if(!smoothcam){ setCamera(position.x, position.y);
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);
}
float prex = camera.position.x, prey = camera.position.y; float prex = camera.position.x, prey = camera.position.y;
updateShake(0.75f); updateShake(0.75f);
@@ -168,7 +158,7 @@ public class Renderer extends RendererModule{
float lastx = camera.position.x, lasty = camera.position.y; 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); 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); Shaders.outline.color.set(team.color);
Graphics.beginShaders(Shaders.outline); 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(unitGroups[team.ordinal()], u -> u.isFlying() == flying);
Entities.draw(playerGroup, p -> p.isFlying() == flying && p.team == team); Entities.draw(playerGroup, p -> p.isFlying() == flying && p.team == team);
Graphics.shader(); Graphics.shader();

View File

@@ -145,7 +145,7 @@ public class Player extends Unit implements BlockBuilder {
public void drawSmooth(){ public void drawSmooth(){
if((debug && (!showPlayer || !showUI)) || dead) return; if((debug && (!showPlayer || !showUI)) || dead) return;
boolean snap = snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate") && isLocal; boolean snap = snapCamera && isLocal;
String mname = mech.name; String mname = mech.name;
@@ -407,6 +407,16 @@ public class Player extends Unit implements BlockBuilder {
rotation = Mathf.slerpDelta(rotation, targetAngle, 0.1f); 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 @Override
public boolean acceptsAmmo(Item item) { public boolean acceptsAmmo(Item item) {
return weapon.getAmmoType(item) != null && inventory.canAcceptAmmo(weapon.getAmmoType(item)); return weapon.getAmmoType(item) != null && inventory.canAcceptAmmo(weapon.getAmmoType(item));

View File

@@ -4,6 +4,8 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectMap.Entry; import com.badlogic.gdx.utils.ObjectMap.Entry;
import com.badlogic.gdx.utils.ObjectSet; 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; import io.anuke.ucore.core.Settings;
public class ContentDatabase { public class ContentDatabase {
@@ -29,9 +31,18 @@ public class ContentDatabase {
unlocked.put(content.getContentTypeName(), new ObjectSet<>()); 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(){ private void load(){
ObjectMap<String, Array<String>> result = Settings.getJson("content-database", ObjectMap.class); ObjectMap<String, Array<String>> result = Settings.getJson("content-database", ObjectMap.class);

View File

@@ -37,4 +37,9 @@ public class EventType {
public interface StateChangeEvent extends Event{ public interface StateChangeEvent extends Event{
void handle(State from, State to); void handle(State from, State to);
} }
public interface UnlockEvent extends Event{
void handle(Content content);
}
} }

View File

@@ -151,7 +151,7 @@ public class OverlayRenderer {
float x = unit.getDrawPosition().x; float x = unit.getDrawPosition().x;
float y = unit.getDrawPosition().y; 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; x = (int)x;
y = (int)y; y = (int)y;
} }

View File

@@ -19,8 +19,6 @@ import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; 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.Core;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Graphics; 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 //only begin selecting if the tapped block is a request
selecting = hasRequest(cursor) && isPlacing(); selecting = hasRequest(cursor) && isPlacing();
Tile linked = cursor.target(); //call tap events
if(pointer == 0 && !selecting){
//when tapping a build block, select it tileTapped(cursor.target());
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);
} }
return false; return false;

View File

@@ -145,7 +145,7 @@ public class DesktopInput extends InputHandler{
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY()); 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; handCursor = true;
} }
@@ -165,7 +165,6 @@ public class DesktopInput extends InputHandler{
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false; if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false;
Tile cursor = tileAt(screenX, screenY); Tile cursor = tileAt(screenX, screenY);
if(cursor == null) return false; if(cursor == null) return false;
if(button == Buttons.LEFT) { //left = begin placing if(button == Buttons.LEFT) { //left = begin placing
@@ -174,7 +173,10 @@ public class DesktopInput extends InputHandler{
selectY = cursor.y; selectY = cursor.y;
mode = placing; mode = placing;
} else { } 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 }else if(button == Buttons.RIGHT){ //right = begin breaking
selectX = cursor.x; selectX = cursor.x;
@@ -190,6 +192,10 @@ public class DesktopInput extends InputHandler{
@Override @Override
public boolean touchUp (int screenX, int screenY, int pointer, int button) { 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; if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false;
Tile cursor = tileAt(screenX, screenY); Tile cursor = tileAt(screenX, screenY);
@@ -199,7 +205,6 @@ public class DesktopInput extends InputHandler{
return false; return false;
} }
if(mode == placing){ //touch up while placing, place everything in selection if(mode == placing){ //touch up while placing, place everything in selection
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength); NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);

View File

@@ -82,10 +82,14 @@ public abstract class InputHandler extends InputAdapter{
} }
/**Handles tile tap events that are not platform specific.*/ /**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 //check if tapped block is configurable
if(tile.block().isConfigurable(tile)){ if(tile.block().isConfigurable(tile)){
consumed = true;
if((!frag.config.isShown() //if the config fragment is hidden, show if((!frag.config.isShown() //if the config fragment is hidden, show
//alternatively, the current selected block can 'agree' to switch config tiles //alternatively, the current selected block can 'agree' to switch config tiles
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile))) { || 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 }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. //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)) { if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile)) {
consumed = true;
frag.config.hideConfig(); frag.config.hideConfig();
} }
} }
//TODO network event! //TODO network event!
//call tapped event //call tapped event
tile.block().tapped(tile, player); if(tile.block().tapped(tile, player)){
consumed = true;
}
return consumed;
} }
//utility methods //utility methods

View File

@@ -102,6 +102,7 @@ public class BlocksFragment implements Fragment{
}}.end(); }}.end();
} }
/**Rebuilds the whole placement menu, attempting to preserve previous state.*/
void rebuild(){ void rebuild(){
selectTable.clear(); selectTable.clear();

View File

@@ -158,7 +158,14 @@ public class Block extends BaseBlock implements Content{
public void load(){} public void load(){}
/**Called when the block is tapped.*/ /**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. /**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.*/ * {@link #isConfigurable(Tile)} able} must return true for this to be called.*/

View File

@@ -34,11 +34,18 @@ public class BuildBlock extends Block {
} }
@Override @Override
public void tapped(Tile tile, Player player) { public boolean tapped(Tile tile, Player player) {
BuildEntity entity = tile.entity(); BuildEntity entity = tile.entity();
player.clearBuilding(); player.clearBuilding();
player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.getRotation(), entity.recipe)); player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.getRotation(), entity.recipe));
return true;
}
@Override
public boolean isCursor(Tile tile) {
return true;
} }
@Override @Override

View File

@@ -40,6 +40,11 @@ public class Door extends Wall{
Draw.rect(name + "-open", tile.drawx(), tile.drawy()); Draw.rect(name + "-open", tile.drawx(), tile.drawy());
} }
} }
@Override
public boolean isCursor(Tile tile){
return true;
}
@Override @Override
public boolean isSolidFor(Tile tile){ public boolean isSolidFor(Tile tile){
@@ -48,11 +53,11 @@ public class Door extends Wall{
} }
@Override @Override
public void tapped(Tile tile, Player player){ public boolean tapped(Tile tile, Player player){
DoorEntity entity = tile.entity(); DoorEntity entity = tile.entity();
if(anyEntities(tile) && entity.open){ if(anyEntities(tile) && entity.open){
return; return true;
} }
entity.open = !entity.open; entity.open = !entity.open;
@@ -61,6 +66,8 @@ public class Door extends Wall{
}else{ }else{
Effects.effect(openfx, tile.drawx(), tile.drawy()); Effects.effect(openfx, tile.drawx(), tile.drawy());
} }
return true;
} }
boolean anyEntities(Tile tile){ boolean anyEntities(Tile tile){