1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright 2017 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/Config/CheatWarningWidget.h"
#include <utility>
#include <QHBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
#include <QStyle>
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/System.h"
#include "DolphinQt/QtUtils/QtUtils.h"
#include "DolphinQt/Settings.h"
CheatWarningWidget::CheatWarningWidget(std::string game_id, bool restart_required, QWidget* parent)
: QWidget(parent), m_game_id(std::move(game_id)), m_restart_required(restart_required)
{
CreateWidgets();
ConnectWidgets();
connect(&Settings::Instance(), &Settings::EnableCheatsChanged, this,
[this] { Update(Core::IsRunning(Core::System::GetInstance())); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this](Core::State state) {
Update(state == Core::State::Running || state == Core::State::Paused);
});
Update(Core::IsRunning(Core::System::GetInstance()));
}
void CheatWarningWidget::CreateWidgets()
{
m_text = new QLabel();
m_config_button = new QPushButton(tr("Configure Dolphin"));
m_config_button->setHidden(true);
auto* const layout = new QHBoxLayout{this};
layout->addWidget(QtUtils::CreateIconWarning(this, QStyle::SP_MessageBoxWarning, m_text));
layout->addWidget(m_config_button);
layout->setContentsMargins(0, 0, 0, 0);
}
void CheatWarningWidget::Update(bool running)
{
bool hide_widget = true;
bool hide_config_button = true;
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."));
}
if (!Settings::Instance().GetCheatsEnabled())
{
hide_widget = false;
hide_config_button = false;
m_text->setText(tr("Dolphin's cheat system is currently disabled."));
}
setHidden(hide_widget);
m_config_button->setHidden(hide_config_button);
}
void CheatWarningWidget::ConnectWidgets()
{
connect(m_config_button, &QPushButton::clicked, this,
&CheatWarningWidget::OpenCheatEnableSettings);
}
|