Bugfixes, cleanup, optimization
This commit is contained in:
@@ -30,7 +30,6 @@ import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.core.KeyBinds;
|
||||
@@ -32,6 +33,8 @@ public class DesktopInput extends InputHandler{
|
||||
private float controlx, controly;
|
||||
private boolean controlling;
|
||||
private final String section;
|
||||
|
||||
/**Current cursor type.*/
|
||||
private CursorType cursorType = normal;
|
||||
|
||||
/**Position where the player started dragging a line.*/
|
||||
@@ -98,10 +101,6 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
Draw.color(Palette.remove);
|
||||
|
||||
Draw.alpha(0.6f);
|
||||
//Fill.crect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
|
||||
Draw.alpha(1f);
|
||||
|
||||
for(int x = dresult.x; x <= dresult.x2; x ++){
|
||||
for(int y = dresult.y; y <= dresult.y2; y ++){
|
||||
Tile tile = world.tile(x, y);
|
||||
@@ -160,9 +159,11 @@ public class DesktopInput extends InputHandler{
|
||||
cursorType = hand;
|
||||
}
|
||||
|
||||
if(cursor.floor().drops != null && cursor.floor().drops.item.hardness <= player.mech.drillPower
|
||||
&& cursor.block() == Blocks.air && player.distanceTo(cursor.worldx(), cursor.worldy()) <= Player.mineDistance &&
|
||||
player.inventory.canAcceptItem(cursor.floor().drops.item)){
|
||||
if(canMine(cursor)){
|
||||
cursorType = drill;
|
||||
}
|
||||
|
||||
if(canTapPlayer(Graphics.mouseWorld().x, Graphics.mouseWorld().y)){
|
||||
cursorType = drill;
|
||||
}
|
||||
|
||||
@@ -189,6 +190,8 @@ public class DesktopInput extends InputHandler{
|
||||
Tile cursor = tileAt(screenX, screenY);
|
||||
if(cursor == null) return false;
|
||||
|
||||
float worldx = Graphics.world(screenX, screenY).x, worldy = Graphics.world(screenX, screenY).y;
|
||||
|
||||
if(button == Buttons.LEFT) { //left = begin placing
|
||||
if (isPlacing()) {
|
||||
selectX = cursor.x;
|
||||
@@ -196,7 +199,8 @@ public class DesktopInput extends InputHandler{
|
||||
mode = placing;
|
||||
} else {
|
||||
//only begin shooting if there's no cursor event
|
||||
if(!tileTapped(cursor) && player.getPlaceQueue().size == 0 && !tryBeginMine(cursor)){
|
||||
if(!tileTapped(cursor) && player.getPlaceQueue().size == 0 && !tryBeginMine(cursor)
|
||||
&& player.getMineTile() == null && !tryTapPlayer(worldx, worldy) && !droppingItem){
|
||||
shooting = true;
|
||||
}
|
||||
}
|
||||
@@ -251,6 +255,8 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}
|
||||
|
||||
tryDropItems(cursor.target());
|
||||
|
||||
mode = none;
|
||||
|
||||
return false;
|
||||
@@ -320,7 +326,8 @@ public class DesktopInput extends InputHandler{
|
||||
enum CursorType{
|
||||
normal(Cursors::restoreCursor),
|
||||
hand(Cursors::setHand),
|
||||
drill(Cursors::setTool1);
|
||||
drill(() -> Cursors.set("drill")),
|
||||
unload(() -> Cursors.set("unload"));
|
||||
|
||||
private final Callable call;
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
@@ -26,7 +25,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public abstract class InputHandler extends InputAdapter{
|
||||
/**Used for dropping items.*/
|
||||
final float playerSelectRange = Unit.dp.scl(40f);
|
||||
final float playerSelectRange = 16f;
|
||||
/**Maximum line length.*/
|
||||
final int maxLength = 100;
|
||||
final Translator stackTrns = new Translator();
|
||||
@@ -87,13 +86,14 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
/**Handles tile tap events that are not platform specific.*/
|
||||
public boolean tileTapped(Tile tile){
|
||||
boolean tileTapped(Tile tile){
|
||||
tile = tile.target();
|
||||
|
||||
boolean consumed = false;
|
||||
boolean showedInventory = false;
|
||||
|
||||
//check if tapped block is configurable
|
||||
if(tile.block().isConfigurable(tile)){
|
||||
if(tile.block().isConfigurable(tile) && tile.getTeam() == player.team){
|
||||
consumed = true;
|
||||
if((!frag.config.isShown() //if the config fragment is hidden, show
|
||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||
@@ -111,19 +111,37 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
//TODO network event!
|
||||
//call tapped event
|
||||
if(tile.block().tapped(tile, player)){
|
||||
if(tile.getTeam() == player.team && tile.block().tapped(tile, player)){
|
||||
consumed = true;
|
||||
}else if(tile.getTeam() == player.team && tile.block().synthetic() && tile.block().hasItems){
|
||||
frag.inv.showFor(tile);
|
||||
consumed = true;
|
||||
showedInventory = true;
|
||||
}
|
||||
|
||||
if(!showedInventory){
|
||||
frag.inv.hide();
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
//utility methods
|
||||
/**Tries to select the player to drop off items, returns true if successful.*/
|
||||
boolean tryTapPlayer(float x, float y){
|
||||
if(canTapPlayer(x, y)){
|
||||
droppingItem = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean canTapPlayer(float x, float y){
|
||||
return Vector2.dst(x, y, player.x, player.y) <= playerSelectRange && player.inventory.hasItem();
|
||||
}
|
||||
|
||||
/**Tries to begin mining a tile, returns true if successful.*/
|
||||
boolean tryBeginMine(Tile tile){
|
||||
if(tile.floor().drops != null && tile.floor().drops.item.hardness <= player.mech.drillPower
|
||||
&& tile.block() == Blocks.air && player.distanceTo(tile.worldx(), tile.worldy()) <= Player.mineDistance){
|
||||
if(canMine(tile)){
|
||||
//if a block is clicked twice, reset it
|
||||
player.setMineTile(player.getMineTile() == tile ? null : tile);
|
||||
return true;
|
||||
@@ -131,6 +149,11 @@ public abstract class InputHandler extends InputAdapter{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean canMine(Tile tile){
|
||||
return tile.floor().drops != null && tile.floor().drops.item.hardness <= player.mech.drillPower
|
||||
&& tile.block() == Blocks.air && player.distanceTo(tile.worldx(), tile.worldy()) <= Player.mineDistance;
|
||||
}
|
||||
|
||||
/**Returns the tile at the specified MOUSE coordinates.*/
|
||||
Tile tileAt(float x, float y){
|
||||
Vector2 vec = Graphics.world(x, y);
|
||||
@@ -166,7 +189,16 @@ public abstract class InputHandler extends InputAdapter{
|
||||
return droppingItem;
|
||||
}
|
||||
|
||||
public void dropItem(Tile tile, ItemStack stack){
|
||||
public void tryDropItems(Tile tile){
|
||||
if(!droppingItem || !player.inventory.hasItem() || !tile.block().hasItems){
|
||||
droppingItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
droppingItem = false;
|
||||
|
||||
ItemStack stack = player.inventory.getItem();
|
||||
|
||||
int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player);
|
||||
|
||||
if(accepted > 0){
|
||||
@@ -203,7 +235,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
if(end){
|
||||
stack.amount -= remaining[0];
|
||||
if(clear) player.inventory.clear();
|
||||
if(clear) player.inventory.clearItem();
|
||||
transferring = false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package io.anuke.mindustry.input;
|
||||
|
||||
enum PlaceMode{
|
||||
none, breaking, placing;
|
||||
none, breaking, placing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user