From 0abfa94bc83b99bfe02b9f310c6cd3ddcb7e11ec Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Wed, 7 Jun 2023 22:14:54 -0400 Subject: [PATCH] Disable Freelook in hardcore mode The player getting a better view of their surroundings than the game would normally allow could possibly give the player an advantage over the original hardware, so Freelook is disabled in hardcore mode. To do this, I disable the config flag for Freelook when it is accessed, to make sure that it is disabled whether it was enabled before or after hardcore mode was enabled. --- Source/Core/Core/FreeLookConfig.cpp | 7 +++++++ Source/Core/DolphinQt/Config/FreeLookWidget.cpp | 10 ++++++++++ Source/Core/DolphinQt/Config/FreeLookWindow.cpp | 17 +++++++++++++++++ Source/Core/DolphinQt/Config/FreeLookWindow.h | 12 ++++++++++++ Source/Core/DolphinQt/HotkeyScheduler.cpp | 10 ++++++++++ Source/Core/DolphinQt/MainWindow.cpp | 5 +++++ 6 files changed, 61 insertions(+) diff --git a/Source/Core/Core/FreeLookConfig.cpp b/Source/Core/Core/FreeLookConfig.cpp index 31a673ce85..c0c58ce2c1 100644 --- a/Source/Core/Core/FreeLookConfig.cpp +++ b/Source/Core/Core/FreeLookConfig.cpp @@ -3,7 +3,9 @@ #include "Core/FreeLookConfig.h" +#include "Core/AchievementManager.h" #include "Core/CPUThreadConfigCallback.h" +#include "Core/Config/AchievementSettings.h" #include "Core/Config/FreeLookSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -44,6 +46,11 @@ void Config::Refresh() } camera_config.control_type = ::Config::Get(::Config::FL1_CONTROL_TYPE); +#ifdef USE_RETRO_ACHIEVEMENTS + enabled = ::Config::Get(::Config::FREE_LOOK_ENABLED) && + !AchievementManager::GetInstance()->IsHardcoreModeActive(); +#else // USE_RETRO_ACHIEVEMENTS enabled = ::Config::Get(::Config::FREE_LOOK_ENABLED); +#endif // USE_RETRO_ACHIEVEMENTS } } // namespace FreeLook diff --git a/Source/Core/DolphinQt/Config/FreeLookWidget.cpp b/Source/Core/DolphinQt/Config/FreeLookWidget.cpp index 5fe1ecd66d..430dce883d 100644 --- a/Source/Core/DolphinQt/Config/FreeLookWidget.cpp +++ b/Source/Core/DolphinQt/Config/FreeLookWidget.cpp @@ -9,6 +9,8 @@ #include #include +#include "Core/AchievementManager.h" +#include "Core/Config/AchievementSettings.h" #include "Core/Config/FreeLookSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -36,6 +38,10 @@ void FreeLookWidget::CreateLayout() m_enable_freelook->SetDescription( tr("Allows manipulation of the in-game camera.

