mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-26 08:27:51 -05:00
input_common: Revert deleted TAS functions
This commit is contained in:
@ -7,11 +7,16 @@
|
||||
#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 "yuzu/configuration/configure_input_player_widget.h"
|
||||
#include "yuzu/debugger/controller.h"
|
||||
|
||||
ControllerDialog::ControllerDialog(Core::System& system, QWidget* parent)
|
||||
: QWidget(parent, Qt::Dialog) {
|
||||
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);
|
||||
@ -21,7 +26,7 @@ ControllerDialog::ControllerDialog(Core::System& system, QWidget* parent)
|
||||
Qt::WindowMaximizeButtonHint);
|
||||
|
||||
widget = new PlayerControlPreview(this);
|
||||
widget->SetController(system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1));
|
||||
refreshConfiguration();
|
||||
QLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(widget);
|
||||
@ -34,6 +39,22 @@ ControllerDialog::ControllerDialog(Core::System& system, QWidget* parent)
|
||||
widget->setFocus();
|
||||
}
|
||||
|
||||
void ControllerDialog::refreshConfiguration() {
|
||||
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() {
|
||||
if (toggle_view_action == nullptr) {
|
||||
toggle_view_action = new QAction(tr("&Controller P1"), this);
|
||||
@ -47,6 +68,10 @@ QAction* ControllerDialog::toggleViewAction() {
|
||||
|
||||
void ControllerDialog::UnloadController() {
|
||||
widget->UnloadController();
|
||||
if (is_controller_set) {
|
||||
controller->DeleteCallback(callback_key);
|
||||
is_controller_set = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerDialog::showEvent(QShowEvent* ev) {
|
||||
@ -62,3 +87,32 @@ void ControllerDialog::hideEvent(QHideEvent* ev) {
|
||||
}
|
||||
QWidget::hideEvent(ev);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -11,24 +11,33 @@ class QHideEvent;
|
||||
class QShowEvent;
|
||||
class PlayerControlPreview;
|
||||
|
||||
namespace InputCommon {
|
||||
class InputSubsystem;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace InputCommon {
|
||||
class InputSubsystem;
|
||||
namespace Core::HID {
|
||||
class EmulatedController;
|
||||
}
|
||||
|
||||
class ControllerDialog : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ControllerDialog(Core::System& system, QWidget* parent = 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();
|
||||
|
||||
// Disables events from the emulated controller
|
||||
/// Reloads the widget to apply any changes in the configuration
|
||||
void refreshConfiguration();
|
||||
|
||||
/// Disables events from the emulated controller
|
||||
void UnloadController();
|
||||
|
||||
protected:
|
||||
@ -36,6 +45,15 @@ protected:
|
||||
void hideEvent(QHideEvent* ev) override;
|
||||
|
||||
private:
|
||||
/// 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;
|
||||
PlayerControlPreview* widget;
|
||||
Core::System& system;
|
||||
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
|
||||
};
|
||||
|
Reference in New Issue
Block a user