mirror of
https://github.com/huderlem/porymap.git
synced 2026-04-25 07:18:02 -05:00
Merge pull request #684 from garakmon/res663
Update Tile / Metatile Usage When Painting
This commit is contained in:
commit
5ea071d581
|
|
@ -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>
|
||||
|
|
@ -34,6 +35,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();
|
||||
|
|
@ -294,6 +299,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());
|
||||
|
|
@ -449,6 +464,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++;
|
||||
}
|
||||
|
|
@ -456,6 +475,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
|
|||
|
||||
this->metatileSelector->draw();
|
||||
this->metatileLayersItem->draw();
|
||||
this->tileSelector->draw();
|
||||
this->commitMetatileChange(prevMetatile);
|
||||
}
|
||||
|
||||
|
|
@ -1043,7 +1063,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) {
|
||||
// It's possible for a layout's tileset labels to change if they are invalid,
|
||||
|
|
|
|||
|
|
@ -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