fix config update crash, add real swap & rename old swap to replace

This commit is contained in:
garak 2022-05-10 15:02:15 -04:00 committed by garakmon
parent 04ef5c5b7c
commit 13603901e2
5 changed files with 69 additions and 7 deletions

View file

@ -1100,6 +1100,7 @@
</property> </property>
<addaction name="action_RegionMap_Resize"/> <addaction name="action_RegionMap_Resize"/>
<addaction name="action_Swap"/> <addaction name="action_Swap"/>
<addaction name="action_Replace"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_RegionMap_ClearImage"/> <addaction name="action_RegionMap_ClearImage"/>
<addaction name="action_RegionMap_ClearLayout"/> <addaction name="action_RegionMap_ClearLayout"/>
@ -1138,7 +1139,7 @@
</action> </action>
<action name="action_Swap"> <action name="action_Swap">
<property name="text"> <property name="text">
<string>Swap...</string> <string>Swap Layout Sections...</string>
</property> </property>
</action> </action>
<action name="action_RegionMap_ClearImage"> <action name="action_RegionMap_ClearImage">
@ -1176,6 +1177,11 @@
<string>Update Config...</string> <string>Update Config...</string>
</property> </property>
</action> </action>
<action name="action_Replace">
<property name="text">
<string>Replace Layout Section...</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View file

@ -70,6 +70,7 @@ public:
void clearLayout(); void clearLayout();
void clearImage(); void clearImage();
void replaceSection(QString oldSection, QString newSection); void replaceSection(QString oldSection, QString newSection);
void swapSections(QString secA, QString secB);
unsigned getTileId(int index); unsigned getTileId(int index);
shared_ptr<TilemapTile> getTile(int index); shared_ptr<TilemapTile> getTile(int index);

View file

@ -126,6 +126,7 @@ private slots:
void on_action_RegionMap_ClearLayout_triggered(); void on_action_RegionMap_ClearLayout_triggered();
void on_action_RegionMap_ClearEntries_triggered(); void on_action_RegionMap_ClearEntries_triggered();
void on_action_Swap_triggered(); void on_action_Swap_triggered();
void on_action_Replace_triggered();
void on_action_Configure_triggered(); void on_action_Configure_triggered();
void on_tabWidget_Region_Map_currentChanged(int); void on_tabWidget_Region_Map_currentChanged(int);
void on_pushButton_RM_Options_delete_clicked(); void on_pushButton_RM_Options_delete_clicked();

View file

