From de9bfaa9bbb24fff2fddc863a4c4ddf04dbd69cc Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sun, 15 Jul 2018 09:05:08 -0500 Subject: [PATCH] Add ability to select metatile chunks directly from the map area. Redraw collision tiles during undo/redo --- editor.cpp | 253 ++++++++++++++++++++++++++++++++++--------------- editor.h | 34 ++++++- mainwindow.cpp | 10 ++ mainwindow.h | 1 + mainwindow.ui | 145 +++++++++++++++++++++++++++- map.cpp | 17 ++++ map.h | 4 + 7 files changed, 382 insertions(+), 82 deletions(-) diff --git a/editor.cpp b/editor.cpp index 55dee019..ecfb78a2 100755 --- a/editor.cpp +++ b/editor.cpp @@ -31,6 +31,7 @@ void Editor::undo() { if (current_view) { map->undo(); map_item->draw(); + collision_item->draw(); } } @@ -38,6 +39,7 @@ void Editor::redo() { if (current_view) { map->redo(); map_item->draw(); + collision_item->draw(); } } @@ -324,21 +326,30 @@ void Editor::setMap(QString map_name) { } if (project) { map = project->loadMap(map_name); + connect(map, &Map::paintTileChanged, [=](Map *map) { + lastSelectedMetatilesFromMap = false; + redrawCurrentMetatilesSelection(); + }); selected_events->clear(); + updateCurrentMetatilesSelection(); displayMap(); updateSelectedEvents(); } } void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) { - if (map_edit_mode == "paint") { - item->paint(event); - } else if (map_edit_mode == "fill") { - item->floodFill(event); - } else if (map_edit_mode == "pick") { - item->pick(event); - } else if (map_edit_mode == "select") { - item->select(event); + if (event->buttons() & Qt::RightButton) { + item->updateMetatileSelection(event); + } else { + if (map_edit_mode == "paint") { + item->paint(event); + } else if (map_edit_mode == "fill") { + item->floodFill(event); + } else if (map_edit_mode == "pick") { + item->pick(event); + } else if (map_edit_mode == "select") { + item->select(event); + } } } void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) { @@ -353,6 +364,15 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm } } +void Editor::updateCurrentMetatilesSelection() { + if (lastSelectedMetatilesFromMap) { + // Remember the copied metatiles from the previously-opened map + map->selected_metatiles_width = this->copiedMetatileSelectionWidth; + map->selected_metatiles_height = this->copiedMetatileSelectionHeight; + *map->selected_metatiles = *this->copiedMetatileSelection; + } +} + void Editor::displayMap() { if (!scene) scene = new QGraphicsScene; @@ -361,7 +381,7 @@ void Editor::displayMap() { scene->removeItem(map_item); delete map_item; } - map_item = new MapPixmapItem(map); + map_item = new MapPixmapItem(map, this); connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)), this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*))); @@ -372,7 +392,7 @@ void Editor::displayMap() { scene->removeItem(collision_item); delete collision_item; } - collision_item = new CollisionPixmapItem(map); + collision_item = new CollisionPixmapItem(map, this); connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)), this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*))); @@ -390,6 +410,7 @@ void Editor::displayMap() { displayMetatiles(); displayBorderMetatiles(); + displayCurrentMetatilesSelection(); displayCollisionMetatiles(); displayElevationMetatiles(); displayMapEvents(); @@ -434,6 +455,25 @@ void Editor::displayBorderMetatiles() { connect(selected_border_metatiles_item, SIGNAL(borderMetatilesChanged()), this, SLOT(onBorderMetatilesChanged())); } +void Editor::displayCurrentMetatilesSelection() { + if (scene_current_metatile_selection_item && scene_current_metatile_selection_item->scene()) { + scene_current_metatile_selection_item->scene()->removeItem(scene_current_metatile_selection_item); + delete scene_current_metatile_selection_item; + } + + scene_current_metatile_selection = new QGraphicsScene; + scene_current_metatile_selection_item = new CurrentSelectedMetatilesPixmapItem(map); + scene_current_metatile_selection_item->draw(); + scene_current_metatile_selection->addItem(scene_current_metatile_selection_item); +} + +void Editor::redrawCurrentMetatilesSelection() { + if (scene_current_metatile_selection_item) { + scene_current_metatile_selection_item->draw(); + emit currentMetatilesSelectionChanged(); + } +} + void Editor::displayCollisionMetatiles() { if (collision_metatiles_item && collision_metatiles_item->scene()) { collision_metatiles_item->scene()->removeItem(collision_metatiles_item); @@ -863,35 +903,28 @@ void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { int y = ((int)pos.y()) / 16; map->paint_metatile_initial_x = x; map->paint_metatile_initial_y = y; - updateSelection(event->pos(), event->button()); + updateSelection(event->pos()); } void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { updateCurHoveredMetatile(event->pos()); - Qt::MouseButton button = event->button(); - if (button == Qt::MouseButton::NoButton) { - Qt::MouseButtons heldButtons = event->buttons(); - if (heldButtons & Qt::RightButton) { - button = Qt::RightButton; - } else if (heldButtons & Qt::LeftButton) { - button = Qt::LeftButton; - } - } - updateSelection(event->pos(), button); + updateSelection(event->pos()); } void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - updateSelection(event->pos(), event->button()); + updateSelection(event->pos()); } -void MetatilesPixmapItem::updateSelection(QPointF pos, Qt::MouseButton button) { +void MetatilesPixmapItem::updateSelection(QPointF pos) { int x = ((int)pos.x()) / 16; int y = ((int)pos.y()) / 16; int width = pixmap().width() / 16; int height = pixmap().height() / 16; if ((x >= 0 && x < width) && (y >=0 && y < height)) { - int baseTileX = x < map->paint_metatile_initial_x ? x : map->paint_metatile_initial_x; - int baseTileY = y < map->paint_metatile_initial_y ? y : map->paint_metatile_initial_y; - map->paint_tile_index = baseTileY * 8 + baseTileX; + int x1 = x < map->paint_metatile_initial_x ? x : map->paint_metatile_initial_x; + int y1 = y < map->paint_metatile_initial_y ? y : map->paint_metatile_initial_y; + map->paint_tile_index = y1 * 8 + x1; map->paint_tile_width = abs(map->paint_metatile_initial_x - x) + 1; map->paint_tile_height = abs(map->paint_metatile_initial_y - y) + 1; + map->setSelectedMetatilesFromTilePicker(); + emit map->paintTileChanged(map); } } @@ -901,10 +934,10 @@ void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) int x = ((int)pos.x()) / 16; int y = ((int)pos.y()) / 16; - for (int i = 0; i < map->paint_tile_width && (i + x) < 2; i++) { - for (int j = 0; j < map->paint_tile_height && (j + y) < 2; j++) { + for (int i = 0; i < map->selected_metatiles_width && (i + x) < 2; i++) { + for (int j = 0; j < map->selected_metatiles_height && (j + y) < 2; j++) { int blockIndex = (j + y) * 2 + (i + x); - int tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8)); + int tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i); (*map->layout->border->blocks)[blockIndex].tile = tile; } } @@ -933,6 +966,27 @@ void BorderMetatilesPixmapItem::draw() { setPixmap(QPixmap::fromImage(image)); } +void CurrentSelectedMetatilesPixmapItem::draw() { + int width = map->selected_metatiles_width * 16; + int height = map->selected_metatiles_height * 16; + QImage image(width, height, QImage::Format_RGBA8888); + QPainter painter(&image); + + for (int i = 0; i < map->selected_metatiles_width; i++) + for (int j = 0; j < map->selected_metatiles_height; j++) + { + int x = i * 16; + int y = j * 16; + int index = j * map->selected_metatiles_width + i; + QImage metatile_image = Metatile::getMetatileImage(map->selected_metatiles->at(index), map->layout->tileset_primary, map->layout->tileset_secondary); + QPoint metatile_origin = QPoint(x, y); + painter.drawImage(metatile_origin, metatile_image); + } + + painter.end(); + setPixmap(QPixmap::fromImage(image)); +} + void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { QPointF pos = event->pos(); int x = ((int)pos.x()) / 16; @@ -1039,7 +1093,8 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) { int x = (int)(pos.x()) / 16; int y = (int)(pos.y()) / 16; - if (map->smart_paths_enabled && map->paint_tile_width == 3 && map->paint_tile_height == 3) { + // Paint onto the map. + if (map->smart_paths_enabled && map->selected_metatiles_width == 3 && map->selected_metatiles_height == 3) { paintSmartPath(x, y); } else { paintNormal(x, y); @@ -1048,6 +1103,7 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) { if (event->type() == QEvent::GraphicsSceneMouseRelease) { map->commit(); } + draw(); } } @@ -1057,18 +1113,18 @@ void MapPixmapItem::paintNormal(int x, int y) { // This allows painting via dragging the mouse to tile the painted region. int xDiff = x - map->paint_tile_initial_x; int yDiff = y - map->paint_tile_initial_y; - if (xDiff < 0 && xDiff % map->paint_tile_width != 0) xDiff -= map->paint_tile_width; - if (yDiff < 0 && yDiff % map->paint_tile_height != 0) yDiff -= map->paint_tile_height; + if (xDiff < 0 && xDiff % map->selected_metatiles_width != 0) xDiff -= map->selected_metatiles_width; + if (yDiff < 0 && yDiff % map->selected_metatiles_height != 0) yDiff -= map->selected_metatiles_height; - x = map->paint_tile_initial_x + (xDiff / map->paint_tile_width) * map->paint_tile_width; - y = map->paint_tile_initial_y + (yDiff / map->paint_tile_height) * map->paint_tile_height; - for (int i = 0; i < map->paint_tile_width && i + x < map->getWidth(); i++) - for (int j = 0; j < map->paint_tile_height && j + y < map->getHeight(); j++) { + x = map->paint_tile_initial_x + (xDiff / map->selected_metatiles_width) * map->selected_metatiles_width; + y = map->paint_tile_initial_y + (yDiff / map->selected_metatiles_height) * map->selected_metatiles_height; + for (int i = 0; i < map->selected_metatiles_width && i + x < map->getWidth(); i++) + for (int j = 0; j < map->selected_metatiles_height && j + y < map->getHeight(); j++) { int actualX = i + x; int actualY = j + y; Block *block = map->getBlock(actualX, actualY); if (block) { - block->tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8)); + block->tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i); map->_setBlock(actualX, actualY, *block); } } @@ -1078,34 +1134,32 @@ void MapPixmapItem::paintNormal(int x, int y) { // Each entry is for one possibility from the marching squares value for a tile. // (Marching Squares: https://en.wikipedia.org/wiki/Marching_squares) QList MapPixmapItem::smartPathTable = QList({ - 8 + 1, // 0000 - 8 + 1, // 0001 - 8 + 1, // 0010 - 16 + 0, // 0011 - 8 + 1, // 0100 - 8 + 1, // 0101 - 0 + 0, // 0110 - 8 + 0, // 0111 - 8 + 1, // 1000 - 16 + 2, // 1001 - 8 + 1, // 1010 - 16 + 1, // 1011 - 0 + 2, // 1100 - 8 + 2, // 1101 - 0 + 1, // 1110 - 8 + 1, // 1111 + 4, // 0000 + 4, // 0001 + 4, // 0010 + 6, // 0011 + 4, // 0100 + 4, // 0101 + 0, // 0110 + 3, // 0111 + 4, // 1000 + 8, // 1001 + 4, // 1010 + 7, // 1011 + 2, // 1100 + 5, // 1101 + 1, // 1110 + 4, // 1111 }); -#define IS_SMART_PATH_TILE(block) ((map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 3) \ - || (map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index + 8 && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 11) \ - || (map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index + 16 && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 19)) +#define IS_SMART_PATH_TILE(block) (map->selected_metatiles->contains(block->tile)) void MapPixmapItem::paintSmartPath(int x, int y) { // Smart path should never be enabled without a 3x3 block selection. - if (map->paint_tile_width != 3 || map->paint_tile_height != 3) return; + if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return; // Shift to the middle tile of the smart path selection. - int openTile = map->paint_tile_index + 8 + 1; + int openTile = map->selected_metatiles->at(4); // Fill the region with the open tile. for (int i = -1; i <= 1; i++) @@ -1117,7 +1171,7 @@ void MapPixmapItem::paintSmartPath(int x, int y) { int actualY = j + y; Block *block = map->getBlock(actualX, actualY); if (block) { - block->tile = map->getSelectedBlockIndex(openTile); + block->tile = openTile; map->_setBlock(actualX, actualY, *block); } } @@ -1157,20 +1211,70 @@ void MapPixmapItem::paintSmartPath(int x, int y) { if (left && IS_SMART_PATH_TILE(left)) id += 8; - block->tile = map->getSelectedBlockIndex(map->paint_tile_index + smartPathTable[id]); + block->tile = map->selected_metatiles->at(smartPathTable[id]); map->_setBlock(actualX, actualY, *block); } } +void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) { + QPointF pos = event->pos(); + int x = (int)(pos.x()) / 16; + int y = (int)(pos.y()) / 16; + + // Snap point to within map bounds. + if (x < 0) x = 0; + if (x >= map->getWidth()) x = map->getWidth() - 1; + if (y < 0) y = 0; + if (y >= map->getHeight()) y = map->getHeight() - 1; + + // Update/apply copied metatiles. + if (event->type() == QEvent::GraphicsSceneMousePress) { + selection_origin = QPoint(x, y); + selection.clear(); + selection.append(QPoint(x, y)); + editor->copiedMetatileSelectionWidth = 1; + editor->copiedMetatileSelectionHeight = 1; + } else if (event->type() == QEvent::GraphicsSceneMouseMove) { + QPoint pos = QPoint(x, y); + int x1 = selection_origin.x(); + int y1 = selection_origin.y(); + int x2 = pos.x(); + int y2 = pos.y(); + if (x1 > x2) SWAP(x1, x2); + if (y1 > y2) SWAP(y1, y2); + selection.clear(); + for (int y = y1; y <= y2; y++) { + for (int x = x1; x <= x2; x++) { + selection.append(QPoint(x, y)); + } + } + + editor->copiedMetatileSelectionWidth = x2 - x1 + 1; + editor->copiedMetatileSelectionHeight = y2 - y1 + 1; + } + + editor->copiedMetatileSelection->clear(); + for (QPoint point : selection) { + editor->copiedMetatileSelection->append(map->getBlock(point.x(), point.y())->tile); + } + + editor->lastSelectedMetatilesFromMap = true; + map->selected_metatiles_width = editor->copiedMetatileSelectionWidth; + map->selected_metatiles_height = editor->copiedMetatileSelectionHeight; + *map->selected_metatiles = *editor->copiedMetatileSelection; + + editor->redrawCurrentMetatilesSelection(); +} + void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) { if (map) { QPointF pos = event->pos(); int x = (int)(pos.x()) / 16; int y = (int)(pos.y()) / 16; Block *block = map->getBlock(x, y); - int tile = map->getSelectedBlockIndex(map->paint_tile_index); + int tile = map->selected_metatiles->first(); if (block && block->tile != tile) { - if (map->smart_paths_enabled && map->paint_tile_width == 3 && map->paint_tile_height == 3) + if (map->smart_paths_enabled && map->selected_metatiles_width == 3 && map->selected_metatiles_height == 3) this->_floodFillSmartPath(x, y); else this->_floodFill(x, y); @@ -1198,11 +1302,11 @@ void MapPixmapItem::_floodFill(int initialX, int initialY) { int xDiff = x - initialX; int yDiff = y - initialY; - int i = xDiff % map->paint_tile_width; - int j = yDiff % map->paint_tile_height; - if (i < 0) i = map->paint_tile_width + i; - if (j < 0) j = map->paint_tile_height + j; - int tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8)); + int i = xDiff % map->selected_metatiles_width; + int j = yDiff % map->selected_metatiles_height; + if (i < 0) i = map->selected_metatiles_width + i; + if (j < 0) j = map->selected_metatiles_height + j; + int tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i); uint old_tile = block->tile; if (old_tile == tile) { continue; @@ -1227,10 +1331,10 @@ void MapPixmapItem::_floodFill(int initialX, int initialY) { void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) { // Smart path should never be enabled without a 3x3 block selection. - if (map->paint_tile_width != 3 || map->paint_tile_height != 3) return; + if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return; // Shift to the middle tile of the smart path selection. - int openTile = map->paint_tile_index + 8 + 1; + int openTile = map->selected_metatiles->at(4); // Flood fill the region with the open tile. QList todo; @@ -1245,13 +1349,12 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) { continue; } - int tile = map->getSelectedBlockIndex(openTile); uint old_tile = block->tile; - if (old_tile == tile) { + if (old_tile == openTile) { continue; } - block->tile = tile; + block->tile = openTile; map->_setBlock(x, y, *block); if ((block = map->getBlock(x + 1, y)) && block->tile == old_tile) { todo.append(QPoint(x + 1, y)); @@ -1301,7 +1404,7 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) { if (left && IS_SMART_PATH_TILE(left)) id += 8; - block->tile = map->getSelectedBlockIndex(map->paint_tile_index + smartPathTable[id]); + block->tile = map->selected_metatiles->at(smartPathTable[id]); map->_setBlock(x, y, *block); // Visit neighbors if they are smart-path tiles, and don't revisit any. @@ -1333,12 +1436,12 @@ void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) { map->paint_tile_index = map->getDisplayedBlockIndex(block->tile); map->paint_tile_width = 1; map->paint_tile_height = 1; + map->setSelectedMetatilesFromTilePicker(); + emit map->paintTileChanged(map); } } -#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0) - void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) { QPointF pos = event->pos(); int x = (int)(pos.x()) / 16; diff --git a/editor.h b/editor.h index ba51c4aa..343a061a 100755 --- a/editor.h +++ b/editor.h @@ -17,9 +17,12 @@ class CollisionPixmapItem; class ConnectionPixmapItem; class MetatilesPixmapItem; class BorderMetatilesPixmapItem; +class CurrentSelectedMetatilesPixmapItem; class CollisionMetatilesPixmapItem; class ElevationMetatilesPixmapItem; +#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0) + class Editor : public QObject { Q_OBJECT @@ -35,9 +38,12 @@ public: void undo(); void redo(); void setMap(QString map_name); + void updateCurrentMetatilesSelection(); void displayMap(); void displayMetatiles(); void displayBorderMetatiles(); + void displayCurrentMetatilesSelection(); + void redrawCurrentMetatilesSelection(); void displayCollisionMetatiles(); void displayElevationMetatiles(); void displayMapEvents(); @@ -84,17 +90,25 @@ public: QList gridLines; QGraphicsScene *scene_metatiles = NULL; + QGraphicsScene *scene_current_metatile_selection = NULL; QGraphicsScene *scene_selected_border_metatiles = NULL; QGraphicsScene *scene_collision_metatiles = NULL; QGraphicsScene *scene_elevation_metatiles = NULL; MetatilesPixmapItem *metatiles_item = NULL; + BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL; + CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = NULL; CollisionMetatilesPixmapItem *collision_metatiles_item = NULL; ElevationMetatilesPixmapItem *elevation_metatiles_item = NULL; QList *events = NULL; QList *selected_events = NULL; + bool lastSelectedMetatilesFromMap = false; + int copiedMetatileSelectionWidth = 0; + int copiedMetatileSelectionHeight = 0; + QList *copiedMetatileSelection = new QList; + QString map_edit_mode; void objectsView_onMousePress(QMouseEvent *event); @@ -139,6 +153,7 @@ signals: void loadMapRequested(QString, QString); void tilesetChanged(QString); void warpEventDoubleClicked(QString mapName, QString warpNum); + void currentMetatilesSelectionChanged(); }; @@ -241,8 +256,10 @@ public: MapPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) { } Map *map = NULL; - MapPixmapItem(Map *map_) { + Editor *editor = NULL; + MapPixmapItem(Map *map_, Editor *editor_) { map = map_; + editor = editor_; setAcceptHoverEvents(true); } bool active; @@ -256,6 +273,7 @@ public: virtual void pick(QGraphicsSceneMouseEvent*); virtual void select(QGraphicsSceneMouseEvent*); virtual void draw(bool ignoreCache = false); + void updateMetatileSelection(QGraphicsSceneMouseEvent *event); private: void updateCurHoveredTile(QPointF pos); @@ -279,7 +297,7 @@ class CollisionPixmapItem : public MapPixmapItem { public: CollisionPixmapItem(QPixmap pixmap): MapPixmapItem(pixmap) { } - CollisionPixmapItem(Map *map_): MapPixmapItem(map_) { + CollisionPixmapItem(Map *map_, Editor *editor_): MapPixmapItem(map_, editor_) { } virtual void paint(QGraphicsSceneMouseEvent*); virtual void floodFill(QGraphicsSceneMouseEvent*); @@ -349,7 +367,7 @@ public: Map* map = NULL; virtual void draw(); private: - void updateSelection(QPointF pos, Qt::MouseButton button); + void updateSelection(QPointF pos); protected: virtual void updateCurHoveredMetatile(QPointF pos); private slots: @@ -377,6 +395,16 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent*); }; +class CurrentSelectedMetatilesPixmapItem : public QObject, public QGraphicsPixmapItem { + Q_OBJECT +public: + CurrentSelectedMetatilesPixmapItem(Map *map_) { + map = map_; + } + Map* map = NULL; + virtual void draw(); +}; + class MovementPermissionsPixmapItem : public MetatilesPixmapItem { Q_OBJECT public: diff --git a/mainwindow.cpp b/mainwindow.cpp index 038e829b..dfe7eee5 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -38,6 +38,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString))); connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString))); connect(editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString))); + connect(editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged())); on_toolButton_Paint_clicked(); @@ -188,6 +189,9 @@ void MainWindow::redrawMapScene() ui->graphicsView_BorderMetatile->setScene(editor->scene_selected_border_metatiles); ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width() + 2, editor->selected_border_metatiles_item->pixmap().height() + 2); + ui->graphicsView_currentMetatileSelection->setScene(editor->scene_current_metatile_selection); + ui->graphicsView_currentMetatileSelection->setFixedSize(editor->scene_current_metatile_selection_item->pixmap().width() + 2, editor->scene_current_metatile_selection_item->pixmap().height() + 2); + ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles); //ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect()); ui->graphicsView_Collision->setFixedSize(editor->collision_metatiles_item->pixmap().width() + 2, editor->collision_metatiles_item->pixmap().height() + 2); @@ -485,6 +489,12 @@ void MainWindow::onTilesetChanged(QString mapName) setMap(mapName); } +void MainWindow::currentMetatilesSelectionChanged() +{ + ui->graphicsView_currentMetatileSelection->setFixedSize(editor->scene_current_metatile_selection_item->pixmap().width() + 2, editor->scene_current_metatile_selection_item->pixmap().height() + 2); + ui->graphicsView_currentMetatileSelection->setSceneRect(0, 0, editor->scene_current_metatile_selection_item->pixmap().width(), editor->scene_current_metatile_selection_item->pixmap().height()); +} + void MainWindow::on_mapList_activated(const QModelIndex &index) { QVariant data = index.data(Qt::UserRole); diff --git a/mainwindow.h b/mainwindow.h index f7a3fe0e..b8a12f8b 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -74,6 +74,7 @@ private slots: void onOpenMapListContextMenu(const QPoint &point); void onAddNewMapToGroupClick(QAction* triggeredAction); void onTilesetChanged(QString); + void currentMetatilesSelectionChanged(); void on_action_Export_Map_Image_triggered(); diff --git a/mainwindow.ui b/mainwindow.ui index 1c0ab3c7..2065a367 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -171,7 +171,7 @@ true - <html><head/><body><p>Pencil</p><p>Click and drag to draw on the map.</p></body></html> + <html><head/><body><p>Editor</p><p><span style=" font-weight:600;">Click</span> and drag to draw on the map.</p><p><span style=" font-weight:600;">Right-click</span> and drag to select tiles.</p></body></html> Paint @@ -334,7 +334,7 @@ 0 0 - 436 + 429 620 @@ -647,6 +647,143 @@ + + + + 0 + 0 + + + + + 0 + 92 + + + + + 16777215 + 92 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 6 + + + QLayout::SetDefaultConstraint + + + 2 + + + 2 + + + + + + 0 + 0 + + + + Selection + + + + + + + true + + + + + 0 + 0 + 315 + 86 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + @@ -677,8 +814,8 @@ 0 0 - 358 - 497 + 365 + 405 diff --git a/map.cpp b/map.cpp index 9c76674f..c9328654 100755 --- a/map.cpp +++ b/map.cpp @@ -12,6 +12,10 @@ Map::Map(QObject *parent) : QObject(parent) paint_tile_index = 1; paint_collision = 0; paint_elevation = 3; + selected_metatiles_width = 1; + selected_metatiles_height = 1; + selected_metatiles = new QList; + selected_metatiles->append(1); } void Map::setName(QString mapName) { @@ -715,3 +719,16 @@ void Map::hoveredElevationTileChanged(int elevation) { void Map::clearHoveredElevationTile() { emit statusBarMessage(QString("")); } + +void Map::setSelectedMetatilesFromTilePicker() { + this->selected_metatiles_width = this->paint_tile_width; + this->selected_metatiles_height = this->paint_tile_height; + this->selected_metatiles->clear(); + for (int j = 0; j < this->paint_tile_height; j++) { + for (int i = 0; i < this->paint_tile_width; i++) { + int metatile = this->getSelectedBlockIndex(this->paint_tile_index + i + (j * 8)); + this->selected_metatiles->append(metatile); + } + } +} + diff --git a/map.h b/map.h index e634f556..6306cc11 100755 --- a/map.h +++ b/map.h @@ -177,6 +177,9 @@ public: int paint_tile_height = 1; int paint_tile_initial_x; int paint_tile_initial_y; + int selected_metatiles_width; + int selected_metatiles_height; + QList *selected_metatiles = NULL; int paint_collision; int paint_elevation; @@ -218,6 +221,7 @@ public: void clearHoveredCollisionTile(); void hoveredElevationTileChanged(int elevation); void clearHoveredElevationTile(); + void setSelectedMetatilesFromTilePicker(); signals: void paintTileChanged(Map *map);