mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-09 10:18:40 +07:00
Bugfixes, cleanup, optimization
This commit is contained in:
parent
ae6b4211b9
commit
9555b10b97
BIN
core/assets/cursors/unload.png
Normal file
BIN
core/assets/cursors/unload.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 210 B |
@ -55,11 +55,8 @@ public class Vars{
|
||||
public static float fontScale;
|
||||
//camera zoom displayed on startup
|
||||
public static int baseCameraScale;
|
||||
//how much the zoom changes every zoom button press (unused?)
|
||||
public static int zoomScale;
|
||||
//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;
|
||||
public static boolean debugNet = true;
|
||||
public static boolean console = false;
|
||||
//whether the player can clip through walls
|
||||
public static boolean noclip = false;
|
||||
@ -83,8 +80,6 @@ public class Vars{
|
||||
public static float baseControllerSpeed = 11f;
|
||||
|
||||
public static final int saveSlots = 64;
|
||||
//amount of drops that are left when breaking a block
|
||||
public static final float breakDropAmount = 0.5f;
|
||||
|
||||
//only if smoothCamera
|
||||
public static boolean snapCamera = true;
|
||||
@ -172,6 +167,5 @@ public class Vars{
|
||||
|
||||
fontScale = Math.max(Unit.dp.scl(1f)/2f, 0.5f);
|
||||
baseCameraScale = Math.round(Unit.dp.scl(4));
|
||||
zoomScale = Math.round(Unit.dp.scl(1));
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.anuke.mindustry.ai;
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator;
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||
@ -39,7 +40,9 @@ public class Pathfinder {
|
||||
}
|
||||
|
||||
public void update(){
|
||||
for(TeamData team : state.teams.getTeams()){
|
||||
ObjectSetIterator<TeamData> iterator = new ObjectSetIterator<>(state.teams.getTeams());
|
||||
|
||||
for(TeamData team : iterator){
|
||||
updateFrontier(team.team, maxUpdate);
|
||||
}
|
||||
}
|
||||
|
@ -175,6 +175,8 @@ public class Control extends Module{
|
||||
|
||||
Timers.runTask(30f, () -> state.set(State.menu));
|
||||
});
|
||||
|
||||
Events.on(WorldLoadEvent.class, () -> Gdx.app.postRunnable(() -> Events.fire(WorldLoadGraphicsEvent.class)));
|
||||
}
|
||||
|
||||
public void addPlayer(int index){
|
||||
@ -259,13 +261,13 @@ public class Control extends Module{
|
||||
ui.loadfrag.show();
|
||||
saves.resetSave();
|
||||
|
||||
Timers.runTask(10, () -> {
|
||||
threads.run(() -> {
|
||||
logic.reset();
|
||||
world.loadMap(map);
|
||||
logic.play();
|
||||
});
|
||||
|
||||
Timers.runTask(18, () -> ui.loadfrag.hide());
|
||||
Gdx.app.postRunnable(ui.loadfrag::hide);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isHighScore(){
|
||||
|
@ -99,10 +99,12 @@ public class Renderer extends RendererModule{
|
||||
|
||||
Cursors.cursorScaling = 3;
|
||||
Cursors.outlineColor = Color.valueOf("444444");
|
||||
|
||||
Cursors.arrow = Cursors.loadCursor("cursor");
|
||||
Cursors.hand = Cursors.loadCursor("hand");
|
||||
Cursors.ibeam = Cursors.loadCursor("ibar");
|
||||
Cursors.tool1 = Cursors.loadCursor("drill");
|
||||
Cursors.loadCustom("drill");
|
||||
Cursors.loadCustom("unload");
|
||||
|
||||
clearColor = Hue.lightness(0.4f);
|
||||
clearColor.a = 1f;
|
||||
|
@ -43,6 +43,16 @@ public class ThreadHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void runDelay(Runnable r){
|
||||
if(enabled) {
|
||||
synchronized (toRun) {
|
||||
toRun.add(r);
|
||||
}
|
||||
}else{
|
||||
Gdx.app.postRunnable(r);
|
||||
}
|
||||
}
|
||||
|
||||
public int getFPS(){
|
||||
return (int)(60/delta);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
@ -21,6 +20,7 @@ import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
import static io.anuke.mindustry.Vars.threads;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class World extends Module{
|
||||
@ -192,7 +192,7 @@ public class World extends Module{
|
||||
|
||||
public void notifyChanged(Tile tile){
|
||||
if(!generating){
|
||||
Gdx.app.postRunnable(() -> Events.fire(TileChangeEvent.class, tile));
|
||||
threads.runDelay(() -> Events.fire(TileChangeEvent.class, tile));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,14 +37,16 @@ public class DrawOperation{
|
||||
public void undo(MapEditor editor) {
|
||||
for(int i = operations.size - 1; i >= 0; i --){
|
||||
TileOperation op = operations.get(i);
|
||||
data.write(op.x, op.y, op.from);
|
||||
data.position(op.x, op.y);
|
||||
data.write(op.from);
|
||||
editor.renderer().updatePoint(op.x, op.y);
|
||||
}
|
||||
}
|
||||
|
||||
public void redo(MapEditor editor) {
|
||||
for(TileOperation op : operations){
|
||||
data.write(op.x, op.y, op.to);
|
||||
data.position(op.x, op.y);
|
||||
data.write(op.to);
|
||||
editor.renderer().updatePoint(op.x, op.y);
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,29 @@ package io.anuke.mindustry.editor;
|
||||
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public enum EditorTool{
|
||||
pick{
|
||||
public void touched(MapEditor editor, int x, int y){
|
||||
TileDataMarker writer = editor.getMap().readAt(x, y);
|
||||
Block block = Block.getByID(writer.wall == 0 ? writer.floor : writer.wall);
|
||||
byte bf = editor.getMap().read(x, y, DataPosition.floor);
|
||||
byte bw = editor.getMap().read(x, y, DataPosition.wall);
|
||||
byte link = editor.getMap().read(x, y, DataPosition.link);
|
||||
|
||||
if(link != 0){
|
||||
x -= (Bits.getLeftByte(link) - 8);
|
||||
y -= (Bits.getRightByte(link) - 8);
|
||||
bf = editor.getMap().read(x, y, DataPosition.floor);
|
||||
bw = editor.getMap().read(x, y, DataPosition.wall);
|
||||
}
|
||||
|
||||
Block block = Block.getByID(bw == 0 ? bf : bw);
|
||||
editor.setDrawBlock(block);
|
||||
ui.editor.updateSelectedBlock();
|
||||
}
|
||||
@ -31,7 +43,6 @@ public enum EditorTool{
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
fill{
|
||||
{
|
||||
@ -39,11 +50,21 @@ public enum EditorTool{
|
||||
}
|
||||
|
||||
public void touched(MapEditor editor, int x, int y){
|
||||
if(editor.getDrawBlock().isMultiblock()){
|
||||
//don't fill multiblocks, thanks
|
||||
pencil.touched(editor, x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean floor = editor.getDrawBlock() instanceof Floor;
|
||||
|
||||
TileDataMarker writer = editor.getMap().readAt(x, y);
|
||||
byte bf = editor.getMap().read(x, y, DataPosition.floor);
|
||||
byte bw = editor.getMap().read(x, y, DataPosition.wall);
|
||||
boolean synth = editor.getDrawBlock().synthetic();
|
||||
byte brt = Bits.packByte((byte)editor.getDrawRotation(), (byte)editor.getDrawTeam().ordinal());
|
||||
|
||||
byte dest = floor ? writer.floor : writer.wall;
|
||||
byte dest = floor ? bf: bw;
|
||||
byte draw = (byte)editor.getDrawBlock().id;
|
||||
|
||||
int width = editor.getMap().width();
|
||||
int height = editor.getMap().height();
|
||||
@ -58,21 +79,28 @@ public enum EditorTool{
|
||||
int py = pos / width;
|
||||
set.add(pos);
|
||||
|
||||
writer = editor.getMap().readAt(px, py);
|
||||
byte nbf = editor.getMap().read(px, py, DataPosition.floor);
|
||||
byte nbw = editor.getMap().read(px, py, DataPosition.wall);
|
||||
|
||||
if((floor ? writer.floor : writer.wall) == dest){
|
||||
if(floor)
|
||||
writer.floor = (byte)editor.getDrawBlock().id;
|
||||
else
|
||||
writer.wall = (byte)editor.getDrawBlock().id;
|
||||
if((floor ? nbf : nbw) == dest){
|
||||
TileDataMarker prev = editor.getPrev(px, py, false);
|
||||
|
||||
editor.write(px, py, writer, false);
|
||||
editor.renderer().updatePoint(px, py);
|
||||
if(floor) {
|
||||
editor.getMap().write(px, py, DataPosition.floor, draw);
|
||||
}else {
|
||||
editor.getMap().write(px, py, DataPosition.wall, draw);
|
||||
}
|
||||
|
||||
if(synth){
|
||||
editor.getMap().write(px, py, DataPosition.rotationTeam, brt);
|
||||
}
|
||||
|
||||
if(px > 0 && !set.contains(asInt(px - 1, py, width))) points.add(asInt(px - 1, py, width));
|
||||
if(py > 0 && !set.contains(asInt(px, py - 1, width))) points.add(asInt(px, py - 1, width));
|
||||
if(px < width - 1 && !set.contains(asInt(px + 1, py, width))) points.add(asInt(px + 1, py, width));
|
||||
if(py < height - 1 && !set.contains(asInt(px, py + 1, width))) points.add(asInt(px, py + 1, width));
|
||||
|
||||
editor.onWrite(px, py, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.editor.DrawOperation.TileOperation;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.io.MapTileData;
|
||||
import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
@ -18,7 +19,6 @@ public class MapEditor{
|
||||
|
||||
private MapTileData map;
|
||||
private ObjectMap<String, String> tags = new ObjectMap<>();
|
||||
private TileDataMarker multiWriter;
|
||||
private MapRenderer renderer = new MapRenderer(this);
|
||||
|
||||
private int brushSize = 1;
|
||||
@ -44,7 +44,6 @@ public class MapEditor{
|
||||
this.tags = tags;
|
||||
|
||||
drawBlock = Blocks.stone;
|
||||
multiWriter = map.new TileDataMarker();
|
||||
renderer.resize(map.width(), map.height());
|
||||
}
|
||||
|
||||
@ -85,94 +84,84 @@ public class MapEditor{
|
||||
return;
|
||||
}
|
||||
|
||||
TileDataMarker writer = map.readAt(x, y);
|
||||
byte writeID = (byte)drawBlock.id;
|
||||
byte partID = (byte)Blocks.blockpart.id;
|
||||
byte rotationTeam = Bits.packByte(drawBlock.rotate ? (byte)rotation : 0, drawBlock.synthetic() ? (byte)drawTeam.ordinal() : 0);
|
||||
|
||||
boolean isfloor = drawBlock instanceof Floor;
|
||||
if(isfloor){
|
||||
writer.floor = (byte)drawBlock.id;
|
||||
}else{
|
||||
writer.wall = (byte)drawBlock.id;
|
||||
}
|
||||
|
||||
if(drawBlock.hasEntity()){
|
||||
writer.team = (byte)drawTeam.ordinal();
|
||||
}
|
||||
if(drawBlock.isMultiblock()) {
|
||||
|
||||
if(drawBlock.rotate){
|
||||
writer.rotation = (byte)rotation;
|
||||
}
|
||||
int offsetx = -(drawBlock.size - 1) / 2;
|
||||
int offsety = -(drawBlock.size - 1) / 2;
|
||||
|
||||
if(drawBlock.isMultiblock()){
|
||||
for(int i = 0; i < 2; i ++){
|
||||
for (int dx = 0; dx < drawBlock.size; dx++) {
|
||||
for (int dy = 0; dy < drawBlock.size; dy++) {
|
||||
int worldx = dx + offsetx + x;
|
||||
int worldy = dy + offsety + y;
|
||||
|
||||
int offsetx = -(drawBlock.size-1)/2;
|
||||
int offsety = -(drawBlock.size-1)/2;
|
||||
if (Mathf.inBounds(worldx, worldy, map.width(), map.height())) {
|
||||
TileDataMarker prev = getPrev(worldx, worldy, false);
|
||||
|
||||
for(int dx = 0; dx < drawBlock.size; dx ++){
|
||||
for(int dy = 0; dy < drawBlock.size; dy ++){
|
||||
int worldx = dx + offsetx + x;
|
||||
int worldy = dy + offsety + y;
|
||||
if(!(worldx == x && worldy == y)){
|
||||
if(i == 1) {
|
||||
map.write(worldx, worldy, DataPosition.wall, partID);
|
||||
map.write(worldx, worldy, DataPosition.rotationTeam, rotationTeam);
|
||||
map.write(worldx, worldy, DataPosition.link, Bits.packByte((byte) (dx + offsetx + 8), (byte) (dy + offsety + 8)));
|
||||
}else{
|
||||
byte link = map.read(worldx, worldy, DataPosition.link);
|
||||
byte block = map.read(worldx, worldy, DataPosition.wall);
|
||||
|
||||
if(Mathf.inBounds(worldx, worldy, map.width(), map.height())){
|
||||
map.readAt(worldx, worldy);
|
||||
byte floor = writer.floor;
|
||||
|
||||
if(writer.link != 0){
|
||||
removeLinked(worldx - (Bits.getLeftByte(writer.link) - 8), worldy - (Bits.getRightByte(writer.link) - 8));
|
||||
if (link != 0) {
|
||||
removeLinked(worldx - (Bits.getLeftByte(link) - 8), worldy - (Bits.getRightByte(link) - 8));
|
||||
}else if(Block.getByID(block).isMultiblock()){
|
||||
removeLinked(worldx, worldy);
|
||||
}
|
||||
}
|
||||
|
||||
writer.wall = (byte)Blocks.blockpart.id;
|
||||
writer.team = (byte)drawTeam.ordinal();
|
||||
writer.floor = floor;
|
||||
writer.link = Bits.packByte((byte) (dx + offsetx + 8), (byte) (dy + offsety + 8));
|
||||
write(worldx, worldy, writer, false);
|
||||
|
||||
renderer.updatePoint(worldx, worldy);
|
||||
onWrite(worldx, worldy, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map.readAt(x, y);
|
||||
if(drawBlock instanceof Floor){
|
||||
writer.floor = (byte)drawBlock.id;
|
||||
}else{
|
||||
writer.wall = (byte)drawBlock.id;
|
||||
}
|
||||
TileDataMarker prev = getPrev(x, y, false);
|
||||
|
||||
writer.team = (byte)drawTeam.ordinal();
|
||||
writer.rotation = 0;
|
||||
writer.link = 0;
|
||||
write(x, y, writer, false);
|
||||
map.write(x, y, DataPosition.wall, writeID);
|
||||
map.write(x, y, DataPosition.link, (byte)0);
|
||||
map.write(x, y, DataPosition.rotationTeam, rotationTeam);
|
||||
|
||||
renderer.updatePoint(x, y);
|
||||
onWrite(x, y, prev);
|
||||
}else{
|
||||
|
||||
for (int rx = -brushSize; rx <= brushSize; rx++) {
|
||||
for (int ry = -brushSize; ry <= brushSize; ry++) {
|
||||
if (Mathf.dst(rx, ry) <= brushSize - 0.5f) {
|
||||
if (x + rx < 0 || y + ry < 0 || x + rx >= map.width() || y + ry >= map.height()) {
|
||||
int wx = x + rx, wy = y + ry;
|
||||
|
||||
if (wx < 0 || wy < 0 || wx >= map.width() || wy >= map.height()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte b1 = map.readAt(x + rx, y + ry, 1);
|
||||
byte b2 = map.readAt(x + rx, y + ry, 2);
|
||||
byte b3 = map.readAt(x + rx, y + ry, 3);
|
||||
TileDataMarker prev = getPrev(wx, wy, true);
|
||||
|
||||
if(!isfloor) {
|
||||
byte link = map.readAt(x + rx, y + ry, 2);
|
||||
byte link = map.read(wx, wy, DataPosition.link);
|
||||
|
||||
if (link != 0) {
|
||||
removeLinked(x + rx - (Bits.getLeftByte(link) - 8), y + ry - (Bits.getRightByte(link) - 8));
|
||||
removeLinked(wx - (Bits.getLeftByte(link) - 8), wy - (Bits.getRightByte(link) - 8));
|
||||
}
|
||||
}
|
||||
|
||||
writer.wall = b1;
|
||||
writer.link = b2;
|
||||
writer.rotation = Bits.getLeftByte(b3);
|
||||
writer.team = Bits.getRightByte(b3);
|
||||
if(isfloor){
|
||||
map.write(wx, wy, DataPosition.floor, writeID);
|
||||
}else{
|
||||
map.write(wx, wy, DataPosition.wall, writeID);
|
||||
map.write(wx, wy, DataPosition.link, (byte)0);
|
||||
map.write(wx, wy, DataPosition.rotationTeam, rotationTeam);
|
||||
}
|
||||
|
||||
write(x + rx, y + ry, writer, true);
|
||||
renderer.updatePoint(x + rx, y + ry);
|
||||
onWrite(x + rx, y + ry, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,8 +169,7 @@ public class MapEditor{
|
||||
}
|
||||
|
||||
private void removeLinked(int x, int y){
|
||||
TileDataMarker marker = map.readAt(x, y, multiWriter);
|
||||
Block block = Block.getByID(marker.wall);
|
||||
Block block = Block.getByID(map.read(x, y, DataPosition.wall));
|
||||
|
||||
int offsetx = -(block.size-1)/2;
|
||||
int offsety = -(block.size-1)/2;
|
||||
@ -189,39 +177,44 @@ public class MapEditor{
|
||||
for(int dy = 0; dy < block.size; dy ++){
|
||||
int worldx = x + dx + offsetx, worldy = y + dy + offsety;
|
||||
if(Mathf.inBounds(worldx, worldy, map.width(), map.height())){
|
||||
map.readAt(worldx, worldy, marker);
|
||||
marker.link = 0;
|
||||
marker.wall = 0;
|
||||
marker.rotation = 0;
|
||||
marker.team = 0;
|
||||
write(worldx, worldy, marker, false);
|
||||
TileDataMarker prev = getPrev(worldx, worldy, false);
|
||||
|
||||
if(worldx == x && worldy == y){
|
||||
renderer.updatePoint(worldx, worldy);
|
||||
}
|
||||
map.write(worldx, worldy, DataPosition.link, (byte)0);
|
||||
map.write(worldx, worldy, DataPosition.rotationTeam, (byte)0);
|
||||
map.write(worldx, worldy, DataPosition.wall, (byte)0);
|
||||
|
||||
onWrite(worldx, worldy, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int x, int y, TileDataMarker writer, boolean checkDupes){
|
||||
boolean dupe = checkDupes && Vars.ui.editor.getView().checkForDuplicates((short) x, (short) y);
|
||||
TileDataMarker prev = null;
|
||||
boolean checkDupes(int x, int y){
|
||||
return Vars.ui.editor.getView().checkForDuplicates((short) x, (short) y);
|
||||
}
|
||||
|
||||
if(!dupe) {
|
||||
prev = map.new TileDataMarker();
|
||||
map.position(x, y);
|
||||
map.read(prev);
|
||||
void onWrite(int x, int y, TileDataMarker previous){
|
||||
if(previous == null){
|
||||
renderer.updatePoint(x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
map.write(x, y, writer);
|
||||
TileDataMarker current = map.new TileDataMarker();
|
||||
map.position(x, y);
|
||||
map.read(current);
|
||||
|
||||
if(!dupe) {
|
||||
TileDataMarker current = map.new TileDataMarker();
|
||||
Vars.ui.editor.getView().addTileOp(new TileOperation((short) x, (short) y, previous, current));
|
||||
renderer.updatePoint(x, y);
|
||||
}
|
||||
|
||||
TileDataMarker getPrev(int x, int y, boolean checkDupes){
|
||||
if(checkDupes && checkDupes(x, y)){
|
||||
return null;
|
||||
}else{
|
||||
TileDataMarker marker = map.newDataMarker();
|
||||
map.position(x, y);
|
||||
map.read(current);
|
||||
|
||||
Vars.ui.editor.getView().addTileOp(new TileOperation((short) x, (short) y, prev, current));
|
||||
map.read(marker);
|
||||
return marker;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ public class MapFilter{
|
||||
OrderedMap<String, GenPref> prefs = new OrderedMap<>();
|
||||
|
||||
for(int i = 0; i < objects.length; i ++){
|
||||
GenPref pref = (GenPref)objects[i];
|
||||
GenPref pref = objects[i];
|
||||
prefs.put(pref.name, pref);
|
||||
}
|
||||
return prefs;
|
||||
|
@ -15,13 +15,14 @@ import com.badlogic.gdx.utils.IntSet;
|
||||
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.IndexedRenderer;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
@ -109,7 +110,7 @@ public class MapRenderer implements Disposable{
|
||||
|
||||
for(int x = 0; x < chunks.length; x ++){
|
||||
for(int y = 0; y < chunks[0].length; y ++){
|
||||
chunks[x][y] = new IndexedRenderer(chunksize*chunksize*3);
|
||||
chunks[x][y] = new IndexedRenderer(chunksize*chunksize*2);
|
||||
}
|
||||
}
|
||||
this.width = width;
|
||||
@ -161,41 +162,47 @@ public class MapRenderer implements Disposable{
|
||||
private void render(int wx, int wy){
|
||||
int x = wx/chunksize, y = wy/chunksize;
|
||||
IndexedRenderer mesh = chunks[x][y];
|
||||
TileDataMarker data = editor.getMap().readAt(wx, wy);
|
||||
Block floor = Block.getByID(data.floor);
|
||||
Block wall = Block.getByID(data.wall);
|
||||
//TileDataMarker data = editor.getMap().readAt(wx, wy);
|
||||
byte bf = editor.getMap().read(wx, wy, DataPosition.floor);
|
||||
byte bw = editor.getMap().read(wx, wy, DataPosition.wall);
|
||||
byte btr = editor.getMap().read(wx, wy, DataPosition.rotationTeam);
|
||||
byte rotation = Bits.getLeftByte(btr);
|
||||
Team team = Team.values()[Bits.getRightByte(btr)];
|
||||
|
||||
Block floor = Block.getByID(bf);
|
||||
Block wall = Block.getByID(bw);
|
||||
|
||||
int offsetx = -(wall.size-1)/2;
|
||||
int offsety = -(wall.size-1)/2;
|
||||
|
||||
TextureRegion region = blockIcons.get(floor, regions.get("clear"));
|
||||
TextureRegion region;
|
||||
|
||||
if(data.link != 0 || wall.solid){
|
||||
region = regions.get("clear");
|
||||
}
|
||||
if(bw != 0) {
|
||||
region = blockIcons.get(wall, regions.get("clear"));
|
||||
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize, region, wx * tilesize, wy * tilesize, 8, 8);
|
||||
|
||||
region = blockIcons.get(wall, regions.get("clear"));
|
||||
|
||||
if(wall.rotate){
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
|
||||
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
|
||||
region.getRegionWidth(), region.getRegionHeight(), data.rotation*90 - 90);
|
||||
if (wall.rotate) {
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize) * chunksize, region,
|
||||
wx * tilesize + offsetx * tilesize, wy * tilesize + offsety * tilesize,
|
||||
region.getRegionWidth(), region.getRegionHeight(), rotation * 90 - 90);
|
||||
} else {
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize) * chunksize, region,
|
||||
wx * tilesize + offsetx * tilesize, wy * tilesize + offsety * tilesize,
|
||||
region.getRegionWidth(), region.getRegionHeight());
|
||||
}
|
||||
}else{
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
|
||||
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
|
||||
region.getRegionWidth(), region.getRegionHeight());
|
||||
region = blockIcons.get(floor, regions.get("clear"));
|
||||
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize, region, wx * tilesize, wy * tilesize, 8, 8);
|
||||
}
|
||||
|
||||
if(wall.update || wall.destructible) {
|
||||
mesh.setColor(Team.values()[data.team].color);
|
||||
mesh.setColor(team.color);
|
||||
region = regions.get("block-border");
|
||||
}else{
|
||||
region = regions.get("clear");
|
||||
}
|
||||
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize*2, region,
|
||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
|
||||
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
|
||||
region.getRegionWidth(), region.getRegionHeight());
|
||||
mesh.setColor(Color.WHITE);
|
||||
|
@ -123,6 +123,9 @@ public class MapView extends Element implements GestureListener{
|
||||
return false;
|
||||
}
|
||||
|
||||
mousex = x;
|
||||
mousey = y;
|
||||
|
||||
op = new DrawOperation(editor.getMap());
|
||||
|
||||
updated = false;
|
||||
|
@ -173,7 +173,7 @@ public interface BlockBuilder {
|
||||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(tile.worldx(), tile.worldy()), 0.4f);
|
||||
|
||||
if(unit.inventory.canAcceptItem(item) &&
|
||||
Mathf.chance(Timers.delta() * 0.05 / item.hardness)){
|
||||
Mathf.chance(Timers.delta() * (0.06 - item.hardness * 0.01))){
|
||||
ItemTransfer.create(item,
|
||||
tile.worldx() + Mathf.range(tilesize/2f),
|
||||
tile.worldy() + Mathf.range(tilesize/2f),
|
||||
|
@ -465,8 +465,8 @@ public class Player extends Unit implements BlockBuilder {
|
||||
rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len()/10f);
|
||||
}
|
||||
|
||||
//update shooting if not building and there's ammo left
|
||||
if(!isBuilding() && inventory.hasAmmo()){
|
||||
//update shooting if not building, not mining and there's ammo left
|
||||
if(!isBuilding() && inventory.hasAmmo() && getMineTile() == null){
|
||||
|
||||
//autofire: mobile only!
|
||||
if(mobile) {
|
||||
|
@ -19,13 +19,11 @@ public class Predict {
|
||||
* @return the intercept location*/
|
||||
public static Vector2 intercept(float srcx, float srcy, float dstx, float dsty, float dstvx, float dstvy, float v) {
|
||||
float tx = dstx - srcx,
|
||||
ty = dsty - srcy,
|
||||
tvx = dstvx,
|
||||
tvy = dstvy;
|
||||
ty = dsty - srcy;
|
||||
|
||||
// Get quadratic equation components
|
||||
float a = tvx*tvx + tvy*tvy - v*v;
|
||||
float b = 2 * (tvx * tx + tvy * ty);
|
||||
float a = dstvx * dstvx + dstvy * dstvy - v*v;
|
||||
float b = 2 * (dstvx * tx + dstvy * ty);
|
||||
float c = tx*tx + ty*ty;
|
||||
|
||||
// Solve quadratic
|
||||
|
@ -132,6 +132,10 @@ public class UnitInventory {
|
||||
totalAmmo = 0;
|
||||
}
|
||||
|
||||
public void clearItem(){
|
||||
item = null;
|
||||
}
|
||||
|
||||
public boolean hasItem(){
|
||||
return item != null;
|
||||
}
|
||||
|
@ -28,16 +28,13 @@ public class Units {
|
||||
* @param range The maximum distance from the target X/Y the targeter can be for it to be valid
|
||||
* @return whether the target is invalid
|
||||
*/
|
||||
public static boolean invalidateTarget(Targetable target, Team team, float x, float y, float range){
|
||||
if(target == null){
|
||||
public static boolean invalidateTarget(Targetable target, Team team, float x, float y, float range) {
|
||||
if (target == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(range != Float.MAX_VALUE && target.distanceTo(x, y) > range){
|
||||
return false;
|
||||
}
|
||||
return (!(range != Float.MAX_VALUE) || !(target.distanceTo(x, y) > range)) && (target.getTeam() == team || !target.isValid());
|
||||
|
||||
return target.getTeam() == team || !target.isValid();
|
||||
}
|
||||
|
||||
/**See {@link #invalidateTarget(Targetable, Team, float, float, float)}*/
|
||||
|
@ -100,7 +100,7 @@ public abstract class UnitType {
|
||||
public abstract void behavior(BaseUnit unit);
|
||||
|
||||
public void updateTargeting(BaseUnit unit){
|
||||
if(unit.target == null || (unit.target instanceof Unit && (((Unit)unit.target).isDead() || ((Unit)unit.target).team == unit.team))
|
||||
if(unit.target == null || (unit.target instanceof Unit && (unit.target.isDead() || ((Unit)unit.target).team == unit.team))
|
||||
|| (unit.target instanceof TileEntity && ((TileEntity) unit.target).tile.entity == null)){
|
||||
unit.target = null;
|
||||
}
|
||||
|
@ -22,10 +22,19 @@ public class EventType {
|
||||
void handle();
|
||||
}
|
||||
|
||||
/**This event is called from the logic thread.
|
||||
* DO NOT INITIALIZE GRAPHICS HERE.*/
|
||||
public interface WorldLoadEvent extends Event{
|
||||
void handle();
|
||||
}
|
||||
|
||||
/**Called after the WorldLoadEvent is, and all logic has been loaded.
|
||||
* It is safe to intialize graphics here.*/
|
||||
public interface WorldLoadGraphicsEvent extends Event{
|
||||
void handle();
|
||||
}
|
||||
|
||||
/**Called from the logic thread. Do not call graphics here!*/
|
||||
public interface TileChangeEvent extends Event{
|
||||
void handle(Tile tile);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class BlockRenderer{
|
||||
|
||||
private FloorRenderer floorRenderer;
|
||||
|
||||
private Array<BlockRequest> requests = new Array<BlockRequest>(initialRequests);
|
||||
private Array<BlockRequest> requests = new Array<>(initialRequests);
|
||||
private Layer lastLayer;
|
||||
private int requestidx = 0;
|
||||
private int iterateidx = 0;
|
||||
|
@ -9,7 +9,7 @@ import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
@ -35,7 +35,7 @@ public class FloorRenderer {
|
||||
private IntArray drawnLayers = new IntArray();
|
||||
|
||||
public FloorRenderer(){
|
||||
Events.on(WorldLoadEvent.class, this::clearTiles);
|
||||
Events.on(WorldLoadGraphicsEvent.class, this::clearTiles);
|
||||
}
|
||||
|
||||
public void drawFloor(){
|
||||
|
@ -12,5 +12,5 @@ public enum Layer{
|
||||
/**Power lasers.*/
|
||||
power,
|
||||
/**Extra lasers, like healing turrets.*/
|
||||
laser;
|
||||
laser
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
@ -8,7 +9,7 @@ import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
@ -17,7 +18,8 @@ import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Pixmaps;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class MinimapRenderer implements Disposable{
|
||||
private static final int baseSize = 16;
|
||||
@ -28,12 +30,13 @@ public class MinimapRenderer implements Disposable{
|
||||
private int zoom = 4;
|
||||
|
||||
public MinimapRenderer(){
|
||||
Events.on(WorldLoadEvent.class, () -> {
|
||||
Events.on(WorldLoadGraphicsEvent.class, () -> {
|
||||
reset();
|
||||
updateAll();
|
||||
});
|
||||
|
||||
Events.on(TileChangeEvent.class, this::update);
|
||||
//make sure to call on the graphics thread
|
||||
Events.on(TileChangeEvent.class, tile -> Gdx.app.postRunnable(() -> update(tile)));
|
||||
}
|
||||
|
||||
public Texture getTexture(){
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
@ -15,7 +16,11 @@ import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.*;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.graphics.CapStyle;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@ -93,22 +98,45 @@ public class OverlayRenderer {
|
||||
}
|
||||
|
||||
if (target.entity != null) {
|
||||
int bot = 0, top = 0;
|
||||
for (BlockBar bar : target.block().bars.list()) {
|
||||
float offset = Mathf.sign(bar.top) * (target.block().size / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) +
|
||||
(bar.top ? -1f : 0f);
|
||||
int[] values = {0, 0};
|
||||
Tile t = target;
|
||||
boolean[] doDraw = {false};
|
||||
|
||||
float value = bar.value.get(target);
|
||||
Callable drawbars = () -> {
|
||||
for (BlockBar bar : t.block().bars.list()) {
|
||||
//TODO fix.
|
||||
float offset = Mathf.sign(bar.top) * (t.block().size / 2f * tilesize + 2f + (bar.top ? values[0] : values[1]));
|
||||
|
||||
if (MathUtils.isEqual(value, -1f)) continue;
|
||||
float value = bar.value.get(t);
|
||||
|
||||
drawBar(bar.type.color, target.drawx(), target.drawy() + offset, value);
|
||||
if (MathUtils.isEqual(value, -1f)) continue;
|
||||
|
||||
if (bar.top)
|
||||
top++;
|
||||
else
|
||||
bot++;
|
||||
if(doDraw[0]){
|
||||
drawBar(bar.type.color, t.drawx(), t.drawy() + offset, value);
|
||||
}
|
||||
|
||||
if (bar.top)
|
||||
values[0]++;
|
||||
else
|
||||
values[1]++;
|
||||
}
|
||||
};
|
||||
|
||||
drawbars.run();
|
||||
|
||||
if(values[0] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() + target.block().size * tilesize/2f + 2f + values[0]/2f + (values[0] > 2 ? 1 : 0), values[0]);
|
||||
}
|
||||
|
||||
if(values[1] > 0){
|
||||
drawEncloser(target.drawx(), target.drawy() - target.block().size * tilesize/2f - 2f - values[1]/2f, values[1]);
|
||||
}
|
||||
|
||||
doDraw[0] = true;
|
||||
values[0] = 0;
|
||||
values[1] = 1;
|
||||
|
||||
drawbars.run();
|
||||
}
|
||||
|
||||
target.block().drawSelect(target);
|
||||
@ -135,7 +163,9 @@ public class OverlayRenderer {
|
||||
}
|
||||
|
||||
if((!debug || showUI) && Settings.getBool("healthbars")){
|
||||
for(TeamData ally : (debug ? state.teams.getTeams() : state.teams.getTeams(true))){
|
||||
ObjectSetIterator<TeamData> iterator = new ObjectSetIterator<>((debug ? state.teams.getTeams() : state.teams.getTeams(true)));
|
||||
|
||||
for(TeamData ally : iterator){
|
||||
for(Unit e : unitGroups[ally.team.ordinal()].all()){
|
||||
drawStats(e);
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap.Entry;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.ColorMapper;
|
||||
@ -37,9 +38,11 @@ public class MapIO {
|
||||
Pixmap pixmap = new Pixmap(data.width(), data.height(), Format.RGBA8888);
|
||||
data.position(0, 0);
|
||||
|
||||
TileDataMarker marker = data.newDataMarker();
|
||||
|
||||
for(int y = 0; y < data.height(); y ++){
|
||||
for(int x = 0; x < data.width(); x ++){
|
||||
TileDataMarker marker = data.read();
|
||||
data.read(marker);
|
||||
Block floor = Block.getByID(marker.floor);
|
||||
Block wall = Block.getByID(marker.wall);
|
||||
int wallc = ColorMapper.getColor(wall);
|
||||
@ -56,22 +59,17 @@ public class MapIO {
|
||||
public static MapTileData readPixmap(Pixmap pixmap){
|
||||
MapTileData data = new MapTileData(pixmap.getWidth(), pixmap.getHeight());
|
||||
|
||||
data.position(0, 0);
|
||||
TileDataMarker marker = data.getMarker();
|
||||
|
||||
for(int x = 0; x < data.width(); x ++){
|
||||
for(int y = 0; y < data.height(); y ++){
|
||||
BlockPair pair = ColorMapper.get(pixmap.getPixel(y, pixmap.getWidth() - 1 - x));
|
||||
|
||||
if(pair == null){
|
||||
marker.floor = (byte)Blocks.stone.id;
|
||||
marker.wall = (byte)Blocks.air.id;
|
||||
data.write(x, y, DataPosition.floor, (byte)Blocks.stone.id);
|
||||
data.write(x, y, DataPosition.wall, (byte)Blocks.air.id);
|
||||
}else{
|
||||
marker.floor = (byte)pair.floor.id;
|
||||
marker.wall = (byte)pair.wall.id;
|
||||
data.write(x, y, DataPosition.floor, (byte)pair.floor.id);
|
||||
data.write(x, y, DataPosition.wall, (byte)pair.wall.id);
|
||||
}
|
||||
|
||||
data.write();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package io.anuke.mindustry.io;
|
||||
|
||||
import com.badlogic.gdx.utils.IntIntMap;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@ -15,7 +14,6 @@ public class MapTileData {
|
||||
private final static int TILE_SIZE = 4;
|
||||
|
||||
private final ByteBuffer buffer;
|
||||
private final TileDataMarker tile = new TileDataMarker();
|
||||
private final int width, height;
|
||||
private final boolean readOnly;
|
||||
|
||||
@ -38,15 +36,14 @@ public class MapTileData {
|
||||
|
||||
if(mapping != null && !readOnly){
|
||||
for(int i = 0; i < width * height; i ++){
|
||||
read();
|
||||
TileDataMarker marker = new TileDataMarker();
|
||||
read(marker);
|
||||
buffer.position(i * TILE_SIZE);
|
||||
write();
|
||||
write(marker);
|
||||
}
|
||||
buffer.position(0);
|
||||
this.map = null;
|
||||
}
|
||||
|
||||
read();
|
||||
}
|
||||
|
||||
public byte[] toArray(){
|
||||
@ -61,14 +58,16 @@ public class MapTileData {
|
||||
return height;
|
||||
}
|
||||
|
||||
public TileDataMarker getMarker() {
|
||||
return tile;
|
||||
/**Write a byte to a specific position.*/
|
||||
public void write(int x, int y, DataPosition position, byte data){
|
||||
buffer.position((x + width * y) * TILE_SIZE + position.ordinal());
|
||||
buffer.put(data);
|
||||
}
|
||||
|
||||
/**Reads and returns the next tile data.*/
|
||||
public TileDataMarker read(){
|
||||
tile.read(buffer);
|
||||
return tile;
|
||||
/**Gets a byte at a specific position.*/
|
||||
public byte read(int x, int y, DataPosition position){
|
||||
buffer.position((x + width * y) * TILE_SIZE + position.ordinal());
|
||||
return buffer.get();
|
||||
}
|
||||
|
||||
/**Reads and returns the next tile data.*/
|
||||
@ -77,35 +76,9 @@ public class MapTileData {
|
||||
return marker;
|
||||
}
|
||||
|
||||
/**Reads and returns the next tile data.*/
|
||||
public TileDataMarker readAt(int x, int y){
|
||||
position(x, y);
|
||||
tile.read(buffer);
|
||||
return tile;
|
||||
}
|
||||
|
||||
/**Reads and returns the next tile data.*/
|
||||
public TileDataMarker readAt(int x, int y, TileDataMarker marker){
|
||||
position(x, y);
|
||||
marker.read(buffer);
|
||||
return marker;
|
||||
}
|
||||
|
||||
/**Reads and returns a specific byte position.*/
|
||||
public byte readAt(int x, int y, int offset){
|
||||
buffer.position((x + width * y) * TILE_SIZE + offset);
|
||||
return buffer.get();
|
||||
}
|
||||
|
||||
/**Writes and returns the next tile data.*/
|
||||
public void write(){
|
||||
tile.write(buffer);
|
||||
}
|
||||
|
||||
/**Writes tile data at a specified position.*/
|
||||
public void write(int x, int y, TileDataMarker writer){
|
||||
position(x, y);
|
||||
writer.write(buffer);
|
||||
/**Writes this tile data marker.*/
|
||||
public void write(TileDataMarker marker){
|
||||
marker.write(buffer);
|
||||
}
|
||||
|
||||
/**Sets read position to the specified coordinates*/
|
||||
@ -113,6 +86,14 @@ public class MapTileData {
|
||||
buffer.position((x + width * y) * TILE_SIZE);
|
||||
}
|
||||
|
||||
public TileDataMarker newDataMarker(){
|
||||
return new TileDataMarker();
|
||||
}
|
||||
|
||||
public enum DataPosition{
|
||||
floor, wall, link, rotationTeam
|
||||
}
|
||||
|
||||
public class TileDataMarker {
|
||||
public byte floor, wall;
|
||||
public byte link;
|
||||
@ -140,11 +121,5 @@ public class MapTileData {
|
||||
buffer.put(link);
|
||||
buffer.put(Bits.packByte(rotation, team));
|
||||
}
|
||||
|
||||
public void writeWallLink(){
|
||||
buffer.position(buffer.position() + 1);
|
||||
buffer.put(wall);
|
||||
buffer.put(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
public class EditLog {
|
||||
@ -21,6 +20,6 @@ public class EditLog {
|
||||
}
|
||||
|
||||
public enum EditAction {
|
||||
PLACE, BREAK;
|
||||
}
|
||||
PLACE, BREAK
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,9 @@ public class ItemImage extends Stack {
|
||||
private Image image;
|
||||
|
||||
public ItemImage(TextureRegion region, Supplier<String> text, Color color) {
|
||||
Table t = new Table();
|
||||
t.left().bottom();
|
||||
Table t = new Table().left().bottom();
|
||||
|
||||
t.label(text).color(Color.DARK_GRAY);
|
||||
t.row();
|
||||
t.label(text).padTop(-22);
|
||||
t.label(text).get().setFontScale(0.5f);
|
||||
|
||||
image = new Image(region);
|
||||
image.setColor(color);
|
||||
|
@ -212,7 +212,7 @@ public class FileChooser extends FloatingDialog {
|
||||
files.row();
|
||||
}
|
||||
|
||||
ButtonGroup<TextButton> group = new ButtonGroup<TextButton>();
|
||||
ButtonGroup<TextButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
|
||||
for(FileHandle file : names){
|
||||
@ -278,7 +278,7 @@ public class FileChooser extends FloatingDialog {
|
||||
}
|
||||
|
||||
public class FileHistory{
|
||||
private Array<FileHandle> history = new Array<FileHandle>();
|
||||
private Array<FileHandle> history = new Array<>();
|
||||
private int index;
|
||||
|
||||
public FileHistory(){
|
||||
|
@ -1,9 +1,7 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.ucore.scene.ui.Label;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class BlockInventoryFragment implements Fragment {
|
||||
int row = 0;
|
||||
|
||||
table.margin(3f);
|
||||
table.defaults().size(16 * 2).space(6f);
|
||||
table.defaults().size(16*2).space(6f);
|
||||
|
||||
if(tile.block().hasItems) {
|
||||
int[] items = tile.entity.items.items;
|
||||
@ -97,13 +97,6 @@ public class BlockInventoryFragment implements Fragment {
|
||||
|
||||
container.add(i);
|
||||
|
||||
Table t = new Table();
|
||||
t.left().bottom();
|
||||
|
||||
t.label(() -> round(items[f])).color(Color.DARK_GRAY);
|
||||
t.row();
|
||||
t.label(() -> round(items[f])).padTop(-22);
|
||||
|
||||
BooleanProvider canPick = () -> player.inventory.canAcceptItem(item);
|
||||
|
||||
HandCursorListener l = new HandCursorListener();
|
||||
|
@ -40,7 +40,7 @@ public class ChatFragment extends Table implements Fragment{
|
||||
private float textWidth = Unit.dp.scl(600);
|
||||
private Color shadowColor = new Color(0, 0, 0, 0.4f);
|
||||
private float textspacing = Unit.dp.scl(10);
|
||||
private Array<String> history = new Array<String>();
|
||||
private Array<String> history = new Array<>();
|
||||
private int historyPos = 0;
|
||||
private int scrollPos = 0;
|
||||
|
||||
|
@ -3,5 +3,5 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
|
||||
public interface Fragment{
|
||||
public void build(Group parent);
|
||||
void build(Group parent);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
|
||||
/**Fragment for displaying overlays such as block inventories. One is created for each input handler.*/
|
||||
public class OverlayFragment implements Fragment{
|
||||
public final BlockInventoryFragment inv;
|
||||
public final BlockConfigFragment config;
|
||||
|
@ -1,5 +1,5 @@
|
||||
package io.anuke.mindustry.world;
|
||||
|
||||
public enum BlockGroup {
|
||||
none, walls, turrets, transportation, power, liquids, drills;
|
||||
none, walls, turrets, transportation, power, liquids, drills
|
||||
}
|
||||
|
@ -21,10 +21,11 @@ public class WorldGenerator {
|
||||
IntArray multiblocks = new IntArray();
|
||||
|
||||
data.position(0, 0);
|
||||
TileDataMarker marker = data.newDataMarker();
|
||||
|
||||
for(int y = 0; y < data.height(); y ++){
|
||||
for(int x = 0; x < data.width(); x ++){
|
||||
TileDataMarker tile = data.read();
|
||||
TileDataMarker tile = data.read(marker);
|
||||
tiles[x][y] = new Tile(x, y, tile.floor, tile.wall == Blocks.blockpart.id ? 0 : tile.wall, tile.rotation, tile.team);
|
||||
|
||||
Team team = Team.values()[tile.team];
|
||||
|
@ -67,14 +67,10 @@ public class BlockPart extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptPower(Tile tile, Tile from, float amount){
|
||||
Block block = linked(tile);
|
||||
if(block.hasPower){
|
||||
return block.acceptPower(tile.getLinked(), from, amount);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public boolean acceptPower(Tile tile, Tile from, float amount) {
|
||||
Block block = linked(tile);
|
||||
return block.hasPower && block.acceptPower(tile.getLinked(), from, amount);
|
||||
}
|
||||
|
||||
private Block linked(Tile tile){
|
||||
return tile.getLinked().block();
|
||||
|
@ -36,13 +36,8 @@ public class Router extends Block{
|
||||
|
||||
@Override
|
||||
public boolean canDump(Tile tile, Tile to, Item item) {
|
||||
if(to.block() instanceof Router){
|
||||
return ((float)to.target().entity.items.totalItems() / to.target().block().itemCapacity) <
|
||||
((float)tile.entity.items.totalItems() / to.target().block().itemCapacity);
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !(to.block() instanceof Router) || ((float) to.target().entity.items.totalItems() / to.target().block().itemCapacity) < ((float) tile.entity.items.totalItems() / to.target().block().itemCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
|
@ -23,6 +23,7 @@ public class LiquidBurnerGenerator extends PowerGenerator {
|
||||
super(name);
|
||||
liquidCapacity = 30f;
|
||||
hasLiquids = true;
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,6 +6,7 @@ public class LiquidHeatGenerator extends LiquidBurnerGenerator {
|
||||
|
||||
public LiquidHeatGenerator(String name) {
|
||||
super(name);
|
||||
hasItems = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,12 +45,8 @@ public class PowerGenerator extends PowerBlock {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldDistribute(Tile tile, Tile other){
|
||||
if(other.block() instanceof PowerGenerator){
|
||||
return other.entity.power.amount / other.block().powerCapacity <
|
||||
tile.entity.power.amount / powerCapacity;
|
||||
}
|
||||
return true;
|
||||
protected boolean shouldDistribute(Tile tile, Tile other) {
|
||||
return !(other.block() instanceof PowerGenerator) || other.entity.power.amount / other.block().powerCapacity < tile.entity.power.amount / powerCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,15 +35,11 @@ public class Vault extends StorageBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDump(Tile tile, Tile to, Item item){
|
||||
public boolean canDump(Tile tile, Tile to, Item item) {
|
||||
to = to.target();
|
||||
if(!(to.block() instanceof StorageBlock)) return false;
|
||||
if (!(to.block() instanceof StorageBlock)) return false;
|
||||
|
||||
if(to.block() instanceof Vault){
|
||||
return (float)to.entity.items.totalItems() / to.block().itemCapacity <
|
||||
(float)tile.entity.items.totalItems() / itemCapacity;
|
||||
}
|
||||
return !(to.block() instanceof Vault) || (float) to.entity.items.totalItems() / to.block().itemCapacity < (float) tile.entity.items.totalItems() / itemCapacity;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user