Update metatile label copy button
This commit is contained in:
parent
dbd6afb0c3
commit
16e5e9fad8
4 changed files with 48 additions and 29 deletions
|
@ -36,8 +36,11 @@ public:
|
||||||
static Tileset* getMetatileTileset(int, Tileset*, Tileset*);
|
static Tileset* getMetatileTileset(int, Tileset*, Tileset*);
|
||||||
static Tileset* getTileTileset(int, Tileset*, Tileset*);
|
static Tileset* getTileTileset(int, Tileset*, Tileset*);
|
||||||
static Metatile* getMetatile(int, Tileset*, Tileset*);
|
static Metatile* getMetatile(int, Tileset*, Tileset*);
|
||||||
static QString getMetatileLabel(int, Tileset *, Tileset *, bool * isAlternateLabel = nullptr);
|
static Tileset* getMetatileLabelTileset(int, Tileset*, Tileset*, bool * isShared = nullptr);
|
||||||
|
static QString getMetatileLabel(int, Tileset *, Tileset *, bool * isShared = nullptr);
|
||||||
static bool setMetatileLabel(int, QString, Tileset *, Tileset *);
|
static bool setMetatileLabel(int, QString, Tileset *, Tileset *);
|
||||||
|
QString getMetatileLabelPrefix();
|
||||||
|
static QString getMetatileLabelPrefix(const QString &name);
|
||||||
static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*, bool useTruePalettes = false);
|
static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*, bool useTruePalettes = false);
|
||||||
static QList<QRgb> getPalette(int, Tileset*, Tileset*, bool useTruePalettes = false);
|
static QList<QRgb> getPalette(int, Tileset*, Tileset*, bool useTruePalettes = false);
|
||||||
static bool metatileIsValid(uint16_t metatileId, Tileset *, Tileset *);
|
static bool metatileIsValid(uint16_t metatileId, Tileset *, Tileset *);
|
||||||
|
|
|
@ -93,26 +93,33 @@ Metatile* Tileset::getMetatile(int metatileId, Tileset *primaryTileset, Tileset
|
||||||
|
|
||||||
// Metatile labels are stored per-tileset. When looking for a metatile label, first search in the tileset
|
// Metatile labels are stored per-tileset. When looking for a metatile label, first search in the tileset
|
||||||
// that the metatile belongs to. If one isn't found, search in the other tileset. Labels coming from the
|
// that the metatile belongs to. If one isn't found, search in the other tileset. Labels coming from the
|
||||||
// tileset that the metatile does not belong to cannot be edited via Porymap.
|
// tileset that the metatile does not belong to are shared and cannot be edited via Porymap.
|
||||||
QString Tileset::getMetatileLabel(int metatileId, Tileset *primaryTileset, Tileset *secondaryTileset, bool * isAlternateLabel) {
|
Tileset* Tileset::getMetatileLabelTileset(int metatileId, Tileset *primaryTileset, Tileset *secondaryTileset, bool * isShared) {
|
||||||
Tileset *mainTileset = nullptr;
|
Tileset *mainTileset = nullptr;
|
||||||
Tileset *backupTileset = nullptr;
|
Tileset *alternateTileset = nullptr;
|
||||||
if (isAlternateLabel) *isAlternateLabel = false;
|
if (isShared) *isShared = false;
|
||||||
if (metatileId < Project::getNumMetatilesPrimary()) {
|
if (metatileId < Project::getNumMetatilesPrimary()) {
|
||||||
mainTileset = primaryTileset;
|
mainTileset = primaryTileset;
|
||||||
backupTileset = secondaryTileset;
|
alternateTileset = secondaryTileset;
|
||||||
} else if (metatileId < Project::getNumMetatilesTotal()) {
|
} else if (metatileId < Project::getNumMetatilesTotal()) {
|
||||||
mainTileset = secondaryTileset;
|
mainTileset = secondaryTileset;
|
||||||
backupTileset = primaryTileset;
|
alternateTileset = primaryTileset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mainTileset && mainTileset->metatileLabels.contains(metatileId)) {
|
if (mainTileset && mainTileset->metatileLabels.contains(metatileId)) {
|
||||||
return mainTileset->metatileLabels.value(metatileId);
|
return mainTileset;
|
||||||
} else if (backupTileset && backupTileset->metatileLabels.contains(metatileId)) {
|
} else if (alternateTileset && alternateTileset->metatileLabels.contains(metatileId)) {
|
||||||
if (isAlternateLabel) *isAlternateLabel = true;
|
if (isShared) *isShared = true;
|
||||||
return backupTileset->metatileLabels.value(metatileId);
|
return alternateTileset;
|
||||||
}
|
}
|
||||||
return QString();
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Tileset::getMetatileLabel(int metatileId, Tileset *primaryTileset, Tileset *secondaryTileset, bool * isShared) {
|
||||||
|
Tileset * tileset = Tileset::getMetatileLabelTileset(metatileId, primaryTileset, secondaryTileset, isShared);
|
||||||
|
if (!tileset)
|
||||||
|
return QString();
|
||||||
|
return tileset->metatileLabels.value(metatileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tileset::setMetatileLabel(int metatileId, QString label, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
bool Tileset::setMetatileLabel(int metatileId, QString label, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
|
@ -130,6 +137,16 @@ bool Tileset::setMetatileLabel(int metatileId, QString label, Tileset *primaryTi
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Tileset::getMetatileLabelPrefix()
|
||||||
|
{
|
||||||
|
return Tileset::getMetatileLabelPrefix(this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Tileset::getMetatileLabelPrefix(const QString &name)
|
||||||
|
{
|
||||||
|
return QString("METATILE_%1_").arg(QString(name).replace("gTileset_", ""));
|
||||||
|
}
|
||||||
|
|
||||||
bool Tileset::metatileIsValid(uint16_t metatileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
bool Tileset::metatileIsValid(uint16_t metatileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
if (metatileId >= Project::getNumMetatilesTotal())
|
if (metatileId >= Project::getNumMetatilesTotal())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -891,8 +891,8 @@ void Project::saveTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveTilesetMetatileLabels(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
void Project::saveTilesetMetatileLabels(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
QString primaryPrefix = QString("METATILE_%1_").arg(QString(primaryTileset->name).replace("gTileset_", ""));
|
QString primaryPrefix = primaryTileset->getMetatileLabelPrefix();
|
||||||
QString secondaryPrefix = QString("METATILE_%1_").arg(QString(secondaryTileset->name).replace("gTileset_", ""));
|
QString secondaryPrefix = secondaryTileset->getMetatileLabelPrefix();
|
||||||
|
|
||||||
QMap<QString, int> defines;
|
QMap<QString, int> defines;
|
||||||
bool definesFileModified = false;
|
bool definesFileModified = false;
|
||||||
|
@ -1500,11 +1500,11 @@ bool Project::readTilesetMetatileLabels() {
|
||||||
|
|
||||||
QMap<QString, int> labels = parser.readCDefines(metatileLabelsFilename, QStringList() << "METATILE_");
|
QMap<QString, int> labels = parser.readCDefines(metatileLabelsFilename, QStringList() << "METATILE_");
|
||||||
|
|
||||||
for (QString label : this->tilesetLabelsOrdered) {
|
for (QString tilesetLabel : this->tilesetLabelsOrdered) {
|
||||||
QString tilesetName = QString(label).replace("gTileset_", "");
|
QString metatileLabelPrefix = Tileset::getMetatileLabelPrefix(tilesetLabel);
|
||||||
for (QString key : labels.keys()) {
|
for (QString key : labels.keys()) {
|
||||||
if (key.contains(QString("METATILE_") + tilesetName + "_")) {
|
if (key.startsWith(metatileLabelPrefix)) {
|
||||||
metatileLabelsMap[label][key] = labels[key];
|
metatileLabelsMap[tilesetLabel][key] = labels[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1513,12 +1513,12 @@ bool Project::readTilesetMetatileLabels() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::loadTilesetMetatileLabels(Tileset* tileset) {
|
void Project::loadTilesetMetatileLabels(Tileset* tileset) {
|
||||||
QString tilesetPrefix = QString("METATILE_%1_").arg(QString(tileset->name).replace("gTileset_", ""));
|
QString metatileLabelPrefix = tileset->getMetatileLabelPrefix();
|
||||||
|
|
||||||
// Reverse map for faster lookup by metatile id
|
// Reverse map for faster lookup by metatile id
|
||||||
for (QString labelName : metatileLabelsMap[tileset->name].keys()) {
|
for (QString labelName : metatileLabelsMap[tileset->name].keys()) {
|
||||||
int metatileId = metatileLabelsMap[tileset->name][labelName];
|
int metatileId = metatileLabelsMap[tileset->name][labelName];
|
||||||
tileset->metatileLabels[metatileId] = labelName.replace(tilesetPrefix, "");
|
tileset->metatileLabels[metatileId] = labelName.replace(metatileLabelPrefix, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -380,10 +380,10 @@ void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
|
||||||
this->metatileLayersItem->draw();
|
this->metatileLayersItem->draw();
|
||||||
this->ui->graphicsView_metatileLayers->setFixedSize(this->metatileLayersItem->pixmap().width() + 2, this->metatileLayersItem->pixmap().height() + 2);
|
this->ui->graphicsView_metatileLayers->setFixedSize(this->metatileLayersItem->pixmap().width() + 2, this->metatileLayersItem->pixmap().height() + 2);
|
||||||
|
|
||||||
bool isAlternateLabel = false;
|
bool isShared = false;
|
||||||
QString label = Tileset::getMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset, &isAlternateLabel);
|
QString label = Tileset::getMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset, &isShared);
|
||||||
this->ui->lineEdit_metatileLabel->setText(label);
|
this->ui->lineEdit_metatileLabel->setText(label);
|
||||||
this->ui->lineEdit_metatileLabel->setReadOnly(isAlternateLabel);
|
this->ui->lineEdit_metatileLabel->setReadOnly(isShared);
|
||||||
|
|
||||||
setComboValue(this->ui->comboBox_metatileBehaviors, this->metatile->behavior);
|
setComboValue(this->ui->comboBox_metatileBehaviors, this->metatile->behavior);
|
||||||
setComboValue(this->ui->comboBox_layerType, this->metatile->layerType);
|
setComboValue(this->ui->comboBox_layerType, this->metatile->layerType);
|
||||||
|
@ -918,9 +918,9 @@ void TilesetEditor::copyMetatile(bool cut) {
|
||||||
// Don't try to copy the label unless it's a cut, these should be unique to each metatile
|
// Don't try to copy the label unless it's a cut, these should be unique to each metatile
|
||||||
this->copiedMetatileLabel = "";
|
this->copiedMetatileLabel = "";
|
||||||
if (cut) {
|
if (cut) {
|
||||||
bool isAlternateLabel = false;
|
bool isShared = false;
|
||||||
QString label = Tileset::getMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset, &isAlternateLabel);
|
QString label = Tileset::getMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset, &isShared);
|
||||||
if (!isAlternateLabel)
|
if (!isShared)
|
||||||
this->copiedMetatileLabel = label;
|
this->copiedMetatileLabel = label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1165,12 +1165,11 @@ void TilesetEditor::countTileUsage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilesetEditor::on_copyButton_metatileLabel_clicked() {
|
void TilesetEditor::on_copyButton_metatileLabel_clicked() {
|
||||||
// TODO: Handle alternate labels
|
|
||||||
QString label = this->ui->lineEdit_metatileLabel->text();
|
QString label = this->ui->lineEdit_metatileLabel->text();
|
||||||
if (label.isEmpty()) return;
|
if (label.isEmpty()) return;
|
||||||
Tileset * tileset = Tileset::getMetatileTileset(this->getSelectedMetatileId(), this->primaryTileset, this->secondaryTileset);
|
Tileset * tileset = Tileset::getMetatileLabelTileset(this->getSelectedMetatileId(), this->primaryTileset, this->secondaryTileset);
|
||||||
if (tileset)
|
if (tileset)
|
||||||
label.prepend("METATILE_" + QString(tileset->name).replace("gTileset_", "") + "_");
|
label.prepend(tileset->getMetatileLabelPrefix());
|
||||||
QGuiApplication::clipboard()->setText(label);
|
QGuiApplication::clipboard()->setText(label);
|
||||||
QToolTip::showText(this->ui->copyButton_metatileLabel->mapToGlobal(QPoint(0, 0)), "Copied!");
|
QToolTip::showText(this->ui->copyButton_metatileLabel->mapToGlobal(QPoint(0, 0)), "Copied!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue