|
@@ -322,7 +322,7 @@ void MetatilesPixmapItem::updateSelection(QPointF pos, Qt::MouseButton button) {
|
322
|
322
|
if ((x >= 0 && x < width) && (y >=0 && y < height)) {
|
323
|
323
|
int baseTileX = x < map->paint_metatile_initial_x ? x : map->paint_metatile_initial_x;
|
324
|
324
|
int baseTileY = y < map->paint_metatile_initial_y ? y : map->paint_metatile_initial_y;
|
325
|
|
- map->paint_tile = baseTileY * 8 + baseTileX;
|
|
325
|
+ map->paint_tile_index = baseTileY * 8 + baseTileX;
|
326
|
326
|
map->paint_tile_width = abs(map->paint_metatile_initial_x - x) + 1;
|
327
|
327
|
map->paint_tile_height = abs(map->paint_metatile_initial_y - y) + 1;
|
328
|
328
|
map->smart_paths_enabled = button == Qt::RightButton
|
|
@@ -411,7 +411,7 @@ void MapPixmapItem::paintNormal(int x, int y) {
|
411
|
411
|
int actualY = j + y;
|
412
|
412
|
Block *block = map->getBlock(actualX, actualY);
|
413
|
413
|
if (block) {
|
414
|
|
- block->tile = map->paint_tile + i + (j * 8);
|
|
414
|
+ block->tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8));
|
415
|
415
|
map->_setBlock(actualX, actualY, *block);
|
416
|
416
|
}
|
417
|
417
|
}
|
|
@@ -439,32 +439,38 @@ QList<int> MapPixmapItem::smartPathTable = QList<int>({
|
439
|
439
|
8 + 1, // 1111
|
440
|
440
|
});
|
441
|
441
|
|
442
|
|
-#define IS_SMART_PATH_TILE(block) ((block->tile >= map->paint_tile && block->tile < map->paint_tile + 3) \
|
443
|
|
- || (block->tile >= map->paint_tile + 8 && block->tile < map->paint_tile + 11) \
|
444
|
|
- || (block->tile >= map->paint_tile + 16 && block->tile < map->paint_tile + 19))
|
|
442
|
+#define IS_SMART_PATH_TILE(block) ((map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 3) \
|
|
443
|
+ || (map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index + 8 && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 11) \
|
|
444
|
+ || (map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index + 16 && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 19))
|
445
|
445
|
|
446
|
446
|
void MapPixmapItem::paintSmartPath(int x, int y) {
|
447
|
447
|
// Smart path should never be enabled without a 3x3 block selection.
|
448
|
448
|
if (map->paint_tile_width != 3 || map->paint_tile_height != 3) return;
|
449
|
449
|
|
450
|
450
|
// Shift to the middle tile of the smart path selection.
|
451
|
|
- int openTile = map->paint_tile + 8 + 1;
|
|
451
|
+ int openTile = map->paint_tile_index + 8 + 1;
|
452
|
452
|
|
453
|
453
|
// Fill the region with the open tile.
|
454
|
|
- for (int i = -1; i <= 1 && i + x < map->getWidth() && i + x >= 0; i++)
|
455
|
|
- for (int j = -1; j <= 1 && j + y < map->getHeight() && j + y >= 0; j++) {
|
|
454
|
+ for (int i = -1; i <= 1; i++)
|
|
455
|
+ for (int j = -1; j <= 1; j++) {
|
|
456
|
+ // Check if in map bounds.
|
|
457
|
+ if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0))
|
|
458
|
+ continue;
|
456
|
459
|
int actualX = i + x;
|
457
|
460
|
int actualY = j + y;
|
458
|
461
|
Block *block = map->getBlock(actualX, actualY);
|
459
|
462
|
if (block) {
|
460
|
|
- block->tile = openTile;
|
|
463
|
+ block->tile = map->getSelectedBlockIndex(openTile);
|
461
|
464
|
map->_setBlock(actualX, actualY, *block);
|
462
|
465
|
}
|
463
|
466
|
}
|
464
|
467
|
|
465
|
468
|
// Go back and resolve the edge tiles
|
466
|
|
- for (int i = -2; i <= 2 && i + x < map->getWidth() && i + x >= 0; i++)
|
467
|
|
- for (int j = -2; j <= 2 && j + y < map->getHeight() && j + y >= 0; j++) {
|
|
469
|
+ for (int i = -2; i <= 2; i++)
|
|
470
|
+ for (int j = -2; j <= 2; j++) {
|
|
471
|
+ // Check if in map bounds.
|
|
472
|
+ if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0))
|
|
473
|
+ continue;
|
468
|
474
|
// Ignore the corners, which can't possible be affected by the smart path.
|
469
|
475
|
if ((i == -2 && j == -2) || (i == 2 && j == -2) ||
|
470
|
476
|
(i == -2 && j == 2) || (i == 2 && j == 2))
|
|
@@ -494,11 +500,7 @@ void MapPixmapItem::paintSmartPath(int x, int y) {
|
494
|
500
|
if (left && IS_SMART_PATH_TILE(left))
|
495
|
501
|
id += 8;
|
496
|
502
|
|
497
|
|
- if (block) {
|
498
|
|
- qDebug() << "tile: " << block->tile << "base: " << map->paint_tile << "id: " << id;
|
499
|
|
- }
|
500
|
|
-
|
501
|
|
- block->tile = map->paint_tile + smartPathTable[id];;
|
|
503
|
+ block->tile = map->getSelectedBlockIndex(map->paint_tile_index + smartPathTable[id]);
|
502
|
504
|
map->_setBlock(actualX, actualY, *block);
|
503
|
505
|
}
|
504
|
506
|
}
|
|
@@ -508,7 +510,7 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
508
|
510
|
QPointF pos = event->pos();
|
509
|
511
|
int x = (int)(pos.x()) / 16;
|
510
|
512
|
int y = (int)(pos.y()) / 16;
|
511
|
|
- map->floodFill(x, y, map->paint_tile);
|
|
513
|
+ map->floodFill(x, y, map->getSelectedBlockIndex(map->paint_tile_index));
|
512
|
514
|
draw();
|
513
|
515
|
}
|
514
|
516
|
}
|
|
@@ -519,7 +521,7 @@ void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
519
|
521
|
int y = (int)(pos.y()) / 16;
|
520
|
522
|
Block *block = map->getBlock(x, y);
|
521
|
523
|
if (block) {
|
522
|
|
- map->paint_tile = block->tile;
|
|
524
|
+ map->paint_tile_index = map->getDisplayedBlockIndex(block->tile);
|
523
|
525
|
map->paint_tile_width = 1;
|
524
|
526
|
map->paint_tile_height = 1;
|
525
|
527
|
emit map->paintTileChanged(map);
|