Major refactoring of building, sound, inventory
This commit is contained in:
@@ -7,7 +7,6 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
@@ -98,28 +97,12 @@ public class AndroidInput extends InputHandler{
|
||||
mousex = Gdx.graphics.getWidth()/2;
|
||||
mousey = Gdx.graphics.getHeight()/2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cursorNear(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public Tile selected(){
|
||||
Vector2 vec = Graphics.world(mousex, mousey);
|
||||
return world.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize));
|
||||
}
|
||||
|
||||
public void breakBlock(){
|
||||
Tile tile = selected();
|
||||
breaktime += Timers.delta();
|
||||
|
||||
if(breaktime >= tile.block().breaktime){
|
||||
brokeBlock = true;
|
||||
breakBlock(tile.x, tile.y, true);
|
||||
breaktime = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
enableHold = breakMode == PlaceMode.holdDelete;
|
||||
@@ -150,15 +133,6 @@ public class AndroidInput extends InputHandler{
|
||||
if(sel == null)
|
||||
return;
|
||||
|
||||
if(warmup > warmupDelay && validBreak(sel.x, sel.y)){
|
||||
breaktime += Timers.delta();
|
||||
|
||||
if(breaktime > selected().block().breaktime){
|
||||
breakBlock();
|
||||
breaktime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
mousex = lx;
|
||||
mousey = ly;
|
||||
}else{
|
||||
@@ -169,23 +143,6 @@ public class AndroidInput extends InputHandler{
|
||||
mousey = Mathf.clamp(mousey, 0, Gdx.graphics.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryPlaceBlock(int x, int y, boolean sound){
|
||||
if(recipe != null &&
|
||||
validPlace(x, y, recipe.result) && cursorNear() &&
|
||||
state.inventory.hasItems(recipe.requirements)){
|
||||
|
||||
placeBlock(x, y, recipe, rotation, true, sound);
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
state.inventory.removeItem(stack);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean breaking(){
|
||||
return recipe == null;
|
||||
|
||||
@@ -21,7 +21,6 @@ public class DesktopInput extends InputHandler{
|
||||
float mousex, mousey;
|
||||
float endx, endy;
|
||||
private float controlx, controly;
|
||||
private boolean enableHold = false;
|
||||
private boolean beganBreak;
|
||||
private boolean controlling;
|
||||
private final int index;
|
||||
@@ -178,17 +177,6 @@ public class DesktopInput extends InputHandler{
|
||||
recipe = null;
|
||||
}
|
||||
|
||||
//block breaking
|
||||
if(enableHold && Inputs.keyDown(section,"break") && cursor != null && validBreak(tilex(), tiley())){
|
||||
breaktime += Timers.delta();
|
||||
if(breaktime >= cursor.getBreakTime()){
|
||||
breakBlock(cursor.x, cursor.y, true);
|
||||
breaktime = 0f;
|
||||
}
|
||||
}else{
|
||||
breaktime = 0f;
|
||||
}
|
||||
|
||||
if(recipe != null){
|
||||
showCursor = validPlace(tilex(), tiley(), recipe.result) && cursorNear();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GestureHandler extends GestureAdapter{
|
||||
if(input.isCursorVisible() && !Inputs.keyDown("select")) return false;
|
||||
|
||||
if(!input.isCursorVisible() && !(input.recipe != null
|
||||
&& input.placeMode.lockCamera && state.inventory.hasItems(input.recipe.requirements)) &&
|
||||
&& input.placeMode.lockCamera) &&
|
||||
!(input.recipe == null && input.breakMode.lockCamera)){
|
||||
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
input.player.x -= dx;
|
||||
|
||||
@@ -4,16 +4,14 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputAdapter;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.entities.BlockPlacer.PlaceRequest;
|
||||
import io.anuke.mindustry.entities.BlockBuilder.BuildRequest;
|
||||
import io.anuke.mindustry.entities.ItemAnimationEffect;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
import io.anuke.mindustry.ui.fragments.OverlayFragment;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Placement;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
@@ -158,25 +156,20 @@ public abstract class InputHandler extends InputAdapter{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean tryPlaceBlock(int x, int y, boolean sound){
|
||||
public boolean tryPlaceBlock(int x, int y){
|
||||
if(recipe != null &&
|
||||
validPlace(x, y, recipe.result) && !ui.hasMouse() && cursorNear() &&
|
||||
state.inventory.hasItems(recipe.requirements)){
|
||||
validPlace(x, y, recipe.result) && !ui.hasMouse() && cursorNear()){
|
||||
|
||||
placeBlock(x, y, recipe, rotation, true, sound);
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
state.inventory.removeItem(stack);
|
||||
}
|
||||
placeBlock(x, y, recipe, rotation);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tryDeleteBlock(int x, int y, boolean sound){
|
||||
public boolean tryDeleteBlock(int x, int y){
|
||||
if(cursorNear() && validBreak(x, y)){
|
||||
breakBlock(x, y, sound);
|
||||
breakBlock(x, y);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -189,7 +182,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public boolean validPlace(int x, int y, Block type){
|
||||
for(Tile tile : state.teams.get(player.team).cores){
|
||||
if(tile.distanceTo(x * tilesize, y * tilesize) < coreBuildRange){
|
||||
return Placement.validPlace(player.team, x, y, type, rotation) &&
|
||||
return Build.validPlace(player.team, x, y, type, rotation) &&
|
||||
Vector2.dst(player.x, player.y, x * tilesize, y * tilesize) < Player.placeDistance;
|
||||
}
|
||||
}
|
||||
@@ -198,35 +191,16 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
public boolean validBreak(int x, int y){
|
||||
return Placement.validBreak(player.team, x, y);
|
||||
return Build.validBreak(player.team, x, y);
|
||||
}
|
||||
|
||||
public void placeBlock(int x, int y, Recipe recipe, int rotation, boolean effects, boolean sound){
|
||||
public void placeBlock(int x, int y, Recipe recipe, int rotation){
|
||||
//todo multiplayer support
|
||||
player.addPlaceBlock(new PlaceRequest(x, y, rotation, recipe));
|
||||
/*
|
||||
if(!Net.client()){ //is server or singleplayer
|
||||
threads.run(() -> Placement.placeBlock(player.team, x, y, recipe, rotation, effects, sound));
|
||||
}
|
||||
|
||||
if(Net.active()){
|
||||
NetEvents.handlePlace(player, x, y, recipe, rotation);
|
||||
}
|
||||
|
||||
//todo fix this, call placed()
|
||||
if(!Net.client()){
|
||||
//Tile tile = world.tile(x, y);
|
||||
//if(tile != null) threads.run(() -> result.placed(tile));
|
||||
}*/
|
||||
player.addBuildRequest(new BuildRequest(x, y, rotation, recipe));
|
||||
}
|
||||
|
||||
public void breakBlock(int x, int y, boolean sound){
|
||||
if(!Net.client()){
|
||||
threads.run(() -> Placement.breakBlock(player.team, x, y, true, sound));
|
||||
}
|
||||
|
||||
if(Net.active()){
|
||||
NetEvents.handleBreak(x, y);
|
||||
}
|
||||
public void breakBlock(int x, int y){
|
||||
//todo multiplayer support
|
||||
player.addBuildRequest(new BuildRequest(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.ui.fragments.ToolFragment;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Placement;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -55,7 +55,7 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void tapped(InputHandler input, int tilex, int tiley){
|
||||
input.tryPlaceBlock(tilex, tiley, true);
|
||||
input.tryPlaceBlock(tilex, tiley);
|
||||
}
|
||||
},
|
||||
touch{
|
||||
@@ -67,7 +67,7 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void tapped(InputHandler input, int x, int y){
|
||||
input.tryPlaceBlock(x, y, true);
|
||||
input.tryPlaceBlock(x, y);
|
||||
}
|
||||
},
|
||||
none{
|
||||
@@ -110,7 +110,7 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void tapped(InputHandler input, int x, int y){
|
||||
input.tryDeleteBlock(x, y, true);
|
||||
input.tryDeleteBlock(x, y);
|
||||
}
|
||||
},
|
||||
areaDelete{
|
||||
@@ -172,7 +172,7 @@ public enum PlaceMode{
|
||||
tilex = this.rtilex; tiley = this.rtiley;
|
||||
endx = this.rendx; endy = this.rendy;
|
||||
|
||||
input.player.getPlaceQueue().clear();
|
||||
input.player.clearBuilding();
|
||||
|
||||
if(mobile){
|
||||
ToolFragment t = input.frag.tool;
|
||||
@@ -186,13 +186,10 @@ public enum PlaceMode{
|
||||
}
|
||||
}
|
||||
|
||||
boolean first = true;
|
||||
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
if(input.tryDeleteBlock(cx, cy, first)){
|
||||
first = false;
|
||||
}
|
||||
input.tryDeleteBlock(cx, cy);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +280,7 @@ public enum PlaceMode{
|
||||
|
||||
int wx = tilex + px * Mathf.sign(endx - tilex),
|
||||
wy = tiley + py * Mathf.sign(endy - tiley);
|
||||
if(!Placement.validPlace(input.player.team, wx, wy, block, rotation)){
|
||||
if(!Build.validPlace(input.player.team, wx, wy, block, rotation)){
|
||||
Draw.color("placeInvalid");
|
||||
}else{
|
||||
Draw.color("accent");
|
||||
@@ -315,22 +312,21 @@ public enum PlaceMode{
|
||||
process(input, tilex, tiley, endx, endy);
|
||||
|
||||
input.rotation = this.rotation;
|
||||
input.player.getPlaceQueue().clear();
|
||||
input.player.clearBuilding();
|
||||
|
||||
boolean first = true;
|
||||
for(int x = 0; x <= Math.abs(this.rendx - this.rtilex); x += input.recipe.result.size){
|
||||
for(int y = 0; y <= Math.abs(this.rendy - this.rtiley); y += input.recipe.result.size){
|
||||
if(input.tryPlaceBlock(
|
||||
input.tryPlaceBlock(
|
||||
tilex + x * Mathf.sign(endx - tilex),
|
||||
tiley + y * Mathf.sign(endy - tiley), first)){
|
||||
first = false;
|
||||
}
|
||||
|
||||
tiley + y * Mathf.sign(endy - tiley));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
|
||||
//todo hold shift to snap
|
||||
/*
|
||||
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
|
||||
endy = tiley;
|
||||
|
||||
Reference in New Issue
Block a user