Skip to content

Commit

Permalink
Merge pull request #9790 from AdmiralCurtiss/cheat-manager-config-change
Browse files Browse the repository at this point in the history
CheatsManager: Avoid recreating child widgets on every OnStateChanged(), and take running game info directly from SConfig.
  • Loading branch information
leoetlino committed Jun 7, 2021
2 parents fd4efd3 + 441d304 commit a208d52
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
1 change: 1 addition & 0 deletions Source/Core/Core/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
46 changes: 24 additions & 22 deletions Source/Core/DolphinQt/CheatsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -175,29 +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++)
{
auto file = m_game_list_model.GetGameFile(i);
const auto& game_id = SConfig::GetInstance().GetGameID();
const auto& game_tdb_id = SConfig::GetInstance().GetGameTDBID();
u16 revision = SConfig::GetInstance().GetRevision();

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_game_id == game_id && m_game_tdb_id == game_tdb_id && m_revision == revision)
return;

if (m_tab_widget->count() == 1)
{
if (m_ar_code)
m_ar_code->deleteLater();
m_game_id = game_id;
m_game_tdb_id = game_tdb_id;
m_revision = revision;

m_ar_code = new ARCodeWidget(*m_game_file, false);
m_tab_widget->insertTab(0, m_ar_code, tr("AR Code"));
m_tab_widget->insertTab(1, new GeckoCodeWidget(*m_game_file, false), tr("Gecko Codes"));
}
}
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();

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

Expand Down
8 changes: 5 additions & 3 deletions Source/Core/DolphinQt/CheatsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -62,10 +62,12 @@ class CheatsManager : public QDialog
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;

Expand Down
6 changes: 4 additions & 2 deletions Source/Core/DolphinQt/Config/ARCodeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "DolphinQt/Config/ARCodeWidget.h"

#include <utility>

#include <QButtonGroup>
#include <QCursor>
#include <QHBoxLayout>
Expand All @@ -23,8 +25,8 @@

#include "UICommon/GameFile.h"

ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game, bool restart_required)
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision()),
ARCodeWidget::ARCodeWidget(std::string game_id, u16 game_revision, bool restart_required)
: m_game_id(std::move(game_id)), m_game_revision(game_revision),
m_restart_required(restart_required)
{
CreateWidgets();
Expand Down
8 changes: 1 addition & 7 deletions Source/Core/DolphinQt/Config/ARCodeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ namespace ActionReplay
struct ARCode;
}

namespace UICommon
{
class GameFile;
}

class CheatWarningWidget;
class QLabel;
class QListWidget;
Expand All @@ -31,7 +26,7 @@ class ARCodeWidget : public QWidget
{
Q_OBJECT
public:
explicit ARCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
explicit ARCodeWidget(std::string game_id, u16 game_revision, bool restart_required = true);
~ARCodeWidget() override;

void AddCode(ActionReplay::ARCode code);
Expand All @@ -56,7 +51,6 @@ class ARCodeWidget : public QWidget

void OnListReordered();

const UICommon::GameFile& m_game;
std::string m_game_id;
u16 m_game_revision;

Expand Down
9 changes: 6 additions & 3 deletions Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "DolphinQt/Config/GeckoCodeWidget.h"

#include <utility>

#include <QCursor>
#include <QFontDatabase>
#include <QFormLayout>
Expand All @@ -28,9 +30,10 @@

#include "UICommon/GameFile.h"

GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required)
: m_game(game), m_game_id(game.GetGameID()), m_gametdb_id(game.GetGameTDBID()),
m_game_revision(game.GetRevision()), m_restart_required(restart_required)
GeckoCodeWidget::GeckoCodeWidget(std::string game_id, std::string gametdb_id, u16 game_revision,
bool restart_required)
: m_game_id(std::move(game_id)), m_gametdb_id(std::move(gametdb_id)),
m_game_revision(game_revision), m_restart_required(restart_required)
{
CreateWidgets();
ConnectWidgets();
Expand Down
9 changes: 2 additions & 7 deletions Source/Core/DolphinQt/Config/GeckoCodeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ namespace Gecko
class GeckoCode;
}

namespace UICommon
{
class GameFile;
}

class GeckoCodeWidget : public QWidget
{
Q_OBJECT
public:
explicit GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
explicit GeckoCodeWidget(std::string game_id, std::string gametdb_id, u16 game_revision,
bool restart_required = true);
~GeckoCodeWidget() override;

signals:
Expand All @@ -54,7 +50,6 @@ class GeckoCodeWidget : public QWidget
void SaveCodes();
void SortAlphabetically();

const UICommon::GameFile& m_game;
std::string m_game_id;
std::string m_gametdb_id;
u16 m_game_revision;
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/Config/PropertiesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ PropertiesDialog::PropertiesDialog(QWidget* parent, const UICommon::GameFile& ga
QTabWidget* tab_widget = new QTabWidget(this);
InfoWidget* info = new InfoWidget(game);

ARCodeWidget* ar = new ARCodeWidget(game);
GeckoCodeWidget* gecko = new GeckoCodeWidget(game);
ARCodeWidget* ar = new ARCodeWidget(game.GetGameID(), game.GetRevision());
GeckoCodeWidget* gecko =
new GeckoCodeWidget(game.GetGameID(), game.GetGameTDBID(), game.GetRevision());
PatchesWidget* patches = new PatchesWidget(game);
GameConfigWidget* game_config = new GameConfigWidget(game);

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a208d52

Please sign in to comment.