mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Qt: Implement Cheats Manager
This commit is contained in:
@ -18,8 +18,9 @@
|
||||
#include "DolphinQt2/Config/CheatWarningWidget.h"
|
||||
#include "UICommon/GameFile.h"
|
||||
|
||||
ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game)
|
||||
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision())
|
||||
ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game, bool restart_required)
|
||||
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision()),
|
||||
m_restart_required(restart_required)
|
||||
{
|
||||
CreateWidgets();
|
||||
ConnectWidgets();
|
||||
@ -39,7 +40,7 @@ ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game)
|
||||
|
||||
void ARCodeWidget::CreateWidgets()
|
||||
{
|
||||
m_warning = new CheatWarningWidget(m_game_id);
|
||||
m_warning = new CheatWarningWidget(m_game_id, m_restart_required);
|
||||
m_code_list = new QListWidget;
|
||||
m_code_add = new QPushButton(tr("&Add New Code..."));
|
||||
m_code_edit = new QPushButton(tr("&Edit Code..."));
|
||||
@ -75,6 +76,10 @@ void ARCodeWidget::ConnectWidgets()
|
||||
void ARCodeWidget::OnItemChanged(QListWidgetItem* item)
|
||||
{
|
||||
m_ar_codes[m_code_list->row(item)].active = (item->checkState() == Qt::Checked);
|
||||
|
||||
if (!m_restart_required)
|
||||
ActionReplay::ApplyCodes(m_ar_codes);
|
||||
|
||||
SaveCodes();
|
||||
}
|
||||
|
||||
@ -119,6 +124,14 @@ void ARCodeWidget::SaveCodes()
|
||||
game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
||||
}
|
||||
|
||||
void ARCodeWidget::AddCode(ActionReplay::ARCode code)
|
||||
{
|
||||
m_ar_codes.push_back(std::move(code));
|
||||
|
||||
UpdateList();
|
||||
SaveCodes();
|
||||
}
|
||||
|
||||
void ARCodeWidget::OnCodeAddPressed()
|
||||
{
|
||||
ActionReplay::ARCode ar;
|
||||
|
@ -27,7 +27,9 @@ class ARCodeWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ARCodeWidget(const UICommon::GameFile& game);
|
||||
explicit ARCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
|
||||
|
||||
void AddCode(ActionReplay::ARCode code);
|
||||
|
||||
signals:
|
||||
void OpenGeneralSettings();
|
||||
@ -56,4 +58,5 @@ private:
|
||||
QPushButton* m_code_remove;
|
||||
|
||||
std::vector<ActionReplay::ARCode> m_ar_codes;
|
||||
bool m_restart_required;
|
||||
};
|
||||
|
@ -14,14 +14,15 @@
|
||||
#include "Core/Core.h"
|
||||
#include "DolphinQt2/Settings.h"
|
||||
|
||||
CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(game_id)
|
||||
CheatWarningWidget::CheatWarningWidget(const std::string& game_id, bool restart_required)
|
||||
: m_game_id(game_id), m_restart_required(restart_required)
|
||||
{
|
||||
CreateWidgets();
|
||||
ConnectWidgets();
|
||||
|
||||
connect(&Settings::Instance(), &Settings::EnableCheatsChanged,
|
||||
connect(&Settings::Instance(), &Settings::EnableCheatsChanged, this,
|
||||
[this] { Update(Core::IsRunning()); });
|
||||
connect(&Settings::Instance(), &Settings::EmulationStateChanged,
|
||||
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
||||
[this](Core::State state) { Update(state == Core::State::Running); });
|
||||
|
||||
Update(Core::IsRunning());
|
||||
@ -58,7 +59,7 @@ void CheatWarningWidget::Update(bool running)
|
||||
bool hide_widget = true;
|
||||
bool hide_config_button = true;
|
||||
|
||||
if (running && SConfig::GetInstance().GetGameID() == m_game_id)
|
||||
if (running && SConfig::GetInstance().GetGameID() == m_game_id && m_restart_required)
|
||||
{
|
||||
hide_widget = false;
|
||||
m_text->setText(tr("Changing cheats will only take effect when the game is restarted."));
|
||||
|
@ -15,7 +15,7 @@ class CheatWarningWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CheatWarningWidget(const std::string& game_id);
|
||||
explicit CheatWarningWidget(const std::string& game_id, bool restart_required);
|
||||
|
||||
signals:
|
||||
void OpenCheatEnableSettings();
|
||||
@ -29,4 +29,5 @@ private:
|
||||
QLabel* m_text;
|
||||
QPushButton* m_config_button;
|
||||
const std::string m_game_id;
|
||||
bool m_restart_required;
|
||||
};
|
||||
|
@ -22,8 +22,9 @@
|
||||
#include "DolphinQt2/Config/CheatWarningWidget.h"
|
||||
#include "UICommon/GameFile.h"
|
||||
|
||||
GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game)
|
||||
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision())
|
||||
GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required)
|
||||
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision()),
|
||||
m_restart_required(restart_required)
|
||||
{
|
||||
CreateWidgets();
|
||||
ConnectWidgets();
|
||||
@ -42,7 +43,7 @@ GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game)
|
||||
|
||||
void GeckoCodeWidget::CreateWidgets()
|
||||
{
|
||||
m_warning = new CheatWarningWidget(m_game_id);
|
||||
m_warning = new CheatWarningWidget(m_game_id, m_restart_required);
|
||||
m_code_list = new QListWidget;
|
||||
m_name_label = new QLabel;
|
||||
m_creator_label = new QLabel;
|
||||
@ -155,6 +156,9 @@ void GeckoCodeWidget::OnItemChanged(QListWidgetItem* item)
|
||||
{
|
||||
m_gecko_codes[m_code_list->row(item)].enabled = (item->checkState() == Qt::Checked);
|
||||
|
||||
if (!m_restart_required)
|
||||
Gecko::SetActiveCodes(m_gecko_codes);
|
||||
|
||||
SaveCodes();
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class GeckoCodeWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GeckoCodeWidget(const UICommon::GameFile& game);
|
||||
explicit GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
|
||||
|
||||
signals:
|
||||
void OpenGeneralSettings();
|
||||
@ -62,4 +62,5 @@ private:
|
||||
QPushButton* m_remove_code;
|
||||
QPushButton* m_download_codes;
|
||||
std::vector<Gecko::GeckoCode> m_gecko_codes;
|
||||
bool m_restart_required;
|
||||
};
|
||||
|
Reference in New Issue
Block a user