Draw border up to players view

This commit is contained in:
GriffinR 2020-04-05 00:03:36 -04:00
parent d4cf3edfc7
commit d5908c0045
5 changed files with 27 additions and 17 deletions

View file

@ -17,9 +17,9 @@
#define DEFAULT_BORDER_WIDTH 2 #define DEFAULT_BORDER_WIDTH 2
#define DEFAULT_BORDER_HEIGHT 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 // 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 class Map : public QObject
{ {

View file

@ -147,6 +147,7 @@ private:
void updateMirroredConnectionMap(MapConnection*, QString); void updateMirroredConnectionMap(MapConnection*, QString);
void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false); void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false);
void updateEncounterFields(EncounterFields newFields); void updateEncounterFields(EncounterFields newFields);
int getBorderDrawDistance(int dimension);
Event* createNewObjectEvent(); Event* createNewObjectEvent();
Event* createNewWarpEvent(); Event* createNewWarpEvent();
Event* createNewHealLocationEvent(); Event* createNewHealLocationEvent();

View file

@ -263,23 +263,23 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout)
int x, y, w, h; int x, y, w, h;
if (connection.direction == "up") { if (connection.direction == "up") {
x = 0; x = 0;
y = getHeight() - (getBorderHeight() * NUM_BORDER_BLOCKS); y = getHeight() - BORDER_DISTANCE;
w = getWidth(); w = getWidth();
h = getBorderHeight() * NUM_BORDER_BLOCKS; h = BORDER_DISTANCE;
} else if (connection.direction == "down") { } else if (connection.direction == "down") {
x = 0; x = 0;
y = 0; y = 0;
w = getWidth(); w = getWidth();
h = getBorderHeight() * NUM_BORDER_BLOCKS; h = BORDER_DISTANCE;
} else if (connection.direction == "left") { } else if (connection.direction == "left") {
x = getWidth() - (getBorderWidth() * NUM_BORDER_BLOCKS); x = getWidth() - BORDER_DISTANCE;
y = 0; y = 0;
w = getBorderWidth() * NUM_BORDER_BLOCKS; w = BORDER_DISTANCE;
h = getHeight(); h = getHeight();
} else if (connection.direction == "right") { } else if (connection.direction == "right") {
x = 0; x = 0;
y = 0; y = 0;
w = getBorderWidth() * NUM_BORDER_BLOCKS; w = BORDER_DISTANCE;
h = getHeight(); h = getHeight();
} else { } else {
// this should not happen // this should not happen

View file

@ -1118,8 +1118,6 @@ void Editor::displayMetatileSelector() {
} }
void Editor::displayMapMetatiles() { 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); map_item = new MapPixmapItem(map, this->metatile_selector_item, this->settings);
connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)), connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*))); this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
@ -1136,10 +1134,10 @@ void Editor::displayMapMetatiles() {
scene->addItem(map_item); scene->addItem(map_item);
scene->setSceneRect( scene->setSceneRect(
-borderHorzDist, -BORDER_DISTANCE * 16,
-borderVertDist, -BORDER_DISTANCE * 16,
map_item->pixmap().width() + borderHorzDist * 2, map_item->pixmap().width() + (BORDER_DISTANCE * 16) * 2,
map_item->pixmap().height() + borderVertDist * 2 map_item->pixmap().height() + (BORDER_DISTANCE * 16) * 2
); );
} }
@ -1336,8 +1334,8 @@ void Editor::displayMapBorder() {
int borderWidth = map->getBorderWidth(); int borderWidth = map->getBorderWidth();
int borderHeight = map->getBorderHeight(); int borderHeight = map->getBorderHeight();
int borderHorzDist = borderWidth * NUM_BORDER_BLOCKS; int borderHorzDist = getBorderDrawDistance(borderWidth);
int borderVertDist = borderHeight * NUM_BORDER_BLOCKS; int borderVertDist = getBorderDrawDistance(borderHeight);
QPixmap pixmap = map->renderBorder(); QPixmap pixmap = map->renderBorder();
for (int y = -borderVertDist; y < map->getHeight() + borderVertDist; y += borderHeight) for (int y = -borderVertDist; y < map->getHeight() + borderVertDist; y += borderHeight)
for (int x = -borderHorzDist; x < map->getWidth() + borderHorzDist; x += borderWidth) { 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() { void Editor::displayMapGrid() {
for (QGraphicsLineItem* item : gridLines) { for (QGraphicsLineItem* item : gridLines) {
if (item && item->scene()) { if (item && item->scene()) {

View file

@ -70,7 +70,7 @@ void MapImageExporter::updatePreview() {
int borderHeight = 0, borderWidth = 0; int borderHeight = 0, borderWidth = 0;
bool forceDrawBorder = showUpConnections || showDownConnections || showLeftConnections || showRightConnections; bool forceDrawBorder = showUpConnections || showDownConnections || showLeftConnections || showRightConnections;
if (showBorder || forceDrawBorder) { 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); QPixmap newPreview = QPixmap(map->pixmap.width() + borderWidth * 2, map->pixmap.height() + borderHeight * 2);
QPainter borderPainter(&newPreview); QPainter borderPainter(&newPreview);
for (auto borderItem : editor->borderItems) { for (auto borderItem : editor->borderItems) {