Add Cut to Tileset Editor

This commit is contained in:
GriffinR 2022-10-03 21:03:43 -04:00 committed by Marcus Huderle
parent 691ab2b9cf
commit eb8b9b0352
3 changed files with 37 additions and 6 deletions

View file

@ -567,6 +567,7 @@
<property name="title"> <property name="title">
<string>Edit</string> <string>Edit</string>
</property> </property>
<addaction name="actionCut"/>
<addaction name="actionCopy"/> <addaction name="actionCopy"/>
<addaction name="actionPaste"/> <addaction name="actionPaste"/>
<addaction name="actionUndo"/> <addaction name="actionUndo"/>
@ -665,6 +666,14 @@
<string>Import Secondary Metatiles from Advance Map 1.92...</string> <string>Import Secondary Metatiles from Advance Map 1.92...</string>
</property> </property>
</action> </action>
<action name="actionCut">
<property name="text">
<string>Cut</string>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
</property>
</action>
<action name="actionCopy"> <action name="actionCopy">
<property name="text"> <property name="text">
<string>Copy</string> <string>Copy</string>

View file

@ -105,8 +105,8 @@ private slots:
void on_copyButton_metatileLabel_clicked(); void on_copyButton_metatileLabel_clicked();
void on_actionCut_triggered();
void on_actionCopy_triggered(); void on_actionCopy_triggered();
void on_actionPaste_triggered(); void on_actionPaste_triggered();
private: private:
@ -133,7 +133,9 @@ private:
void closeEvent(QCloseEvent*); void closeEvent(QCloseEvent*);
void countMetatileUsage(); void countMetatileUsage();
void countTileUsage(); void countTileUsage();
bool replaceMetatile(uint16_t metatileId, Metatile * src); void copyMetatile(bool cut);
void pasteMetatile(const Metatile * toPaste);
bool replaceMetatile(uint16_t metatileId, const Metatile * src);
Ui::TilesetEditor *ui; Ui::TilesetEditor *ui;
History<MetatileHistoryItem*> metatileHistory; History<MetatileHistoryItem*> metatileHistory;

View file

@ -818,7 +818,7 @@ void TilesetEditor::onPaletteEditorChangedPalette(int paletteId) {
this->on_spinBox_paletteSelector_valueChanged(paletteId); this->on_spinBox_paletteSelector_valueChanged(paletteId);
} }
bool TilesetEditor::replaceMetatile(uint16_t metatileId, Metatile * src) bool TilesetEditor::replaceMetatile(uint16_t metatileId, const Metatile * src)
{ {
Metatile * dest = Tileset::getMetatile(metatileId, this->primaryTileset, this->secondaryTileset); Metatile * dest = Tileset::getMetatile(metatileId, this->primaryTileset, this->secondaryTileset);
if (!dest || !src || *dest == *src) if (!dest || !src || *dest == *src)
@ -850,8 +850,28 @@ void TilesetEditor::on_actionRedo_triggered()
this->replaceMetatile(commit->metatileId, commit->newMetatile); this->replaceMetatile(commit->metatileId, commit->newMetatile);
} }
void TilesetEditor::on_actionCut_triggered()
{
int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
Metatile * empty = new Metatile();
for (int i = 0; i < numTiles; i++)
empty->tiles.append(Tile());
this->copyMetatile(true);
this->pasteMetatile(empty);
delete empty;
}
void TilesetEditor::on_actionCopy_triggered() void TilesetEditor::on_actionCopy_triggered()
{ {
this->copyMetatile(false);
}
void TilesetEditor::on_actionPaste_triggered()
{
this->pasteMetatile(this->copiedMetatile);
}
void TilesetEditor::copyMetatile(bool cut) {
Metatile * toCopy = Tileset::getMetatile(this->getSelectedMetatileId(), this->primaryTileset, this->secondaryTileset); Metatile * toCopy = Tileset::getMetatile(this->getSelectedMetatileId(), this->primaryTileset, this->secondaryTileset);
if (!toCopy) return; if (!toCopy) return;
@ -859,14 +879,14 @@ void TilesetEditor::on_actionCopy_triggered()
this->copiedMetatile = new Metatile(*toCopy); this->copiedMetatile = new Metatile(*toCopy);
else else
*this->copiedMetatile = *toCopy; *this->copiedMetatile = *toCopy;
this->copiedMetatile->label = ""; // Don't copy the label, these should be unique to each metatile if (!cut) this->copiedMetatile->label = ""; // Don't copy the label unless it's a cut, these should be unique to each metatile
} }
void TilesetEditor::on_actionPaste_triggered() void TilesetEditor::pasteMetatile(const Metatile * toPaste)
{ {
Metatile *prevMetatile = new Metatile(*this->metatile); Metatile *prevMetatile = new Metatile(*this->metatile);
uint16_t metatileId = this->getSelectedMetatileId(); uint16_t metatileId = this->getSelectedMetatileId();
if (!this->replaceMetatile(metatileId, this->copiedMetatile)) { if (!this->replaceMetatile(metatileId, toPaste)) {
delete prevMetatile; delete prevMetatile;
return; return;
} }