Merge remote-tracking branch 'huderlem/master'

This commit is contained in:
garak 2018-09-14 20:09:39 -04:00
commit 80370fdd16
27 changed files with 257 additions and 351 deletions

10
.gitignore vendored
View file

@ -1,2 +1,10 @@
pretmap.pro.user porymap.pro.user
*.autosave *.autosave
*.stash
*.o
moc_*
qrc_*
porymap.app*
Makefile
ui_mainwindow.h
ui_objectpropertiesframe.h

View file

@ -1,5 +1,8 @@
# pretmap # porymap
A map editor for [pokeruby][pokeruby] using Qt. A map editor for the generation 3 disassembly projects using Qt.
Currently supporting [pokeruby][pokeruby] and [pokeemerald][pokeemerald].
[pokeruby]: https://github.com/pret/pokeruby [pokeruby]: https://github.com/pret/pokeruby
[pokeemerald]: https://github.com/pret/pokeemerald

View file

@ -17,7 +17,10 @@ Block::Block(const Block &block) {
} }
uint16_t Block::rawValue() { uint16_t Block::rawValue() {
return (tile & 0x3ff) + ((collision & 0x3) << 10) + ((elevation & 0xf) << 12); return static_cast<uint16_t>(
(tile & 0x3ff) +
((collision & 0x3) << 10) +
((elevation & 0xf) << 12));
} }
bool Block::operator ==(Block other) { bool Block::operator ==(Block other) {

View file

@ -20,8 +20,8 @@ QByteArray Blockdata::serialize() {
for (int i = 0; i < blocks->length(); i++) { for (int i = 0; i < blocks->length(); i++) {
Block block = blocks->value(i); Block block = blocks->value(i);
uint16_t word = block.rawValue(); uint16_t word = block.rawValue();
data.append(word & 0xff); data.append(static_cast<char>(word & 0xff));
data.append((word >> 8) & 0xff); data.append(static_cast<char>((word >> 8) & 0xff));
} }
return data; return data;
} }

View file

@ -10,13 +10,13 @@ class Blockdata : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Blockdata(QObject *parent = 0); explicit Blockdata(QObject *parent = nullptr);
~Blockdata() { ~Blockdata() {
if (blocks) delete blocks; if (blocks) delete blocks;
} }
public: public:
QList<Block> *blocks = NULL; QList<Block> *blocks = nullptr;
void addBlock(uint16_t); void addBlock(uint16_t);
void addBlock(Block); void addBlock(Block);
QByteArray serialize(); QByteArray serialize();

View file

@ -5,7 +5,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <math.h> #include <math.h>
bool selectingEvent = false; static bool selectingEvent = false;
Editor::Editor(Ui::MainWindow* ui) Editor::Editor(Ui::MainWindow* ui)
{ {
@ -107,7 +107,8 @@ void Editor::setEditingConnections() {
ui->label_NumConnections->setText(QString::number(map->connections.length())); ui->label_NumConnections->setText(QString::number(map->connections.length()));
setConnectionsVisibility(false); setConnectionsVisibility(false);
setDiveEmergeControls(); setDiveEmergeControls();
setConnectionEditControlsEnabled(selected_connection_item != NULL); bool controlsEnabled = selected_connection_item != nullptr;
setConnectionEditControlsEnabled(controlsEnabled);
if (selected_connection_item) { if (selected_connection_item) {
onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt()); onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt());
setConnectionMap(selected_connection_item->connection->map_name); setConnectionMap(selected_connection_item->connection->map_name);
@ -258,7 +259,7 @@ void Editor::setConnectionEditControlsEnabled(bool enabled) {
ui->spinBox_ConnectionOffset->setEnabled(enabled); ui->spinBox_ConnectionOffset->setEnabled(enabled);
if (!enabled) { if (!enabled) {
setConnectionEditControlValues(0); setConnectionEditControlValues(nullptr);
} }
} }
@ -326,7 +327,7 @@ void Editor::setMap(QString map_name) {
} }
if (project) { if (project) {
map = project->loadMap(map_name); map = project->loadMap(map_name);
connect(map, &Map::paintTileChanged, [=](Map *map) { connect(map, &Map::paintTileChanged, [=]() {
lastSelectedMetatilesFromMap = false; lastSelectedMetatilesFromMap = false;
redrawCurrentMetatilesSelection(); redrawCurrentMetatilesSelection();
}); });
@ -561,7 +562,7 @@ void Editor::displayMapConnections() {
} }
delete item; delete item;
} }
selected_connection_item = NULL; selected_connection_item = nullptr;
connection_edit_items.clear(); connection_edit_items.clear();
for (Connection *connection : map->connections) { for (Connection *connection : map->connections) {
@ -756,8 +757,7 @@ void Editor::updateMirroredConnection(Connection* connection, QString originalDi
QString oppositeDirection = oppositeDirections.value(originalDirection); QString oppositeDirection = oppositeDirections.value(originalDirection);
// Find the matching connection in the connected map. // Find the matching connection in the connected map.
QMap<QString, Map*> *mapcache = project->map_cache; Connection* mirrorConnection = nullptr;
Connection* mirrorConnection = NULL;
Map* otherMap = project->getMap(originalMapName); Map* otherMap = project->getMap(originalMapName);
for (Connection* conn : otherMap->connections) { for (Connection* conn : otherMap->connections) {
if (conn->direction == oppositeDirection && conn->map_name == map->name) { if (conn->direction == oppositeDirection && conn->map_name == map->name) {
@ -777,7 +777,7 @@ void Editor::updateMirroredConnection(Connection* connection, QString originalDi
if (mirrorConnection) { if (mirrorConnection) {
otherMap->connections.removeOne(mirrorConnection); otherMap->connections.removeOne(mirrorConnection);
delete mirrorConnection; delete mirrorConnection;
mirrorConnection = NULL; mirrorConnection = nullptr;
otherMap = project->getMap(connection->map_name); otherMap = project->getMap(connection->map_name);
} }
} }
@ -806,7 +806,7 @@ void Editor::removeCurrentConnection() {
delete selected_connection_item; delete selected_connection_item;
} }
selected_connection_item = NULL; selected_connection_item = nullptr;
setConnectionEditControlsEnabled(false); setConnectionEditControlsEnabled(false);
ui->spinBox_ConnectionOffset->setValue(0); ui->spinBox_ConnectionOffset->setValue(0);
ui->label_NumConnections->setText(QString::number(map->connections.length())); ui->label_NumConnections->setText(QString::number(map->connections.length()));
@ -830,7 +830,7 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
return; return;
} }
Connection* connection = NULL; Connection* connection = nullptr;
for (Connection* conn : map->connections) { for (Connection* conn : map->connections) {
if (conn->direction == direction) { if (conn->direction == direction) {
connection = conn; connection = conn;
@ -888,7 +888,7 @@ void Editor::toggleBorderVisibility(bool visible)
this->setConnectionsVisibility(visible); this->setConnectionsVisibility(visible);
} }
void MetatilesPixmapItem::paintTileChanged(Map *map) { void MetatilesPixmapItem::paintTileChanged() {
draw(); draw();
} }
@ -897,8 +897,8 @@ void MetatilesPixmapItem::draw() {
} }
void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) { void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
int x = ((int)pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = ((int)pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
int width = pixmap().width() / 16; int width = pixmap().width() / 16;
int height = pixmap().height() / 16; int height = pixmap().height() / 16;
if (x < 0 || x >= width || y < 0 || y >= height) { if (x < 0 || x >= width || y < 0 || y >= height) {
@ -912,13 +912,13 @@ void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
void MetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { void MetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
updateCurHoveredMetatile(event->pos()); updateCurHoveredMetatile(event->pos());
} }
void MetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { void MetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
map->clearHoveredMetatile(); map->clearHoveredMetatile();
} }
void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = ((int)pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = ((int)pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
map->paint_metatile_initial_x = x; map->paint_metatile_initial_x = x;
map->paint_metatile_initial_y = y; map->paint_metatile_initial_y = y;
updateSelection(event->pos()); updateSelection(event->pos());
@ -931,8 +931,8 @@ void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
updateSelection(event->pos()); updateSelection(event->pos());
} }
void MetatilesPixmapItem::updateSelection(QPointF pos) { void MetatilesPixmapItem::updateSelection(QPointF pos) {
int x = ((int)pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = ((int)pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
int width = pixmap().width() / 16; int width = pixmap().width() / 16;
int height = pixmap().height() / 16; int height = pixmap().height() / 16;
if ((x >= 0 && x < width) && (y >=0 && y < height)) { if ((x >= 0 && x < width) && (y >=0 && y < height)) {
@ -943,19 +943,19 @@ void MetatilesPixmapItem::updateSelection(QPointF pos) {
map->paint_tile_height = abs(map->paint_metatile_initial_y - y) + 1; map->paint_tile_height = abs(map->paint_metatile_initial_y - y) + 1;
map->setSelectedMetatilesFromTilePicker(); map->setSelectedMetatilesFromTilePicker();
emit map->paintTileChanged(map); emit map->paintTileChanged();
} }
} }
void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = ((int)pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = ((int)pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
for (int i = 0; i < map->selected_metatiles_width && (i + x) < 2; i++) { for (int i = 0; i < map->selected_metatiles_width && (i + x) < 2; i++) {
for (int j = 0; j < map->selected_metatiles_height && (j + y) < 2; j++) { for (int j = 0; j < map->selected_metatiles_height && (j + y) < 2; j++) {
int blockIndex = (j + y) * 2 + (i + x); int blockIndex = (j + y) * 2 + (i + x);
int tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i); uint16_t tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i);
(*map->layout->border->blocks)[blockIndex].tile = tile; (*map->layout->border->blocks)[blockIndex].tile = tile;
} }
} }
@ -1007,8 +1007,8 @@ void CurrentSelectedMetatilesPixmapItem::draw() {
void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = ((int)pos.x()) / 32; int x = static_cast<int>(pos.x()) / 32;
int y = ((int)pos.y()) / 32; int y = static_cast<int>(pos.y()) / 32;
int width = pixmap().width() / 32; int width = pixmap().width() / 32;
int height = pixmap().height() / 32; int height = pixmap().height() / 32;
@ -1017,7 +1017,7 @@ void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* ev
if (x >= width) x = width - 1; if (x >= width) x = width - 1;
if (y < 0) y = 0; if (y < 0) y = 0;
if (y >= height) y = height - 1; if (y >= height) y = height - 1;
pick(x, y); pick(static_cast<uint16_t>(x), static_cast<uint16_t>(y));
} }
void MovementPermissionsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { void MovementPermissionsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
updateCurHoveredMetatile(event->pos()); updateCurHoveredMetatile(event->pos());
@ -1028,8 +1028,8 @@ void MovementPermissionsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent*
} }
void MovementPermissionsPixmapItem::updateCurHoveredMetatile(QPointF pos) { void MovementPermissionsPixmapItem::updateCurHoveredMetatile(QPointF pos) {
int x = ((int)pos.x()) / 32; int x = static_cast<int>(pos.x()) / 32;
int y = ((int)pos.y()) / 32; int y = static_cast<int>(pos.y()) / 32;
int width = pixmap().width() / 32; int width = pixmap().width() / 32;
int height = pixmap().height() / 32; int height = pixmap().height() / 32;
@ -1090,7 +1090,7 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
return QGraphicsItem::itemChange(change, value); return QGraphicsItem::itemChange(change, value);
} }
} }
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) {
emit connectionItemSelected(this); emit connectionItemSelected(this);
} }
void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) { void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
@ -1103,8 +1103,8 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
map->commit(); map->commit();
} else { } else {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
// Paint onto the map. // Paint onto the map.
bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier; bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier;
@ -1125,8 +1125,8 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
map->commit(); map->commit();
} else { } else {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
if (event->type() == QEvent::GraphicsSceneMousePress) { if (event->type() == QEvent::GraphicsSceneMousePress) {
selection_origin = QPoint(x, y); selection_origin = QPoint(x, y);
@ -1138,8 +1138,6 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
Blockdata *backupBlockdata = map->layout->blockdata->copy(); Blockdata *backupBlockdata = map->layout->blockdata->copy();
for (int i = 0; i < map->getWidth(); i++) for (int i = 0; i < map->getWidth(); i++)
for (int j = 0; j < map->getHeight(); j++) { for (int j = 0; j < map->getHeight(); j++) {
int srcX = i;
int srcY = j;
int destX = i + xDelta; int destX = i + xDelta;
int destY = j + yDelta; int destY = j + yDelta;
if (destX < 0) if (destX < 0)
@ -1215,7 +1213,7 @@ void MapPixmapItem::paintSmartPath(int x, int y) {
if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return; if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return;
// Shift to the middle tile of the smart path selection. // Shift to the middle tile of the smart path selection.
int openTile = map->selected_metatiles->at(4); uint16_t openTile = map->selected_metatiles->at(4);
// Fill the region with the open tile. // Fill the region with the open tile.
for (int i = 0; i <= 1; i++) for (int i = 0; i <= 1; i++)
@ -1274,8 +1272,8 @@ void MapPixmapItem::paintSmartPath(int x, int y) {
void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) { void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
// Snap point to within map bounds. // Snap point to within map bounds.
if (x < 0) x = 0; if (x < 0) x = 0;
@ -1328,8 +1326,8 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
map->commit(); map->commit();
} else { } else {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
Block *block = map->getBlock(x, y); Block *block = map->getBlock(x, y);
int tile = map->selected_metatiles->first(); int tile = map->selected_metatiles->first();
if (block && block->tile != tile) { if (block && block->tile != tile) {
@ -1354,7 +1352,7 @@ void MapPixmapItem::_floodFill(int initialX, int initialY) {
int y = point.y(); int y = point.y();
Block *block = map->getBlock(x, y); Block *block = map->getBlock(x, y);
if (block == NULL) { if (!block) {
continue; continue;
} }
@ -1364,8 +1362,8 @@ void MapPixmapItem::_floodFill(int initialX, int initialY) {
int j = yDiff % map->selected_metatiles_height; int j = yDiff % map->selected_metatiles_height;
if (i < 0) i = map->selected_metatiles_width + i; if (i < 0) i = map->selected_metatiles_width + i;
if (j < 0) j = map->selected_metatiles_height + j; if (j < 0) j = map->selected_metatiles_height + j;
int tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i); uint16_t tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i);
uint old_tile = block->tile; uint16_t old_tile = block->tile;
if (old_tile == tile) { if (old_tile == tile) {
continue; continue;
} }
@ -1392,7 +1390,7 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return; if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return;
// Shift to the middle tile of the smart path selection. // Shift to the middle tile of the smart path selection.
int openTile = map->selected_metatiles->at(4); uint16_t openTile = map->selected_metatiles->at(4);
// Flood fill the region with the open tile. // Flood fill the region with the open tile.
QList<QPoint> todo; QList<QPoint> todo;
@ -1403,11 +1401,11 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
int y = point.y(); int y = point.y();
Block *block = map->getBlock(x, y); Block *block = map->getBlock(x, y);
if (block == NULL) { if (!block) {
continue; continue;
} }
uint old_tile = block->tile; uint16_t old_tile = block->tile;
if (old_tile == openTile) { if (old_tile == openTile) {
continue; continue;
} }
@ -1430,8 +1428,9 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
// Go back and resolve the flood-filled edge tiles. // Go back and resolve the flood-filled edge tiles.
// Mark tiles as visited while we go. // Mark tiles as visited while we go.
bool visited[map->getWidth() * map->getHeight()]; int numMetatiles = map->getWidth() * map->getHeight();
for (int i = 0; i < sizeof visited; i++) bool *visited = new bool[numMetatiles];
for (int i = 0; i < numMetatiles; i++)
visited[i] = false; visited[i] = false;
todo.append(QPoint(initialX, initialY)); todo.append(QPoint(initialX, initialY));
@ -1442,7 +1441,7 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
visited[x + y * map->getWidth()] = true; visited[x + y * map->getWidth()] = true;
Block *block = map->getBlock(x, y); Block *block = map->getBlock(x, y);
if (block == NULL) { if (!block) {
continue; continue;
} }
@ -1483,12 +1482,14 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
visited[x + (y - 1) * map->getWidth()] = true; visited[x + (y - 1) * map->getWidth()] = true;
} }
} }
delete[] visited;
} }
void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) { void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
Block *block = map->getBlock(x, y); Block *block = map->getBlock(x, y);
if (block) { if (block) {
map->paint_tile_index = map->getDisplayedBlockIndex(block->tile); map->paint_tile_index = map->getDisplayedBlockIndex(block->tile);
@ -1496,14 +1497,14 @@ void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
map->paint_tile_height = 1; map->paint_tile_height = 1;
map->setSelectedMetatilesFromTilePicker(); map->setSelectedMetatilesFromTilePicker();
emit map->paintTileChanged(map); emit map->paintTileChanged();
} }
} }
void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) { void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
if (event->type() == QEvent::GraphicsSceneMousePress) { if (event->type() == QEvent::GraphicsSceneMousePress) {
selection_origin = QPoint(x, y); selection_origin = QPoint(x, y);
selection.clear(); selection.clear();
@ -1539,8 +1540,8 @@ void MapPixmapItem::draw(bool ignoreCache) {
} }
void MapPixmapItem::updateCurHoveredTile(QPointF pos) { void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
int x = ((int)pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = ((int)pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
int blockIndex = y * map->getWidth() + x; int blockIndex = y * map->getWidth() + x;
if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) { if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
map->clearHoveredTile(); map->clearHoveredTile();
@ -1562,7 +1563,7 @@ void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
setCursor(editor->cursor); setCursor(editor->cursor);
} }
} }
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
map->clearHoveredTile(); map->clearHoveredTile();
if (editor->ui->actionBetter_Cursors->isChecked()){ if (editor->ui->actionBetter_Cursors->isChecked()){
unsetCursor(); unsetCursor();
@ -1570,8 +1571,8 @@ void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
} }
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = ((int)pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = ((int)pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
map->paint_tile_initial_x = x; map->paint_tile_initial_x = x;
map->paint_tile_initial_y = y; map->paint_tile_initial_y = y;
emit mouseEvent(event, this); emit mouseEvent(event, this);
@ -1603,16 +1604,12 @@ void CollisionPixmapItem::draw(bool ignoreCache) {
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) { void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
if (map) { if (map) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
Block *block = map->getBlock(x, y); Block *block = map->getBlock(x, y);
if (block) { if (block) {
if (map->paint_collision >= 0) {
block->collision = map->paint_collision; block->collision = map->paint_collision;
}
if (map->paint_elevation >= 0) {
block->elevation = map->paint_elevation; block->elevation = map->paint_elevation;
}
map->_setBlock(x, y, *block); map->_setBlock(x, y, *block);
} }
if (event->type() == QEvent::GraphicsSceneMouseRelease) { if (event->type() == QEvent::GraphicsSceneMouseRelease) {
@ -1625,25 +1622,17 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) { void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
if (map) { if (map) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
bool collision = map->paint_collision >= 0;
bool elevation = map->paint_elevation >= 0;
if (collision && elevation) {
map->floodFillCollisionElevation(x, y, map->paint_collision, map->paint_elevation); map->floodFillCollisionElevation(x, y, map->paint_collision, map->paint_elevation);
} else if (collision) {
map->floodFillCollision(x, y, map->paint_collision);
} else if (elevation) {
map->floodFillElevation(x, y, map->paint_elevation);
}
draw(); draw();
} }
} }
void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) { void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
Block *block = map->getBlock(x, y); Block *block = map->getBlock(x, y);
if (block) { if (block) {
map->paint_collision = block->collision; map->paint_collision = block->collision;
@ -1654,8 +1643,8 @@ void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event) { void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos(); QPointF pos = event->pos();
int x = (int)(pos.x()) / 16; int x = static_cast<int>(pos.x()) / 16;
int y = (int)(pos.y()) / 16; int y = static_cast<int>(pos.y()) / 16;
// Snap point to within map bounds. // Snap point to within map bounds.
if (x < 0) x = 0; if (x < 0) x = 0;
@ -1663,17 +1652,16 @@ void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseE
if (y < 0) y = 0; if (y < 0) y = 0;
if (y >= map->getHeight()) y = map->getHeight() - 1; if (y >= map->getHeight()) y = map->getHeight() - 1;
int collision = map->getBlock(x, y)->collision; Block *block = map->getBlock(x, y);
int elevation = map->getBlock(x, y)->elevation; map->paint_collision = block->collision;
map->paint_collision = collision; map->paint_elevation = block->elevation;
map->paint_elevation = elevation;
editor->collision_metatiles_item->draw(); editor->collision_metatiles_item->draw();
} }
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) { void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
active = true; active = true;
last_x = (mouse->pos().x() + this->pos().x()) / 16; last_x = static_cast<int>(mouse->pos().x() + this->pos().x()) / 16;
last_y = (mouse->pos().y() + this->pos().y()) / 16; last_y = static_cast<int>(mouse->pos().y() + this->pos().y()) / 16;
this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier); this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
this->editor->updateSelectedEvents(); this->editor->updateSelectedEvents();
selectingEvent = true; selectingEvent = true;
@ -1689,8 +1677,8 @@ void DraggablePixmapItem::move(int x, int y) {
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) { void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
if (active) { if (active) {
int x = (mouse->pos().x() + this->pos().x()) / 16; int x = static_cast<int>(mouse->pos().x() + this->pos().x()) / 16;
int y = (mouse->pos().y() + this->pos().y()) / 16; int y = static_cast<int>(mouse->pos().y() + this->pos().y()) / 16;
if (x != last_x || y != last_y) { if (x != last_x || y != last_y) {
if (editor->selected_events->contains(this)) { if (editor->selected_events->contains(this)) {
for (DraggablePixmapItem *item : *editor->selected_events) { for (DraggablePixmapItem *item : *editor->selected_events) {
@ -1706,11 +1694,11 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
} }
} }
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) { void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
active = false; active = false;
} }
void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouse) { void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
if (this->event->get("event_type") == EventType::Warp) { if (this->event->get("event_type") == EventType::Warp) {
emit editor->warpEventDoubleClicked(this->event->get("destination_map_name"), this->event->get("destination_warp")); emit editor->warpEventDoubleClicked(this->event->get("destination_map_name"), this->event->get("destination_warp"));
} }
@ -1720,7 +1708,7 @@ QList<DraggablePixmapItem *> *Editor::getObjects() {
QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>; QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
for (Event *event : map->getAllEvents()) { for (Event *event : map->getAllEvents()) {
for (QGraphicsItem *child : events_group->childItems()) { for (QGraphicsItem *child : events_group->childItems()) {
DraggablePixmapItem *item = (DraggablePixmapItem *)child; DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
if (item->event == event) { if (item->event == event) {
list->append(item); list->append(item);
break; break;
@ -1779,10 +1767,9 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
map->addEvent(event); map->addEvent(event);
project->loadEventPixmaps(map->getAllEvents()); project->loadEventPixmaps(map->getAllEvents());
DraggablePixmapItem *object = addMapEvent(event); DraggablePixmapItem *object = addMapEvent(event);
return object; return object;
} }
return NULL; return nullptr;
} }
void Editor::deleteEvent(Event *event) { void Editor::deleteEvent(Event *event) {

View file

@ -30,9 +30,9 @@ public:
Editor(Ui::MainWindow* ui); Editor(Ui::MainWindow* ui);
public: public:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QObject *parent = NULL; QObject *parent = nullptr;
Project *project = NULL; Project *project = nullptr;
Map *map = NULL; Map *map = nullptr;
void saveProject(); void saveProject();
void save(); void save();
void undo(); void undo();
@ -79,35 +79,35 @@ public:
void redrawObject(DraggablePixmapItem *item); void redrawObject(DraggablePixmapItem *item);
QList<DraggablePixmapItem *> *getObjects(); QList<DraggablePixmapItem *> *getObjects();
QGraphicsScene *scene = NULL; QGraphicsScene *scene = nullptr;
QGraphicsPixmapItem *current_view = NULL; QGraphicsPixmapItem *current_view = nullptr;
MapPixmapItem *map_item = NULL; MapPixmapItem *map_item = nullptr;
ConnectionPixmapItem* selected_connection_item = NULL; ConnectionPixmapItem* selected_connection_item = nullptr;
QList<QGraphicsPixmapItem*> connection_items; QList<QGraphicsPixmapItem*> connection_items;
QList<ConnectionPixmapItem*> connection_edit_items; QList<ConnectionPixmapItem*> connection_edit_items;
CollisionPixmapItem *collision_item = NULL; CollisionPixmapItem *collision_item = nullptr;
QGraphicsItemGroup *events_group = NULL; QGraphicsItemGroup *events_group = nullptr;
QList<QGraphicsPixmapItem*> borderItems; QList<QGraphicsPixmapItem*> borderItems;
QList<QGraphicsLineItem*> gridLines; QList<QGraphicsLineItem*> gridLines;
QGraphicsScene *scene_metatiles = NULL; QGraphicsScene *scene_metatiles = nullptr;
QGraphicsScene *scene_current_metatile_selection = NULL; QGraphicsScene *scene_current_metatile_selection = nullptr;
QGraphicsScene *scene_selected_border_metatiles = NULL; QGraphicsScene *scene_selected_border_metatiles = nullptr;
QGraphicsScene *scene_collision_metatiles = NULL; QGraphicsScene *scene_collision_metatiles = nullptr;
QGraphicsScene *scene_elevation_metatiles = NULL; QGraphicsScene *scene_elevation_metatiles = nullptr;
MetatilesPixmapItem *metatiles_item = NULL; MetatilesPixmapItem *metatiles_item = nullptr;
BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL; BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = NULL; CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = nullptr;
MovementPermissionsPixmapItem *collision_metatiles_item = NULL; MovementPermissionsPixmapItem *collision_metatiles_item = nullptr;
QList<DraggablePixmapItem*> *events = NULL; QList<DraggablePixmapItem*> *events = nullptr;
QList<DraggablePixmapItem*> *selected_events = NULL; QList<DraggablePixmapItem*> *selected_events = nullptr;
bool lastSelectedMetatilesFromMap = false; bool lastSelectedMetatilesFromMap = false;
int copiedMetatileSelectionWidth = 0; int copiedMetatileSelectionWidth = 0;
int copiedMetatileSelectionHeight = 0; int copiedMetatileSelectionHeight = 0;
QList<int> *copiedMetatileSelection = new QList<int>; QList<uint16_t> *copiedMetatileSelection = new QList<uint16_t>;
QString map_edit_mode; QString map_edit_mode;
QString prev_edit_mode; QString prev_edit_mode;
@ -166,9 +166,9 @@ class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
public: public:
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) { DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
} }
Editor *editor = NULL; Editor *editor = nullptr;
Event *event = NULL; Event *event = nullptr;
QGraphicsItemAnimation *pos_anim = NULL; QGraphicsItemAnimation *pos_anim = nullptr;
DraggablePixmapItem(Event *event_, Editor *editor_) : QGraphicsPixmapItem(event_->pixmap) { DraggablePixmapItem(Event *event_, Editor *editor_) : QGraphicsPixmapItem(event_->pixmap) {
event = event_; event = event_;
editor = editor_; editor = editor_;
@ -257,8 +257,8 @@ class MapPixmapItem : public QObject, public QGraphicsPixmapItem {
public: public:
MapPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) { MapPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
} }
Map *map = NULL; Map *map = nullptr;
Editor *editor = NULL; Editor *editor = nullptr;
MapPixmapItem(Map *map_, Editor *editor_) { MapPixmapItem(Map *map_, Editor *editor_) {
map = map_; map = map_;
editor = editor_; editor = editor_;
@ -335,7 +335,7 @@ public:
QPixmap newPixmap = basePixmap.copy(0, 0, basePixmap.width(), basePixmap.height()); QPixmap newPixmap = basePixmap.copy(0, 0, basePixmap.width(), basePixmap.height());
if (opacity < 1) { if (opacity < 1) {
QPainter painter(&newPixmap); QPainter painter(&newPixmap);
int alpha = (int)(255 * (1 - opacity)); int alpha = static_cast<int>(255 * (1 - opacity));
painter.fillRect(0, 0, newPixmap.width(), newPixmap.height(), QColor(0, 0, 0, alpha)); painter.fillRect(0, 0, newPixmap.width(), newPixmap.height(), QColor(0, 0, 0, alpha));
painter.end(); painter.end();
} }
@ -366,16 +366,16 @@ public:
MetatilesPixmapItem(Map *map_) { MetatilesPixmapItem(Map *map_) {
map = map_; map = map_;
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
connect(map, SIGNAL(paintTileChanged(Map*)), this, SLOT(paintTileChanged(Map *))); connect(map, SIGNAL(paintTileChanged()), this, SLOT(paintTileChanged()));
} }
Map* map = NULL; Map* map = nullptr;
virtual void draw(); virtual void draw();
private: private:
void updateSelection(QPointF pos); void updateSelection(QPointF pos);
protected: protected:
virtual void updateCurHoveredMetatile(QPointF pos); virtual void updateCurHoveredMetatile(QPointF pos);
private slots: private slots:
void paintTileChanged(Map *map); void paintTileChanged();
protected: protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent*); void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*); void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
@ -391,7 +391,7 @@ public:
map = map_; map = map_;
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
} }
Map* map = NULL; Map* map = nullptr;
virtual void draw(); virtual void draw();
signals: signals:
void borderMetatilesChanged(); void borderMetatilesChanged();
@ -405,7 +405,7 @@ public:
CurrentSelectedMetatilesPixmapItem(Map *map_) { CurrentSelectedMetatilesPixmapItem(Map *map_) {
map = map_; map = map_;
} }
Map* map = NULL; Map* map = nullptr;
virtual void draw(); virtual void draw();
}; };
@ -415,7 +415,7 @@ public:
MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) { MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *))); connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
} }
virtual void pick(uint collision, uint elevation) { virtual void pick(uint16_t collision, uint16_t elevation) {
map->paint_collision = collision; map->paint_collision = collision;
map->paint_elevation = elevation; map->paint_elevation = elevation;
draw(); draw();
@ -429,7 +429,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent*); void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
virtual void updateCurHoveredMetatile(QPointF pos); virtual void updateCurHoveredMetatile(QPointF pos);
private slots: private slots:
void paintCollisionChanged(Map *map) { void paintCollisionChanged(Map *) {
draw(); draw();
} }
}; };

View file

@ -18,7 +18,7 @@ Event::Event()
Event* Event::createNewEvent(QString event_type, QString map_name) Event* Event::createNewEvent(QString event_type, QString map_name)
{ {
Event *event; Event *event = new Event;
if (event_type == EventType::Object) { if (event_type == EventType::Object) {
event = createNewObjectEvent(); event = createNewObjectEvent();
} else if (event_type == EventType::Warp) { } else if (event_type == EventType::Warp) {
@ -142,8 +142,8 @@ QString Event::buildObjectEventMacro(int item_index)
{ {
int radius_x = this->getInt("radius_x"); int radius_x = this->getInt("radius_x");
int radius_y = this->getInt("radius_y"); int radius_y = this->getInt("radius_y");
uint16_t x = this->getInt("x"); uint16_t x = this->getU16("x");
uint16_t y = this->getInt("y"); uint16_t y = this->getU16("y");
QString text = ""; QString text = "";
text += QString("\tobject_event %1").arg(item_index + 1); text += QString("\tobject_event %1").arg(item_index + 1);
@ -185,8 +185,8 @@ HealLocation Event::buildHealLocation()
catch(...) { catch(...) {
hl.index = 0; hl.index = 0;
} }
hl.x = this->get("x").toInt(); hl.x = this->getU16("x");
hl.y = this->get("y").toInt(); hl.y = this->getU16("y");
return hl; return hl;
} }

View file

@ -46,6 +46,9 @@ public:
int getInt(QString key) { int getInt(QString key) {
return values.value(key).toInt(nullptr, 0); return values.value(key).toInt(nullptr, 0);
} }
uint16_t getU16(QString key) {
return values.value(key).toUShort(nullptr, 0);
}
void put(QString key, int value) { void put(QString key, int value) {
put(key, QString("%1").arg(value)); put(key, QString("%1").arg(value));
} }

View file

@ -6,18 +6,6 @@
class Editor; class Editor;
/*
class GraphicsView_Object : public QObject
{
Q_OBJECT
signals:
void onMousePress(QMouseEvent *event);
void onMouseMove(QMouseEvent *event);
void onMouseRelease(QMouseEvent *event);
};
*/
class GraphicsView : public QGraphicsView class GraphicsView : public QGraphicsView
{ {
public: public:

View file

@ -1,19 +1,15 @@
#include "heallocation.h" #include "heallocation.h"
//HealLocation::HealLocation() {} HealLocation::HealLocation(QString map, int i, uint16_t x, uint16_t y)
{
HealLocation::HealLocation(QString map, int i, size_t x0, size_t y0) { this->name = map;
this->index = i;
name = map; this->x = x;
index = i; this->y = y;
x = x0;
y = y0;
} }
QDebug operator<<(QDebug debug, const HealLocation &hl) { QDebug operator<<(QDebug debug, const HealLocation &hl)
{
debug << "HealLocation_" + hl.name << "(" << hl.x << ',' << hl.y << ")"; debug << "HealLocation_" + hl.name << "(" << hl.x << ',' << hl.y << ")";
return debug; return debug;
} }

View file

@ -8,15 +8,15 @@ class HealLocation {
public: public:
HealLocation()=default; HealLocation()=default;
HealLocation(QString, int, size_t, size_t); HealLocation(QString, int, uint16_t, uint16_t);
friend QDebug operator<<(QDebug debug, const HealLocation &hl); friend QDebug operator<<(QDebug debug, const HealLocation &hl);
public: public:
//QString group; //QString group;
QString name; QString name;
int index; int index;
size_t x; uint16_t x;
size_t y; uint16_t y;
}; };

View file

@ -29,7 +29,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
QCoreApplication::setOrganizationName("pret"); QCoreApplication::setOrganizationName("pret");
QCoreApplication::setApplicationName("pretmap"); QCoreApplication::setApplicationName("porymap");
QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-1.ico"));
ui->setupUi(this); ui->setupUi(this);
@ -80,19 +81,19 @@ void MainWindow::openProject(QString dir) {
setStatusBarMessage(QString("Opening project %1").arg(dir)); setStatusBarMessage(QString("Opening project %1").arg(dir));
bool already_open = ( bool already_open = (
(editor != NULL && editor != nullptr) (editor && editor != nullptr)
&& (editor->project != NULL && editor->project != nullptr) && (editor->project && editor->project != nullptr)
&& (editor->project->root == dir) && (editor->project->root == dir)
); );
if (!already_open) { if (!already_open) {
editor->project = new Project; editor->project = new Project;
editor->project->root = dir; editor->project->root = dir;
setWindowTitle(editor->project->getProjectTitle() + " - pretmap"); setWindowTitle(editor->project->getProjectTitle() + " - porymap");
loadDataStructures(); loadDataStructures();
populateMapList(); populateMapList();
setMap(getDefaultMap()); setMap(getDefaultMap());
} else { } else {
setWindowTitle(editor->project->getProjectTitle() + " - pretmap"); setWindowTitle(editor->project->getProjectTitle() + " - porymap");
loadDataStructures(); loadDataStructures();
populateMapList(); populateMapList();
} }
@ -164,10 +165,10 @@ void MainWindow::setMap(QString map_name) {
redrawMapScene(); redrawMapScene();
displayMapProperties(); displayMapProperties();
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap"); setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - porymap");
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *))); connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
connect(editor->map, SIGNAL(mapNeedsRedrawing(Map*)), this, SLOT(onMapNeedsRedrawing(Map *))); connect(editor->map, SIGNAL(mapNeedsRedrawing()), this, SLOT(onMapNeedsRedrawing()));
connect(editor->map, SIGNAL(statusBarMessage(QString)), this, SLOT(setStatusBarMessage(QString))); connect(editor->map, SIGNAL(statusBarMessage(QString)), this, SLOT(setStatusBarMessage(QString)));
setRecentMap(map_name); setRecentMap(map_name);
@ -181,16 +182,16 @@ void MainWindow::redrawMapScene()
ui->graphicsView_Map->setScene(editor->scene); ui->graphicsView_Map->setScene(editor->scene);
ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect()); ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect());
ui->graphicsView_Map->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2); ui->graphicsView_Map->setFixedSize(static_cast<int>(editor->scene->width()) + 2, static_cast<int>(editor->scene->height()) + 2);
ui->graphicsView_Objects_Map->setScene(editor->scene); ui->graphicsView_Objects_Map->setScene(editor->scene);
ui->graphicsView_Objects_Map->setSceneRect(editor->scene->sceneRect()); ui->graphicsView_Objects_Map->setSceneRect(editor->scene->sceneRect());
ui->graphicsView_Objects_Map->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2); ui->graphicsView_Objects_Map->setFixedSize(static_cast<int>(editor->scene->width()) + 2, static_cast<int>(editor->scene->height()) + 2);
ui->graphicsView_Objects_Map->editor = editor; ui->graphicsView_Objects_Map->editor = editor;
ui->graphicsView_Connections->setScene(editor->scene); ui->graphicsView_Connections->setScene(editor->scene);
ui->graphicsView_Connections->setSceneRect(editor->scene->sceneRect()); ui->graphicsView_Connections->setSceneRect(editor->scene->sceneRect());
ui->graphicsView_Connections->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2); ui->graphicsView_Connections->setFixedSize(static_cast<int>(editor->scene->width()) + 2, static_cast<int>(editor->scene->height()) + 2);
ui->graphicsView_Metatiles->setScene(editor->scene_metatiles); ui->graphicsView_Metatiles->setScene(editor->scene_metatiles);
//ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect()); //ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect());
@ -507,7 +508,6 @@ void MainWindow::on_mapList_activated(const QModelIndex &index)
if (!data.isNull()) { if (!data.isNull()) {
setMap(data.toString()); setMap(data.toString());
} }
//updateMapList();
} }
void MainWindow::markAllEdited(QAbstractItemModel *model) { void MainWindow::markAllEdited(QAbstractItemModel *model) {
@ -651,18 +651,17 @@ void MainWindow::on_actionMap_Shift_triggered()
void MainWindow::scaleMapView(int s) { void MainWindow::scaleMapView(int s) {
editor->map->scale_exp += s; editor->map->scale_exp += s;
double base = (double)editor->map->scale_base; double base = editor->map->scale_base;
double exp = editor->map->scale_exp; double exp = editor->map->scale_exp;
double sfactor = pow(base,s); double sfactor = pow(base,s);
ui->graphicsView_Map->scale(sfactor,sfactor); ui->graphicsView_Map->scale(sfactor,sfactor);
ui->graphicsView_Objects_Map->scale(sfactor,sfactor); ui->graphicsView_Objects_Map->scale(sfactor,sfactor);
ui->graphicsView_Map->setFixedSize((editor->scene->width() + 2) * pow(base,exp), int width = static_cast<int>((editor->scene->width() + 2) * pow(base,exp));
(editor->scene->height() + 2) * pow(base,exp)); int height = static_cast<int>((editor->scene->height() + 2) * pow(base,exp));
ui->graphicsView_Map->setFixedSize(width, height);
ui->graphicsView_Objects_Map->setFixedSize((editor->scene->width() + 2) * pow(base,exp), ui->graphicsView_Objects_Map->setFixedSize(width, height);
(editor->scene->height() + 2) * pow(base,exp));
} }
void MainWindow::addNewEvent(QString event_type) void MainWindow::addNewEvent(QString event_type)
@ -679,7 +678,7 @@ void MainWindow::addNewEvent(QString event_type)
// Should probably just pass layout and let the editor work it out // Should probably just pass layout and let the editor work it out
void MainWindow::updateSelectedObjects() { void MainWindow::updateSelectedObjects() {
QList<DraggablePixmapItem *> *all_events = editor->getObjects(); QList<DraggablePixmapItem *> *all_events = editor->getObjects();
QList<DraggablePixmapItem *> *events = NULL; QList<DraggablePixmapItem *> *events = nullptr;
if (editor->selected_events && editor->selected_events->length()) { if (editor->selected_events && editor->selected_events->length()) {
events = editor->selected_events; events = editor->selected_events;
@ -1053,7 +1052,7 @@ void MainWindow::onMapChanged(Map *map) {
updateMapList(); updateMapList();
} }
void MainWindow::onMapNeedsRedrawing(Map *map) { void MainWindow::onMapNeedsRedrawing() {
redrawMapScene(); redrawMapScene();
} }
@ -1167,7 +1166,7 @@ void MainWindow::on_pushButton_clicked()
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
editor->map->setDimensions(widthSpinBox->value(), heightSpinBox->value()); editor->map->setDimensions(widthSpinBox->value(), heightSpinBox->value());
editor->map->commit(); editor->map->commit();
onMapNeedsRedrawing(editor->map); onMapNeedsRedrawing();
} }
} }

View file

@ -22,7 +22,7 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
public slots: public slots:
@ -41,7 +41,7 @@ private slots:
void onLoadMapRequested(QString, QString); void onLoadMapRequested(QString, QString);
void onMapChanged(Map *map); void onMapChanged(Map *map);
void onMapNeedsRedrawing(Map *map); void onMapNeedsRedrawing();
void on_action_Save_triggered(); void on_action_Save_triggered();
void on_tabWidget_2_currentChanged(int index); void on_tabWidget_2_currentChanged(int index);
@ -125,7 +125,7 @@ private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QStandardItemModel *mapListModel; QStandardItemModel *mapListModel;
QList<QStandardItem*> *mapGroupsModel; QList<QStandardItem*> *mapGroupsModel;
Editor *editor = NULL; Editor *editor = nullptr;
QIcon* mapIcon; QIcon* mapIcon;
void setMap(QString); void setMap(QString);
void redrawMapScene(); void redrawMapScene();

View file

@ -17,7 +17,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>pretmap</string> <string>porymap</string>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">

126
map.cpp
View file

@ -14,7 +14,7 @@ Map::Map(QObject *parent) : QObject(parent)
paint_elevation = 3; paint_elevation = 3;
selected_metatiles_width = 1; selected_metatiles_width = 1;
selected_metatiles_height = 1; selected_metatiles_height = 1;
selected_metatiles = new QList<int>; selected_metatiles = new QList<uint16_t>;
selected_metatiles->append(1); selected_metatiles->append(1);
} }
@ -64,11 +64,11 @@ int Map::getHeight() {
return layout->height.toInt(nullptr, 0); return layout->height.toInt(nullptr, 0);
} }
int Map::getSelectedBlockIndex(int index) { uint16_t Map::getSelectedBlockIndex(int index) {
if (index < layout->tileset_primary->metatiles->length()) { if (index < layout->tileset_primary->metatiles->length()) {
return index; return static_cast<uint16_t>(index);
} else { } else {
return 0x200 + (index - layout->tileset_primary->metatiles->length()); return 0x200 + static_cast<uint16_t>(index - layout->tileset_primary->metatiles->length());
} }
} }
@ -92,24 +92,19 @@ QImage Map::getCollisionMetatileImage(int collision, int elevation) {
} }
bool Map::blockChanged(int i, Blockdata *cache) { bool Map::blockChanged(int i, Blockdata *cache) {
if (cache == NULL || cache == nullptr) { if (!cache)
return true; return true;
} if (!layout->blockdata)
if (layout->blockdata == NULL || layout->blockdata == nullptr) {
return true; return true;
} if (!cache->blocks)
if (cache->blocks == NULL || cache->blocks == nullptr) {
return true; return true;
} if (!layout->blockdata->blocks)
if (layout->blockdata->blocks == NULL || layout->blockdata->blocks == nullptr) {
return true; return true;
} if (cache->blocks->length() <= i)
if (cache->blocks->length() <= i) {
return true; return true;
} if (layout->blockdata->blocks->length() <= i)
if (layout->blockdata->blocks->length() <= i) {
return true; return true;
}
return layout->blockdata->blocks->value(i) != cache->blocks->value(i); return layout->blockdata->blocks->value(i) != cache->blocks->value(i);
} }
@ -389,13 +384,12 @@ void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
Block* Map::getBlock(int x, int y) { Block* Map::getBlock(int x, int y) {
if (layout->blockdata && layout->blockdata->blocks) { if (layout->blockdata && layout->blockdata->blocks) {
if (x >= 0 && x < getWidth()) if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
if (y >= 0 && y < getHeight()) {
int i = y * getWidth() + x; int i = y * getWidth() + x;
return new Block(layout->blockdata->blocks->value(i)); return new Block(layout->blockdata->blocks->value(i));
} }
} }
return NULL; return nullptr;
} }
void Map::_setBlock(int x, int y, Block block) { void Map::_setBlock(int x, int y, Block block) {
@ -405,7 +399,7 @@ void Map::_setBlock(int x, int y, Block block) {
} }
} }
void Map::_floodFillCollision(int x, int y, uint collision) { void Map::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
QList<QPoint> todo; QList<QPoint> todo;
todo.append(QPoint(x, y)); todo.append(QPoint(x, y));
while (todo.length()) { while (todo.length()) {
@ -413,79 +407,16 @@ void Map::_floodFillCollision(int x, int y, uint collision) {
x = point.x(); x = point.x();
y = point.y(); y = point.y();
Block *block = getBlock(x, y); Block *block = getBlock(x, y);
if (block == NULL) { if (!block) {
continue; continue;
} }
uint old_coll = block->collision;
if (old_coll == collision) {
continue;
}
block->collision = collision;
_setBlock(x, y, *block);
if ((block = getBlock(x + 1, y)) && block->collision == old_coll) {
todo.append(QPoint(x + 1, y));
}
if ((block = getBlock(x - 1, y)) && block->collision == old_coll) {
todo.append(QPoint(x - 1, y));
}
if ((block = getBlock(x, y + 1)) && block->collision == old_coll) {
todo.append(QPoint(x, y + 1));
}
if ((block = getBlock(x, y - 1)) && block->collision == old_coll) {
todo.append(QPoint(x, y - 1));
}
}
}
void Map::_floodFillElevation(int x, int y, uint elevation) {
QList<QPoint> todo;
todo.append(QPoint(x, y));
while (todo.length()) {
QPoint point = todo.takeAt(0);
x = point.x();
y = point.y();
Block *block = getBlock(x, y);
if (block == NULL) {
continue;
}
uint old_z = block->elevation;
if (old_z == elevation) {
continue;
}
Block block_(*block);
block_.elevation = elevation;
_setBlock(x, y, block_);
if ((block = getBlock(x + 1, y)) && block->elevation == old_z) {
todo.append(QPoint(x + 1, y));
}
if ((block = getBlock(x - 1, y)) && block->elevation == old_z) {
todo.append(QPoint(x - 1, y));
}
if ((block = getBlock(x, y + 1)) && block->elevation == old_z) {
todo.append(QPoint(x, y + 1));
}
if ((block = getBlock(x, y - 1)) && block->elevation == old_z) {
todo.append(QPoint(x, y - 1));
}
}
}
void Map::_floodFillCollisionElevation(int x, int y, uint collision, uint elevation) {
QList<QPoint> todo;
todo.append(QPoint(x, y));
while (todo.length()) {
QPoint point = todo.takeAt(0);
x = point.x();
y = point.y();
Block *block = getBlock(x, y);
if (block == NULL) {
continue;
}
uint old_coll = block->collision; uint old_coll = block->collision;
uint old_elev = block->elevation; uint old_elev = block->elevation;
if (old_coll == collision && old_elev == elevation) { if (old_coll == collision && old_elev == elevation) {
continue; continue;
} }
block->collision = collision; block->collision = collision;
block->elevation = elevation; block->elevation = elevation;
_setBlock(x, y, *block); _setBlock(x, y, *block);
@ -515,7 +446,7 @@ void Map::undo() {
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); this->setDimensions(commit->layoutWidth, commit->layoutHeight, false);
emit mapNeedsRedrawing(this); emit mapNeedsRedrawing();
} }
emit mapChanged(this); emit mapChanged(this);
@ -532,7 +463,7 @@ void Map::redo() {
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); this->setDimensions(commit->layoutWidth, commit->layoutHeight, false);
emit mapNeedsRedrawing(this); emit mapNeedsRedrawing();
} }
emit mapChanged(this); emit mapChanged(this);
@ -562,22 +493,7 @@ void Map::setBlock(int x, int y, Block block) {
} }
} }
void Map::floodFillCollision(int x, int y, uint collision) { void Map::floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
Block *block = getBlock(x, y);
if (block && block->collision != collision) {
_floodFillCollision(x, y, collision);
commit();
}
}
void Map::floodFillElevation(int x, int y, uint elevation) {
Block *block = getBlock(x, y);
if (block && block->elevation != elevation) {
_floodFillElevation(x, y, elevation);
commit();
}
}
void Map::floodFillCollisionElevation(int x, int y, uint collision, uint elevation) {
Block *block = getBlock(x, y); Block *block = getBlock(x, y);
if (block && (block->collision != collision || block->elevation != elevation)) { if (block && (block->collision != collision || block->elevation != elevation)) {
_floodFillCollisionElevation(x, y, collision, elevation); _floodFillCollisionElevation(x, y, collision, elevation);
@ -620,7 +536,7 @@ void Map::clearHoveredTile() {
} }
void Map::hoveredMetatileChanged(int blockIndex) { void Map::hoveredMetatileChanged(int blockIndex) {
int tile = getSelectedBlockIndex(blockIndex); uint16_t tile = getSelectedBlockIndex(blockIndex);
emit statusBarMessage(QString("Metatile: 0x%1") emit statusBarMessage(QString("Metatile: 0x%1")
.arg(QString("%1").arg(tile, 3, 16, QChar('0')).toUpper())); .arg(QString("%1").arg(tile, 3, 16, QChar('0')).toUpper()));
} }
@ -655,7 +571,7 @@ void Map::setSelectedMetatilesFromTilePicker() {
this->selected_metatiles->clear(); this->selected_metatiles->clear();
for (int j = 0; j < this->paint_tile_height; j++) { for (int j = 0; j < this->paint_tile_height; j++) {
for (int i = 0; i < this->paint_tile_width; i++) { for (int i = 0; i < this->paint_tile_width; i++) {
int metatile = this->getSelectedBlockIndex(this->paint_tile_index + i + (j * 8)); uint16_t metatile = this->getSelectedBlockIndex(this->paint_tile_index + i + (j * 8));
this->selected_metatiles->append(metatile); this->selected_metatiles->append(metatile);
} }
} }

47
map.h
View file

@ -14,13 +14,16 @@
class HistoryItem { class HistoryItem {
public: public:
Blockdata *metatiles; Blockdata *metatiles;
short layoutWidth; int layoutWidth;
short layoutHeight; int layoutHeight;
HistoryItem(Blockdata *metatiles_, short layoutWidth_, short layoutHeight_) { HistoryItem(Blockdata *metatiles_, int layoutWidth_, int layoutHeight_) {
this->metatiles = metatiles_; this->metatiles = metatiles_;
this->layoutWidth = layoutWidth_; this->layoutWidth = layoutWidth_;
this->layoutHeight = layoutHeight_; this->layoutHeight = layoutHeight_;
} }
~HistoryItem() {
if (metatiles) delete metatiles;
}
}; };
template <typename T> template <typename T>
@ -43,7 +46,9 @@ public:
} }
void push(T commit) { void push(T commit) {
while (head + 1 < history.length()) { while (head + 1 < history.length()) {
HistoryItem *item = history.last();
history.removeLast(); history.removeLast();
delete item;
} }
if (saved > head) { if (saved > head) {
saved = -1; saved = -1;
@ -94,15 +99,15 @@ public:
QString blockdata_path; QString blockdata_path;
QString tileset_primary_label; QString tileset_primary_label;
QString tileset_secondary_label; QString tileset_secondary_label;
Tileset *tileset_primary = NULL; Tileset *tileset_primary = nullptr;
Tileset *tileset_secondary = NULL; Tileset *tileset_secondary = nullptr;
Blockdata* blockdata = NULL; Blockdata* blockdata = nullptr;
QImage border_image; QImage border_image;
QPixmap border_pixmap; QPixmap border_pixmap;
Blockdata *border = NULL; Blockdata *border = nullptr;
Blockdata *cached_blockdata = NULL; Blockdata *cached_blockdata = nullptr;
Blockdata *cached_collision = NULL; Blockdata *cached_collision = nullptr;
Blockdata *cached_border = NULL; Blockdata *cached_border = nullptr;
bool has_unsaved_changes = false; bool has_unsaved_changes = false;
public: public:
static QString getNameFromLabel(QString label) { static QString getNameFromLabel(QString label) {
@ -115,7 +120,7 @@ class Map : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Map(QObject *parent = 0); explicit Map(QObject *parent = nullptr);
public: public:
QString name; QString name;
@ -150,7 +155,7 @@ public:
static QString bgEventsLabelFromName(QString mapName); static QString bgEventsLabelFromName(QString mapName);
int getWidth(); int getWidth();
int getHeight(); int getHeight();
int getSelectedBlockIndex(int); uint16_t getSelectedBlockIndex(int);
int getDisplayedBlockIndex(int); int getDisplayedBlockIndex(int);
QPixmap render(bool ignoreCache); QPixmap render(bool ignoreCache);
QPixmap renderMetatiles(); QPixmap renderMetatiles();
@ -180,20 +185,16 @@ public:
int paint_tile_initial_y; int paint_tile_initial_y;
int selected_metatiles_width; int selected_metatiles_width;
int selected_metatiles_height; int selected_metatiles_height;
QList<int> *selected_metatiles = NULL; QList<uint16_t> *selected_metatiles = nullptr;
int paint_collision; uint16_t paint_collision;
int paint_elevation; uint16_t paint_elevation;
Block *getBlock(int x, int y); Block *getBlock(int x, int y);
void setBlock(int x, int y, Block block); void setBlock(int x, int y, Block block);
void _setBlock(int x, int y, Block block); void _setBlock(int x, int y, Block block);
void floodFillCollision(int x, int y, uint collision); void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void _floodFillCollision(int x, int y, uint collision); void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void floodFillElevation(int x, int y, uint elevation);
void _floodFillElevation(int x, int y, uint elevation);
void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
History<HistoryItem*> history; History<HistoryItem*> history;
void undo(); void undo();
@ -223,10 +224,10 @@ public:
void setSelectedMetatilesFromTilePicker(); void setSelectedMetatilesFromTilePicker();
signals: signals:
void paintTileChanged(Map *map); void paintTileChanged();
void paintCollisionChanged(Map *map); void paintCollisionChanged(Map *map);
void mapChanged(Map *map); void mapChanged(Map *map);
void mapNeedsRedrawing(Map *map); void mapNeedsRedrawing();
void statusBarMessage(QString); void statusBarMessage(QString);
public slots: public slots:

View file

@ -8,7 +8,7 @@ class NewEventToolButton : public QToolButton
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit NewEventToolButton(QWidget *parent = 0); explicit NewEventToolButton(QWidget *parent = nullptr);
void initButton(); void initButton();
QString getSelectedEventType(); QString getSelectedEventType();
public slots: public slots:

View file

@ -12,7 +12,7 @@ class ObjectPropertiesFrame : public QFrame
Q_OBJECT Q_OBJECT
public: public:
explicit ObjectPropertiesFrame(QWidget *parent = 0); explicit ObjectPropertiesFrame(QWidget *parent = nullptr);
~ObjectPropertiesFrame(); ~ObjectPropertiesFrame();
public: public:

View file

@ -78,7 +78,7 @@ QList<HealLocation>* ParseUtil::parseHealLocs(QString text) {
for (auto line : lines){ for (auto line : lines){
if (line.contains("MAP_GROUP")){ if (line.contains("MAP_GROUP")){
QList<QString> li = line.replace(" ","").chopped(2).remove('{').split(','); QList<QString> li = line.replace(" ","").chopped(2).remove('{').split(',');
HealLocation hloc = HealLocation(li[1].remove("MAP_NUM(").remove(")"), i, li[2].toInt(), li[3].toInt()); HealLocation hloc = HealLocation(li[1].remove("MAP_NUM(").remove(")"), i, li[2].toUShort(), li[3].toUShort());
parsed->append(hloc); parsed->append(hloc);
i++; i++;
} }

View file

@ -8,8 +8,10 @@ QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = pretmap TARGET = porymap
TEMPLATE = app TEMPLATE = app
RC_ICONS = resources/icons/porymap-icon-1.ico
ICON = resources/icons/porymap-icon-1.ico
SOURCES += main.cpp\ SOURCES += main.cpp\

View file

@ -267,7 +267,6 @@ void Project::updateMapsWithConnections(Map *map) {
} }
void Project::readMapLayoutsTable() { void Project::readMapLayoutsTable() {
int curIndex = 1;
QString layoutsText = readTextFile(getMapLayoutsTableFilepath()); QString layoutsText = readTextFile(getMapLayoutsTableFilepath());
QList<QStringList>* values = parseAsm(layoutsText); QList<QStringList>* values = parseAsm(layoutsText);
bool inLayoutPointers = false; bool inLayoutPointers = false;
@ -311,7 +310,7 @@ QStringList* Project::readLayoutValues(QString layoutLabel) {
QString layoutText = readTextFile(getMapLayoutFilepath(layoutLabel)); QString layoutText = readTextFile(getMapLayoutFilepath(layoutLabel));
if (layoutText.isNull()) { if (layoutText.isNull()) {
return NULL; return nullptr;
} }
QStringList *layoutValues = getLabelValues(parser->parseAsm(layoutText), layoutLabel); QStringList *layoutValues = getLabelValues(parser->parseAsm(layoutText), layoutLabel);
@ -326,7 +325,7 @@ QStringList* Project::readLayoutValues(QString layoutLabel) {
if (layoutValues->size() != 8) { if (layoutValues->size() != 8) {
qDebug() << "Error: Unexpected number of properties in layout '" << layoutLabel << "'"; qDebug() << "Error: Unexpected number of properties in layout '" << layoutLabel << "'";
return NULL; return nullptr;
} }
return layoutValues; return layoutValues;
@ -340,7 +339,7 @@ void Project::readMapLayout(Map* map) {
MapLayout *layout; MapLayout *layout;
if (!mapLayouts.contains(map->layout_label)) { if (!mapLayouts.contains(map->layout_label)) {
QStringList *layoutValues = readLayoutValues(map->layout->label); QStringList *layoutValues = readLayoutValues(map->layout->label);
if (layoutValues == NULL) { if (!layoutValues) {
return; return;
} }
@ -372,7 +371,7 @@ void Project::readAllMapLayouts() {
for (int i = 0; i < mapLayoutsTable.size(); i++) { for (int i = 0; i < mapLayoutsTable.size(); i++) {
QString layoutLabel = mapLayoutsTable[i]; QString layoutLabel = mapLayoutsTable[i];
QStringList *layoutValues = readLayoutValues(layoutLabel); QStringList *layoutValues = readLayoutValues(layoutLabel);
if (layoutValues == NULL) { if (!layoutValues) {
return; return;
} }
@ -885,7 +884,7 @@ Blockdata* Project::readBlockdata(QString path) {
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
QByteArray data = file.readAll(); QByteArray data = file.readAll();
for (int i = 0; (i + 1) < data.length(); i += 2) { for (int i = 0; (i + 1) < data.length(); i += 2) {
uint16_t word = (data[i] & 0xff) + ((data[i + 1] & 0xff) << 8); uint16_t word = static_cast<uint16_t>((data[i] & 0xff) + ((data[i + 1] & 0xff) << 8));
blockdata->addBlock(word); blockdata->addBlock(word);
} }
} else { } else {

View file

@ -14,10 +14,10 @@ class Project
public: public:
Project(); Project();
QString root; QString root;
QStringList *groupNames = NULL; QStringList *groupNames = nullptr;
QMap<QString, int> *map_groups; QMap<QString, int> *map_groups;
QList<QStringList> groupedMapNames; QList<QStringList> groupedMapNames;
QStringList *mapNames = NULL; QStringList *mapNames = nullptr;
QList<HealLocation> flyableMaps; QList<HealLocation> flyableMaps;
QMap<QString, QString>* mapConstantsToMapNames; QMap<QString, QString>* mapConstantsToMapNames;
QMap<QString, QString>* mapNamesToMapConstants; QMap<QString, QString>* mapNamesToMapConstants;
@ -25,24 +25,24 @@ public:
QList<QString> mapLayoutsTableMaster; QList<QString> mapLayoutsTableMaster;
QMap<QString, MapLayout*> mapLayouts; QMap<QString, MapLayout*> mapLayouts;
QMap<QString, MapLayout*> mapLayoutsMaster; QMap<QString, MapLayout*> mapLayoutsMaster;
QStringList *regionMapSections = NULL; QStringList *regionMapSections = nullptr;
QStringList *itemNames = NULL; QStringList *itemNames = nullptr;
QStringList *flagNames = NULL; QStringList *flagNames = nullptr;
QStringList *varNames = NULL; QStringList *varNames = nullptr;
QStringList *movementTypes = NULL; QStringList *movementTypes = nullptr;
QStringList *mapTypes = NULL; QStringList *mapTypes = nullptr;
QStringList *mapBattleScenes = NULL; QStringList *mapBattleScenes = nullptr;
QStringList *weatherNames = NULL; QStringList *weatherNames = nullptr;
QStringList *coordEventWeatherNames = NULL; QStringList *coordEventWeatherNames = nullptr;
QStringList *secretBaseIds = NULL; QStringList *secretBaseIds = nullptr;
QStringList *bgEventFacingDirections = NULL; QStringList *bgEventFacingDirections = nullptr;
QStringList mapsWithConnections; QStringList mapsWithConnections;
QMap<QString, Map*> *map_cache; QMap<QString, Map*> *map_cache;
Map* loadMap(QString); Map* loadMap(QString);
Map* getMap(QString); Map* getMap(QString);
QMap<QString, Tileset*> *tileset_cache = NULL; QMap<QString, Tileset*> *tileset_cache = nullptr;
Tileset* loadTileset(QString); Tileset* loadTileset(QString);
Tileset* getTileset(QString); Tileset* getTileset(QString);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -22,5 +22,6 @@
<file>icons/pipette_cursor.ico</file> <file>icons/pipette_cursor.ico</file>
<file>icons/shift.ico</file> <file>icons/shift.ico</file>
<file>icons/shift_cursor.ico</file> <file>icons/shift_cursor.ico</file>
<file>icons/porymap-icon-1.ico</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -72,9 +72,9 @@ Metatile* Metatile::getMetatile(int index, Tileset *primaryTileset, Tileset *sec
Tileset *tileset = Metatile::getBlockTileset(index, primaryTileset, secondaryTileset); Tileset *tileset = Metatile::getBlockTileset(index, primaryTileset, secondaryTileset);
int local_index = Metatile::getBlockIndex(index); int local_index = Metatile::getBlockIndex(index);
if (!tileset || !tileset->metatiles) { if (!tileset || !tileset->metatiles) {
return NULL; return nullptr;
} }
Metatile *metatile = tileset->metatiles->value(local_index, NULL); Metatile *metatile = tileset->metatiles->value(local_index, nullptr);
return metatile; return metatile;
} }

View file

@ -21,9 +21,9 @@ public:
QString callback_label; QString callback_label;
QString metatile_attrs_label; QString metatile_attrs_label;
QList<QImage> *tiles = NULL; QList<QImage> *tiles = nullptr;
QList<Metatile*> *metatiles = NULL; QList<Metatile*> *metatiles = nullptr;
QList<QList<QRgb>> *palettes = NULL; QList<QList<QRgb>> *palettes = nullptr;
}; };
class Metatile class Metatile
@ -31,7 +31,7 @@ class Metatile
public: public:
Metatile(); Metatile();
public: public:
QList<Tile> *tiles = NULL; QList<Tile> *tiles = nullptr;
int attr; int attr;
static QImage getMetatileImage(int, Tileset*, Tileset*); static QImage getMetatileImage(int, Tileset*, Tileset*);