early-access version 2177
This commit is contained in:
@@ -6,13 +6,17 @@
|
||||
#include <QLayout>
|
||||
#include <QString>
|
||||
#include "common/settings.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hid/emulated_controller.h"
|
||||
#include "input_common/drivers/tas_input.h"
|
||||
#include "input_common/main.h"
|
||||
#include "input_common/tas/tas_input.h"
|
||||
#include "yuzu/configuration/configure_input_player_widget.h"
|
||||
#include "yuzu/debugger/controller.h"
|
||||
|
||||
ControllerDialog::ControllerDialog(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_)
|
||||
: QWidget(parent, Qt::Dialog), input_subsystem{input_subsystem_} {
|
||||
ControllerDialog::ControllerDialog(Core::System& system_,
|
||||
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_,
|
||||
QWidget* parent)
|
||||
: QWidget(parent, Qt::Dialog), system{system_}, input_subsystem{input_subsystem_} {
|
||||
setObjectName(QStringLiteral("Controller"));
|
||||
setWindowTitle(tr("Controller P1"));
|
||||
resize(500, 350);
|
||||
@@ -31,20 +35,24 @@ ControllerDialog::ControllerDialog(QWidget* parent, InputCommon::InputSubsystem*
|
||||
// Configure focus so that widget is focusable and the dialog automatically forwards focus to
|
||||
// it.
|
||||
setFocusProxy(widget);
|
||||
widget->SetConnectedStatus(false);
|
||||
widget->setFocusPolicy(Qt::StrongFocus);
|
||||
widget->setFocus();
|
||||
}
|
||||
|
||||
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);
|
||||
ControllerCallback callback{[this](ControllerInput input) { InputController(input); }};
|
||||
widget->SetCallBack(callback);
|
||||
widget->repaint();
|
||||
widget->SetConnectedStatus(players[player].connected);
|
||||
UnloadController();
|
||||
auto* player_1 = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
|
||||
auto* handheld = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld);
|
||||
// Display the correct controller
|
||||
controller = handheld->IsConnected() ? handheld : player_1;
|
||||
|
||||
Core::HID::ControllerUpdateCallback engine_callback{
|
||||
.on_change = [this](Core::HID::ControllerTriggerType type) { ControllerUpdate(type); },
|
||||
.is_npad_service = true,
|
||||
};
|
||||
callback_key = controller->SetCallback(engine_callback);
|
||||
widget->SetController(controller);
|
||||
is_controller_set = true;
|
||||
}
|
||||
|
||||
QAction* ControllerDialog::toggleViewAction() {
|
||||
@@ -58,11 +66,18 @@ QAction* ControllerDialog::toggleViewAction() {
|
||||
return toggle_view_action;
|
||||
}
|
||||
|
||||
void ControllerDialog::UnloadController() {
|
||||
widget->UnloadController();
|
||||
if (is_controller_set) {
|
||||
controller->DeleteCallback(callback_key);
|
||||
is_controller_set = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerDialog::showEvent(QShowEvent* ev) {
|
||||
if (toggle_view_action) {
|
||||
toggle_view_action->setChecked(isVisible());
|
||||
}
|
||||
refreshConfiguration();
|
||||
QWidget::showEvent(ev);
|
||||
}
|
||||
|
||||
@@ -70,16 +85,34 @@ void ControllerDialog::hideEvent(QHideEvent* ev) {
|
||||
if (toggle_view_action) {
|
||||
toggle_view_action->setChecked(isVisible());
|
||||
}
|
||||
widget->SetConnectedStatus(false);
|
||||
QWidget::hideEvent(ev);
|
||||
}
|
||||
|
||||
void ControllerDialog::InputController(ControllerInput input) {
|
||||
u32 buttons = 0;
|
||||
int index = 0;
|
||||
for (bool btn : input.button_values) {
|
||||
buttons |= (btn ? 1U : 0U) << index;
|
||||
index++;
|
||||
void ControllerDialog::ControllerUpdate(Core::HID::ControllerTriggerType type) {
|
||||
// TODO(german77): Remove TAS from here
|
||||
switch (type) {
|
||||
case Core::HID::ControllerTriggerType::Button:
|
||||
case Core::HID::ControllerTriggerType::Stick: {
|
||||
const auto buttons_values = controller->GetButtonsValues();
|
||||
const auto stick_values = controller->GetSticksValues();
|
||||
u64 buttons = 0;
|
||||
std::size_t index = 0;
|
||||
for (const auto& button : buttons_values) {
|
||||
buttons |= button.value ? 1LLU << index : 0;
|
||||
index++;
|
||||
}
|
||||
const InputCommon::TasInput::TasAnalog left_axis = {
|
||||
.x = stick_values[Settings::NativeAnalog::LStick].x.value,
|
||||
.y = stick_values[Settings::NativeAnalog::LStick].y.value,
|
||||
};
|
||||
const InputCommon::TasInput::TasAnalog right_axis = {
|
||||
.x = stick_values[Settings::NativeAnalog::RStick].x.value,
|
||||
.y = stick_values[Settings::NativeAnalog::RStick].y.value,
|
||||
};
|
||||
input_subsystem->GetTas()->RecordInput(buttons, left_axis, right_axis);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
input_subsystem->GetTas()->RecordInput(buttons, input.axis_values);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QWidget>
|
||||
#include "common/settings.h"
|
||||
|
||||
class QAction;
|
||||
class QHideEvent;
|
||||
@@ -17,35 +15,46 @@ namespace InputCommon {
|
||||
class InputSubsystem;
|
||||
}
|
||||
|
||||
struct ControllerInput {
|
||||
std::array<std::pair<float, float>, Settings::NativeAnalog::NUM_STICKS_HID> axis_values{};
|
||||
std::array<bool, Settings::NativeButton::NumButtons> button_values{};
|
||||
bool changed{};
|
||||
};
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
struct ControllerCallback {
|
||||
std::function<void(ControllerInput)> input;
|
||||
};
|
||||
namespace Core::HID {
|
||||
class EmulatedController;
|
||||
enum class ControllerTriggerType;
|
||||
} // namespace Core::HID
|
||||
|
||||
class ControllerDialog : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ControllerDialog(QWidget* parent = nullptr,
|
||||
InputCommon::InputSubsystem* input_subsystem_ = nullptr);
|
||||
explicit ControllerDialog(Core::System& system_,
|
||||
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
/// Returns a QAction that can be used to toggle visibility of this dialog.
|
||||
QAction* toggleViewAction();
|
||||
|
||||
/// Reloads the widget to apply any changes in the configuration
|
||||
void refreshConfiguration();
|
||||
|
||||
/// Disables events from the emulated controller
|
||||
void UnloadController();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* ev) override;
|
||||
void hideEvent(QHideEvent* ev) override;
|
||||
|
||||
private:
|
||||
void InputController(ControllerInput input);
|
||||
/// Redirects input from the widget to the TAS driver
|
||||
void ControllerUpdate(Core::HID::ControllerTriggerType type);
|
||||
|
||||
int callback_key;
|
||||
bool is_controller_set{};
|
||||
Core::HID::EmulatedController* controller;
|
||||
|
||||
QAction* toggle_view_action = nullptr;
|
||||
QFileSystemWatcher* watcher = nullptr;
|
||||
PlayerControlPreview* widget;
|
||||
InputCommon::InputSubsystem* input_subsystem;
|
||||
Core::System& system;
|
||||
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user