Move metatile labels to tilesets

This commit is contained in:
GriffinR
2023-02-14 14:10:05 -05:00
parent 72ae9dfc01
commit dbd6afb0c3
8 changed files with 118 additions and 70 deletions

View File

@@ -598,32 +598,30 @@ Metatile * MainWindow::getMetatile(int metatileId) {
}
QString MainWindow::getMetatileLabel(int metatileId) {
Metatile * metatile = this->getMetatile(metatileId);
if (!metatile || metatile->label.size() == 0)
if (!this->editor || !this->editor->map || !this->editor->map->layout)
return QString();
return metatile->label;
return Tileset::getMetatileLabel(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
}
void MainWindow::setMetatileLabel(int metatileId, QString label) {
Metatile * metatile = this->getMetatile(metatileId);
if (!metatile)
if (!this->editor || !this->editor->map || !this->editor->map->layout)
return;
static const QRegularExpression expression("[_A-Za-z0-9]*$");
QRegularExpressionValidator validator(expression);
int pos = 0;
if (validator.validate(label, pos) != QValidator::Acceptable) {
logError(QString("Invalid metatile label %1").arg(label));
return;
}
if (this->tilesetEditor && this->tilesetEditor->getSelectedMetatileId() == metatileId) {
// If the Tileset Editor is opened on this metatile we need to update the text box
if (this->tilesetEditor && this->tilesetEditor->getSelectedMetatileId() == metatileId){
this->tilesetEditor->setMetatileLabel(label);
} else if (metatile->label != label) {
metatile->label = label;
if (this->editor->project)
this->editor->project->saveTilesetMetatileLabels(this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
return;
}
if (!Tileset::setMetatileLabel(metatileId, label, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary)) {
logError("Failed to set metatile label. Must be a valid metatile id and a label containing only letters, numbers, and underscores.");
return;
}
// The user may not have the Tileset Editor open. This forcefully saves the change for them.
// If they do have the Tileset Editor open, this has the unintended side effect of saving other unsaved label changes.
if (this->editor->project)
this->editor->project->saveTilesetMetatileLabels(this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
}
int MainWindow::getMetatileLayerType(int metatileId) {