Implemented touch/scrollwheel zooming, fixed many Android bugs

This commit is contained in:
Anuken
2017-09-21 22:10:09 -04:00
parent f68de4d69f
commit 41c6f90ca3
14 changed files with 96 additions and 69 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.anuke.mindustry" package="io.anuke.mindustry"
android:versionCode="8" android:versionCode="9"
android:versionName="1.1.4" > android:versionName="1.2" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" /> <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />

View File

@ -79,7 +79,7 @@ project(":core") {
apply plugin: "java" apply plugin: "java"
dependencies { dependencies {
compile 'com.github.anuken:ucore:073aa61a1c' compile 'com.github.anuken:ucore:42a04f8cb4'
compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:1.8.1" compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

View File

@ -25,11 +25,11 @@ import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity; import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.graphics.Atlas; import io.anuke.ucore.graphics.Atlas;
import io.anuke.ucore.modules.ControlModule; import io.anuke.ucore.modules.ControlModule;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
public class Control extends ControlModule{ public class Control extends ControlModule{
public int rangex = 10, rangey = 10; int targetscale = baseCameraScale;
public float targetzoom = 1f;
boolean showedTutorial; boolean showedTutorial;
boolean hiscore = false; boolean hiscore = false;
@ -86,12 +86,13 @@ public class Control extends ControlModule{
Settings.loadAll("io.anuke.moment"); Settings.loadAll("io.anuke.moment");
for(String map : maps) for(String map : maps){
Settings.defaults("hiscore"+map, 0); Settings.defaults("hiscore"+map, 0);
}
player = new Player(); player = new Player();
} }
/*
public void setCameraScale(int scale){ public void setCameraScale(int scale){
Core.cameraScale = scale; Core.cameraScale = scale;
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
@ -99,7 +100,7 @@ public class Control extends ControlModule{
Draw.getSurface("pixel").setScale(Core.cameraScale); Draw.getSurface("pixel").setScale(Core.cameraScale);
Draw.getSurface("shadow").setScale(Core.cameraScale); Draw.getSurface("shadow").setScale(Core.cameraScale);
} }
*/
public void reset(){ public void reset(){
weapons.clear(); weapons.clear();
Renderer.clearTiles(); Renderer.clearTiles();
@ -238,11 +239,6 @@ public class Control extends ControlModule{
return wavespace*out; return wavespace*out;
} }
public void clampZoom(){
targetzoom = Mathf.clamp(targetzoom, 0.5f, 2f);
camera.zoom = Mathf.clamp(camera.zoom, 0.5f, 2f);
}
public boolean isHighScore(){ public boolean isHighScore(){
return hiscore; return hiscore;
} }
@ -267,6 +263,21 @@ public class Control extends ControlModule{
return wave; return wave;
} }
public void setCameraScale(int amount){
targetscale = amount;
clampScale();
Draw.getSurface("pixel").setScale(targetscale);
Draw.getSurface("shadow").setScale(targetscale);
}
public void scaleCamera(int amount){
setCameraScale(targetscale + amount);
}
public void clampScale(){
targetscale = Mathf.clamp(targetscale, Math.round(Unit.dp.inPixels(3)), Math.round(Unit.dp.inPixels((5))));
}
@Override @Override
public void init(){ public void init(){
Musics.shuffleAll(); Musics.shuffleAll();
@ -284,6 +295,15 @@ public class Control extends ControlModule{
public void update(){ public void update(){
if(debug){ if(debug){
if(Inputs.keyUp(Keys.PLUS)){
scaleCamera(1);
}
if(Inputs.keyUp(Keys.MINUS)){
scaleCamera(-1);
}
if(Inputs.keyUp(Keys.SPACE)) if(Inputs.keyUp(Keys.SPACE))
Effects.sound("shoot", World.core.worldx(), World.core.worldy()); Effects.sound("shoot", World.core.worldx(), World.core.worldy());
@ -316,6 +336,22 @@ public class Control extends ControlModule{
} }
} }
if(Core.cameraScale != targetscale){
float targetzoom = (float)Core.cameraScale / targetscale;
camera.zoom = Mathf.lerp(camera.zoom, targetzoom, 0.2f*Timers.delta());
if(Mathf.in(camera.zoom, targetzoom, 0.005f)){
camera.zoom = 1f;
Core.cameraScale = targetscale;
//super.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.viewportWidth = Gdx.graphics.getWidth() / Core.cameraScale;
camera.viewportHeight = Gdx.graphics.getHeight() / Core.cameraScale;
AndroidInput.mousex = Gdx.graphics.getWidth()/2;
AndroidInput.mousey = Gdx.graphics.getHeight()/2;
}
}
if(GameState.is(State.menu)){ if(GameState.is(State.menu)){
clearScreen(); clearScreen();
}else{ }else{
@ -423,9 +459,6 @@ public class Control extends ControlModule{
public void resize(int width, int height){ public void resize(int width, int height){
super.resize(width, height); super.resize(width, height);
rangex = (int) (width / tilesize / Core.cameraScale/2)+2;
rangey = (int) (height / tilesize / Core.cameraScale/2)+2;
AndroidInput.mousex = Gdx.graphics.getWidth()/2; AndroidInput.mousex = Gdx.graphics.getWidth()/2;
AndroidInput.mousey = Gdx.graphics.getHeight()/2; AndroidInput.mousey = Gdx.graphics.getHeight()/2;
camera.position.set(player.x, player.y, 0); camera.position.set(player.x, player.y, 0);

View File

@ -68,7 +68,8 @@ public class Renderer{
Draw.begin(); Draw.begin();
Draw.reset(); Draw.reset();
int rangex = control.rangex, rangey = control.rangey; int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
boolean noshadows = Settings.getBool("noshadows"); boolean noshadows = Settings.getBool("noshadows");

View File

@ -75,7 +75,7 @@ public class UI extends SceneModule{
Draw.color(); Draw.color();
Texture back = Textures.get("background"); Texture back = Textures.get("background");
int backscl = 5; float backscl = 5;
Draw.batch().draw(back, w/2 - back.getWidth()*backscl/2, h/2 - back.getHeight()*backscl/2, Draw.batch().draw(back, w/2 - back.getWidth()*backscl/2, h/2 - back.getHeight()*backscl/2,
back.getWidth()*backscl, back.getHeight()*backscl); back.getWidth()*backscl, back.getHeight()*backscl);
@ -98,14 +98,14 @@ public class UI extends SceneModule{
} }
*/ */
int logoscl = 7; float logoscl = (int)Unit.dp.inPixels(7);
TextureRegion logo = skin.getRegion("logotext"); TextureRegion logo = skin.getRegion("logotext");
int logow = logo.getRegionWidth()*logoscl; float logow = logo.getRegionWidth()*logoscl;
int logoh = logo.getRegionHeight()*logoscl; float logoh = logo.getRegionHeight()*logoscl;
Draw.color(); Draw.color();
//Draw.color(Color.CORAL); //Draw.color(Color.CORAL);
Draw.batch().draw(logo, w/2 - logow/2, h - logoh + 10, logow, logoh); Draw.batch().draw(logo, w/2 - logow/2, h - logoh + 15, logow, logoh);
Draw.color(); Draw.color();
@ -167,7 +167,7 @@ public class UI extends SceneModule{
restart.content().add("[YELLOW]New highscore!").pad(6); restart.content().add("[YELLOW]New highscore!").pad(6);
restart.content().row(); restart.content().row();
} }
restart.content().add("You lasted until wave [GREEN]" + control.getWave() + "[].").pad(6); restart.content().add("You lasted until wave [GREEN]" + control.getWave() + "[].").pad(12).units(Unit.dp).get();
restart.pack(); restart.pack();
}); });
@ -175,10 +175,10 @@ public class UI extends SceneModule{
restart.hide(); restart.hide();
GameState.set(State.menu); GameState.set(State.menu);
control.reset(); control.reset();
}); }).size(200, 50).pad(3).units(Unit.dp);
weapontable = fill(); weapontable = fill();
weapontable.bottom(); weapontable.bottom().left();
weapontable.setVisible(play); weapontable.setVisible(play);
if(android){ if(android){
@ -265,7 +265,7 @@ public class UI extends SceneModule{
} }
//additional padding //additional padding
for(int j = 0; j < maxcol - (int)((float)recipes.size/rows+1); j ++){ for(int j = 0; j < maxcol - (int)((float)recipes.size/rows+2); j ++){
table.row(); table.row();
table.add().size(size); table.add().size(size);
} }
@ -304,16 +304,17 @@ public class UI extends SceneModule{
new table(){{ new table(){{
left(); left();
defaults().size(66).units(Unit.dp).left(); defaults().size(66).units(Unit.dp).left();
float isize = Unit.dp.inPixels(40);
new imagebutton("icon-menu", 40, ()->{ new imagebutton("icon-menu", isize, ()->{
showMenu(); showMenu();
}); });
new imagebutton("icon-settings", 40, ()->{ new imagebutton("icon-settings", isize, ()->{
prefs.show(); prefs.show();
}); });
new imagebutton("icon-pause", 40, ()->{ new imagebutton("icon-pause", isize, ()->{
//TODO pause //TODO pause
}); });
}}.end(); }}.end();
@ -351,30 +352,6 @@ public class UI extends SceneModule{
get().setVisible(play); get().setVisible(play);
}}.end(); }}.end();
//+- table
//TODO refactor to make this less messy?
new table(){{
aleft();
abottom();
int base = baseCameraScale;
int min = base-zoomScale*2;
int max = base+zoomScale;
new button("+", ()->{
if(Core.cameraScale < max){
control.setCameraScale(Core.cameraScale+zoomScale);
}
}).size(Unit.dp.inPixels(40));
new button("-", ()->{
if(Core.cameraScale > min){
control.setCameraScale(Core.cameraScale-zoomScale);
}
}).size(Unit.dp.inPixels(40));
get().setVisible(play);
}}.end();
//menu table //menu table
new table(){{ new table(){{
@ -498,7 +475,7 @@ public class UI extends SceneModule{
desctable.defaults().left(); desctable.defaults().left();
desctable.left(); desctable.left();
desctable.pad(12); desctable.pad(Unit.dp.inPixels(12));
Table header = new Table(); Table header = new Table();
@ -507,10 +484,10 @@ public class UI extends SceneModule{
desctable.row(); desctable.row();
header.addImage(Draw.region(recipe.result.name)).size(8*5).padTop(4); header.addImage(Draw.region(recipe.result.name)).size(8*5).padTop(4).units(Unit.dp);
header.add(recipe.result.formalName).padLeft(4); header.add(recipe.result.formalName).padLeft(4).units(Unit.dp);
desctable.add().pad(2); desctable.add().pad(2).units(Unit.dp);
Table requirements = new Table(); Table requirements = new Table();
@ -521,7 +498,7 @@ public class UI extends SceneModule{
for(ItemStack stack : recipe.requirements){ for(ItemStack stack : recipe.requirements){
ItemStack fs = stack; ItemStack fs = stack;
requirements.addImage(Draw.region("icon-"+stack.item.name())).size(8*3); requirements.addImage(Draw.region("icon-"+stack.item.name())).size(8*3).units(Unit.dp);
Label reqlabel = new Label(""); Label reqlabel = new Label("");
reqlabel.update(()->{ reqlabel.update(()->{
@ -542,7 +519,7 @@ public class UI extends SceneModule{
Label label = new Label("[health]health: " + recipe.result.health + (recipe.result.description() == null ? Label label = new Label("[health]health: " + recipe.result.health + (recipe.result.description() == null ?
"" : ("\n[]" + recipe.result.description()))); "" : ("\n[]" + recipe.result.description())));
label.setWrap(true); label.setWrap(true);
desctable.add(label).width(200).padTop(4).padBottom(2); desctable.add(label).width(200).padTop(4).padBottom(2).units(Unit.dp);
} }

View File

@ -135,6 +135,7 @@ public class Enemy extends DestructibleEntity{
@Override @Override
public void draw(){ public void draw(){
Draw.color();
Draw.rect("mech1", x, y, direction.angle()-90); Draw.rect("mech1", x, y, direction.angle()-90);
} }
} }

View File

@ -10,11 +10,13 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.World; import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.Blocks; import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
import io.anuke.ucore.scene.ui.layout.Unit;
public class GestureHandler extends GestureAdapter{ public class GestureHandler extends GestureAdapter{
Vector2 pinch1 = new Vector2(-1, -1), pinch2 = pinch1.cpy(); Vector2 pinch1 = new Vector2(-1, -1), pinch2 = pinch1.cpy();
Vector2 vector = new Vector2(); Vector2 vector = new Vector2();
float initzoom = -1; float initzoom = -1;
boolean zoomed = false;
@Override @Override
public boolean longPress(float x, float y){ public boolean longPress(float x, float y){
@ -66,15 +68,17 @@ public class GestureHandler extends GestureAdapter{
@Override @Override
public boolean zoom(float initialDistance, float distance){ public boolean zoom(float initialDistance, float distance){
if(initzoom < 0){
if(initzoom <= 0)
initzoom = initialDistance; initzoom = initialDistance;
}
control.targetzoom /= (distance/initzoom); if(Math.abs(distance - initzoom) > Unit.dp.inPixels(100f) && !zoomed){
control.clampZoom(); int amount = (distance > initzoom ? 1 : -1);
control.camera.update(); control.scaleCamera(Math.round(Unit.dp.inPixels(amount)));
initzoom = distance;
initzoom = distance; zoomed = true;
return true;
}
return false; return false;
} }
@ -83,6 +87,7 @@ public class GestureHandler extends GestureAdapter{
public void pinchStop () { public void pinchStop () {
initzoom = -1; initzoom = -1;
pinch2.set(pinch1.set(-1, -1)); pinch2.set(pinch1.set(-1, -1));
zoomed = false;
} }
int touches(){ int touches(){

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import io.anuke.mindustry.Inventory; import io.anuke.mindustry.Inventory;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.resource.ItemStack; import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Weapon; import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@ -14,7 +15,6 @@ import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks; import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
import io.anuke.ucore.scene.utils.Cursors; import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
public class Input{ public class Input{
@ -23,12 +23,16 @@ public class Input{
if(player.health <= 0) return; if(player.health <= 0) return;
if(Inputs.scrolled()){ if(Inputs.scrolled()){
Vars.control.scaleCamera(Inputs.scroll());
//TODO
/*
int index = currentWeapon(); int index = currentWeapon();
index -= Inputs.scroll(); index -= Inputs.scroll();
player.weapon = control.getWeapons().get(Mathf.clamp(index, 0, control.getWeapons().size-1)); player.weapon = control.getWeapons().get(Mathf.clamp(index, 0, control.getWeapons().size-1));
ui.updateWeapons(); ui.updateWeapons();
*/
} }
if(Inputs.keyUp("rotate")) if(Inputs.keyUp("rotate"))

View File

@ -37,7 +37,7 @@ public enum Recipe{
irondrill(production, ProductionBlocks.irondrill, stack(Item.stone, 40)), irondrill(production, ProductionBlocks.irondrill, stack(Item.stone, 40)),
coaldrill(production, ProductionBlocks.coaldrill, stack(Item.stone, 40), stack(Item.iron, 40)), coaldrill(production, ProductionBlocks.coaldrill, stack(Item.stone, 40), stack(Item.iron, 40)),
titaniumdrill(production, ProductionBlocks.titaniumdrill, stack(Item.iron, 40), stack(Item.steel, 40)), titaniumdrill(production, ProductionBlocks.titaniumdrill, stack(Item.iron, 40), stack(Item.steel, 40)),
omnidrill(production, ProductionBlocks.omnidrill, stack(Item.steel, 50), stack(Item.titanium, 50)), omnidrill(production, ProductionBlocks.omnidrill, stack(Item.titanium, 40), stack(Item.dirium, 40)),
smelter(production, ProductionBlocks.smelter, stack(Item.stone, 80), stack(Item.iron, 80)), smelter(production, ProductionBlocks.smelter, stack(Item.stone, 80), stack(Item.iron, 80)),
crucible(production, ProductionBlocks.crucible, stack(Item.titanium, 80), stack(Item.steel, 80)), crucible(production, ProductionBlocks.crucible, stack(Item.titanium, 80), stack(Item.steel, 80)),
coalpurifier(production, ProductionBlocks.coalpurifier, stack(Item.steel, 20), stack(Item.iron, 20)), coalpurifier(production, ProductionBlocks.coalpurifier, stack(Item.steel, 20), stack(Item.iron, 20)),

View File

@ -195,7 +195,7 @@ public class ProductionBlocks{
omnidrill = new Drill("omnidrill"){ omnidrill = new Drill("omnidrill"){
{ {
time = 4; time = 3;
formalName = "omnidrill"; formalName = "omnidrill";
} }

View File

@ -13,6 +13,11 @@ public class Pump extends Conduit{
rotate = false; rotate = false;
} }
@Override
public String description(){
return "Pumps liquids from blocks into conduits.";
}
@Override @Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return false; return false;

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 KiB

View File

@ -18,6 +18,7 @@ public class DesktopLauncher {
config.setMaximized(true); config.setMaximized(true);
//config.useVsync(false); //config.useVsync(false);
config.setWindowedMode(800, 600); config.setWindowedMode(800, 600);
config.setWindowIcon("sprites/icon.png");
SaveIO.setFormatProvider(new FormatProvider(){ SaveIO.setFormatProvider(new FormatProvider(){
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"); SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");