render collision apart from metatiles, using graphics item layering to display
This commit is contained in:
parent
07caad3fce
commit
55c97a45d9
5 changed files with 13 additions and 17 deletions
|
@ -76,8 +76,8 @@ public:
|
|||
int getHeight();
|
||||
int getBorderWidth();
|
||||
int getBorderHeight();
|
||||
QPixmap render(bool ignoreCache, MapLayout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1));
|
||||
QPixmap renderCollision(qreal opacity, bool ignoreCache);
|
||||
QPixmap render(bool ignoreCache = false, MapLayout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1));
|
||||
QPixmap renderCollision(bool ignoreCache);
|
||||
bool mapBlockChanged(int i, const Blockdata &cache);
|
||||
bool borderBlockChanged(int i, const Blockdata &cache);
|
||||
void cacheBlockdata();
|
||||
|
|
|
@ -100,7 +100,7 @@ void Map::cacheCollision() {
|
|||
layout->cached_collision.append(block);
|
||||
}
|
||||
|
||||
QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
|
||||
QPixmap Map::renderCollision(bool ignoreCache) {
|
||||
bool changed_any = false;
|
||||
int width_ = getWidth();
|
||||
int height_ = getHeight();
|
||||
|
@ -119,17 +119,11 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
|
|||
}
|
||||
changed_any = true;
|
||||
Block block = layout->blockdata.at(i);
|
||||
QImage metatile_image = getMetatileImage(block.metatileId, layout->tileset_primary, layout->tileset_secondary, metatileLayerOrder, metatileLayerOpacity);
|
||||
QImage collision_metatile_image = getCollisionMetatileImage(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();
|
||||
painter.setOpacity(opacity);
|
||||
painter.drawImage(metatile_origin, collision_metatile_image);
|
||||
painter.restore();
|
||||
}
|
||||
painter.end();
|
||||
cacheCollision();
|
||||
|
@ -139,7 +133,7 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
|
|||
return collision_pixmap;
|
||||
}
|
||||
|
||||
QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout, QRect bounds) {
|
||||
QPixmap Map::render(bool ignoreCache, MapLayout * fromLayout, QRect bounds) {
|
||||
bool changed_any = false;
|
||||
int width_ = getWidth();
|
||||
int height_ = getHeight();
|
||||
|
|
|
@ -111,7 +111,6 @@ void Editor::setEditingCollision() {
|
|||
}
|
||||
if (map_item) {
|
||||
map_item->paintingMode = MapPixmapItem::PaintMode::Metatiles;
|
||||
map_item->setVisible(false);
|
||||
}
|
||||
if (events_group) {
|
||||
events_group->setVisible(false);
|
||||
|
|
|
@ -51,7 +51,8 @@ void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
|||
void CollisionPixmapItem::draw(bool ignoreCache) {
|
||||
if (map) {
|
||||
map->setCollisionItem(this);
|
||||
setPixmap(map->renderCollision(*this->opacity, ignoreCache));
|
||||
setPixmap(map->renderCollision(ignoreCache));
|
||||
setOpacity(*this->opacity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -359,11 +359,14 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
|
|||
|
||||
// draw background layer / base image
|
||||
map->render(true);
|
||||
pixmap = map->pixmap;
|
||||
|
||||
if (showCollision) {
|
||||
map->renderCollision(editor->collisionOpacity, true);
|
||||
pixmap = map->collision_pixmap;
|
||||
} else {
|
||||
pixmap = map->pixmap;
|
||||
QPainter collisionPainter(&pixmap);
|
||||
map->renderCollision(true);
|
||||
collisionPainter.setOpacity(editor->collisionOpacity);
|
||||
collisionPainter.drawPixmap(0, 0, map->collision_pixmap);
|
||||
collisionPainter.end();
|
||||
}
|
||||
|
||||
// draw map border
|
||||
|
@ -384,7 +387,6 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
|
|||
borderPainter.drawPixmap(x * 16, y * 16, map->layout->border_pixmap);
|
||||
}
|
||||
}
|
||||
|
||||
borderPainter.drawImage(borderWidth, borderHeight, pixmap.toImage());
|
||||
borderPainter.end();
|
||||
pixmap = newPixmap;
|
||||
|
|
Loading…
Reference in a new issue