1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-11 14:56:10 +03:00

Major bugfix, new incomplete placemodes

This commit is contained in:
Anuken 2017-12-15 01:39:54 -05:00
parent 52a996cf77
commit 64439126a3
22 changed files with 728 additions and 535 deletions

View File

@ -30,6 +30,6 @@ After building, the output .JAR file should be in the output JAR file should be
<a href="https://anuke.itch.io/mindustry"><img src="https://i.imgur.com/sk26hTV.png" width="auto" height="75"></a>
<a href="https://anuke.itch.io/mindustry"><img src="https://i.imgur.com/Zbks9.gif" width="auto" height="75"></a>
<a href="https://anuke.itch.io/mindustry"><img src="https://i.imgur.com/dAFMjEJ.gif" width="auto" height="75"></a>
<a href="https://play.google.com/store/apps/details?id=io.anuke.mindustry&hl=en"><img src="https://i.imgur.com/8dF6l81.png" width="auto" height="75"></a>

View File

@ -79,7 +79,7 @@ project(":core") {
apply plugin: "java"
dependencies {
compile 'com.github.Anuken:ucore:a1a3bd9'
compile 'com.github.Anuken:ucore:6eea0a3'
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View File

@ -2,7 +2,6 @@ package io.anuke.mindustry;
import java.util.Date;
import com.badlogic.gdx.graphics.profiling.GLProfiler;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.core.*;
@ -14,7 +13,6 @@ import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.Callable;
import io.anuke.ucore.modules.ModuleCore;
import io.anuke.ucore.util.Profiler;
public class Mindustry extends ModuleCore {
public static Callable donationsCallable;
@ -43,15 +41,11 @@ public class Mindustry extends ModuleCore {
@Override
public void postInit(){
if(Vars.debug && Vars.debugGL){
GLProfiler.enable();
}
Vars.control.reset();
}
@Override
public void render(){
Profiler.begin("total");
try{
super.render();
@ -66,7 +60,5 @@ public class Mindustry extends ModuleCore {
}
Inputs.update();
Profiler.end("total");
}
}

View File

@ -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
@ -34,10 +34,6 @@ public class Vars{
public static final int zoomScale = Math.round(Unit.dp.inPixels(1));
//if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available
public static boolean debug = false;
//whether to debug openGL info
public static boolean debugGL = false;
//whether profiling is shown
public static boolean profile = false;
//whether the player can clip through walls
public static boolean noclip = false;
//whether to draw chunk borders

View File

@ -19,7 +19,7 @@ import io.anuke.mindustry.entities.enemies.BlastEnemy;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.HealerEnemy;
import io.anuke.mindustry.input.AndroidInput;
import io.anuke.mindustry.input.Input;
import io.anuke.mindustry.input.DesktopInput;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
@ -32,7 +32,6 @@ import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.graphics.Atlas;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Profiler;
public class Control extends Module{
int targetscale = baseCameraScale;
@ -65,10 +64,6 @@ public class Control extends Module{
public Control(){
if(Mindustry.args.contains("-debug", false))
Vars.debug = true;
if(Mindustry.args.contains("-profile", false))
Vars.profile = true;
if(Mindustry.args.contains("-debugGL", false))
Vars.debugGL = true;
UCore.log("Total blocks loaded: " + Block.getAllBlocks().size);
@ -83,7 +78,7 @@ public class Control extends Module{
if(android){
input = new AndroidInput();
}else{
input = new Input();
input = new DesktopInput();
}
Inputs.addProcessor(input);
@ -111,7 +106,8 @@ public class Control extends Module{
"pause", Keys.SPACE,
"dash", Keys.SHIFT_LEFT,
"rotate_right", Keys.R,
"rotate_left", Keys.E
"rotate_left", Keys.E,
"area_delete_mode", Keys.Q
);
for(int i = 0; i < Vars.saveSlots; i ++){
@ -165,7 +161,7 @@ public class Control extends Module{
renderer.clearTiles();
player.x = core.worldx();
player.y = core.worldy() - Vars.tilesize*2 - ((int)(Gdx.graphics.getWidth() / (float)Core.cameraScale * 2) % 2 == 0 ? 0.5f : 0);
player.y = core.worldy() - Vars.tilesize*2;
Core.camera.position.set(player.x, player.y, 0);
@ -282,7 +278,7 @@ public class Control extends Module{
int last = Settings.getInt("hiscore" + world.getMap().name());
if(wave > last){
if(wave > last && mode != GameMode.sandbox){
Settings.putInt("hiscore" + world.getMap().name(), wave);
Settings.save();
hiscore = true;
@ -522,10 +518,7 @@ public class Control extends Module{
if(wavetime <= 0){
runWave();
}
Profiler.begin("entityUpdate");
//TODO
Entities.update(Entities.defaultGroup());
Entities.update(bulletGroup);
Entities.update(enemyGroup);
@ -533,8 +526,6 @@ public class Control extends Module{
Entities.collideGroups(enemyGroup, bulletGroup);
Entities.collideGroups(Entities.defaultGroup(), bulletGroup);
Profiler.end("entityUpdate");
}
}
}

View File

@ -1,11 +1,12 @@
package io.anuke.mindustry.core;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.core.Core.camera;
import static io.anuke.ucore.core.Core.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.profiling.GLProfiler;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.FloatArray;
@ -22,16 +23,18 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.types.StaticBlock;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.entities.EffectEntity;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.graphics.CacheBatch;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Surface;
import io.anuke.ucore.modules.RendererModule;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.*;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
public class Renderer extends RendererModule{
private final static int chunksize = 32;
@ -56,6 +59,8 @@ public class Renderer extends RendererModule{
}
}
});
clearColor = Hue.lightness(0.4f);
}
@Override
@ -131,7 +136,7 @@ public class Renderer extends RendererModule{
if(Vars.snapCamera && smoothcam && Settings.getBool("pixelate")){
camera.position.set((int) camera.position.x, (int) camera.position.y, 0);
}
if(Gdx.graphics.getHeight() / Core.cameraScale % 2 == 1){
camera.position.add(0, -0.5f, 0);
}
@ -139,47 +144,82 @@ public class Renderer extends RendererModule{
if(Gdx.graphics.getWidth() / Core.cameraScale % 2 == 1){
camera.position.add(-0.5f, 0, 0);
}
Profiler.begin("draw");
drawDefault();
Profiler.end("draw");
if(Profiler.updating())
Profiler.getTimes().put("draw", Profiler.getTimes().get("draw") - Profiler.getTimes().get("blockDraw") - Profiler.getTimes().get("entityDraw"));
if(Vars.debug && Vars.debugGL && Timers.get("profile", 60)){
UCore.log("shaders: " + GLProfiler.shaderSwitches, "calls: " + GLProfiler.drawCalls, "bindings: " + GLProfiler.textureBindings, "vertices: " + GLProfiler.vertexCount.average);
}
draw();
camera.position.set(lastx - deltax, lasty - deltay, 0);
record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
}
}
FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
void drawTest(){
camera.update();
clearScreen(clearColor);
Core.batch.setProjectionMatrix(camera.combined);
Graphics.surface(pixelSurface, false);
Draw.color(1f, 1f, 1f, Mathf.absin(Timers.time(), 10f, 1f));
Draw.rect("blank", camera.position.x, camera.position.y, camera.viewportWidth, camera.viewportHeight);
Draw.color();
Graphics.surface(shadowSurface);
Draw.color(Color.RED);
Draw.alpha(0.5f);
Draw.rect("blank", camera.position.x, camera.position.y, 100, 100);
Draw.color();
Graphics.flushSurface();
Graphics.flushSurface();
Graphics.end();
}
void drawTest2(){
camera.update();
clearScreen(clearColor);
Core.batch.setProjectionMatrix(camera.combined);
Graphics.surface(pixelSurface, false);
Draw.color(1f, 1f, 1f, 0.3f);
Draw.rect("blank", camera.position.x, camera.position.y, camera.viewportWidth, camera.viewportHeight);
Draw.color();
Graphics.flushSurface();
}
@Override
public void draw(){
camera.update();
clearScreen(clearColor);
batch.setProjectionMatrix(camera.combined);
if(pixelate)
Graphics.surface(pixelSurface, false);
else
batch.begin();
//clears shield surface
Graphics.surface(shieldSurface);
Graphics.surface();
boolean optimize = false;
Profiler.begin("blockDraw");
drawFloor();
drawBlocks(false, optimize);
Profiler.end("blockDraw");
Profiler.begin("entityDraw");
Graphics.shader(Shaders.outline, false);
Entities.draw(control.enemyGroup);
Graphics.shader();
Entities.draw(Entities.defaultGroup());
Profiler.end("entityDraw");
if(!optimize) drawBlocks(true, false);
@ -192,6 +232,12 @@ public class Renderer extends RendererModule{
if(Settings.getBool("indicators") && Vars.showUI){
drawEnemyMarkers();
}
if(pixelate)
Graphics.flushSurface();
batch.end();
}
@Override
@ -476,9 +522,10 @@ public class Renderer extends RendererModule{
int tiley = control.input.getBlockY();
//draw placement box
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android)){
if((player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android)
&& control.input.drawPlace()) || (player.placeMode.delete && Inputs.keyDown("area_delete_mode"))){
player.placeMode.draw(tilex, tiley, control.input.getBlockEndX(), control.input.getBlockEndY()); //TODO proper end points
player.placeMode.draw(tilex, tiley, control.input.getBlockEndX(), control.input.getBlockEndY());
Draw.thickness(1f);
Draw.color(Color.SCARLET);

View File

@ -32,7 +32,6 @@ import io.anuke.ucore.scene.ui.*;
import io.anuke.ucore.scene.ui.Window.WindowStyle;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Profiler;
public class UI extends SceneModule{
Table loadingtable, desctable, configtable;
@ -99,6 +98,12 @@ public class UI extends SceneModule{
Colors.put("healthstats", Color.SCARLET);
Colors.put("interact", Color.ORANGE);
Colors.put("accent", Color.valueOf("f4ba6e"));
Colors.put("place", Color.PURPLE);
Colors.put("placeInvalid", Color.RED);
Colors.put("placeRotate", Color.ORANGE);
Colors.put("break", Color.CORAL);
Colors.put("breakStart", Color.YELLOW);
Colors.put("breakInvalid", Color.RED);
}
protected void loadSkin(){
@ -133,8 +138,6 @@ public class UI extends SceneModule{
public void update(){
if(Vars.debug && !Vars.showUI) return;
Profiler.begin("ui");
if(nplay.visible()){
scene.getBatch().getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
scene.getBatch().begin();
@ -144,9 +147,8 @@ public class UI extends SceneModule{
scene.getBatch().end();
}
super.update();
Profiler.end("ui");
scene.act();
scene.draw();
}
@Override

View File

@ -5,26 +5,21 @@ import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.*;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.effect.Fx;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Profiler;
import io.anuke.ucore.util.Tmp;
public class World extends Module{
@ -43,9 +38,7 @@ public class World extends Module{
@Override
public void update(){
Profiler.begin("pathfind");
pathfind.update();
Profiler.end("pathfind");
}
@Override
@ -190,7 +183,7 @@ public class World extends Module{
Generator.generate(mapPixmaps[map.ordinal()], tiles);
//TODO multiblock core
placeBlock(control.getCore().x, control.getCore().y, ProductionBlocks.core, 0, false);
control.getInput().placeBlock(control.getCore().x, control.getCore().y, ProductionBlocks.core, 0, false);
if(map != Map.tutorial){
setDefaultBlocks();
@ -239,146 +232,6 @@ public class World extends Module{
return seed;
}
//TODO move to control or player?
public void placeBlock(int x, int y, Block result, int rotation, boolean effects){
Tile tile = tile(x, y);
//just in case
if(tile == null)
return;
tile.setBlock(result, rotation);
if(result.isMultiblock()){
int offsetx = -(result.width-1)/2;
int offsety = -(result.height-1)/2;
for(int dx = 0; dx < result.width; dx ++){
for(int dy = 0; dy < result.height; dy ++){
int worldx = dx + offsetx + x;
int worldy = dy + offsety + y;
if(!(worldx == x && worldy == y)){
Tile toplace = tile(worldx, worldy);
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}
if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
}
}
}else{
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
}
//Effects.shake(2f, 2f, player);
if(effects) Sounds.play("place");
}
//TODO move this to control?
public boolean validPlace(int x, int y, Block type){
for(SpawnPoint spawn : control.getSpawnPoints()){
if(Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace){
return false;
}
}
Tmp.r2.setSize(type.width * Vars.tilesize, type.height * Vars.tilesize);
Vector2 offset = type.getPlaceOffset();
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
for(SolidEntity e : Entities.getNearby(control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if(Tmp.r2.overlaps(rect)){
return false;
}
}
if(!Vars.android && Tmp.r2.overlaps(player.hitbox.getRect(player.x, player.y))){
return false;
}
Tile tile = tile(x, y);
if(tile == null) return false;
if(!type.isMultiblock() && Vars.control.getTutorial().active() &&
Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(type != block || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
return false;
}
}else if(Vars.control.getTutorial().active()){
return false;
}
if(type.isMultiblock()){
int offsetx = -(type.width-1)/2;
int offsety = -(type.height-1)/2;
for(int dx = 0; dx < type.width; dx ++){
for(int dy = 0; dy < type.height; dy ++){
Tile other = tile(x + dx + offsetx, y + dy + offsety);
if(other == null || other.block() != Blocks.air){
return false;
}
}
}
return true;
}else{
if(tile.block() != type && type.canReplace(tile.block()) && tile.block().isMultiblock() == type.isMultiblock()){
return true;
}
return tile != null && tile.block() == Blocks.air;
}
}
public void breakBlock(int x, int y){
Tile tile = tile(x, y);
if(tile == null) return;
Block block = tile.isLinked() ? tile.getLinked().block() : tile.block();
Recipe result = null;
for(Recipe recipe : Recipe.values()){
if(recipe.result == block){
result = recipe;
break;
}
}
if(result != null){
for(ItemStack stack : result.requirements){
Vars.control.addItem(stack.item, (int)(stack.amount * Vars.breakDropAmount));
}
}
if(tile.block().drops != null){
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
}
Effects.shake(3f, 1f, player);
Sounds.play("break");
if(!tile.block().isMultiblock() && !tile.isLinked()){
tile.setBlock(Blocks.air);
Effects.effect(Fx.breakBlock, tile.worldx(), tile.worldy());
}else{
Tile target = tile.isLinked() ? tile.getLinked() : tile;
Array<Tile> removals = target.getLinkedTiles();
for(Tile toremove : removals){
//note that setting a new block automatically unlinks it
toremove.setBlock(Blocks.air);
Effects.effect(Fx.breakBlock, toremove.worldx(), toremove.worldy());
}
}
}
public void removeBlock(Tile tile){
if(!tile.block().isMultiblock() && !tile.isLinked()){
tile.setBlock(Blocks.air);
@ -392,34 +245,6 @@ public class World extends Module{
}
}
public boolean validBreak(int x, int y){
Tile tile = tile(x, y);
if(tile == null || tile.block() == ProductionBlocks.core) return false;
if(tile.isLinked() && tile.getLinked().block() == ProductionBlocks.core){
return false;
}
if(Vars.control.getTutorial().active()){
if(Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(block != Blocks.air || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
return false;
}
}else{
return false;
}
}
return tile.breakable();
}
public TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged){
Entity closest = null;
float dst = 0;

View File

@ -26,7 +26,7 @@ public class Player extends DestructibleEntity{
public transient float breaktime = 0;
public transient Recipe recipe;
public transient int rotation;
public transient PlaceMode placeMode = PlaceMode.touch;
public transient PlaceMode placeMode = android ? PlaceMode.cursor : PlaceMode.hold;
public Player(){
hitbox.setSize(5);
@ -86,7 +86,7 @@ public class Player extends DestructibleEntity{
vector.x += speed;
boolean shooting = !Inputs.keyDown("dash") && Inputs.buttonDown(Buttons.LEFT) && recipe == null
&& !ui.hasMouse() && !control.getInput().onConfigurable();
&& !ui.hasMouse() && !control.getInput().onConfigurable() && !Inputs.keyDown("area_delete_mode");
if(shooting && Timers.get(this, "reload", weapon.reload)){
weapon.shoot(this);
@ -108,7 +108,8 @@ public class Player extends DestructibleEntity{
}
if(!shooting){
angle = Mathf.lerpAngDelta(angle, vector.angle(), 0.13f);
if(!vector.isZero())
angle = Mathf.lerpAngDelta(angle, vector.angle(), 0.13f);
}else{
float angle = Angles.mouseAngle(x, y);
this.angle = Mathf.lerpAngDelta(this.angle, angle, 0.1f);

View File

@ -7,7 +7,6 @@ import com.badlogic.gdx.Input.Keys;
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;
@ -20,9 +19,10 @@ import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf;
public class AndroidInput extends InputHandler{
public float lmousex, lmousey;
public float mousex, mousey;
public boolean brokeBlock = false;
private float lmousex, lmousey;
private boolean placing = true;
private float warmup;
private float warmupDelay = 20;
@ -34,11 +34,12 @@ public class AndroidInput extends InputHandler{
@Override public float getCursorEndY(){ return Gdx.input.getY(0); }
@Override public float getCursorX(){ return mousex; }
@Override public float getCursorY(){ return mousey; }
@Override public boolean drawPlace(){ return placing; }
@Override
public boolean keyDown(int keycode){
if(keycode == Keys.E){
place();
}
return false;
}
@ -46,26 +47,43 @@ public class AndroidInput extends InputHandler{
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button){
brokeBlock = false;
if(placing && pointer == 0 && !player.placeMode.pan){
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
placing = false;
}
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button){
if(ui.hasMouse()) return false;
ui.hideTooltip();
if(pointer == 0){
lmousex = screenX;
lmousey = screenY;
lmousex = screenX;
lmousey = screenY;
if(!player.placeMode.pan){
if(pointer == 0){
placing = true;
mousex = screenX;
mousey = screenY;
}else{
placing = false;
}
}
warmup = 0;
if(!GameState.is(State.menu)){
Tile cursor = Vars.world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
if(cursor != null && !Vars.ui.hasMouse()){
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
if(cursor != null && !ui.hasMouse()){
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
if(linked != null && linked.block() instanceof Configurable){
Vars.ui.showConfig(linked);
}else if(!Vars.ui.hasConfigMouse()){
Vars.ui.hideConfig();
ui.showConfig(linked);
}else if(!ui.hasConfigMouse()){
ui.hideConfig();
}
}
}
@ -85,7 +103,7 @@ public class AndroidInput extends InputHandler{
public Tile selected(){
Vector2 vec = Graphics.world(mousex, mousey);
return Vars.world.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize));
return world.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize));
}
public void breakBlock(){
@ -94,23 +112,18 @@ public class AndroidInput extends InputHandler{
if(player.breaktime >= tile.block().breaktime){
brokeBlock = true;
Vars.world.breakBlock(tile.x, tile.y);
breakBlock(tile.x, tile.y);
player.breaktime = 0f;
}
}
public void tryPlaceBlock(int tilex, int tiley){
if(player.recipe != null && control.hasItems(player.recipe.requirements) && validPlace(tilex, tiley, player.recipe.result)){
public void place(){
Vector2 vec = Graphics.world(mousex, mousey);
int tilex = Mathf.scl2(vec.x, tilesize);
int tiley = Mathf.scl2(vec.y, tilesize);
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && Vars.world.validPlace(tilex, tiley, player.recipe.result)){
Vars.world.placeBlock(tilex, tiley, player.recipe.result, player.rotation, true);
placeBlock(tilex, tiley, player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);
control.removeItem(stack);
}
}
}
@ -132,7 +145,7 @@ public class AndroidInput extends InputHandler{
if(sel == null)
return;
if(warmup > warmupDelay && Vars.world.validBreak(sel.x, sel.y)){
if(warmup > warmupDelay && validBreak(sel.x, sel.y)){
player.breaktime += Timers.delta();
if(player.breaktime > selected().block().breaktime){
@ -145,8 +158,6 @@ public class AndroidInput extends InputHandler{
mousey = ly;
}else{
warmup = 0;
//lmousex = Gdx.input.getX(0);
//lmousey = Gdx.input.getY(0);
player.breaktime = 0;
mousex = Mathf.clamp(mousex, 0, Gdx.graphics.getWidth());

View File

@ -7,7 +7,6 @@ import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
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;
@ -20,27 +19,27 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
public class Input extends InputHandler{
float mousex, mousey;
float endx, endy;
public class DesktopInput extends InputHandler{
int mousex, mousey;
int endx, endy;
@Override public float getCursorEndX(){ return endx; }
@Override public float getCursorEndY(){ return endy; }
@Override public float getCursorX(){ return Graphics.screen(mousex, mousey).x; }
@Override public float getCursorY(){ return Gdx.graphics.getHeight() - Graphics.screen(mousex, mousey).y; }
@Override public float getCursorX(){ return (int)(Graphics.screen(mousex, mousey).x + 2); }
@Override public float getCursorY(){ return (int)(Gdx.graphics.getHeight() - 1 - Graphics.screen(mousex, mousey).y); }
@Override
public boolean touchDown (int screenX, int screenY, int pointer, int button){
if(button == Buttons.LEFT){
Vector2 vec = Graphics.world(screenX, screenY);
mousex = vec.x;
mousey = vec.y;
mousex = (int)vec.x;
mousey = (int)vec.y;
}
return false;
}
public boolean touchUp(int screenX, int screenY, int pointer, int button){
player.placeMode.tapped(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
return false;
}
@ -49,15 +48,14 @@ public class Input extends InputHandler{
if(player.isDead()) return;
if(!Inputs.buttonDown(Buttons.LEFT)){
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
mousex = vec.x;
mousey = vec.y;
mousex = (int)Graphics.mouseWorld().x;
mousey = (int)Graphics.mouseWorld().y;
}
endx = Gdx.input.getX();
endy = Gdx.input.getY();
if(Inputs.scrolled() && Inputs.keyDown("zoom_hold") && !GameState.is(State.menu) && !Vars.ui.onDialog()){
Vars.renderer.scaleCamera(Inputs.scroll());
if(Inputs.scrolled() && Inputs.keyDown("zoom_hold") && !GameState.is(State.menu) && !ui.onDialog()){
renderer.scaleCamera(Inputs.scroll());
}
if(Inputs.scrolled()){
@ -72,6 +70,12 @@ public class Input extends InputHandler{
player.rotation ++;
}
if(Inputs.keyDown("area_delete_mode")){
player.placeMode = PlaceMode.areaDelete;
}else{
player.placeMode = PlaceMode.hold;
}
player.rotation = Mathf.mod(player.rotation, 4);
for(int i = 0; i < 9; i ++){
@ -81,19 +85,19 @@ public class Input extends InputHandler{
}
}
Tile cursor = Vars.world.tile(tilex(), tiley());
Tile cursor = world.tile(tilex(), tiley());
if(Inputs.buttonUp(Buttons.LEFT) && cursor != null){
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
if(linked != null && linked.block() instanceof Configurable){
Vars.ui.showConfig(linked);
}else if(!Vars.ui.hasConfigMouse()){
Vars.ui.hideConfig();
ui.showConfig(linked);
}else if(!ui.hasConfigMouse()){
ui.hideConfig();
}
}
if(Inputs.buttonUp(Buttons.RIGHT)){
Vars.ui.hideConfig();
ui.hideConfig();
}
if(player.recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
@ -102,11 +106,11 @@ public class Input extends InputHandler{
}
//block breaking
if(Inputs.buttonDown(Buttons.RIGHT) && cursor != null && Vars.world.validBreak(tilex(), tiley())){
if(Inputs.buttonDown(Buttons.RIGHT) && cursor != null && validBreak(tilex(), tiley())){
Tile tile = cursor;
player.breaktime += Timers.delta();
if(player.breaktime >= tile.getBreakTime()){
Vars.world.breakBlock(cursor.x, cursor.y);
breakBlock(cursor.x, cursor.y);
player.breaktime = 0f;
}
}else{
@ -117,16 +121,16 @@ public class Input extends InputHandler{
public void tryPlaceBlock(int x, int y){
if(player.recipe != null &&
Vars.world.validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
control.hasItems(player.recipe.requirements)){
Vars.world.placeBlock(x, y, player.recipe.result, player.rotation, true);
placeBlock(x, y, player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);
control.removeItem(stack);
}
if(!Vars.control.hasItems(player.recipe.requirements)){
if(!control.hasItems(player.recipe.requirements)){
Cursors.restoreCursor();
}
}

View File

@ -9,7 +9,6 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf;
public class GestureHandler extends GestureAdapter{
AndroidInput input;
@ -29,14 +28,10 @@ public class GestureHandler extends GestureAdapter{
@Override
public boolean tap (float x, float y, int count, int button) {
if(!ui.hasMouse() && player.recipe != null &&
Vars.control.hasItems(player.recipe.requirements) && !Vars.ui.hasMouse() && !input.brokeBlock){
player.placeMode.tapped(Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize), Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize));
if(!player.placeMode.pan){
input.mousex = x;
input.mousey = y;
return true;
player.placeMode.tapped(input.getBlockX(), input.getBlockY());
}
return false;
}

View File

@ -3,15 +3,29 @@ package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.effect.Fx;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.SpawnPoint;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.types.Configurable;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
public abstract class InputHandler extends InputAdapter{
public abstract void update();
@ -24,6 +38,7 @@ public abstract class InputHandler extends InputAdapter{
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, Vars.tilesize, round2()); }
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, Vars.tilesize, round2()); }
public void resetCursor(){}
public boolean drawPlace(){ return true; }
public boolean onConfigurable(){
Tile tile = Vars.world.tile(getBlockX(), getBlockY());
@ -36,10 +51,10 @@ public abstract class InputHandler extends InputAdapter{
public void tryPlaceBlock(int x, int y){
if(player.recipe != null &&
Vars.world.validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
Vars.world.placeBlock(x, y, player.recipe.result, player.rotation, true);
placeBlock(x, y, player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);
@ -51,7 +66,178 @@ public abstract class InputHandler extends InputAdapter{
}
}
public void tryDeleteBlock(int x, int y){
if(cursorNear() && validBreak(x, y)){
breakBlock(x, y);
}
}
public boolean round2(){
return !(player.recipe != null && player.recipe.result.isMultiblock() && player.recipe.result.height % 2 == 0);
}
public boolean validPlace(int x, int y, Block type){
for(SpawnPoint spawn : control.getSpawnPoints()){
if(Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace){
return false;
}
}
Tmp.r2.setSize(type.width * Vars.tilesize, type.height * Vars.tilesize);
Vector2 offset = type.getPlaceOffset();
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
for(SolidEntity e : Entities.getNearby(control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if(Tmp.r2.overlaps(rect)){
return false;
}
}
if(!Vars.android && Tmp.r2.overlaps(player.hitbox.getRect(player.x, player.y))){
return false;
}
Tile tile = world.tile(x, y);
if(tile == null) return false;
if(!type.isMultiblock() && Vars.control.getTutorial().active() &&
Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(type != block || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
return false;
}
}else if(Vars.control.getTutorial().active()){
return false;
}
if(type.isMultiblock()){
int offsetx = -(type.width-1)/2;
int offsety = -(type.height-1)/2;
for(int dx = 0; dx < type.width; dx ++){
for(int dy = 0; dy < type.height; dy ++){
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
if(other == null || other.block() != Blocks.air){
return false;
}
}
}
return true;
}else{
if(tile.block() != type && type.canReplace(tile.block()) && tile.block().isMultiblock() == type.isMultiblock()){
return true;
}
return tile != null && tile.block() == Blocks.air;
}
}
public boolean validBreak(int x, int y){
Tile tile = world.tile(x, y);
if(tile == null || tile.block() == ProductionBlocks.core) return false;
if(tile.isLinked() && tile.getLinked().block() == ProductionBlocks.core){
return false;
}
if(Vars.control.getTutorial().active()){
if(Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(block != Blocks.air || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
return false;
}
}else{
return false;
}
}
return tile.breakable();
}
public void placeBlock(int x, int y, Block result, int rotation, boolean effects){
Tile tile = world.tile(x, y);
//just in case
if(tile == null)
return;
tile.setBlock(result, rotation);
if(result.isMultiblock()){
int offsetx = -(result.width-1)/2;
int offsety = -(result.height-1)/2;
for(int dx = 0; dx < result.width; dx ++){
for(int dy = 0; dy < result.height; dy ++){
int worldx = dx + offsetx + x;
int worldy = dy + offsety + y;
if(!(worldx == x && worldy == y)){
Tile toplace = world.tile(worldx, worldy);
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}
if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
}
}
}else{
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
}
if(effects) Sounds.play("place");
}
public void breakBlock(int x, int y){
Tile tile = world.tile(x, y);
if(tile == null) return;
Block block = tile.isLinked() ? tile.getLinked().block() : tile.block();
Recipe result = null;
for(Recipe recipe : Recipe.values()){
if(recipe.result == block){
result = recipe;
break;
}
}
if(result != null){
for(ItemStack stack : result.requirements){
Vars.control.addItem(stack.item, (int)(stack.amount * Vars.breakDropAmount));
}
}
if(tile.block().drops != null){
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
}
Effects.shake(3f, 1f, player);
Sounds.play("break");
if(!tile.block().isMultiblock() && !tile.isLinked()){
tile.setBlock(Blocks.air);
Effects.effect(Fx.breakBlock, tile.worldx(), tile.worldy());
}else{
Tile target = tile.isLinked() ? tile.getLinked() : tile;
Array<Tile> removals = target.getLinkedTiles();
for(Tile toremove : removals){
//note that setting a new block automatically unlinks it
toremove.setBlock(Blocks.air);
Effects.effect(Fx.breakBlock, toremove.worldx(), toremove.worldy());
}
}
}
}

View File

@ -2,12 +2,15 @@ package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Inputs;
@ -18,25 +21,32 @@ import io.anuke.ucore.util.Tmp;
public enum PlaceMode{
cursor{
{
shown = true;
lockCamera = true;
pan = true;
}
public void draw(int tilex, int tiley, int endx, int endy){
float x = tilex * Vars.tilesize;
float y = tiley * Vars.tilesize;
boolean valid = world.validPlace(tilex, tiley, player.recipe.result) && (android || control.getInput().cursorNear());
boolean valid = control.getInput().validPlace(tilex, tiley, player.recipe.result) && (android || control.getInput().cursorNear());
Vector2 offset = player.recipe.result.getPlaceOffset();
float si = MathUtils.sin(Timers.time() / 6f) + 1;
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
Draw.color(valid ? Color.PURPLE : Color.SCARLET);
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
Draw.thickness(2f);
Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si, tilesize * player.recipe.result.height + si);
Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si,
tilesize * player.recipe.result.height + si);
player.recipe.result.drawPlace(tilex, tiley, player.rotation, valid);
Draw.thickness(2f);
if(player.recipe.result.rotate){
Draw.color(Color.ORANGE);
Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(player.rotation * 90);
Draw.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
}
@ -46,24 +56,42 @@ public enum PlaceMode{
else
Cursors.restoreCursor();
}
},
public void tapped(int tilex, int tiley){
System.out.println("tap " + tilex + " " + tiley);
control.getInput().tryPlaceBlock(tilex, tiley);
}
},
touch{
{
shown = true;
lockCamera = false;
showRotate = true;
showCancel = true;
}
public void tapped(int x, int y){
control.getInput().tryPlaceBlock(x, y);
}
},
areaDelete{
int maxlen = 10;
int tilex;
int tiley;
int endx;
int endy;
int rotation;
{
shown = true;
lockCamera = true;
delete = true;
}
public void draw(int tilex, int tiley, int endx, int endy){
float t = Vars.tilesize;
float t = tilesize;
process(tilex, tiley, endx, endy);
int tx = tilex, ty = tiley, ex = endx, ey = endy;
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
float x = this.tilex * t, y = this.tiley * t,
@ -79,16 +107,124 @@ public enum PlaceMode{
y2 += t/2;
}
Draw.color(Colors.get("break"));
Draw.thick(1f);
for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){
Tile tile = Vars.world.tile(cx, cy);
if(tile != null && tile.getLinked() != null)
tile = tile.getLinked();
if(tile != null && control.getInput().validBreak(tile.x, tile.y)){
Vector2 offset = tile.block().getPlaceOffset();
Draw.linecrect(tile.worldx() + offset.x, tile.worldy() + offset.y,
tile.block().width * t, tile.block().height * t);
}
}
}
Draw.thick(2f);
Draw.color(control.getInput().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
Draw.linerect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
Draw.reset();
}
public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){
control.getInput().tryDeleteBlock(cx, cy);
}
}
}
void process(int tilex, int tiley, int endx, int endy){
if(Math.abs(endx - tilex) > maxlen){
endx = Mathf.sign(endx - tilex) * maxlen + tilex;
}
if(Math.abs(endy - tiley) > maxlen){
endy = Mathf.sign(endy - tiley) * maxlen + tiley;
}
if(endx < tilex){
int t = endx;
endx = tilex;
tilex = t;
}
if(endy < tiley){
int t = endy;
endy = tiley;
tiley = t;
}
this.endx = endx;
this.endy = endy;
this.tilex = tilex;
this.tiley = tiley;
}
},
hold{ //TODO multiblock support!
int maxlen = 10;
int tilex;
int tiley;
int endx;
int endy;
int rotation;
{
lockCamera = true;
shown = true;
showCancel = true;
showRotate = true;
}
public void draw(int tilex, int tiley, int endx, int endy){
if(Vars.android && !Gdx.input.isTouched(0)){
return;
}
float t = Vars.tilesize;
Block block = player.recipe.result;
Vector2 offset = block.getPlaceOffset();
process(tilex, tiley, endx, endy);
int tx = tilex, ty = tiley, ex = endx, ey = endy;
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
float x = this.tilex * t, y = this.tiley * t,
x2 = this.endx * t, y2 = this.endy * t;
if(x2 >= x){
x -= block.width * t/2;
x2 += block.width * t/2;
}
if(y2 >= y){
y -= block.height * t/2;
y2 += block.height * t/2;
}
x += offset.x;
y += offset.y;
x2 += offset.x;
y2 += offset.y;
if(tilex == endx && tiley == endy){
cursor.draw(tilex, tiley, endx, endy);
}else{
Draw.thick(2f);
Draw.color(control.getInput().cursorNear() ? Color.PURPLE : Color.RED);
Draw.color(control.getInput().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
Draw.linerect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
Draw.color(Color.RED);
Draw.color(Colors.get("placeInvalid"));
int amount = 1;
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
@ -96,17 +232,17 @@ public enum PlaceMode{
int px = tx + cx * Mathf.sign(ex - tx),
py = ty + cy * Mathf.sign(ey - ty);
if(!world.validPlace(px, py, player.recipe.result)
if(!control.getInput().validPlace(px, py, player.recipe.result)
|| !control.hasItems(player.recipe.requirements, amount)){
Draw.square(px * t, py * t, t/2);
Draw.linecrect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
}
amount ++;
}
}
if(player.recipe.result.rotate){
float cx = tilex * t, cy = tiley * t;
Draw.color(Color.ORANGE);
float cx = tx * t, cy = ty * t;
Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(rotation * 90);
Draw.line(cx, cy, cx + Tmp.v1.x, cy + Tmp.v1.y);
}
@ -114,11 +250,8 @@ public enum PlaceMode{
}
}
public void tapped(int tilex, int tiley, int endx, int endy){
int prev = player.rotation;
public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
//tilex = this.tilex; tiley = this.tiley;
//endx = this.endx; endy = this.endy;
player.rotation = this.rotation;
@ -129,9 +262,6 @@ public enum PlaceMode{
tiley + y * Mathf.sign(endy - tiley));
}
}
player.rotation = prev;
}
void process(int tilex, int tiley, int endx, int endy){
@ -181,7 +311,7 @@ public enum PlaceMode{
public void draw(int tilex, int tiley, int endx, int endy){
Tile tile = world.tile(tilex, tiley);
if(tile != null && world.validBreak(tilex, tiley)){
if(tile != null && control.getInput().validBreak(tilex, tiley)){
if(tile.isLinked())
tile = tile.getLinked();
Vector2 offset = tile.block().getPlaceOffset();
@ -191,20 +321,29 @@ public enum PlaceMode{
Draw.color(Color.YELLOW, Color.SCARLET, fract);
Draw.linecrect(tile.worldx() + offset.x, tile.worldy() + offset.y, tile.block().width * Vars.tilesize, tile.block().height * Vars.tilesize);
}else if(android && player.breaktime > 0){
Draw.color(Color.YELLOW, Color.SCARLET, fract);
Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f - fract) * 26);
Draw.color(Colors.get("breakStart"), Colors.get("break"), fract);
Draw.polygon(25, tile.worldx() + offset.x, tile.worldy() + offset.y, 4 + (1f - fract) * 26);
}
Draw.reset();
}
}
};
public boolean lockCamera;
public boolean pan = false;
public boolean shown = false;
public boolean showRotate;
public boolean showCancel;
public boolean delete = false;
public void draw(int tilex, int tiley, int endx, int endy){
}
public void tapped(int tilex, int tiley, int endx, int endy){
public void released(int tilex, int tiley, int endx, int endy){
}
public void tapped(int x, int y){
}
}

View File

@ -14,7 +14,6 @@ import io.anuke.mindustry.world.GameMode;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.function.StringSupplier;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.imagebutton;
import io.anuke.ucore.scene.builders.label;
@ -25,7 +24,6 @@ import io.anuke.ucore.scene.ui.Label;
import io.anuke.ucore.scene.ui.layout.Cell;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Profiler;
public class HudFragment implements Fragment{
private Table itemtable, respawntable;
@ -137,26 +135,14 @@ public class HudFragment implements Fragment{
new table(){{
abottom();
aleft();
new label((StringSupplier)()->"[purple]tiles: " + Vars.control.tileGroup.amount()).left();
new label(()->"[purple]tiles: " + Vars.control.tileGroup.amount()).left();
row();
new label((StringSupplier)()->"[purple]enemies: " + Vars.control.enemyGroup.amount()).left();
new label(()->"[purple]enemies: " + Vars.control.enemyGroup.amount()).left();
row();
new label((StringSupplier)()->"[orange]noclip: " + Vars.noclip).left();
new label(()->"[orange]noclip: " + Vars.noclip).left();
row();
new label("[red]DEBUG MODE").scale(0.5f).left();
}}.end();
if(profile){
new table(){{
atop();
new table("button"){{
defaults().left().growX();
atop();
aleft();
new label((StringSupplier)()->Profiler.formatDisplayTimes());
}}.width(400f).units(Unit.dp).end();
}}.end();
}
}
}
@ -188,8 +174,6 @@ public class HudFragment implements Fragment{
}}.left().end();
playButton(uheight);
//get().padTop(Unit.dp.inPixels(1));
//get().padBottom(Unit.dp.inPixels(1));
}}.height(uheight).units(Unit.dp).fillX().expandX().end();
}

View File

@ -8,7 +8,6 @@ import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.ucore.scene.builders.imagebutton;
import io.anuke.ucore.scene.builders.label;
import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.ButtonGroup;
@ -28,8 +27,8 @@ public class PlacementFragment implements Fragment{
new table("pane"){{
get().setTouchable(Touchable.enabled);
new label(()->"Placement Mode: [orange]" + player.placeMode.name()).pad(4).units(Unit.dp);
row();
//new label(()->"Placement Mode: [orange]" + player.placeMode.name()).pad(4).units(Unit.dp);
//row();
aleft();
@ -37,19 +36,28 @@ public class PlacementFragment implements Fragment{
aleft();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
defaults().size(58, 62).pad(6).units(Unit.dp);
defaults().size(52, 56).pad(0).units(Unit.dp);
int d = 0;
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown) continue;
new imagebutton("icon-" + mode.name(), "toggle", Unit.dp.inPixels(10*3), ()->{
control.getInput().resetCursor();
player.placeMode = mode;
}){{
group.add(get());
}};
}}.padBottom(-5.5f).units(Unit.dp);
if(++d % 2 == 0){
row();
}
}
new imagebutton("icon-cancel", Unit.dp.inPixels(14*3), ()->{
player.recipe = null;
}).visible(()->player.recipe != null && player.placeMode == PlaceMode.touch);
}).visible(()->player.recipe != null && player.placeMode.showCancel);
new imagebutton("icon-rotate-arrow", Unit.dp.inPixels(14*3), ()->{
player.rotation ++;
@ -57,7 +65,7 @@ public class PlacementFragment implements Fragment{
}).update(i->{
i.getImage().setOrigin(Align.center);
i.getImage().setRotation(player.rotation*90);
}).visible(()->player.recipe != null && player.placeMode == PlaceMode.touch
}).visible(() -> player.recipe != null && player.placeMode.showRotate
&& player.recipe.result.rotate);
}}.left().end();

View File

@ -27,8 +27,7 @@ public class ToolFragment implements Fragment{
});
tools.addIButton("icon-check", Unit.dp.inPixels(42), ()->{
player.placeMode.tapped(control.getInput().getBlockX(), control.getInput().getBlockY(),
control.getInput().getBlockEndX(), control.getInput().getBlockEndY());
player.placeMode.tapped(control.getInput().getBlockX(), control.getInput().getBlockY());
});
Core.scene.add(tools);

View File

@ -17,7 +17,6 @@ import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
//TODO
public class Sorter extends Junction implements Configurable{
public Sorter(String name) {