Clean up API changes

This commit is contained in:
GriffinR 2021-12-13 11:41:46 -05:00 committed by huderlem
parent 36dc1c6649
commit 574151aebb
7 changed files with 73 additions and 28 deletions

View file

@ -124,6 +124,10 @@ public:
Q_INVOKABLE int getMaxPrimaryTilesetMetatiles(); Q_INVOKABLE int getMaxPrimaryTilesetMetatiles();
Q_INVOKABLE int getNumSecondaryTilesetMetatiles(); Q_INVOKABLE int getNumSecondaryTilesetMetatiles();
Q_INVOKABLE int getMaxSecondaryTilesetMetatiles(); Q_INVOKABLE int getMaxSecondaryTilesetMetatiles();
Q_INVOKABLE int getNumPrimaryTilesetTiles();
Q_INVOKABLE int getMaxPrimaryTilesetTiles();
Q_INVOKABLE int getNumSecondaryTilesetTiles();
Q_INVOKABLE int getMaxSecondaryTilesetTiles();
Q_INVOKABLE bool isPrimaryTileset(QString tilesetName); Q_INVOKABLE bool isPrimaryTileset(QString tilesetName);
Q_INVOKABLE bool isSecondaryTileset(QString tilesetName); Q_INVOKABLE bool isSecondaryTileset(QString tilesetName);
Q_INVOKABLE QString getPrimaryTileset(); Q_INVOKABLE QString getPrimaryTileset();
@ -396,8 +400,6 @@ private:
QString getEventGroupFromTabWidget(QWidget *tab); QString getEventGroupFromTabWidget(QWidget *tab);
void closeSupplementaryWindows(); void closeSupplementaryWindows();
void setWindowDisabled(bool); void setWindowDisabled(bool);
void setMainTabInternal(int);
void setMapViewTabInternal(int);
void initTilesetEditor(); void initTilesetEditor();
bool initRegionMapEditor(); bool initRegionMapEditor();

View file

@ -59,6 +59,7 @@ public:
void updateLocation(int x, int y); void updateLocation(int x, int y);
void updateSelectionSize(int width, int height); void updateSelectionSize(int width, int height);
void setActive(bool active); void setActive(bool active);
bool getActive();
bool *enabled; bool *enabled;
private: private:
bool active; bool active;

View file

