DolphinQt: Use input override system for TAS input windows

This lets the TAS input code use a higher-level interface for
overriding inputs instead of having to fiddle with raw bits.
WiiTASInputWindow in particular was messy with how much
controller code it had to re-implement.
This commit is contained in:
JosJuice
2021-03-21 22:42:33 +01:00
parent 8fd25259ee
commit b296248b49
21 changed files with 557 additions and 507 deletions

View File

@ -15,18 +15,14 @@
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/MathUtil.h"
#include "Core/Core.h"
#include "Core/HW/WiimoteCommon/DataReport.h"
#include "Core/HW/WiimoteEmu/Encryption.h"
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
#include "Core/HW/WiimoteEmu/Extension/Extension.h"
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/Camera.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
@ -34,6 +30,9 @@
#include "DolphinQt/TAS/IRWidget.h"
#include "DolphinQt/TAS/TASCheckBox.h"
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/StickGate.h"
#include "InputCommon/InputConfig.h"
using namespace WiimoteCommon;
@ -48,21 +47,25 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
ir_x_shortcut_key_sequence.toString(QKeySequence::NativeText),
ir_y_shortcut_key_sequence.toString(QKeySequence::NativeText)));
const int ir_x_default = static_cast<int>(std::round(ir_max_x / 2.));
const int ir_y_default = static_cast<int>(std::round(ir_max_y / 2.));
const int ir_x_center = static_cast<int>(std::round(ir_max_x / 2.));
const int ir_y_center = static_cast<int>(std::round(ir_max_y / 2.));
auto* x_layout = new QHBoxLayout;
m_ir_x_value = CreateSliderValuePair(x_layout, ir_x_default, ir_max_x, ir_x_shortcut_key_sequence,
Qt::Horizontal, m_ir_box, true);
m_ir_x_value = CreateSliderValuePair(
WiimoteEmu::Wiimote::IR_GROUP, ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE,
&m_wiimote_overrider, x_layout, ir_x_center, ir_x_center, ir_min_x, ir_max_x,
ir_x_shortcut_key_sequence, Qt::Horizontal, m_ir_box);
auto* y_layout = new QVBoxLayout;
m_ir_y_value = CreateSliderValuePair(y_layout, ir_y_default, ir_max_y, ir_y_shortcut_key_sequence,
Qt::Vertical, m_ir_box, true);
m_ir_y_value = CreateSliderValuePair(
WiimoteEmu::Wiimote::IR_GROUP, ControllerEmu::ReshapableInput::Y_INPUT_OVERRIDE,
&m_wiimote_overrider, y_layout, ir_y_center, ir_y_center, ir_min_y, ir_max_y,
ir_y_shortcut_key_sequence, Qt::Vertical, m_ir_box);
m_ir_y_value->setMaximumWidth(60);
auto* visual = new IRWidget(this);
visual->SetX(ir_x_default);
visual->SetY(ir_y_default);
visual->SetX(ir_x_center);
visual->SetY(ir_y_center);
connect(m_ir_x_value, qOverload<int>(&QSpinBox::valueChanged), visual, &IRWidget::SetX);
connect(m_ir_y_value, qOverload<int>(&QSpinBox::valueChanged), visual, &IRWidget::SetY);
@ -80,16 +83,19 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
ir_layout->addLayout(visual_layout);
m_ir_box->setLayout(ir_layout);
m_nunchuk_stick_box = CreateStickInputs(tr("Nunchuk Stick"), m_nunchuk_stick_x_value,
m_nunchuk_stick_y_value, 255, 255, Qt::Key_X, Qt::Key_Y);
m_nunchuk_stick_box = CreateStickInputs(
tr("Nunchuk Stick"), WiimoteEmu::Nunchuk::STICK_GROUP, &m_nunchuk_overrider,
m_nunchuk_stick_x_value, m_nunchuk_stick_y_value, 0, 0, 255, 255, Qt::Key_X, Qt::Key_Y);
m_classic_left_stick_box =
CreateStickInputs(tr("Left Stick"), m_classic_left_stick_x_value,
m_classic_left_stick_y_value, 63, 63, Qt::Key_F, Qt::Key_G);
CreateStickInputs(tr("Left Stick"), WiimoteEmu::Classic::LEFT_STICK_GROUP,
&m_classic_overrider, m_classic_left_stick_x_value,
m_classic_left_stick_y_value, 0, 0, 63, 63, Qt::Key_F, Qt::Key_G);
m_classic_right_stick_box =
CreateStickInputs(tr("Right Stick"), m_classic_right_stick_x_value,
m_classic_right_stick_y_value, 31, 31, Qt::Key_Q, Qt::Key_W);
CreateStickInputs(tr("Right Stick"), WiimoteEmu::Classic::RIGHT_STICK_GROUP,
&m_classic_overrider, m_classic_right_stick_x_value,
m_classic_right_stick_y_value, 0, 0, 31, 31, Qt::Key_Q, Qt::Key_W);
// Need to enforce the same minimum width because otherwise the different lengths in the labels
// used on the QGroupBox will cause the StickWidgets to have different sizes.
@ -104,18 +110,33 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
top_layout->addWidget(m_classic_left_stick_box);
top_layout->addWidget(m_classic_right_stick_box);
constexpr u16 ACCEL_ZERO_G = WiimoteEmu::Wiimote::ACCEL_ZERO_G << 2;
constexpr u16 ACCEL_ONE_G = WiimoteEmu::Wiimote::ACCEL_ONE_G << 2;
constexpr u16 ACCEL_MIN = 0;
constexpr u16 ACCEL_MAX = (1 << 10) - 1;
constexpr double ACCEL_SCALE = (ACCEL_ONE_G - ACCEL_ZERO_G) / MathUtil::GRAVITY_ACCELERATION;
auto* remote_orientation_x_layout =
// i18n: Refers to a 3D axis (used when mapping motion controls)
CreateSliderValuePairLayout(tr("X"), m_remote_orientation_x_value, 512, 1023, Qt::Key_Q,
m_remote_orientation_box);
CreateSliderValuePairLayout(tr("X"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP,
ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE,
&m_wiimote_overrider, m_remote_orientation_x_value, ACCEL_ZERO_G,
ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_Q,
m_remote_orientation_box, ACCEL_SCALE);
auto* remote_orientation_y_layout =
// i18n: Refers to a 3D axis (used when mapping motion controls)
CreateSliderValuePairLayout(tr("Y"), m_remote_orientation_y_value, 512, 1023, Qt::Key_W,
m_remote_orientation_box);
CreateSliderValuePairLayout(tr("Y"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP,
ControllerEmu::ReshapableInput::Y_INPUT_OVERRIDE,
&m_wiimote_overrider, m_remote_orientation_y_value, ACCEL_ZERO_G,
ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_W,
m_remote_orientation_box, ACCEL_SCALE);
auto* remote_orientation_z_layout =
// i18n: Refers to a 3D axis (used when mapping motion controls)
CreateSliderValuePairLayout(tr("Z"), m_remote_orientation_z_value, 616, 1023, Qt::Key_E,
m_remote_orientation_box);
CreateSliderValuePairLayout(tr("Z"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP,
ControllerEmu::ReshapableInput::Z_INPUT_OVERRIDE,
&m_wiimote_overrider, m_remote_orientation_z_value, ACCEL_ZERO_G,
ACCEL_ONE_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_E,
m_remote_orientation_box, ACCEL_SCALE);
auto* remote_orientation_layout = new QVBoxLayout;
remote_orientation_layout->addLayout(remote_orientation_x_layout);
@ -127,15 +148,24 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
auto* nunchuk_orientation_x_layout =
// i18n: Refers to a 3D axis (used when mapping motion controls)
CreateSliderValuePairLayout(tr("X"), m_nunchuk_orientation_x_value, 512, 1023, Qt::Key_I,
CreateSliderValuePairLayout(tr("X"), WiimoteEmu::Nunchuk::ACCELEROMETER_GROUP,
ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE,
&m_nunchuk_overrider, m_nunchuk_orientation_x_value, ACCEL_ZERO_G,
ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_I,
m_nunchuk_orientation_box);
auto* nunchuk_orientation_y_layout =
// i18n: Refers to a 3D axis (used when mapping motion controls)
CreateSliderValuePairLayout(tr("Y"), m_nunchuk_orientation_y_value, 512, 1023, Qt::Key_O,
CreateSliderValuePairLayout(tr("Y"), WiimoteEmu::Nunchuk::ACCELEROMETER_GROUP,
ControllerEmu::ReshapableInput::Y_INPUT_OVERRIDE,
&m_nunchuk_overrider, m_nunchuk_orientation_y_value, ACCEL_ZERO_G,
ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_O,
m_nunchuk_orientation_box);
auto* nunchuk_orientation_z_layout =
// i18n: Refers to a 3D axis (used when mapping motion controls)
CreateSliderValuePairLayout(tr("Z"), m_nunchuk_orientation_z_value, 512, 1023, Qt::Key_P,
CreateSliderValuePairLayout(tr("Z"), WiimoteEmu::Nunchuk::ACCELEROMETER_GROUP,
ControllerEmu::ReshapableInput::Z_INPUT_OVERRIDE,
&m_nunchuk_overrider, m_nunchuk_orientation_z_value, ACCEL_ZERO_G,
ACCEL_ONE_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_P,
m_nunchuk_orientation_box);
auto* nunchuk_orientation_layout = new QVBoxLayout;
@ -145,29 +175,46 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
m_nunchuk_orientation_box->setLayout(nunchuk_orientation_layout);
m_triggers_box = new QGroupBox(tr("Triggers"));
auto* l_trigger_layout = CreateSliderValuePairLayout(tr("Left"), m_left_trigger_value, 0, 31,
Qt::Key_N, m_triggers_box);
auto* r_trigger_layout = CreateSliderValuePairLayout(tr("Right"), m_right_trigger_value, 0, 31,
Qt::Key_M, m_triggers_box);
auto* l_trigger_layout = CreateSliderValuePairLayout(
tr("Left"), WiimoteEmu::Classic::TRIGGERS_GROUP, WiimoteEmu::Classic::L_ANALOG,
&m_classic_overrider, m_left_trigger_value, 0, 0, 0, 31, Qt::Key_N, m_triggers_box);
auto* r_trigger_layout = CreateSliderValuePairLayout(
tr("Right"), WiimoteEmu::Classic::TRIGGERS_GROUP, WiimoteEmu::Classic::R_ANALOG,
&m_classic_overrider, m_right_trigger_value, 0, 0, 0, 31, Qt::Key_M, m_triggers_box);
auto* triggers_layout = new QVBoxLayout;
triggers_layout->addLayout(l_trigger_layout);
triggers_layout->addLayout(r_trigger_layout);
m_triggers_box->setLayout(triggers_layout);
m_a_button = CreateButton(QStringLiteral("&A"));
m_b_button = CreateButton(QStringLiteral("&B"));
m_1_button = CreateButton(QStringLiteral("&1"));
m_2_button = CreateButton(QStringLiteral("&2"));
m_plus_button = CreateButton(QStringLiteral("&+"));
m_minus_button = CreateButton(QStringLiteral("&-"));
m_home_button = CreateButton(QStringLiteral("&HOME"));
m_left_button = CreateButton(QStringLiteral("&Left"));
m_up_button = CreateButton(QStringLiteral("&Up"));
m_down_button = CreateButton(QStringLiteral("&Down"));
m_right_button = CreateButton(QStringLiteral("&Right"));
m_c_button = CreateButton(QStringLiteral("&C"));
m_z_button = CreateButton(QStringLiteral("&Z"));
m_a_button = CreateButton(QStringLiteral("&A"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
WiimoteEmu::Wiimote::A_BUTTON, &m_wiimote_overrider);
m_b_button = CreateButton(QStringLiteral("&B"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
WiimoteEmu::Wiimote::B_BUTTON, &m_wiimote_overrider);
m_1_button = CreateButton(QStringLiteral("&1"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
WiimoteEmu::Wiimote::ONE_BUTTON, &m_wiimote_overrider);
m_2_button = CreateButton(QStringLiteral("&2"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
WiimoteEmu::Wiimote::TWO_BUTTON, &m_wiimote_overrider);
m_plus_button = CreateButton(QStringLiteral("&+"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
WiimoteEmu::Wiimote::PLUS_BUTTON, &m_wiimote_overrider);
m_minus_button = CreateButton(QStringLiteral("&-"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
WiimoteEmu::Wiimote::MINUS_BUTTON, &m_wiimote_overrider);
m_home_button = CreateButton(QStringLiteral("&HOME"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
WiimoteEmu::Wiimote::HOME_BUTTON, &m_wiimote_overrider);
m_left_button = CreateButton(QStringLiteral("&Left"), WiimoteEmu::Wiimote::DPAD_GROUP,
DIRECTION_LEFT, &m_wiimote_overrider);
m_up_button = CreateButton(QStringLiteral("&Up"), WiimoteEmu::Wiimote::DPAD_GROUP, DIRECTION_UP,
&m_wiimote_overrider);
m_down_button = CreateButton(QStringLiteral("&Down"), WiimoteEmu::Wiimote::DPAD_GROUP,
DIRECTION_DOWN, &m_wiimote_overrider);
m_right_button = CreateButton(QStringLiteral("&Right"), WiimoteEmu::Wiimote::DPAD_GROUP,
DIRECTION_RIGHT, &m_wiimote_overrider);
m_c_button = CreateButton(QStringLiteral("&C"), WiimoteEmu::Nunchuk::BUTTONS_GROUP,
WiimoteEmu::Nunchuk::C_BUTTON, &m_nunchuk_overrider);
m_z_button = CreateButton(QStringLiteral("&Z"), WiimoteEmu::Nunchuk::BUTTONS_GROUP,
WiimoteEmu::Nunchuk::Z_BUTTON, &m_nunchuk_overrider);
auto* buttons_layout = new QGridLayout;
buttons_layout->addWidget(m_a_button, 0, 0);
@ -196,21 +243,38 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
m_nunchuk_buttons_box = new QGroupBox(tr("Nunchuk Buttons"));
m_nunchuk_buttons_box->setLayout(nunchuk_buttons_layout);
m_classic_a_button = CreateButton(QStringLiteral("&A"));
m_classic_b_button = CreateButton(QStringLiteral("&B"));
m_classic_x_button = CreateButton(QStringLiteral("&X"));
m_classic_y_button = CreateButton(QStringLiteral("&Y"));
m_classic_l_button = CreateButton(QStringLiteral("&L"));
m_classic_r_button = CreateButton(QStringLiteral("&R"));
m_classic_zl_button = CreateButton(QStringLiteral("&ZL"));
m_classic_zr_button = CreateButton(QStringLiteral("ZR"));
m_classic_plus_button = CreateButton(QStringLiteral("&+"));
m_classic_minus_button = CreateButton(QStringLiteral("&-"));
m_classic_home_button = CreateButton(QStringLiteral("&HOME"));
m_classic_left_button = CreateButton(QStringLiteral("L&eft"));
m_classic_up_button = CreateButton(QStringLiteral("&Up"));
m_classic_down_button = CreateButton(QStringLiteral("&Down"));
m_classic_right_button = CreateButton(QStringLiteral("R&ight"));
m_classic_a_button = CreateButton(QStringLiteral("&A"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::A_BUTTON, &m_classic_overrider);
m_classic_b_button = CreateButton(QStringLiteral("&B"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::B_BUTTON, &m_classic_overrider);
m_classic_x_button = CreateButton(QStringLiteral("&X"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::X_BUTTON, &m_classic_overrider);
m_classic_y_button = CreateButton(QStringLiteral("&Y"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::Y_BUTTON, &m_classic_overrider);
m_classic_zl_button = CreateButton(QStringLiteral("&ZL"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::ZL_BUTTON, &m_classic_overrider);
m_classic_zr_button = CreateButton(QStringLiteral("ZR"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::ZR_BUTTON, &m_classic_overrider);
m_classic_plus_button = CreateButton(QStringLiteral("&+"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::PLUS_BUTTON, &m_classic_overrider);
m_classic_minus_button = CreateButton(QStringLiteral("&-"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::MINUS_BUTTON, &m_classic_overrider);
m_classic_home_button = CreateButton(QStringLiteral("&HOME"), WiimoteEmu::Classic::BUTTONS_GROUP,
WiimoteEmu::Classic::HOME_BUTTON, &m_classic_overrider);
m_classic_l_button = CreateButton(QStringLiteral("&L"), WiimoteEmu::Classic::TRIGGERS_GROUP,
WiimoteEmu::Classic::L_DIGITAL, &m_classic_overrider);
m_classic_r_button = CreateButton(QStringLiteral("&R"), WiimoteEmu::Classic::TRIGGERS_GROUP,
WiimoteEmu::Classic::R_DIGITAL, &m_classic_overrider);
m_classic_left_button = CreateButton(QStringLiteral("L&eft"), WiimoteEmu::Classic::DPAD_GROUP,
DIRECTION_LEFT, &m_classic_overrider);
m_classic_up_button = CreateButton(QStringLiteral("&Up"), WiimoteEmu::Classic::DPAD_GROUP,
DIRECTION_UP, &m_classic_overrider);
m_classic_down_button = CreateButton(QStringLiteral("&Down"), WiimoteEmu::Classic::DPAD_GROUP,
DIRECTION_DOWN, &m_classic_overrider);
m_classic_right_button = CreateButton(QStringLiteral("R&ight"), WiimoteEmu::Classic::DPAD_GROUP,
DIRECTION_RIGHT, &m_classic_overrider);
auto* classic_buttons_layout = new QGridLayout;
classic_buttons_layout->addWidget(m_classic_a_button, 0, 0);
@ -247,11 +311,9 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
setLayout(layout);
u8 ext = 0;
if (Core::IsRunning())
{
ext = static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(num))
->GetActiveExtensionNumber();
m_active_extension = GetWiimote()->GetActiveExtensionNumber();
}
else
{
@ -261,16 +323,35 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
ini.GetIfExists("Wiimote" + std::to_string(num + 1), "Extension", &extension);
if (extension == "Nunchuk")
ext = 1;
if (extension == "Classic")
ext = 2;
m_active_extension = WiimoteEmu::ExtensionNumber::NUNCHUK;
else if (extension == "Classic")
m_active_extension = WiimoteEmu::ExtensionNumber::CLASSIC;
else
m_active_extension = WiimoteEmu::ExtensionNumber::NONE;
}
UpdateExt(ext);
UpdateExt();
}
void WiiTASInputWindow::UpdateExt(u8 ext)
WiimoteEmu::Wiimote* WiiTASInputWindow::GetWiimote()
{
if (ext == 1)
return static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(m_num));
}
ControllerEmu::Attachments* WiiTASInputWindow::GetAttachments()
{
return static_cast<ControllerEmu::Attachments*>(
GetWiimote()->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::Attachments));
}
WiimoteEmu::Extension* WiiTASInputWindow::GetExtension()
{
return static_cast<WiimoteEmu::Extension*>(
GetAttachments()->GetAttachmentList()[m_active_extension].get());
}
void WiiTASInputWindow::UpdateExt()
{
if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK)
{
setWindowTitle(tr("Wii TAS Input %1 - Wii Remote + Nunchuk").arg(m_num + 1));
m_ir_box->show();
@ -284,7 +365,7 @@ void WiiTASInputWindow::UpdateExt(u8 ext)
m_remote_buttons_box->show();
m_classic_buttons_box->hide();
}
else if (ext == 2)
else if (m_active_extension == WiimoteEmu::ExtensionNumber::CLASSIC)
{
setWindowTitle(tr("Wii TAS Input %1 - Classic Controller").arg(m_num + 1));
m_ir_box->hide();
@ -314,183 +395,22 @@ void WiiTASInputWindow::UpdateExt(u8 ext)
}
}
void WiiTASInputWindow::GetValues(DataReportBuilder& rpt, int ext,
const WiimoteEmu::EncryptionKey& key)
void WiiTASInputWindow::hideEvent(QHideEvent* event)
{
if (!isVisible())
return;
UpdateExt(ext);
if (m_remote_buttons_box->isVisible() && rpt.HasCore())
{
DataReportBuilder::CoreData core;
rpt.GetCoreData(&core);
using EmuWiimote = WiimoteEmu::Wiimote;
u16& buttons = core.hex;
GetButton<u16>(m_a_button, buttons, EmuWiimote::BUTTON_A);
GetButton<u16>(m_b_button, buttons, EmuWiimote::BUTTON_B);
GetButton<u16>(m_1_button, buttons, EmuWiimote::BUTTON_ONE);
GetButton<u16>(m_2_button, buttons, EmuWiimote::BUTTON_TWO);
GetButton<u16>(m_plus_button, buttons, EmuWiimote::BUTTON_PLUS);
GetButton<u16>(m_minus_button, buttons, EmuWiimote::BUTTON_MINUS);
GetButton<u16>(m_home_button, buttons, EmuWiimote::BUTTON_HOME);
GetButton<u16>(m_left_button, buttons, EmuWiimote::PAD_LEFT);
GetButton<u16>(m_up_button, buttons, EmuWiimote::PAD_UP);
GetButton<u16>(m_down_button, buttons, EmuWiimote::PAD_DOWN);
GetButton<u16>(m_right_button, buttons, EmuWiimote::PAD_RIGHT);
rpt.SetCoreData(core);
}
if (m_remote_orientation_box->isVisible() && rpt.HasAccel())
{
// FYI: Interleaved reports may behave funky as not all data is always available.
AccelData accel;
rpt.GetAccelData(&accel);
GetSpinBoxU16(m_remote_orientation_x_value, accel.value.x);
GetSpinBoxU16(m_remote_orientation_y_value, accel.value.y);
GetSpinBoxU16(m_remote_orientation_z_value, accel.value.z);
rpt.SetAccelData(accel);
}
if (m_ir_box->isVisible() && rpt.HasIR() && !m_use_controller->isChecked())
{
u8* const ir_data = rpt.GetIRDataPtr();
u16 y = m_ir_y_value->value();
std::array<u16, 4> x;
x[0] = m_ir_x_value->value();
x[1] = x[0] + 100;
x[2] = x[0] - 10;
x[3] = x[1] + 10;
// FYI: This check is not entirely foolproof.
// TODO: IR "full" mode not implemented.
u8 mode = WiimoteEmu::CameraLogic::IR_MODE_BASIC;
if (rpt.GetIRDataSize() == sizeof(WiimoteEmu::IRExtended) * 4)
mode = WiimoteEmu::CameraLogic::IR_MODE_EXTENDED;
else if (rpt.GetIRDataSize() == sizeof(WiimoteEmu::IRFull) * 2)
mode = WiimoteEmu::CameraLogic::IR_MODE_FULL;
if (mode == WiimoteEmu::CameraLogic::IR_MODE_BASIC)
{
memset(ir_data, 0xFF, sizeof(WiimoteEmu::IRBasic) * 2);
auto* const ir_basic = reinterpret_cast<WiimoteEmu::IRBasic*>(ir_data);
for (int i = 0; i < 2; ++i)
{
if (x[i * 2] < 1024 && y < 768)
{
ir_basic[i].x1 = static_cast<u8>(x[i * 2]);
ir_basic[i].x1hi = x[i * 2] >> 8;
ir_basic[i].y1 = static_cast<u8>(y);
ir_basic[i].y1hi = y >> 8;
}
if (x[i * 2 + 1] < 1024 && y < 768)
{
ir_basic[i].x2 = static_cast<u8>(x[i * 2 + 1]);
ir_basic[i].x2hi = x[i * 2 + 1] >> 8;
ir_basic[i].y2 = static_cast<u8>(y);
ir_basic[i].y2hi = y >> 8;
}
}
}
else
{
// TODO: this code doesnt work, resulting in no IR TAS inputs in e.g. wii sports menu when no
// remote extension is used
memset(ir_data, 0xFF, sizeof(WiimoteEmu::IRExtended) * 4);
auto* const ir_extended = reinterpret_cast<WiimoteEmu::IRExtended*>(ir_data);
for (size_t i = 0; i < x.size(); ++i)
{
if (x[i] < 1024 && y < 768)
{
ir_extended[i].x = static_cast<u8>(x[i]);
ir_extended[i].xhi = x[i] >> 8;
ir_extended[i].y = static_cast<u8>(y);
ir_extended[i].yhi = y >> 8;
ir_extended[i].size = 10;
}
}
}
}
if (rpt.HasExt() && m_nunchuk_stick_box->isVisible())
{
u8* const ext_data = rpt.GetExtDataPtr();
auto& nunchuk = *reinterpret_cast<WiimoteEmu::Nunchuk::DataFormat*>(ext_data);
GetSpinBoxU8(m_nunchuk_stick_x_value, nunchuk.jx);
GetSpinBoxU8(m_nunchuk_stick_y_value, nunchuk.jy);
auto accel = nunchuk.GetAccel().value;
GetSpinBoxU16(m_nunchuk_orientation_x_value, accel.x);
GetSpinBoxU16(m_nunchuk_orientation_y_value, accel.y);
GetSpinBoxU16(m_nunchuk_orientation_z_value, accel.z);
nunchuk.SetAccel(accel);
u8 bt = nunchuk.GetButtons();
GetButton<u8>(m_c_button, bt, WiimoteEmu::Nunchuk::BUTTON_C);
GetButton<u8>(m_z_button, bt, WiimoteEmu::Nunchuk::BUTTON_Z);
nunchuk.SetButtons(bt);
key.Encrypt(reinterpret_cast<u8*>(&nunchuk), 0, sizeof(nunchuk));
}
if (m_classic_left_stick_box->isVisible())
{
u8* const ext_data = rpt.GetExtDataPtr();
auto& cc = *reinterpret_cast<WiimoteEmu::Classic::DataFormat*>(ext_data);
key.Decrypt(reinterpret_cast<u8*>(&cc), 0, sizeof(cc));
u16 bt = cc.GetButtons();
GetButton<u16>(m_classic_a_button, bt, WiimoteEmu::Classic::BUTTON_A);
GetButton<u16>(m_classic_b_button, bt, WiimoteEmu::Classic::BUTTON_B);
GetButton<u16>(m_classic_x_button, bt, WiimoteEmu::Classic::BUTTON_X);
GetButton<u16>(m_classic_y_button, bt, WiimoteEmu::Classic::BUTTON_Y);
GetButton<u16>(m_classic_plus_button, bt, WiimoteEmu::Classic::BUTTON_PLUS);
GetButton<u16>(m_classic_minus_button, bt, WiimoteEmu::Classic::BUTTON_MINUS);
GetButton<u16>(m_classic_l_button, bt, WiimoteEmu::Classic::TRIGGER_L);
GetButton<u16>(m_classic_r_button, bt, WiimoteEmu::Classic::TRIGGER_R);
GetButton<u16>(m_classic_zl_button, bt, WiimoteEmu::Classic::BUTTON_ZL);
GetButton<u16>(m_classic_zr_button, bt, WiimoteEmu::Classic::BUTTON_ZR);
GetButton<u16>(m_classic_home_button, bt, WiimoteEmu::Classic::BUTTON_HOME);
GetButton<u16>(m_classic_left_button, bt, WiimoteEmu::Classic::PAD_LEFT);
GetButton<u16>(m_classic_up_button, bt, WiimoteEmu::Classic::PAD_UP);
GetButton<u16>(m_classic_down_button, bt, WiimoteEmu::Classic::PAD_DOWN);
GetButton<u16>(m_classic_right_button, bt, WiimoteEmu::Classic::PAD_RIGHT);
cc.SetButtons(bt);
auto right_stick = cc.GetRightStick().value;
GetSpinBoxU8(m_classic_right_stick_x_value, right_stick.x);
GetSpinBoxU8(m_classic_right_stick_y_value, right_stick.y);
cc.SetRightStick(right_stick);
auto left_stick = cc.GetLeftStick().value;
GetSpinBoxU8(m_classic_left_stick_x_value, left_stick.x);
GetSpinBoxU8(m_classic_left_stick_y_value, left_stick.y);
cc.SetLeftStick(left_stick);
u8 rt = cc.GetRightTrigger().value;
GetSpinBoxU8(m_right_trigger_value, rt);
cc.SetRightTrigger(rt);
u8 lt = cc.GetLeftTrigger().value;
GetSpinBoxU8(m_left_trigger_value, lt);
cc.SetLeftTrigger(lt);
key.Encrypt(reinterpret_cast<u8*>(&cc), 0, sizeof(cc));
}
GetWiimote()->ClearInputOverrideFunction();
GetExtension()->ClearInputOverrideFunction();
}
void WiiTASInputWindow::showEvent(QShowEvent* event)
{
WiimoteEmu::Wiimote* wiimote = GetWiimote();
if (m_active_extension != WiimoteEmu::ExtensionNumber::CLASSIC)
wiimote->SetInputOverrideFunction(m_wiimote_overrider.GetInputOverrideFunction());
if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK)
GetExtension()->SetInputOverrideFunction(m_nunchuk_overrider.GetInputOverrideFunction());
if (m_active_extension == WiimoteEmu::ExtensionNumber::CLASSIC)
GetExtension()->SetInputOverrideFunction(m_classic_overrider.GetInputOverrideFunction());
}