diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
index 676b8174..c65e6cde 100644
--- a/forms/mainwindow.ui
+++ b/forms/mainwindow.ui
@@ -7,15 +7,15 @@
0
0
1117
- 747
+ 788
porymap
-
- -
+
+
-
Qt::Horizontal
@@ -512,7 +512,7 @@
-
-
+
<html><head/><body><p>Change a map layout's width and height.</p></body></html>
@@ -561,8 +561,8 @@
0
0
- 469
- 608
+ 545
+ 628
@@ -736,305 +736,6 @@
3
-
-
-
-
-
- 0
- 0
-
-
-
- QFrame::StyledPanel
-
-
- QFrame::Raised
-
-
-
-
-
-
- Primary Tileset
-
-
-
- -
-
-
- Qt::StrongFocus
-
-
- <html><head/><body><p>Primary Tileset</p><p>Defines the first 0x200 metatiles available for the map.</p></body></html>
-
-
- true
-
-
-
- -
-
-
- Secondary Tileset
-
-
-
- -
-
-
- Qt::StrongFocus
-
-
- <html><head/><body><p>Secondary Tileset</p><p>Defines the second 0x200 metatiles available for the map.</p></body></html>
-
-
- true
-
-
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 0
- 92
-
-
-
-
- 16777215
- 92
-
-
-
- QFrame::NoFrame
-
-
- QFrame::Raised
-
-
-
- 0
-
-
- QLayout::SetDefaultConstraint
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
- Selection
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
- QFrame::NoFrame
-
-
- QFrame::Plain
-
-
- true
-
-
-
-
- 0
- 0
- 324
- 77
-
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 16777215
- 16777215
-
-
-
- Qt::ScrollBarAlwaysOff
-
-
- Qt::ScrollBarAlwaysOff
-
-
- true
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
- Border
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- 16777215
- 48
-
-
-
- <html><head/><body><p>The border is a 2x2 metatile which is repeated outside of the map layout's boundary. Draw on this border area to modify it.</p></body></html>
-
-
- QFrame::StyledPanel
-
-
- QFrame::Sunken
-
-
- Qt::ScrollBarAsNeeded
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
-
-
-
@@ -1064,10 +765,10 @@
- 0
+ 8
0
- 307
- 362
+ 221
+ 324
@@ -1160,6 +861,309 @@
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 92
+
+
+
+
+ 16777215
+ 92
+
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Raised
+
+
+
+ 0
+
+
+ QLayout::SetDefaultConstraint
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ Selection
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Plain
+
+
+ true
+
+
+
+
+ 0
+ 0
+ 256
+ 74
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 16777215
+ 16777215
+
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+ true
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 110
+
+
+
+
+ 16777215
+ 110
+
+
+
+ Border
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ QLayout::SetMinAndMaxSize
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 0
+
+
+
+
+ 16777215
+ 16777215
+
+
+
+ true
+
+
+
+
+ 0
+ 0
+ 231
+ 83
+
+
+
+
+ 0
+ 0
+
+
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 1
+ 1
+
+
+
+
+ 16777215
+ 16777215
+
+
+
+ <html><head/><body><p>The border is a group of metatiles which are repeated outside of the map layout's boundary. Draw on this border area to modify it.</p></body></html>
+
+
+
+
+
+
+
+
+
+
+
+
+
-
@@ -1176,6 +1180,64 @@
+ -
+
+
+
+ 0
+ 0
+
+
+
+ QFrame::StyledPanel
+
+
+ QFrame::Raised
+
+
+
-
+
+
+ Primary Tileset
+
+
+
+ -
+
+
+ Qt::StrongFocus
+
+
+ <html><head/><body><p>Primary Tileset</p><p>Defines the first 0x200 metatiles available for the map.</p></body></html>
+
+
+ true
+
+
+
+ -
+
+
+ Secondary Tileset
+
+
+
+ -
+
+
+ Qt::StrongFocus
+
+
+ <html><head/><body><p>Secondary Tileset</p><p>Defines the second 0x200 metatiles available for the map.</p></body></html>
+
+
+ true
+
+
+
+
+
+
@@ -1344,8 +1406,8 @@
0
0
- 381
- 657
+ 371
+ 684
@@ -1618,7 +1680,7 @@
0
0
430
- 568
+ 575
@@ -2095,21 +2157,21 @@
-
-
-
- Floor Number
-
-
-
- -
-
-
- <html><head/><body><p>Floor number to be used for maps with elevators.</p></body></html>
-
-
- 127
-
-
+
+
+ Floor Number
+
+
+
+ -
+
+
+ <html><head/><body><p>Floor number to be used for maps with elevators.</p></body></html>
+
+
+ 127
+
+
@@ -2548,8 +2610,8 @@
0
0
- 826
- 557
+ 818
+ 574
@@ -2813,7 +2875,7 @@
0
0
1117
- 21
+ 22
-
+
+
+ Border Width
+
+
+
+ -
+
+
+ <html><head/><body><p>Width (in blocks) of the new map's border.</p></body></html>
+
+
+ 255
+
+
+
+ -
+
+
+ Border Height
+
+
+
+ -
+
+
+ <html><head/><body><p>Height (in blocks) of the new map's border.</p></body></html>
+
+
+ 255
+
+
+
+ -
Primary Tileset
- -
+
-
<html><head/><body><p>The primary tileset for the new map.</p></body></html>
@@ -121,14 +155,14 @@
- -
+
-
Secondary Tileset
- -
+
-
<html><head/><body><p>The secondary tileset for the new map.</p></body></html>
@@ -138,14 +172,14 @@
- -
+
-
Type
- -
+
-
<html><head/><body><p>The map type is a general attribute, which is used for many different things. For example. it determines whether biking or running is allowed.</p></body></html>
@@ -155,14 +189,14 @@
- -
+
-
Location
- -
+
-
<html><head/><body><p>The section of the region map which the map is grouped under. This also determines the name of the map that is displayed when the player enters it.</p></body></html>
@@ -172,14 +206,14 @@
- -
+
-
Can Fly To
- -
+
-
<html><head/><body><p>Whether to add a heal location to the new map.</p></body></html>
@@ -189,56 +223,56 @@
- -
+
-
Allow Running
- -
+
-
Allow Biking
- -
+
-
Allow Escape Rope
- -
+
-
- -
+
-
- -
+
-
- -
+
-
Floor Number
- -
+
-
<html><head/><body><p>Floor number to be used for maps with elevators.</p></body></html>
diff --git a/include/core/historyitem.h b/include/core/historyitem.h
index 92675055..693d733c 100644
--- a/include/core/historyitem.h
+++ b/include/core/historyitem.h
@@ -6,9 +6,12 @@
class HistoryItem {
public:
Blockdata *metatiles;
+ Blockdata *border;
int layoutWidth;
int layoutHeight;
- HistoryItem(Blockdata *metatiles, int layoutWidth, int layoutHeight);
+ int borderWidth;
+ int borderHeight;
+ HistoryItem(Blockdata *metatiles, Blockdata *border, int layoutWidth, int layoutHeight, int borderWidth, int borderHeight);
~HistoryItem();
};
diff --git a/include/core/map.h b/include/core/map.h
index 8be435a8..2873844f 100644
--- a/include/core/map.h
+++ b/include/core/map.h
@@ -17,6 +17,10 @@
#define DEFAULT_BORDER_WIDTH 2
#define DEFAULT_BORDER_HEIGHT 2
+// 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 BORDER_DISTANCE 6
+
class Map : public QObject
{
Q_OBJECT
@@ -65,7 +69,8 @@ public:
int getBorderHeight();
QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr);
QPixmap renderCollision(qreal opacity, bool ignoreCache);
- bool blockChanged(int, Blockdata*);
+ bool mapBlockChanged(int i, Blockdata * cache);
+ bool borderBlockChanged(int i, Blockdata * cache);
void cacheBlockdata();
void cacheCollision();
Block *getBlock(int x, int y);
@@ -82,12 +87,14 @@ public:
void addEvent(Event*);
QPixmap renderConnection(MapConnection, MapLayout *);
QPixmap renderBorder();
- void setDimensions(int newWidth, int newHeight, bool setNewBlockData = true);
+ void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
+ void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
void cacheBorder();
bool hasUnsavedChanges();
private:
void setNewDimensionsBlockdata(int newWidth, int newHeight);
+ void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
signals:
void mapChanged(Map *map);
diff --git a/include/mainwindow.h b/include/mainwindow.h
index 48df4608..9113e227 100644
--- a/include/mainwindow.h
+++ b/include/mainwindow.h
@@ -119,7 +119,7 @@ private slots:
void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName);
void on_comboBox_PrimaryTileset_currentTextChanged(const QString &arg1);
void on_comboBox_SecondaryTileset_currentTextChanged(const QString &arg1);
- void on_pushButton_clicked();
+ void on_pushButton_ChangeDimensions_clicked();
void on_checkBox_smartPaths_stateChanged(int selected);
void on_checkBox_Visibility_clicked(bool checked);
void on_checkBox_ToggleBorder_stateChanged(int arg1);
diff --git a/src/core/historyitem.cpp b/src/core/historyitem.cpp
index 1b0f3888..6eb66fa3 100644
--- a/src/core/historyitem.cpp
+++ b/src/core/historyitem.cpp
@@ -1,13 +1,17 @@
#include "historyitem.h"
-HistoryItem::HistoryItem(Blockdata *metatiles, int layoutWidth, int layoutHeight) {
+HistoryItem::HistoryItem(Blockdata *metatiles, Blockdata *border, int layoutWidth, int layoutHeight, int borderWidth, int borderHeight) {
this->metatiles = metatiles;
+ this->border = border;
this->layoutWidth = layoutWidth;
this->layoutHeight = layoutHeight;
+ this->borderWidth = borderWidth;
+ this->borderHeight = borderHeight;
}
HistoryItem::~HistoryItem() {
if (this->metatiles) delete this->metatiles;
+ if (this->border) delete this->border;
}
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector tiles, QString cityMap) {
diff --git a/src/core/map.cpp b/src/core/map.cpp
index c4e88dd4..4f89c6c6 100644
--- a/src/core/map.cpp
+++ b/src/core/map.cpp
@@ -67,7 +67,7 @@ int Map::getBorderHeight() {
return layout->border_height.toInt(nullptr, 0);
}
-bool Map::blockChanged(int i, Blockdata *cache) {
+bool Map::mapBlockChanged(int i, Blockdata *cache) {
if (!cache)
return true;
if (!layout->blockdata)
@@ -84,6 +84,23 @@ bool Map::blockChanged(int i, Blockdata *cache) {
return layout->blockdata->blocks->value(i) != cache->blocks->value(i);
}
+bool Map::borderBlockChanged(int i, Blockdata *cache) {
+ if (!cache)
+ return true;
+ if (!layout->border)
+ return true;
+ if (!cache->blocks)
+ return true;
+ if (!layout->border->blocks)
+ return true;
+ if (cache->blocks->length() <= i)
+ return true;
+ if (layout->border->blocks->length() <= i)
+ return true;
+
+ return layout->border->blocks->value(i) != cache->blocks->value(i);
+}
+
void Map::cacheBorder() {
if (layout->cached_border) delete layout->cached_border;
layout->cached_border = new Blockdata;
@@ -135,7 +152,7 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
}
QPainter painter(&collision_image);
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
- if (!ignoreCache && layout->cached_collision && !blockChanged(i, layout->cached_collision)) {
+ if (!ignoreCache && layout->cached_collision && !mapBlockChanged(i, layout->cached_collision)) {
continue;
}
changed_any = true;
@@ -179,7 +196,7 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) {
QPainter painter(&image);
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
- if (!ignoreCache && !blockChanged(i, layout->cached_blockdata)) {
+ if (!ignoreCache && !mapBlockChanged(i, layout->cached_blockdata)) {
continue;
}
changed_any = true;
@@ -204,27 +221,33 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) {
}
QPixmap Map::renderBorder() {
- bool changed_any = false;
+ bool changed_any = false, border_resized = false;
int width_ = getBorderWidth();
int height_ = getBorderHeight();
if (layout->border_image.isNull()) {
layout->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
changed_any = true;
}
+ if (layout->border_image.width() != width_ * 16 || layout->border_image.height() != height_ * 16) {
+ layout->border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
+ border_resized = true;
+ }
if (!(layout->border && layout->border->blocks)) {
layout->border_pixmap = layout->border_pixmap.fromImage(layout->border_image);
return layout->border_pixmap;
}
QPainter painter(&layout->border_image);
for (int i = 0; i < layout->border->blocks->length(); i++) {
- if (!blockChanged(i, layout->cached_border)) {
+ if (!border_resized && !borderBlockChanged(i, layout->cached_border)) {
continue;
}
+
changed_any = true;
Block block = layout->border->blocks->value(i);
- QImage metatile_image = getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
- int map_y = i / width_;
- int map_x = i % width_;
+ uint16_t tile = block.tile;
+ QImage metatile_image = getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary);
+ int map_y = width_ ? i / width_ : 0;
+ int map_x = width_ ? i % width_ : 0;
painter.drawImage(QPoint(map_x * 16, map_y * 16), metatile_image);
}
painter.end();
@@ -240,23 +263,23 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout)
int x, y, w, h;
if (connection.direction == "up") {
x = 0;
- y = getHeight() - 6;
+ y = getHeight() - BORDER_DISTANCE;
w = getWidth();
- h = 6;
+ h = BORDER_DISTANCE;
} else if (connection.direction == "down") {
x = 0;
y = 0;
w = getWidth();
- h = 6;
+ h = BORDER_DISTANCE;
} else if (connection.direction == "left") {
- x = getWidth() - 6;
+ x = getWidth() - BORDER_DISTANCE;
y = 0;
- w = 6;
+ w = BORDER_DISTANCE;
h = getHeight();
} else if (connection.direction == "right") {
x = 0;
y = 0;
- w = 6;
+ w = BORDER_DISTANCE;
h = getHeight();
} else {
// this should not happen
@@ -289,6 +312,25 @@ void Map::setNewDimensionsBlockdata(int newWidth, int newHeight) {
layout->blockdata->copyFrom(newBlockData);
}
+void Map::setNewBorderDimensionsBlockdata(int newWidth, int newHeight) {
+ int oldWidth = getBorderWidth();
+ int oldHeight = getBorderHeight();
+
+ Blockdata* newBlockData = new Blockdata;
+
+ for (int y = 0; y < newHeight; y++)
+ for (int x = 0; x < newWidth; x++) {
+ if (x < oldWidth && y < oldHeight) {
+ int index = y * oldWidth + x;
+ newBlockData->addBlock(layout->border->blocks->value(index));
+ } else {
+ newBlockData->addBlock(0);
+ }
+ }
+
+ layout->border->copyFrom(newBlockData);
+}
+
void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
if (setNewBlockdata) {
setNewDimensionsBlockdata(newWidth, newHeight);
@@ -300,6 +342,17 @@ void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
emit mapChanged(this);
}
+void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
+ if (setNewBlockdata) {
+ setNewBorderDimensionsBlockdata(newWidth, newHeight);
+ }
+
+ layout->border_width = QString::number(newWidth);
+ layout->border_height = QString::number(newHeight);
+
+ emit mapChanged(this);
+}
+
Block* Map::getBlock(int x, int y) {
if (layout->blockdata && layout->blockdata->blocks) {
if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
@@ -354,35 +407,64 @@ void Map::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_
}
void Map::undo() {
+ bool redraw = false, changed = false;
HistoryItem *commit = metatileHistory.back();
if (!commit)
return;
+
if (layout->blockdata) {
layout->blockdata->copyFrom(commit->metatiles);
- if (commit->layoutWidth != this->getWidth() || commit->layoutHeight != this->getHeight())
- {
+ if (commit->layoutWidth != this->getWidth() || commit->layoutHeight != this->getHeight()) {
this->setDimensions(commit->layoutWidth, commit->layoutHeight, false);
- emit mapNeedsRedrawing();
+ redraw = true;
}
+ changed = true;
+ }
+ if (layout->border) {
+ layout->border->copyFrom(commit->border);
+ if (commit->borderWidth != this->getBorderWidth() || commit->borderHeight != this->getBorderHeight()) {
+ this->setBorderDimensions(commit->borderWidth, commit->borderHeight, false);
+ redraw = true;
+ }
+ changed = true;
+ }
+ if (redraw) {
+ emit mapNeedsRedrawing();
+ }
+ if (changed) {
emit mapChanged(this);
}
}
void Map::redo() {
+ bool redraw = false, changed = false;
HistoryItem *commit = metatileHistory.next();
if (!commit)
return;
if (layout->blockdata) {
layout->blockdata->copyFrom(commit->metatiles);
- if (commit->layoutWidth != this->getWidth() || commit->layoutHeight != this->getHeight())
- {
+ if (commit->layoutWidth != this->getWidth() || commit->layoutHeight != this->getHeight()) {
this->setDimensions(commit->layoutWidth, commit->layoutHeight, false);
- emit mapNeedsRedrawing();
+ redraw = true;
}
+ changed = true;
+ }
+ if (layout->border) {
+ layout->border->copyFrom(commit->border);
+ if (commit->borderWidth != this->getBorderWidth() || commit->borderHeight != this->getBorderHeight()) {
+ this->setBorderDimensions(commit->borderWidth, commit->borderHeight, false);
+ redraw = true;
+ }
+ changed = true;
+ }
+ if (redraw) {
+ emit mapNeedsRedrawing();
+ }
+ if (changed) {
emit mapChanged(this);
}
}
@@ -392,14 +474,22 @@ void Map::commit() {
return;
}
+ int layoutWidth = this->getWidth();
+ int layoutHeight = this->getHeight();
+ int borderWidth = this->getBorderWidth();
+ int borderHeight = this->getBorderHeight();
+
if (layout->blockdata) {
HistoryItem *item = metatileHistory.current();
bool atCurrentHistory = item
&& layout->blockdata->equals(item->metatiles)
- && this->getWidth() == item->layoutWidth
- && this->getHeight() == item->layoutHeight;
+ && layout->border->equals(item->border)
+ && layoutWidth == item->layoutWidth
+ && layoutHeight == item->layoutHeight
+ && borderWidth == item->borderWidth
+ && borderHeight == item->borderHeight;
if (!atCurrentHistory) {
- HistoryItem *commit = new HistoryItem(layout->blockdata->copy(), this->getWidth(), this->getHeight());
+ HistoryItem *commit = new HistoryItem(layout->blockdata->copy(), layout->border->copy(), layoutWidth, layoutHeight, borderWidth, borderHeight);
metatileHistory.push(commit);
emit mapChanged(this);
}
diff --git a/src/editor.cpp b/src/editor.cpp
index d424254f..ff0b6d8b 100644
--- a/src/editor.cpp
+++ b/src/editor.cpp
@@ -1136,10 +1136,10 @@ void Editor::displayMapMetatiles() {
int tw = 16;
int th = 16;
scene->setSceneRect(
- -6 * tw,
- -6 * th,
- map_item->pixmap().width() + 12 * tw,
- map_item->pixmap().height() + 12 * th
+ -BORDER_DISTANCE * tw,
+ -BORDER_DISTANCE * th,
+ map_item->pixmap().width() + (BORDER_DISTANCE * 2) * tw,
+ map_item->pixmap().height() + (BORDER_DISTANCE * 2) * th
);
}
@@ -1335,8 +1335,8 @@ void Editor::displayMapBorder() {
borderItems.clear();
QPixmap pixmap = map->renderBorder();
- for (int y = -6; y < map->getHeight() + 6; y += map->getBorderHeight())
- for (int x = -6; x < map->getWidth() + 6; x += map->getBorderWidth()) {
+ for (int y = -BORDER_DISTANCE; y < map->getHeight() + BORDER_DISTANCE; y += map->getBorderHeight())
+ for (int x = -BORDER_DISTANCE; x < map->getWidth() + BORDER_DISTANCE; x += map->getBorderWidth()) {
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
item->setX(x * 16);
item->setY(y * 16);
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 510ff4e9..89bc9bc5 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2150,7 +2150,7 @@ void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString &
}
}
-void MainWindow::on_pushButton_clicked()
+void MainWindow::on_pushButton_ChangeDimensions_clicked()
{
QDialog dialog(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
dialog.setWindowTitle("Change Map Dimensions");
@@ -2160,15 +2160,31 @@ void MainWindow::on_pushButton_clicked()
QSpinBox *widthSpinBox = new QSpinBox();
QSpinBox *heightSpinBox = new QSpinBox();
+ QSpinBox *bwidthSpinBox = new QSpinBox();
+ QSpinBox *bheightSpinBox = new QSpinBox();
widthSpinBox->setMinimum(1);
heightSpinBox->setMinimum(1);
+ bwidthSpinBox->setMinimum(1);
+ bheightSpinBox->setMinimum(1);
// See below for explanation of maximum map dimensions
widthSpinBox->setMaximum(0x1E7);
heightSpinBox->setMaximum(0x1D1);
+ // Maximum based only on data type (u8) of map border width/height
+ bwidthSpinBox->setMaximum(255);
+ bheightSpinBox->setMaximum(255);
widthSpinBox->setValue(editor->map->getWidth());
heightSpinBox->setValue(editor->map->getHeight());
- form.addRow(new QLabel("Width"), widthSpinBox);
- form.addRow(new QLabel("Height"), heightSpinBox);
+ bwidthSpinBox->setValue(editor->map->getBorderWidth());
+ bheightSpinBox->setValue(editor->map->getBorderHeight());
+ if (projectConfig.getUseCustomBorderSize()) {
+ form.addRow(new QLabel("Map Width"), widthSpinBox);
+ form.addRow(new QLabel("Map Height"), heightSpinBox);
+ form.addRow(new QLabel("Border Width"), bwidthSpinBox);
+ form.addRow(new QLabel("Border Height"), bheightSpinBox);
+ } else {
+ form.addRow(new QLabel("Width"), widthSpinBox);
+ form.addRow(new QLabel("Height"), heightSpinBox);
+ }
QLabel *errorLabel = new QLabel();
QPalette errorPalette;
@@ -2178,7 +2194,7 @@ void MainWindow::on_pushButton_clicked()
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
form.addRow(&buttonBox);
- connect(&buttonBox, &QDialogButtonBox::accepted, [&dialog, &widthSpinBox, &heightSpinBox, &errorLabel](){
+ connect(&buttonBox, &QDialogButtonBox::accepted, [&dialog, &widthSpinBox, &heightSpinBox, &bwidthSpinBox, &bheightSpinBox, &errorLabel](){
// Ensure width and height are an acceptable size.
// The maximum number of metatiles in a map is the following:
// max = (width + 15) * (height + 14)
@@ -2190,8 +2206,8 @@ void MainWindow::on_pushButton_clicked()
dialog.accept();
} else {
QString errorText = QString("Error: The specified width and height are too large.\n"
- "The maximum width and height is the following: (width + 15) * (height + 14) <= 10240\n"
- "The specified width and height was: (%1 + 15) * (%2 + 14) = %3")
+ "The maximum map width and height is the following: (width + 15) * (height + 14) <= 10240\n"
+ "The specified map width and height was: (%1 + 15) * (%2 + 14) = %3")
.arg(widthSpinBox->value())
.arg(heightSpinBox->value())
.arg(numMetatiles);
@@ -2205,6 +2221,7 @@ void MainWindow::on_pushButton_clicked()
if (dialog.exec() == QDialog::Accepted) {
editor->map->setDimensions(widthSpinBox->value(), heightSpinBox->value());
+ editor->map->setBorderDimensions(bwidthSpinBox->value(), bheightSpinBox->value());
editor->map->commit();
onMapNeedsRedrawing();
}
diff --git a/src/project.cpp b/src/project.cpp
index ab840edb..55db6cd3 100644
--- a/src/project.cpp
+++ b/src/project.cpp
@@ -617,6 +617,8 @@ void Project::setNewMapLayout(Map* map) {
layout->name = QString("%1_Layout").arg(map->name);
layout->width = "20";
layout->height = "20";
+ layout->border_width = DEFAULT_BORDER_WIDTH;
+ layout->border_height = DEFAULT_BORDER_HEIGHT;
layout->border_path = QString("data/layouts/%1/border.bin").arg(map->name);
layout->blockdata_path = QString("data/layouts/%1/map.bin").arg(map->name);
layout->tileset_primary_label = "gTileset_General";
@@ -1074,7 +1076,11 @@ bool Project::loadMapBorder(Map *map) {
void Project::setNewMapBorder(Map *map) {
Blockdata *blockdata = new Blockdata;
- if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) {
+ if (map->getBorderWidth() != DEFAULT_BORDER_WIDTH || map->getBorderHeight() != DEFAULT_BORDER_HEIGHT) {
+ for (int i = 0; i < map->getBorderWidth() * map->getBorderHeight(); i++) {
+ blockdata->addBlock(0);
+ }
+ } else if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) {
blockdata->addBlock(qint16(0x0014));
blockdata->addBlock(qint16(0x0015));
blockdata->addBlock(qint16(0x001C));
diff --git a/src/ui/bordermetatilespixmapitem.cpp b/src/ui/bordermetatilespixmapitem.cpp
index f5f4d2c4..ad31a7ca 100644
--- a/src/ui/bordermetatilespixmapitem.cpp
+++ b/src/ui/bordermetatilespixmapitem.cpp
@@ -8,10 +8,12 @@ void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
QPointF pos = event->pos();
int x = static_cast(pos.x()) / 16;
int y = static_cast(pos.y()) / 16;
+ int width = map->getBorderWidth();
+ int height = map->getBorderHeight();
- for (int i = 0; i < selectionDimensions.x() && (i + x) < map->getBorderWidth(); i++) {
- for (int j = 0; j < selectionDimensions.y() && (j + y) < map->getBorderHeight(); j++) {
- int blockIndex = (j + y) * map->getBorderWidth() + (i + x);
+ for (int i = 0; i < selectionDimensions.x() && (i + x) < width; i++) {
+ for (int j = 0; j < selectionDimensions.y() && (j + y) < height; j++) {
+ int blockIndex = (j + y) * width + (i + x);
uint16_t tile = selectedMetatiles->at(j * selectionDimensions.x() + i);
(*map->layout->border->blocks)[blockIndex].tile = tile;
}
@@ -22,15 +24,17 @@ void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
void BorderMetatilesPixmapItem::draw() {
- QImage image(16 * map->getBorderWidth(), 16 * map->getBorderHeight(), QImage::Format_RGBA8888);
+ int width = map->getBorderWidth();
+ int height = map->getBorderHeight();
+ QImage image(16 * width, 16 * height, QImage::Format_RGBA8888);
QPainter painter(&image);
QVector *blocks = map->layout->border->blocks;
- for (int i = 0; i < map->getBorderWidth(); i++) {
- for (int j = 0; j < map->getBorderHeight(); j++) {
+ for (int i = 0; i < width; i++) {
+ for (int j = 0; j < height; j++) {
int x = i * 16;
int y = j * 16;
- int index = j * map->getBorderWidth() + i;
+ int index = j * width + i;
QImage metatile_image = getMetatileImage(blocks->value(index).tile, map->layout->tileset_primary, map->layout->tileset_secondary);
QPoint metatile_origin = QPoint(x, y);
painter.drawImage(metatile_origin, metatile_image);
diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp
index 8323278a..833d35a0 100644
--- a/src/ui/newmappopup.cpp
+++ b/src/ui/newmappopup.cpp
@@ -62,11 +62,15 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_secondary_label);
ui->spinBox_NewMap_Width->setDisabled(true);
ui->spinBox_NewMap_Height->setDisabled(true);
+ ui->spinBox_NewMap_BorderWidth->setDisabled(true);
+ ui->spinBox_NewMap_BorderHeight->setDisabled(true);
ui->comboBox_NewMap_Primary_Tileset->setDisabled(true);
ui->comboBox_NewMap_Secondary_Tileset->setDisabled(true);
} else {
ui->spinBox_NewMap_Width->setValue(20);
ui->spinBox_NewMap_Height->setValue(20);
+ ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH);
+ ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT);
}
ui->comboBox_NewMap_Type->addItems(*project->mapTypes);
@@ -108,6 +112,17 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
ui->label_NewMap_Floor_Number->setVisible(true);
break;
}
+ if (projectConfig.getUseCustomBorderSize()) {
+ ui->spinBox_NewMap_BorderWidth->setVisible(true);
+ ui->spinBox_NewMap_BorderHeight->setVisible(true);
+ ui->label_NewMap_BorderWidth->setVisible(true);
+ ui->label_NewMap_BorderHeight->setVisible(true);
+ } else {
+ ui->spinBox_NewMap_BorderWidth->setVisible(false);
+ ui->spinBox_NewMap_BorderHeight->setVisible(false);
+ ui->label_NewMap_BorderWidth->setVisible(false);
+ ui->label_NewMap_BorderHeight->setVisible(false);
+ }
}
void NewMapPopup::on_lineEdit_NewMap_Name_textChanged(const QString &text) {
@@ -154,8 +169,13 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
layout->name = QString("%1_Layout").arg(newMap->name);
layout->width = QString::number(this->ui->spinBox_NewMap_Width->value());
layout->height = QString::number(this->ui->spinBox_NewMap_Height->value());
- layout->border_width = QString::number(DEFAULT_BORDER_WIDTH);
- layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT);
+ if (projectConfig.getUseCustomBorderSize()) {
+ layout->border_width = QString::number(this->ui->spinBox_NewMap_BorderWidth->value());
+ layout->border_height = QString::number(this->ui->spinBox_NewMap_BorderHeight->value());
+ } else {
+ layout->border_width = QString::number(DEFAULT_BORDER_WIDTH);
+ layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT);
+ }
layout->tileset_primary_label = this->ui->comboBox_NewMap_Primary_Tileset->currentText();
layout->tileset_secondary_label = this->ui->comboBox_NewMap_Secondary_Tileset->currentText();
layout->border_path = QString("data/layouts/%1/border.bin").arg(newMapName);