2017-08-26 18:55:16 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-08-26 18:55:16 +00:00
|
|
|
|
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"
|
2024-04-09 03:33:55 +00:00
|
|
|
#include "Core/System.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,
|
2024-04-09 03:33:55 +00:00
|
|
|
[this] { Update(Core::IsRunning(Core::System::GetInstance())); });
|
2024-06-02 14:45:30 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this](Core::State state) {
|
|
|
|
Update(state == Core::State::Running || state == Core::State::Paused);
|
|
|
|
});
|
2017-08-26 18:55:16 +00:00
|
|
|
|
2024-04-09 03:33:55 +00:00
|
|
|
Update(Core::IsRunning(Core::System::GetInstance()));
|
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
|
|
|
}
|