Refactored almost every class, somehow didn't break game yet
This commit is contained in:
@@ -3,10 +3,9 @@ package io.anuke.mindustry.input;
|
||||
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.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;
|
||||
@@ -73,7 +72,7 @@ public class AndroidInput extends InputHandler{
|
||||
|
||||
warmup = 0;
|
||||
|
||||
if(!GameState.is(State.menu)){
|
||||
if(!state.is(State.menu)){
|
||||
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
|
||||
if(cursor != null && !ui.hasMouse(screenX, screenY)){
|
||||
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
|
||||
@@ -85,7 +84,7 @@ public class AndroidInput extends InputHandler{
|
||||
|
||||
if(linked != null) {
|
||||
linked.block().tapped(linked);
|
||||
if(Net.active()) netClient.handleBlockTap(linked);
|
||||
if(Net.active()) NetEvents.handleBlockTap(linked);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,8 +124,8 @@ public class AndroidInput extends InputHandler{
|
||||
|
||||
float xa = Inputs.getAxis("move_x");
|
||||
float ya = Inputs.getAxis("move_y");
|
||||
if(Math.abs(xa) < Vars.controllerMin) xa = 0;
|
||||
if(Math.abs(ya) < Vars.controllerMin) ya = 0;
|
||||
if(Math.abs(xa) < controllerMin) xa = 0;
|
||||
if(Math.abs(ya) < controllerMin) ya = 0;
|
||||
|
||||
player.x += xa * 4f;
|
||||
player.y += ya * 4f;
|
||||
@@ -173,15 +172,15 @@ public class AndroidInput extends InputHandler{
|
||||
public boolean tryPlaceBlock(int x, int y, boolean sound){
|
||||
if(recipe != null &&
|
||||
validPlace(x, y, recipe.result) && cursorNear() &&
|
||||
Vars.control.hasItems(recipe.requirements)){
|
||||
state.inventory.hasItems(recipe.requirements)){
|
||||
|
||||
placeBlock(x, y, recipe.result, rotation, true, sound);
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
Vars.control.removeItem(stack);
|
||||
state.inventory.removeItem(stack);
|
||||
}
|
||||
|
||||
if(!Vars.control.hasItems(recipe.requirements)){
|
||||
if(!state.inventory.hasItems(recipe.requirements)){
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -2,11 +2,9 @@ package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
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.net.Net;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
@@ -60,7 +58,7 @@ public class DesktopInput extends InputHandler{
|
||||
boolean controller = KeyBinds.getSection("default").device.type == DeviceType.controller;
|
||||
|
||||
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown("zoom_hold") || controller)
|
||||
&& !GameState.is(State.menu) && !ui.hasDialog()){
|
||||
&& !state.is(State.menu) && !ui.hasDialog()){
|
||||
if((!zoomed || !controller)) {
|
||||
renderer.scaleCamera((int) Inputs.getAxis("zoom"));
|
||||
}
|
||||
@@ -89,11 +87,11 @@ public class DesktopInput extends InputHandler{
|
||||
breakMode = PlaceMode.hold;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= 6 && i <= control.getWeapons().size; i ++){
|
||||
for(int i = 1; i <= 6 && i <= control.upgrades().getWeapons().size; i ++){
|
||||
if(Inputs.keyTap("weapon_" + i)){
|
||||
player.weaponLeft = player.weaponRight = control.getWeapons().get(i - 1);
|
||||
if(Net.active()) Vars.netClient.handleWeaponSwitch();
|
||||
Vars.ui.hudfrag.updateWeapons();
|
||||
player.weaponLeft = player.weaponRight = control.upgrades().getWeapons().get(i - 1);
|
||||
if(Net.active()) NetEvents.handleWeaponSwitch();
|
||||
ui.hudfrag.updateWeapons();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +107,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(linked != null) {
|
||||
linked.block().tapped(linked);
|
||||
if(Net.active()) netClient.handleBlockTap(linked);
|
||||
if(Net.active()) NetEvents.handleBlockTap(linked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,16 +149,6 @@ public class DesktopInput extends InputHandler{
|
||||
recipe.result.height % 2 == 0) ?
|
||||
Mathf.scl(Graphics.mouseWorld().y, tilesize) : Mathf.scl2(Graphics.mouseWorld().y, tilesize);
|
||||
}
|
||||
|
||||
public int currentWeapon(){
|
||||
int i = 0;
|
||||
for(Weapon weapon : control.getWeapons()){
|
||||
if(weapon == weapon)
|
||||
return i;
|
||||
i ++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.input;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
@@ -45,9 +44,10 @@ public class GestureHandler extends GestureAdapter{
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
if(Vars.control.showCursor() && !Inputs.keyDown("select")) return false;
|
||||
if(control.showCursor() && !Inputs.keyDown("select")) return false;
|
||||
|
||||
if(!Vars.control.showCursor() && !(control.input().recipe != null && Vars.control.hasItems(control.input().recipe.requirements) && control.input().placeMode.lockCamera) &&
|
||||
if(!control.showCursor() && !(control.input().recipe != null
|
||||
&& state.inventory.hasItems(control.input().recipe.requirements) && control.input().placeMode.lockCamera) &&
|
||||
!(control.input().recipe == null && control.input().breakMode.lockCamera)){
|
||||
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
player.x -= dx;
|
||||
|
||||
@@ -5,15 +5,15 @@ 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.Player;
|
||||
import io.anuke.mindustry.game.SpawnPoint;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
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.resource.Recipes;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.game.SpawnPoint;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
@@ -27,7 +27,6 @@ import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.player;
|
||||
|
||||
public abstract class InputHandler extends InputAdapter{
|
||||
public float breaktime = 0;
|
||||
@@ -43,15 +42,15 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public abstract float getCursorY();
|
||||
public abstract float getCursorEndX();
|
||||
public abstract float getCursorEndY();
|
||||
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, Vars.tilesize, round2()); }
|
||||
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, Vars.tilesize, round2()); }
|
||||
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 int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
|
||||
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, tilesize, round2()); }
|
||||
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, tilesize, round2()); }
|
||||
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, tilesize, round2()); }
|
||||
public void resetCursor(){}
|
||||
public boolean drawPlace(){ return true; }
|
||||
|
||||
public boolean onConfigurable(){
|
||||
Tile tile = Vars.world.tile(getBlockX(), getBlockY());
|
||||
Tile tile = world.tile(getBlockX(), getBlockY());
|
||||
return tile != null && (tile.block().isConfigurable(tile) || (tile.isLinked() && tile.getLinked().block().isConfigurable(tile)));
|
||||
}
|
||||
|
||||
@@ -62,15 +61,15 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public boolean tryPlaceBlock(int x, int y, boolean sound){
|
||||
if(recipe != null &&
|
||||
validPlace(x, y, recipe.result) && !ui.hasMouse() && cursorNear() &&
|
||||
Vars.control.hasItems(recipe.requirements)){
|
||||
state.inventory.hasItems(recipe.requirements)){
|
||||
|
||||
placeBlock(x, y, recipe.result, rotation, true, sound);
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
Vars.control.removeItem(stack);
|
||||
state.inventory.removeItem(stack);
|
||||
}
|
||||
|
||||
if(!Vars.control.hasItems(recipe.requirements)){
|
||||
if(!state.inventory.hasItems(recipe.requirements)){
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
return true;
|
||||
@@ -92,17 +91,17 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
public boolean validPlace(int x, int y, Block type){
|
||||
|
||||
for(SpawnPoint spawn : control.getSpawnPoints()){
|
||||
for(SpawnPoint spawn : world.getSpawns()){
|
||||
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);
|
||||
Tmp.r2.setSize(type.width * tilesize, type.height * tilesize);
|
||||
Vector2 offset = type.getPlaceOffset();
|
||||
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
|
||||
Tmp.r2.setCenter(offset.x + x * tilesize, offset.y + y * tilesize);
|
||||
|
||||
for(SolidEntity e : Entities.getNearby(control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
||||
for(SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
|
||||
Rectangle rect = e.hitbox.getRect(e.x, e.y);
|
||||
|
||||
if(Tmp.r2.overlaps(rect)){
|
||||
@@ -111,7 +110,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
if(type.solid || type.solidifes) {
|
||||
for (Player player : Vars.control.playerGroup.all()) {
|
||||
for (Player player : playerGroup.all()) {
|
||||
if (!player.isAndroid && Tmp.r2.overlaps(player.hitbox.getRect(player.x, player.y))) {
|
||||
return false;
|
||||
}
|
||||
@@ -122,18 +121,18 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
if(tile == null) return false;
|
||||
|
||||
if(!type.isMultiblock() && Vars.control.getTutorial().active() &&
|
||||
Vars.control.getTutorial().showBlock()){
|
||||
if(!type.isMultiblock() && control.tutorial().active() &&
|
||||
control.tutorial().showBlock()){
|
||||
|
||||
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
|
||||
int rotation = Vars.control.getTutorial().getPlaceRotation();
|
||||
Block block = Vars.control.getTutorial().getPlaceBlock();
|
||||
GridPoint2 point = control.tutorial().getPlacePoint();
|
||||
int rotation = control.tutorial().getPlaceRotation();
|
||||
Block block = control.tutorial().getPlaceBlock();
|
||||
|
||||
if(type != block || point.x != x - world.getCore().x || point.y != y - world.getCore().y
|
||||
|| (rotation != -1 && rotation != this.rotation)){
|
||||
return false;
|
||||
}
|
||||
}else if(Vars.control.getTutorial().active()){
|
||||
}else if(control.tutorial().active()){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -166,12 +165,12 @@ public abstract class InputHandler extends InputAdapter{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Vars.control.getTutorial().active()){
|
||||
if(control.tutorial().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(control.tutorial().showBlock()){
|
||||
GridPoint2 point = control.tutorial().getPlacePoint();
|
||||
int rotation = control.tutorial().getPlaceRotation();
|
||||
Block block = control.tutorial().getPlaceBlock();
|
||||
|
||||
if(block != Blocks.air || point.x != x - world.getCore().x || point.y != y - world.getCore().y
|
||||
|| (rotation != -1 && rotation != this.rotation)){
|
||||
@@ -190,7 +189,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
placeBlockInternal(x, y, result, rotation, effects, sound);
|
||||
|
||||
if(Net.active() && result != ProductionBlocks.core){
|
||||
Vars.netClient.handlePlace(x, y, result, rotation);
|
||||
NetEvents.handlePlace(x, y, result, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,11 +216,11 @@ public abstract class InputHandler extends InputAdapter{
|
||||
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
|
||||
}
|
||||
|
||||
if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
|
||||
if(effects) Effects.effect(Fx.place, worldx * tilesize, worldy * tilesize);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
|
||||
if(effects) Effects.effect(Fx.place, x * tilesize, y * tilesize);
|
||||
}
|
||||
|
||||
if(effects && sound) Sounds.play("place");
|
||||
@@ -233,7 +232,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
breakBlockInternal(x, y, sound);
|
||||
|
||||
if(Net.active()){
|
||||
Vars.netClient.handleBreak(x, y);
|
||||
NetEvents.handleBreak(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,12 +253,12 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
if(result != null){
|
||||
for(ItemStack stack : result.requirements){
|
||||
Vars.control.addItem(stack.item, (int)(stack.amount * Vars.breakDropAmount));
|
||||
state.inventory.addItem(stack.item, (int)(stack.amount * breakDropAmount));
|
||||
}
|
||||
}
|
||||
|
||||
if(tile.block().drops != null){
|
||||
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
|
||||
state.inventory.addItem(tile.block().drops.item, tile.block().drops.amount);
|
||||
}
|
||||
|
||||
//Effects.shake(3f, 1f, player);
|
||||
|
||||
@@ -4,12 +4,11 @@ import com.badlogic.gdx.Gdx;
|
||||
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.ui.fragments.ToolFragment;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
@@ -27,8 +26,8 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
float x = tilex * Vars.tilesize;
|
||||
float y = tiley * Vars.tilesize;
|
||||
float x = tilex * tilesize;
|
||||
float y = tiley * tilesize;
|
||||
|
||||
boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (android || control.input().cursorNear());
|
||||
|
||||
@@ -152,7 +151,7 @@ public enum PlaceMode{
|
||||
Lines.stroke(1f);
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
Tile tile = Vars.world.tile(cx, cy);
|
||||
Tile tile = world.tile(cx, cy);
|
||||
if(tile != null && tile.getLinked() != null)
|
||||
tile = tile.getLinked();
|
||||
if(tile != null && control.input().validBreak(tile.x, tile.y)){
|
||||
@@ -176,8 +175,8 @@ public enum PlaceMode{
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
|
||||
if(Vars.android){
|
||||
ToolFragment t = Vars.ui.toolfrag;
|
||||
if(android){
|
||||
ToolFragment t = ui.toolfrag;
|
||||
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
|
||||
t.confirming = true;
|
||||
t.px = tilex;
|
||||
@@ -242,11 +241,11 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
if(Vars.android && !Gdx.input.isTouched(0) && !Vars.control.showCursor()){
|
||||
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){
|
||||
return;
|
||||
}
|
||||
|
||||
float t = Vars.tilesize;
|
||||
float t = tilesize;
|
||||
Block block = control.input().recipe.result;
|
||||
Vector2 offset = block.getPlaceOffset();
|
||||
|
||||
@@ -290,7 +289,7 @@ public enum PlaceMode{
|
||||
py = ty + cy * Mathf.sign(ey - ty);
|
||||
|
||||
if(!control.input().validPlace(px, py, control.input().recipe.result)
|
||||
|| !control.hasItems(control.input().recipe.requirements, amount)){
|
||||
|| !state.inventory.hasItems(control.input().recipe.requirements, amount)){
|
||||
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
|
||||
}
|
||||
amount ++;
|
||||
|
||||
Reference in New Issue
Block a user