Bugfixes, cleanup, optimization
This commit is contained in:
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;
|
public static float fontScale;
|
||||||
//camera zoom displayed on startup
|
//camera zoom displayed on startup
|
||||||
public static int baseCameraScale;
|
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
|
//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 debug = false;
|
||||||
public static boolean debugNet = true;
|
|
||||||
public static boolean console = false;
|
public static boolean console = false;
|
||||||
//whether the player can clip through walls
|
//whether the player can clip through walls
|
||||||
public static boolean noclip = false;
|
public static boolean noclip = false;
|
||||||
@@ -83,8 +80,6 @@ public class Vars{
|
|||||||
public static float baseControllerSpeed = 11f;
|
public static float baseControllerSpeed = 11f;
|
||||||
|
|
||||||
public static final int saveSlots = 64;
|
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
|
//only if smoothCamera
|
||||||
public static boolean snapCamera = true;
|
public static boolean snapCamera = true;
|
||||||
@@ -172,6 +167,5 @@ public class Vars{
|
|||||||
|
|
||||||
fontScale = Math.max(Unit.dp.scl(1f)/2f, 0.5f);
|
fontScale = Math.max(Unit.dp.scl(1f)/2f, 0.5f);
|
||||||
baseCameraScale = Math.round(Unit.dp.scl(4));
|
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.math.GridPoint2;
|
||||||
import com.badlogic.gdx.utils.IntArray;
|
import com.badlogic.gdx.utils.IntArray;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
|
import com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator;
|
||||||
import com.badlogic.gdx.utils.Queue;
|
import com.badlogic.gdx.utils.Queue;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||||
@@ -39,7 +40,9 @@ public class Pathfinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
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);
|
updateFrontier(team.team, maxUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,6 +175,8 @@ public class Control extends Module{
|
|||||||
|
|
||||||
Timers.runTask(30f, () -> state.set(State.menu));
|
Timers.runTask(30f, () -> state.set(State.menu));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Events.on(WorldLoadEvent.class, () -> Gdx.app.postRunnable(() -> Events.fire(WorldLoadGraphicsEvent.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(int index){
|
public void addPlayer(int index){
|
||||||
@@ -259,13 +261,13 @@ public class Control extends Module{
|
|||||||
ui.loadfrag.show();
|
ui.loadfrag.show();
|
||||||
saves.resetSave();
|
saves.resetSave();
|
||||||
|
|
||||||
Timers.runTask(10, () -> {
|
threads.run(() -> {
|
||||||
logic.reset();
|
logic.reset();
|
||||||
world.loadMap(map);
|
world.loadMap(map);
|
||||||
logic.play();
|
logic.play();
|
||||||
});
|
|
||||||
|
|
||||||
Timers.runTask(18, () -> ui.loadfrag.hide());
|
Gdx.app.postRunnable(ui.loadfrag::hide);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHighScore(){
|
public boolean isHighScore(){
|
||||||
|
|||||||
@@ -99,10 +99,12 @@ public class Renderer extends RendererModule{
|
|||||||
|
|
||||||
Cursors.cursorScaling = 3;
|
Cursors.cursorScaling = 3;
|
||||||
Cursors.outlineColor = Color.valueOf("444444");
|
Cursors.outlineColor = Color.valueOf("444444");
|
||||||
|
|
||||||
Cursors.arrow = Cursors.loadCursor("cursor");
|
Cursors.arrow = Cursors.loadCursor("cursor");
|
||||||
Cursors.hand = Cursors.loadCursor("hand");
|
Cursors.hand = Cursors.loadCursor("hand");
|
||||||
Cursors.ibeam = Cursors.loadCursor("ibar");
|
Cursors.ibeam = Cursors.loadCursor("ibar");
|
||||||
Cursors.tool1 = Cursors.loadCursor("drill");
|
Cursors.loadCustom("drill");
|
||||||
|
Cursors.loadCustom("unload");
|
||||||
|
|
||||||
clearColor = Hue.lightness(0.4f);
|
clearColor = Hue.lightness(0.4f);
|
||||||
clearColor.a = 1f;
|
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(){
|
public int getFPS(){
|
||||||
return (int)(60/delta);
|
return (int)(60/delta);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package io.anuke.mindustry.core;
|
package io.anuke.mindustry.core;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.math.GridPoint2;
|
import com.badlogic.gdx.math.GridPoint2;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.utils.Array;
|
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.Mathf;
|
||||||
import io.anuke.ucore.util.Tmp;
|
import io.anuke.ucore.util.Tmp;
|
||||||
|
|
||||||
|
import static io.anuke.mindustry.Vars.threads;
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
public class World extends Module{
|
public class World extends Module{
|
||||||
@@ -192,7 +192,7 @@ public class World extends Module{
|
|||||||
|
|
||||||
public void notifyChanged(Tile tile){
|
public void notifyChanged(Tile tile){
|
||||||
if(!generating){
|
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) {
|
public void undo(MapEditor editor) {
|
||||||
for(int i = operations.size - 1; i >= 0; i --){
|
for(int i = operations.size - 1; i >= 0; i --){
|
||||||
TileOperation op = operations.get(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);
|
editor.renderer().updatePoint(op.x, op.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void redo(MapEditor editor) {
|
public void redo(MapEditor editor) {
|
||||||
for(TileOperation op : operations){
|
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);
|
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.IntArray;
|
||||||
import com.badlogic.gdx.utils.IntSet;
|
import com.badlogic.gdx.utils.IntSet;
|
||||||
|
import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||||
|
import io.anuke.ucore.util.Bits;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.ui;
|
import static io.anuke.mindustry.Vars.ui;
|
||||||
|
|
||||||
public enum EditorTool{
|
public enum EditorTool{
|
||||||
pick{
|
pick{
|
||||||
public void touched(MapEditor editor, int x, int y){
|
public void touched(MapEditor editor, int x, int y){
|
||||||
TileDataMarker writer = editor.getMap().readAt(x, y);
|
byte bf = editor.getMap().read(x, y, DataPosition.floor);
|
||||||
Block block = Block.getByID(writer.wall == 0 ? writer.floor : writer.wall);
|
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);
|
editor.setDrawBlock(block);
|
||||||
ui.editor.updateSelectedBlock();
|
ui.editor.updateSelectedBlock();
|
||||||
}
|
}
|
||||||
@@ -31,7 +43,6 @@ public enum EditorTool{
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
fill{
|
fill{
|
||||||
{
|
{
|
||||||
@@ -39,11 +50,21 @@ public enum EditorTool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void touched(MapEditor editor, int x, int y){
|
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;
|
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 width = editor.getMap().width();
|
||||||
int height = editor.getMap().height();
|
int height = editor.getMap().height();
|
||||||
@@ -58,21 +79,28 @@ public enum EditorTool{
|
|||||||
int py = pos / width;
|
int py = pos / width;
|
||||||
set.add(pos);
|
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 ? nbf : nbw) == dest){
|
||||||
if(floor)
|
TileDataMarker prev = editor.getPrev(px, py, false);
|
||||||
writer.floor = (byte)editor.getDrawBlock().id;
|
|
||||||
else
|
|
||||||
writer.wall = (byte)editor.getDrawBlock().id;
|
|
||||||
|
|
||||||
editor.write(px, py, writer, false);
|
if(floor) {
|
||||||
editor.renderer().updatePoint(px, py);
|
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(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(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(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));
|
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.editor.DrawOperation.TileOperation;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.io.MapTileData;
|
import io.anuke.mindustry.io.MapTileData;
|
||||||
|
import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||||
@@ -18,7 +19,6 @@ public class MapEditor{
|
|||||||
|
|
||||||
private MapTileData map;
|
private MapTileData map;
|
||||||
private ObjectMap<String, String> tags = new ObjectMap<>();
|
private ObjectMap<String, String> tags = new ObjectMap<>();
|
||||||
private TileDataMarker multiWriter;
|
|
||||||
private MapRenderer renderer = new MapRenderer(this);
|
private MapRenderer renderer = new MapRenderer(this);
|
||||||
|
|
||||||
private int brushSize = 1;
|
private int brushSize = 1;
|
||||||
@@ -44,7 +44,6 @@ public class MapEditor{
|
|||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
|
|
||||||
drawBlock = Blocks.stone;
|
drawBlock = Blocks.stone;
|
||||||
multiWriter = map.new TileDataMarker();
|
|
||||||
renderer.resize(map.width(), map.height());
|
renderer.resize(map.width(), map.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,94 +84,84 @@ public class MapEditor{
|
|||||||
return;
|
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;
|
boolean isfloor = drawBlock instanceof Floor;
|
||||||
if(isfloor){
|
|
||||||
writer.floor = (byte)drawBlock.id;
|
|
||||||
}else{
|
|
||||||
writer.wall = (byte)drawBlock.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(drawBlock.hasEntity()){
|
if(drawBlock.isMultiblock()) {
|
||||||
writer.team = (byte)drawTeam.ordinal();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(drawBlock.rotate){
|
int offsetx = -(drawBlock.size - 1) / 2;
|
||||||
writer.rotation = (byte)rotation;
|
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;
|
if (Mathf.inBounds(worldx, worldy, map.width(), map.height())) {
|
||||||
int offsety = -(drawBlock.size-1)/2;
|
TileDataMarker prev = getPrev(worldx, worldy, false);
|
||||||
|
|
||||||
for(int dx = 0; dx < drawBlock.size; dx ++){
|
if(i == 1) {
|
||||||
for(int dy = 0; dy < drawBlock.size; dy ++){
|
map.write(worldx, worldy, DataPosition.wall, partID);
|
||||||
int worldx = dx + offsetx + x;
|
map.write(worldx, worldy, DataPosition.rotationTeam, rotationTeam);
|
||||||
int worldy = dy + offsety + y;
|
map.write(worldx, worldy, DataPosition.link, Bits.packByte((byte) (dx + offsetx + 8), (byte) (dy + offsety + 8)));
|
||||||
if(!(worldx == x && worldy == y)){
|
}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())){
|
if (link != 0) {
|
||||||
map.readAt(worldx, worldy);
|
removeLinked(worldx - (Bits.getLeftByte(link) - 8), worldy - (Bits.getRightByte(link) - 8));
|
||||||
byte floor = writer.floor;
|
}else if(Block.getByID(block).isMultiblock()){
|
||||||
|
removeLinked(worldx, worldy);
|
||||||
if(writer.link != 0){
|
}
|
||||||
removeLinked(worldx - (Bits.getLeftByte(writer.link) - 8), worldy - (Bits.getRightByte(writer.link) - 8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.wall = (byte)Blocks.blockpart.id;
|
onWrite(worldx, worldy, prev);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map.readAt(x, y);
|
TileDataMarker prev = getPrev(x, y, false);
|
||||||
if(drawBlock instanceof Floor){
|
|
||||||
writer.floor = (byte)drawBlock.id;
|
|
||||||
}else{
|
|
||||||
writer.wall = (byte)drawBlock.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.team = (byte)drawTeam.ordinal();
|
map.write(x, y, DataPosition.wall, writeID);
|
||||||
writer.rotation = 0;
|
map.write(x, y, DataPosition.link, (byte)0);
|
||||||
writer.link = 0;
|
map.write(x, y, DataPosition.rotationTeam, rotationTeam);
|
||||||
write(x, y, writer, false);
|
|
||||||
|
|
||||||
renderer.updatePoint(x, y);
|
onWrite(x, y, prev);
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
for (int rx = -brushSize; rx <= brushSize; rx++) {
|
for (int rx = -brushSize; rx <= brushSize; rx++) {
|
||||||
for (int ry = -brushSize; ry <= brushSize; ry++) {
|
for (int ry = -brushSize; ry <= brushSize; ry++) {
|
||||||
if (Mathf.dst(rx, ry) <= brushSize - 0.5f) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte b1 = map.readAt(x + rx, y + ry, 1);
|
TileDataMarker prev = getPrev(wx, wy, true);
|
||||||
byte b2 = map.readAt(x + rx, y + ry, 2);
|
|
||||||
byte b3 = map.readAt(x + rx, y + ry, 3);
|
|
||||||
|
|
||||||
if(!isfloor) {
|
if(!isfloor) {
|
||||||
byte link = map.readAt(x + rx, y + ry, 2);
|
byte link = map.read(wx, wy, DataPosition.link);
|
||||||
|
|
||||||
if (link != 0) {
|
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;
|
if(isfloor){
|
||||||
writer.link = b2;
|
map.write(wx, wy, DataPosition.floor, writeID);
|
||||||
writer.rotation = Bits.getLeftByte(b3);
|
}else{
|
||||||
writer.team = Bits.getRightByte(b3);
|
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);
|
onWrite(x + rx, y + ry, prev);
|
||||||
renderer.updatePoint(x + rx, y + ry);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,8 +169,7 @@ public class MapEditor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void removeLinked(int x, int y){
|
private void removeLinked(int x, int y){
|
||||||
TileDataMarker marker = map.readAt(x, y, multiWriter);
|
Block block = Block.getByID(map.read(x, y, DataPosition.wall));
|
||||||
Block block = Block.getByID(marker.wall);
|
|
||||||
|
|
||||||
int offsetx = -(block.size-1)/2;
|
int offsetx = -(block.size-1)/2;
|
||||||
int offsety = -(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 ++){
|
for(int dy = 0; dy < block.size; dy ++){
|
||||||
int worldx = x + dx + offsetx, worldy = y + dy + offsety;
|
int worldx = x + dx + offsetx, worldy = y + dy + offsety;
|
||||||
if(Mathf.inBounds(worldx, worldy, map.width(), map.height())){
|
if(Mathf.inBounds(worldx, worldy, map.width(), map.height())){
|
||||||
map.readAt(worldx, worldy, marker);
|
TileDataMarker prev = getPrev(worldx, worldy, false);
|
||||||
marker.link = 0;
|
|
||||||
marker.wall = 0;
|
|
||||||
marker.rotation = 0;
|
|
||||||
marker.team = 0;
|
|
||||||
write(worldx, worldy, marker, false);
|
|
||||||
|
|
||||||
if(worldx == x && worldy == y){
|
map.write(worldx, worldy, DataPosition.link, (byte)0);
|
||||||
renderer.updatePoint(worldx, worldy);
|
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 checkDupes(int x, int y){
|
||||||
boolean dupe = checkDupes && Vars.ui.editor.getView().checkForDuplicates((short) x, (short) y);
|
return Vars.ui.editor.getView().checkForDuplicates((short) x, (short) y);
|
||||||
TileDataMarker prev = null;
|
}
|
||||||
|
|
||||||
if(!dupe) {
|
void onWrite(int x, int y, TileDataMarker previous){
|
||||||
prev = map.new TileDataMarker();
|
if(previous == null){
|
||||||
map.position(x, y);
|
renderer.updatePoint(x, y);
|
||||||
map.read(prev);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
map.write(x, y, writer);
|
TileDataMarker current = map.new TileDataMarker();
|
||||||
|
map.position(x, y);
|
||||||
|
map.read(current);
|
||||||
|
|
||||||
if(!dupe) {
|
Vars.ui.editor.getView().addTileOp(new TileOperation((short) x, (short) y, previous, current));
|
||||||
TileDataMarker current = map.new TileDataMarker();
|
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.position(x, y);
|
||||||
map.read(current);
|
map.read(marker);
|
||||||
|
return marker;
|
||||||
Vars.ui.editor.getView().addTileOp(new TileOperation((short) x, (short) y, prev, current));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ public class MapFilter{
|
|||||||
OrderedMap<String, GenPref> prefs = new OrderedMap<>();
|
OrderedMap<String, GenPref> prefs = new OrderedMap<>();
|
||||||
|
|
||||||
for(int i = 0; i < objects.length; i ++){
|
for(int i = 0; i < objects.length; i ++){
|
||||||
GenPref pref = (GenPref)objects[i];
|
GenPref pref = objects[i];
|
||||||
prefs.put(pref.name, pref);
|
prefs.put(pref.name, pref);
|
||||||
}
|
}
|
||||||
return prefs;
|
return prefs;
|
||||||
|
|||||||
@@ -15,13 +15,14 @@ import com.badlogic.gdx.utils.IntSet;
|
|||||||
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import io.anuke.mindustry.game.Team;
|
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.mindustry.world.Block;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.graphics.IndexedRenderer;
|
import io.anuke.ucore.graphics.IndexedRenderer;
|
||||||
|
import io.anuke.ucore.util.Bits;
|
||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
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 x = 0; x < chunks.length; x ++){
|
||||||
for(int y = 0; y < chunks[0].length; y ++){
|
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;
|
this.width = width;
|
||||||
@@ -161,41 +162,47 @@ public class MapRenderer implements Disposable{
|
|||||||
private void render(int wx, int wy){
|
private void render(int wx, int wy){
|
||||||
int x = wx/chunksize, y = wy/chunksize;
|
int x = wx/chunksize, y = wy/chunksize;
|
||||||
IndexedRenderer mesh = chunks[x][y];
|
IndexedRenderer mesh = chunks[x][y];
|
||||||
TileDataMarker data = editor.getMap().readAt(wx, wy);
|
//TileDataMarker data = editor.getMap().readAt(wx, wy);
|
||||||
Block floor = Block.getByID(data.floor);
|
byte bf = editor.getMap().read(wx, wy, DataPosition.floor);
|
||||||
Block wall = Block.getByID(data.wall);
|
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 offsetx = -(wall.size-1)/2;
|
||||||
int offsety = -(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){
|
if(bw != 0) {
|
||||||
region = regions.get("clear");
|
region = blockIcons.get(wall, regions.get("clear"));
|
||||||
}
|
|
||||||
|
|
||||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize, region, wx * tilesize, wy * tilesize, 8, 8);
|
if (wall.rotate) {
|
||||||
|
mesh.draw((wx % chunksize) + (wy % chunksize) * chunksize, region,
|
||||||
region = blockIcons.get(wall, regions.get("clear"));
|
wx * tilesize + offsetx * tilesize, wy * tilesize + offsety * tilesize,
|
||||||
|
region.getRegionWidth(), region.getRegionHeight(), rotation * 90 - 90);
|
||||||
if(wall.rotate){
|
} else {
|
||||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
|
mesh.draw((wx % chunksize) + (wy % chunksize) * chunksize, region,
|
||||||
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
|
wx * tilesize + offsetx * tilesize, wy * tilesize + offsety * tilesize,
|
||||||
region.getRegionWidth(), region.getRegionHeight(), data.rotation*90 - 90);
|
region.getRegionWidth(), region.getRegionHeight());
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize + chunksize*chunksize, region,
|
region = blockIcons.get(floor, regions.get("clear"));
|
||||||
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
|
|
||||||
region.getRegionWidth(), region.getRegionHeight());
|
mesh.draw((wx % chunksize) + (wy % chunksize)*chunksize, region, wx * tilesize, wy * tilesize, 8, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wall.update || wall.destructible) {
|
if(wall.update || wall.destructible) {
|
||||||
mesh.setColor(Team.values()[data.team].color);
|
mesh.setColor(team.color);
|
||||||
region = regions.get("block-border");
|
region = regions.get("block-border");
|
||||||
}else{
|
}else{
|
||||||
region = regions.get("clear");
|
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,
|
wx * tilesize + offsetx*tilesize, wy * tilesize + offsety * tilesize,
|
||||||
region.getRegionWidth(), region.getRegionHeight());
|
region.getRegionWidth(), region.getRegionHeight());
|
||||||
mesh.setColor(Color.WHITE);
|
mesh.setColor(Color.WHITE);
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ public class MapView extends Element implements GestureListener{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mousex = x;
|
||||||
|
mousey = y;
|
||||||
|
|
||||||
op = new DrawOperation(editor.getMap());
|
op = new DrawOperation(editor.getMap());
|
||||||
|
|
||||||
updated = false;
|
updated = false;
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ public interface BlockBuilder {
|
|||||||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(tile.worldx(), tile.worldy()), 0.4f);
|
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(tile.worldx(), tile.worldy()), 0.4f);
|
||||||
|
|
||||||
if(unit.inventory.canAcceptItem(item) &&
|
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,
|
ItemTransfer.create(item,
|
||||||
tile.worldx() + Mathf.range(tilesize/2f),
|
tile.worldx() + Mathf.range(tilesize/2f),
|
||||||
tile.worldy() + 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);
|
rotation = Mathf.slerpDelta(rotation, velocity.angle(), velocity.len()/10f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//update shooting if not building and there's ammo left
|
//update shooting if not building, not mining and there's ammo left
|
||||||
if(!isBuilding() && inventory.hasAmmo()){
|
if(!isBuilding() && inventory.hasAmmo() && getMineTile() == null){
|
||||||
|
|
||||||
//autofire: mobile only!
|
//autofire: mobile only!
|
||||||
if(mobile) {
|
if(mobile) {
|
||||||
|
|||||||
@@ -19,13 +19,11 @@ public class Predict {
|
|||||||
* @return the intercept location*/
|
* @return the intercept location*/
|
||||||
public static Vector2 intercept(float srcx, float srcy, float dstx, float dsty, float dstvx, float dstvy, float v) {
|
public static Vector2 intercept(float srcx, float srcy, float dstx, float dsty, float dstvx, float dstvy, float v) {
|
||||||
float tx = dstx - srcx,
|
float tx = dstx - srcx,
|
||||||
ty = dsty - srcy,
|
ty = dsty - srcy;
|
||||||
tvx = dstvx,
|
|
||||||
tvy = dstvy;
|
|
||||||
|
|
||||||
// Get quadratic equation components
|
// Get quadratic equation components
|
||||||
float a = tvx*tvx + tvy*tvy - v*v;
|
float a = dstvx * dstvx + dstvy * dstvy - v*v;
|
||||||
float b = 2 * (tvx * tx + tvy * ty);
|
float b = 2 * (dstvx * tx + dstvy * ty);
|
||||||
float c = tx*tx + ty*ty;
|
float c = tx*tx + ty*ty;
|
||||||
|
|
||||||
// Solve quadratic
|
// Solve quadratic
|
||||||
|
|||||||
@@ -132,6 +132,10 @@ public class UnitInventory {
|
|||||||
totalAmmo = 0;
|
totalAmmo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearItem(){
|
||||||
|
item = null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasItem(){
|
public boolean hasItem(){
|
||||||
return item != null;
|
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
|
* @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
|
* @return whether the target is invalid
|
||||||
*/
|
*/
|
||||||
public static boolean invalidateTarget(Targetable target, Team team, float x, float y, float range){
|
public static boolean invalidateTarget(Targetable target, Team team, float x, float y, float range) {
|
||||||
if(target == null){
|
if (target == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(range != Float.MAX_VALUE && target.distanceTo(x, y) > range){
|
return (!(range != Float.MAX_VALUE) || !(target.distanceTo(x, y) > range)) && (target.getTeam() == team || !target.isValid());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return target.getTeam() == team || !target.isValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**See {@link #invalidateTarget(Targetable, Team, float, float, float)}*/
|
/**See {@link #invalidateTarget(Targetable, Team, float, float, float)}*/
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public abstract class UnitType {
|
|||||||
public abstract void behavior(BaseUnit unit);
|
public abstract void behavior(BaseUnit unit);
|
||||||
|
|
||||||
public void updateTargeting(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 instanceof TileEntity && ((TileEntity) unit.target).tile.entity == null)){
|
||||||
unit.target = null;
|
unit.target = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,19 @@ public class EventType {
|
|||||||
void handle();
|
void handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**This event is called from the logic thread.
|
||||||
|
* DO NOT INITIALIZE GRAPHICS HERE.*/
|
||||||
public interface WorldLoadEvent extends Event{
|
public interface WorldLoadEvent extends Event{
|
||||||
void handle();
|
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{
|
public interface TileChangeEvent extends Event{
|
||||||
void handle(Tile tile);
|
void handle(Tile tile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class BlockRenderer{
|
|||||||
|
|
||||||
private FloorRenderer floorRenderer;
|
private FloorRenderer floorRenderer;
|
||||||
|
|
||||||
private Array<BlockRequest> requests = new Array<BlockRequest>(initialRequests);
|
private Array<BlockRequest> requests = new Array<>(initialRequests);
|
||||||
private Layer lastLayer;
|
private Layer lastLayer;
|
||||||
private int requestidx = 0;
|
private int requestidx = 0;
|
||||||
private int iterateidx = 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;
|
||||||
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
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.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
@@ -35,7 +35,7 @@ public class FloorRenderer {
|
|||||||
private IntArray drawnLayers = new IntArray();
|
private IntArray drawnLayers = new IntArray();
|
||||||
|
|
||||||
public FloorRenderer(){
|
public FloorRenderer(){
|
||||||
Events.on(WorldLoadEvent.class, this::clearTiles);
|
Events.on(WorldLoadGraphicsEvent.class, this::clearTiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawFloor(){
|
public void drawFloor(){
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ public enum Layer{
|
|||||||
/**Power lasers.*/
|
/**Power lasers.*/
|
||||||
power,
|
power,
|
||||||
/**Extra lasers, like healing turrets.*/
|
/**Extra lasers, like healing turrets.*/
|
||||||
laser;
|
laser
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.anuke.mindustry.graphics;
|
package io.anuke.mindustry.graphics;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
@@ -8,7 +9,7 @@ import com.badlogic.gdx.math.Rectangle;
|
|||||||
import com.badlogic.gdx.utils.Disposable;
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
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.ColorMapper;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Core;
|
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.graphics.Pixmaps;
|
||||||
import io.anuke.ucore.util.Mathf;
|
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{
|
public class MinimapRenderer implements Disposable{
|
||||||
private static final int baseSize = 16;
|
private static final int baseSize = 16;
|
||||||
@@ -28,12 +30,13 @@ public class MinimapRenderer implements Disposable{
|
|||||||
private int zoom = 4;
|
private int zoom = 4;
|
||||||
|
|
||||||
public MinimapRenderer(){
|
public MinimapRenderer(){
|
||||||
Events.on(WorldLoadEvent.class, () -> {
|
Events.on(WorldLoadGraphicsEvent.class, () -> {
|
||||||
reset();
|
reset();
|
||||||
updateAll();
|
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(){
|
public Texture getTexture(){
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import com.badlogic.gdx.utils.ObjectSet.ObjectSetIterator;
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
import io.anuke.mindustry.content.blocks.Blocks;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
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.Inputs;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.core.Timers;
|
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 io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
@@ -93,22 +98,45 @@ public class OverlayRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target.entity != null) {
|
if (target.entity != null) {
|
||||||
int bot = 0, top = 0;
|
int[] values = {0, 0};
|
||||||
for (BlockBar bar : target.block().bars.list()) {
|
Tile t = target;
|
||||||
float offset = Mathf.sign(bar.top) * (target.block().size / 2f * tilesize + 3f + 4f * ((bar.top ? top : bot))) +
|
boolean[] doDraw = {false};
|
||||||
(bar.top ? -1f : 0f);
|
|
||||||
|
|
||||||
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)
|
if(doDraw[0]){
|
||||||
top++;
|
drawBar(bar.type.color, t.drawx(), t.drawy() + offset, value);
|
||||||
else
|
}
|
||||||
bot++;
|
|
||||||
|
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);
|
target.block().drawSelect(target);
|
||||||
@@ -135,7 +163,9 @@ public class OverlayRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if((!debug || showUI) && Settings.getBool("healthbars")){
|
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()){
|
for(Unit e : unitGroups[ally.team.ordinal()].all()){
|
||||||
drawStats(e);
|
drawStats(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import io.anuke.ucore.graphics.Lines;
|
|||||||
import io.anuke.ucore.scene.Group;
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.builders.imagebutton;
|
import io.anuke.ucore.scene.builders.imagebutton;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
import io.anuke.ucore.util.Log;
|
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
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.net.NetEvents;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.ucore.core.Graphics;
|
||||||
import io.anuke.ucore.core.Inputs;
|
import io.anuke.ucore.core.Inputs;
|
||||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||||
import io.anuke.ucore.core.KeyBinds;
|
import io.anuke.ucore.core.KeyBinds;
|
||||||
@@ -32,6 +33,8 @@ public class DesktopInput extends InputHandler{
|
|||||||
private float controlx, controly;
|
private float controlx, controly;
|
||||||
private boolean controlling;
|
private boolean controlling;
|
||||||
private final String section;
|
private final String section;
|
||||||
|
|
||||||
|
/**Current cursor type.*/
|
||||||
private CursorType cursorType = normal;
|
private CursorType cursorType = normal;
|
||||||
|
|
||||||
/**Position where the player started dragging a line.*/
|
/**Position where the player started dragging a line.*/
|
||||||
@@ -98,10 +101,6 @@ public class DesktopInput extends InputHandler{
|
|||||||
|
|
||||||
Draw.color(Palette.remove);
|
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 x = dresult.x; x <= dresult.x2; x ++){
|
||||||
for(int y = dresult.y; y <= dresult.y2; y ++){
|
for(int y = dresult.y; y <= dresult.y2; y ++){
|
||||||
Tile tile = world.tile(x, y);
|
Tile tile = world.tile(x, y);
|
||||||
@@ -160,9 +159,11 @@ public class DesktopInput extends InputHandler{
|
|||||||
cursorType = hand;
|
cursorType = hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cursor.floor().drops != null && cursor.floor().drops.item.hardness <= player.mech.drillPower
|
if(canMine(cursor)){
|
||||||
&& cursor.block() == Blocks.air && player.distanceTo(cursor.worldx(), cursor.worldy()) <= Player.mineDistance &&
|
cursorType = drill;
|
||||||
player.inventory.canAcceptItem(cursor.floor().drops.item)){
|
}
|
||||||
|
|
||||||
|
if(canTapPlayer(Graphics.mouseWorld().x, Graphics.mouseWorld().y)){
|
||||||
cursorType = drill;
|
cursorType = drill;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +190,8 @@ public class DesktopInput extends InputHandler{
|
|||||||
Tile cursor = tileAt(screenX, screenY);
|
Tile cursor = tileAt(screenX, screenY);
|
||||||
if(cursor == null) return false;
|
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(button == Buttons.LEFT) { //left = begin placing
|
||||||
if (isPlacing()) {
|
if (isPlacing()) {
|
||||||
selectX = cursor.x;
|
selectX = cursor.x;
|
||||||
@@ -196,7 +199,8 @@ public class DesktopInput extends InputHandler{
|
|||||||
mode = placing;
|
mode = placing;
|
||||||
} else {
|
} else {
|
||||||
//only begin shooting if there's no cursor event
|
//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;
|
shooting = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,6 +255,8 @@ public class DesktopInput extends InputHandler{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tryDropItems(cursor.target());
|
||||||
|
|
||||||
mode = none;
|
mode = none;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -320,7 +326,8 @@ public class DesktopInput extends InputHandler{
|
|||||||
enum CursorType{
|
enum CursorType{
|
||||||
normal(Cursors::restoreCursor),
|
normal(Cursors::restoreCursor),
|
||||||
hand(Cursors::setHand),
|
hand(Cursors::setHand),
|
||||||
drill(Cursors::setTool1);
|
drill(() -> Cursors.set("drill")),
|
||||||
|
unload(() -> Cursors.set("unload"));
|
||||||
|
|
||||||
private final Callable call;
|
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.Inputs;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.scene.Group;
|
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.Angles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Translator;
|
import io.anuke.ucore.util.Translator;
|
||||||
@@ -26,7 +25,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
|
|
||||||
public abstract class InputHandler extends InputAdapter{
|
public abstract class InputHandler extends InputAdapter{
|
||||||
/**Used for dropping items.*/
|
/**Used for dropping items.*/
|
||||||
final float playerSelectRange = Unit.dp.scl(40f);
|
final float playerSelectRange = 16f;
|
||||||
/**Maximum line length.*/
|
/**Maximum line length.*/
|
||||||
final int maxLength = 100;
|
final int maxLength = 100;
|
||||||
final Translator stackTrns = new Translator();
|
final Translator stackTrns = new Translator();
|
||||||
@@ -87,13 +86,14 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Handles tile tap events that are not platform specific.*/
|
/**Handles tile tap events that are not platform specific.*/
|
||||||
public boolean tileTapped(Tile tile){
|
boolean tileTapped(Tile tile){
|
||||||
tile = tile.target();
|
tile = tile.target();
|
||||||
|
|
||||||
boolean consumed = false;
|
boolean consumed = false;
|
||||||
|
boolean showedInventory = false;
|
||||||
|
|
||||||
//check if tapped block is configurable
|
//check if tapped block is configurable
|
||||||
if(tile.block().isConfigurable(tile)){
|
if(tile.block().isConfigurable(tile) && tile.getTeam() == player.team){
|
||||||
consumed = true;
|
consumed = true;
|
||||||
if((!frag.config.isShown() //if the config fragment is hidden, show
|
if((!frag.config.isShown() //if the config fragment is hidden, show
|
||||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||||
@@ -111,19 +111,37 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
|
|
||||||
//TODO network event!
|
//TODO network event!
|
||||||
//call tapped event
|
//call tapped event
|
||||||
if(tile.block().tapped(tile, player)){
|
if(tile.getTeam() == player.team && tile.block().tapped(tile, player)){
|
||||||
consumed = true;
|
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;
|
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.*/
|
/**Tries to begin mining a tile, returns true if successful.*/
|
||||||
boolean tryBeginMine(Tile tile){
|
boolean tryBeginMine(Tile tile){
|
||||||
if(tile.floor().drops != null && tile.floor().drops.item.hardness <= player.mech.drillPower
|
if(canMine(tile)){
|
||||||
&& tile.block() == Blocks.air && player.distanceTo(tile.worldx(), tile.worldy()) <= Player.mineDistance){
|
|
||||||
//if a block is clicked twice, reset it
|
//if a block is clicked twice, reset it
|
||||||
player.setMineTile(player.getMineTile() == tile ? null : tile);
|
player.setMineTile(player.getMineTile() == tile ? null : tile);
|
||||||
return true;
|
return true;
|
||||||
@@ -131,6 +149,11 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
return false;
|
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.*/
|
/**Returns the tile at the specified MOUSE coordinates.*/
|
||||||
Tile tileAt(float x, float y){
|
Tile tileAt(float x, float y){
|
||||||
Vector2 vec = Graphics.world(x, y);
|
Vector2 vec = Graphics.world(x, y);
|
||||||
@@ -166,7 +189,16 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
return droppingItem;
|
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);
|
int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player);
|
||||||
|
|
||||||
if(accepted > 0){
|
if(accepted > 0){
|
||||||
@@ -203,7 +235,7 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
|
|
||||||
if(end){
|
if(end){
|
||||||
stack.amount -= remaining[0];
|
stack.amount -= remaining[0];
|
||||||
if(clear) player.inventory.clear();
|
if(clear) player.inventory.clearItem();
|
||||||
transferring = false;
|
transferring = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package io.anuke.mindustry.input;
|
package io.anuke.mindustry.input;
|
||||||
|
|
||||||
enum PlaceMode{
|
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 com.badlogic.gdx.utils.ObjectMap.Entry;
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
import io.anuke.mindustry.content.blocks.Blocks;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
|
import io.anuke.mindustry.io.MapTileData.DataPosition;
|
||||||
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
import io.anuke.mindustry.io.MapTileData.TileDataMarker;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.ColorMapper;
|
import io.anuke.mindustry.world.ColorMapper;
|
||||||
@@ -37,9 +38,11 @@ public class MapIO {
|
|||||||
Pixmap pixmap = new Pixmap(data.width(), data.height(), Format.RGBA8888);
|
Pixmap pixmap = new Pixmap(data.width(), data.height(), Format.RGBA8888);
|
||||||
data.position(0, 0);
|
data.position(0, 0);
|
||||||
|
|
||||||
|
TileDataMarker marker = data.newDataMarker();
|
||||||
|
|
||||||
for(int y = 0; y < data.height(); y ++){
|
for(int y = 0; y < data.height(); y ++){
|
||||||
for(int x = 0; x < data.width(); x ++){
|
for(int x = 0; x < data.width(); x ++){
|
||||||
TileDataMarker marker = data.read();
|
data.read(marker);
|
||||||
Block floor = Block.getByID(marker.floor);
|
Block floor = Block.getByID(marker.floor);
|
||||||
Block wall = Block.getByID(marker.wall);
|
Block wall = Block.getByID(marker.wall);
|
||||||
int wallc = ColorMapper.getColor(wall);
|
int wallc = ColorMapper.getColor(wall);
|
||||||
@@ -56,22 +59,17 @@ public class MapIO {
|
|||||||
public static MapTileData readPixmap(Pixmap pixmap){
|
public static MapTileData readPixmap(Pixmap pixmap){
|
||||||
MapTileData data = new MapTileData(pixmap.getWidth(), pixmap.getHeight());
|
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 x = 0; x < data.width(); x ++){
|
||||||
for(int y = 0; y < data.height(); y ++){
|
for(int y = 0; y < data.height(); y ++){
|
||||||
BlockPair pair = ColorMapper.get(pixmap.getPixel(y, pixmap.getWidth() - 1 - x));
|
BlockPair pair = ColorMapper.get(pixmap.getPixel(y, pixmap.getWidth() - 1 - x));
|
||||||
|
|
||||||
if(pair == null){
|
if(pair == null){
|
||||||
marker.floor = (byte)Blocks.stone.id;
|
data.write(x, y, DataPosition.floor, (byte)Blocks.stone.id);
|
||||||
marker.wall = (byte)Blocks.air.id;
|
data.write(x, y, DataPosition.wall, (byte)Blocks.air.id);
|
||||||
}else{
|
}else{
|
||||||
marker.floor = (byte)pair.floor.id;
|
data.write(x, y, DataPosition.floor, (byte)pair.floor.id);
|
||||||
marker.wall = (byte)pair.wall.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 com.badlogic.gdx.utils.IntIntMap;
|
||||||
import io.anuke.ucore.util.Bits;
|
import io.anuke.ucore.util.Bits;
|
||||||
import io.anuke.ucore.util.Log;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
@@ -15,7 +14,6 @@ public class MapTileData {
|
|||||||
private final static int TILE_SIZE = 4;
|
private final static int TILE_SIZE = 4;
|
||||||
|
|
||||||
private final ByteBuffer buffer;
|
private final ByteBuffer buffer;
|
||||||
private final TileDataMarker tile = new TileDataMarker();
|
|
||||||
private final int width, height;
|
private final int width, height;
|
||||||
private final boolean readOnly;
|
private final boolean readOnly;
|
||||||
|
|
||||||
@@ -38,15 +36,14 @@ public class MapTileData {
|
|||||||
|
|
||||||
if(mapping != null && !readOnly){
|
if(mapping != null && !readOnly){
|
||||||
for(int i = 0; i < width * height; i ++){
|
for(int i = 0; i < width * height; i ++){
|
||||||
read();
|
TileDataMarker marker = new TileDataMarker();
|
||||||
|
read(marker);
|
||||||
buffer.position(i * TILE_SIZE);
|
buffer.position(i * TILE_SIZE);
|
||||||
write();
|
write(marker);
|
||||||
}
|
}
|
||||||
buffer.position(0);
|
buffer.position(0);
|
||||||
this.map = null;
|
this.map = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
read();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] toArray(){
|
public byte[] toArray(){
|
||||||
@@ -61,14 +58,16 @@ public class MapTileData {
|
|||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileDataMarker getMarker() {
|
/**Write a byte to a specific position.*/
|
||||||
return tile;
|
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.*/
|
/**Gets a byte at a specific position.*/
|
||||||
public TileDataMarker read(){
|
public byte read(int x, int y, DataPosition position){
|
||||||
tile.read(buffer);
|
buffer.position((x + width * y) * TILE_SIZE + position.ordinal());
|
||||||
return tile;
|
return buffer.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Reads and returns the next tile data.*/
|
/**Reads and returns the next tile data.*/
|
||||||
@@ -77,35 +76,9 @@ public class MapTileData {
|
|||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Reads and returns the next tile data.*/
|
/**Writes this tile data marker.*/
|
||||||
public TileDataMarker readAt(int x, int y){
|
public void write(TileDataMarker marker){
|
||||||
position(x, y);
|
marker.write(buffer);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Sets read position to the specified coordinates*/
|
/**Sets read position to the specified coordinates*/
|
||||||
@@ -113,6 +86,14 @@ public class MapTileData {
|
|||||||
buffer.position((x + width * y) * TILE_SIZE);
|
buffer.position((x + width * y) * TILE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TileDataMarker newDataMarker(){
|
||||||
|
return new TileDataMarker();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DataPosition{
|
||||||
|
floor, wall, link, rotationTeam
|
||||||
|
}
|
||||||
|
|
||||||
public class TileDataMarker {
|
public class TileDataMarker {
|
||||||
public byte floor, wall;
|
public byte floor, wall;
|
||||||
public byte link;
|
public byte link;
|
||||||
@@ -140,11 +121,5 @@ public class MapTileData {
|
|||||||
buffer.put(link);
|
buffer.put(link);
|
||||||
buffer.put(Bits.packByte(rotation, team));
|
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;
|
package io.anuke.mindustry.net;
|
||||||
|
|
||||||
import io.anuke.mindustry.entities.Player;
|
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
|
|
||||||
public class EditLog {
|
public class EditLog {
|
||||||
@@ -21,6 +20,6 @@ public class EditLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum EditAction {
|
public enum EditAction {
|
||||||
PLACE, BREAK;
|
PLACE, BREAK
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,9 @@ public class ItemImage extends Stack {
|
|||||||
private Image image;
|
private Image image;
|
||||||
|
|
||||||
public ItemImage(TextureRegion region, Supplier<String> text, Color color) {
|
public ItemImage(TextureRegion region, Supplier<String> text, Color color) {
|
||||||
Table t = new Table();
|
Table t = new Table().left().bottom();
|
||||||
t.left().bottom();
|
|
||||||
|
|
||||||
t.label(text).color(Color.DARK_GRAY);
|
t.label(text).get().setFontScale(0.5f);
|
||||||
t.row();
|
|
||||||
t.label(text).padTop(-22);
|
|
||||||
|
|
||||||
image = new Image(region);
|
image = new Image(region);
|
||||||
image.setColor(color);
|
image.setColor(color);
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ public class FileChooser extends FloatingDialog {
|
|||||||
files.row();
|
files.row();
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonGroup<TextButton> group = new ButtonGroup<TextButton>();
|
ButtonGroup<TextButton> group = new ButtonGroup<>();
|
||||||
group.setMinCheckCount(0);
|
group.setMinCheckCount(0);
|
||||||
|
|
||||||
for(FileHandle file : names){
|
for(FileHandle file : names){
|
||||||
@@ -278,7 +278,7 @@ public class FileChooser extends FloatingDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class FileHistory{
|
public class FileHistory{
|
||||||
private Array<FileHandle> history = new Array<FileHandle>();
|
private Array<FileHandle> history = new Array<>();
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
public FileHistory(){
|
public FileHistory(){
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package io.anuke.mindustry.ui.dialogs;
|
package io.anuke.mindustry.ui.dialogs;
|
||||||
|
|
||||||
import io.anuke.mindustry.net.NetEvents;
|
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.TextField;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
|
||||||
import io.anuke.ucore.util.Strings;
|
import io.anuke.ucore.util.Strings;
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class BlockInventoryFragment implements Fragment {
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
table.margin(3f);
|
table.margin(3f);
|
||||||
table.defaults().size(16 * 2).space(6f);
|
table.defaults().size(16*2).space(6f);
|
||||||
|
|
||||||
if(tile.block().hasItems) {
|
if(tile.block().hasItems) {
|
||||||
int[] items = tile.entity.items.items;
|
int[] items = tile.entity.items.items;
|
||||||
@@ -97,13 +97,6 @@ public class BlockInventoryFragment implements Fragment {
|
|||||||
|
|
||||||
container.add(i);
|
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);
|
BooleanProvider canPick = () -> player.inventory.canAcceptItem(item);
|
||||||
|
|
||||||
HandCursorListener l = new HandCursorListener();
|
HandCursorListener l = new HandCursorListener();
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
private float textWidth = Unit.dp.scl(600);
|
private float textWidth = Unit.dp.scl(600);
|
||||||
private Color shadowColor = new Color(0, 0, 0, 0.4f);
|
private Color shadowColor = new Color(0, 0, 0, 0.4f);
|
||||||
private float textspacing = Unit.dp.scl(10);
|
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 historyPos = 0;
|
||||||
private int scrollPos = 0;
|
private int scrollPos = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package io.anuke.mindustry.ui.fragments;
|
|||||||
import io.anuke.ucore.scene.Group;
|
import io.anuke.ucore.scene.Group;
|
||||||
|
|
||||||
public interface Fragment{
|
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.mindustry.input.InputHandler;
|
||||||
import io.anuke.ucore.scene.Group;
|
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 class OverlayFragment implements Fragment{
|
||||||
public final BlockInventoryFragment inv;
|
public final BlockInventoryFragment inv;
|
||||||
public final BlockConfigFragment config;
|
public final BlockConfigFragment config;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package io.anuke.mindustry.world;
|
package io.anuke.mindustry.world;
|
||||||
|
|
||||||
public enum BlockGroup {
|
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();
|
IntArray multiblocks = new IntArray();
|
||||||
|
|
||||||
data.position(0, 0);
|
data.position(0, 0);
|
||||||
|
TileDataMarker marker = data.newDataMarker();
|
||||||
|
|
||||||
for(int y = 0; y < data.height(); y ++){
|
for(int y = 0; y < data.height(); y ++){
|
||||||
for(int x = 0; x < data.width(); x ++){
|
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);
|
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];
|
Team team = Team.values()[tile.team];
|
||||||
|
|||||||
@@ -67,14 +67,10 @@ public class BlockPart extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptPower(Tile tile, Tile from, float amount){
|
public boolean acceptPower(Tile tile, Tile from, float amount) {
|
||||||
Block block = linked(tile);
|
Block block = linked(tile);
|
||||||
if(block.hasPower){
|
return block.hasPower && block.acceptPower(tile.getLinked(), from, amount);
|
||||||
return block.acceptPower(tile.getLinked(), from, amount);
|
}
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Block linked(Tile tile){
|
private Block linked(Tile tile){
|
||||||
return tile.getLinked().block();
|
return tile.getLinked().block();
|
||||||
|
|||||||
@@ -36,13 +36,8 @@ public class Router extends Block{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDump(Tile tile, Tile to, Item item) {
|
public boolean canDump(Tile tile, Tile to, Item item) {
|
||||||
if(to.block() instanceof Router){
|
return !(to.block() instanceof Router) || ((float) to.target().entity.items.totalItems() / to.target().block().itemCapacity) < ((float) tile.entity.items.totalItems() / to.target().block().itemCapacity);
|
||||||
return ((float)to.target().entity.items.totalItems() / to.target().block().itemCapacity) <
|
}
|
||||||
((float)tile.entity.items.totalItems() / to.target().block().itemCapacity);
|
|
||||||
}else{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleItem(Item item, Tile tile, Tile source){
|
public void handleItem(Item item, Tile tile, Tile source){
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class LiquidBurnerGenerator extends PowerGenerator {
|
|||||||
super(name);
|
super(name);
|
||||||
liquidCapacity = 30f;
|
liquidCapacity = 30f;
|
||||||
hasLiquids = true;
|
hasLiquids = true;
|
||||||
|
hasItems = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ public class LiquidHeatGenerator extends LiquidBurnerGenerator {
|
|||||||
|
|
||||||
public LiquidHeatGenerator(String name) {
|
public LiquidHeatGenerator(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
hasItems = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -45,12 +45,8 @@ public class PowerGenerator extends PowerBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean shouldDistribute(Tile tile, Tile other){
|
protected boolean shouldDistribute(Tile tile, Tile other) {
|
||||||
if(other.block() instanceof PowerGenerator){
|
return !(other.block() instanceof PowerGenerator) || other.entity.power.amount / other.block().powerCapacity < tile.entity.power.amount / powerCapacity;
|
||||||
return other.entity.power.amount / other.block().powerCapacity <
|
|
||||||
tile.entity.power.amount / powerCapacity;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -35,15 +35,11 @@ public class Vault extends StorageBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDump(Tile tile, Tile to, Item item){
|
public boolean canDump(Tile tile, Tile to, Item item) {
|
||||||
to = to.target();
|
to = to.target();
|
||||||
if(!(to.block() instanceof StorageBlock)) return false;
|
if (!(to.block() instanceof StorageBlock)) return false;
|
||||||
|
|
||||||
if(to.block() instanceof Vault){
|
return !(to.block() instanceof Vault) || (float) to.entity.items.totalItems() / to.block().itemCapacity < (float) tile.entity.items.totalItems() / itemCapacity;
|
||||||
return (float)to.entity.items.totalItems() / to.block().itemCapacity <
|
|
||||||
(float)tile.entity.items.totalItems() / itemCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user