Fix tile status not updating while painting on layer view

This commit is contained in:
GriffinR 2025-08-08 13:34:31 -04:00
parent b97a4e76b1
commit 9e820a79fe
4 changed files with 50 additions and 54 deletions

View File

@ -12,12 +12,14 @@ public:
MetatileLayersItem(Metatile *metatile,
Tileset *primaryTileset,
Tileset *secondaryTileset,
Qt::Orientation orientation = Qt::Horizontal);
void draw();
Qt::Orientation orientation = Qt::Vertical);
void draw() override;
void setTilesets(Tileset*, Tileset*);
void setMetatile(Metatile*);
void clearLastModifiedCoords();
void clearLastHoveredCoords();
bool hasCursor() const { return this->cursorCellPos != QPoint(-1,-1); }
Tile tileUnderCursor() const;
QPoint tileIndexToPos(int index) const { return this->tilePositions.value(index); }
int posToTileIndex(const QPoint &pos) const { return this->tilePositions.indexOf(pos); }
@ -31,14 +33,14 @@ private:
Tileset *primaryTileset;
Tileset *secondaryTileset;
Qt::Orientation orientation;
QPoint prevChangedPos;
QPoint prevHoveredPos;
QPoint cursorCellPos = QPoint(-1,-1);
QList<QPoint> tilePositions;
QPoint getBoundedPos(const QPointF &);
void updateSelection();
void hover(const QPoint &pos);
bool setCursorCellPos(const QPoint &pos);
signals:
void tileChanged(const QPoint &pos);
void paletteChanged(const QPoint &pos);
@ -46,11 +48,11 @@ signals:
void hoveredTileChanged(const Tile &tile);
void hoveredTileCleared();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
void mousePressEvent(QGraphicsSceneMouseEvent*) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
void hoverMoveEvent(QGraphicsSceneHoverEvent*) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
};
#endif // METATILELAYERSITEM_H

View File

@ -77,8 +77,6 @@ private slots:
void onWindowActivated();
void onHoveredMetatileChanged(uint16_t);
void onHoveredMetatileCleared();
void onHoveredTileChanged(const Tile&);
void onHoveredTileChanged(uint16_t);
void onHoveredTileCleared();
void onMetatileLayerSelectionChanged(const QPoint&, const QSize&);
void onPaletteEditorChangedPaletteColor();
@ -159,6 +157,9 @@ private:
void applyMetatileSwapsToLayouts();
void rebuildMetatilePropertiesFrame();
void addWidgetToMetatileProperties(QWidget *w, int *row, int rowSpan);
void updateLayerTileStatus();
void showTileStatus(const Tile &tile);
void showTileStatus(uint16_t tileId);
Ui::TilesetEditor *ui;
History<MetatileHistoryItem*> metatileHistory;

View File

