zone planner ui improvements
This commit is contained in:
parent
578db0e85c
commit
72ce20c4ff
5 changed files with 98 additions and 42 deletions
6
buildcraft_resources/changelog/7.0.21
Normal file
6
buildcraft_resources/changelog/7.0.21
Normal file
|
@ -0,0 +1,6 @@
|
|||
Bugs fixed:
|
||||
|
||||
* [#2939] Quarry makes server crash when used and chunkloading is off in some cases (asie)
|
||||
* Builder inconsistently respecting OreDict (knexer)
|
||||
* ClassCastException when trying to plant reeds (hea3ven)
|
||||
* Random minor crashes (asie)
|
|
@ -40,19 +40,29 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
|
||||
public static final int RESOLUTION = 2048;
|
||||
public static final int CRAFT_TIME = 120;
|
||||
private static final int PREVIEW_BLOCKS_PER_PIXEL = 10;
|
||||
private static int RESOLUTION_CHUNKS = RESOLUTION >> 4;
|
||||
|
||||
public final byte[] previewColors = new byte[80];
|
||||
public int chunkStartX, chunkStartZ;
|
||||
public short progress = 0;
|
||||
public String mapName = "";
|
||||
|
||||
private final byte[] previewColors = new byte[80];
|
||||
private final SimpleInventory inv = new SimpleInventory(3, "inv", 64);
|
||||
private final SafeTimeTracker previewRecalcTimer = new SafeTimeTracker(100);
|
||||
|
||||
private boolean previewColorsPushed = false;
|
||||
private ZonePlan[] selectedAreas = new ZonePlan[16];
|
||||
private int currentSelectedArea = 0;
|
||||
|
||||
public byte[] getPreviewTexture(boolean force) {
|
||||
if (!previewColorsPushed || force) {
|
||||
previewColorsPushed = true;
|
||||
return previewColors;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
@ -108,9 +118,9 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
|
||||
for (int y = 0; y < 8; y++) {
|
||||
for (int x = 0; x < 10; x++) {
|
||||
int tx = (x * 10) - 45;
|
||||
int ty = (y * 10) - 35;
|
||||
newPreviewColors[y * 10 + x] = (byte) mw.getColor(xCoord + tx, zCoord + ty);
|
||||
int tx = (x * PREVIEW_BLOCKS_PER_PIXEL) - (5 * PREVIEW_BLOCKS_PER_PIXEL) + (PREVIEW_BLOCKS_PER_PIXEL / 2);
|
||||
int ty = (y * PREVIEW_BLOCKS_PER_PIXEL) - (4 * PREVIEW_BLOCKS_PER_PIXEL) + (PREVIEW_BLOCKS_PER_PIXEL / 2);
|
||||
newPreviewColors[y * 10 + x] = (byte) mw.getColor(xCoord - (xCoord % PREVIEW_BLOCKS_PER_PIXEL) + tx, zCoord - (zCoord % PREVIEW_BLOCKS_PER_PIXEL) + ty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,6 +180,7 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
progress = stream.readShort();
|
||||
mapName = NetworkUtils.readUTF(stream);
|
||||
stream.readBytes(previewColors, 0, 80);
|
||||
previewColorsPushed = false;
|
||||
}
|
||||
|
||||
private void importMap(ItemStack stack) {
|
||||
|
|
|
@ -116,26 +116,26 @@ public class ContainerZonePlan extends BuildCraftContainer implements ICommandRe
|
|||
} else if ("computeMap".equals(command)) {
|
||||
computeMap(stream.readInt(), stream.readInt(),
|
||||
stream.readUnsignedShort(), stream.readUnsignedShort(),
|
||||
stream.readUnsignedByte(), (EntityPlayer) sender);
|
||||
stream.readFloat(), (EntityPlayer) sender);
|
||||
} else if ("setName".equals(command)) {
|
||||
map.mapName = NetworkUtils.readUTF(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void computeMap(int cx, int cz, int width, int height, int blocksPerPixel, EntityPlayer player) {
|
||||
private void computeMap(int cx, int cz, int width, int height, float blocksPerPixel, EntityPlayer player) {
|
||||
final byte[] textureData = new byte[width * height];
|
||||
|
||||
MapWorld w = BuildCraftRobotics.manager.getWorld(map.getWorldObj());
|
||||
int startX = cx - width * blocksPerPixel / 2;
|
||||
int startZ = cz - height * blocksPerPixel / 2;
|
||||
int startX = Math.round(cx - width * blocksPerPixel / 2);
|
||||
int startZ = Math.round(cz - height * blocksPerPixel / 2);
|
||||
int mapStartX = map.chunkStartX << 4;
|
||||
int mapStartZ = map.chunkStartZ << 4;
|
||||
|
||||
for (int i = 0; i < width; ++i) {
|
||||
for (int j = 0; j < height; ++j) {
|
||||
int x = startX + i * blocksPerPixel;
|
||||
int z = startZ + j * blocksPerPixel;
|
||||
int x = Math.round(startX + i * blocksPerPixel);
|
||||
int z = Math.round(startZ + j * blocksPerPixel);
|
||||
int ix = x - mapStartX;
|
||||
int iz = z - mapStartZ;
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
private int mapXMin = 0;
|
||||
private int mapYMin = 0;
|
||||
|
||||
private int zoomLevel = 1;
|
||||
private float blocksPerPixel = 1.0f;
|
||||
private int cx;
|
||||
private int cz;
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
data.writeInt(cz);
|
||||
data.writeShort(getContainer().mapTexture.width);
|
||||
data.writeShort(getContainer().mapTexture.height);
|
||||
data.writeByte(zoomLevel);
|
||||
data.writeFloat(blocksPerPixel);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -234,11 +234,11 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
int blocksX = (mouseX - mapXMin) * zoomLevel;
|
||||
int blocksZ = (mouseY - mapYMin) * zoomLevel;
|
||||
int blocksX = Math.round((mouseX - mapXMin) * blocksPerPixel);
|
||||
int blocksZ = Math.round((mouseY - mapYMin) * blocksPerPixel);
|
||||
|
||||
int blockStartX = cx - mapWidth * zoomLevel / 2;
|
||||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
int blockStartX = Math.round(cx - mapWidth * blocksPerPixel / 2);
|
||||
int blockStartZ = Math.round(cz - mapHeight * blocksPerPixel / 2);
|
||||
|
||||
boolean clickOnMap = mouseX >= mapXMin
|
||||
&& mouseX <= mapXMin + getContainer().mapTexture.width && mouseY >= mapYMin &&
|
||||
|
@ -294,21 +294,21 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
|
||||
if (eventType != -1 && inSelection) {
|
||||
boolean val = tool.displayString.equals("+");
|
||||
int blockStartX = cx - mapWidth * zoomLevel / 2;
|
||||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
int blockStartX = Math.round(cx - mapWidth * blocksPerPixel / 2);
|
||||
int blockStartZ = Math.round(cz - mapHeight * blocksPerPixel / 2);
|
||||
|
||||
int x1 = selX1 < selX2 ? selX1 : selX2;
|
||||
int x2 = selX1 < selX2 ? selX2 : selX1;
|
||||
int y1 = selY1 < selY2 ? selY1 : selY2;
|
||||
int y2 = selY1 < selY2 ? selY2 : selY1;
|
||||
|
||||
int lengthX = (x2 - x1) * zoomLevel;
|
||||
int lengthY = (y2 - y1) * zoomLevel;
|
||||
int lengthX = Math.round((x2 - x1) * blocksPerPixel);
|
||||
int lengthY = Math.round((y2 - y1) * blocksPerPixel);
|
||||
|
||||
for (int i = 0; i <= lengthX; ++i) {
|
||||
for (int j = 0; j <= lengthY; ++j) {
|
||||
int x = blockStartX + (x1 - mapXMin) * zoomLevel + i;
|
||||
int z = blockStartZ + (y1 - mapYMin) * zoomLevel + j;
|
||||
int x = Math.round(blockStartX + (x1 - mapXMin) * blocksPerPixel) + i;
|
||||
int z = Math.round(blockStartZ + (y1 - mapYMin) * blocksPerPixel) + j;
|
||||
|
||||
getContainer().currentAreaSelection.set(x, z, val);
|
||||
}
|
||||
|
@ -321,6 +321,10 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
}
|
||||
|
||||
private void toFullscreen() {
|
||||
if (blocksPerPixel > 4.0f) {
|
||||
blocksPerPixel = 4.0f;
|
||||
}
|
||||
|
||||
mapWidth = this.mc.displayWidth;
|
||||
mapHeight = this.mc.displayHeight;
|
||||
|
||||
|
@ -348,6 +352,30 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
buttonList = savedButtonList;
|
||||
}
|
||||
|
||||
private boolean incBlocksPerPixel() {
|
||||
if (blocksPerPixel > 0.125f) {
|
||||
if (blocksPerPixel <= 1.0f) {
|
||||
blocksPerPixel /= 2;
|
||||
} else {
|
||||
blocksPerPixel--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean decBlocksPerPixel() {
|
||||
if ((isFullscreen() && blocksPerPixel < 4.0f) || (!isFullscreen() && blocksPerPixel < 8.0f)) {
|
||||
if (blocksPerPixel >= 1.0f) {
|
||||
blocksPerPixel++;
|
||||
} else {
|
||||
blocksPerPixel *= 2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char carac, int val) {
|
||||
if (!isFullscreen() && textField.isFocused()) {
|
||||
|
@ -366,12 +394,10 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
} else if (val == Keyboard.KEY_F5) {
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
} else if (carac == '+' && zoomLevel > 1) {
|
||||
zoomLevel--;
|
||||
} else if (carac == '+' && incBlocksPerPixel()) {
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
} else if (carac == '-' && zoomLevel < 6) {
|
||||
zoomLevel++;
|
||||
} else if (carac == '-' && decBlocksPerPixel()) {
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
} else if (carac == 'm' || (carac == 27 && isFullscreen())) {
|
||||
|
@ -392,17 +418,18 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
|
||||
for (int i = 0; i < currentSelection.width; ++i) {
|
||||
for (int j = 0; j < currentSelection.height; ++j) {
|
||||
int blockStartX = cx - mapWidth * zoomLevel / 2;
|
||||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
int blockStartX = Math.round(cx - mapWidth * blocksPerPixel / 2);
|
||||
int blockStartZ = Math.round(cz - mapHeight * blocksPerPixel / 2);
|
||||
int c = (int) Math.ceil(blocksPerPixel);
|
||||
|
||||
double r = 0;
|
||||
double g = 0;
|
||||
double b = 0;
|
||||
|
||||
for (int stepi = 0; stepi < zoomLevel; ++stepi) {
|
||||
for (int stepj = 0; stepj < zoomLevel; ++stepj) {
|
||||
int x = blockStartX + i * zoomLevel + stepi;
|
||||
int z = blockStartZ + j * zoomLevel + stepj;
|
||||
for (int stepi = 0; stepi < c; ++stepi) {
|
||||
for (int stepj = 0; stepj < c; ++stepj) {
|
||||
int x = Math.round(blockStartX + i * blocksPerPixel) + stepi;
|
||||
int z = Math.round(blockStartZ + j * blocksPerPixel) + stepj;
|
||||
|
||||
if (getContainer().currentAreaSelection.get(x, z)) {
|
||||
r += rAdd;
|
||||
|
@ -412,9 +439,9 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
}
|
||||
}
|
||||
|
||||
r /= zoomLevel * zoomLevel;
|
||||
g /= zoomLevel * zoomLevel;
|
||||
b /= zoomLevel * zoomLevel;
|
||||
r /= c * c;
|
||||
g /= c * c;
|
||||
b /= c * c;
|
||||
|
||||
if (r != 0) {
|
||||
currentSelection.setColori(i, j, (int) r, (int) g, (int) b, (int) (alpha * 255.0F));
|
||||
|
@ -458,12 +485,10 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
&& mouseY >= mapYMin && mouseY <= mapYMin + getContainer().mapTexture.height) {
|
||||
int wheel = Mouse.getEventDWheel();
|
||||
if (wheel != 0) {
|
||||
if (zoomLevel < 6 && wheel > 0) {
|
||||
zoomLevel++;
|
||||
if (wheel > 0 && decBlocksPerPixel()) {
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
} else if (zoomLevel > 1 && wheel < 0) {
|
||||
zoomLevel--;
|
||||
} else if (wheel < 0 && incBlocksPerPixel()) {
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
}
|
||||
|
|
|
@ -20,17 +20,31 @@ public class RenderZonePlan extends TileEntitySpecialRenderer {
|
|||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tile, double tx, double ty, double tz, float partialTicks) {
|
||||
boolean rendered = true;
|
||||
TileZonePlan zonePlan = (TileZonePlan) tile;
|
||||
|
||||
if (!TEXTURES.containsKey(zonePlan)) {
|
||||
DynamicTextureBC textureBC = new DynamicTextureBC(16, 16);
|
||||
TEXTURES.put(zonePlan, textureBC);
|
||||
rendered = false;
|
||||
}
|
||||
DynamicTextureBC textureBC = TEXTURES.get(zonePlan);
|
||||
FakeIcon fakeIcon = new FakeIcon(0, 1, 0, 1, 16, 16);
|
||||
|
||||
for (int y = 0; y < 8; y++) {
|
||||
for (int x = 0; x < 10; x++) {
|
||||
textureBC.setColor(x + 3, y + 3, 0xFF000000 | MapColor.mapColorArray[zonePlan.previewColors[y * 10 + x]].colorValue);
|
||||
byte[] previewColors = zonePlan.getPreviewTexture(!rendered);
|
||||
|
||||
if (previewColors != null) {
|
||||
for (int y = 0; y < 8; y++) {
|
||||
for (int x = 0; x < 10; x++) {
|
||||
int col = MapColor.mapColorArray[previewColors[y * 10 + x]].colorValue;
|
||||
if ((x & 1) != (y & 1)) {
|
||||
int ocol = col;
|
||||
col = (ocol & 0xFF) * 15 / 16
|
||||
| (((ocol & 0xFF00) >> 8) * 15 / 16) << 8
|
||||
| (((ocol & 0xFF0000) >> 16) * 15 / 16) << 16;
|
||||
}
|
||||
textureBC.setColor(x + 3, y + 3, 0xFF000000 | col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue