remember changes to region map layout between saves

This commit is contained in:
garak 2019-03-23 16:56:30 -04:00
parent 8af714a681
commit 545e2134d8
4 changed files with 22 additions and 16 deletions

View file

@ -29,6 +29,7 @@ public:
void loadRegionMapData();
void loadCityMaps();
void setCurrentSquareOptions();
void onRegionMapTileSelectorSelectedTileChanged(unsigned id);
void onCityMapTileSelectorSelectedTileChanged(unsigned id);

View file

@ -174,10 +174,10 @@ 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);
if (!mapSecToMapEntry.keys().contains(sec)) {
QString sName = fix_case(sec);
sMapNames.append(sName);
sMapNamesMap.insert(sName, name);
if (!mapSecToMapEntry.keys().contains(sec)) {
sMapNames.append(sName);
struct RegionMapEntry entry = {x, y, 1, 1, sName};
mapSecToMapEntry.insert(sec, entry);
}

View file

@ -39,14 +39,8 @@ RegionMapEditor::~RegionMapEditor()
}
void RegionMapEditor::on_action_RegionMap_Save_triggered() {
setCurrentSquareOptions();
if (project && region_map) {
this->region_map->saveOptions(
this->region_map_layout_item->selectedTile,
this->ui->comboBox_RM_ConnectedMap->currentText(),
this->ui->lineEdit_RM_MapName->text(),
this->ui->spinBox_RM_Options_x->value(),
this->ui->spinBox_RM_Options_y->value()
);
this->region_map->save();
this->city_map_item->save();
this->currIndex = this->region_map_layout_item->highlightedTile;
@ -56,6 +50,18 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() {
this->hasUnsavedChanges = false;
}
void RegionMapEditor::setCurrentSquareOptions() {
if (project && region_map) {
this->region_map->saveOptions(
this->currIndex,
this->ui->comboBox_RM_ConnectedMap->currentText(),
this->ui->lineEdit_RM_MapName->text(),
this->ui->spinBox_RM_Options_x->value(),
this->ui->spinBox_RM_Options_y->value()
);
}
}
void RegionMapEditor::loadRegionMapData() {
this->region_map->init(project);
this->currIndex = this->region_map->width() * this->region_map->padTop + this->region_map->padLeft;
@ -154,7 +160,7 @@ void RegionMapEditor::displayRegionMapLayoutOptions() {
this->region_map->height() - this->region_map->padTop - this->region_map->padBottom - 1
);
updateRegionMapLayoutOptions(currIndex);
updateRegionMapLayoutOptions(this->currIndex);
// TODO: implement when the code is decompiled
this->ui->label_RM_CityMap->setVisible(false);
@ -296,6 +302,7 @@ void RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared() {
}
void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
setCurrentSquareOptions();
QString message = QString();
this->currIndex = index;
this->region_map_layout_item->highlightedTile = index;
@ -306,6 +313,7 @@ void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
this->ui->statusbar->showMessage(message);
updateRegionMapLayoutOptions(index);
this->region_map_layout_item->draw();
}
void RegionMapEditor::onRegionMapLayoutHoveredTileChanged(int index) {
@ -348,6 +356,7 @@ void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, Reg
//} else if (event->buttons() & Qt::MiddleButton) {// TODO
} else {
item->paint(event);
this->region_map_layout_item->draw();
this->hasUnsavedChanges = true;
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
RegionMapHistoryItem *current = history.current();

View file

@ -10,11 +10,7 @@ void RegionMapLayoutPixmapItem::draw() {
QImage bottom_img = this->tile_selector->tileImg(region_map->map_squares[i].tile_img_id);
QImage top_img(8, 8, QImage::Format_RGBA8888);
if (region_map->map_squares[i].has_map) {
if (i == highlightedTile) {
top_img.fill(Qt::red);
} else {
top_img.fill(Qt::gray);
}
} else {
top_img.fill(Qt::black);
}
@ -55,8 +51,8 @@ void RegionMapLayoutPixmapItem::select(int index) {
void RegionMapLayoutPixmapItem::highlight(int x, int y, int red) {
this->highlightedTile = red;
draw();
SelectablePixmapItem::select(x + this->region_map->padLeft, y + this->region_map->padTop, 0, 0);
draw();
}
void RegionMapLayoutPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {