controller.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QAction>
  5. #include <QLayout>
  6. #include <QString>
  7. #include "common/settings.h"
  8. #include "input_common/main.h"
  9. #include "yuzu/configuration/configure_input_player_widget.h"
  10. #include "yuzu/debugger/controller.h"
  11. ControllerDialog::ControllerDialog(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_)
  12. : QWidget(parent, Qt::Dialog), input_subsystem{input_subsystem_} {
  13. setObjectName(QStringLiteral("Controller"));
  14. setWindowTitle(tr("Controller P1"));
  15. resize(500, 350);
  16. setMinimumSize(500, 350);
  17. // Remove the "?" button from the titlebar and enable the maximize button
  18. setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) |
  19. Qt::WindowMaximizeButtonHint);
  20. widget = new PlayerControlPreview(this);
  21. refreshConfiguration();
  22. QLayout* layout = new QVBoxLayout(this);
  23. layout->setContentsMargins(0, 0, 0, 0);
  24. layout->addWidget(widget);
  25. setLayout(layout);
  26. // Configure focus so that widget is focusable and the dialog automatically forwards focus to
  27. // it.
  28. setFocusProxy(widget);
  29. widget->SetConnectedStatus(false);
  30. widget->setFocusPolicy(Qt::StrongFocus);
  31. widget->setFocus();
  32. }
  33. void ControllerDialog::refreshConfiguration() {
  34. const auto& players = Settings::values.players.GetValue();
  35. constexpr std::size_t player = 0;
  36. widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs);
  37. widget->SetControllerType(players[player].controller_type);
  38. ControllerCallback callback{[this](ControllerInput input) { InputController(input); }};
  39. widget->SetCallBack(callback);
  40. widget->repaint();
  41. widget->SetConnectedStatus(players[player].connected);
  42. }
  43. QAction* ControllerDialog::toggleViewAction() {
  44. if (toggle_view_action == nullptr) {
  45. toggle_view_action = new QAction(tr("&Controller P1"), this);
  46. toggle_view_action->setCheckable(true);
  47. toggle_view_action->setChecked(isVisible());
  48. connect(toggle_view_action, &QAction::toggled, this, &ControllerDialog::setVisible);
  49. }
  50. return toggle_view_action;
  51. }
  52. void ControllerDialog::showEvent(QShowEvent* ev) {
  53. if (toggle_view_action) {
  54. toggle_view_action->setChecked(isVisible());
  55. }
  56. refreshConfiguration();
  57. QWidget::showEvent(ev);
  58. }
  59. void ControllerDialog::hideEvent(QHideEvent* ev) {
  60. if (toggle_view_action) {
  61. toggle_view_action->setChecked(isVisible());
  62. }
  63. widget->SetConnectedStatus(false);
  64. QWidget::hideEvent(ev);
  65. }
  66. void ControllerDialog::InputController(ControllerInput input) {
  67. u32 buttons = 0;
  68. int index = 0;
  69. for (bool btn : input.button_values) {
  70. buttons |= (btn ? 1U : 0U) << index;
  71. index++;
  72. }
  73. //input_subsystem->GetTas()->RecordInput(buttons, input.axis_values);
  74. }