insert new map entries when edited
This commit is contained in:
parent
875320ae26
commit
92ea089876
4 changed files with 47 additions and 9 deletions
|
@ -18,6 +18,14 @@
|
||||||
class RegionMapEntry
|
class RegionMapEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
RegionMapEntry()=default;
|
||||||
|
RegionMapEntry(int x_, int y_, int width_, int height_, QString name_) {
|
||||||
|
this-> x = x_;
|
||||||
|
this-> y = y_;
|
||||||
|
this-> width = width_;
|
||||||
|
this-> height = height_;
|
||||||
|
this-> name = name_;
|
||||||
|
}
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int width;
|
int width;
|
||||||
|
@ -98,6 +106,8 @@ public:
|
||||||
QVector<uint8_t> getTiles();
|
QVector<uint8_t> getTiles();
|
||||||
void setTiles(QVector<uint8_t> tileIds);
|
void setTiles(QVector<uint8_t> tileIds);
|
||||||
|
|
||||||
|
QString fixCase(QString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int layout_width_;
|
int layout_width_;
|
||||||
int layout_height_;
|
int layout_height_;
|
||||||
|
@ -112,8 +122,6 @@ private:
|
||||||
|
|
||||||
int img_index_(int x, int y);
|
int img_index_(int x, int y);
|
||||||
int layout_index_(int x, int y);
|
int layout_index_(int x, int y);
|
||||||
|
|
||||||
QString fix_case(QString);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REGIONMAP_H
|
#endif // REGIONMAP_H
|
||||||
|
|
|
@ -92,11 +92,11 @@ private:
|
||||||
void displayCityMapTileSelector();
|
void displayCityMapTileSelector();
|
||||||
void displayCityMap(QString name);
|
void displayCityMap(QString name);
|
||||||
void displayRegionMapEntryOptions();
|
void displayRegionMapEntryOptions();
|
||||||
void uodateRegionMapEntryOptions(int);//
|
void updateRegionMapEntryOptions(QString);
|
||||||
void updateRegionMapEntryOptions(QString);//
|
|
||||||
void importTileImage(bool city = false);
|
void importTileImage(bool city = false);
|
||||||
|
|
||||||
bool createCityMap(QString name);
|
bool createCityMap(QString name);
|
||||||
|
bool tryInsertNewMapEntry(QString);
|
||||||
|
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent* event);
|
||||||
|
|
||||||
|
|
|
@ -163,11 +163,17 @@ void RegionMap::saveLayout() {
|
||||||
|
|
||||||
entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n";
|
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()) {
|
for (auto sec : project->mapSectionNameToValue.keys()) {
|
||||||
if (!mapSecToMapEntry.contains(sec)) continue;
|
if (!mapSecToMapEntry.contains(sec)) continue;
|
||||||
RegionMapEntry entry = mapSecToMapEntry.value(sec);
|
RegionMapEntry entry = mapSecToMapEntry.value(sec);
|
||||||
entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
|
entries_text += " [" + sec + QString("]%1= {").arg(QString(" ").repeated(1 + longest - sec.length()))
|
||||||
+ QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
|
+ 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";
|
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()) {
|
if (!name.isEmpty()) {
|
||||||
this->map_squares[index].map_name = name;
|
this->map_squares[index].map_name = name;
|
||||||
this->project->mapSecToMapHoverName->insert(sec, name);
|
this->project->mapSecToMapHoverName->insert(sec, name);
|
||||||
QString sName = fix_case(sec);
|
QString sName = fixCase(sec);
|
||||||
sMapNamesMap.insert(sName, name);
|
sMapNamesMap.insert(sName, name);
|
||||||
if (!mapSecToMapEntry.keys().contains(sec)) {
|
if (!mapSecToMapEntry.keys().contains(sec)) {
|
||||||
sMapNames.append(sName);
|
sMapNames.append(sName);
|
||||||
RegionMapEntry entry = {x, y, 1, 1, sName};
|
RegionMapEntry entry(x, y, 1, 1, sName);
|
||||||
mapSecToMapEntry.insert(sec, entry);
|
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.
|
// For turning a MAPSEC_NAME into a unique identifier sMapName-style variable.
|
||||||
// CAPS_WITH_UNDERSCORE to CamelCase
|
// CAPS_WITH_UNDERSCORE to CamelCase
|
||||||
QString RegionMap::fix_case(QString caps) {
|
QString RegionMap::fixCase(QString caps) {
|
||||||
bool big = true;
|
bool big = true;
|
||||||
QString camel;
|
QString camel;
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,15 @@ void RegionMapEditor::displayRegionMapEntryOptions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::updateRegionMapEntryOptions(QString section) {
|
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->ui->comboBox_RM_Entry_MapSection->setCurrentText(section);
|
||||||
this->activeEntry = section;
|
this->activeEntry = section;
|
||||||
this->region_map_entries_item->currentSection = section;
|
this->region_map_entries_item->currentSection = section;
|
||||||
|
@ -328,6 +337,17 @@ bool RegionMapEditor::createCityMap(QString name) {
|
||||||
return !errored;
|
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) {
|
void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) {
|
||||||
this->selectedImageTile = 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) {
|
void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
|
||||||
|
tryInsertNewMapEntry(activeEntry);
|
||||||
this->region_map->mapSecToMapEntry[activeEntry].setX(x);
|
this->region_map->mapSecToMapEntry[activeEntry].setX(x);
|
||||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
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);
|
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) {
|
void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
|
||||||
|
tryInsertNewMapEntry(activeEntry);
|
||||||
this->region_map->mapSecToMapEntry[activeEntry].setY(y);
|
this->region_map->mapSecToMapEntry[activeEntry].setY(y);
|
||||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
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);
|
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) {
|
void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
|
||||||
|
tryInsertNewMapEntry(activeEntry);
|
||||||
this->region_map->mapSecToMapEntry[activeEntry].setWidth(width);
|
this->region_map->mapSecToMapEntry[activeEntry].setWidth(width);
|
||||||
this->region_map_entries_item->draw();
|
this->region_map_entries_item->draw();
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
|
void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
|
||||||
|
tryInsertNewMapEntry(activeEntry);
|
||||||
this->region_map->mapSecToMapEntry[activeEntry].setHeight(height);
|
this->region_map->mapSecToMapEntry[activeEntry].setHeight(height);
|
||||||
this->region_map_entries_item->draw();
|
this->region_map_entries_item->draw();
|
||||||
this->hasUnsavedChanges = true;
|
this->hasUnsavedChanges = true;
|
||||||
|
|
Loading…
Reference in a new issue