dolphin/Source/Core/DolphinQt/Config/HardcoreWarningWidget.cpp
LillyJadeKatrin 71f3039f96 Added Hardcore Warning Widget
This widget will be used in several places to notify the player that a feature has been disabled because hardcore mode is on. It includes a button to open the Achievement Settings so that Hardcore Mode may be turned off. Also included is the framework required to open AchievementsWindow specifically on the Settings tab.
2023-12-02 16:41:15 -05:00

63 lines
1.5 KiB
C++

// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#ifdef USE_RETRO_ACHIEVEMENTS
#include "DolphinQt/Config/HardcoreWarningWidget.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>
#include <QStyle>
#include "Core/Config/AchievementSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "DolphinQt/Settings.h"
HardcoreWarningWidget::HardcoreWarningWidget(QWidget* parent) : QWidget(parent)
{
CreateWidgets();
ConnectWidgets();
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] { Update(); });
Update();
}
void HardcoreWarningWidget::CreateWidgets()
{
const auto size = 1.5 * QFontMetrics(font()).height();
QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(size, size);
auto* icon = new QLabel;
icon->setPixmap(warning_icon);
m_text = new QLabel(tr("This feature is disabled in hardcore mode."));
m_settings_button = new QPushButton(tr("Achievement Settings"));
auto* layout = new QHBoxLayout;
layout->addWidget(icon);
layout->addWidget(m_text, 1);
layout->addWidget(m_settings_button);
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
}
void HardcoreWarningWidget::ConnectWidgets()
{
connect(m_settings_button, &QPushButton::clicked, this,
&HardcoreWarningWidget::OpenAchievementSettings);
}
void HardcoreWarningWidget::Update()
{
setHidden(!Config::Get(Config::RA_HARDCORE_ENABLED));
}
#endif // USE_RETRO_ACHIEVEMENTS