From f4db168a8e63751535d174d27abe7dbab19d4d74 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Tue, 30 Jul 2024 19:55:27 -0700 Subject: 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. --- Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp | 39 +++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp') diff --git a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp index 08db0c1648..0fc875401c 100644 --- a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp @@ -45,6 +45,29 @@ GeckoCodeWidget::GeckoCodeWidget(std::string game_id, std::string gametdb_id, u1 LoadCodes(); } +void GeckoCodeWidget::ChangeGame(std::string game_id, std::string gametdb_id, + const u16 game_revision) +{ + m_game_id = std::move(game_id); + m_gametdb_id = std::move(gametdb_id); + m_game_revision = game_revision; + m_restart_required = false; + + m_gecko_codes.clear(); + m_code_list->clear(); + m_name_label->clear(); + m_creator_label->clear(); + m_code_description->clear(); + m_code_view->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(); +} + GeckoCodeWidget::~GeckoCodeWidget() = default; void GeckoCodeWidget::CreateWidgets() @@ -78,6 +101,8 @@ void GeckoCodeWidget::CreateWidgets() m_remove_code = new NonDefaultQPushButton(tr("&Remove Code")); m_download_codes = new NonDefaultQPushButton(tr("Download Codes")); + m_cheat_code_editor = new CheatCodeEditor(this); + m_download_codes->setToolTip(tr("Download Codes from the WiiRD Database")); auto* layout = new QVBoxLayout; @@ -187,10 +212,9 @@ void GeckoCodeWidget::AddCode() Gecko::GeckoCode code; code.enabled = true; - CheatCodeEditor ed(this); - ed.SetGeckoCode(&code); - SetQWidgetWindowDecorations(&ed); - if (ed.exec() == QDialog::Rejected) + m_cheat_code_editor->SetGeckoCode(&code); + SetQWidgetWindowDecorations(m_cheat_code_editor); + if (m_cheat_code_editor->exec() == QDialog::Rejected) return; m_gecko_codes.push_back(std::move(code)); @@ -206,10 +230,9 @@ void GeckoCodeWidget::EditCode() const int index = item->data(Qt::UserRole).toInt(); - CheatCodeEditor ed(this); - ed.SetGeckoCode(&m_gecko_codes[index]); - SetQWidgetWindowDecorations(&ed); - if (ed.exec() == QDialog::Rejected) + m_cheat_code_editor->SetGeckoCode(&m_gecko_codes[index]); + SetQWidgetWindowDecorations(m_cheat_code_editor); + if (m_cheat_code_editor->exec() == QDialog::Rejected) return; SaveCodes(); -- cgit v1.2.3