If unsure, " "leave this unchecked.")); +#ifdef USE_RETRO_ACHIEVEMENTS + bool hardcore = AchievementManager::GetInstance()->IsHardcoreModeActive(); + m_enable_freelook->setEnabled(!hardcore); +#endif // USE_RETRO_ACHIEVEMENTS m_freelook_controller_configure_button = new NonDefaultQPushButton(tr("Configure Controller")); m_freelook_control_type = new ConfigChoice({tr("Six Axis"), tr("First Person"), tr("Orbital")}, @@ -106,6 +112,10 @@ void FreeLookWidget::LoadSettings() { const bool checked = Config::Get(Config::FREE_LOOK_ENABLED); m_enable_freelook->setChecked(checked); +#ifdef USE_RETRO_ACHIEVEMENTS + bool hardcore = AchievementManager::GetInstance()->IsHardcoreModeActive(); + m_enable_freelook->setEnabled(!hardcore); +#endif // USE_RETRO_ACHIEVEMENTS m_freelook_control_type->setEnabled(checked); m_freelook_controller_configure_button->setEnabled(checked); m_freelook_background_input->setEnabled(checked); diff --git a/Source/Core/DolphinQt/Config/FreeLookWindow.cpp b/Source/Core/DolphinQt/Config/FreeLookWindow.cpp index 86b78ae39c..d2c57be8a6 100644 --- a/Source/Core/DolphinQt/Config/FreeLookWindow.cpp +++ b/Source/Core/DolphinQt/Config/FreeLookWindow.cpp @@ -9,10 +9,12 @@ #include #include "DolphinQt/Config/FreeLookWidget.h" +#include "DolphinQt/Config/HardcoreWarningWidget.h" FreeLookWindow::FreeLookWindow(QWidget* parent) : QDialog(parent) { CreateMainLayout(); + ConnectWidgets(); setWindowTitle(tr("Free Look Settings")); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); @@ -20,11 +22,26 @@ FreeLookWindow::FreeLookWindow(QWidget* parent) : QDialog(parent) void FreeLookWindow::CreateMainLayout() { +#ifdef USE_RETRO_ACHIEVEMENTS + m_hc_warning = new HardcoreWarningWidget(this); +#endif // USE_RETRO_ACHIEVEMENTS m_button_box = new QDialogButtonBox(QDialogButtonBox::Close); connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); auto* main_layout = new QVBoxLayout(); + +#ifdef USE_RETRO_ACHIEVEMENTS + main_layout->addWidget(m_hc_warning); +#endif // USE_RETRO_ACHIEVEMENTS main_layout->addWidget(new FreeLookWidget(this)); main_layout->addWidget(m_button_box); setLayout(main_layout); } + +void FreeLookWindow::ConnectWidgets() +{ +#ifdef USE_RETRO_ACHIEVEMENTS + connect(m_hc_warning, &HardcoreWarningWidget::OpenAchievementSettings, this, + &FreeLookWindow::OpenAchievementSettings); +#endif // USE_RETRO_ACHIEVEMENTS +} diff --git a/Source/Core/DolphinQt/Config/FreeLookWindow.h b/Source/Core/DolphinQt/Config/FreeLookWindow.h index 3a7b6c17fd..0ffd4472ee 100644 --- a/Source/Core/DolphinQt/Config/FreeLookWindow.h +++ b/Source/Core/DolphinQt/Config/FreeLookWindow.h @@ -5,6 +5,9 @@ #include +#ifdef USE_RETRO_ACHIEVEMENTS +class HardcoreWarningWidget; +#endif // USE_RETRO_ACHIEVEMENTS class QDialogButtonBox; class FreeLookWindow final : public QDialog @@ -13,8 +16,17 @@ class FreeLookWindow final : public QDialog public: explicit FreeLookWindow(QWidget* parent); +#ifdef USE_RETRO_ACHIEVEMENTS +signals: + void OpenAchievementSettings(); +#endif // USE_RETRO_ACHIEVEMENTS + private: void CreateMainLayout(); + void ConnectWidgets(); +#ifdef USE_RETRO_ACHIEVEMENTS + HardcoreWarningWidget* m_hc_warning; +#endif // USE_RETRO_ACHIEVEMENTS QDialogButtonBox* m_button_box; }; diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp index b527e96c6c..6ccd09b0f5 100644 --- a/Source/Core/DolphinQt/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp @@ -17,6 +17,8 @@ #include "Common/Config/Config.h" #include "Common/Thread.h" +#include "Core/AchievementManager.h" +#include "Core/Config/AchievementSettings.h" #include "Core/Config/FreeLookSettings.h" #include "Core/Config/GraphicsSettings.h" #include "Core/Config/MainSettings.h" @@ -579,7 +581,15 @@ void HotkeyScheduler::Run() { const bool new_value = !Config::Get(Config::FREE_LOOK_ENABLED); Config::SetCurrent(Config::FREE_LOOK_ENABLED, new_value); +#ifdef USE_RETRO_ACHIEVEMENTS + bool hardcore = AchievementManager::GetInstance()->IsHardcoreModeActive(); + if (hardcore) + OSD::AddMessage("Free Look is Disabled in Hardcore Mode"); + else + OSD::AddMessage(fmt::format("Free Look: {}", new_value ? "Enabled" : "Disabled")); +#else // USE_RETRO_ACHIEVEMENTS OSD::AddMessage(fmt::format("Free Look: {}", new_value ? "Enabled" : "Disabled")); +#endif // USE_RETRO_ACHIEVEMENTS } // Savestates diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index e3b96c6390..881e28549c 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1244,6 +1244,11 @@ void MainWindow::ShowFreeLookWindow() { m_freelook_window = new FreeLookWindow(this); InstallHotkeyFilter(m_freelook_window); + +#ifdef USE_RETRO_ACHIEVEMENTS + connect(m_freelook_window, &FreeLookWindow::OpenAchievementSettings, this, + &MainWindow::ShowAchievementSettings); +#endif // USE_RETRO_ACHIEVEMENTS } SetQWidgetWindowDecorations(m_freelook_window);