CheatsManager: Use game information directly from SConfig, and only recreate widgets if game changes.

This commit is contained in:
Admiral H. Curtiss 2021-06-06 21:56:34 +02:00
parent 414e0f4598
commit 441d304317
4 changed files with 31 additions and 29 deletions

View File

@ -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; }

View File

@ -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"));
}
}

View File

@ -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<Result> m_results;
std::vector<Result> m_watch;
std::shared_ptr<const UICommon::GameFile> m_game_file;
QDialogButtonBox* m_button_box;
QTabWidget* m_tab_widget = nullptr;

View File

@ -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);