mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-09 19:37:45 -05:00
update tile & metatile usage counts automatically when painting
This commit is contained in:
parent
3e13986686
commit
089d90c9cb
|
|
@ -26,3 +26,16 @@ signals:
|
|||
void wheelZoom(int delta);
|
||||
public slots:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Emits a signal when a window gets activated / regains focus
|
||||
class ActiveWindowFilter : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ActiveWindowFilter(QObject *parent) : QObject(parent) {}
|
||||
virtual ~ActiveWindowFilter() {}
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
signals:
|
||||
void activated();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public slots:
|
|||
void onSelectedMetatileChanged(uint16_t);
|
||||
|
||||
private slots:
|
||||
void onWindowActivated();
|
||||
void onHoveredMetatileChanged(uint16_t);
|
||||
void onHoveredMetatileCleared();
|
||||
void onHoveredTileChanged(uint16_t);
|
||||
|
|
|
|||
|
|
@ -24,3 +24,12 @@ bool MapSceneEventFilter::eventFilter(QObject*, QEvent *event) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ActiveWindowFilter::eventFilter(QObject*, QEvent *event) {
|
||||
if (event->type() == QEvent::WindowActivate) {
|
||||
emit activated();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "shortcut.h"
|
||||
#include "filedialog.h"
|
||||
#include "validator.h"
|
||||
#include "eventfilters.h"
|
||||
#include <QMessageBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QCloseEvent>
|
||||
|
|
@ -40,6 +41,10 @@ TilesetEditor::TilesetEditor(Project *project, Layout *layout, QWidget *parent)
|
|||
ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1);
|
||||
ui->lineEdit_metatileLabel->setValidator(new IdentifierValidator(this));
|
||||
|
||||
ActiveWindowFilter *filter = new ActiveWindowFilter(this);
|
||||
connect(filter, &ActiveWindowFilter::activated, this, &TilesetEditor::onWindowActivated);
|
||||
this->installEventFilter(filter);
|
||||
|
||||
setAttributesUi();
|
||||
initMetatileSelector();
|
||||
initMetatileLayersItem();
|
||||
|
|
@ -300,6 +305,16 @@ void TilesetEditor::restoreWindowState() {
|
|||
this->ui->splitter->restoreState(geometry.value("tileset_editor_splitter_state"));
|
||||
}
|
||||
|
||||
void TilesetEditor::onWindowActivated() {
|
||||
// User may have made layout edits since window was last focused, so update counts
|
||||
if (this->metatileSelector) {
|
||||
if (this->metatileSelector->selectorShowUnused || this->metatileSelector->selectorShowCounts) {
|
||||
countMetatileUsage();
|
||||
this->metatileSelector->draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TilesetEditor::initMetatileHistory() {
|
||||
metatileHistory.clear();
|
||||
MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, new Metatile(), QString(), QString());
|
||||
|
|
@ -455,6 +470,10 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
|
|||
tile.xflip = tiles.at(selectedTileIndex).xflip;
|
||||
tile.yflip = tiles.at(selectedTileIndex).yflip;
|
||||
tile.palette = tiles.at(selectedTileIndex).palette;
|
||||
if (this->tileSelector->showUnused) {
|
||||
this->tileSelector->usedTiles[tile.tileId] += 1;
|
||||
this->tileSelector->usedTiles[prevMetatile->tiles[tileIndex].tileId] -= 1;
|
||||
}
|
||||
}
|
||||
selectedTileIndex++;
|
||||
}
|
||||
|
|
@ -462,6 +481,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
|
|||
|
||||
this->metatileSelector->draw();
|
||||
this->metatileLayersItem->draw();
|
||||
this->tileSelector->draw();
|
||||
this->commitMetatileChange(prevMetatile);
|
||||
}
|
||||
|
||||
|
|
@ -1049,7 +1069,7 @@ void TilesetEditor::on_actionShow_Tileset_Divider_triggered(bool checked) {
|
|||
|
||||
void TilesetEditor::countMetatileUsage() {
|
||||
// do not double count
|
||||
metatileSelector->usedMetatiles.fill(0);
|
||||
this->metatileSelector->usedMetatiles.fill(0);
|
||||
|
||||
for (auto layout : this->project->mapLayouts.values()) {
|
||||
bool usesPrimary = false;
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ void TilesetEditorTileSelector::drawUnused() {
|
|||
unusedPainter.setOpacity(0.5);
|
||||
|
||||
for (int tile = 0; tile < this->usedTiles.size(); tile++) {
|
||||
if (!usedTiles[tile]) {
|
||||
if (!this->usedTiles[tile]) {
|
||||
unusedPainter.drawPixmap((tile % 16) * 16, (tile / 16) * 16, redX);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user