configure_input_advanced.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <QColorDialog>
  4. #include "common/settings.h"
  5. #include "core/core.h"
  6. #include "ui_configure_input_advanced.h"
  7. #include "yuzu/configuration/configure_input_advanced.h"
  8. ConfigureInputAdvanced::ConfigureInputAdvanced(QWidget* parent)
  9. : QWidget(parent), ui(std::make_unique<Ui::ConfigureInputAdvanced>()) {
  10. ui->setupUi(this);
  11. controllers_color_buttons = {{
  12. {
  13. ui->player1_left_body_button,
  14. ui->player1_left_buttons_button,
  15. ui->player1_right_body_button,
  16. ui->player1_right_buttons_button,
  17. },
  18. {
  19. ui->player2_left_body_button,
  20. ui->player2_left_buttons_button,
  21. ui->player2_right_body_button,
  22. ui->player2_right_buttons_button,
  23. },
  24. {
  25. ui->player3_left_body_button,
  26. ui->player3_left_buttons_button,
  27. ui->player3_right_body_button,
  28. ui->player3_right_buttons_button,
  29. },
  30. {
  31. ui->player4_left_body_button,
  32. ui->player4_left_buttons_button,
  33. ui->player4_right_body_button,
  34. ui->player4_right_buttons_button,
  35. },
  36. {
  37. ui->player5_left_body_button,
  38. ui->player5_left_buttons_button,
  39. ui->player5_right_body_button,
  40. ui->player5_right_buttons_button,
  41. },
  42. {
  43. ui->player6_left_body_button,
  44. ui->player6_left_buttons_button,
  45. ui->player6_right_body_button,
  46. ui->player6_right_buttons_button,
  47. },
  48. {
  49. ui->player7_left_body_button,
  50. ui->player7_left_buttons_button,
  51. ui->player7_right_body_button,
  52. ui->player7_right_buttons_button,
  53. },
  54. {
  55. ui->player8_left_body_button,
  56. ui->player8_left_buttons_button,
  57. ui->player8_right_body_button,
  58. ui->player8_right_buttons_button,
  59. },
  60. }};
  61. for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
  62. auto& color_buttons = controllers_color_buttons[player_idx];
  63. for (std::size_t button_idx = 0; button_idx < color_buttons.size(); ++button_idx) {
  64. connect(color_buttons[button_idx], &QPushButton::clicked, this,
  65. [this, player_idx, button_idx] {
  66. OnControllerButtonClick(player_idx, button_idx);
  67. });
  68. }
  69. }
  70. connect(ui->mouse_enabled, &QCheckBox::stateChanged, this,
  71. &ConfigureInputAdvanced::UpdateUIEnabled);
  72. connect(ui->debug_enabled, &QCheckBox::stateChanged, this,
  73. &ConfigureInputAdvanced::UpdateUIEnabled);
  74. connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this,
  75. &ConfigureInputAdvanced::UpdateUIEnabled);
  76. connect(ui->enable_ring_controller, &QCheckBox::stateChanged, this,
  77. &ConfigureInputAdvanced::UpdateUIEnabled);
  78. connect(ui->debug_configure, &QPushButton::clicked, this,
  79. [this] { CallDebugControllerDialog(); });
  80. connect(ui->touchscreen_advanced, &QPushButton::clicked, this,
  81. [this] { CallTouchscreenConfigDialog(); });
  82. connect(ui->buttonMotionTouch, &QPushButton::clicked, this,
  83. [this] { CallMotionTouchConfigDialog(); });
  84. connect(ui->ring_controller_configure, &QPushButton::clicked, this,
  85. [this] { CallRingControllerDialog(); });
  86. connect(ui->camera_configure, &QPushButton::clicked, this, [this] { CallCameraDialog(); });
  87. #ifndef _WIN32
  88. ui->enable_raw_input->setVisible(false);
  89. #endif
  90. LoadConfiguration();
  91. }
  92. ConfigureInputAdvanced::~ConfigureInputAdvanced() = default;
  93. void ConfigureInputAdvanced::OnControllerButtonClick(std::size_t player_idx,
  94. std::size_t button_idx) {
  95. const QColor new_bg_color = QColorDialog::getColor(controllers_colors[player_idx][button_idx]);
  96. if (!new_bg_color.isValid()) {
  97. return;
  98. }
  99. controllers_colors[player_idx][button_idx] = new_bg_color;
  100. controllers_color_buttons[player_idx][button_idx]->setStyleSheet(
  101. QStringLiteral("background-color: %1; min-width: 60px;")
  102. .arg(controllers_colors[player_idx][button_idx].name()));
  103. }
  104. void ConfigureInputAdvanced::ApplyConfiguration() {
  105. for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
  106. auto& player = Settings::values.players.GetValue()[player_idx];
  107. std::array<u32, 4> colors{};
  108. std::transform(controllers_colors[player_idx].begin(), controllers_colors[player_idx].end(),
  109. colors.begin(), [](QColor color) { return color.rgb(); });
  110. player.body_color_left = colors[0];
  111. player.button_color_left = colors[1];
  112. player.body_color_right = colors[2];
  113. player.button_color_right = colors[3];
  114. }
  115. Settings::values.debug_pad_enabled = ui->debug_enabled->isChecked();
  116. Settings::values.mouse_enabled = ui->mouse_enabled->isChecked();
  117. Settings::values.keyboard_enabled = ui->keyboard_enabled->isChecked();
  118. Settings::values.emulate_analog_keyboard = ui->emulate_analog_keyboard->isChecked();
  119. Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked();
  120. Settings::values.enable_raw_input = ui->enable_raw_input->isChecked();
  121. Settings::values.enable_udp_controller = ui->enable_udp_controller->isChecked();
  122. Settings::values.controller_navigation = ui->controller_navigation->isChecked();
  123. Settings::values.enable_ring_controller = ui->enable_ring_controller->isChecked();
  124. Settings::values.enable_ir_sensor = ui->enable_ir_sensor->isChecked();
  125. Settings::values.enable_joycon_driver = ui->enable_joycon_driver->isChecked();
  126. Settings::values.enable_procon_driver = ui->enable_procon_driver->isChecked();
  127. Settings::values.random_amiibo_id = ui->random_amiibo_id->isChecked();
  128. }
  129. void ConfigureInputAdvanced::LoadConfiguration() {
  130. for (std::size_t player_idx = 0; player_idx < controllers_color_buttons.size(); ++player_idx) {
  131. auto& player = Settings::values.players.GetValue()[player_idx];
  132. std::array<u32, 4> colors = {
  133. player.body_color_left,
  134. player.button_color_left,
  135. player.body_color_right,
  136. player.button_color_right,
  137. };
  138. std::transform(colors.begin(), colors.end(), controllers_colors[player_idx].begin(),
  139. [](u32 rgb) { return QColor::fromRgb(rgb); });
  140. for (std::size_t button_idx = 0; button_idx < colors.size(); ++button_idx) {
  141. controllers_color_buttons[player_idx][button_idx]->setStyleSheet(
  142. QStringLiteral("background-color: %1; min-width: 60px;")
  143. .arg(controllers_colors[player_idx][button_idx].name()));
  144. }
  145. }
  146. ui->debug_enabled->setChecked(Settings::values.debug_pad_enabled.GetValue());
  147. ui->mouse_enabled->setChecked(Settings::values.mouse_enabled.GetValue());
  148. ui->keyboard_enabled->setChecked(Settings::values.keyboard_enabled.GetValue());
  149. ui->emulate_analog_keyboard->setChecked(Settings::values.emulate_analog_keyboard.GetValue());
  150. ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled);
  151. ui->enable_raw_input->setChecked(Settings::values.enable_raw_input.GetValue());
  152. ui->enable_udp_controller->setChecked(Settings::values.enable_udp_controller.GetValue());
  153. ui->controller_navigation->setChecked(Settings::values.controller_navigation.GetValue());
  154. ui->enable_ring_controller->setChecked(Settings::values.enable_ring_controller.GetValue());
  155. ui->enable_ir_sensor->setChecked(Settings::values.enable_ir_sensor.GetValue());
  156. ui->enable_joycon_driver->setChecked(Settings::values.enable_joycon_driver.GetValue());
  157. ui->enable_procon_driver->setChecked(Settings::values.enable_procon_driver.GetValue());
  158. ui->random_amiibo_id->setChecked(Settings::values.random_amiibo_id.GetValue());
  159. UpdateUIEnabled();
  160. }
  161. void ConfigureInputAdvanced::changeEvent(QEvent* event) {
  162. if (event->type() == QEvent::LanguageChange) {
  163. RetranslateUI();
  164. }
  165. QWidget::changeEvent(event);
  166. }
  167. void ConfigureInputAdvanced::RetranslateUI() {
  168. ui->retranslateUi(this);
  169. }
  170. void ConfigureInputAdvanced::UpdateUIEnabled() {
  171. ui->debug_configure->setEnabled(ui->debug_enabled->isChecked());
  172. ui->touchscreen_advanced->setEnabled(ui->touchscreen_enabled->isChecked());
  173. ui->ring_controller_configure->setEnabled(ui->enable_ring_controller->isChecked());
  174. #if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) || !defined(YUZU_USE_QT_MULTIMEDIA)
  175. ui->enable_ir_sensor->setEnabled(false);
  176. ui->camera_configure->setEnabled(false);
  177. #endif
  178. }