diff --git a/editor.cpp b/editor.cpp index ecfb78a2..31a03dc2 100755 --- a/editor.cpp +++ b/editor.cpp @@ -353,14 +353,18 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item } } void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *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->updateMovementPermissionSelection(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); + } } } @@ -412,7 +416,6 @@ void Editor::displayMap() { displayBorderMetatiles(); displayCurrentMetatilesSelection(); displayCollisionMetatiles(); - displayElevationMetatiles(); displayMapEvents(); displayMapConnections(); displayMapBorder(); @@ -481,23 +484,11 @@ void Editor::displayCollisionMetatiles() { } scene_collision_metatiles = new QGraphicsScene; - collision_metatiles_item = new CollisionMetatilesPixmapItem(map); + collision_metatiles_item = new MovementPermissionsPixmapItem(map); collision_metatiles_item->draw(); scene_collision_metatiles->addItem(collision_metatiles_item); } -void Editor::displayElevationMetatiles() { - if (elevation_metatiles_item && elevation_metatiles_item->scene()) { - elevation_metatiles_item->scene()->removeItem(elevation_metatiles_item); - delete elevation_metatiles_item; - } - - scene_elevation_metatiles = new QGraphicsScene; - elevation_metatiles_item = new ElevationMetatilesPixmapItem(map); - elevation_metatiles_item->draw(); - scene_elevation_metatiles->addItem(elevation_metatiles_item); -} - void Editor::displayMapEvents() { if (events_group) { for (QGraphicsItem *child : events_group->childItems()) { @@ -989,13 +980,17 @@ void CurrentSelectedMetatilesPixmapItem::draw() { void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { QPointF pos = event->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)) { - pick(y * width + x); - } + int x = ((int)pos.x()) / 32; + int y = ((int)pos.y()) / 32; + int width = pixmap().width() / 32; + int height = pixmap().height() / 32; + + // Snap to a valid position inside the selection area. + if (x < 0) x = 0; + if (x >= width) x = width - 1; + if (y < 0) y = 0; + if (y >= height) y = height - 1; + pick(x, y); } void MovementPermissionsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { updateCurHoveredMetatile(event->pos()); @@ -1005,17 +1000,18 @@ void MovementPermissionsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* mousePressEvent(event); } -void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(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) { - map->clearHoveredCollisionTile(); - } else { - int collision = y * width + x; - map->hoveredCollisionTileChanged(collision); - } +void MovementPermissionsPixmapItem::updateCurHoveredMetatile(QPointF pos) { + int x = ((int)pos.x()) / 32; + int y = ((int)pos.y()) / 32; + int width = pixmap().width() / 32; + int height = pixmap().height() / 32; + + // Snap to a valid position inside the selection area. + if (x < 0) x = 0; + if (x >= width) x = width - 1; + if (y < 0) y = 0; + if (y >= height) y = height - 1; + map->hoveredMovementPermissionTileChanged(x, y); } int ConnectionPixmapItem::getMinOffset() { @@ -1074,19 +1070,6 @@ void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) { emit connectionItemDoubleClicked(this); } -void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(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) { - map->clearHoveredElevationTile(); - } else { - int elevation = y * width + x; - map->hoveredElevationTileChanged(elevation); - } -} - void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) { if (map) { QPointF pos = event->pos(); @@ -1487,8 +1470,14 @@ void MapPixmapItem::updateCurHoveredTile(QPointF pos) { if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) { map->clearHoveredTile(); } else { - int tile = map->layout->blockdata->blocks->at(blockIndex).tile; - map->hoveredTileChanged(x, y, tile); + if (editor->current_view == editor->map_item) { + int tile = map->layout->blockdata->blocks->at(blockIndex).tile; + map->hoveredTileChanged(x, y, tile); + } else if (editor->current_view == editor->collision_item) { + int collision = map->layout->blockdata->blocks->at(blockIndex).collision; + int elevation = map->layout->blockdata->blocks->at(blockIndex).elevation; + map->hoveredMovementPermissionTileChanged(collision, elevation); + } } } @@ -1582,6 +1571,24 @@ void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) { } } +void CollisionPixmapItem::updateMovementPermissionSelection(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; + + int collision = map->getBlock(x, y)->collision; + int elevation = map->getBlock(x, y)->elevation; + map->paint_collision = collision; + map->paint_elevation = elevation; + editor->collision_metatiles_item->draw(); +} + void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) { active = true; last_x = (mouse->pos().x() + this->pos().x()) / 16; diff --git a/editor.h b/editor.h index 343a061a..863b096f 100755 --- a/editor.h +++ b/editor.h @@ -18,8 +18,7 @@ class ConnectionPixmapItem; class MetatilesPixmapItem; class BorderMetatilesPixmapItem; class CurrentSelectedMetatilesPixmapItem; -class CollisionMetatilesPixmapItem; -class ElevationMetatilesPixmapItem; +class MovementPermissionsPixmapItem; #define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0) @@ -98,8 +97,7 @@ public: BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL; CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = NULL; - CollisionMetatilesPixmapItem *collision_metatiles_item = NULL; - ElevationMetatilesPixmapItem *elevation_metatiles_item = NULL; + MovementPermissionsPixmapItem *collision_metatiles_item = NULL; QList *events = NULL; QList *selected_events = NULL; @@ -299,6 +297,7 @@ public: } CollisionPixmapItem(Map *map_, Editor *editor_): MapPixmapItem(map_, editor_) { } + void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event); virtual void paint(QGraphicsSceneMouseEvent*); virtual void floodFill(QGraphicsSceneMouseEvent*); virtual void pick(QGraphicsSceneMouseEvent*); @@ -408,31 +407,21 @@ public: class MovementPermissionsPixmapItem : public MetatilesPixmapItem { Q_OBJECT public: - MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) {} - virtual void pick(uint collision) { - map->paint_collision = collision; - draw(); - } -protected: - void mousePressEvent(QGraphicsSceneMouseEvent*); - void mouseMoveEvent(QGraphicsSceneMouseEvent*); - void mouseReleaseEvent(QGraphicsSceneMouseEvent*); -}; - -class CollisionMetatilesPixmapItem : public MovementPermissionsPixmapItem { - Q_OBJECT -public: - CollisionMetatilesPixmapItem(Map *map_): MovementPermissionsPixmapItem(map_) { + MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) { connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *))); } - virtual void pick(uint collision) { + virtual void pick(uint collision, uint elevation) { map->paint_collision = collision; + map->paint_elevation = elevation; draw(); } virtual void draw() { setPixmap(map->renderCollisionMetatiles()); } protected: + void mousePressEvent(QGraphicsSceneMouseEvent*); + void mouseMoveEvent(QGraphicsSceneMouseEvent*); + void mouseReleaseEvent(QGraphicsSceneMouseEvent*); virtual void updateCurHoveredMetatile(QPointF pos); private slots: void paintCollisionChanged(Map *map) { @@ -440,26 +429,4 @@ private slots: } }; -class ElevationMetatilesPixmapItem : public MovementPermissionsPixmapItem { - Q_OBJECT -public: - ElevationMetatilesPixmapItem(Map *map_): MovementPermissionsPixmapItem(map_) { - connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *))); - } - virtual void pick(uint elevation) { - map->paint_elevation = elevation; - draw(); - } - virtual void draw() { - setPixmap(map->renderElevationMetatiles()); - } -protected: - virtual void updateCurHoveredMetatile(QPointF pos); -private slots: - void paintCollisionChanged(Map *map) { - draw(); - } -}; - - #endif // EDITOR_H diff --git a/mainwindow.cpp b/mainwindow.cpp index dfe7eee5..d518ae9d 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -38,7 +38,6 @@ 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(); @@ -195,10 +194,6 @@ void MainWindow::redrawMapScene() 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); - - ui->graphicsView_Elevation->setScene(editor->scene_elevation_metatiles); - //ui->graphicsView_Elevation->setSceneRect(editor->scene_elevation_metatiles->sceneRect()); - ui->graphicsView_Elevation->setFixedSize(editor->elevation_metatiles_item->pixmap().width() + 2, editor->elevation_metatiles_item->pixmap().height() + 2); } void MainWindow::openWarpMap(QString map_name, QString warp_num) { diff --git a/mainwindow.ui b/mainwindow.ui index 2065a367..193d98e1 100755 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -466,7 +466,7 @@ - 0 + 1 @@ -912,7 +912,7 @@ true - + 0 0 @@ -920,97 +920,78 @@ Collision - - - - 20 - 60 - 111 - 20 - + + + QLayout::SetDefaultConstraint - - Qt::Horizontal + + 0 - - - - - 0 - 80 - 151 - 101 - + + 0 - - QFrame::StyledPanel + + 0 - - QFrame::Raised + + 0 - - - - 10 - 10 - 47 - 13 - - - - Elevation - - - - - - 10 - 30 - 131 - 61 - - - - - - - - 0 - 0 - 151 - 61 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 10 - 10 - 47 - 13 - - - - Collision - - - - - - 40 - 30 - 66 - 18 - - - - + + + + + 0 + 0 + + + + + 64 + 512 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + diff --git a/map.cpp b/map.cpp index c9328654..5206da76 100755 --- a/map.cpp +++ b/map.cpp @@ -81,46 +81,14 @@ int Map::getDisplayedBlockIndex(int index) { } QImage Map::getCollisionMetatileImage(Block block) { - return getCollisionMetatileImage(block.collision); + return getCollisionMetatileImage(block.collision, block.elevation); } -QImage Map::getCollisionMetatileImage(int collision) { - QImage metatile_image(16, 16, QImage::Format_RGBA8888); - QColor color; - if (collision == 0) { - color.setGreen(0xff); - } else if (collision == 1) { - color.setRed(0xff); - } else if (collision == 2) { - color.setBlue(0xff); - } else if (collision == 3) { - // black - } - metatile_image.fill(color); - return metatile_image; -} - -QImage Map::getElevationMetatileImage(Block block) { - return getElevationMetatileImage(block.elevation); -} - -QImage Map::getElevationMetatileImage(int elevation) { - QImage metatile_image(16, 16, QImage::Format_RGBA8888); - QColor color; - if (elevation < 15) { - uint saturation = (elevation + 1) * 16 + 15; - color.setGreen(saturation); - color.setRed(saturation); - color.setBlue(saturation); - } else { - color.setGreen(0xd0); - color.setBlue(0xd0); - color.setRed(0); - } - metatile_image.fill(color); - //QPainter painter(&metatile_image); - //painter.end(); - return metatile_image; +QImage Map::getCollisionMetatileImage(int collision, int elevation) { + int x = collision * 16; + int y = elevation * 16; + QPixmap collisionImage = QPixmap(":/images/collisions.png").copy(x, y, 16, 16); + return collisionImage.toImage(); } bool Map::blockChanged(int i, Blockdata *cache) { @@ -203,40 +171,15 @@ QPixmap Map::renderCollision(bool ignoreCache) { Block block = layout->blockdata->blocks->value(i); QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary); QImage collision_metatile_image = getCollisionMetatileImage(block); - QImage elevation_metatile_image = getElevationMetatileImage(block); int map_y = width_ ? i / width_ : 0; int map_x = width_ ? i % width_ : 0; QPoint metatile_origin = QPoint(map_x * 16, map_y * 16); painter.setOpacity(1); painter.drawImage(metatile_origin, metatile_image); - painter.save(); - if (block.elevation == 15) { - painter.setOpacity(0.5); - } else if (block.elevation == 0) { - painter.setOpacity(0); - } else { - painter.setOpacity(1);//(block.elevation / 16.0) * 0.8); - painter.setCompositionMode(QPainter::CompositionMode_Overlay); - } - painter.drawImage(metatile_origin, elevation_metatile_image); - painter.restore(); - - painter.save(); - if (block.collision == 0) { - painter.setOpacity(0.1); - } else { - painter.setOpacity(0.4); - } + painter.setOpacity(0.55); painter.drawImage(metatile_origin, collision_metatile_image); painter.restore(); - - painter.save(); - painter.setOpacity(0.6); - painter.setPen(QColor(255, 255, 255, 192)); - painter.setFont(QFont("Helvetica", 8)); - painter.drawText(QPoint(metatile_origin.x(), metatile_origin.y() + 8), QString("%1").arg(block.elevation)); - painter.restore(); } painter.end(); cacheCollision(); @@ -353,54 +296,35 @@ QPixmap Map::renderConnection(Connection connection) { } QPixmap Map::renderCollisionMetatiles() { - int length_ = 4; - int height_ = 1; - int width_ = length_ / height_; - QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888); + int width_ = 2; + int height_ = 16; + QImage image(width_ * 32, height_ * 32, QImage::Format_RGBA8888); QPainter painter(&image); - for (int i = 0; i < length_; i++) { - int y = i / width_; - int x = i % width_; - QPoint origin(x * 16, y * 16); - QImage metatile_image = getCollisionMetatileImage(i); - painter.drawImage(origin, metatile_image); + for (int i = 0; i < width_; i++) { + for (int j = 0; j < height_; j++) { + QPoint origin(i * 32, j * 32); + QImage metatile_image = getCollisionMetatileImage(i, j).scaled(32, 32); + painter.drawImage(origin, metatile_image); + } } - drawSelection(paint_collision, width_, 1, 1, &painter); + drawSelection(paint_collision + paint_elevation * width_, width_, 1, 1, &painter, 32); painter.end(); return QPixmap::fromImage(image); } -QPixmap Map::renderElevationMetatiles() { - int length_ = 16; - int height_ = 2; - int width_ = length_ / height_; - QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888); - QPainter painter(&image); - for (int i = 0; i < length_; i++) { - int y = i / width_; - int x = i % width_; - QPoint origin(x * 16, y * 16); - QImage metatile_image = getElevationMetatileImage(i); - painter.drawImage(origin, metatile_image); - } - drawSelection(paint_elevation, width_, 1, 1, &painter); - painter.end(); - return QPixmap::fromImage(image); -} - -void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter) { +void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth) { int x = i % w; int y = i / w; painter->save(); QColor penColor = QColor(0xff, 0xff, 0xff); painter->setPen(penColor); - int rectWidth = selectionWidth * 16; - int rectHeight = selectionHeight * 16; - painter->drawRect(x * 16, y * 16, rectWidth - 1, rectHeight -1); + int rectWidth = selectionWidth * gridWidth; + int rectHeight = selectionHeight * gridWidth; + painter->drawRect(x * gridWidth, y * gridWidth, rectWidth - 1, rectHeight -1); painter->setPen(QColor(0, 0, 0)); - painter->drawRect(x * 16 - 1, y * 16 - 1, rectWidth + 1, rectHeight + 1); - painter->drawRect(x * 16 + 1, y * 16 + 1, rectWidth - 3, rectHeight - 3); + painter->drawRect(x * gridWidth - 1, y * gridWidth - 1, rectWidth + 1, rectHeight + 1); + painter->drawRect(x * gridWidth + 1, y * gridWidth + 1, rectWidth - 3, rectHeight - 3); painter->restore(); } @@ -427,7 +351,7 @@ QPixmap Map::renderMetatiles() { painter.drawImage(metatile_origin, metatile_image); } - drawSelection(paint_tile_index, width_, paint_tile_width, paint_tile_height, &painter); + drawSelection(paint_tile_index, width_, paint_tile_width, paint_tile_height, &painter, 16); painter.end(); return QPixmap::fromImage(image); @@ -684,7 +608,7 @@ bool Map::hasUnsavedChanges() { } void Map::hoveredTileChanged(int x, int y, int block) { - emit statusBarMessage(QString("X: %1, Y: %2, Block: 0x%3") + emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3") .arg(x) .arg(y) .arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())); @@ -704,19 +628,23 @@ void Map::clearHoveredMetatile() { emit statusBarMessage(QString("")); } -void Map::hoveredCollisionTileChanged(int collision) { - emit statusBarMessage(QString("Collision: %1").arg(collision)); +void Map::hoveredMovementPermissionTileChanged(int collision, int elevation) { + QString message; + if (collision == 0 && elevation == 0) { + message = "Collision: Transition between elevations"; + } else if (collision == 0 && elevation == 15) { + message = "Collision: Multi-Level (Bridge)"; + } else if (collision == 0 && elevation == 1) { + message = "Collision: Surf"; + } else if (collision == 0) { + message = QString("Collision: Passable, Elevation: %1").arg(elevation); + } else { + message = QString("Collision: Impassable, Elevation: %1").arg(elevation); + } + emit statusBarMessage(message); } -void Map::clearHoveredCollisionTile() { - emit statusBarMessage(QString("")); -} - -void Map::hoveredElevationTileChanged(int elevation) { - emit statusBarMessage(QString("Elevation: %1").arg(elevation)); -} - -void Map::clearHoveredElevationTile() { +void Map::clearHoveredMovementPermissionTile() { emit statusBarMessage(QString("")); } diff --git a/map.h b/map.h index 6306cc11..82e70675 100755 --- a/map.h +++ b/map.h @@ -155,13 +155,10 @@ public: QImage collision_image; QPixmap collision_pixmap; QImage getCollisionMetatileImage(Block); - QImage getElevationMetatileImage(Block); - QImage getCollisionMetatileImage(int); - QImage getElevationMetatileImage(int); - + QImage getCollisionMetatileImage(int, int); QPixmap renderCollisionMetatiles(); - QPixmap renderElevationMetatiles(); - void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter); + + void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth); bool blockChanged(int, Blockdata*); void cacheBlockdata(); @@ -217,10 +214,8 @@ public: void clearHoveredTile(); void hoveredMetatileChanged(int block); void clearHoveredMetatile(); - void hoveredCollisionTileChanged(int collision); - void clearHoveredCollisionTile(); - void hoveredElevationTileChanged(int elevation); - void clearHoveredElevationTile(); + void hoveredMovementPermissionTileChanged(int collision, int elevation); + void clearHoveredMovementPermissionTile(); void setSelectedMetatilesFromTilePicker(); signals: diff --git a/resources/images.qrc b/resources/images.qrc index 913146ec..dfca147d 100755 --- a/resources/images.qrc +++ b/resources/images.qrc @@ -15,5 +15,6 @@ icons/add.ico icons/delete.ico icons/viewsprites.ico + images/collisions.png diff --git a/resources/images/collisions.png b/resources/images/collisions.png new file mode 100644 index 00000000..d173d8ff Binary files /dev/null and b/resources/images/collisions.png differ