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:
parent
8fd25259ee
commit
b296248b49
Source/Core
Core
DolphinQt
InputCommon/ControllerEmu
|
@ -36,62 +36,47 @@ static const u16 trigger_bitmasks[] = {
|
||||||
static const u16 dpad_bitmasks[] = {PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT,
|
static const u16 dpad_bitmasks[] = {PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT,
|
||||||
PAD_BUTTON_RIGHT};
|
PAD_BUTTON_RIGHT};
|
||||||
|
|
||||||
static const char* const named_buttons[] = {"A", "B", "X", "Y", "Z", "Start"};
|
|
||||||
|
|
||||||
static const char* const named_triggers[] = {
|
|
||||||
// i18n: The left trigger button (labeled L on real controllers)
|
|
||||||
_trans("L"),
|
|
||||||
// i18n: The right trigger button (labeled R on real controllers)
|
|
||||||
_trans("R"),
|
|
||||||
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
|
|
||||||
_trans("L-Analog"),
|
|
||||||
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
|
|
||||||
_trans("R-Analog")};
|
|
||||||
|
|
||||||
GCPad::GCPad(const unsigned int index) : m_index(index)
|
GCPad::GCPad(const unsigned int index) : m_index(index)
|
||||||
{
|
{
|
||||||
// buttons
|
// buttons
|
||||||
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
|
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
|
||||||
for (const char* named_button : named_buttons)
|
for (const char* named_button : {A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, Z_BUTTON})
|
||||||
{
|
{
|
||||||
const bool is_start = named_button == std::string("Start");
|
m_buttons->AddInput(ControllerEmu::DoNotTranslate, named_button);
|
||||||
const ControllerEmu::Translatability translate =
|
|
||||||
is_start ? ControllerEmu::Translate : ControllerEmu::DoNotTranslate;
|
|
||||||
// i18n: The START/PAUSE button on GameCube controllers
|
|
||||||
std::string ui_name = is_start ? _trans("START") : named_button;
|
|
||||||
m_buttons->AddInput(translate, named_button, std::move(ui_name));
|
|
||||||
}
|
}
|
||||||
|
// i18n: The START/PAUSE button on GameCube controllers
|
||||||
|
m_buttons->AddInput(ControllerEmu::Translate, START_BUTTON, _trans("START"));
|
||||||
|
|
||||||
// sticks
|
// sticks
|
||||||
groups.emplace_back(m_main_stick = new ControllerEmu::OctagonAnalogStick(
|
groups.emplace_back(m_main_stick = new ControllerEmu::OctagonAnalogStick(
|
||||||
"Main Stick", _trans("Control Stick"), MAIN_STICK_GATE_RADIUS));
|
MAIN_STICK_GROUP, _trans("Control Stick"), MAIN_STICK_GATE_RADIUS));
|
||||||
groups.emplace_back(m_c_stick = new ControllerEmu::OctagonAnalogStick(
|
groups.emplace_back(m_c_stick = new ControllerEmu::OctagonAnalogStick(
|
||||||
"C-Stick", _trans("C Stick"), C_STICK_GATE_RADIUS));
|
C_STICK_GROUP, _trans("C Stick"), C_STICK_GATE_RADIUS));
|
||||||
|
|
||||||
// triggers
|
// triggers
|
||||||
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
|
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(TRIGGERS_GROUP));
|
||||||
for (const char* named_trigger : named_triggers)
|
for (const char* named_trigger : {L_DIGITAL, R_DIGITAL, L_ANALOG, R_ANALOG})
|
||||||
{
|
{
|
||||||
m_triggers->AddInput(ControllerEmu::Translate, named_trigger);
|
m_triggers->AddInput(ControllerEmu::Translate, named_trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
// rumble
|
// rumble
|
||||||
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
|
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(RUMBLE_GROUP));
|
||||||
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
|
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
|
||||||
|
|
||||||
// Microphone
|
// Microphone
|
||||||
groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone")));
|
groups.emplace_back(m_mic = new ControllerEmu::Buttons(MIC_GROUP));
|
||||||
m_mic->AddInput(ControllerEmu::Translate, _trans("Button"));
|
m_mic->AddInput(ControllerEmu::Translate, _trans("Button"));
|
||||||
|
|
||||||
// dpad
|
// dpad
|
||||||
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
|
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(DPAD_GROUP));
|
||||||
for (const char* named_direction : named_directions)
|
for (const char* named_direction : named_directions)
|
||||||
{
|
{
|
||||||
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
|
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// options
|
// options
|
||||||
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
|
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(OPTIONS_GROUP));
|
||||||
m_options->AddSetting(
|
m_options->AddSetting(
|
||||||
&m_always_connected_setting,
|
&m_always_connected_setting,
|
||||||
// i18n: Treat a controller as always being connected regardless of what
|
// i18n: Treat a controller as always being connected regardless of what
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Common/Common.h"
|
||||||
|
|
||||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
||||||
|
@ -49,6 +51,31 @@ public:
|
||||||
static constexpr ControlState MAIN_STICK_GATE_RADIUS = 0.7937125;
|
static constexpr ControlState MAIN_STICK_GATE_RADIUS = 0.7937125;
|
||||||
static constexpr ControlState C_STICK_GATE_RADIUS = 0.7221375;
|
static constexpr ControlState C_STICK_GATE_RADIUS = 0.7221375;
|
||||||
|
|
||||||
|
static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
|
||||||
|
static constexpr const char* MAIN_STICK_GROUP = "Main Stick";
|
||||||
|
static constexpr const char* C_STICK_GROUP = "C-Stick";
|
||||||
|
static constexpr const char* DPAD_GROUP = _trans("D-Pad");
|
||||||
|
static constexpr const char* TRIGGERS_GROUP = _trans("Triggers");
|
||||||
|
static constexpr const char* RUMBLE_GROUP = _trans("Rumble");
|
||||||
|
static constexpr const char* MIC_GROUP = _trans("Microphone");
|
||||||
|
static constexpr const char* OPTIONS_GROUP = _trans("Options");
|
||||||
|
|
||||||
|
static constexpr const char* A_BUTTON = "A";
|
||||||
|
static constexpr const char* B_BUTTON = "B";
|
||||||
|
static constexpr const char* X_BUTTON = "X";
|
||||||
|
static constexpr const char* Y_BUTTON = "Y";
|
||||||
|
static constexpr const char* Z_BUTTON = "Z";
|
||||||
|
static constexpr const char* START_BUTTON = "Start";
|
||||||
|
|
||||||
|
// i18n: The left trigger button (labeled L on real controllers)
|
||||||
|
static constexpr const char* L_DIGITAL = _trans("L");
|
||||||
|
// i18n: The right trigger button (labeled R on real controllers)
|
||||||
|
static constexpr const char* R_DIGITAL = _trans("R");
|
||||||
|
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
|
||||||
|
static constexpr const char* L_ANALOG = _trans("L-Analog");
|
||||||
|
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
|
||||||
|
static constexpr const char* R_ANALOG = _trans("R-Analog");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ControllerEmu::Buttons* m_buttons;
|
ControllerEmu::Buttons* m_buttons;
|
||||||
ControllerEmu::AnalogStick* m_main_stick;
|
ControllerEmu::AnalogStick* m_main_stick;
|
||||||
|
|
|
@ -119,8 +119,6 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)
|
||||||
|
|
||||||
void CSIDevice_GCController::HandleMoviePadStatus(int device_number, GCPadStatus* pad_status)
|
void CSIDevice_GCController::HandleMoviePadStatus(int device_number, GCPadStatus* pad_status)
|
||||||
{
|
{
|
||||||
Movie::CallGCInputManip(pad_status, device_number);
|
|
||||||
|
|
||||||
Movie::SetPolledDevice();
|
Movie::SetPolledDevice();
|
||||||
if (NetPlay_GetInput(device_number, pad_status))
|
if (NetPlay_GetInput(device_number, pad_status))
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,34 +39,11 @@ constexpr std::array<u16, 9> classic_button_bitmasks{{
|
||||||
Classic::BUTTON_HOME,
|
Classic::BUTTON_HOME,
|
||||||
}};
|
}};
|
||||||
|
|
||||||
constexpr std::array<std::string_view, 9> classic_button_names{{
|
|
||||||
"A",
|
|
||||||
"B",
|
|
||||||
"X",
|
|
||||||
"Y",
|
|
||||||
"ZL",
|
|
||||||
"ZR",
|
|
||||||
"-",
|
|
||||||
"+",
|
|
||||||
"Home",
|
|
||||||
}};
|
|
||||||
|
|
||||||
constexpr std::array<u16, 2> classic_trigger_bitmasks{{
|
constexpr std::array<u16, 2> classic_trigger_bitmasks{{
|
||||||
Classic::TRIGGER_L,
|
Classic::TRIGGER_L,
|
||||||
Classic::TRIGGER_R,
|
Classic::TRIGGER_R,
|
||||||
}};
|
}};
|
||||||
|
|
||||||
constexpr std::array<const char*, 4> classic_trigger_names{{
|
|
||||||
// i18n: The left trigger button (labeled L on real controllers)
|
|
||||||
_trans("L"),
|
|
||||||
// i18n: The right trigger button (labeled R on real controllers)
|
|
||||||
_trans("R"),
|
|
||||||
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
|
|
||||||
_trans("L-Analog"),
|
|
||||||
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
|
|
||||||
_trans("R-Analog"),
|
|
||||||
}};
|
|
||||||
|
|
||||||
constexpr std::array<u16, 4> classic_dpad_bitmasks{{
|
constexpr std::array<u16, 4> classic_dpad_bitmasks{{
|
||||||
Classic::PAD_UP,
|
Classic::PAD_UP,
|
||||||
Classic::PAD_DOWN,
|
Classic::PAD_DOWN,
|
||||||
|
@ -77,30 +54,30 @@ constexpr std::array<u16, 4> classic_dpad_bitmasks{{
|
||||||
Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
|
Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
|
||||||
{
|
{
|
||||||
// buttons
|
// buttons
|
||||||
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
|
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
|
||||||
for (auto& button_name : classic_button_names)
|
for (auto& button_name :
|
||||||
|
{A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, ZL_BUTTON, ZR_BUTTON, MINUS_BUTTON, PLUS_BUTTON})
|
||||||
{
|
{
|
||||||
std::string_view ui_name = (button_name == "Home") ? "HOME" : button_name;
|
m_buttons->AddInput(ControllerEmu::DoNotTranslate, button_name);
|
||||||
m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(button_name),
|
|
||||||
std::string(ui_name));
|
|
||||||
}
|
}
|
||||||
|
m_buttons->AddInput(ControllerEmu::DoNotTranslate, HOME_BUTTON, "HOME");
|
||||||
|
|
||||||
// sticks
|
// sticks
|
||||||
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / CAL_STICK_RADIUS;
|
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / CAL_STICK_RADIUS;
|
||||||
groups.emplace_back(m_left_stick =
|
groups.emplace_back(m_left_stick =
|
||||||
new ControllerEmu::OctagonAnalogStick(_trans("Left Stick"), gate_radius));
|
new ControllerEmu::OctagonAnalogStick(LEFT_STICK_GROUP, gate_radius));
|
||||||
groups.emplace_back(
|
groups.emplace_back(m_right_stick =
|
||||||
m_right_stick = new ControllerEmu::OctagonAnalogStick(_trans("Right Stick"), gate_radius));
|
new ControllerEmu::OctagonAnalogStick(RIGHT_STICK_GROUP, gate_radius));
|
||||||
|
|
||||||
// triggers
|
// triggers
|
||||||
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
|
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(TRIGGERS_GROUP));
|
||||||
for (const char* trigger_name : classic_trigger_names)
|
for (const char* trigger_name : {L_DIGITAL, R_DIGITAL, L_ANALOG, R_ANALOG})
|
||||||
{
|
{
|
||||||
m_triggers->AddInput(ControllerEmu::Translate, trigger_name);
|
m_triggers->AddInput(ControllerEmu::Translate, trigger_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dpad
|
// dpad
|
||||||
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
|
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(DPAD_GROUP));
|
||||||
for (const char* named_direction : named_directions)
|
for (const char* named_direction : named_directions)
|
||||||
{
|
{
|
||||||
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
|
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
|
||||||
|
|
|
@ -216,6 +216,31 @@ public:
|
||||||
|
|
||||||
static constexpr u8 TRIGGER_RANGE = 0x1F;
|
static constexpr u8 TRIGGER_RANGE = 0x1F;
|
||||||
|
|
||||||
|
static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
|
||||||
|
static constexpr const char* LEFT_STICK_GROUP = _trans("Left Stick");
|
||||||
|
static constexpr const char* RIGHT_STICK_GROUP = _trans("Right Stick");
|
||||||
|
static constexpr const char* TRIGGERS_GROUP = _trans("Triggers");
|
||||||
|
static constexpr const char* DPAD_GROUP = _trans("D-Pad");
|
||||||
|
|
||||||
|
static constexpr const char* A_BUTTON = "A";
|
||||||
|
static constexpr const char* B_BUTTON = "B";
|
||||||
|
static constexpr const char* X_BUTTON = "X";
|
||||||
|
static constexpr const char* Y_BUTTON = "Y";
|
||||||
|
static constexpr const char* ZL_BUTTON = "ZL";
|
||||||
|
static constexpr const char* ZR_BUTTON = "ZR";
|
||||||
|
static constexpr const char* MINUS_BUTTON = "-";
|
||||||
|
static constexpr const char* PLUS_BUTTON = "+";
|
||||||
|
static constexpr const char* HOME_BUTTON = "Home";
|
||||||
|
|
||||||
|
// i18n: The left trigger button (labeled L on real controllers)
|
||||||
|
static constexpr const char* L_DIGITAL = _trans("L");
|
||||||
|
// i18n: The right trigger button (labeled R on real controllers)
|
||||||
|
static constexpr const char* R_DIGITAL = _trans("R");
|
||||||
|
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
|
||||||
|
static constexpr const char* L_ANALOG = _trans("L-Analog");
|
||||||
|
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
|
||||||
|
static constexpr const char* R_ANALOG = _trans("R-Analog");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ControllerEmu::Buttons* m_buttons;
|
ControllerEmu::Buttons* m_buttons;
|
||||||
ControllerEmu::MixedTriggers* m_triggers;
|
ControllerEmu::MixedTriggers* m_triggers;
|
||||||
|
|
|
@ -37,14 +37,13 @@ constexpr std::array<u8, 2> nunchuk_button_bitmasks{{
|
||||||
Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk"))
|
Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk"))
|
||||||
{
|
{
|
||||||
// buttons
|
// buttons
|
||||||
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
|
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
|
||||||
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "C");
|
m_buttons->AddInput(ControllerEmu::DoNotTranslate, C_BUTTON);
|
||||||
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "Z");
|
m_buttons->AddInput(ControllerEmu::DoNotTranslate, Z_BUTTON);
|
||||||
|
|
||||||
// stick
|
// stick
|
||||||
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
|
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
|
||||||
groups.emplace_back(m_stick =
|
groups.emplace_back(m_stick = new ControllerEmu::OctagonAnalogStick(STICK_GROUP, gate_radius));
|
||||||
new ControllerEmu::OctagonAnalogStick(_trans("Stick"), gate_radius));
|
|
||||||
|
|
||||||
// swing
|
// swing
|
||||||
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
|
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
|
||||||
|
@ -59,7 +58,7 @@ Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk"))
|
||||||
|
|
||||||
// accelerometer
|
// accelerometer
|
||||||
groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer(
|
groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer(
|
||||||
"IMUAccelerometer", _trans("Accelerometer")));
|
ACCELEROMETER_GROUP, _trans("Accelerometer")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Nunchuk::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
void Nunchuk::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#include "Common/Common.h"
|
||||||
|
|
||||||
#include "Core/HW/WiimoteCommon/WiimoteReport.h"
|
#include "Core/HW/WiimoteCommon/WiimoteReport.h"
|
||||||
#include "Core/HW/WiimoteEmu/Dynamics.h"
|
#include "Core/HW/WiimoteEmu/Dynamics.h"
|
||||||
#include "Core/HW/WiimoteEmu/Extension/Extension.h"
|
#include "Core/HW/WiimoteEmu/Extension/Extension.h"
|
||||||
|
@ -156,6 +158,8 @@ public:
|
||||||
|
|
||||||
ControllerEmu::ControlGroup* GetGroup(NunchukGroup group);
|
ControllerEmu::ControlGroup* GetGroup(NunchukGroup group);
|
||||||
|
|
||||||
|
void LoadDefaults(const ControllerInterface& ciface) override;
|
||||||
|
|
||||||
static constexpr u8 BUTTON_C = 0x02;
|
static constexpr u8 BUTTON_C = 0x02;
|
||||||
static constexpr u8 BUTTON_Z = 0x01;
|
static constexpr u8 BUTTON_Z = 0x01;
|
||||||
|
|
||||||
|
@ -168,7 +172,12 @@ public:
|
||||||
static constexpr u8 STICK_RADIUS = 0x7F;
|
static constexpr u8 STICK_RADIUS = 0x7F;
|
||||||
static constexpr u8 STICK_RANGE = 0xFF;
|
static constexpr u8 STICK_RANGE = 0xFF;
|
||||||
|
|
||||||
void LoadDefaults(const ControllerInterface& ciface) override;
|
static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
|
||||||
|
static constexpr const char* STICK_GROUP = _trans("Stick");
|
||||||
|
static constexpr const char* ACCELEROMETER_GROUP = "IMUAccelerometer";
|
||||||
|
|
||||||
|
static constexpr const char* C_BUTTON = "C";
|
||||||
|
static constexpr const char* Z_BUTTON = "Z";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ControllerEmu::Tilt* m_tilt;
|
ControllerEmu::Tilt* m_tilt;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "Common/Assert.h"
|
#include "Common/Assert.h"
|
||||||
|
#include "Common/Common.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
@ -64,10 +65,6 @@ static const u16 dpad_bitmasks[] = {Wiimote::PAD_UP, Wiimote::PAD_DOWN, Wiimote:
|
||||||
static const u16 dpad_sideways_bitmasks[] = {Wiimote::PAD_RIGHT, Wiimote::PAD_LEFT, Wiimote::PAD_UP,
|
static const u16 dpad_sideways_bitmasks[] = {Wiimote::PAD_RIGHT, Wiimote::PAD_LEFT, Wiimote::PAD_UP,
|
||||||
Wiimote::PAD_DOWN};
|
Wiimote::PAD_DOWN};
|
||||||
|
|
||||||
constexpr std::array<std::string_view, 7> named_buttons{
|
|
||||||
"A", "B", "1", "2", "-", "+", "Home",
|
|
||||||
};
|
|
||||||
|
|
||||||
void Wiimote::Reset()
|
void Wiimote::Reset()
|
||||||
{
|
{
|
||||||
const bool want_determinism = Core::WantsDeterminism();
|
const bool want_determinism = Core::WantsDeterminism();
|
||||||
|
@ -212,24 +209,23 @@ void Wiimote::Reset()
|
||||||
Wiimote::Wiimote(const unsigned int index) : m_index(index), m_bt_device_index(index)
|
Wiimote::Wiimote(const unsigned int index) : m_index(index), m_bt_device_index(index)
|
||||||
{
|
{
|
||||||
// Buttons
|
// Buttons
|
||||||
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
|
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
|
||||||
for (auto& named_button : named_buttons)
|
for (auto& named_button : {A_BUTTON, B_BUTTON, ONE_BUTTON, TWO_BUTTON, MINUS_BUTTON, PLUS_BUTTON})
|
||||||
{
|
{
|
||||||
std::string_view ui_name = (named_button == "Home") ? "HOME" : named_button;
|
m_buttons->AddInput(ControllerEmu::DoNotTranslate, named_button);
|
||||||
m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(named_button),
|
|
||||||
std::string(ui_name));
|
|
||||||
}
|
}
|
||||||
|
m_buttons->AddInput(ControllerEmu::DoNotTranslate, HOME_BUTTON, "HOME");
|
||||||
|
|
||||||
// Pointing (IR)
|
// Pointing (IR)
|
||||||
// i18n: "Point" refers to the action of pointing a Wii Remote.
|
// i18n: "Point" refers to the action of pointing a Wii Remote.
|
||||||
groups.emplace_back(m_ir = new ControllerEmu::Cursor("IR", _trans("Point")));
|
groups.emplace_back(m_ir = new ControllerEmu::Cursor(IR_GROUP, _trans("Point")));
|
||||||
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
|
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
|
||||||
groups.emplace_back(m_tilt = new ControllerEmu::Tilt(_trans("Tilt")));
|
groups.emplace_back(m_tilt = new ControllerEmu::Tilt(_trans("Tilt")));
|
||||||
groups.emplace_back(m_shake = new ControllerEmu::Shake(_trans("Shake")));
|
groups.emplace_back(m_shake = new ControllerEmu::Shake(_trans("Shake")));
|
||||||
groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer(
|
groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer(
|
||||||
"IMUAccelerometer", _trans("Accelerometer")));
|
ACCELEROMETER_GROUP, _trans("Accelerometer")));
|
||||||
groups.emplace_back(m_imu_gyroscope =
|
groups.emplace_back(m_imu_gyroscope =
|
||||||
new ControllerEmu::IMUGyroscope("IMUGyroscope", _trans("Gyroscope")));
|
new ControllerEmu::IMUGyroscope(GYROSCOPE_GROUP, _trans("Gyroscope")));
|
||||||
groups.emplace_back(m_imu_ir = new ControllerEmu::IMUCursor("IMUIR", _trans("Point")));
|
groups.emplace_back(m_imu_ir = new ControllerEmu::IMUCursor("IMUIR", _trans("Point")));
|
||||||
|
|
||||||
const auto fov_default =
|
const auto fov_default =
|
||||||
|
@ -273,7 +269,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index), m_bt_device_index(i
|
||||||
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
|
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));
|
||||||
|
|
||||||
// D-Pad
|
// D-Pad
|
||||||
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
|
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(DPAD_GROUP));
|
||||||
for (const char* named_direction : named_directions)
|
for (const char* named_direction : named_directions)
|
||||||
{
|
{
|
||||||
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
|
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Common/Common.h"
|
||||||
|
|
||||||
#include "Core/HW/WiimoteCommon/WiimoteReport.h"
|
#include "Core/HW/WiimoteCommon/WiimoteReport.h"
|
||||||
|
|
||||||
#include "Core/HW/WiimoteEmu/Camera.h"
|
#include "Core/HW/WiimoteEmu/Camera.h"
|
||||||
|
@ -113,6 +115,20 @@ public:
|
||||||
static constexpr u16 BUTTON_MINUS = 0x1000;
|
static constexpr u16 BUTTON_MINUS = 0x1000;
|
||||||
static constexpr u16 BUTTON_HOME = 0x8000;
|
static constexpr u16 BUTTON_HOME = 0x8000;
|
||||||
|
|
||||||
|
static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
|
||||||
|
static constexpr const char* DPAD_GROUP = _trans("D-Pad");
|
||||||
|
static constexpr const char* ACCELEROMETER_GROUP = "IMUAccelerometer";
|
||||||
|
static constexpr const char* GYROSCOPE_GROUP = "IMUGyroscope";
|
||||||
|
static constexpr const char* IR_GROUP = "IR";
|
||||||
|
|
||||||
|
static constexpr const char* A_BUTTON = "A";
|
||||||
|
static constexpr const char* B_BUTTON = "B";
|
||||||
|
static constexpr const char* ONE_BUTTON = "1";
|
||||||
|
static constexpr const char* TWO_BUTTON = "2";
|
||||||
|
static constexpr const char* MINUS_BUTTON = "-";
|
||||||
|
static constexpr const char* PLUS_BUTTON = "+";
|
||||||
|
static constexpr const char* HOME_BUTTON = "Home";
|
||||||
|
|
||||||
explicit Wiimote(unsigned int index);
|
explicit Wiimote(unsigned int index);
|
||||||
~Wiimote();
|
~Wiimote();
|
||||||
|
|
||||||
|
|
|
@ -122,9 +122,6 @@ static bool s_bPolled = false;
|
||||||
static std::mutex s_input_display_lock;
|
static std::mutex s_input_display_lock;
|
||||||
static std::string s_InputDisplay[8];
|
static std::string s_InputDisplay[8];
|
||||||
|
|
||||||
static GCManipFunction s_gc_manip_func;
|
|
||||||
static WiiManipFunction s_wii_manip_func;
|
|
||||||
|
|
||||||
static std::string s_current_file_name;
|
static std::string s_current_file_name;
|
||||||
|
|
||||||
static void GetSettings();
|
static void GetSettings();
|
||||||
|
@ -1426,28 +1423,6 @@ void SaveRecording(const std::string& filename)
|
||||||
Core::DisplayMessage(fmt::format("Failed to save {}", filename), 2000);
|
Core::DisplayMessage(fmt::format("Failed to save {}", filename), 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetGCInputManip(GCManipFunction func)
|
|
||||||
{
|
|
||||||
s_gc_manip_func = std::move(func);
|
|
||||||
}
|
|
||||||
void SetWiiInputManip(WiiManipFunction func)
|
|
||||||
{
|
|
||||||
s_wii_manip_func = std::move(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: CPU Thread
|
|
||||||
void CallGCInputManip(GCPadStatus* PadStatus, int controllerID)
|
|
||||||
{
|
|
||||||
if (s_gc_manip_func)
|
|
||||||
s_gc_manip_func(PadStatus, controllerID);
|
|
||||||
}
|
|
||||||
// NOTE: CPU Thread
|
|
||||||
void CallWiiInputManip(DataReportBuilder& rpt, int controllerID, int ext, const EncryptionKey& key)
|
|
||||||
{
|
|
||||||
if (s_wii_manip_func)
|
|
||||||
s_wii_manip_func(rpt, controllerID, ext, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: GPU Thread
|
// NOTE: GPU Thread
|
||||||
void SetGraphicsConfig()
|
void SetGraphicsConfig()
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
@ -200,14 +199,4 @@ std::string GetInputDisplay();
|
||||||
std::string GetRTCDisplay();
|
std::string GetRTCDisplay();
|
||||||
std::string GetRerecords();
|
std::string GetRerecords();
|
||||||
|
|
||||||
// Done this way to avoid mixing of core and gui code
|
|
||||||
using GCManipFunction = std::function<void(GCPadStatus*, int)>;
|
|
||||||
using WiiManipFunction = std::function<void(WiimoteCommon::DataReportBuilder&, int, int,
|
|
||||||
const WiimoteEmu::EncryptionKey&)>;
|
|
||||||
|
|
||||||
void SetGCInputManip(GCManipFunction);
|
|
||||||
void SetWiiInputManip(WiiManipFunction);
|
|
||||||
void CallGCInputManip(GCPadStatus* PadStatus, int controllerID);
|
|
||||||
void CallWiiInputManip(WiimoteCommon::DataReportBuilder& rpt, int controllerID, int ext,
|
|
||||||
const WiimoteEmu::EncryptionKey& key);
|
|
||||||
} // namespace Movie
|
} // namespace Movie
|
||||||
|
|
|
@ -403,15 +403,6 @@ void MainWindow::CreateComponents()
|
||||||
m_wii_tas_input_windows[i] = new WiiTASInputWindow(nullptr, i);
|
m_wii_tas_input_windows[i] = new WiiTASInputWindow(nullptr, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
Movie::SetGCInputManip([this](GCPadStatus* pad_status, int controller_id) {
|
|
||||||
m_gc_tas_input_windows[controller_id]->GetValues(pad_status);
|
|
||||||
});
|
|
||||||
|
|
||||||
Movie::SetWiiInputManip([this](WiimoteCommon::DataReportBuilder& rpt, int controller_id, int ext,
|
|
||||||
const WiimoteEmu::EncryptionKey& key) {
|
|
||||||
m_wii_tas_input_windows[controller_id]->GetValues(rpt, ext, key);
|
|
||||||
});
|
|
||||||
|
|
||||||
m_jit_widget = new JITWidget(this);
|
m_jit_widget = new JITWidget(this);
|
||||||
m_log_widget = new LogWidget(this);
|
m_log_widget = new LogWidget(this);
|
||||||
m_log_config_widget = new LogConfigWidget(this);
|
m_log_config_widget = new LogConfigWidget(this);
|
||||||
|
|
|
@ -13,18 +13,25 @@
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
#include "Core/HW/GCPad.h"
|
||||||
|
#include "Core/HW/GCPadEmu.h"
|
||||||
|
|
||||||
#include "DolphinQt/TAS/TASCheckBox.h"
|
#include "DolphinQt/TAS/TASCheckBox.h"
|
||||||
|
|
||||||
#include "InputCommon/GCPadStatus.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
|
#include "InputCommon/InputConfig.h"
|
||||||
|
|
||||||
GCTASInputWindow::GCTASInputWindow(QWidget* parent, int num) : TASInputWindow(parent)
|
GCTASInputWindow::GCTASInputWindow(QWidget* parent, int controller_id)
|
||||||
|
: TASInputWindow(parent), m_controller_id(controller_id)
|
||||||
{
|
{
|
||||||
setWindowTitle(tr("GameCube TAS Input %1").arg(num + 1));
|
setWindowTitle(tr("GameCube TAS Input %1").arg(controller_id + 1));
|
||||||
|
|
||||||
m_main_stick_box = CreateStickInputs(tr("Main Stick"), m_x_main_stick_value, m_y_main_stick_value,
|
m_main_stick_box = CreateStickInputs(tr("Main Stick"), GCPad::MAIN_STICK_GROUP, &m_overrider,
|
||||||
255, 255, Qt::Key_F, Qt::Key_G);
|
m_x_main_stick_value, m_y_main_stick_value, 1, 1, 255, 255,
|
||||||
m_c_stick_box = CreateStickInputs(tr("C Stick"), m_x_c_stick_value, m_y_c_stick_value, 255, 255,
|
Qt::Key_F, Qt::Key_G);
|
||||||
Qt::Key_H, Qt::Key_J);
|
m_c_stick_box =
|
||||||
|
CreateStickInputs(tr("C Stick"), GCPad::C_STICK_GROUP, &m_overrider, m_x_c_stick_value,
|
||||||
|
m_y_c_stick_value, 1, 1, 255, 255, Qt::Key_H, Qt::Key_J);
|
||||||
|
|
||||||
auto* top_layout = new QHBoxLayout;
|
auto* top_layout = new QHBoxLayout;
|
||||||
top_layout->addWidget(m_main_stick_box);
|
top_layout->addWidget(m_main_stick_box);
|
||||||
|
@ -33,27 +40,43 @@ GCTASInputWindow::GCTASInputWindow(QWidget* parent, int num) : TASInputWindow(pa
|
||||||
m_triggers_box = new QGroupBox(tr("Triggers"));
|
m_triggers_box = new QGroupBox(tr("Triggers"));
|
||||||
|
|
||||||
auto* l_trigger_layout =
|
auto* l_trigger_layout =
|
||||||
CreateSliderValuePairLayout(tr("Left"), m_l_trigger_value, 0, 255, Qt::Key_N, m_triggers_box);
|
CreateSliderValuePairLayout(tr("Left"), GCPad::TRIGGERS_GROUP, GCPad::L_ANALOG, &m_overrider,
|
||||||
auto* r_trigger_layout = CreateSliderValuePairLayout(tr("Right"), m_r_trigger_value, 0, 255,
|
m_l_trigger_value, 0, 0, 0, 255, Qt::Key_N, m_triggers_box);
|
||||||
Qt::Key_M, m_triggers_box);
|
|
||||||
|
auto* r_trigger_layout =
|
||||||
|
CreateSliderValuePairLayout(tr("Right"), GCPad::TRIGGERS_GROUP, GCPad::R_ANALOG, &m_overrider,
|
||||||
|
m_r_trigger_value, 0, 0, 0, 255, Qt::Key_M, m_triggers_box);
|
||||||
|
|
||||||
auto* triggers_layout = new QVBoxLayout;
|
auto* triggers_layout = new QVBoxLayout;
|
||||||
triggers_layout->addLayout(l_trigger_layout);
|
triggers_layout->addLayout(l_trigger_layout);
|
||||||
triggers_layout->addLayout(r_trigger_layout);
|
triggers_layout->addLayout(r_trigger_layout);
|
||||||
m_triggers_box->setLayout(triggers_layout);
|
m_triggers_box->setLayout(triggers_layout);
|
||||||
|
|
||||||
m_a_button = CreateButton(QStringLiteral("&A"));
|
m_a_button =
|
||||||
m_b_button = CreateButton(QStringLiteral("&B"));
|
CreateButton(QStringLiteral("&A"), GCPad::BUTTONS_GROUP, GCPad::A_BUTTON, &m_overrider);
|
||||||
m_x_button = CreateButton(QStringLiteral("&X"));
|
m_b_button =
|
||||||
m_y_button = CreateButton(QStringLiteral("&Y"));
|
CreateButton(QStringLiteral("&B"), GCPad::BUTTONS_GROUP, GCPad::B_BUTTON, &m_overrider);
|
||||||
m_z_button = CreateButton(QStringLiteral("&Z"));
|
m_x_button =
|
||||||
m_l_button = CreateButton(QStringLiteral("&L"));
|
CreateButton(QStringLiteral("&X"), GCPad::BUTTONS_GROUP, GCPad::X_BUTTON, &m_overrider);
|
||||||
m_r_button = CreateButton(QStringLiteral("&R"));
|
m_y_button =
|
||||||
m_start_button = CreateButton(QStringLiteral("&START"));
|
CreateButton(QStringLiteral("&Y"), GCPad::BUTTONS_GROUP, GCPad::Y_BUTTON, &m_overrider);
|
||||||
m_left_button = CreateButton(QStringLiteral("L&eft"));
|
m_z_button =
|
||||||
m_up_button = CreateButton(QStringLiteral("&Up"));
|
CreateButton(QStringLiteral("&Z"), GCPad::BUTTONS_GROUP, GCPad::Z_BUTTON, &m_overrider);
|
||||||
m_down_button = CreateButton(QStringLiteral("&Down"));
|
m_start_button = CreateButton(QStringLiteral("&START"), GCPad::BUTTONS_GROUP, GCPad::START_BUTTON,
|
||||||
m_right_button = CreateButton(QStringLiteral("R&ight"));
|
&m_overrider);
|
||||||
|
|
||||||
|
m_l_button =
|
||||||
|
CreateButton(QStringLiteral("&L"), GCPad::TRIGGERS_GROUP, GCPad::L_DIGITAL, &m_overrider);
|
||||||
|
m_r_button =
|
||||||
|
CreateButton(QStringLiteral("&R"), GCPad::TRIGGERS_GROUP, GCPad::R_DIGITAL, &m_overrider);
|
||||||
|
|
||||||
|
m_left_button =
|
||||||
|
CreateButton(QStringLiteral("L&eft"), GCPad::DPAD_GROUP, DIRECTION_LEFT, &m_overrider);
|
||||||
|
m_up_button = CreateButton(QStringLiteral("&Up"), GCPad::DPAD_GROUP, DIRECTION_UP, &m_overrider);
|
||||||
|
m_down_button =
|
||||||
|
CreateButton(QStringLiteral("&Down"), GCPad::DPAD_GROUP, DIRECTION_DOWN, &m_overrider);
|
||||||
|
m_right_button =
|
||||||
|
CreateButton(QStringLiteral("R&ight"), GCPad::DPAD_GROUP, DIRECTION_RIGHT, &m_overrider);
|
||||||
|
|
||||||
auto* buttons_layout = new QGridLayout;
|
auto* buttons_layout = new QGridLayout;
|
||||||
buttons_layout->addWidget(m_a_button, 0, 0);
|
buttons_layout->addWidget(m_a_button, 0, 0);
|
||||||
|
@ -84,40 +107,14 @@ GCTASInputWindow::GCTASInputWindow(QWidget* parent, int num) : TASInputWindow(pa
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCTASInputWindow::GetValues(GCPadStatus* pad)
|
void GCTASInputWindow::hideEvent(QHideEvent* event)
|
||||||
{
|
{
|
||||||
if (!isVisible())
|
Pad::GetConfig()->GetController(m_controller_id)->ClearInputOverrideFunction();
|
||||||
return;
|
}
|
||||||
|
|
||||||
GetButton<u16>(m_a_button, pad->button, PAD_BUTTON_A);
|
void GCTASInputWindow::showEvent(QShowEvent* event)
|
||||||
GetButton<u16>(m_b_button, pad->button, PAD_BUTTON_B);
|
{
|
||||||
GetButton<u16>(m_x_button, pad->button, PAD_BUTTON_X);
|
Pad::GetConfig()
|
||||||
GetButton<u16>(m_y_button, pad->button, PAD_BUTTON_Y);
|
->GetController(m_controller_id)
|
||||||
GetButton<u16>(m_z_button, pad->button, PAD_TRIGGER_Z);
|
->SetInputOverrideFunction(m_overrider.GetInputOverrideFunction());
|
||||||
GetButton<u16>(m_l_button, pad->button, PAD_TRIGGER_L);
|
|
||||||
GetButton<u16>(m_r_button, pad->button, PAD_TRIGGER_R);
|
|
||||||
GetButton<u16>(m_left_button, pad->button, PAD_BUTTON_LEFT);
|
|
||||||
GetButton<u16>(m_up_button, pad->button, PAD_BUTTON_UP);
|
|
||||||
GetButton<u16>(m_down_button, pad->button, PAD_BUTTON_DOWN);
|
|
||||||
GetButton<u16>(m_right_button, pad->button, PAD_BUTTON_RIGHT);
|
|
||||||
GetButton<u16>(m_start_button, pad->button, PAD_BUTTON_START);
|
|
||||||
|
|
||||||
if (m_a_button->isChecked())
|
|
||||||
pad->analogA = 0xFF;
|
|
||||||
else
|
|
||||||
pad->analogA = 0x00;
|
|
||||||
|
|
||||||
if (m_b_button->isChecked())
|
|
||||||
pad->analogB = 0xFF;
|
|
||||||
else
|
|
||||||
pad->analogB = 0x00;
|
|
||||||
|
|
||||||
GetSpinBoxU8(m_l_trigger_value, pad->triggerLeft);
|
|
||||||
GetSpinBoxU8(m_r_trigger_value, pad->triggerRight);
|
|
||||||
|
|
||||||
GetSpinBoxU8(m_x_main_stick_value, pad->stickX);
|
|
||||||
GetSpinBoxU8(m_y_main_stick_value, pad->stickY);
|
|
||||||
|
|
||||||
GetSpinBoxU8(m_x_c_stick_value, pad->substickX);
|
|
||||||
GetSpinBoxU8(m_y_c_stick_value, pad->substickY);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,25 @@
|
||||||
#include "DolphinQt/TAS/TASInputWindow.h"
|
#include "DolphinQt/TAS/TASInputWindow.h"
|
||||||
|
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
|
class QHideEvent;
|
||||||
|
class QShowEvent;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class TASCheckBox;
|
class TASCheckBox;
|
||||||
struct GCPadStatus;
|
|
||||||
|
|
||||||
class GCTASInputWindow : public TASInputWindow
|
class GCTASInputWindow : public TASInputWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GCTASInputWindow(QWidget* parent, int num);
|
explicit GCTASInputWindow(QWidget* parent, int controller_id);
|
||||||
void GetValues(GCPadStatus* pad);
|
|
||||||
|
void hideEvent(QHideEvent* event) override;
|
||||||
|
void showEvent(QShowEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int m_controller_id;
|
||||||
|
|
||||||
|
InputOverrider m_overrider;
|
||||||
|
|
||||||
TASCheckBox* m_a_button;
|
TASCheckBox* m_a_button;
|
||||||
TASCheckBox* m_b_button;
|
TASCheckBox* m_b_button;
|
||||||
TASCheckBox* m_x_button;
|
TASCheckBox* m_x_button;
|
||||||
|
|
|
@ -54,8 +54,8 @@ void IRWidget::paintEvent(QPaintEvent* event)
|
||||||
painter.drawLine(PADDING + w / 2, PADDING, PADDING + w / 2, PADDING + h);
|
painter.drawLine(PADDING + w / 2, PADDING, PADDING + w / 2, PADDING + h);
|
||||||
|
|
||||||
// convert from value space to widget space
|
// convert from value space to widget space
|
||||||
u16 x = PADDING + (w - (m_x * w) / ir_max_x);
|
u16 x = PADDING + ((m_x * w) / ir_max_x);
|
||||||
u16 y = PADDING + ((m_y * h) / ir_max_y);
|
u16 y = PADDING + (h - (m_y * h) / ir_max_y);
|
||||||
|
|
||||||
painter.drawLine(PADDING + w / 2, PADDING + h / 2, x, y);
|
painter.drawLine(PADDING + w / 2, PADDING + h / 2, x, y);
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ void IRWidget::handleMouseEvent(QMouseEvent* event)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// convert from widget space to value space
|
// convert from widget space to value space
|
||||||
int new_x = ir_max_x - (event->pos().x() * ir_max_x) / width();
|
int new_x = (event->pos().x() * ir_max_x) / width();
|
||||||
int new_y = (event->pos().y() * ir_max_y) / height();
|
int new_y = ir_max_y - (event->pos().y() * ir_max_y) / height();
|
||||||
|
|
||||||
m_x = std::max(0, std::min(static_cast<int>(ir_max_x), new_x));
|
m_x = std::max(0, std::min(static_cast<int>(ir_max_x), new_x));
|
||||||
m_y = std::max(0, std::min(static_cast<int>(ir_max_y), new_y));
|
m_y = std::max(0, std::min(static_cast<int>(ir_max_y), new_y));
|
||||||
|
|
|
@ -34,5 +34,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Should be part of class but fails to compile on mac os
|
// Should be part of class but fails to compile on mac os
|
||||||
|
static const u16 ir_min_x = 0;
|
||||||
|
static const u16 ir_min_y = 0;
|
||||||
static const u16 ir_max_x = 1023;
|
static const u16 ir_max_x = 1023;
|
||||||
static const u16 ir_max_y = 767;
|
static const u16 ir_max_y = 767;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "DolphinQt/TAS/TASInputWindow.h"
|
#include "DolphinQt/TAS/TASInputWindow.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
@ -23,7 +24,23 @@
|
||||||
#include "DolphinQt/TAS/TASCheckBox.h"
|
#include "DolphinQt/TAS/TASCheckBox.h"
|
||||||
#include "DolphinQt/TAS/TASSlider.h"
|
#include "DolphinQt/TAS/TASSlider.h"
|
||||||
|
|
||||||
#include "InputCommon/GCPadStatus.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
|
#include "InputCommon/ControllerEmu/StickGate.h"
|
||||||
|
|
||||||
|
void InputOverrider::AddFunction(std::string_view group_name, std::string_view control_name,
|
||||||
|
OverrideFunction function)
|
||||||
|
{
|
||||||
|
m_functions.emplace(std::make_pair(group_name, control_name), std::move(function));
|
||||||
|
}
|
||||||
|
|
||||||
|
ControllerEmu::InputOverrideFunction InputOverrider::GetInputOverrideFunction() const
|
||||||
|
{
|
||||||
|
return [this](std::string_view group_name, std::string_view control_name,
|
||||||
|
ControlState controller_state) {
|
||||||
|
const auto it = m_functions.find(std::make_pair(group_name, control_name));
|
||||||
|
return it != m_functions.end() ? it->second(controller_state) : std::nullopt;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
TASInputWindow::TASInputWindow(QWidget* parent) : QDialog(parent)
|
TASInputWindow::TASInputWindow(QWidget* parent) : QDialog(parent)
|
||||||
{
|
{
|
||||||
|
@ -63,13 +80,22 @@ int TASInputWindow::GetTurboReleaseFrames() const
|
||||||
return m_turbo_release_frames->value();
|
return m_turbo_release_frames->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
TASCheckBox* TASInputWindow::CreateButton(const QString& name)
|
TASCheckBox* TASInputWindow::CreateButton(const QString& text, std::string_view group_name,
|
||||||
|
std::string_view control_name, InputOverrider* overrider)
|
||||||
{
|
{
|
||||||
return new TASCheckBox(name, this);
|
TASCheckBox* checkbox = new TASCheckBox(text, this);
|
||||||
|
|
||||||
|
overrider->AddFunction(group_name, control_name, [this, checkbox](ControlState controller_state) {
|
||||||
|
return GetButton(checkbox, controller_state);
|
||||||
|
});
|
||||||
|
|
||||||
|
return checkbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGroupBox* TASInputWindow::CreateStickInputs(QString name, QSpinBox*& x_value, QSpinBox*& y_value,
|
QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_view group_name,
|
||||||
u16 max_x, u16 max_y, Qt::Key x_shortcut_key,
|
InputOverrider* overrider, QSpinBox*& x_value,
|
||||||
|
QSpinBox*& y_value, u16 min_x, u16 min_y, u16 max_x,
|
||||||
|
u16 max_y, Qt::Key x_shortcut_key,
|
||||||
Qt::Key y_shortcut_key)
|
Qt::Key y_shortcut_key)
|
||||||
{
|
{
|
||||||
const QKeySequence x_shortcut_key_sequence = QKeySequence(Qt::ALT | x_shortcut_key);
|
const QKeySequence x_shortcut_key_sequence = QKeySequence(Qt::ALT | x_shortcut_key);
|
||||||
|
@ -77,7 +103,7 @@ QGroupBox* TASInputWindow::CreateStickInputs(QString name, QSpinBox*& x_value, Q
|
||||||
|
|
||||||
auto* box =
|
auto* box =
|
||||||
new QGroupBox(QStringLiteral("%1 (%2/%3)")
|
new QGroupBox(QStringLiteral("%1 (%2/%3)")
|
||||||
.arg(name, x_shortcut_key_sequence.toString(QKeySequence::NativeText),
|
.arg(text, x_shortcut_key_sequence.toString(QKeySequence::NativeText),
|
||||||
y_shortcut_key_sequence.toString(QKeySequence::NativeText)));
|
y_shortcut_key_sequence.toString(QKeySequence::NativeText)));
|
||||||
|
|
||||||
const int x_default = static_cast<int>(std::round(max_x / 2.));
|
const int x_default = static_cast<int>(std::round(max_x / 2.));
|
||||||
|
@ -112,33 +138,72 @@ QGroupBox* TASInputWindow::CreateStickInputs(QString name, QSpinBox*& x_value, Q
|
||||||
layout->addLayout(visual_layout);
|
layout->addLayout(visual_layout);
|
||||||
box->setLayout(layout);
|
box->setLayout(layout);
|
||||||
|
|
||||||
|
overrider->AddFunction(group_name, ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE,
|
||||||
|
[this, x_value, x_default, min_x, max_x](ControlState controller_state) {
|
||||||
|
return GetSpinBox(x_value, x_default, min_x, max_x, controller_state);
|
||||||
|
});
|
||||||
|
|
||||||
|
overrider->AddFunction(group_name, ControllerEmu::ReshapableInput::Y_INPUT_OVERRIDE,
|
||||||
|
[this, y_value, y_default, min_y, max_y](ControlState controller_state) {
|
||||||
|
return GetSpinBox(y_value, y_default, min_y, max_y, controller_state);
|
||||||
|
});
|
||||||
|
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
QBoxLayout* TASInputWindow::CreateSliderValuePairLayout(QString name, QSpinBox*& value,
|
QBoxLayout* TASInputWindow::CreateSliderValuePairLayout(
|
||||||
int default_, u16 max, Qt::Key shortcut_key,
|
const QString& text, std::string_view group_name, std::string_view control_name,
|
||||||
QWidget* shortcut_widget, bool invert)
|
InputOverrider* overrider, QSpinBox*& value, u16 zero, int default_, u16 min, u16 max,
|
||||||
|
Qt::Key shortcut_key, QWidget* shortcut_widget, std::optional<ControlState> scale)
|
||||||
{
|
{
|
||||||
const QKeySequence shortcut_key_sequence = QKeySequence(Qt::ALT | shortcut_key);
|
const QKeySequence shortcut_key_sequence = QKeySequence(Qt::ALT | shortcut_key);
|
||||||
|
|
||||||
auto* label = new QLabel(QStringLiteral("%1 (%2)").arg(
|
auto* label = new QLabel(QStringLiteral("%1 (%2)").arg(
|
||||||
name, shortcut_key_sequence.toString(QKeySequence::NativeText)));
|
text, shortcut_key_sequence.toString(QKeySequence::NativeText)));
|
||||||
|
|
||||||
QBoxLayout* layout = new QHBoxLayout;
|
QBoxLayout* layout = new QHBoxLayout;
|
||||||
layout->addWidget(label);
|
layout->addWidget(label);
|
||||||
|
|
||||||
value = CreateSliderValuePair(layout, default_, max, shortcut_key_sequence, Qt::Horizontal,
|
value = CreateSliderValuePair(group_name, control_name, overrider, layout, zero, default_, min,
|
||||||
shortcut_widget, invert);
|
max, shortcut_key_sequence, Qt::Horizontal, shortcut_widget, scale);
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSpinBox* TASInputWindow::CreateSliderValuePair(
|
||||||
|
std::string_view group_name, std::string_view control_name, InputOverrider* overrider,
|
||||||
|
QBoxLayout* layout, u16 zero, int default_, u16 min, u16 max,
|
||||||
|
QKeySequence shortcut_key_sequence, Qt::Orientation orientation, QWidget* shortcut_widget,
|
||||||
|
std::optional<ControlState> scale)
|
||||||
|
{
|
||||||
|
QSpinBox* value = CreateSliderValuePair(layout, default_, max, shortcut_key_sequence, orientation,
|
||||||
|
shortcut_widget);
|
||||||
|
|
||||||
|
InputOverrider::OverrideFunction func;
|
||||||
|
if (scale)
|
||||||
|
{
|
||||||
|
func = [this, value, zero, scale](ControlState controller_state) {
|
||||||
|
return GetSpinBox(value, zero, controller_state, *scale);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
func = [this, value, zero, min, max](ControlState controller_state) {
|
||||||
|
return GetSpinBox(value, zero, min, max, controller_state);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
overrider->AddFunction(group_name, control_name, std::move(func));
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
// The shortcut_widget argument needs to specify the container widget that will be hidden/shown.
|
// The shortcut_widget argument needs to specify the container widget that will be hidden/shown.
|
||||||
// This is done to avoid ambigous shortcuts
|
// This is done to avoid ambigous shortcuts
|
||||||
QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max,
|
QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max,
|
||||||
QKeySequence shortcut_key_sequence,
|
QKeySequence shortcut_key_sequence,
|
||||||
Qt::Orientation orientation,
|
Qt::Orientation orientation,
|
||||||
QWidget* shortcut_widget, bool invert)
|
QWidget* shortcut_widget)
|
||||||
{
|
{
|
||||||
auto* value = new QSpinBox();
|
auto* value = new QSpinBox();
|
||||||
value->setRange(0, 99999);
|
value->setRange(0, 99999);
|
||||||
|
@ -151,7 +216,6 @@ QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_
|
||||||
slider->setRange(0, max);
|
slider->setRange(0, max);
|
||||||
slider->setValue(default_);
|
slider->setValue(default_);
|
||||||
slider->setFocusPolicy(Qt::ClickFocus);
|
slider->setFocusPolicy(Qt::ClickFocus);
|
||||||
slider->setInvertedAppearance(invert);
|
|
||||||
|
|
||||||
connect(slider, &QSlider::valueChanged, value, &QSpinBox::setValue);
|
connect(slider, &QSlider::valueChanged, value, &QSpinBox::setValue);
|
||||||
connect(value, qOverload<int>(&QSpinBox::valueChanged), slider, &QSlider::setValue);
|
connect(value, qOverload<int>(&QSpinBox::valueChanged), slider, &QSlider::setValue);
|
||||||
|
@ -170,10 +234,10 @@ QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename UX>
|
std::optional<ControlState> TASInputWindow::GetButton(TASCheckBox* checkbox,
|
||||||
void TASInputWindow::GetButton(TASCheckBox* checkbox, UX& buttons, UX mask)
|
ControlState controller_state)
|
||||||
{
|
{
|
||||||
const bool pressed = (buttons & mask) != 0;
|
const bool pressed = std::llround(controller_state) > 0;
|
||||||
if (m_use_controller->isChecked())
|
if (m_use_controller->isChecked())
|
||||||
{
|
{
|
||||||
if (pressed)
|
if (pressed)
|
||||||
|
@ -188,50 +252,54 @@ void TASInputWindow::GetButton(TASCheckBox* checkbox, UX& buttons, UX mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkbox->GetValue())
|
return checkbox->GetValue() ? 1.0 : 0.0;
|
||||||
buttons |= mask;
|
|
||||||
else
|
|
||||||
buttons &= ~mask;
|
|
||||||
}
|
}
|
||||||
template void TASInputWindow::GetButton<u8>(TASCheckBox* button, u8& pad, u8 mask);
|
|
||||||
template void TASInputWindow::GetButton<u16>(TASCheckBox* button, u16& pad, u16 mask);
|
|
||||||
|
|
||||||
void TASInputWindow::GetSpinBoxU8(QSpinBox* spin, u8& controller_value)
|
std::optional<ControlState> TASInputWindow::GetSpinBox(QSpinBox* spin, u16 zero, u16 min, u16 max,
|
||||||
|
ControlState controller_state)
|
||||||
{
|
{
|
||||||
|
const u16 controller_value =
|
||||||
|
ControllerEmu::EmulatedController::MapFloat<u16>(controller_state, zero, 0, max);
|
||||||
|
|
||||||
if (m_use_controller->isChecked())
|
if (m_use_controller->isChecked())
|
||||||
{
|
{
|
||||||
if (!m_spinbox_most_recent_values_u8.count(spin) ||
|
if (!m_spinbox_most_recent_values.count(spin) ||
|
||||||
m_spinbox_most_recent_values_u8[spin] != controller_value)
|
m_spinbox_most_recent_values[spin] != controller_value)
|
||||||
{
|
{
|
||||||
QueueOnObjectBlocking(spin, [spin, controller_value] { spin->setValue(controller_value); });
|
QueueOnObjectBlocking(spin, [spin, controller_value] { spin->setValue(controller_value); });
|
||||||
}
|
}
|
||||||
|
|
||||||
m_spinbox_most_recent_values_u8[spin] = controller_value;
|
m_spinbox_most_recent_values[spin] = controller_value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_spinbox_most_recent_values_u8.clear();
|
m_spinbox_most_recent_values.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
controller_value = spin->value();
|
return ControllerEmu::EmulatedController::MapToFloat<ControlState, u16>(spin->value(), zero, min,
|
||||||
|
max);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TASInputWindow::GetSpinBoxU16(QSpinBox* spin, u16& controller_value)
|
std::optional<ControlState> TASInputWindow::GetSpinBox(QSpinBox* spin, u16 zero,
|
||||||
|
ControlState controller_state,
|
||||||
|
ControlState scale)
|
||||||
{
|
{
|
||||||
|
const u16 controller_value = static_cast<u16>(std::llround(controller_state * scale + zero));
|
||||||
|
|
||||||
if (m_use_controller->isChecked())
|
if (m_use_controller->isChecked())
|
||||||
{
|
{
|
||||||
if (!m_spinbox_most_recent_values_u16.count(spin) ||
|
if (!m_spinbox_most_recent_values.count(spin) ||
|
||||||
m_spinbox_most_recent_values_u16[spin] != controller_value)
|
m_spinbox_most_recent_values[spin] != controller_value)
|
||||||
{
|
{
|
||||||
QueueOnObjectBlocking(spin, [spin, controller_value] { spin->setValue(controller_value); });
|
QueueOnObjectBlocking(spin, [spin, controller_value] { spin->setValue(controller_value); });
|
||||||
}
|
}
|
||||||
|
|
||||||
m_spinbox_most_recent_values_u16[spin] = controller_value;
|
m_spinbox_most_recent_values[spin] = controller_value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_spinbox_most_recent_values_u16.clear();
|
m_spinbox_most_recent_values.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
controller_value = spin->value();
|
return (spin->value() - zero) / scale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,18 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
|
#include <string_view>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
struct GCPadStatus;
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||||
|
#include "InputCommon/ControllerInterface/CoreDevice.h"
|
||||||
|
|
||||||
class QBoxLayout;
|
class QBoxLayout;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
class QDialog;
|
class QDialog;
|
||||||
|
@ -16,6 +23,20 @@ class QSpinBox;
|
||||||
class QString;
|
class QString;
|
||||||
class TASCheckBox;
|
class TASCheckBox;
|
||||||
|
|
||||||
|
class InputOverrider final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using OverrideFunction = std::function<std::optional<ControlState>(ControlState)>;
|
||||||
|
|
||||||
|
void AddFunction(std::string_view group_name, std::string_view control_name,
|
||||||
|
OverrideFunction function);
|
||||||
|
|
||||||
|
ControllerEmu::InputOverrideFunction GetInputOverrideFunction() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::pair<std::string_view, std::string_view>, OverrideFunction> m_functions;
|
||||||
|
};
|
||||||
|
|
||||||
class TASInputWindow : public QDialog
|
class TASInputWindow : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -26,19 +47,25 @@ public:
|
||||||
int GetTurboReleaseFrames() const;
|
int GetTurboReleaseFrames() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TASCheckBox* CreateButton(const QString& name);
|
TASCheckBox* CreateButton(const QString& text, std::string_view group_name,
|
||||||
QGroupBox* CreateStickInputs(QString name, QSpinBox*& x_value, QSpinBox*& y_value, u16 max_x,
|
std::string_view control_name, InputOverrider* overrider);
|
||||||
u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key);
|
QGroupBox* CreateStickInputs(const QString& text, std::string_view group_name,
|
||||||
QBoxLayout* CreateSliderValuePairLayout(QString name, QSpinBox*& value, int default_, u16 max,
|
InputOverrider* overrider, QSpinBox*& x_value, QSpinBox*& y_value,
|
||||||
Qt::Key shortcut_key, QWidget* shortcut_widget,
|
u16 min_x, u16 min_y, u16 max_x, u16 max_y, Qt::Key x_shortcut_key,
|
||||||
bool invert = false);
|
Qt::Key y_shortcut_key);
|
||||||
|
QBoxLayout* CreateSliderValuePairLayout(const QString& text, std::string_view group_name,
|
||||||
|
std::string_view control_name, InputOverrider* overrider,
|
||||||
|
QSpinBox*& value, u16 zero, int default_, u16 min,
|
||||||
|
u16 max, Qt::Key shortcut_key, QWidget* shortcut_widget,
|
||||||
|
std::optional<ControlState> scale = {});
|
||||||
|
QSpinBox* CreateSliderValuePair(std::string_view group_name, std::string_view control_name,
|
||||||
|
InputOverrider* overrider, QBoxLayout* layout, u16 zero,
|
||||||
|
int default_, u16 min, u16 max,
|
||||||
|
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
|
||||||
|
QWidget* shortcut_widget, std::optional<ControlState> scale = {});
|
||||||
QSpinBox* CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max,
|
QSpinBox* CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max,
|
||||||
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
|
QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
|
||||||
QWidget* shortcut_widget, bool invert = false);
|
QWidget* shortcut_widget);
|
||||||
template <typename UX>
|
|
||||||
void GetButton(TASCheckBox* button, UX& pad, UX mask);
|
|
||||||
void GetSpinBoxU8(QSpinBox* spin, u8& controller_value);
|
|
||||||
void GetSpinBoxU16(QSpinBox* spin, u16& controller_value);
|
|
||||||
|
|
||||||
QGroupBox* m_settings_box;
|
QGroupBox* m_settings_box;
|
||||||
QCheckBox* m_use_controller;
|
QCheckBox* m_use_controller;
|
||||||
|
@ -46,7 +73,12 @@ protected:
|
||||||
QSpinBox* m_turbo_release_frames;
|
QSpinBox* m_turbo_release_frames;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::optional<ControlState> GetButton(TASCheckBox* checkbox, ControlState controller_state);
|
||||||
|
std::optional<ControlState> GetSpinBox(QSpinBox* spin, u16 zero, u16 min, u16 max,
|
||||||
|
ControlState controller_state);
|
||||||
|
std::optional<ControlState> GetSpinBox(QSpinBox* spin, u16 zero, ControlState controller_state,
|
||||||
|
ControlState scale);
|
||||||
|
|
||||||
std::map<TASCheckBox*, bool> m_checkbox_set_by_controller;
|
std::map<TASCheckBox*, bool> m_checkbox_set_by_controller;
|
||||||
std::map<QSpinBox*, u8> m_spinbox_most_recent_values_u8;
|
std::map<QSpinBox*, u16> m_spinbox_most_recent_values;
|
||||||
std::map<QSpinBox*, u8> m_spinbox_most_recent_values_u16;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,18 +15,14 @@
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
#include "Common/MathUtil.h"
|
||||||
|
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/HW/WiimoteCommon/DataReport.h"
|
#include "Core/HW/Wiimote.h"
|
||||||
#include "Core/HW/WiimoteEmu/Encryption.h"
|
|
||||||
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
|
|
||||||
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
|
|
||||||
|
|
||||||
#include "Core/HW/WiimoteEmu/Extension/Classic.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/Extension/Nunchuk.h"
|
||||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||||
|
|
||||||
#include "Core/HW/WiimoteEmu/Camera.h"
|
|
||||||
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
||||||
|
|
||||||
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
|
#include "DolphinQt/QtUtils/AspectRatioWidget.h"
|
||||||
|
@ -34,6 +30,9 @@
|
||||||
#include "DolphinQt/TAS/IRWidget.h"
|
#include "DolphinQt/TAS/IRWidget.h"
|
||||||
#include "DolphinQt/TAS/TASCheckBox.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"
|
#include "InputCommon/InputConfig.h"
|
||||||
|
|
||||||
using namespace WiimoteCommon;
|
using namespace WiimoteCommon;
|
||||||
|
@ -48,21 +47,25 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
|
||||||
ir_x_shortcut_key_sequence.toString(QKeySequence::NativeText),
|
ir_x_shortcut_key_sequence.toString(QKeySequence::NativeText),
|
||||||
ir_y_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_x_center = 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_y_center = static_cast<int>(std::round(ir_max_y / 2.));
|
||||||
|
|
||||||
auto* x_layout = new QHBoxLayout;
|
auto* x_layout = new QHBoxLayout;
|
||||||
m_ir_x_value = CreateSliderValuePair(x_layout, ir_x_default, ir_max_x, ir_x_shortcut_key_sequence,
|
m_ir_x_value = CreateSliderValuePair(
|
||||||
Qt::Horizontal, m_ir_box, true);
|
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;
|
auto* y_layout = new QVBoxLayout;
|
||||||
m_ir_y_value = CreateSliderValuePair(y_layout, ir_y_default, ir_max_y, ir_y_shortcut_key_sequence,
|
m_ir_y_value = CreateSliderValuePair(
|
||||||
Qt::Vertical, m_ir_box, true);
|
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);
|
m_ir_y_value->setMaximumWidth(60);
|
||||||
|
|
||||||
auto* visual = new IRWidget(this);
|
auto* visual = new IRWidget(this);
|
||||||
visual->SetX(ir_x_default);
|
visual->SetX(ir_x_center);
|
||||||
visual->SetY(ir_y_default);
|
visual->SetY(ir_y_center);
|
||||||
|
|
||||||
connect(m_ir_x_value, qOverload<int>(&QSpinBox::valueChanged), visual, &IRWidget::SetX);
|
connect(m_ir_x_value, qOverload<int>(&QSpinBox::valueChanged), visual, &IRWidget::SetX);
|
||||||
connect(m_ir_y_value, qOverload<int>(&QSpinBox::valueChanged), visual, &IRWidget::SetY);
|
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);
|
ir_layout->addLayout(visual_layout);
|
||||||
m_ir_box->setLayout(ir_layout);
|
m_ir_box->setLayout(ir_layout);
|
||||||
|
|
||||||
m_nunchuk_stick_box = CreateStickInputs(tr("Nunchuk Stick"), m_nunchuk_stick_x_value,
|
m_nunchuk_stick_box = CreateStickInputs(
|
||||||
m_nunchuk_stick_y_value, 255, 255, Qt::Key_X, Qt::Key_Y);
|
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 =
|
m_classic_left_stick_box =
|
||||||
CreateStickInputs(tr("Left Stick"), m_classic_left_stick_x_value,
|
CreateStickInputs(tr("Left Stick"), WiimoteEmu::Classic::LEFT_STICK_GROUP,
|
||||||
m_classic_left_stick_y_value, 63, 63, Qt::Key_F, Qt::Key_G);
|
&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 =
|
m_classic_right_stick_box =
|
||||||
CreateStickInputs(tr("Right Stick"), m_classic_right_stick_x_value,
|
CreateStickInputs(tr("Right Stick"), WiimoteEmu::Classic::RIGHT_STICK_GROUP,
|
||||||
m_classic_right_stick_y_value, 31, 31, Qt::Key_Q, Qt::Key_W);
|
&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
|
// 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.
|
// 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_left_stick_box);
|
||||||
top_layout->addWidget(m_classic_right_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 =
|
auto* remote_orientation_x_layout =
|
||||||
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
||||||
CreateSliderValuePairLayout(tr("X"), m_remote_orientation_x_value, 512, 1023, Qt::Key_Q,
|
CreateSliderValuePairLayout(tr("X"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP,
|
||||||
m_remote_orientation_box);
|
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 =
|
auto* remote_orientation_y_layout =
|
||||||
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
||||||
CreateSliderValuePairLayout(tr("Y"), m_remote_orientation_y_value, 512, 1023, Qt::Key_W,
|
CreateSliderValuePairLayout(tr("Y"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP,
|
||||||
m_remote_orientation_box);
|
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 =
|
auto* remote_orientation_z_layout =
|
||||||
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
||||||
CreateSliderValuePairLayout(tr("Z"), m_remote_orientation_z_value, 616, 1023, Qt::Key_E,
|
CreateSliderValuePairLayout(tr("Z"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP,
|
||||||
m_remote_orientation_box);
|
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;
|
auto* remote_orientation_layout = new QVBoxLayout;
|
||||||
remote_orientation_layout->addLayout(remote_orientation_x_layout);
|
remote_orientation_layout->addLayout(remote_orientation_x_layout);
|
||||||
|
@ -127,15 +148,24 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
|
||||||
|
|
||||||
auto* nunchuk_orientation_x_layout =
|
auto* nunchuk_orientation_x_layout =
|
||||||
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
// 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);
|
m_nunchuk_orientation_box);
|
||||||
auto* nunchuk_orientation_y_layout =
|
auto* nunchuk_orientation_y_layout =
|
||||||
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
// 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);
|
m_nunchuk_orientation_box);
|
||||||
auto* nunchuk_orientation_z_layout =
|
auto* nunchuk_orientation_z_layout =
|
||||||
// i18n: Refers to a 3D axis (used when mapping motion controls)
|
// 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);
|
m_nunchuk_orientation_box);
|
||||||
|
|
||||||
auto* nunchuk_orientation_layout = new QVBoxLayout;
|
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_nunchuk_orientation_box->setLayout(nunchuk_orientation_layout);
|
||||||
|
|
||||||
m_triggers_box = new QGroupBox(tr("Triggers"));
|
m_triggers_box = new QGroupBox(tr("Triggers"));
|
||||||
auto* l_trigger_layout = CreateSliderValuePairLayout(tr("Left"), m_left_trigger_value, 0, 31,
|
auto* l_trigger_layout = CreateSliderValuePairLayout(
|
||||||
Qt::Key_N, m_triggers_box);
|
tr("Left"), WiimoteEmu::Classic::TRIGGERS_GROUP, WiimoteEmu::Classic::L_ANALOG,
|
||||||
auto* r_trigger_layout = CreateSliderValuePairLayout(tr("Right"), m_right_trigger_value, 0, 31,
|
&m_classic_overrider, m_left_trigger_value, 0, 0, 0, 31, Qt::Key_N, m_triggers_box);
|
||||||
Qt::Key_M, 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;
|
auto* triggers_layout = new QVBoxLayout;
|
||||||
triggers_layout->addLayout(l_trigger_layout);
|
triggers_layout->addLayout(l_trigger_layout);
|
||||||
triggers_layout->addLayout(r_trigger_layout);
|
triggers_layout->addLayout(r_trigger_layout);
|
||||||
m_triggers_box->setLayout(triggers_layout);
|
m_triggers_box->setLayout(triggers_layout);
|
||||||
|
|
||||||
m_a_button = CreateButton(QStringLiteral("&A"));
|
m_a_button = CreateButton(QStringLiteral("&A"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
|
||||||
m_b_button = CreateButton(QStringLiteral("&B"));
|
WiimoteEmu::Wiimote::A_BUTTON, &m_wiimote_overrider);
|
||||||
m_1_button = CreateButton(QStringLiteral("&1"));
|
m_b_button = CreateButton(QStringLiteral("&B"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
|
||||||
m_2_button = CreateButton(QStringLiteral("&2"));
|
WiimoteEmu::Wiimote::B_BUTTON, &m_wiimote_overrider);
|
||||||
m_plus_button = CreateButton(QStringLiteral("&+"));
|
m_1_button = CreateButton(QStringLiteral("&1"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
|
||||||
m_minus_button = CreateButton(QStringLiteral("&-"));
|
WiimoteEmu::Wiimote::ONE_BUTTON, &m_wiimote_overrider);
|
||||||
m_home_button = CreateButton(QStringLiteral("&HOME"));
|
m_2_button = CreateButton(QStringLiteral("&2"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
|
||||||
m_left_button = CreateButton(QStringLiteral("&Left"));
|
WiimoteEmu::Wiimote::TWO_BUTTON, &m_wiimote_overrider);
|
||||||
m_up_button = CreateButton(QStringLiteral("&Up"));
|
m_plus_button = CreateButton(QStringLiteral("&+"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
|
||||||
m_down_button = CreateButton(QStringLiteral("&Down"));
|
WiimoteEmu::Wiimote::PLUS_BUTTON, &m_wiimote_overrider);
|
||||||
m_right_button = CreateButton(QStringLiteral("&Right"));
|
m_minus_button = CreateButton(QStringLiteral("&-"), WiimoteEmu::Wiimote::BUTTONS_GROUP,
|
||||||
m_c_button = CreateButton(QStringLiteral("&C"));
|
WiimoteEmu::Wiimote::MINUS_BUTTON, &m_wiimote_overrider);
|
||||||
m_z_button = CreateButton(QStringLiteral("&Z"));
|
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;
|
auto* buttons_layout = new QGridLayout;
|
||||||
buttons_layout->addWidget(m_a_button, 0, 0);
|
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 = new QGroupBox(tr("Nunchuk Buttons"));
|
||||||
m_nunchuk_buttons_box->setLayout(nunchuk_buttons_layout);
|
m_nunchuk_buttons_box->setLayout(nunchuk_buttons_layout);
|
||||||
|
|
||||||
m_classic_a_button = CreateButton(QStringLiteral("&A"));
|
m_classic_a_button = CreateButton(QStringLiteral("&A"), WiimoteEmu::Classic::BUTTONS_GROUP,
|
||||||
m_classic_b_button = CreateButton(QStringLiteral("&B"));
|
WiimoteEmu::Classic::A_BUTTON, &m_classic_overrider);
|
||||||
m_classic_x_button = CreateButton(QStringLiteral("&X"));
|
m_classic_b_button = CreateButton(QStringLiteral("&B"), WiimoteEmu::Classic::BUTTONS_GROUP,
|
||||||
m_classic_y_button = CreateButton(QStringLiteral("&Y"));
|
WiimoteEmu::Classic::B_BUTTON, &m_classic_overrider);
|
||||||
m_classic_l_button = CreateButton(QStringLiteral("&L"));
|
m_classic_x_button = CreateButton(QStringLiteral("&X"), WiimoteEmu::Classic::BUTTONS_GROUP,
|
||||||
m_classic_r_button = CreateButton(QStringLiteral("&R"));
|
WiimoteEmu::Classic::X_BUTTON, &m_classic_overrider);
|
||||||
m_classic_zl_button = CreateButton(QStringLiteral("&ZL"));
|
m_classic_y_button = CreateButton(QStringLiteral("&Y"), WiimoteEmu::Classic::BUTTONS_GROUP,
|
||||||
m_classic_zr_button = CreateButton(QStringLiteral("ZR"));
|
WiimoteEmu::Classic::Y_BUTTON, &m_classic_overrider);
|
||||||
m_classic_plus_button = CreateButton(QStringLiteral("&+"));
|
m_classic_zl_button = CreateButton(QStringLiteral("&ZL"), WiimoteEmu::Classic::BUTTONS_GROUP,
|
||||||
m_classic_minus_button = CreateButton(QStringLiteral("&-"));
|
WiimoteEmu::Classic::ZL_BUTTON, &m_classic_overrider);
|
||||||
m_classic_home_button = CreateButton(QStringLiteral("&HOME"));
|
m_classic_zr_button = CreateButton(QStringLiteral("ZR"), WiimoteEmu::Classic::BUTTONS_GROUP,
|
||||||
m_classic_left_button = CreateButton(QStringLiteral("L&eft"));
|
WiimoteEmu::Classic::ZR_BUTTON, &m_classic_overrider);
|
||||||
m_classic_up_button = CreateButton(QStringLiteral("&Up"));
|
m_classic_plus_button = CreateButton(QStringLiteral("&+"), WiimoteEmu::Classic::BUTTONS_GROUP,
|
||||||
m_classic_down_button = CreateButton(QStringLiteral("&Down"));
|
WiimoteEmu::Classic::PLUS_BUTTON, &m_classic_overrider);
|
||||||
m_classic_right_button = CreateButton(QStringLiteral("R&ight"));
|
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;
|
auto* classic_buttons_layout = new QGridLayout;
|
||||||
classic_buttons_layout->addWidget(m_classic_a_button, 0, 0);
|
classic_buttons_layout->addWidget(m_classic_a_button, 0, 0);
|
||||||
|
@ -247,11 +311,9 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
|
||||||
|
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
u8 ext = 0;
|
|
||||||
if (Core::IsRunning())
|
if (Core::IsRunning())
|
||||||
{
|
{
|
||||||
ext = static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(num))
|
m_active_extension = GetWiimote()->GetActiveExtensionNumber();
|
||||||
->GetActiveExtensionNumber();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -261,16 +323,35 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
|
||||||
ini.GetIfExists("Wiimote" + std::to_string(num + 1), "Extension", &extension);
|
ini.GetIfExists("Wiimote" + std::to_string(num + 1), "Extension", &extension);
|
||||||
|
|
||||||
if (extension == "Nunchuk")
|
if (extension == "Nunchuk")
|
||||||
ext = 1;
|
m_active_extension = WiimoteEmu::ExtensionNumber::NUNCHUK;
|
||||||
if (extension == "Classic")
|
else if (extension == "Classic")
|
||||||
ext = 2;
|
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));
|
setWindowTitle(tr("Wii TAS Input %1 - Wii Remote + Nunchuk").arg(m_num + 1));
|
||||||
m_ir_box->show();
|
m_ir_box->show();
|
||||||
|
@ -284,7 +365,7 @@ void WiiTASInputWindow::UpdateExt(u8 ext)
|
||||||
m_remote_buttons_box->show();
|
m_remote_buttons_box->show();
|
||||||
m_classic_buttons_box->hide();
|
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));
|
setWindowTitle(tr("Wii TAS Input %1 - Classic Controller").arg(m_num + 1));
|
||||||
m_ir_box->hide();
|
m_ir_box->hide();
|
||||||
|
@ -314,183 +395,22 @@ void WiiTASInputWindow::UpdateExt(u8 ext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiTASInputWindow::GetValues(DataReportBuilder& rpt, int ext,
|
void WiiTASInputWindow::hideEvent(QHideEvent* event)
|
||||||
const WiimoteEmu::EncryptionKey& key)
|
|
||||||
{
|
{
|
||||||
if (!isVisible())
|
GetWiimote()->ClearInputOverrideFunction();
|
||||||
return;
|
GetExtension()->ClearInputOverrideFunction();
|
||||||
|
}
|
||||||
UpdateExt(ext);
|
|
||||||
|
void WiiTASInputWindow::showEvent(QShowEvent* event)
|
||||||
if (m_remote_buttons_box->isVisible() && rpt.HasCore())
|
{
|
||||||
{
|
WiimoteEmu::Wiimote* wiimote = GetWiimote();
|
||||||
DataReportBuilder::CoreData core;
|
|
||||||
rpt.GetCoreData(&core);
|
if (m_active_extension != WiimoteEmu::ExtensionNumber::CLASSIC)
|
||||||
|
wiimote->SetInputOverrideFunction(m_wiimote_overrider.GetInputOverrideFunction());
|
||||||
using EmuWiimote = WiimoteEmu::Wiimote;
|
|
||||||
|
if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK)
|
||||||
u16& buttons = core.hex;
|
GetExtension()->SetInputOverrideFunction(m_nunchuk_overrider.GetInputOverrideFunction());
|
||||||
GetButton<u16>(m_a_button, buttons, EmuWiimote::BUTTON_A);
|
|
||||||
GetButton<u16>(m_b_button, buttons, EmuWiimote::BUTTON_B);
|
if (m_active_extension == WiimoteEmu::ExtensionNumber::CLASSIC)
|
||||||
GetButton<u16>(m_1_button, buttons, EmuWiimote::BUTTON_ONE);
|
GetExtension()->SetInputOverrideFunction(m_classic_overrider.GetInputOverrideFunction());
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,31 +5,48 @@
|
||||||
|
|
||||||
#include "DolphinQt/TAS/TASInputWindow.h"
|
#include "DolphinQt/TAS/TASInputWindow.h"
|
||||||
|
|
||||||
namespace WiimoteCommon
|
#include "Core/HW/WiimoteEmu/ExtensionPort.h"
|
||||||
{
|
|
||||||
class DataReportBuilder;
|
class QGroupBox;
|
||||||
}
|
class QHideEvent;
|
||||||
|
class QShowEvent;
|
||||||
|
class QSpinBox;
|
||||||
|
class TASCheckBox;
|
||||||
|
|
||||||
namespace WiimoteEmu
|
namespace WiimoteEmu
|
||||||
{
|
{
|
||||||
class EncryptionKey;
|
class Extension;
|
||||||
}
|
class Wiimote;
|
||||||
|
} // namespace WiimoteEmu
|
||||||
|
|
||||||
class QGroupBox;
|
namespace ControllerEmu
|
||||||
class QSpinBox;
|
{
|
||||||
class TASCheckBox;
|
class Attachments;
|
||||||
|
}
|
||||||
|
|
||||||
class WiiTASInputWindow : public TASInputWindow
|
class WiiTASInputWindow : public TASInputWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit WiiTASInputWindow(QWidget* parent, int num);
|
explicit WiiTASInputWindow(QWidget* parent, int num);
|
||||||
void GetValues(WiimoteCommon::DataReportBuilder& rpt, int ext,
|
|
||||||
const WiimoteEmu::EncryptionKey& key);
|
void hideEvent(QHideEvent* event) override;
|
||||||
|
void showEvent(QShowEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateExt(u8 ext);
|
WiimoteEmu::Wiimote* GetWiimote();
|
||||||
|
ControllerEmu::Attachments* GetAttachments();
|
||||||
|
WiimoteEmu::Extension* GetExtension();
|
||||||
|
|
||||||
|
void UpdateExt();
|
||||||
|
|
||||||
|
WiimoteEmu::ExtensionNumber m_active_extension;
|
||||||
int m_num;
|
int m_num;
|
||||||
|
|
||||||
|
InputOverrider m_wiimote_overrider;
|
||||||
|
InputOverrider m_nunchuk_overrider;
|
||||||
|
InputOverrider m_classic_overrider;
|
||||||
|
|
||||||
TASCheckBox* m_a_button;
|
TASCheckBox* m_a_button;
|
||||||
TASCheckBox* m_b_button;
|
TASCheckBox* m_b_button;
|
||||||
TASCheckBox* m_1_button;
|
TASCheckBox* m_1_button;
|
||||||
|
|
|
@ -20,8 +20,13 @@
|
||||||
|
|
||||||
class ControllerInterface;
|
class ControllerInterface;
|
||||||
|
|
||||||
const char* const named_directions[] = {_trans("Up"), _trans("Down"), _trans("Left"),
|
constexpr const char* DIRECTION_UP = _trans("Up");
|
||||||
_trans("Right")};
|
constexpr const char* DIRECTION_DOWN = _trans("Down");
|
||||||
|
constexpr const char* DIRECTION_LEFT = _trans("Left");
|
||||||
|
constexpr const char* DIRECTION_RIGHT = _trans("Right");
|
||||||
|
|
||||||
|
constexpr const char* named_directions[] = {DIRECTION_UP, DIRECTION_DOWN, DIRECTION_LEFT,
|
||||||
|
DIRECTION_RIGHT};
|
||||||
|
|
||||||
class ControlReference;
|
class ControlReference;
|
||||||
|
|
||||||
|
@ -204,7 +209,7 @@ public:
|
||||||
|
|
||||||
std::vector<std::unique_ptr<ControlGroup>> groups;
|
std::vector<std::unique_ptr<ControlGroup>> groups;
|
||||||
|
|
||||||
// Maps a float from -1.0..+1.0 to an integer of the provided values.
|
// Maps a float from -1.0..+1.0 to an integer in the provided range.
|
||||||
template <typename T, typename F>
|
template <typename T, typename F>
|
||||||
static T MapFloat(F input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
static T MapFloat(F input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
||||||
T pos_1_value = std::numeric_limits<T>::max())
|
T pos_1_value = std::numeric_limits<T>::max())
|
||||||
|
@ -227,6 +232,21 @@ public:
|
||||||
return T(std::llround((zero_value - neg_1_value) * input_value + zero_value));
|
return T(std::llround((zero_value - neg_1_value) * input_value + zero_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The inverse of the function above.
|
||||||
|
// Maps an integer in the provided range to a float in the range -1.0..1.0.
|
||||||
|
template <typename F, typename T>
|
||||||
|
static F MapToFloat(T input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
||||||
|
T pos_1_value = std::numeric_limits<T>::max())
|
||||||
|
{
|
||||||
|
static_assert(std::is_integral<T>(), "T is only sane for int types.");
|
||||||
|
static_assert(std::is_floating_point<F>(), "F is only sane for float types.");
|
||||||
|
|
||||||
|
if (input_value >= zero_value)
|
||||||
|
return F(input_value - zero_value) / F(pos_1_value - zero_value);
|
||||||
|
else
|
||||||
|
return -F(zero_value - input_value) / F(zero_value - neg_1_value);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// TODO: Wiimote attachments actually end up using their parent controller value for this,
|
// TODO: Wiimote attachments actually end up using their parent controller value for this,
|
||||||
// so theirs won't be used (and thus shouldn't even exist).
|
// so theirs won't be used (and thus shouldn't even exist).
|
||||||
|
|
Loading…
Reference in New Issue