mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 07:45:33 +01:00
Qt/Settings: Implement cheat settings
This commit is contained in:
parent
8687f6aae7
commit
5aecd61ede
@ -6,35 +6,34 @@
|
|||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/Core.h"
|
#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) : m_game_id(game_id)
|
||||||
{
|
{
|
||||||
CreateWidgets();
|
CreateWidgets();
|
||||||
ConnectWidgets();
|
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,
|
Update(Core::IsRunning());
|
||||||
&CheatWarningWidget::CheatEnableToggled);
|
|
||||||
connect(this, &CheatWarningWidget::EmulationStarted, this,
|
|
||||||
&CheatWarningWidget::CheatEnableToggled);
|
|
||||||
connect(this, &CheatWarningWidget::EmulationStopped, this,
|
|
||||||
&CheatWarningWidget::CheatEnableToggled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatWarningWidget::CreateWidgets()
|
void CheatWarningWidget::CreateWidgets()
|
||||||
{
|
{
|
||||||
auto* icon = new QLabel;
|
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);
|
icon->setPixmap(warning_icon);
|
||||||
|
|
||||||
@ -46,34 +45,38 @@ void CheatWarningWidget::CreateWidgets()
|
|||||||
auto* layout = new QHBoxLayout;
|
auto* layout = new QHBoxLayout;
|
||||||
|
|
||||||
layout->addWidget(icon);
|
layout->addWidget(icon);
|
||||||
layout->addWidget(m_text);
|
layout->addWidget(m_text, 1);
|
||||||
layout->addWidget(m_config_button);
|
layout->addWidget(m_config_button);
|
||||||
|
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
setLayout(layout);
|
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 (running && SConfig::GetInstance().GetGameID() == m_game_id)
|
||||||
|
|
||||||
if (Core::IsRunning() && 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."));
|
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_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()
|
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 QLabel;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QTimer;
|
|
||||||
|
|
||||||
class CheatWarningWidget : public QWidget
|
class CheatWarningWidget : public QWidget
|
||||||
{
|
{
|
||||||
@ -20,18 +19,16 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void OpenCheatEnableSettings();
|
void OpenCheatEnableSettings();
|
||||||
void CheatEnableToggled();
|
|
||||||
void EmulationStarted();
|
void EmulationStarted();
|
||||||
void EmulationStopped();
|
void EmulationStopped();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string& m_game_id;
|
|
||||||
|
|
||||||
void CreateWidgets();
|
void CreateWidgets();
|
||||||
void ConnectWidgets();
|
void ConnectWidgets();
|
||||||
|
|
||||||
void Update();
|
void Update(bool running);
|
||||||
|
|
||||||
QLabel* m_text;
|
QLabel* m_text;
|
||||||
QPushButton* m_config_button;
|
QPushButton* m_config_button;
|
||||||
|
const std::string m_game_id;
|
||||||
};
|
};
|
||||||
|
@ -203,3 +203,17 @@ void Settings::ResetNetPlayServer(NetPlayServer* server)
|
|||||||
{
|
{
|
||||||
m_server.reset(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();
|
NetPlayServer* GetNetPlayServer();
|
||||||
void ResetNetPlayServer(NetPlayServer* server = nullptr);
|
void ResetNetPlayServer(NetPlayServer* server = nullptr);
|
||||||
|
|
||||||
|
// Cheats
|
||||||
|
bool GetCheatsEnabled() const;
|
||||||
|
void SetCheatsEnabled(bool enabled);
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
GameListModel* GetGameListModel() const;
|
GameListModel* GetGameListModel() const;
|
||||||
|
|
||||||
@ -90,6 +94,7 @@ signals:
|
|||||||
void NANDRefresh();
|
void NANDRefresh();
|
||||||
void LogVisibilityChanged(bool visible);
|
void LogVisibilityChanged(bool visible);
|
||||||
void LogConfigVisibilityChanged(bool visible);
|
void LogConfigVisibilityChanged(bool visible);
|
||||||
|
void EnableCheatsChanged(bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<NetPlayClient> m_client;
|
std::unique_ptr<NetPlayClient> m_client;
|
||||||
|
@ -145,7 +145,7 @@ void GeneralPane::LoadConfig()
|
|||||||
m_checkbox_enable_analytics->setChecked(SConfig::GetInstance().m_analytics_enabled);
|
m_checkbox_enable_analytics->setChecked(SConfig::GetInstance().m_analytics_enabled);
|
||||||
#endif
|
#endif
|
||||||
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);
|
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);
|
int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10);
|
||||||
if (selection < m_combobox_speedlimit->count())
|
if (selection < m_combobox_speedlimit->count())
|
||||||
m_combobox_speedlimit->setCurrentIndex(selection);
|
m_combobox_speedlimit->setCurrentIndex(selection);
|
||||||
@ -177,7 +177,7 @@ void GeneralPane::OnSaveConfig()
|
|||||||
SConfig::GetInstance().m_analytics_enabled = m_checkbox_enable_analytics->isChecked();
|
SConfig::GetInstance().m_analytics_enabled = m_checkbox_enable_analytics->isChecked();
|
||||||
#endif
|
#endif
|
||||||
SConfig::GetInstance().bCPUThread = m_checkbox_dualcore->isChecked();
|
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;
|
SConfig::GetInstance().m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f;
|
||||||
int engine_value = 0;
|
int engine_value = 0;
|
||||||
if (m_radio_interpreter->isChecked())
|
if (m_radio_interpreter->isChecked())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user