2021-01-22 00:51:24 +00:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QString>
|
2021-04-15 00:07:40 +01:00
|
|
|
#include "common/settings.h"
|
2021-06-18 15:15:42 +01:00
|
|
|
#include "input_common/main.h"
|
2021-01-22 00:51:24 +00:00
|
|
|
#include "yuzu/configuration/configure_input_player_widget.h"
|
|
|
|
#include "yuzu/debugger/controller.h"
|
|
|
|
|
2021-06-18 15:15:42 +01:00
|
|
|
ControllerDialog::ControllerDialog(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_)
|
|
|
|
: QWidget(parent, Qt::Dialog), input_subsystem{input_subsystem_} {
|
2021-01-22 00:51:24 +00:00
|
|
|
setObjectName(QStringLiteral("Controller"));
|
|
|
|
setWindowTitle(tr("Controller P1"));
|
|
|
|
resize(500, 350);
|
|
|
|
setMinimumSize(500, 350);
|
|
|
|
// Remove the "?" button from the titlebar and enable the maximize button
|
|
|
|
setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) |
|
|
|
|
Qt::WindowMaximizeButtonHint);
|
|
|
|
|
2021-02-04 14:54:27 +00:00
|
|
|
widget = new PlayerControlPreview(this);
|
|
|
|
refreshConfiguration();
|
2021-01-22 00:51:24 +00:00
|
|
|
QLayout* layout = new QVBoxLayout(this);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->addWidget(widget);
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
// Configure focus so that widget is focusable and the dialog automatically forwards focus to
|
|
|
|
// it.
|
|
|
|
setFocusProxy(widget);
|
2021-05-30 16:57:20 +01:00
|
|
|
widget->SetConnectedStatus(false);
|
2021-01-22 00:51:24 +00:00
|
|
|
widget->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
widget->setFocus();
|
|
|
|
}
|
|
|
|
|
2021-02-04 14:54:27 +00:00
|
|
|
void ControllerDialog::refreshConfiguration() {
|
|
|
|
const auto& players = Settings::values.players.GetValue();
|
|
|
|
constexpr std::size_t player = 0;
|
|
|
|
widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs);
|
|
|
|
widget->SetControllerType(players[player].controller_type);
|
2021-07-10 05:30:58 +01:00
|
|
|
ControllerCallback callback{[this](ControllerInput input) { InputController(input); }};
|
2021-06-18 15:15:42 +01:00
|
|
|
widget->SetCallBack(callback);
|
|
|
|
widget->repaint();
|
2021-05-30 16:57:20 +01:00
|
|
|
widget->SetConnectedStatus(players[player].connected);
|
2021-02-04 14:54:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 00:51:24 +00:00
|
|
|
QAction* ControllerDialog::toggleViewAction() {
|
|
|
|
if (toggle_view_action == nullptr) {
|
2021-02-14 20:57:47 +00:00
|
|
|
toggle_view_action = new QAction(tr("&Controller P1"), this);
|
2021-01-22 00:51:24 +00:00
|
|
|
toggle_view_action->setCheckable(true);
|
|
|
|
toggle_view_action->setChecked(isVisible());
|
|
|
|
connect(toggle_view_action, &QAction::toggled, this, &ControllerDialog::setVisible);
|
|
|
|
}
|
|
|
|
|
|
|
|
return toggle_view_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerDialog::showEvent(QShowEvent* ev) {
|
|
|
|
if (toggle_view_action) {
|
|
|
|
toggle_view_action->setChecked(isVisible());
|
|
|
|
}
|
2021-05-30 16:57:20 +01:00
|
|
|
refreshConfiguration();
|
2021-01-22 00:51:24 +00:00
|
|
|
QWidget::showEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerDialog::hideEvent(QHideEvent* ev) {
|
|
|
|
if (toggle_view_action) {
|
|
|
|
toggle_view_action->setChecked(isVisible());
|
|
|
|
}
|
2021-05-30 16:57:20 +01:00
|
|
|
widget->SetConnectedStatus(false);
|
2021-01-22 00:51:24 +00:00
|
|
|
QWidget::hideEvent(ev);
|
|
|
|
}
|
2021-06-18 15:15:42 +01:00
|
|
|
|
|
|
|
void ControllerDialog::InputController(ControllerInput input) {
|
|
|
|
u32 buttons = 0;
|
|
|
|
int index = 0;
|
|
|
|
for (bool btn : input.button_values) {
|
2021-07-26 02:52:19 +01:00
|
|
|
buttons |= (btn ? 1U : 0U) << index;
|
2021-06-18 15:15:42 +01:00
|
|
|
index++;
|
|
|
|
}
|
2021-09-20 23:18:40 +01:00
|
|
|
//input_subsystem->GetTas()->RecordInput(buttons, input.axis_values);
|
2021-06-19 23:04:34 +01:00
|
|
|
}
|