diff --git a/include/core/map.h b/include/core/map.h index 425ce639..32eb6e70 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -17,9 +17,9 @@ #define DEFAULT_BORDER_WIDTH 2 #define DEFAULT_BORDER_HEIGHT 2 -// Number of border blocks to draw out from edge of map. Could allow modification of this in the future. +// Number of metatiles to draw out from edge of map. Could allow modification of this in the future. // porymap will reflect changes to it, but the value is hard-coded in the projects at the moment -#define NUM_BORDER_BLOCKS 3 +#define BORDER_DISTANCE 7 class Map : public QObject { diff --git a/include/editor.h b/include/editor.h index 45706daf..a0ab0e7e 100644 --- a/include/editor.h +++ b/include/editor.h @@ -147,6 +147,7 @@ private: void updateMirroredConnectionMap(MapConnection*, QString); void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false); void updateEncounterFields(EncounterFields newFields); + int getBorderDrawDistance(int dimension); Event* createNewObjectEvent(); Event* createNewWarpEvent(); Event* createNewHealLocationEvent(); diff --git a/src/core/map.cpp b/src/core/map.cpp index 2320152a..667c151a 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -263,23 +263,23 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) int x, y, w, h; if (connection.direction == "up") { x = 0; - y = getHeight() - (getBorderHeight() * NUM_BORDER_BLOCKS); + y = getHeight() - BORDER_DISTANCE; w = getWidth(); - h = getBorderHeight() * NUM_BORDER_BLOCKS; + h = BORDER_DISTANCE; } else if (connection.direction == "down") { x = 0; y = 0; w = getWidth(); - h = getBorderHeight() * NUM_BORDER_BLOCKS; + h = BORDER_DISTANCE; } else if (connection.direction == "left") { - x = getWidth() - (getBorderWidth() * NUM_BORDER_BLOCKS); + x = getWidth() - BORDER_DISTANCE; y = 0; - w = getBorderWidth() * NUM_BORDER_BLOCKS; + w = BORDER_DISTANCE; h = getHeight(); } else if (connection.direction == "right") { x = 0; y = 0; - w = getBorderWidth() * NUM_BORDER_BLOCKS; + w = BORDER_DISTANCE; h = getHeight(); } else { // this should not happen diff --git a/src/editor.cpp b/src/editor.cpp index d87ad832..0cf52cdd 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1118,8 +1118,6 @@ void Editor::displayMetatileSelector() { } void Editor::displayMapMetatiles() { - int borderHorzDist = map->getBorderWidth() * NUM_BORDER_BLOCKS * 16; - int borderVertDist = map->getBorderHeight() * NUM_BORDER_BLOCKS * 16; map_item = new MapPixmapItem(map, this->metatile_selector_item, this->settings); connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)), this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*))); @@ -1136,10 +1134,10 @@ void Editor::displayMapMetatiles() { scene->addItem(map_item); scene->setSceneRect( - -borderHorzDist, - -borderVertDist, - map_item->pixmap().width() + borderHorzDist * 2, - map_item->pixmap().height() + borderVertDist * 2 + -BORDER_DISTANCE * 16, + -BORDER_DISTANCE * 16, + map_item->pixmap().width() + (BORDER_DISTANCE * 16) * 2, + map_item->pixmap().height() + (BORDER_DISTANCE * 16) * 2 ); } @@ -1336,8 +1334,8 @@ void Editor::displayMapBorder() { int borderWidth = map->getBorderWidth(); int borderHeight = map->getBorderHeight(); - int borderHorzDist = borderWidth * NUM_BORDER_BLOCKS; - int borderVertDist = borderHeight * NUM_BORDER_BLOCKS; + int borderHorzDist = getBorderDrawDistance(borderWidth); + int borderVertDist = getBorderDrawDistance(borderHeight); QPixmap pixmap = map->renderBorder(); for (int y = -borderVertDist; y < map->getHeight() + borderVertDist; y += borderHeight) for (int x = -borderHorzDist; x < map->getWidth() + borderHorzDist; x += borderWidth) { @@ -1350,6 +1348,17 @@ void Editor::displayMapBorder() { } } +int Editor::getBorderDrawDistance(int dimension) { + // Draw sufficient border blocks to fill the player's view (BORDER_DISTANCE) + if (dimension >= BORDER_DISTANCE) { + return dimension; + } else if (dimension) { + return dimension * (BORDER_DISTANCE / dimension + (BORDER_DISTANCE % dimension ? 1 : 0)); + } else { + return BORDER_DISTANCE; + } +} + void Editor::displayMapGrid() { for (QGraphicsLineItem* item : gridLines) { if (item && item->scene()) { diff --git a/src/ui/mapimageexporter.cpp b/src/ui/mapimageexporter.cpp index af7e180c..2cdd45e7 100644 --- a/src/ui/mapimageexporter.cpp +++ b/src/ui/mapimageexporter.cpp @@ -70,7 +70,7 @@ void MapImageExporter::updatePreview() { int borderHeight = 0, borderWidth = 0; bool forceDrawBorder = showUpConnections || showDownConnections || showLeftConnections || showRightConnections; if (showBorder || forceDrawBorder) { - borderHeight = 32 * 3, borderWidth = 32 * 3; + borderHeight = BORDER_DISTANCE * 16, borderWidth = BORDER_DISTANCE * 16; QPixmap newPreview = QPixmap(map->pixmap.width() + borderWidth * 2, map->pixmap.height() + borderHeight * 2); QPainter borderPainter(&newPreview); for (auto borderItem : editor->borderItems) {