mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-25 17:25:38 -05:00
insert new map entries when edited
This commit is contained in:
@@ -163,11 +163,17 @@ void RegionMap::saveLayout() {
|
||||
|
||||
entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n";
|
||||
|
||||
int longest = 1;
|
||||
for (auto sec : project->mapSectionNameToValue.keys()) {
|
||||
if (sec.length() > longest) longest = sec.length();
|
||||
}
|
||||
|
||||
for (auto sec : project->mapSectionNameToValue.keys()) {
|
||||
if (!mapSecToMapEntry.contains(sec)) continue;
|
||||
RegionMapEntry entry = mapSecToMapEntry.value(sec);
|
||||
entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
|
||||
+ QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
|
||||
entries_text += " [" + sec + QString("]%1= {").arg(QString(" ").repeated(1 + longest - sec.length()))
|
||||
+ QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
|
||||
+ QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
|
||||
}
|
||||
entries_text += "};\n\n#endif // GUARD_DATA_REGION_MAP_REGION_MAP_ENTRIES_H\n";
|
||||
|
||||
@@ -201,11 +207,11 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
|
||||
if (!name.isEmpty()) {
|
||||
this->map_squares[index].map_name = name;
|
||||
this->project->mapSecToMapHoverName->insert(sec, name);
|
||||
QString sName = fix_case(sec);
|
||||
QString sName = fixCase(sec);
|
||||
sMapNamesMap.insert(sName, name);
|
||||
if (!mapSecToMapEntry.keys().contains(sec)) {
|
||||
sMapNames.append(sName);
|
||||
RegionMapEntry entry = {x, y, 1, 1, sName};
|
||||
RegionMapEntry entry(x, y, 1, 1, sName);
|
||||
mapSecToMapEntry.insert(sec, entry);
|
||||
}
|
||||
}
|
||||
@@ -342,7 +348,7 @@ int RegionMap::getMapSquareIndex(int x, int y) {
|
||||
|
||||
// For turning a MAPSEC_NAME into a unique identifier sMapName-style variable.
|
||||
// CAPS_WITH_UNDERSCORE to CamelCase
|
||||
QString RegionMap::fix_case(QString caps) {
|
||||
QString RegionMap::fixCase(QString caps) {
|
||||
bool big = true;
|
||||
QString camel;
|
||||
|
||||
|
||||
@@ -214,6 +214,15 @@ void RegionMapEditor::displayRegionMapEntryOptions() {
|
||||
}
|
||||
|
||||
void RegionMapEditor::updateRegionMapEntryOptions(QString section) {
|
||||
bool enabled = section == "MAPSEC_NONE" ? false : true;
|
||||
|
||||
this->ui->spinBox_RM_Entry_x->setEnabled(enabled);
|
||||
this->ui->spinBox_RM_Entry_y->setEnabled(enabled);
|
||||
this->ui->spinBox_RM_Entry_width->setEnabled(enabled);
|
||||
this->ui->spinBox_RM_Entry_height->setEnabled(enabled);
|
||||
|
||||
// if the key is not in the entries map, add it
|
||||
|
||||
this->ui->comboBox_RM_Entry_MapSection->setCurrentText(section);
|
||||
this->activeEntry = section;
|
||||
this->region_map_entries_item->currentSection = section;
|
||||
@@ -328,6 +337,17 @@ bool RegionMapEditor::createCityMap(QString name) {
|
||||
return !errored;
|
||||
}
|
||||
|
||||
bool RegionMapEditor::tryInsertNewMapEntry(QString mapsec) {
|
||||
if (!this->region_map->mapSecToMapEntry.keys().contains(mapsec) && mapsec != "MAPSEC_NONE") {
|
||||
RegionMapEntry entry(0, 0, 1, 1, region_map->fixCase(mapsec));
|
||||
this->region_map->sMapNamesMap.insert(region_map->fixCase(mapsec), QString());
|
||||
this->region_map->mapSecToMapEntry.insert(mapsec, entry);
|
||||
this->region_map->sMapNames.append(region_map->fixCase(mapsec));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) {
|
||||
this->selectedImageTile = id;
|
||||
}
|
||||
@@ -485,6 +505,7 @@ void RegionMapEditor::on_comboBox_RM_Entry_MapSection_activated(const QString &t
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
|
||||
tryInsertNewMapEntry(activeEntry);
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setX(x);
|
||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
||||
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
|
||||
@@ -494,6 +515,7 @@ void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
|
||||
tryInsertNewMapEntry(activeEntry);
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setY(y);
|
||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
||||
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
|
||||
@@ -503,12 +525,14 @@ void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
|
||||
tryInsertNewMapEntry(activeEntry);
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setWidth(width);
|
||||
this->region_map_entries_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
|
||||
tryInsertNewMapEntry(activeEntry);
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setHeight(height);
|
||||
this->region_map_entries_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
|
||||
Reference in New Issue
Block a user