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