From 49737d16cc2a26bf6e2c14e87e10b9d9eda74c3a Mon Sep 17 00:00:00 2001 From: Ashley Coleman Date: Fri, 13 Nov 2020 19:00:09 -0800 Subject: [PATCH] Implement delete for wild encounter table --- forms/mainwindow.ui | 17 +++++++++++++++++ include/editor.h | 1 + include/mainwindow.h | 1 + src/editor.cpp | 29 +++++++++++++++++++++++++++++ src/mainwindow.cpp | 4 ++++ 5 files changed, 52 insertions(+) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index f1061bdb..5d703867 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -2527,6 +2527,23 @@ + + + + <html><head/><body><p>Delete a group of wild pokemon data on this map.</p></body></html> + + + + + + + :/icons/delete.ico:/icons/delete.ico + + + true + + + diff --git a/include/editor.h b/include/editor.h index c1492b0f..bfdbd1bc 100644 --- a/include/editor.h +++ b/include/editor.h @@ -84,6 +84,7 @@ public: void addNewConnection(); void removeCurrentConnection(); void addNewWildMonGroup(QWidget *window); + void deleteWildMonGroup(); void updateDiveMap(QString mapName); void updateEmergeMap(QString mapName); void setSelectedConnectionFromMap(QString mapName); diff --git a/include/mainwindow.h b/include/mainwindow.h index d9377993..b19908b8 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -225,6 +225,7 @@ private slots: void on_tableWidget_CustomHeaderFields_cellChanged(int row, int column); void on_horizontalSlider_MetatileZoom_valueChanged(int value); void on_pushButton_NewWildMonGroup_clicked(); + void on_pushButton_DeleteWildMonGroup_clicked(); void on_pushButton_ConfigureEncountersJSON_clicked(); void on_actionRegion_Map_Editor_triggered(); diff --git a/src/editor.cpp b/src/editor.cpp index 12697eb6..85cc7fd1 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -356,6 +356,35 @@ void Editor::addNewWildMonGroup(QWidget *window) { } } +void Editor::deleteWildMonGroup() { + QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel; + + if (labelCombo->count() < 1) { + return; + } + + QMessageBox msgBox; + msgBox.setText("Confirm Delete"); + msgBox.setInformativeText("Are you sure you want to delete " + labelCombo->currentText() + "?"); + + QPushButton *deleteButton = msgBox.addButton("Delete", QMessageBox::DestructiveRole); + msgBox.addButton(QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Cancel); + msgBox.exec(); + + if (msgBox.clickedButton() == deleteButton) { + auto it = project->wildMonData.find(map->constantName); + it.value().erase(labelCombo->currentText()); + + int i = project->encounterGroupLabels.indexOf(labelCombo->currentText()); + project->encounterGroupLabels.remove(i); + + displayWildMonTables(); + + emit wildMonDataChanged(); + } +} + void Editor::configureEncounterJSON(QWidget *window) { QVector fieldSlots; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f40d94c1..d9e7d9a2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2376,6 +2376,10 @@ void MainWindow::on_pushButton_NewWildMonGroup_clicked() { editor->addNewWildMonGroup(this); } +void MainWindow::on_pushButton_DeleteWildMonGroup_clicked() { + editor->deleteWildMonGroup(); +} + void MainWindow::on_pushButton_ConfigureEncountersJSON_clicked() { editor->configureEncounterJSON(this); }