summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/Config/HardcoreWarningWidget.cpp
blob: 2244aa6a0be56ef64904a741c4b645e6304da640 (plain)
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
// 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 <QPushButton>
#include <QStyle>

#include "Core/AchievementManager.h"

#include "DolphinQt/QtUtils/QtUtils.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()
{
  auto* const text = new QLabel(tr("Only approved codes will be applied in hardcore mode."));
  auto* const icon_warning = QtUtils::CreateIconWarning(this, QStyle::SP_MessageBoxWarning, text);

  m_settings_button = new QPushButton(tr("Achievement Settings"));

  auto* const layout = new QHBoxLayout{this};

  layout->addWidget(icon_warning, 1);
  layout->addWidget(m_settings_button);

  layout->setContentsMargins(0, 0, 0, 0);
}

void HardcoreWarningWidget::ConnectWidgets()
{
  connect(m_settings_button, &QPushButton::clicked, this,
          &HardcoreWarningWidget::OpenAchievementSettings);
}

void HardcoreWarningWidget::Update()
{
  setHidden(!AchievementManager::GetInstance().IsHardcoreModeActive());
}
#endif  // USE_RETRO_ACHIEVEMENTS