mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-06 07:30:35 +07:00
Fix more bugs, add support for tablets
This commit is contained in:
parent
7ecbd3afd0
commit
ac17a2fcc4
@ -8,16 +8,17 @@ import com.badlogic.gdx.backends.android.AndroidApplication;
|
||||
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import io.anuke.mindustry.io.PlatformFunction;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class AndroidLauncher extends AndroidApplication{
|
||||
boolean doubleScaleTablets = false;
|
||||
boolean doubleScaleTablets = true;
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
@Override
|
||||
@ -51,22 +52,12 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
Mindustry.donationsCallable = new Callable(){ @Override public void run(){ showDonations(); } };
|
||||
|
||||
if(doubleScaleTablets){
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
|
||||
float yInches = metrics.heightPixels / metrics.ydpi;
|
||||
float xInches = metrics.widthPixels / metrics.xdpi;
|
||||
double diagonalInches = Math.sqrt(xInches * xInches + yInches * yInches);
|
||||
if(diagonalInches >= 6.5){
|
||||
// 6.5inch device or bigger
|
||||
if(isTablet(this.getContext())){
|
||||
Unit.dp.multiplier = 2f;
|
||||
}else{
|
||||
// smaller device
|
||||
Unit.dp.multiplier = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
//Mindustry.args.add("-debug");
|
||||
|
||||
config.hideStatusBar = true;
|
||||
|
||||
@ -82,7 +73,13 @@ public class AndroidLauncher extends AndroidApplication{
|
||||
}
|
||||
}
|
||||
|
||||
void showDonations(){
|
||||
private boolean isTablet(Context context) {
|
||||
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
|
||||
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
|
||||
return (xlarge || large);
|
||||
}
|
||||
|
||||
private void showDonations(){
|
||||
Intent intent = new Intent(this, DonationsActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class Vars{
|
||||
public static final boolean testAndroid = false;
|
||||
public static final boolean testAndroid = true;
|
||||
//shorthand for whether or not this is running on android
|
||||
public static final boolean android = (Gdx.app.getType() == ApplicationType.Android) || testAndroid;
|
||||
//shorthand for whether or not this is running on GWT
|
||||
|
@ -529,6 +529,7 @@ public class Control extends Module{
|
||||
Entities.update(bulletGroup);
|
||||
Entities.update(enemyGroup);
|
||||
Entities.update(tileGroup);
|
||||
Entities.update(shieldGroup);
|
||||
|
||||
Entities.collideGroups(enemyGroup, bulletGroup);
|
||||
Entities.collideGroups(Entities.defaultGroup(), bulletGroup);
|
||||
|
@ -16,7 +16,6 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.SpawnPoint;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -132,7 +131,7 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
|
||||
float lastx = camera.position.x, lasty = camera.position.y;
|
||||
|
||||
|
||||
if(Vars.snapCamera && smoothcam && Settings.getBool("pixelate")){
|
||||
camera.position.set((int) camera.position.x, (int) camera.position.y, 0);
|
||||
}
|
||||
@ -547,7 +546,6 @@ public class Renderer extends RendererModule{
|
||||
Draw.dashCircle(spawn.start.worldx(), spawn.start.worldy(), enemyspawnspace);
|
||||
}
|
||||
|
||||
PlaceMode.holdDelete.draw(tilex, tiley, 0, 0);
|
||||
}else if(player.breakMode.delete && control.input.drawPlace()){
|
||||
player.breakMode.draw(control.input.getBlockX(), control.input.getBlockY(),
|
||||
control.input.getBlockEndX(), control.input.getBlockEndY());
|
||||
|
@ -86,7 +86,7 @@ public class Shield extends Entity{
|
||||
|
||||
@Override
|
||||
public Shield add(){
|
||||
return add(Vars.control.shieldGroup);
|
||||
return super.add(Vars.control.shieldGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,20 +6,25 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class AndroidInput extends InputHandler{
|
||||
public float lmousex, lmousey;
|
||||
public float mousex, mousey;
|
||||
public boolean brokeBlock = false;
|
||||
|
||||
private boolean enableHold = false;
|
||||
private boolean placing = false;
|
||||
private float warmup;
|
||||
private float warmupDelay = 20;
|
||||
@ -115,7 +120,7 @@ public class AndroidInput extends InputHandler{
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
if(player.recipe != null && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.inPixels(50))
|
||||
if(enableHold && player.recipe != null && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.inPixels(50))
|
||||
&& !ui.hasMouse()){
|
||||
warmup += Timers.delta();
|
||||
|
||||
@ -148,13 +153,22 @@ public class AndroidInput extends InputHandler{
|
||||
mousey = Mathf.clamp(mousey, 0, Gdx.graphics.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public int touches(){
|
||||
int sum = 0;
|
||||
for(int i = 0; i < 10; i++){
|
||||
if(Gdx.input.isTouched(i))
|
||||
sum++;
|
||||
|
||||
@Override
|
||||
public void tryPlaceBlock(int x, int y, boolean sound){
|
||||
if(player.recipe != null &&
|
||||
validPlace(x, y, player.recipe.result) && cursorNear() &&
|
||||
Vars.control.hasItems(player.recipe.requirements)){
|
||||
|
||||
placeBlock(x, y, player.recipe.result, player.rotation, true, sound);
|
||||
|
||||
for(ItemStack stack : player.recipe.requirements){
|
||||
Vars.control.removeItem(stack);
|
||||
}
|
||||
|
||||
if(!Vars.control.hasItems(player.recipe.requirements)){
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
@ -66,10 +66,12 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
}
|
||||
|
||||
public void tryDeleteBlock(int x, int y, boolean sound){
|
||||
public boolean tryDeleteBlock(int x, int y, boolean sound){
|
||||
if(cursorNear() && validBreak(x, y)){
|
||||
breakBlock(x, y, sound);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean round2(){
|
||||
@ -225,7 +227,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
//Effects.shake(3f, 1f, player);
|
||||
if(sound)Sounds.play("break");
|
||||
if(sound) Sounds.play("break");
|
||||
|
||||
if(!tile.block().isMultiblock() && !tile.isLinked()){
|
||||
tile.setBlock(Blocks.air);
|
||||
|
@ -183,8 +183,9 @@ public enum PlaceMode{
|
||||
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
control.getInput().tryDeleteBlock(cx, cy, first);
|
||||
first = false;
|
||||
if(control.getInput().tryDeleteBlock(cx, cy, first)){
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +135,8 @@ public class HudFragment implements Fragment{
|
||||
new table(){{
|
||||
abottom();
|
||||
aleft();
|
||||
new label("[green]density: " + Gdx.graphics.getDensity()).left();
|
||||
row();
|
||||
new label(()->"[purple]tiles: " + Vars.control.tileGroup.amount()).left();
|
||||
row();
|
||||
new label(()->"[purple]enemies: " + Vars.control.enemyGroup.amount()).left();
|
||||
|
@ -16,19 +16,19 @@ public class Pump extends LiquidBlock{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected float pumpAmount = 2f;
|
||||
protected float pumpTime = 8f;
|
||||
|
||||
public Pump(String name) {
|
||||
super(name);
|
||||
rotate = false;
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
flowfactor = 3f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStats(Array<String> list){
|
||||
super.getStats(list);
|
||||
list.add("[liquidinfo]Pump Speed: " + Strings.toFixed(60f/pumpTime*pumpAmount, 1) + "/s");
|
||||
list.add("[liquidinfo]Pump Speed: " + Strings.toFixed(60f*pumpAmount, 1) + "/s");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,13 +63,13 @@ public class Pump extends LiquidBlock{
|
||||
public void update(Tile tile){
|
||||
LiquidEntity entity = tile.entity();
|
||||
|
||||
if(tile.floor().liquidDrop != null &&
|
||||
entity.timer.get(timerPump, pumpTime) && entity.liquidAmount < liquidCapacity){
|
||||
if(tile.floor().liquidDrop != null){
|
||||
float maxPump = Math.min(liquidCapacity - entity.liquidAmount, pumpAmount);
|
||||
entity.liquid = tile.floor().liquidDrop;
|
||||
entity.liquidAmount += Math.min(pumpAmount, this.liquidCapacity - entity.liquidAmount);
|
||||
entity.liquidAmount += maxPump;
|
||||
}
|
||||
|
||||
if(entity.timer.get(timerDump, pumpTime)){
|
||||
if(entity.timer.get(timerDump, 2)){
|
||||
tryDumpLiquid(tile);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user