| 1 | // Copyright 2020 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/Config/FreeLookWidget.h" |
| 5 | |
| 6 | #include <QHBoxLayout> |
| 7 | #include <QLabel> |
| 8 | #include <QPushButton> |
| 9 | #include <QVBoxLayout> |
| 10 | |
| 11 | #include "Core/AchievementManager.h" |
| 12 | #include "Core/Config/FreeLookSettings.h" |
| 13 | |
| 14 | #include "DolphinQt/Config/ConfigControls/ConfigBool.h" |
| 15 | #include "DolphinQt/Config/ConfigControls/ConfigChoice.h" |
| 16 | #include "DolphinQt/Config/Mapping/MappingWindow.h" |
| 17 | #include "DolphinQt/QtUtils/NonDefaultQPushButton.h" |
| 18 | #include "DolphinQt/Settings.h" |
| 19 | |
| 20 | FreeLookWidget::FreeLookWidget(QWidget* parent) : QWidget(parent) |
| 21 | { |
| 22 | CreateLayout(); |
| 23 | LoadSettings(); |
| 24 | ConnectWidgets(); |
| 25 | } |
| 26 | |
| 27 | void FreeLookWidget::CreateLayout() |
| 28 | { |
| 29 | auto* layout = new QVBoxLayout(); |
| 30 | |
| 31 | m_enable_freelook = new ConfigBool(tr("Enable"), Config::FREE_LOOK_ENABLED); |
| 32 | m_enable_freelook->SetDescription( |
| 33 | tr("Allows manipulation of the in-game camera.<br><br><dolphin_emphasis>If unsure, " |
| 34 | "leave this unchecked.</dolphin_emphasis>")); |
| 35 | #ifdef USE_RETRO_ACHIEVEMENTS |
| 36 | const bool hardcore = AchievementManager::GetInstance().IsHardcoreModeActive(); |
| 37 | m_enable_freelook->setEnabled(!hardcore); |
| 38 | #endif // USE_RETRO_ACHIEVEMENTS |
| 39 | m_freelook_controller_configure_button = new NonDefaultQPushButton(tr("Configure Controller")); |
| 40 | |
| 41 | m_freelook_control_type = new ConfigChoice({tr("Six Axis"), tr("First Person"), tr("Orbital")}, |
| 42 | Config::FL1_CONTROL_TYPE); |
| 43 | m_freelook_control_type->SetTitle(tr("Free Look Control Type")); |
| 44 | m_freelook_control_type->SetDescription(tr( |
| 45 | "Changes the in-game camera type during Free Look.<br><br>" |
| 46 | "Six Axis: Offers full camera control on all axes, akin to moving a spacecraft in zero " |
| 47 | "gravity. This is the most powerful Free Look option but is the most challenging to use.<br> " |
| 48 | "<br>" |
| 49 | "First Person: Controls the free camera similarly to a first person video game. The camera " |
| 50 | "can rotate and travel, but roll is impossible. Easy to use, but limiting.<br><br>" |
| 51 | "Orbital: Rotates the free camera around the original camera. Has no lateral movement, only " |
| 52 | "rotation and you may zoom up to the camera's origin point.")); |
| 53 | |
| 54 | auto* description = |
| 55 | new QLabel(tr("Free Look allows for manipulation of the in-game camera. " |
| 56 | "Different camera types are available from the dropdown.<br><br>" |
| 57 | "For detailed instructions, " |
| 58 | "<a href=\"https://wiki.dolphin-emu.org/index.php?title=Free_Look\">" |
| 59 | "refer to this page</a>.")); |
| 60 | description->setTextFormat(Qt::RichText); |
| 61 | description->setWordWrap(true); |
| 62 | description->setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 63 | description->setOpenExternalLinks(true); |
| 64 | |
| 65 | m_freelook_background_input = |
| 66 | new ConfigBool(tr("Background Input"), Config::FREE_LOOK_BACKGROUND_INPUT); |
| 67 | |
| 68 | auto* hlayout = new QHBoxLayout(); |
| 69 | hlayout->addWidget(new QLabel(tr("Camera 1"))); |
| 70 | hlayout->addWidget(m_freelook_control_type); |
| 71 | hlayout->addWidget(m_freelook_controller_configure_button); |
| 72 | |
| 73 | layout->addWidget(m_enable_freelook); |
| 74 | layout->addLayout(hlayout); |
| 75 | layout->addWidget(m_freelook_background_input); |
| 76 | layout->addWidget(description); |
| 77 | |
| 78 | setLayout(layout); |
| 79 | } |
| 80 | |
| 81 | void FreeLookWidget::ConnectWidgets() |
| 82 | { |
| 83 | connect(m_freelook_controller_configure_button, &QPushButton::clicked, this, |
| 84 | &FreeLookWidget::OnFreeLookControllerConfigured); |
| 85 | connect(&Settings::Instance(), &Settings::ConfigChanged, this, [this] { |
| 86 | const QSignalBlocker blocker(this); |
| 87 | LoadSettings(); |
| 88 | }); |
| 89 | } |
| 90 | |
| 91 | void FreeLookWidget::OnFreeLookControllerConfigured() |
| 92 | { |
| 93 | if (m_freelook_controller_configure_button != QObject::sender()) |
| 94 | return; |
| 95 | const int index = 0; |
| 96 | MappingWindow* window = new MappingWindow(this, MappingWindow::Type::MAPPING_FREELOOK, index); |
| 97 | window->setAttribute(Qt::WA_DeleteOnClose, true); |
| 98 | window->setWindowModality(Qt::WindowModality::WindowModal); |
| 99 | window->show(); |
| 100 | } |
| 101 | |
| 102 | void FreeLookWidget::LoadSettings() |
| 103 | { |
| 104 | const bool checked = Config::Get(Config::FREE_LOOK_ENABLED); |
| 105 | #ifdef USE_RETRO_ACHIEVEMENTS |
| 106 | const bool hardcore = AchievementManager::GetInstance().IsHardcoreModeActive(); |
| 107 | m_enable_freelook->setEnabled(!hardcore); |
| 108 | #endif // USE_RETRO_ACHIEVEMENTS |
| 109 | m_freelook_control_type->setEnabled(checked); |
| 110 | m_freelook_controller_configure_button->setEnabled(checked); |
| 111 | m_freelook_background_input->setEnabled(checked); |
| 112 | } |