Insert new tilesets in sorted order
This commit is contained in:
parent
09ce5b5913
commit
8fbcee7f21
4 changed files with 23 additions and 18 deletions
|
@ -389,6 +389,7 @@ private:
|
|||
|
||||
QObjectList shortcutableObjects() const;
|
||||
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
|
||||
int insertTilesetLabel(QStringList * list, QString label);
|
||||
};
|
||||
|
||||
enum MapListUserRoles {
|
||||
|
|
|
@ -171,8 +171,7 @@ public:
|
|||
|
||||
QString defaultSong;
|
||||
QStringList getVisibilities();
|
||||
void insertTilesetLabel(QString label, bool isSecondary);
|
||||
void insertTilesetLabel(QString label, QString isSecondaryStr);
|
||||
void appendTilesetLabel(QString label, QString isSecondaryStr);
|
||||
bool readTilesetLabels();
|
||||
bool readTilesetProperties();
|
||||
bool readMaxMapDataSize();
|
||||
|
|
|
@ -1239,6 +1239,15 @@ void MainWindow::on_action_NewMap_triggered() {
|
|||
openNewMapPopupWindow(MapSortOrder::Group, 0);
|
||||
}
|
||||
|
||||
// Insert label for newly-created tileset into sorted list of existing labels
|
||||
int MainWindow::insertTilesetLabel(QStringList * list, QString label) {
|
||||
int i = 0;
|
||||
for (; i < list->length(); i++)
|
||||
if (list->at(i) > label) break;
|
||||
list->insert(i, label);
|
||||
return i;
|
||||
}
|
||||
|
||||
void MainWindow::on_actionNew_Tileset_triggered() {
|
||||
NewTilesetDialog *createTilesetDialog = new NewTilesetDialog(editor->project, this);
|
||||
if(createTilesetDialog->exec() == QDialog::Accepted){
|
||||
|
@ -1325,11 +1334,13 @@ void MainWindow::on_actionNew_Tileset_triggered() {
|
|||
newSet.appendToMetatiles(editor->project->root, createTilesetDialog->friendlyName, editor->project->usingAsmTilesets);
|
||||
|
||||
if (!createTilesetDialog->isSecondary) {
|
||||
this->ui->comboBox_PrimaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
||||
int index = insertTilesetLabel(&editor->project->primaryTilesetLabels, createTilesetDialog->fullSymbolName);
|
||||
this->ui->comboBox_PrimaryTileset->insertItem(index, createTilesetDialog->fullSymbolName);
|
||||
} else {
|
||||
this->ui->comboBox_SecondaryTileset->addItem(createTilesetDialog->fullSymbolName);
|
||||
int index = insertTilesetLabel(&editor->project->secondaryTilesetLabels, createTilesetDialog->fullSymbolName);
|
||||
this->ui->comboBox_SecondaryTileset->insertItem(index, createTilesetDialog->fullSymbolName);
|
||||
}
|
||||
editor->project->insertTilesetLabel(createTilesetDialog->fullSymbolName, createTilesetDialog->isSecondary);
|
||||
insertTilesetLabel(&editor->project->tilesetLabelsOrdered, createTilesetDialog->fullSymbolName);
|
||||
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setText("Successfully created tileset.");
|
||||
|
|
|
@ -1851,22 +1851,16 @@ QString Project::getDefaultSecondaryTilesetLabel() {
|
|||
return defaultLabel;
|
||||
}
|
||||
|
||||
void Project::insertTilesetLabel(QString label, bool isSecondary) {
|
||||
if (!isSecondary)
|
||||
this->primaryTilesetLabels.append(label);
|
||||
else
|
||||
this->secondaryTilesetLabels.append(label);
|
||||
this->tilesetLabelsOrdered.append(label);
|
||||
}
|
||||
|
||||
void Project::insertTilesetLabel(QString label, QString isSecondaryStr) {
|
||||
void Project::appendTilesetLabel(QString label, QString isSecondaryStr) {
|
||||
bool ok;
|
||||
bool isSecondary = ParseUtil::gameStringToBool(isSecondaryStr, &ok);
|
||||
if (!ok) {
|
||||
logError(QString("Unable to convert value '%1' of isSecondary to bool for tileset %2.").arg(isSecondaryStr).arg(label));
|
||||
return;
|
||||
}
|
||||
insertTilesetLabel(label, isSecondary);
|
||||
QStringList * list = isSecondary ? &this->secondaryTilesetLabels : &this->primaryTilesetLabels;
|
||||
list->append(label);
|
||||
this->tilesetLabelsOrdered.append(label);
|
||||
}
|
||||
|
||||
bool Project::readTilesetLabels() {
|
||||
|
@ -1891,7 +1885,7 @@ bool Project::readTilesetLabels() {
|
|||
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
||||
while (iter.hasNext()) {
|
||||
QRegularExpressionMatch match = iter.next();
|
||||
insertTilesetLabel(match.captured("label"), match.captured("isSecondary"));
|
||||
appendTilesetLabel(match.captured("label"), match.captured("isSecondary"));
|
||||
}
|
||||
filename = asm_filename; // For error reporting further down
|
||||
} else {
|
||||
|
@ -1900,7 +1894,7 @@ bool Project::readTilesetLabels() {
|
|||
QStringList labels = structs.keys();
|
||||
// TODO: This is alphabetical, AdvanceMap import wants the vanilla order in tilesetLabelsOrdered
|
||||
for (const auto tilesetLabel : labels){
|
||||
insertTilesetLabel(tilesetLabel, structs[tilesetLabel].value("isSecondary"));
|
||||
appendTilesetLabel(tilesetLabel, structs[tilesetLabel].value("isSecondary"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue