From 441d304317606c2c9448108728f8f38a2b2f7f5d Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 6 Jun 2021 21:56:34 +0200 Subject: [PATCH] CheatsManager: Use game information directly from SConfig, and only recreate widgets if game changes. --- Source/Core/Core/ConfigManager.h | 1 + Source/Core/DolphinQt/CheatsManager.cpp | 49 ++++++++++++------------- Source/Core/DolphinQt/CheatsManager.h | 8 ++-- Source/Core/DolphinQt/MainWindow.cpp | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 995b84ab8f..316eed85b9 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -191,6 +191,7 @@ struct SConfig bool m_disc_booted_from_game_list = false; const std::string& GetGameID() const { return m_game_id; } + const std::string& GetGameTDBID() const { return m_gametdb_id; } const std::string& GetTitleName() const { return m_title_name; } const std::string& GetTitleDescription() const { return m_title_description; } u64 GetTitleID() const { return m_title_id; } diff --git a/Source/Core/DolphinQt/CheatsManager.cpp b/Source/Core/DolphinQt/CheatsManager.cpp index ea6aaf8e25..46fc006b12 100644 --- a/Source/Core/DolphinQt/CheatsManager.cpp +++ b/Source/Core/DolphinQt/CheatsManager.cpp @@ -151,8 +151,7 @@ static bool Compare(T mem_value, T value, CompareType op) } } -CheatsManager::CheatsManager(const GameListModel& game_list_model, QWidget* parent) - : QDialog(parent), m_game_list_model(game_list_model) +CheatsManager::CheatsManager(QWidget* parent) : QDialog(parent) { setWindowTitle(tr("Cheats Manager")); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); @@ -175,32 +174,32 @@ void CheatsManager::OnStateChanged(Core::State state) if (state != Core::State::Running && state != Core::State::Paused) return; - for (int i = 0; i < m_game_list_model.rowCount(QModelIndex()); i++) + const auto& game_id = SConfig::GetInstance().GetGameID(); + const auto& game_tdb_id = SConfig::GetInstance().GetGameTDBID(); + u16 revision = SConfig::GetInstance().GetRevision(); + + if (m_game_id == game_id && m_game_tdb_id == game_tdb_id && m_revision == revision) + return; + + m_game_id = game_id; + m_game_tdb_id = game_tdb_id; + m_revision = revision; + + if (m_tab_widget->count() == 3) { - auto file = m_game_list_model.GetGameFile(i); + m_tab_widget->removeTab(0); + m_tab_widget->removeTab(0); + } - if (file->GetGameID() == SConfig::GetInstance().GetGameID()) - { - m_game_file = file; - if (m_tab_widget->count() == 3) - { - m_tab_widget->removeTab(0); - m_tab_widget->removeTab(0); - } + if (m_tab_widget->count() == 1) + { + if (m_ar_code) + m_ar_code->deleteLater(); - if (m_tab_widget->count() == 1) - { - if (m_ar_code) - m_ar_code->deleteLater(); - - m_ar_code = new ARCodeWidget(m_game_file->GetGameID(), m_game_file->GetRevision(), false); - m_tab_widget->insertTab(0, m_ar_code, tr("AR Code")); - auto* gecko_code = - new GeckoCodeWidget(m_game_file->GetGameID(), m_game_file->GetGameTDBID(), - m_game_file->GetRevision(), false); - m_tab_widget->insertTab(1, gecko_code, tr("Gecko Codes")); - } - } + m_ar_code = new ARCodeWidget(m_game_id, m_revision, false); + m_tab_widget->insertTab(0, m_ar_code, tr("AR Code")); + auto* gecko_code = new GeckoCodeWidget(m_game_id, m_game_tdb_id, m_revision, false); + m_tab_widget->insertTab(1, gecko_code, tr("Gecko Codes")); } } diff --git a/Source/Core/DolphinQt/CheatsManager.h b/Source/Core/DolphinQt/CheatsManager.h index f1e0c1ec86..3fda1712e4 100644 --- a/Source/Core/DolphinQt/CheatsManager.h +++ b/Source/Core/DolphinQt/CheatsManager.h @@ -40,7 +40,7 @@ class CheatsManager : public QDialog { Q_OBJECT public: - explicit CheatsManager(const GameListModel& game_list_model, QWidget* parent = nullptr); + explicit CheatsManager(QWidget* parent = nullptr); ~CheatsManager(); private: @@ -62,10 +62,12 @@ private: void OnMatchContextMenu(); void OnWatchItemChanged(QTableWidgetItem* item); - const GameListModel& m_game_list_model; + std::string m_game_id; + std::string m_game_tdb_id; + u16 m_revision = 0; + std::vector m_results; std::vector m_watch; - std::shared_ptr m_game_file; QDialogButtonBox* m_button_box; QTabWidget* m_tab_widget = nullptr; diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index df580398d8..3b01fec11b 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -411,7 +411,7 @@ void MainWindow::CreateComponents() m_watch_widget = new WatchWidget(this); m_breakpoint_widget = new BreakpointWidget(this); m_code_widget = new CodeWidget(this); - m_cheats_manager = new CheatsManager(m_game_list->GetGameListModel(), this); + m_cheats_manager = new CheatsManager(this); const auto request_watch = [this](QString name, u32 addr) { m_watch_widget->AddWatch(name, addr);