mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-20 07:36:31 -05:00
Add metatile swap
This commit is contained in:
@@ -44,7 +44,7 @@ private:
|
||||
Tileset *secondaryTileset;
|
||||
|
||||
QList<ColorInputWidget*> colorInputs;
|
||||
QList<History<PaletteHistoryItem*>> palettesHistory;
|
||||
QMap<int, History<PaletteHistoryItem*>> palettesHistory;
|
||||
QMap<int,QSet<int>> unusedColorCache;
|
||||
QPointer<PaletteColorSearch> colorSearchWindow;
|
||||
|
||||
@@ -53,6 +53,7 @@ private:
|
||||
void refreshPaletteId();
|
||||
void commitEditHistory();
|
||||
void commitEditHistory(int paletteId);
|
||||
void updateEditHistoryActions();
|
||||
void restoreWindowState();
|
||||
void invalidateCache();
|
||||
void closeEvent(QCloseEvent*);
|
||||
|
||||
@@ -26,6 +26,8 @@ public:
|
||||
virtual void setMaxSelectionSize(int width, int height);
|
||||
QSize maxSelectionSize() { return QSize(this->maxSelectionWidth, this->maxSelectionHeight); }
|
||||
|
||||
void setSelectionStyle(Qt::PenStyle style);
|
||||
|
||||
protected:
|
||||
int cellWidth;
|
||||
int cellHeight;
|
||||
@@ -40,10 +42,13 @@ protected:
|
||||
void select(const QPoint &pos, const QSize &size = QSize(1,1));
|
||||
void select(int x, int y, int width = 1, int height = 1) { select(QPoint(x, y), QSize(width, height)); }
|
||||
void updateSelection(const QPoint &pos);
|
||||
QPoint getCellPos(QPointF);
|
||||
QPoint getCellPos(const QPointF &itemPos);
|
||||
int getBoundedWidth(int width) const { return qBound(1, width, this->maxSelectionWidth); }
|
||||
int getBoundedHeight(int height) const { return qBound(1, height, this->maxSelectionHeight); }
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void drawSelectionRect(const QPoint &, const QSize &, Qt::PenStyle style = Qt::SolidLine);
|
||||
virtual void drawSelection();
|
||||
virtual int cellsWide() const { return this->cellWidth ? (pixmap().width() / this->cellWidth) : 0; }
|
||||
virtual int cellsTall() const { return this->cellHeight ? (pixmap().height() / this->cellHeight) : 0; }
|
||||
@@ -53,6 +58,9 @@ signals:
|
||||
|
||||
private:
|
||||
QPoint prevCellPos = QPoint(-1,-1);
|
||||
Qt::PenStyle selectionStyle = Qt::SolidLine;
|
||||
|
||||
void setSelection(const QPoint &pos, const QSize &size);
|
||||
};
|
||||
|
||||
#endif // SELECTABLEPIXMAPITEM_H
|
||||
|
||||
@@ -20,6 +20,7 @@ class TilesetEditor;
|
||||
|
||||
class MetatileHistoryItem {
|
||||
public:
|
||||
MetatileHistoryItem() {};
|
||||
MetatileHistoryItem(uint16_t metatileId, Metatile *prevMetatile, Metatile *newMetatile, QString prevLabel, QString newLabel) {
|
||||
this->metatileId = metatileId;
|
||||
this->prevMetatile = prevMetatile;
|
||||
@@ -27,15 +28,24 @@ public:
|
||||
this->prevLabel = prevLabel;
|
||||
this->newLabel = newLabel;
|
||||
}
|
||||
MetatileHistoryItem(uint16_t metatileIdA, uint16_t metatileIdB) {
|
||||
this->metatileId = metatileIdA;
|
||||
this->swapMetatileId = metatileIdB;
|
||||
this->isSwap = true;
|
||||
}
|
||||
~MetatileHistoryItem() {
|
||||
delete this->prevMetatile;
|
||||
delete this->newMetatile;
|
||||
}
|
||||
uint16_t metatileId;
|
||||
Metatile *prevMetatile;
|
||||
Metatile *newMetatile;
|
||||
|
||||
uint16_t metatileId = 0;
|
||||
Metatile *prevMetatile = nullptr;
|
||||
Metatile *newMetatile = nullptr;
|
||||
QString prevLabel;
|
||||
QString newLabel;
|
||||
|
||||
uint16_t swapMetatileId = 0;
|
||||
bool isSwap = false;
|
||||
};
|
||||
|
||||
class TilesetEditor : public QMainWindow
|
||||
@@ -122,8 +132,8 @@ private:
|
||||
void countMetatileUsage();
|
||||
void countTileUsage();
|
||||
void copyMetatile(bool cut);
|
||||
void pasteMetatile(const Metatile * toPaste, QString label);
|
||||
bool replaceMetatile(uint16_t metatileId, const Metatile * src, QString label);
|
||||
void pasteMetatile(const Metatile &toPaste, QString label);
|
||||
bool replaceMetatile(uint16_t metatileId, const Metatile &src, QString label);
|
||||
void commitMetatileChange(Metatile * prevMetatile);
|
||||
void commitMetatileAndLabelChange(Metatile * prevMetatile, QString prevLabel);
|
||||
uint32_t attributeNameToValue(Metatile::Attr attribute, const QString &text, bool *ok);
|
||||
@@ -134,11 +144,17 @@ private:
|
||||
void commitEncounterType();
|
||||
void commitTerrainType();
|
||||
void commitLayerType();
|
||||
void commit(MetatileHistoryItem *item);
|
||||
void updateEditHistoryActions();
|
||||
void setRawAttributesVisible(bool visible);
|
||||
void refreshTileFlips();
|
||||
void refreshPaletteId();
|
||||
void paintSelectedLayerTiles(const QPoint &pos, bool paletteOnly = false);
|
||||
void setMetatileLayerOrientation(Qt::Orientation orientation);
|
||||
void commitMetatileSwap(uint16_t metatileIdA, uint16_t metatileIdB);
|
||||
bool swapMetatiles(uint16_t metatileIdA, uint16_t metatileIdB);
|
||||
void applyMetatileSwapToLayouts(uint16_t metatileIdA, uint16_t metatileIdB);
|
||||
void applyMetatileSwapsToLayouts();
|
||||
|
||||
Ui::TilesetEditor *ui;
|
||||
History<MetatileHistoryItem*> metatileHistory;
|
||||
@@ -162,6 +178,7 @@ private:
|
||||
bool lockSelection = false;
|
||||
QSet<uint16_t> metatileReloadQueue;
|
||||
MetatileImageExporter::Settings *metatileImageExportSettings = nullptr;
|
||||
QList<QPair<uint16_t,uint16_t>> metatileIdSwaps;
|
||||
|
||||
bool save();
|
||||
|
||||
|
||||
@@ -19,9 +19,13 @@ public:
|
||||
bool select(uint16_t metatileId);
|
||||
void setTilesets(Tileset*, Tileset*);
|
||||
uint16_t getSelectedMetatileId() const { return this->selectedMetatileId; }
|
||||
void updateSelectedMetatile();
|
||||
QPoint getMetatileIdCoordsOnWidget(uint16_t metatileId) const;
|
||||
|
||||
void setSwapMode(bool enabeled);
|
||||
void addToSwapSelection(uint16_t metatileId);
|
||||
void removeFromSwapSelection(uint16_t metatileId);
|
||||
void clearSwapSelection();
|
||||
|
||||
QVector<uint16_t> usedMetatiles;
|
||||
bool selectorShowUnused = false;
|
||||
bool selectorShowCounts = false;
|
||||
@@ -42,11 +46,15 @@ private:
|
||||
Tileset *primaryTileset = nullptr;
|
||||
Tileset *secondaryTileset = nullptr;
|
||||
uint16_t selectedMetatileId;
|
||||
|
||||
QList<uint16_t> swapMetatileIds;
|
||||
bool inSwapMode = false;
|
||||
|
||||
void updateBasePixmap();
|
||||
uint16_t posToMetatileId(int x, int y, bool *ok = nullptr) const;
|
||||
uint16_t posToMetatileId(const QPoint &pos, bool *ok = nullptr) const;
|
||||
QPoint metatileIdToPos(uint16_t metatileId, bool *ok = nullptr) const;
|
||||
bool shouldAcceptEvent(QGraphicsSceneMouseEvent*);
|
||||
bool isValidMetatileId(uint16_t metatileId) const;
|
||||
int numRows(int numMetatiles) const;
|
||||
int numRows() const;
|
||||
void drawGrid();
|
||||
@@ -60,6 +68,7 @@ signals:
|
||||
void hoveredMetatileChanged(uint16_t);
|
||||
void hoveredMetatileCleared();
|
||||
void selectedMetatileChanged(uint16_t);
|
||||
void swapRequested(uint16_t, uint16_t);
|
||||
};
|
||||
|
||||
#endif // TILESETEDITORMETATILESELECTOR_H
|
||||
|
||||
Reference in New Issue
Block a user