diff --git a/examples/isometric_staggered_grass_and_water.tmx b/examples/isometric_staggered_grass_and_water.tmx new file mode 100644 index 0000000000..b5cdb15ac3 --- /dev/null +++ b/examples/isometric_staggered_grass_and_water.tmx @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eJytl21zozAMhE0ghCOlpJAp+f+/9OIZ7fCwNaHt3QcNAduSdvXmPFJKj6csT7k+ZQ55i28PrF+ecgqpntLgvY73JtZq/Nb5LO+xlqULO7Ix2fkKe1237Gst+z6GXGz9DnzC4DYa7HdM2j8V9uhdWPKeM6ROW3/JHTFJ3gv88ncXGPLzT0hrPJXw8HsfZ9yXynSMERf5pP2Ukq+K+YQ90lkHL208B/BGH8UdfZIeiXzTmvSKp09w1Nu+nBMfoZ/nyF1+n4Nv+SL+G7wrh5fQ0yA+j7Cjc8xp6SRHzD3G4h66esR0NLvMM88rcj/E/ipt43pLa50OaZsHS9imvrPFQxhu8LXF98zBNa195QNxFpbB9IhP5kKV1pqmHfF1SWv/WiIOwqPvwn9La2547Lu07YPMUWFhf2zjO7nSPtljPVZmh/mstYxlDh1XxF/7hfuStn2PuVzDjvLZ8yx/+wy9A/iVP+wnFc76PKDvrCu939JaF3r25ov3qwrPGrqG0KGZcodOzhzxr3PMI+Lw2mSOKfZ3068c6MH/3eLN2ijFfkRclD/SPaW1NhTrm8WFPPlsYvyZGzNwqb+9gcsu1sg3+5Xzx34lWzN0NNApHRfsVz8mllP6is3npuq9xn6f//KnA49eJ6U7DfujzzDPV/Zk1ajPSuIo2dy79zivp4hVW7DxE/Gcpz9d2vb73whzxOMmTHs4zvZ8JV4Dytf8VK2UzmWM6nV7XHquMV5Zt2a7epifzzWQe9K0o1+547NBdb6EDfFUslGl9Q71iiOPO2e15uQrrrRWikmDNYnqWvr9jl8S9tDB1nTn0AzRXFddsxe/slEZt/zOGcK70Bz4eX8o1bjrEu7BbFP/A3Y0A3jXe4WB3LZm1/+/Ca96vd73ckpxXyB92vJXEvnSpS22PSxzgYculTHod184e9QP+V9TMeHd3eNBnaPZPeKKNVXCoH2aj7RxhGM0nZ5LLqpb9a0x7de5x+SavmJyrqSLM+RyoJ9YJsThuiP8X+x3aPWdvTzmveo9rXdll1c9UzV1hEd3HvVZ3pmPRPVytP+73O7VwHdwHIl6fGlNfelf9KrHDwU77Hu/saEer9rkf8T/YUNxLNVna3v0/S8kYST7 + + + diff --git a/src/tiled/terrainbrush.cpp b/src/tiled/terrainbrush.cpp index 1388ab7a77..f790fc719e 100644 --- a/src/tiled/terrainbrush.cpp +++ b/src/tiled/terrainbrush.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using namespace Tiled; using namespace Tiled::Internal; @@ -376,6 +377,24 @@ void TerrainBrush::updateBrush(QPoint cursorPos, const QVector *list) if (checked[i]) continue; + // to support isometric staggered, make edges into variables + QPoint upPoint(x, y-1); + QPoint bottomPoint(x, y+1); + QPoint leftPoint(x-1, y); + QPoint rightPoint(x+1, y); + + if (auto renderer = dynamic_cast(mapDocument()->renderer())) { + upPoint = renderer->topRight(x, y); + bottomPoint = renderer->bottomLeft(x, y); + leftPoint = renderer->topLeft(x, y); + rightPoint = renderer->bottomRight(x, y); + } + + int upperIndex = upPoint.y()*layerWidth + upPoint.x(); + int bottomIndex = bottomPoint.y()*layerWidth + bottomPoint.x(); + int leftIndex = leftPoint.y()*layerWidth + leftPoint.x(); + int rightIndex = rightPoint.y()*layerWidth + rightPoint.x(); + const Tile *tile = currentLayer->cellAt(p).tile; const unsigned currentTerrain = ::terrain(tile); @@ -429,20 +448,20 @@ void TerrainBrush::updateBrush(QPoint cursorPos, const QVector *list) mask = 0; // depending which connections have been set, we update the preferred terrain of the tile accordingly - if (y > 0 && checked[i - layerWidth]) { - preferredTerrain = (::terrain(newTerrain[i - layerWidth]) << 16) | (preferredTerrain & 0x0000FFFF); + if (currentLayer->contains(upPoint) && checked[upperIndex]) { + preferredTerrain = (::terrain(newTerrain[upperIndex]) << 16) | (preferredTerrain & 0x0000FFFF); mask |= 0xFFFF0000; } - if (y < layerHeight - 1 && checked[i + layerWidth]) { - preferredTerrain = (::terrain(newTerrain[i + layerWidth]) >> 16) | (preferredTerrain & 0xFFFF0000); + if (currentLayer->contains(bottomPoint) && checked[bottomIndex]) { + preferredTerrain = (::terrain(newTerrain[bottomIndex]) >> 16) | (preferredTerrain & 0xFFFF0000); mask |= 0x0000FFFF; } - if (x > 0 && checked[i - 1]) { - preferredTerrain = ((::terrain(newTerrain[i - 1]) << 8) & 0xFF00FF00) | (preferredTerrain & 0x00FF00FF); + if (currentLayer->contains(leftPoint) && checked[leftIndex]) { + preferredTerrain = ((::terrain(newTerrain[leftIndex]) << 8) & 0xFF00FF00) | (preferredTerrain & 0x00FF00FF); mask |= 0xFF00FF00; } - if (x < layerWidth - 1 && checked[i + 1]) { - preferredTerrain = ((::terrain(newTerrain[i + 1]) >> 8) & 0x00FF00FF) | (preferredTerrain & 0xFF00FF00); + if (currentLayer->contains(rightPoint) && checked[rightIndex]) { + preferredTerrain = ((::terrain(newTerrain[rightIndex]) >> 8) & 0x00FF00FF) | (preferredTerrain & 0xFF00FF00); mask |= 0x00FF00FF; } } @@ -464,25 +483,25 @@ void TerrainBrush::updateBrush(QPoint cursorPos, const QVector *list) brushRect |= QRect(p, p); // consider surrounding tiles if terrain constraints were not satisfied - if (y > 0 && !checked[i - layerWidth]) { - const Tile *above = currentLayer->cellAt(x, y - 1).tile; + if (currentLayer->contains(upPoint) && !checked[upperIndex]) { + const Tile *above = currentLayer->cellAt(upPoint).tile; if (topEdge(paste) != bottomEdge(above)) - transitionList.append(QPoint(x, y - 1)); + transitionList.append(upPoint); } - if (y < layerHeight - 1 && !checked[i + layerWidth]) { - const Tile *below = currentLayer->cellAt(x, y + 1).tile; + if (currentLayer->contains(bottomPoint) && !checked[bottomIndex]) { + const Tile *below = currentLayer->cellAt(bottomPoint).tile; if (bottomEdge(paste) != topEdge(below)) - transitionList.append(QPoint(x, y + 1)); + transitionList.append(bottomPoint); } - if (x > 0 && !checked[i - 1]) { - const Tile *left = currentLayer->cellAt(x - 1, y).tile; + if (currentLayer->contains(leftPoint) && !checked[leftIndex]) { + const Tile *left = currentLayer->cellAt(leftPoint).tile; if (leftEdge(paste) != rightEdge(left)) - transitionList.append(QPoint(x - 1, y)); + transitionList.append(leftPoint); } - if (x < layerWidth - 1 && !checked[i + 1]) { - const Tile *right = currentLayer->cellAt(x + 1, y).tile; + if (currentLayer->contains(rightPoint) && !checked[rightIndex]) { + const Tile *right = currentLayer->cellAt(rightPoint).tile; if (rightEdge(paste) != leftEdge(right)) - transitionList.append(QPoint(x + 1, y)); + transitionList.append(rightPoint); } }