@ -209,7 +209,7 @@ void ResizeMap::redo() {
if (!map) return; if (!map) return;
map->setBlockdata(newMetatiles); map->layout->blockdata = newMetatiles;
map->setDimensions(newMapWidth, newMapHeight, false); map->setDimensions(newMapWidth, newMapHeight, false);
map->layout->border = newBorder; map->layout->border = newBorder;
@ -223,7 +223,7 @@ void ResizeMap::redo() {
void ResizeMap::undo() { void ResizeMap::undo() {
if (!map) return; if (!map) return;
map->setBlockdata(oldMetatiles); map->layout->blockdata = oldMetatiles;
map->setDimensions(oldMapWidth, oldMapHeight, false); map->setDimensions(oldMapWidth, oldMapHeight, false);
map->layout->border = oldBorder; map->layout->border = oldBorder;
@ -510,9 +510,11 @@ void ScriptEditMap::redo() {
if (!map) return; if (!map) return;
map->setBlockdata(newMetatiles);
if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) { if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) {
map->layout->blockdata = newMetatiles;
map->setDimensions(newMapWidth, newMapHeight, false); map->setDimensions(newMapWidth, newMapHeight, false);
} else {
map->setBlockdata(newMetatiles);
} }
map->layout->lastCommitMapBlocks.blocks = newMetatiles; map->layout->lastCommitMapBlocks.blocks = newMetatiles;
@ -524,9 +526,11 @@ void ScriptEditMap::redo() {
void ScriptEditMap::undo() { void ScriptEditMap::undo() {
if (!map) return; if (!map) return;
map->setBlockdata(oldMetatiles);
if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) { if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) {
map->layout->blockdata = oldMetatiles;
map->setDimensions(oldMapWidth, oldMapHeight, false); map->setDimensions(oldMapWidth, oldMapHeight, false);
} else {
map->setBlockdata(oldMetatiles);
} }
map->layout->lastCommitMapBlocks.blocks = oldMetatiles; map->layout->lastCommitMapBlocks.blocks = oldMetatiles;

View file

@ -676,7 +676,7 @@ void MainWindow::redrawMapScene()
void MainWindow::refreshMapScene() void MainWindow::refreshMapScene()
{ {
setMainTabInternal(ui->mainTabBar->currentIndex()); on_mainTabBar_tabBarClicked(ui->mainTabBar->currentIndex());
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());
@ -1663,12 +1663,12 @@ void MainWindow::on_action_Save_triggered() {
void MainWindow::on_mapViewTab_tabBarClicked(int index) void MainWindow::on_mapViewTab_tabBarClicked(int index)
{ {
Scripting::cb_MapViewTabChanged(ui->mapViewTab->currentIndex(), index); int oldIndex = ui->mapViewTab->currentIndex();
setMapViewTabInternal(index); if (index != oldIndex)
} Scripting::cb_MapViewTabChanged(oldIndex, index);
ui->mapViewTab->setCurrentIndex(index);
void MainWindow::setMapViewTabInternal(int index)
{
if (index == 0) { if (index == 0) {
editor->setEditingMap(); editor->setEditingMap();
} else if (index == 1) { } else if (index == 1) {
@ -1687,11 +1687,7 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index)
int oldIndex = ui->mainTabBar->currentIndex(); int oldIndex = ui->mainTabBar->currentIndex();
if (index != oldIndex) if (index != oldIndex)
Scripting::cb_MainTabChanged(oldIndex, index); Scripting::cb_MainTabChanged(oldIndex, index);
setMainTabInternal(index);
}
void MainWindow::setMainTabInternal(int index)
{
ui->mainTabBar->setCurrentIndex(index); ui->mainTabBar->setCurrentIndex(index);
int tabIndexToStackIndex[5] = {0, 0, 1, 2, 3}; int tabIndexToStackIndex[5] = {0, 0, 1, 2, 3};
@ -1699,7 +1695,7 @@ void MainWindow::setMainTabInternal(int index)
if (index == 0) { if (index == 0) {
ui->stackedWidget_MapEvents->setCurrentIndex(0); ui->stackedWidget_MapEvents->setCurrentIndex(0);
setMapViewTabInternal(ui->mapViewTab->currentIndex()); on_mapViewTab_tabBarClicked(ui->mapViewTab->currentIndex());
clickToolButtonFromEditMode(editor->map_edit_mode); clickToolButtonFromEditMode(editor->map_edit_mode);
} else if (index == 1) { } else if (index == 1) {
ui->stackedWidget_MapEvents->setCurrentIndex(1); ui->stackedWidget_MapEvents->setCurrentIndex(1);
@ -1747,7 +1743,7 @@ void MainWindow::on_actionCursor_Tile_Outline_triggered()
porymapConfig.setShowCursorTile(enabled); porymapConfig.setShowCursorTile(enabled);
this->editor->settings->cursorTileRectEnabled = enabled; this->editor->settings->cursorTileRectEnabled = enabled;
if (this->editor->map_item->has_mouse) { if (this->editor->map_item->has_mouse) {
this->editor->cursorMapTileRect->setVisible(enabled); this->editor->cursorMapTileRect->setVisible(enabled && this->editor->cursorMapTileRect->getActive());
ui->graphicsView_Map->scene()->update(); ui->graphicsView_Map->scene()->update();
} }
} }

View file

@ -22,7 +22,7 @@ QJSValue MainWindow::getBlock(int x, int y) {
// isn't ignored. Ideally the setMetatileTiles functions would properly // isn't ignored. Ideally the setMetatileTiles functions would properly
// set each of the map spaces that use the modified metatile so that // set each of the map spaces that use the modified metatile so that
// the cache could be used, though this would lkely still require a // the cache could be used, though this would lkely still require a
// full read of the map and its border/connections. // full read of the map.
void MainWindow::tryRedrawMapArea(bool forceRedraw) { void MainWindow::tryRedrawMapArea(bool forceRedraw) {
if (!forceRedraw) return; if (!forceRedraw) return;
@ -655,6 +655,31 @@ int MainWindow::getMaxSecondaryTilesetMetatiles() {
return this->editor->project->getNumMetatilesTotal() - this->editor->project->getNumMetatilesPrimary(); return this->editor->project->getNumMetatilesTotal() - this->editor->project->getNumMetatilesPrimary();
} }
int MainWindow::getNumPrimaryTilesetTiles() {
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
return 0;
return this->editor->map->layout->tileset_primary->tiles.length();
}
int MainWindow::getMaxPrimaryTilesetTiles() {
if (!this->editor || !this->editor->project)
return 0;
return this->editor->project->getNumTilesPrimary();
}
int MainWindow::getNumSecondaryTilesetTiles() {
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
return 0;
return this->editor->map->layout->tileset_secondary->tiles.length();
}
int MainWindow::getMaxSecondaryTilesetTiles() {
if (!this->editor || !this->editor->project)
return 0;
return this->editor->project->getNumTilesTotal() - this->editor->project->getNumTilesPrimary();
}
bool MainWindow::isPrimaryTileset(QString tilesetName) { bool MainWindow::isPrimaryTileset(QString tilesetName) {
if (!this->editor || !this->editor->project) if (!this->editor || !this->editor->project)
return false; return false;
@ -823,12 +848,19 @@ QString MainWindow::getMetatileLabel(int metatileId) {
return metatile->label; return metatile->label;
} }
// TODO: Validate label
void MainWindow::setMetatileLabel(int metatileId, QString label) { void MainWindow::setMetatileLabel(int metatileId, QString label) {
Metatile * metatile = this->getMetatile(metatileId); Metatile * metatile = this->getMetatile(metatileId);
if (!metatile) if (!metatile)
return; return;
QRegularExpression expression("[_A-Za-z0-9]*$");
QRegularExpressionValidator validator(expression);
int pos = 0;
if (validator.validate(label, pos) != QValidator::Acceptable) {
logError(QString("Invalid metatile label %1").arg(label));
return;
}
if (this->tilesetEditor && this->tilesetEditor->getSelectedMetatile() == metatileId) { if (this->tilesetEditor && this->tilesetEditor->getSelectedMetatile() == metatileId) {
this->tilesetEditor->setMetatileLabel(label); this->tilesetEditor->setMetatileLabel(label);
} else if (metatile->label != label) { } else if (metatile->label != label) {
@ -932,12 +964,12 @@ void MainWindow::setMetatileTiles(int metatileId, QJSValue tilesObj, int tileSta
// Write to metatile using as many of the given Tiles as possible // Write to metatile using as many of the given Tiles as possible
int numTileObjs = qMin(tilesObj.property("length").toInt(), numTiles); int numTileObjs = qMin(tilesObj.property("length").toInt(), numTiles);
int i = 0; int i = 0;
for (; i < numTileObjs; i++) for (; i < numTileObjs; i++, tileStart++)
metatile->tiles[i] = Scripting::toTile(tilesObj.property(i)); metatile->tiles[tileStart] = Scripting::toTile(tilesObj.property(i));
// Fill remainder of specified length with empty Tiles // Fill remainder of specified length with empty Tiles
for (; i < numTiles; i++) for (; i < numTiles; i++, tileStart++)
metatile->tiles[i] = Tile(); metatile->tiles[tileStart] = Tile();
this->saveMetatilesByMetatileId(metatileId); this->saveMetatilesByMetatileId(metatileId);
this->needsFullRedraw = true; this->needsFullRedraw = true;
@ -952,7 +984,7 @@ void MainWindow::setMetatileTiles(int metatileId, int tileId, bool xflip, bool y
// Write to metatile using Tiles of the specified value // Write to metatile using Tiles of the specified value
Tile tile = Tile(tileId, xflip, yflip, palette); Tile tile = Tile(tileId, xflip, yflip, palette);
for (int i = 0; i < numTiles; i++) for (int i = tileStart; i <= tileEnd; i++)
metatile->tiles[i] = tile; metatile->tiles[i] = tile;
this->saveMetatilesByMetatileId(metatileId); this->saveMetatilesByMetatileId(metatileId);
@ -999,7 +1031,10 @@ int MainWindow::getMainTab() {
void MainWindow::setMainTab(int index) { void MainWindow::setMainTab(int index) {
if (!this->ui || !this->ui->mainTabBar || index < 0 || index >= this->ui->mainTabBar->count()) if (!this->ui || !this->ui->mainTabBar || index < 0 || index >= this->ui->mainTabBar->count())
return; return;
this->setMainTabInternal(index); // Can't select Wild Encounters tab if it's disabled
if (index == 4 && !projectConfig.getEncounterJsonActive())
return;
this->on_mainTabBar_tabBarClicked(index);
} }
int MainWindow::getMapViewTab() { int MainWindow::getMapViewTab() {
@ -1011,5 +1046,5 @@ int MainWindow::getMapViewTab() {
void MainWindow::setMapViewTab(int index) { void MainWindow::setMapViewTab(int index) {
if (this->getMainTab() != 0 || !this->ui->mapViewTab || index < 0 || index >= this->ui->mapViewTab->count()) if (this->getMainTab() != 0 || !this->ui->mapViewTab || index < 0 || index >= this->ui->mapViewTab->count())
return; return;
this->setMapViewTabInternal(index); this->on_mapViewTab_tabBarClicked(index);
} }

View file

@ -24,6 +24,11 @@ void CursorTileRect::setActive(bool active)
this->active = active; this->active = active;
} }
bool CursorTileRect::getActive()
{
return active;
}
void CursorTileRect::initAnchor(int coordX, int coordY) void CursorTileRect::initAnchor(int coordX, int coordY)
{ {
this->anchorCoordX = coordX; this->anchorCoordX = coordX;

View file

@ -683,8 +683,10 @@ void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
setCursor(this->settings->mapCursor); setCursor(this->settings->mapCursor);
} }
} }
void MapPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) { void MapPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
this->has_mouse = true; this->has_mouse = true;
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
emit this->hoveredMapMetatileChanged(pos);
} }
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
emit this->hoveredMapMetatileCleared(); emit this->hoveredMapMetatileCleared();