diff options
| author | Dentomologist <dentomologist@gmail.com> | 2024-07-30 19:55:27 -0700 |
|---|---|---|
| committer | Dentomologist <dentomologist@gmail.com> | 2024-08-25 23:44:17 -0700 |
| commit | f4db168a8e63751535d174d27abe7dbab19d4d74 (patch) | |
| tree | 7b60b7b49c51c63e6b73698504538aa5517336c0 /Source/Core/DolphinQt/Config/ARCodeWidget.cpp | |
| parent | 232d24109df7af9449c0604523ce4568e78aa52d (diff) | |
CheatsManager: Create ARCodeWidget and GeckoCodeWidget only once.
Create ARCodeWidget and GeckoCodeWidget once on startup rather than
every time a game is launched or shutdown.
In addition to losing focus on the tab (since the previous widget and
tab no longer existed), the behavior prior to this commit could cause a
crash if the user initiated a game shutdown and then opened a code edit
window since the AR/GeckoCodeWidget would get deleted in the meantime.
Diffstat (limited to 'Source/Core/DolphinQt/Config/ARCodeWidget.cpp')
| -rw-r--r-- | Source/Core/DolphinQt/Config/ARCodeWidget.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp index 82a5dce74b..a305786f68 100644 --- a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp @@ -40,6 +40,22 @@ ARCodeWidget::ARCodeWidget(std::string game_id, u16 game_revision, bool restart_ ARCodeWidget::~ARCodeWidget() = default; +void ARCodeWidget::ChangeGame(std::string game_id, const u16 game_revision) +{ + m_game_id = std::move(game_id); + m_game_revision = game_revision; + m_restart_required = false; + + m_ar_codes.clear(); + + // If a CheatCodeEditor is open, it's now trying to add or edit a code in the previous game's code + // list which is no longer loaded. Letting the user save the code wouldn't make sense, so close + // the dialog instead. + m_cheat_code_editor->reject(); + + LoadCodes(); +} + void ARCodeWidget::CreateWidgets() { m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this); @@ -51,6 +67,8 @@ void ARCodeWidget::CreateWidgets() m_code_edit = new NonDefaultQPushButton(tr("&Edit Code...")); m_code_remove = new NonDefaultQPushButton(tr("&Remove Code")); + m_cheat_code_editor = new CheatCodeEditor(this); + m_code_list->setContextMenuPolicy(Qt::CustomContextMenu); auto* button_layout = new QHBoxLayout; @@ -250,10 +268,9 @@ void ARCodeWidget::OnCodeAddClicked() ActionReplay::ARCode ar; ar.enabled = true; - CheatCodeEditor ed(this); - ed.SetARCode(&ar); - SetQWidgetWindowDecorations(&ed); - if (ed.exec() == QDialog::Rejected) + m_cheat_code_editor->SetARCode(&ar); + SetQWidgetWindowDecorations(m_cheat_code_editor); + if (m_cheat_code_editor->exec() == QDialog::Rejected) return; m_ar_codes.push_back(std::move(ar)); @@ -270,23 +287,19 @@ void ARCodeWidget::OnCodeEditClicked() const auto* const selected = items[0]; auto& current_ar = m_ar_codes[m_code_list->row(selected)]; + SetQWidgetWindowDecorations(m_cheat_code_editor); - CheatCodeEditor ed(this); if (current_ar.user_defined) { - ed.SetARCode(¤t_ar); - - SetQWidgetWindowDecorations(&ed); - if (ed.exec() == QDialog::Rejected) + m_cheat_code_editor->SetARCode(¤t_ar); + if (m_cheat_code_editor->exec() == QDialog::Rejected) return; } else { ActionReplay::ARCode ar = current_ar; - ed.SetARCode(&ar); - - SetQWidgetWindowDecorations(&ed); - if (ed.exec() == QDialog::Rejected) + m_cheat_code_editor->SetARCode(&ar); + if (m_cheat_code_editor->exec() == QDialog::Rejected) return; m_ar_codes.push_back(std::move(ar)); |