@ -415,6 +415,19 @@ void RegionMap::replaceSection(QString oldSection, QString newSection) {
} }
} }
void RegionMap::swapSections(QString secA, QString secB) {
for (auto &square : this->layouts[this->current_layer]) {
if (square.map_section == secA) {
square.map_section = secB;
square.has_map = (square.map_section != "MAPSEC_NONE");
}
else if (square.map_section == secB) {
square.map_section = secA;
square.has_map = (square.map_section != "MAPSEC_NONE");
}
}
}
void RegionMap::resizeTilemap(int newWidth, int newHeight, bool update) { void RegionMap::resizeTilemap(int newWidth, int newHeight, bool update) {
auto tilemapCopy = this->tilemap; auto tilemapCopy = this->tilemap;
int oldWidth = this->tilemap_width; int oldWidth = this->tilemap_width;

View file

@ -83,6 +83,10 @@ void RegionMapEditor::initShortcuts() {
shortcutsConfig.load(); shortcutsConfig.load();
shortcutsConfig.setDefaultShortcuts(shortcutableObjects()); shortcutsConfig.setDefaultShortcuts(shortcutableObjects());
applyUserShortcuts(); applyUserShortcuts();
connect(&(this->history), &QUndoGroup::indexChanged, [this](int) {
on_tabWidget_Region_Map_currentChanged(this->ui->tabWidget_Region_Map->currentIndex());
});
} }
QObjectList RegionMapEditor::shortcutableObjects() const { QObjectList RegionMapEditor::shortcutableObjects() const {
@ -421,9 +425,11 @@ void RegionMapEditor::clear() {
// except the config json // except the config json
auto stacks = this->history.stacks(); auto stacks = this->history.stacks();
this->history.blockSignals(true);
for (auto *stack : stacks) { for (auto *stack : stacks) {
this->history.removeStack(stack); this->history.removeStack(stack);
} }
this->history.blockSignals(false);
for (auto p : this->region_maps) { for (auto p : this->region_maps) {
delete p.second; delete p.second;
} }
@ -497,10 +503,6 @@ bool RegionMapEditor::setup() {
setRegionMap(region_maps.begin()->second); setRegionMap(region_maps.begin()->second);
} }
connect(&(this->history), &QUndoGroup::indexChanged, [this](int) {
on_tabWidget_Region_Map_currentChanged(this->ui->tabWidget_Region_Map->currentIndex());
});
this->show(); this->show();
this->setWindowState(Qt::WindowState::WindowActive); this->setWindowState(Qt::WindowState::WindowActive);
this->activateWindow(); this->activateWindow();
@ -555,7 +557,6 @@ bool RegionMapEditor::load() {
void RegionMapEditor::setRegionMap(RegionMap *map) { void RegionMapEditor::setRegionMap(RegionMap *map) {
this->region_map = map; this->region_map = map;
this->currIndex = this->region_map->firstLayoutIndex(); this->currIndex = this->region_map->firstLayoutIndex();
this->region_map->editHistory.setActive();
if (this->region_map->layoutEnabled()) { if (this->region_map->layoutEnabled()) {
this->ui->tabWidget_Region_Map->setTabEnabled(1, true); this->ui->tabWidget_Region_Map->setTabEnabled(1, true);
@ -567,6 +568,7 @@ void RegionMapEditor::setRegionMap(RegionMap *map) {
} }
displayRegionMap(); displayRegionMap();
this->region_map->editHistory.setActive();
} }
bool RegionMapEditor::saveRegionMap(RegionMap *map) { bool RegionMapEditor::saveRegionMap(RegionMap *map) {
@ -1215,6 +1217,45 @@ void RegionMapEditor::on_action_Swap_triggered() {
QFormLayout form(&popup); QFormLayout form(&popup);
QComboBox *oldSecBox = new QComboBox();
oldSecBox->addItems(this->project->mapSectionValueToName.values());
form.addRow(new QLabel("Map Section 1:"), oldSecBox);
QComboBox *newSecBox = new QComboBox();
newSecBox->addItems(this->project->mapSectionValueToName.values());
form.addRow(new QLabel("Map Section 2:"), newSecBox);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &popup);
form.addRow(&buttonBox);
QString beforeSection, afterSection;
connect(&buttonBox, &QDialogButtonBox::rejected, &popup, &QDialog::reject);
connect(&buttonBox, &QDialogButtonBox::accepted, [&popup, &oldSecBox, &newSecBox, &beforeSection, &afterSection](){
beforeSection = oldSecBox->currentText();
afterSection = newSecBox->currentText();
if (!beforeSection.isEmpty() && !afterSection.isEmpty()) {
popup.accept();
}
});
if (popup.exec() == QDialog::Accepted) {
QList<LayoutSquare> oldLayout = this->region_map->getLayout(this->region_map->getLayer());
this->region_map->swapSections(beforeSection, afterSection);
QList<LayoutSquare> newLayout = this->region_map->getLayout(this->region_map->getLayer());
EditLayout *commit = new EditLayout(this->region_map, this->region_map->getLayer(), -5, oldLayout, newLayout);
commit->setText("Swap Layout Sections " + beforeSection + " <<>> " + afterSection);
this->region_map->editHistory.push(commit);
displayRegionMapLayout();
this->region_map_layout_item->select(this->region_map_layout_item->selectedTile);
}
}
void RegionMapEditor::on_action_Replace_triggered() {
QDialog popup(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
popup.setWindowTitle("Replace Map Section");
popup.setWindowModality(Qt::NonModal);
QFormLayout form(&popup);
QComboBox *oldSecBox = new QComboBox(); QComboBox *oldSecBox = new QComboBox();
oldSecBox->addItems(this->project->mapSectionValueToName.values()); oldSecBox->addItems(this->project->mapSectionValueToName.values());
form.addRow(new QLabel("Old Map Section:"), oldSecBox); form.addRow(new QLabel("Old Map Section:"), oldSecBox);
@ -1240,7 +1281,7 @@ void RegionMapEditor::on_action_Swap_triggered() {
this->region_map->replaceSection(beforeSection, afterSection); this->region_map->replaceSection(beforeSection, afterSection);
QList<LayoutSquare> newLayout = this->region_map->getLayout(this->region_map->getLayer()); QList<LayoutSquare> newLayout = this->region_map->getLayout(this->region_map->getLayer());
EditLayout *commit = new EditLayout(this->region_map, this->region_map->getLayer(), -2, oldLayout, newLayout); EditLayout *commit = new EditLayout(this->region_map, this->region_map->getLayer(), -2, oldLayout, newLayout);
commit->setText("Swap Layout Sections " + beforeSection + " >> " + afterSection); commit->setText("Replace Layout Section " + beforeSection + " >> " + afterSection);
this->region_map->editHistory.push(commit); this->region_map->editHistory.push(commit);
displayRegionMapLayout(); displayRegionMapLayout();
this->region_map_layout_item->select(this->region_map_layout_item->selectedTile); this->region_map_layout_item->select(this->region_map_layout_item->selectedTile);