2017-08-26 18:55:16 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Config/CheatWarningWidget.h"
|
2017-08-26 18:55:16 +00:00
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QStyle>
|
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
2017-08-26 18:55:16 +00:00
|
|
|
|
2018-05-18 05:17:30 +00:00
|
|
|
CheatWarningWidget::CheatWarningWidget(const std::string& game_id, bool restart_required,
|
|
|
|
QWidget* parent)
|
|
|
|
: QWidget(parent), m_game_id(game_id), m_restart_required(restart_required)
|
2017-08-26 18:55:16 +00:00
|
|
|
{
|
|
|
|
CreateWidgets();
|
|
|
|
ConnectWidgets();
|
|
|
|
|
2018-03-26 02:17:47 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EnableCheatsChanged, this,
|
2017-08-30 19:00:59 +00:00
|
|
|
[this] { Update(Core::IsRunning()); });
|
2018-03-26 02:17:47 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
2018-02-21 21:30:08 +00:00
|
|
|
[this](Core::State state) { Update(state == Core::State::Running); });
|
2017-08-26 18:55:16 +00:00
|
|
|
|
2017-08-30 19:00:59 +00:00
|
|
|
Update(Core::IsRunning());
|
2017-08-26 18:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheatWarningWidget::CreateWidgets()
|
|
|
|
{
|
|
|
|
auto* icon = new QLabel;
|
|
|
|
|
2017-08-30 19:00:59 +00:00
|
|
|
const auto size = 1.5 * QFontMetrics(font()).height();
|
|
|
|
|
|
|
|
QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(size, size);
|
2017-08-26 18:55:16 +00:00
|
|
|
|
|
|
|
icon->setPixmap(warning_icon);
|
|
|
|
|
|
|
|
m_text = new QLabel();
|
|
|
|
m_config_button = new QPushButton(tr("Configure Dolphin"));
|
|
|
|
|
|
|
|
m_config_button->setHidden(true);
|
|
|
|
|
|
|
|
auto* layout = new QHBoxLayout;
|
|
|
|
|
|
|
|
layout->addWidget(icon);
|
2017-08-30 19:00:59 +00:00
|
|
|
layout->addWidget(m_text, 1);
|
2017-08-26 18:55:16 +00:00
|
|
|
layout->addWidget(m_config_button);
|
|
|
|
|
2017-08-30 19:00:59 +00:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
2017-08-26 18:55:16 +00:00
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:00:59 +00:00
|
|
|
void CheatWarningWidget::Update(bool running)
|
2017-08-26 18:55:16 +00:00
|
|
|
{
|
2017-08-30 19:00:59 +00:00
|
|
|
bool hide_widget = true;
|
|
|
|
bool hide_config_button = true;
|
2017-08-26 18:55:16 +00:00
|
|
|
|
2018-03-26 02:17:47 +00:00
|
|
|
if (running && SConfig::GetInstance().GetGameID() == m_game_id && m_restart_required)
|
2017-08-26 18:55:16 +00:00
|
|
|
{
|
2017-08-30 19:00:59 +00:00
|
|
|
hide_widget = false;
|
2017-08-26 18:55:16 +00:00
|
|
|
m_text->setText(tr("Changing cheats will only take effect when the game is restarted."));
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:00:59 +00:00
|
|
|
if (!Settings::Instance().GetCheatsEnabled())
|
2017-08-26 18:55:16 +00:00
|
|
|
{
|
2017-08-30 19:00:59 +00:00
|
|
|
hide_widget = false;
|
|
|
|
hide_config_button = false;
|
2017-08-26 18:55:16 +00:00
|
|
|
m_text->setText(tr("Dolphin's cheat system is currently disabled."));
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:00:59 +00:00
|
|
|
setHidden(hide_widget);
|
|
|
|
m_config_button->setHidden(hide_config_button);
|
2017-08-26 18:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheatWarningWidget::ConnectWidgets()
|
|
|
|
{
|
2019-07-23 22:18:58 +00:00
|
|
|
connect(m_config_button, &QPushButton::clicked, this,
|
2017-08-30 19:00:59 +00:00
|
|
|
&CheatWarningWidget::OpenCheatEnableSettings);
|
2017-08-26 18:55:16 +00:00
|
|
|
}
|