mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Qt/Settings: Implement cheat settings
This commit is contained in:
parent
8687f6aae7
commit
5aecd61ede
@ -6,35 +6,34 @@
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
#include <QPushButton>
|
||||
#include <QStyle>
|
||||
#include <QTimer>
|
||||
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "DolphinQt2/Settings.h"
|
||||
|
||||
CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(game_id)
|
||||
{
|
||||
CreateWidgets();
|
||||
ConnectWidgets();
|
||||
|
||||
setHidden(true);
|
||||
connect(&Settings::Instance(), &Settings::EnableCheatsChanged,
|
||||
[this] { Update(Core::IsRunning()); });
|
||||
connect(this, &CheatWarningWidget::EmulationStarted, [this] { Update(true); });
|
||||
connect(this, &CheatWarningWidget::EmulationStopped, [this] { Update(false); });
|
||||
|
||||
connect(this, &CheatWarningWidget::CheatEnableToggled, this,
|
||||
&CheatWarningWidget::CheatEnableToggled);
|
||||
connect(this, &CheatWarningWidget::EmulationStarted, this,
|
||||
&CheatWarningWidget::CheatEnableToggled);
|
||||
connect(this, &CheatWarningWidget::EmulationStopped, this,
|
||||
&CheatWarningWidget::CheatEnableToggled);
|
||||
Update(Core::IsRunning());
|
||||
}
|
||||
|
||||
void CheatWarningWidget::CreateWidgets()
|
||||
{
|
||||
auto* icon = new QLabel;
|
||||
|
||||
QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(24, 24);
|
||||
const auto size = 1.5 * QFontMetrics(font()).height();
|
||||
|
||||
QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(size, size);
|
||||
|
||||
icon->setPixmap(warning_icon);
|
||||
|
||||
@ -46,34 +45,38 @@ void CheatWarningWidget::CreateWidgets()
|
||||
auto* layout = new QHBoxLayout;
|
||||
|
||||
layout->addWidget(icon);
|
||||
layout->addWidget(m_text);
|
||||
layout->addWidget(m_text, 1);
|
||||
layout->addWidget(m_config_button);
|
||||
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void CheatWarningWidget::Update()
|
||||
void CheatWarningWidget::Update(bool running)
|
||||
{
|
||||
bool cheats_enabled = SConfig::GetInstance().bEnableCheats;
|
||||
bool hide_widget = true;
|
||||
bool hide_config_button = true;
|
||||
|
||||
bool hide = true;
|
||||
|
||||
if (Core::IsRunning() && SConfig::GetInstance().GetGameID() == m_game_id)
|
||||
if (running && SConfig::GetInstance().GetGameID() == m_game_id)
|
||||
{
|
||||
hide = false;
|
||||
hide_widget = false;
|
||||
m_text->setText(tr("Changing cheats will only take effect when the game is restarted."));
|
||||
}
|
||||
|
||||
if (!cheats_enabled)
|
||||
if (!Settings::Instance().GetCheatsEnabled())
|
||||
{
|
||||
hide = false;
|
||||
hide_widget = false;
|
||||
hide_config_button = false;
|
||||
m_text->setText(tr("Dolphin's cheat system is currently disabled."));
|
||||
}
|
||||
|
||||
m_config_button->setHidden(hide);
|
||||
setHidden(hide_widget);
|
||||
m_config_button->setHidden(hide_config_button);
|
||||
}
|
||||
|
||||
void CheatWarningWidget::ConnectWidgets()
|
||||
{
|
||||
connect(m_config_button, &QPushButton::pressed, [this] { emit OpenCheatEnableSettings(); });
|
||||
connect(m_config_button, &QPushButton::pressed, this,
|
||||
&CheatWarningWidget::OpenCheatEnableSettings);
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QTimer;
|
||||
|
||||
class CheatWarningWidget : public QWidget
|
||||
{
|
||||
@ -20,18 +19,16 @@ public:
|
||||
|
||||
signals:
|
||||
void OpenCheatEnableSettings();
|
||||
void CheatEnableToggled();
|
||||
void EmulationStarted();
|
||||
void EmulationStopped();
|
||||
|
||||
private:
|
||||
const std::string& m_game_id;
|
||||
|
||||
void CreateWidgets();
|
||||
void ConnectWidgets();
|
||||
|
||||
void Update();
|
||||
void Update(bool running);
|
||||
|
||||
QLabel* m_text;
|
||||
QPushButton* m_config_button;
|
||||
const std::string m_game_id;
|
||||
};
|
||||
|
@ -203,3 +203,17 @@ void Settings::ResetNetPlayServer(NetPlayServer* server)
|
||||
{
|
||||
m_server.reset(server);
|
||||
}
|
||||
|
||||
bool Settings::GetCheatsEnabled() const
|
||||
{
|
||||
return SConfig::GetInstance().bEnableCheats;
|
||||
}
|
||||
|
||||
void Settings::SetCheatsEnabled(bool enabled)
|
||||
{
|
||||
if (SConfig::GetInstance().bEnableCheats != enabled)
|
||||
{
|
||||
SConfig::GetInstance().bEnableCheats = enabled;
|
||||
emit EnableCheatsChanged(enabled);
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,10 @@ public:
|
||||
NetPlayServer* GetNetPlayServer();
|
||||
void ResetNetPlayServer(NetPlayServer* server = nullptr);
|
||||
|
||||
// Cheats
|
||||
bool GetCheatsEnabled() const;
|
||||
void SetCheatsEnabled(bool enabled);
|
||||
|
||||
// Other
|
||||
GameListModel* GetGameListModel() const;
|
||||
|
||||
@ -90,6 +94,7 @@ signals:
|
||||
void NANDRefresh();
|
||||
void LogVisibilityChanged(bool visible);
|
||||
void LogConfigVisibilityChanged(bool visible);
|
||||
void EnableCheatsChanged(bool enabled);
|
||||
|
||||
private:
|
||||
std::unique_ptr<NetPlayClient> m_client;
|
||||
|
@ -145,7 +145,7 @@ void GeneralPane::LoadConfig()
|
||||
m_checkbox_enable_analytics->setChecked(SConfig::GetInstance().m_analytics_enabled);
|
||||
#endif
|
||||
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);
|
||||
m_checkbox_cheats->setChecked(SConfig::GetInstance().bEnableCheats);
|
||||
m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled());
|
||||
int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10);
|
||||
if (selection < m_combobox_speedlimit->count())
|
||||
m_combobox_speedlimit->setCurrentIndex(selection);
|
||||
@ -177,7 +177,7 @@ void GeneralPane::OnSaveConfig()
|
||||
SConfig::GetInstance().m_analytics_enabled = m_checkbox_enable_analytics->isChecked();
|
||||
#endif
|
||||
SConfig::GetInstance().bCPUThread = m_checkbox_dualcore->isChecked();
|
||||
SConfig::GetInstance().bEnableCheats = m_checkbox_cheats->isChecked();
|
||||
Settings::Instance().SetCheatsEnabled(m_checkbox_cheats->isChecked());
|
||||
SConfig::GetInstance().m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f;
|
||||
int engine_value = 0;
|
||||
if (m_radio_interpreter->isChecked())
|
||||
|
Loading…
Reference in New Issue
Block a user