Fix tile rect leaving map grid on paint, cursor rects not updating state on collision tab

This commit is contained in:
GriffinR 2022-02-07 17:38:29 -05:00 committed by huderlem
parent d531c9407c
commit 7d51c11a94
4 changed files with 30 additions and 15 deletions

View file

@ -177,6 +177,7 @@ private:
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
QString getMetatileDisplayMessage(uint16_t metatileId);
bool eventLimitReached(Map *, QString);
bool isWithinMap(int x, int y);
bool startDetachedProcess(const QString &command,
const QString &workingDirectory = QString(),
qint64 *pid = nullptr) const;

View file

@ -1004,25 +1004,33 @@ void Editor::setCursorRectVisible(bool visible) {
ui->graphicsView_Map->scene()->update();
}
bool Editor::isWithinMap(int x, int y) {
return (x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight());
}
void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
this->updateCursorRectPos(pos.x(), pos.y());
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles
&& pos.x() >= 0 && pos.x() < map->getWidth() && pos.y() >= 0 && pos.y() < map->getHeight()) {
int blockIndex = pos.y() * map->getWidth() + pos.x();
int x = pos.x();
int y = pos.y();
if (!this->isWithinMap(x, y))
return;
this->updateCursorRectPos(x, y);
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
int blockIndex = y * map->getWidth() + x;
int metatileId = map->layout->blockdata.at(blockIndex).metatileId;
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x")
.arg(pos.x())
.arg(pos.y())
.arg(x)
.arg(y)
.arg(getMetatileDisplayMessage(metatileId))
.arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
} else if (map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects
&& pos.x() >= 0 && pos.x() < map->getWidth() && pos.y() >= 0 && pos.y() < map->getHeight()) {
}
else if (map_item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Scale = %3x")
.arg(pos.x())
.arg(pos.y())
.arg(x)
.arg(y)
.arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2)));
}
Scripting::cb_BlockHoverChanged(pos.x(), pos.y());
Scripting::cb_BlockHoverChanged(x, y);
}
void Editor::onHoveredMapMetatileCleared() {
@ -1035,9 +1043,11 @@ void Editor::onHoveredMapMetatileCleared() {
}
void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
if (!this->isWithinMap(x, y))
return;
this->updateCursorRectPos(x, y);
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles
&& x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) {
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
int blockIndex = y * map->getWidth() + x;
uint16_t collision = map->layout->blockdata.at(blockIndex).collision;
uint16_t elevation = map->layout->blockdata.at(blockIndex).elevation;

View file

@ -1733,7 +1733,8 @@ void MainWindow::on_actionPlayer_View_Rectangle_triggered()
bool enabled = ui->actionPlayer_View_Rectangle->isChecked();
porymapConfig.setShowPlayerView(enabled);
this->editor->settings->playerViewRectEnabled = enabled;
if (this->editor->map_item->has_mouse) {
if ((this->editor->map_item && this->editor->map_item->has_mouse)
|| (this->editor->collision_item && this->editor->collision_item->has_mouse)) {
this->editor->playerViewRect->setVisible(enabled);
ui->graphicsView_Map->scene()->update();
}
@ -1744,7 +1745,8 @@ void MainWindow::on_actionCursor_Tile_Outline_triggered()
bool enabled = ui->actionCursor_Tile_Outline->isChecked();
porymapConfig.setShowCursorTile(enabled);
this->editor->settings->cursorTileRectEnabled = enabled;
if (this->editor->map_item->has_mouse) {
if ((this->editor->map_item && this->editor->map_item->has_mouse)
|| (this->editor->collision_item && this->editor->collision_item->has_mouse)) {
this->editor->cursorMapTileRect->setVisible(enabled && this->editor->cursorMapTileRect->getActive());
ui->graphicsView_Map->scene()->update();
}

View file

@ -14,6 +14,7 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
}
void CollisionPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
this->has_mouse = true;
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
emit this->hoveredMapMovementPermissionChanged(pos.x(), pos.y());
}
@ -23,6 +24,7 @@ void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles){
unsetCursor();
}
this->has_mouse = false;
}
void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {