mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-28 11:36:26 -05:00
Support custom fields for top-level map attributes
This commit is contained in:
@@ -1109,6 +1109,21 @@ void Editor::toggleBorderVisibility(bool visible)
|
||||
this->setConnectionsVisibility(visible);
|
||||
}
|
||||
|
||||
void Editor::updateCustomMapHeaderValues(QTableWidget *table)
|
||||
{
|
||||
QMap<QString, QString> fields;
|
||||
for (int row = 0; row < table->rowCount(); row++) {
|
||||
QString keyStr = "";
|
||||
QString valueStr = "";
|
||||
QTableWidgetItem *key = table->item(row, 0);
|
||||
QTableWidgetItem *value = table->item(row, 1);
|
||||
if (key) keyStr = key->text();
|
||||
if (value) valueStr = value->text();
|
||||
fields[keyStr] = valueStr;
|
||||
}
|
||||
map->customHeaders = fields;
|
||||
}
|
||||
|
||||
Tileset* Editor::getCurrentMapPrimaryTileset()
|
||||
{
|
||||
QString tilesetLabel = map->layout->tileset_primary_label;
|
||||
|
||||
@@ -486,6 +486,17 @@ void MainWindow::displayMapProperties() {
|
||||
ui->checkBox_AllowRunning->setChecked(map->allowRunning.toInt() > 0 || map->allowRunning == "TRUE");
|
||||
ui->checkBox_AllowBiking->setChecked(map->allowBiking.toInt() > 0 || map->allowBiking == "TRUE");
|
||||
ui->checkBox_AllowEscapeRope->setChecked(map->allowEscapeRope.toInt() > 0 || map->allowEscapeRope == "TRUE");
|
||||
|
||||
// Custom fields table.
|
||||
ui->tableWidget_CustomHeaderFields->blockSignals(true);
|
||||
ui->tableWidget_CustomHeaderFields->setRowCount(0);
|
||||
for (auto it = map->customHeaders.begin(); it != map->customHeaders.end(); it++) {
|
||||
int rowIndex = ui->tableWidget_CustomHeaderFields->rowCount();
|
||||
ui->tableWidget_CustomHeaderFields->insertRow(rowIndex);
|
||||
ui->tableWidget_CustomHeaderFields->setItem(rowIndex, 0, new QTableWidgetItem(it.key()));
|
||||
ui->tableWidget_CustomHeaderFields->setItem(rowIndex, 1, new QTableWidgetItem(it.value()));
|
||||
}
|
||||
ui->tableWidget_CustomHeaderFields->blockSignals(false);
|
||||
}
|
||||
|
||||
void MainWindow::on_comboBox_Song_activated(const QString &song)
|
||||
@@ -1903,6 +1914,42 @@ void MainWindow::on_actionAbout_Porymap_triggered()
|
||||
window->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_AddCustomHeaderField_clicked()
|
||||
{
|
||||
int rowIndex = this->ui->tableWidget_CustomHeaderFields->rowCount();
|
||||
this->ui->tableWidget_CustomHeaderFields->insertRow(rowIndex);
|
||||
this->ui->tableWidget_CustomHeaderFields->selectRow(rowIndex);
|
||||
this->editor->updateCustomMapHeaderValues(this->ui->tableWidget_CustomHeaderFields);
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_DeleteCustomHeaderField_clicked()
|
||||
{
|
||||
int rowCount = this->ui->tableWidget_CustomHeaderFields->rowCount();
|
||||
if (rowCount > 0) {
|
||||
QModelIndexList indexList = ui->tableWidget_CustomHeaderFields->selectionModel()->selectedIndexes();
|
||||
QList<QPersistentModelIndex> persistentIndexes;
|
||||
for (QModelIndex index : indexList) {
|
||||
QPersistentModelIndex persistentIndex(index);
|
||||
persistentIndexes.append(persistentIndex);
|
||||
}
|
||||
|
||||
for (QPersistentModelIndex index : persistentIndexes) {
|
||||
this->ui->tableWidget_CustomHeaderFields->removeRow(index.row());
|
||||
}
|
||||
|
||||
if (this->ui->tableWidget_CustomHeaderFields->rowCount() > 0) {
|
||||
this->ui->tableWidget_CustomHeaderFields->selectRow(0);
|
||||
}
|
||||
|
||||
this->editor->updateCustomMapHeaderValues(this->ui->tableWidget_CustomHeaderFields);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_tableWidget_CustomHeaderFields_cellChanged(int row, int column)
|
||||
{
|
||||
this->editor->updateCustomMapHeaderValues(this->ui->tableWidget_CustomHeaderFields);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
porymapConfig.setGeometry(
|
||||
this->saveGeometry(),
|
||||
|
||||
@@ -128,6 +128,58 @@ QStringList* Project::getLabelValues(QList<QStringList> *list, QString label) {
|
||||
return values;
|
||||
}
|
||||
|
||||
QMap<QString, bool> Project::getTopLevelMapFields() {
|
||||
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeemerald) {
|
||||
return QMap<QString, bool>
|
||||
{
|
||||
{"id", true},
|
||||
{"name", true},
|
||||
{"layout", true},
|
||||
{"music", true},
|
||||
{"region_map_section", true},
|
||||
{"requires_flash", true},
|
||||
{"weather", true},
|
||||
{"map_type", true},
|
||||
{"allow_bike", true},
|
||||
{"allow_escape_rope", true},
|
||||
{"allow_running", true},
|
||||
{"show_map_name", true},
|
||||
{"battle_scene", true},
|
||||
{"connections", true},
|
||||
{"object_events", true},
|
||||
{"warp_events", true},
|
||||
{"coord_events", true},
|
||||
{"bg_events", true},
|
||||
{"shared_events_map", true},
|
||||
{"shared_scripts_map", true},
|
||||
};
|
||||
} else if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby) {
|
||||
return QMap<QString, bool>
|
||||
{
|
||||
{"id", true},
|
||||
{"name", true},
|
||||
{"layout", true},
|
||||
{"music", true},
|
||||
{"region_map_section", true},
|
||||
{"requires_flash", true},
|
||||
{"weather", true},
|
||||
{"map_type", true},
|
||||
{"show_map_name", true},
|
||||
{"battle_scene", true},
|
||||
{"connections", true},
|
||||
{"object_events", true},
|
||||
{"warp_events", true},
|
||||
{"coord_events", true},
|
||||
{"bg_events", true},
|
||||
{"shared_events_map", true},
|
||||
{"shared_scripts_map", true},
|
||||
};
|
||||
} else {
|
||||
logError("Invalid game version");
|
||||
return QMap<QString, bool>();
|
||||
}
|
||||
}
|
||||
|
||||
bool Project::loadMapData(Map* map) {
|
||||
if (!map->isPersistedToFile) {
|
||||
return true;
|
||||
@@ -322,6 +374,14 @@ bool Project::loadMapData(Map* map) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for custom fields
|
||||
QMap<QString, bool> baseFields = this->getTopLevelMapFields();
|
||||
for (QString key : mapObj.keys()) {
|
||||
if (!baseFields.contains(key)) {
|
||||
map->customHeaders.insert(key, mapObj[key].toString());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -954,6 +1014,11 @@ void Project::saveMap(Map *map) {
|
||||
mapObj["shared_scripts_map"] = map->sharedScriptsMap;
|
||||
}
|
||||
|
||||
// Custom header fields.
|
||||
for (QString key : map->customHeaders.keys()) {
|
||||
mapObj[key] = map->customHeaders[key];
|
||||
}
|
||||
|
||||
QJsonDocument mapDoc(mapObj);
|
||||
mapFile.write(mapDoc.toJson());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user