@ -9,13 +9,13 @@ MetatileLayersItem::MetatileLayersItem(Metatile *metatile, Tileset *primaryTiles
primaryTileset(primaryTileset),
secondaryTileset(secondaryTileset)
{
clearLastModifiedCoords();
clearLastHoveredCoords();
setAcceptHoverEvents(true);
setOrientation(orientation);
}
void MetatileLayersItem::setOrientation(Qt::Orientation orientation) {
if (this->orientation == orientation)
return;
this->orientation = orientation;
int maxWidth = Metatile::tileWidth();
int maxHeight = Metatile::tileHeight();
@ -94,16 +94,13 @@ void MetatileLayersItem::draw() {
void MetatileLayersItem::setMetatile(Metatile *metatile) {
this->metatile = metatile;
this->clearLastModifiedCoords();
this->clearLastHoveredCoords();
draw();
}
void MetatileLayersItem::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
this->primaryTileset = primaryTileset;
this->secondaryTileset = secondaryTileset;
this->draw();
this->clearLastModifiedCoords();
this->clearLastHoveredCoords();
}
void MetatileLayersItem::updateSelection() {
@ -112,8 +109,8 @@ void MetatileLayersItem::updateSelection() {
}
void MetatileLayersItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
const QPoint pos = this->getBoundedPos(event->pos());
hover(pos);
const QPoint pos = getBoundedPos(event->pos());
setCursorCellPos(pos);
if (event->buttons() & Qt::RightButton) {
SelectablePixmapItem::mousePressEvent(event);
@ -123,14 +120,12 @@ void MetatileLayersItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
} else {
emit tileChanged(pos);
}
this->prevChangedPos = pos;
}
void MetatileLayersItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
const QPoint pos = this->getBoundedPos(event->pos());
if (this->prevChangedPos == pos)
const QPoint pos = getBoundedPos(event->pos());
if (!setCursorCellPos(pos))
return;
hover(pos);
if (event->buttons() & Qt::RightButton) {
SelectablePixmapItem::mouseMoveEvent(event);
@ -140,7 +135,6 @@ void MetatileLayersItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
} else {
emit tileChanged(pos);
}
this->prevChangedPos = pos;
}
void MetatileLayersItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
@ -154,32 +148,29 @@ void MetatileLayersItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
}
void MetatileLayersItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event) {
hover(getBoundedPos(event->pos()));
setCursorCellPos(getBoundedPos(event->pos()));
}
void MetatileLayersItem::hover(const QPoint &pos) {
if (pos == this->prevHoveredPos)
return;
this->prevHoveredPos = pos;
bool MetatileLayersItem::setCursorCellPos(const QPoint &pos) {
if (this->cursorCellPos == pos)
return false;
this->cursorCellPos = pos;
int tileIndex = posToTileIndex(pos);
if (tileIndex < 0 || !this->metatile || tileIndex >= this->metatile->tiles.length())
return;
emit this->hoveredTileChanged(this->metatile->tiles.at(tileIndex));
emit this->hoveredTileChanged(tileUnderCursor());
return true;
}
void MetatileLayersItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
this->clearLastHoveredCoords();
this->cursorCellPos = QPoint(-1,-1);
emit this->hoveredTileCleared();
}
void MetatileLayersItem::clearLastModifiedCoords() {
this->prevChangedPos = QPoint(-1, -1);
}
void MetatileLayersItem::clearLastHoveredCoords() {
this->prevHoveredPos = QPoint(-1, -1);
Tile MetatileLayersItem::tileUnderCursor() const {
int tileIndex = posToTileIndex(this->cursorCellPos);
if (tileIndex < 0 || !this->metatile || tileIndex >= this->metatile->tiles.length()) {
return Tile();
}
return this->metatile->tiles.at(tileIndex);
}
QPoint MetatileLayersItem::getBoundedPos(const QPointF &pos) {

View File

@ -314,7 +314,7 @@ void TilesetEditor::initMetatileLayersItem() {
connect(this->metatileLayersItem, &MetatileLayersItem::tileChanged, [this](const QPoint &pos) { paintSelectedLayerTiles(pos); });
connect(this->metatileLayersItem, &MetatileLayersItem::paletteChanged, [this](const QPoint &pos) { paintSelectedLayerTiles(pos, true); });
connect(this->metatileLayersItem, &MetatileLayersItem::selectedTilesChanged, this, &TilesetEditor::onMetatileLayerSelectionChanged);
connect(this->metatileLayersItem, &MetatileLayersItem::hoveredTileChanged, [this](const Tile &tile) { onHoveredTileChanged(tile); });
connect(this->metatileLayersItem, &MetatileLayersItem::hoveredTileChanged, [this](const Tile &tile) { showTileStatus(tile); });
connect(this->metatileLayersItem, &MetatileLayersItem::hoveredTileCleared, this, &TilesetEditor::onHoveredTileCleared);
bool showGrid = porymapConfig.showTilesetEditorLayerGrid;
@ -329,7 +329,7 @@ void TilesetEditor::initMetatileLayersItem() {
void TilesetEditor::initTileSelector() {
this->tileSelector = new TilesetEditorTileSelector(this->primaryTileset, this->secondaryTileset);
connect(this->tileSelector, &TilesetEditorTileSelector::hoveredTileChanged, [this](uint16_t tileId) {
onHoveredTileChanged(tileId);
showTileStatus(tileId);
});
connect(this->tileSelector, &TilesetEditorTileSelector::hoveredTileCleared, this, &TilesetEditor::onHoveredTileCleared);
connect(this->tileSelector, &TilesetEditorTileSelector::selectedTilesChanged, this, &TilesetEditor::drawSelectedTiles);
@ -499,7 +499,6 @@ void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
}
this->metatileLayersItem->setMetatile(metatile);
this->metatileLayersItem->draw();
MetatileLabelPair labels = Tileset::getMetatileLabelPair(metatileId, this->primaryTileset, this->secondaryTileset);
this->ui->lineEdit_MetatileLabel->setText(labels.owned);
@ -512,7 +511,13 @@ void TilesetEditor::queueMetatileReload(uint16_t metatileId) {
this->metatileReloadQueue.insert(metatileId);
}
void TilesetEditor::onHoveredTileChanged(const Tile &tile) {
void TilesetEditor::updateLayerTileStatus() {
if (this->metatileLayersItem->hasCursor()) {
showTileStatus(this->metatileLayersItem->tileUnderCursor());
}
}
void TilesetEditor::showTileStatus(const Tile &tile) {
this->ui->statusbar->showMessage(QString("Tile: %1, Palette: %2%3%4")
.arg(Util::toHexString(tile.tileId, 3))
.arg(QString::number(tile.palette))
@ -521,7 +526,7 @@ void TilesetEditor::onHoveredTileChanged(const Tile &tile) {
);
}
void TilesetEditor::onHoveredTileChanged(uint16_t tileId) {
void TilesetEditor::showTileStatus(uint16_t tileId) {
this->ui->statusbar->showMessage(QString("Tile: %1").arg(Util::toHexString(tileId, 3)));
}
@ -570,6 +575,7 @@ void TilesetEditor::paintSelectedLayerTiles(const QPoint &pos, bool paletteOnly)
this->metatileSelector->drawSelectedMetatile();
this->metatileLayersItem->draw();
updateLayerTileStatus();
this->tileSelector->draw();
this->commitMetatileChange(prevMetatile);
}
@ -589,7 +595,6 @@ void TilesetEditor::onMetatileLayerSelectionChanged(const QPoint &selectionOrigi
this->tileSelector->highlight(tiles[0].tileId);
this->redrawTileSelector();
}
this->metatileLayersItem->clearLastModifiedCoords();
}
void TilesetEditor::setPaletteId(int paletteId) {
@ -606,13 +611,11 @@ void TilesetEditor::refreshPaletteId() {
if (this->paletteEditor) {
this->paletteEditor->setPaletteId(paletteId());
}
this->metatileLayersItem->clearLastModifiedCoords();
}
void TilesetEditor::refreshTileFlips() {
this->tileSelector->setTileFlips(ui->checkBox_xFlip->isChecked(), ui->checkBox_yFlip->isChecked());
this->drawSelectedTiles();
this->metatileLayersItem->clearLastModifiedCoords();
}
void TilesetEditor::setMetatileLabel(QString label)
@ -957,8 +960,7 @@ bool TilesetEditor::replaceMetatile(uint16_t metatileId, const Metatile &src, QS
this->metatileSelector->select(metatileId);
this->metatileSelector->drawMetatile(metatileId);
this->metatileLayersItem->draw();
this->metatileLayersItem->clearLastModifiedCoords();
this->metatileLayersItem->clearLastHoveredCoords();
updateLayerTileStatus();
return true;
}