diff --git a/Source/Core/Core/HW/GCPadEmu.cpp b/Source/Core/Core/HW/GCPadEmu.cpp index 94f1605edb93..470d2b8c2f8c 100644 --- a/Source/Core/Core/HW/GCPadEmu.cpp +++ b/Source/Core/Core/HW/GCPadEmu.cpp @@ -36,62 +36,47 @@ static const u16 trigger_bitmasks[] = { static const u16 dpad_bitmasks[] = {PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT, 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) { // buttons - groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); - for (const char* named_button : named_buttons) + groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP)); + for (const char* named_button : {A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, Z_BUTTON}) { - const bool is_start = named_button == std::string("Start"); - 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)); + m_buttons->AddInput(ControllerEmu::DoNotTranslate, named_button); } + // i18n: The START/PAUSE button on GameCube controllers + m_buttons->AddInput(ControllerEmu::Translate, START_BUTTON, _trans("START")); // sticks 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( - "C-Stick", _trans("C Stick"), C_STICK_GATE_RADIUS)); + C_STICK_GROUP, _trans("C Stick"), C_STICK_GATE_RADIUS)); // triggers - groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers"))); - for (const char* named_trigger : named_triggers) + groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(TRIGGERS_GROUP)); + for (const char* named_trigger : {L_DIGITAL, R_DIGITAL, L_ANALOG, R_ANALOG}) { m_triggers->AddInput(ControllerEmu::Translate, named_trigger); } // 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")); // 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")); // 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) { m_dpad->AddInput(ControllerEmu::Translate, named_direction); } // 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_always_connected_setting, // i18n: Treat a controller as always being connected regardless of what diff --git a/Source/Core/Core/HW/GCPadEmu.h b/Source/Core/Core/HW/GCPadEmu.h index 912e3f417f85..66a1aee4e496 100644 --- a/Source/Core/Core/HW/GCPadEmu.h +++ b/Source/Core/Core/HW/GCPadEmu.h @@ -5,6 +5,8 @@ #include +#include "Common/Common.h" + #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/Setting/NumericSetting.h" @@ -49,6 +51,31 @@ class GCPad : public ControllerEmu::EmulatedController static constexpr ControlState MAIN_STICK_GATE_RADIUS = 0.7937125; 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: ControllerEmu::Buttons* m_buttons; ControllerEmu::AnalogStick* m_main_stick; diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp index 2672f70f63ca..aad9d33cd20c 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp @@ -119,8 +119,6 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) void CSIDevice_GCController::HandleMoviePadStatus(int device_number, GCPadStatus* pad_status) { - Movie::CallGCInputManip(pad_status, device_number); - Movie::SetPolledDevice(); if (NetPlay_GetInput(device_number, pad_status)) { diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.cpp b/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.cpp index ba4f58fb39b2..768a1d89b461 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.cpp @@ -37,34 +37,11 @@ constexpr std::array classic_button_bitmasks{{ Classic::BUTTON_HOME, }}; -constexpr std::array classic_button_names{{ - "A", - "B", - "X", - "Y", - "ZL", - "ZR", - "-", - "+", - "Home", -}}; - constexpr std::array classic_trigger_bitmasks{{ Classic::TRIGGER_L, Classic::TRIGGER_R, }}; -constexpr std::array 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 classic_dpad_bitmasks{{ Classic::PAD_UP, Classic::PAD_DOWN, @@ -75,30 +52,30 @@ constexpr std::array classic_dpad_bitmasks{{ Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller")) { // buttons - groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); - for (auto& button_name : classic_button_names) + groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP)); + 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, std::string(button_name), - std::string(ui_name)); + m_buttons->AddInput(ControllerEmu::DoNotTranslate, button_name); } + m_buttons->AddInput(ControllerEmu::DoNotTranslate, HOME_BUTTON, "HOME"); // sticks constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / CAL_STICK_RADIUS; groups.emplace_back(m_left_stick = - new ControllerEmu::OctagonAnalogStick(_trans("Left Stick"), gate_radius)); - groups.emplace_back( - m_right_stick = new ControllerEmu::OctagonAnalogStick(_trans("Right Stick"), gate_radius)); + new ControllerEmu::OctagonAnalogStick(LEFT_STICK_GROUP, gate_radius)); + groups.emplace_back(m_right_stick = + new ControllerEmu::OctagonAnalogStick(RIGHT_STICK_GROUP, gate_radius)); // triggers - groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers"))); - for (const char* trigger_name : classic_trigger_names) + groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(TRIGGERS_GROUP)); + for (const char* trigger_name : {L_DIGITAL, R_DIGITAL, L_ANALOG, R_ANALOG}) { m_triggers->AddInput(ControllerEmu::Translate, trigger_name); } // 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) { m_dpad->AddInput(ControllerEmu::Translate, named_direction); diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.h b/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.h index 8944b92f7226..6d3594a205a1 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.h +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/Classic.h @@ -215,6 +215,31 @@ class Classic : public Extension1stParty 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: ControllerEmu::Buttons* m_buttons; ControllerEmu::MixedTriggers* m_triggers; diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.cpp b/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.cpp index 5e804fd0932b..9a90ba7abc64 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.cpp @@ -35,14 +35,13 @@ constexpr std::array nunchuk_button_bitmasks{{ Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk")) { // buttons - groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); - m_buttons->AddInput(ControllerEmu::DoNotTranslate, "C"); - m_buttons->AddInput(ControllerEmu::DoNotTranslate, "Z"); + groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP)); + m_buttons->AddInput(ControllerEmu::DoNotTranslate, C_BUTTON); + m_buttons->AddInput(ControllerEmu::DoNotTranslate, Z_BUTTON); // stick constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS; - groups.emplace_back(m_stick = - new ControllerEmu::OctagonAnalogStick(_trans("Stick"), gate_radius)); + groups.emplace_back(m_stick = new ControllerEmu::OctagonAnalogStick(STICK_GROUP, gate_radius)); // swing groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing"))); @@ -57,7 +56,7 @@ Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk")) // accelerometer groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer( - "IMUAccelerometer", _trans("Accelerometer"))); + ACCELEROMETER_GROUP, _trans("Accelerometer"))); } void Nunchuk::Update() diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.h b/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.h index c3ef1d477eb7..bdb11ffe536c 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.h +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.h @@ -5,6 +5,8 @@ #include +#include "Common/Common.h" + #include "Core/HW/WiimoteCommon/WiimoteReport.h" #include "Core/HW/WiimoteEmu/Dynamics.h" #include "Core/HW/WiimoteEmu/Extension/Extension.h" @@ -155,6 +157,8 @@ class Nunchuk : public Extension1stParty ControllerEmu::ControlGroup* GetGroup(NunchukGroup group); + void LoadDefaults(const ControllerInterface& ciface) override; + static constexpr u8 BUTTON_C = 0x02; static constexpr u8 BUTTON_Z = 0x01; @@ -167,7 +171,12 @@ class Nunchuk : public Extension1stParty static constexpr u8 STICK_RADIUS = 0x7F; 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: ControllerEmu::Tilt* m_tilt; diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index dc54b9ed6db8..2fecf6f3ebb1 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -11,6 +11,7 @@ #include #include "Common/Assert.h" +#include "Common/Common.h" #include "Common/CommonTypes.h" #include "Common/Config/Config.h" #include "Common/FileUtil.h" @@ -63,10 +64,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, Wiimote::PAD_DOWN}; -constexpr std::array named_buttons{ - "A", "B", "1", "2", "-", "+", "Home", -}; - void Wiimote::Reset() { SetRumble(false); @@ -197,24 +194,23 @@ void Wiimote::Reset() Wiimote::Wiimote(const unsigned int index) : m_index(index) { // Buttons - groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons"))); - for (auto& named_button : named_buttons) + groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP)); + 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, std::string(named_button), - std::string(ui_name)); + m_buttons->AddInput(ControllerEmu::DoNotTranslate, named_button); } + m_buttons->AddInput(ControllerEmu::DoNotTranslate, HOME_BUTTON, "HOME"); // Pointing (IR) // 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_tilt = new ControllerEmu::Tilt(_trans("Tilt"))); groups.emplace_back(m_shake = new ControllerEmu::Shake(_trans("Shake"))); groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer( - "IMUAccelerometer", _trans("Accelerometer"))); + ACCELEROMETER_GROUP, _trans("Accelerometer"))); 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"))); const auto fov_default = @@ -258,7 +254,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index) m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor")); // 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) { m_dpad->AddInput(ControllerEmu::Translate, named_direction); diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index 9234fec70d98..0823ff3d179c 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -8,6 +8,8 @@ #include #include +#include "Common/Common.h" + #include "Core/HW/WiimoteCommon/WiimoteReport.h" #include "Core/HW/WiimoteEmu/Camera.h" @@ -110,6 +112,20 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon:: static constexpr u16 BUTTON_MINUS = 0x1000; 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); ~Wiimote(); diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index f988fc7e6582..eb432bd92665 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -122,9 +122,6 @@ static bool s_bPolled = false; static std::mutex s_input_display_lock; 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 void GetSettings(); @@ -1426,28 +1423,6 @@ void SaveRecording(const std::string& filename) 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 void SetGraphicsConfig() { diff --git a/Source/Core/Core/Movie.h b/Source/Core/Core/Movie.h index 25747cd8a26d..e5cc13f2bfa0 100644 --- a/Source/Core/Core/Movie.h +++ b/Source/Core/Core/Movie.h @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -200,14 +199,4 @@ std::string GetInputDisplay(); std::string GetRTCDisplay(); std::string GetRerecords(); -// Done this way to avoid mixing of core and gui code -using GCManipFunction = std::function; -using WiiManipFunction = std::function; - -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 diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 0e833a7d2cc0..5ecef8586c4a 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -405,15 +405,6 @@ void MainWindow::CreateComponents() 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_log_widget = new LogWidget(this); m_log_config_widget = new LogConfigWidget(this); diff --git a/Source/Core/DolphinQt/TAS/GCTASInputWindow.cpp b/Source/Core/DolphinQt/TAS/GCTASInputWindow.cpp index cd618f196fef..68075185d228 100644 --- a/Source/Core/DolphinQt/TAS/GCTASInputWindow.cpp +++ b/Source/Core/DolphinQt/TAS/GCTASInputWindow.cpp @@ -13,18 +13,25 @@ #include "Common/CommonTypes.h" +#include "Core/HW/GCPad.h" +#include "Core/HW/GCPadEmu.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, - 255, 255, Qt::Key_F, Qt::Key_G); - m_c_stick_box = CreateStickInputs(tr("C Stick"), m_x_c_stick_value, m_y_c_stick_value, 255, 255, - Qt::Key_H, Qt::Key_J); + m_main_stick_box = CreateStickInputs(tr("Main Stick"), GCPad::MAIN_STICK_GROUP, &m_overrider, + m_x_main_stick_value, m_y_main_stick_value, 1, 1, 255, 255, + Qt::Key_F, Qt::Key_G); + 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; 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")); auto* l_trigger_layout = - CreateSliderValuePairLayout(tr("Left"), m_l_trigger_value, 0, 255, Qt::Key_N, m_triggers_box); - auto* r_trigger_layout = CreateSliderValuePairLayout(tr("Right"), m_r_trigger_value, 0, 255, - Qt::Key_M, m_triggers_box); + CreateSliderValuePairLayout(tr("Left"), GCPad::TRIGGERS_GROUP, GCPad::L_ANALOG, &m_overrider, + m_l_trigger_value, 0, 0, 0, 255, Qt::Key_N, 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; triggers_layout->addLayout(l_trigger_layout); triggers_layout->addLayout(r_trigger_layout); m_triggers_box->setLayout(triggers_layout); - m_a_button = CreateButton(QStringLiteral("&A")); - m_b_button = CreateButton(QStringLiteral("&B")); - m_x_button = CreateButton(QStringLiteral("&X")); - m_y_button = CreateButton(QStringLiteral("&Y")); - m_z_button = CreateButton(QStringLiteral("&Z")); - m_l_button = CreateButton(QStringLiteral("&L")); - m_r_button = CreateButton(QStringLiteral("&R")); - m_start_button = CreateButton(QStringLiteral("&START")); - m_left_button = CreateButton(QStringLiteral("L&eft")); - m_up_button = CreateButton(QStringLiteral("&Up")); - m_down_button = CreateButton(QStringLiteral("&Down")); - m_right_button = CreateButton(QStringLiteral("R&ight")); + m_a_button = + CreateButton(QStringLiteral("&A"), GCPad::BUTTONS_GROUP, GCPad::A_BUTTON, &m_overrider); + m_b_button = + CreateButton(QStringLiteral("&B"), GCPad::BUTTONS_GROUP, GCPad::B_BUTTON, &m_overrider); + m_x_button = + CreateButton(QStringLiteral("&X"), GCPad::BUTTONS_GROUP, GCPad::X_BUTTON, &m_overrider); + m_y_button = + CreateButton(QStringLiteral("&Y"), GCPad::BUTTONS_GROUP, GCPad::Y_BUTTON, &m_overrider); + m_z_button = + CreateButton(QStringLiteral("&Z"), GCPad::BUTTONS_GROUP, GCPad::Z_BUTTON, &m_overrider); + m_start_button = CreateButton(QStringLiteral("&START"), GCPad::BUTTONS_GROUP, GCPad::START_BUTTON, + &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; buttons_layout->addWidget(m_a_button, 0, 0); @@ -84,40 +107,14 @@ GCTASInputWindow::GCTASInputWindow(QWidget* parent, int num) : TASInputWindow(pa setLayout(layout); } -void GCTASInputWindow::GetValues(GCPadStatus* pad) +void GCTASInputWindow::hideEvent(QHideEvent* event) +{ + Pad::GetConfig()->GetController(m_controller_id)->ClearInputOverrideFunction(); +} + +void GCTASInputWindow::showEvent(QShowEvent* event) { - if (!isVisible()) - return; - - GetButton(m_a_button, pad->button, PAD_BUTTON_A); - GetButton(m_b_button, pad->button, PAD_BUTTON_B); - GetButton(m_x_button, pad->button, PAD_BUTTON_X); - GetButton(m_y_button, pad->button, PAD_BUTTON_Y); - GetButton(m_z_button, pad->button, PAD_TRIGGER_Z); - GetButton(m_l_button, pad->button, PAD_TRIGGER_L); - GetButton(m_r_button, pad->button, PAD_TRIGGER_R); - GetButton(m_left_button, pad->button, PAD_BUTTON_LEFT); - GetButton(m_up_button, pad->button, PAD_BUTTON_UP); - GetButton(m_down_button, pad->button, PAD_BUTTON_DOWN); - GetButton(m_right_button, pad->button, PAD_BUTTON_RIGHT); - GetButton(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); + Pad::GetConfig() + ->GetController(m_controller_id) + ->SetInputOverrideFunction(m_overrider.GetInputOverrideFunction()); } diff --git a/Source/Core/DolphinQt/TAS/GCTASInputWindow.h b/Source/Core/DolphinQt/TAS/GCTASInputWindow.h index ab7e70800393..00830c0f5270 100644 --- a/Source/Core/DolphinQt/TAS/GCTASInputWindow.h +++ b/Source/Core/DolphinQt/TAS/GCTASInputWindow.h @@ -6,18 +6,25 @@ #include "DolphinQt/TAS/TASInputWindow.h" class QGroupBox; +class QHideEvent; +class QShowEvent; class QSpinBox; class TASCheckBox; -struct GCPadStatus; class GCTASInputWindow : public TASInputWindow { Q_OBJECT public: - explicit GCTASInputWindow(QWidget* parent, int num); - void GetValues(GCPadStatus* pad); + explicit GCTASInputWindow(QWidget* parent, int controller_id); + + void hideEvent(QHideEvent* event) override; + void showEvent(QShowEvent* event) override; private: + int m_controller_id; + + InputOverrider m_overrider; + TASCheckBox* m_a_button; TASCheckBox* m_b_button; TASCheckBox* m_x_button; diff --git a/Source/Core/DolphinQt/TAS/IRWidget.cpp b/Source/Core/DolphinQt/TAS/IRWidget.cpp index 992c10c90eba..7bab30186b99 100644 --- a/Source/Core/DolphinQt/TAS/IRWidget.cpp +++ b/Source/Core/DolphinQt/TAS/IRWidget.cpp @@ -54,8 +54,8 @@ void IRWidget::paintEvent(QPaintEvent* event) painter.drawLine(PADDING + w / 2, PADDING, PADDING + w / 2, PADDING + h); // convert from value space to widget space - u16 x = PADDING + (w - (m_x * w) / ir_max_x); - u16 y = PADDING + ((m_y * h) / ir_max_y); + u16 x = PADDING + ((m_x * w) / ir_max_x); + u16 y = PADDING + (h - (m_y * h) / ir_max_y); painter.drawLine(PADDING + w / 2, PADDING + h / 2, x, y); @@ -87,8 +87,8 @@ void IRWidget::handleMouseEvent(QMouseEvent* event) else { // convert from widget space to value space - int new_x = ir_max_x - (event->pos().x() * ir_max_x) / width(); - int new_y = (event->pos().y() * ir_max_y) / height(); + int new_x = (event->pos().x() * ir_max_x) / width(); + int new_y = ir_max_y - (event->pos().y() * ir_max_y) / height(); m_x = std::max(0, std::min(static_cast(ir_max_x), new_x)); m_y = std::max(0, std::min(static_cast(ir_max_y), new_y)); diff --git a/Source/Core/DolphinQt/TAS/IRWidget.h b/Source/Core/DolphinQt/TAS/IRWidget.h index b47954540339..b5681d852fc3 100644 --- a/Source/Core/DolphinQt/TAS/IRWidget.h +++ b/Source/Core/DolphinQt/TAS/IRWidget.h @@ -34,5 +34,7 @@ public slots: }; // 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_y = 767; diff --git a/Source/Core/DolphinQt/TAS/TASInputWindow.cpp b/Source/Core/DolphinQt/TAS/TASInputWindow.cpp index 771b1402fc47..0054043a8ea3 100644 --- a/Source/Core/DolphinQt/TAS/TASInputWindow.cpp +++ b/Source/Core/DolphinQt/TAS/TASInputWindow.cpp @@ -4,6 +4,7 @@ #include "DolphinQt/TAS/TASInputWindow.h" #include +#include #include #include @@ -23,7 +24,23 @@ #include "DolphinQt/TAS/TASCheckBox.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) { @@ -63,13 +80,22 @@ int TASInputWindow::GetTurboReleaseFrames() const 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, - u16 max_x, u16 max_y, Qt::Key x_shortcut_key, +QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_view group_name, + 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) { 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 = 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))); const int x_default = static_cast(std::round(max_x / 2.)); @@ -112,33 +138,72 @@ QGroupBox* TASInputWindow::CreateStickInputs(QString name, QSpinBox*& x_value, Q layout->addLayout(visual_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; } -QBoxLayout* TASInputWindow::CreateSliderValuePairLayout(QString name, QSpinBox*& value, - int default_, u16 max, Qt::Key shortcut_key, - QWidget* shortcut_widget, bool invert) +QBoxLayout* TASInputWindow::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 scale) { const QKeySequence shortcut_key_sequence = QKeySequence(Qt::ALT | shortcut_key); 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; layout->addWidget(label); - value = CreateSliderValuePair(layout, default_, max, shortcut_key_sequence, Qt::Horizontal, - shortcut_widget, invert); + value = CreateSliderValuePair(group_name, control_name, overrider, layout, zero, default_, min, + max, shortcut_key_sequence, Qt::Horizontal, shortcut_widget, scale); 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 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. // This is done to avoid ambigous shortcuts QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max, QKeySequence shortcut_key_sequence, Qt::Orientation orientation, - QWidget* shortcut_widget, bool invert) + QWidget* shortcut_widget) { auto* value = new QSpinBox(); value->setRange(0, 99999); @@ -151,7 +216,6 @@ QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_ slider->setRange(0, max); slider->setValue(default_); slider->setFocusPolicy(Qt::ClickFocus); - slider->setInvertedAppearance(invert); connect(slider, &QSlider::valueChanged, value, &QSpinBox::setValue); connect(value, qOverload(&QSpinBox::valueChanged), slider, &QSlider::setValue); @@ -170,10 +234,10 @@ QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_ return value; } -template -void TASInputWindow::GetButton(TASCheckBox* checkbox, UX& buttons, UX mask) +std::optional TASInputWindow::GetButton(TASCheckBox* checkbox, + ControlState controller_state) { - const bool pressed = (buttons & mask) != 0; + const bool pressed = std::llround(controller_state) > 0; if (m_use_controller->isChecked()) { if (pressed) @@ -188,50 +252,54 @@ void TASInputWindow::GetButton(TASCheckBox* checkbox, UX& buttons, UX mask) } } - if (checkbox->GetValue()) - buttons |= mask; - else - buttons &= ~mask; + return checkbox->GetValue() ? 1.0 : 0.0; } -template void TASInputWindow::GetButton(TASCheckBox* button, u8& pad, u8 mask); -template void TASInputWindow::GetButton(TASCheckBox* button, u16& pad, u16 mask); -void TASInputWindow::GetSpinBoxU8(QSpinBox* spin, u8& controller_value) +std::optional TASInputWindow::GetSpinBox(QSpinBox* spin, u16 zero, u16 min, u16 max, + ControlState controller_state) { + const u16 controller_value = + ControllerEmu::EmulatedController::MapFloat(controller_state, zero, 0, max); + if (m_use_controller->isChecked()) { - if (!m_spinbox_most_recent_values_u8.count(spin) || - m_spinbox_most_recent_values_u8[spin] != controller_value) + if (!m_spinbox_most_recent_values.count(spin) || + m_spinbox_most_recent_values[spin] != 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 { - m_spinbox_most_recent_values_u8.clear(); + m_spinbox_most_recent_values.clear(); } - controller_value = spin->value(); + return ControllerEmu::EmulatedController::MapToFloat(spin->value(), zero, min, + max); } -void TASInputWindow::GetSpinBoxU16(QSpinBox* spin, u16& controller_value) +std::optional TASInputWindow::GetSpinBox(QSpinBox* spin, u16 zero, + ControlState controller_state, + ControlState scale) { + const u16 controller_value = static_cast(std::llround(controller_state * scale + zero)); + if (m_use_controller->isChecked()) { - if (!m_spinbox_most_recent_values_u16.count(spin) || - m_spinbox_most_recent_values_u16[spin] != controller_value) + if (!m_spinbox_most_recent_values.count(spin) || + m_spinbox_most_recent_values[spin] != 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 { - m_spinbox_most_recent_values_u16.clear(); + m_spinbox_most_recent_values.clear(); } - controller_value = spin->value(); + return (spin->value() - zero) / scale; } diff --git a/Source/Core/DolphinQt/TAS/TASInputWindow.h b/Source/Core/DolphinQt/TAS/TASInputWindow.h index 26d6e48a00c8..e1f56e023596 100644 --- a/Source/Core/DolphinQt/TAS/TASInputWindow.h +++ b/Source/Core/DolphinQt/TAS/TASInputWindow.h @@ -3,11 +3,18 @@ #pragma once +#include +#include +#include +#include + #include #include "Common/CommonTypes.h" -struct GCPadStatus; +#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" +#include "InputCommon/ControllerInterface/CoreDevice.h" + class QBoxLayout; class QCheckBox; class QDialog; @@ -16,6 +23,20 @@ class QSpinBox; class QString; class TASCheckBox; +class InputOverrider final +{ +public: + using OverrideFunction = std::function(ControlState)>; + + void AddFunction(std::string_view group_name, std::string_view control_name, + OverrideFunction function); + + ControllerEmu::InputOverrideFunction GetInputOverrideFunction() const; + +private: + std::map, OverrideFunction> m_functions; +}; + class TASInputWindow : public QDialog { Q_OBJECT @@ -26,19 +47,25 @@ class TASInputWindow : public QDialog int GetTurboReleaseFrames() const; protected: - TASCheckBox* CreateButton(const QString& name); - QGroupBox* CreateStickInputs(QString name, QSpinBox*& x_value, QSpinBox*& y_value, u16 max_x, - u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key); - QBoxLayout* CreateSliderValuePairLayout(QString name, QSpinBox*& value, int default_, u16 max, - Qt::Key shortcut_key, QWidget* shortcut_widget, - bool invert = false); + TASCheckBox* CreateButton(const QString& text, std::string_view group_name, + std::string_view control_name, InputOverrider* overrider); + QGroupBox* CreateStickInputs(const QString& text, std::string_view group_name, + 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); + 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 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 scale = {}); QSpinBox* CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max, QKeySequence shortcut_key_sequence, Qt::Orientation orientation, - QWidget* shortcut_widget, bool invert = false); - template - void GetButton(TASCheckBox* button, UX& pad, UX mask); - void GetSpinBoxU8(QSpinBox* spin, u8& controller_value); - void GetSpinBoxU16(QSpinBox* spin, u16& controller_value); + QWidget* shortcut_widget); QGroupBox* m_settings_box; QCheckBox* m_use_controller; @@ -46,7 +73,12 @@ class TASInputWindow : public QDialog QSpinBox* m_turbo_release_frames; private: + std::optional GetButton(TASCheckBox* checkbox, ControlState controller_state); + std::optional GetSpinBox(QSpinBox* spin, u16 zero, u16 min, u16 max, + ControlState controller_state); + std::optional GetSpinBox(QSpinBox* spin, u16 zero, ControlState controller_state, + ControlState scale); + std::map m_checkbox_set_by_controller; - std::map m_spinbox_most_recent_values_u8; - std::map m_spinbox_most_recent_values_u16; + std::map m_spinbox_most_recent_values; }; diff --git a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp index 1b379c739fbc..e207ee0bb852 100644 --- a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp +++ b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp @@ -15,18 +15,14 @@ #include "Common/CommonTypes.h" #include "Common/FileUtil.h" +#include "Common/MathUtil.h" #include "Core/Core.h" -#include "Core/HW/WiimoteCommon/DataReport.h" -#include "Core/HW/WiimoteEmu/Encryption.h" -#include "Core/HW/WiimoteEmu/Extension/Classic.h" -#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h" - +#include "Core/HW/Wiimote.h" #include "Core/HW/WiimoteEmu/Extension/Classic.h" +#include "Core/HW/WiimoteEmu/Extension/Extension.h" #include "Core/HW/WiimoteEmu/Extension/Nunchuk.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" - -#include "Core/HW/WiimoteEmu/Camera.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" #include "DolphinQt/QtUtils/AspectRatioWidget.h" @@ -34,6 +30,9 @@ #include "DolphinQt/TAS/IRWidget.h" #include "DolphinQt/TAS/TASCheckBox.h" +#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h" +#include "InputCommon/ControllerEmu/ControllerEmu.h" +#include "InputCommon/ControllerEmu/StickGate.h" #include "InputCommon/InputConfig.h" using namespace WiimoteCommon; @@ -48,21 +47,25 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( ir_x_shortcut_key_sequence.toString(QKeySequence::NativeText), ir_y_shortcut_key_sequence.toString(QKeySequence::NativeText))); - const int ir_x_default = static_cast(std::round(ir_max_x / 2.)); - const int ir_y_default = static_cast(std::round(ir_max_y / 2.)); + const int ir_x_center = static_cast(std::round(ir_max_x / 2.)); + const int ir_y_center = static_cast(std::round(ir_max_y / 2.)); auto* x_layout = new QHBoxLayout; - m_ir_x_value = CreateSliderValuePair(x_layout, ir_x_default, ir_max_x, ir_x_shortcut_key_sequence, - Qt::Horizontal, m_ir_box, true); + m_ir_x_value = CreateSliderValuePair( + WiimoteEmu::Wiimote::IR_GROUP, ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE, + &m_wiimote_overrider, x_layout, ir_x_center, ir_x_center, ir_min_x, ir_max_x, + ir_x_shortcut_key_sequence, Qt::Horizontal, m_ir_box); auto* y_layout = new QVBoxLayout; - m_ir_y_value = CreateSliderValuePair(y_layout, ir_y_default, ir_max_y, ir_y_shortcut_key_sequence, - Qt::Vertical, m_ir_box, true); + m_ir_y_value = CreateSliderValuePair( + WiimoteEmu::Wiimote::IR_GROUP, ControllerEmu::ReshapableInput::Y_INPUT_OVERRIDE, + &m_wiimote_overrider, y_layout, ir_y_center, ir_y_center, ir_min_y, ir_max_y, + ir_y_shortcut_key_sequence, Qt::Vertical, m_ir_box); m_ir_y_value->setMaximumWidth(60); auto* visual = new IRWidget(this); - visual->SetX(ir_x_default); - visual->SetY(ir_y_default); + visual->SetX(ir_x_center); + visual->SetY(ir_y_center); connect(m_ir_x_value, qOverload(&QSpinBox::valueChanged), visual, &IRWidget::SetX); connect(m_ir_y_value, qOverload(&QSpinBox::valueChanged), visual, &IRWidget::SetY); @@ -80,16 +83,19 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( ir_layout->addLayout(visual_layout); m_ir_box->setLayout(ir_layout); - m_nunchuk_stick_box = CreateStickInputs(tr("Nunchuk Stick"), m_nunchuk_stick_x_value, - m_nunchuk_stick_y_value, 255, 255, Qt::Key_X, Qt::Key_Y); + m_nunchuk_stick_box = CreateStickInputs( + tr("Nunchuk Stick"), WiimoteEmu::Nunchuk::STICK_GROUP, &m_nunchuk_overrider, + m_nunchuk_stick_x_value, m_nunchuk_stick_y_value, 0, 0, 255, 255, Qt::Key_X, Qt::Key_Y); m_classic_left_stick_box = - CreateStickInputs(tr("Left Stick"), m_classic_left_stick_x_value, - m_classic_left_stick_y_value, 63, 63, Qt::Key_F, Qt::Key_G); + CreateStickInputs(tr("Left Stick"), WiimoteEmu::Classic::LEFT_STICK_GROUP, + &m_classic_overrider, m_classic_left_stick_x_value, + m_classic_left_stick_y_value, 0, 0, 63, 63, Qt::Key_F, Qt::Key_G); m_classic_right_stick_box = - CreateStickInputs(tr("Right Stick"), m_classic_right_stick_x_value, - m_classic_right_stick_y_value, 31, 31, Qt::Key_Q, Qt::Key_W); + CreateStickInputs(tr("Right Stick"), WiimoteEmu::Classic::RIGHT_STICK_GROUP, + &m_classic_overrider, m_classic_right_stick_x_value, + m_classic_right_stick_y_value, 0, 0, 31, 31, Qt::Key_Q, Qt::Key_W); // Need to enforce the same minimum width because otherwise the different lengths in the labels // used on the QGroupBox will cause the StickWidgets to have different sizes. @@ -104,18 +110,33 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( top_layout->addWidget(m_classic_left_stick_box); top_layout->addWidget(m_classic_right_stick_box); + constexpr u16 ACCEL_ZERO_G = WiimoteEmu::Wiimote::ACCEL_ZERO_G << 2; + constexpr u16 ACCEL_ONE_G = WiimoteEmu::Wiimote::ACCEL_ONE_G << 2; + constexpr u16 ACCEL_MIN = 0; + constexpr u16 ACCEL_MAX = (1 << 10) - 1; + constexpr double ACCEL_SCALE = (ACCEL_ONE_G - ACCEL_ZERO_G) / MathUtil::GRAVITY_ACCELERATION; + auto* remote_orientation_x_layout = // i18n: Refers to a 3D axis (used when mapping motion controls) - CreateSliderValuePairLayout(tr("X"), m_remote_orientation_x_value, 512, 1023, Qt::Key_Q, - m_remote_orientation_box); + CreateSliderValuePairLayout(tr("X"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP, + ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE, + &m_wiimote_overrider, m_remote_orientation_x_value, ACCEL_ZERO_G, + ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_Q, + m_remote_orientation_box, ACCEL_SCALE); auto* remote_orientation_y_layout = // i18n: Refers to a 3D axis (used when mapping motion controls) - CreateSliderValuePairLayout(tr("Y"), m_remote_orientation_y_value, 512, 1023, Qt::Key_W, - m_remote_orientation_box); + CreateSliderValuePairLayout(tr("Y"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP, + ControllerEmu::ReshapableInput::Y_INPUT_OVERRIDE, + &m_wiimote_overrider, m_remote_orientation_y_value, ACCEL_ZERO_G, + ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_W, + m_remote_orientation_box, ACCEL_SCALE); auto* remote_orientation_z_layout = // i18n: Refers to a 3D axis (used when mapping motion controls) - CreateSliderValuePairLayout(tr("Z"), m_remote_orientation_z_value, 616, 1023, Qt::Key_E, - m_remote_orientation_box); + CreateSliderValuePairLayout(tr("Z"), WiimoteEmu::Wiimote::ACCELEROMETER_GROUP, + ControllerEmu::ReshapableInput::Z_INPUT_OVERRIDE, + &m_wiimote_overrider, m_remote_orientation_z_value, ACCEL_ZERO_G, + ACCEL_ONE_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_E, + m_remote_orientation_box, ACCEL_SCALE); auto* remote_orientation_layout = new QVBoxLayout; remote_orientation_layout->addLayout(remote_orientation_x_layout); @@ -127,15 +148,24 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( auto* nunchuk_orientation_x_layout = // i18n: Refers to a 3D axis (used when mapping motion controls) - CreateSliderValuePairLayout(tr("X"), m_nunchuk_orientation_x_value, 512, 1023, Qt::Key_I, + CreateSliderValuePairLayout(tr("X"), WiimoteEmu::Nunchuk::ACCELEROMETER_GROUP, + ControllerEmu::ReshapableInput::X_INPUT_OVERRIDE, + &m_nunchuk_overrider, m_nunchuk_orientation_x_value, ACCEL_ZERO_G, + ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_I, m_nunchuk_orientation_box); auto* nunchuk_orientation_y_layout = // i18n: Refers to a 3D axis (used when mapping motion controls) - CreateSliderValuePairLayout(tr("Y"), m_nunchuk_orientation_y_value, 512, 1023, Qt::Key_O, + CreateSliderValuePairLayout(tr("Y"), WiimoteEmu::Nunchuk::ACCELEROMETER_GROUP, + ControllerEmu::ReshapableInput::Y_INPUT_OVERRIDE, + &m_nunchuk_overrider, m_nunchuk_orientation_y_value, ACCEL_ZERO_G, + ACCEL_ZERO_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_O, m_nunchuk_orientation_box); auto* nunchuk_orientation_z_layout = // i18n: Refers to a 3D axis (used when mapping motion controls) - CreateSliderValuePairLayout(tr("Z"), m_nunchuk_orientation_z_value, 512, 1023, Qt::Key_P, + CreateSliderValuePairLayout(tr("Z"), WiimoteEmu::Nunchuk::ACCELEROMETER_GROUP, + ControllerEmu::ReshapableInput::Z_INPUT_OVERRIDE, + &m_nunchuk_overrider, m_nunchuk_orientation_z_value, ACCEL_ZERO_G, + ACCEL_ONE_G, ACCEL_MIN, ACCEL_MAX, Qt::Key_P, m_nunchuk_orientation_box); auto* nunchuk_orientation_layout = new QVBoxLayout; @@ -145,29 +175,46 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( m_nunchuk_orientation_box->setLayout(nunchuk_orientation_layout); m_triggers_box = new QGroupBox(tr("Triggers")); - auto* l_trigger_layout = CreateSliderValuePairLayout(tr("Left"), m_left_trigger_value, 0, 31, - Qt::Key_N, m_triggers_box); - auto* r_trigger_layout = CreateSliderValuePairLayout(tr("Right"), m_right_trigger_value, 0, 31, - Qt::Key_M, m_triggers_box); + auto* l_trigger_layout = CreateSliderValuePairLayout( + tr("Left"), WiimoteEmu::Classic::TRIGGERS_GROUP, WiimoteEmu::Classic::L_ANALOG, + &m_classic_overrider, m_left_trigger_value, 0, 0, 0, 31, Qt::Key_N, m_triggers_box); + auto* r_trigger_layout = CreateSliderValuePairLayout( + tr("Right"), WiimoteEmu::Classic::TRIGGERS_GROUP, WiimoteEmu::Classic::R_ANALOG, + &m_classic_overrider, m_right_trigger_value, 0, 0, 0, 31, Qt::Key_M, m_triggers_box); auto* triggers_layout = new QVBoxLayout; triggers_layout->addLayout(l_trigger_layout); triggers_layout->addLayout(r_trigger_layout); m_triggers_box->setLayout(triggers_layout); - m_a_button = CreateButton(QStringLiteral("&A")); - m_b_button = CreateButton(QStringLiteral("&B")); - m_1_button = CreateButton(QStringLiteral("&1")); - m_2_button = CreateButton(QStringLiteral("&2")); - m_plus_button = CreateButton(QStringLiteral("&+")); - m_minus_button = CreateButton(QStringLiteral("&-")); - m_home_button = CreateButton(QStringLiteral("&HOME")); - m_left_button = CreateButton(QStringLiteral("&Left")); - m_up_button = CreateButton(QStringLiteral("&Up")); - m_down_button = CreateButton(QStringLiteral("&Down")); - m_right_button = CreateButton(QStringLiteral("&Right")); - m_c_button = CreateButton(QStringLiteral("&C")); - m_z_button = CreateButton(QStringLiteral("&Z")); + m_a_button = CreateButton(QStringLiteral("&A"), WiimoteEmu::Wiimote::BUTTONS_GROUP, + WiimoteEmu::Wiimote::A_BUTTON, &m_wiimote_overrider); + m_b_button = CreateButton(QStringLiteral("&B"), WiimoteEmu::Wiimote::BUTTONS_GROUP, + WiimoteEmu::Wiimote::B_BUTTON, &m_wiimote_overrider); + m_1_button = CreateButton(QStringLiteral("&1"), WiimoteEmu::Wiimote::BUTTONS_GROUP, + WiimoteEmu::Wiimote::ONE_BUTTON, &m_wiimote_overrider); + m_2_button = CreateButton(QStringLiteral("&2"), WiimoteEmu::Wiimote::BUTTONS_GROUP, + WiimoteEmu::Wiimote::TWO_BUTTON, &m_wiimote_overrider); + m_plus_button = CreateButton(QStringLiteral("&+"), WiimoteEmu::Wiimote::BUTTONS_GROUP, + WiimoteEmu::Wiimote::PLUS_BUTTON, &m_wiimote_overrider); + m_minus_button = CreateButton(QStringLiteral("&-"), WiimoteEmu::Wiimote::BUTTONS_GROUP, + WiimoteEmu::Wiimote::MINUS_BUTTON, &m_wiimote_overrider); + m_home_button = CreateButton(QStringLiteral("&HOME"), WiimoteEmu::Wiimote::BUTTONS_GROUP, + WiimoteEmu::Wiimote::HOME_BUTTON, &m_wiimote_overrider); + + m_left_button = CreateButton(QStringLiteral("&Left"), WiimoteEmu::Wiimote::DPAD_GROUP, + DIRECTION_LEFT, &m_wiimote_overrider); + m_up_button = CreateButton(QStringLiteral("&Up"), WiimoteEmu::Wiimote::DPAD_GROUP, DIRECTION_UP, + &m_wiimote_overrider); + m_down_button = CreateButton(QStringLiteral("&Down"), WiimoteEmu::Wiimote::DPAD_GROUP, + DIRECTION_DOWN, &m_wiimote_overrider); + m_right_button = CreateButton(QStringLiteral("&Right"), WiimoteEmu::Wiimote::DPAD_GROUP, + DIRECTION_RIGHT, &m_wiimote_overrider); + + m_c_button = CreateButton(QStringLiteral("&C"), WiimoteEmu::Nunchuk::BUTTONS_GROUP, + WiimoteEmu::Nunchuk::C_BUTTON, &m_nunchuk_overrider); + m_z_button = CreateButton(QStringLiteral("&Z"), WiimoteEmu::Nunchuk::BUTTONS_GROUP, + WiimoteEmu::Nunchuk::Z_BUTTON, &m_nunchuk_overrider); auto* buttons_layout = new QGridLayout; buttons_layout->addWidget(m_a_button, 0, 0); @@ -196,21 +243,38 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( m_nunchuk_buttons_box = new QGroupBox(tr("Nunchuk Buttons")); m_nunchuk_buttons_box->setLayout(nunchuk_buttons_layout); - m_classic_a_button = CreateButton(QStringLiteral("&A")); - m_classic_b_button = CreateButton(QStringLiteral("&B")); - m_classic_x_button = CreateButton(QStringLiteral("&X")); - m_classic_y_button = CreateButton(QStringLiteral("&Y")); - m_classic_l_button = CreateButton(QStringLiteral("&L")); - m_classic_r_button = CreateButton(QStringLiteral("&R")); - m_classic_zl_button = CreateButton(QStringLiteral("&ZL")); - m_classic_zr_button = CreateButton(QStringLiteral("ZR")); - m_classic_plus_button = CreateButton(QStringLiteral("&+")); - m_classic_minus_button = CreateButton(QStringLiteral("&-")); - m_classic_home_button = CreateButton(QStringLiteral("&HOME")); - m_classic_left_button = CreateButton(QStringLiteral("L&eft")); - m_classic_up_button = CreateButton(QStringLiteral("&Up")); - m_classic_down_button = CreateButton(QStringLiteral("&Down")); - m_classic_right_button = CreateButton(QStringLiteral("R&ight")); + m_classic_a_button = CreateButton(QStringLiteral("&A"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::A_BUTTON, &m_classic_overrider); + m_classic_b_button = CreateButton(QStringLiteral("&B"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::B_BUTTON, &m_classic_overrider); + m_classic_x_button = CreateButton(QStringLiteral("&X"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::X_BUTTON, &m_classic_overrider); + m_classic_y_button = CreateButton(QStringLiteral("&Y"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::Y_BUTTON, &m_classic_overrider); + m_classic_zl_button = CreateButton(QStringLiteral("&ZL"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::ZL_BUTTON, &m_classic_overrider); + m_classic_zr_button = CreateButton(QStringLiteral("ZR"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::ZR_BUTTON, &m_classic_overrider); + m_classic_plus_button = CreateButton(QStringLiteral("&+"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::PLUS_BUTTON, &m_classic_overrider); + m_classic_minus_button = CreateButton(QStringLiteral("&-"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::MINUS_BUTTON, &m_classic_overrider); + m_classic_home_button = CreateButton(QStringLiteral("&HOME"), WiimoteEmu::Classic::BUTTONS_GROUP, + WiimoteEmu::Classic::HOME_BUTTON, &m_classic_overrider); + + m_classic_l_button = CreateButton(QStringLiteral("&L"), WiimoteEmu::Classic::TRIGGERS_GROUP, + WiimoteEmu::Classic::L_DIGITAL, &m_classic_overrider); + m_classic_r_button = CreateButton(QStringLiteral("&R"), WiimoteEmu::Classic::TRIGGERS_GROUP, + WiimoteEmu::Classic::R_DIGITAL, &m_classic_overrider); + + m_classic_left_button = CreateButton(QStringLiteral("L&eft"), WiimoteEmu::Classic::DPAD_GROUP, + DIRECTION_LEFT, &m_classic_overrider); + m_classic_up_button = CreateButton(QStringLiteral("&Up"), WiimoteEmu::Classic::DPAD_GROUP, + DIRECTION_UP, &m_classic_overrider); + m_classic_down_button = CreateButton(QStringLiteral("&Down"), WiimoteEmu::Classic::DPAD_GROUP, + DIRECTION_DOWN, &m_classic_overrider); + m_classic_right_button = CreateButton(QStringLiteral("R&ight"), WiimoteEmu::Classic::DPAD_GROUP, + DIRECTION_RIGHT, &m_classic_overrider); auto* classic_buttons_layout = new QGridLayout; classic_buttons_layout->addWidget(m_classic_a_button, 0, 0); @@ -247,11 +311,9 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( setLayout(layout); - u8 ext = 0; if (Core::IsRunning()) { - ext = static_cast(Wiimote::GetConfig()->GetController(num)) - ->GetActiveExtensionNumber(); + m_active_extension = GetWiimote()->GetActiveExtensionNumber(); } else { @@ -261,16 +323,35 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( ini.GetIfExists("Wiimote" + std::to_string(num + 1), "Extension", &extension); if (extension == "Nunchuk") - ext = 1; - if (extension == "Classic") - ext = 2; + m_active_extension = WiimoteEmu::ExtensionNumber::NUNCHUK; + else if (extension == "Classic") + m_active_extension = WiimoteEmu::ExtensionNumber::CLASSIC; + else + m_active_extension = WiimoteEmu::ExtensionNumber::NONE; } - UpdateExt(ext); + UpdateExt(); } -void WiiTASInputWindow::UpdateExt(u8 ext) +WiimoteEmu::Wiimote* WiiTASInputWindow::GetWiimote() { - if (ext == 1) + return static_cast(Wiimote::GetConfig()->GetController(m_num)); +} + +ControllerEmu::Attachments* WiiTASInputWindow::GetAttachments() +{ + return static_cast( + GetWiimote()->GetWiimoteGroup(WiimoteEmu::WiimoteGroup::Attachments)); +} + +WiimoteEmu::Extension* WiiTASInputWindow::GetExtension() +{ + return static_cast( + GetAttachments()->GetAttachmentList()[m_active_extension].get()); +} + +void WiiTASInputWindow::UpdateExt() +{ + if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK) { setWindowTitle(tr("Wii TAS Input %1 - Wii Remote + Nunchuk").arg(m_num + 1)); m_ir_box->show(); @@ -284,7 +365,7 @@ void WiiTASInputWindow::UpdateExt(u8 ext) m_remote_buttons_box->show(); m_classic_buttons_box->hide(); } - else if (ext == 2) + else if (m_active_extension == WiimoteEmu::ExtensionNumber::CLASSIC) { setWindowTitle(tr("Wii TAS Input %1 - Classic Controller").arg(m_num + 1)); m_ir_box->hide(); @@ -314,183 +395,22 @@ void WiiTASInputWindow::UpdateExt(u8 ext) } } -void WiiTASInputWindow::GetValues(DataReportBuilder& rpt, int ext, - const WiimoteEmu::EncryptionKey& key) +void WiiTASInputWindow::hideEvent(QHideEvent* event) { - if (!isVisible()) - return; - - UpdateExt(ext); - - if (m_remote_buttons_box->isVisible() && rpt.HasCore()) - { - DataReportBuilder::CoreData core; - rpt.GetCoreData(&core); - - using EmuWiimote = WiimoteEmu::Wiimote; - - u16& buttons = core.hex; - GetButton(m_a_button, buttons, EmuWiimote::BUTTON_A); - GetButton(m_b_button, buttons, EmuWiimote::BUTTON_B); - GetButton(m_1_button, buttons, EmuWiimote::BUTTON_ONE); - GetButton(m_2_button, buttons, EmuWiimote::BUTTON_TWO); - GetButton(m_plus_button, buttons, EmuWiimote::BUTTON_PLUS); - GetButton(m_minus_button, buttons, EmuWiimote::BUTTON_MINUS); - GetButton(m_home_button, buttons, EmuWiimote::BUTTON_HOME); - GetButton(m_left_button, buttons, EmuWiimote::PAD_LEFT); - GetButton(m_up_button, buttons, EmuWiimote::PAD_UP); - GetButton(m_down_button, buttons, EmuWiimote::PAD_DOWN); - GetButton(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 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(ir_data); - for (int i = 0; i < 2; ++i) - { - if (x[i * 2] < 1024 && y < 768) - { - ir_basic[i].x1 = static_cast(x[i * 2]); - ir_basic[i].x1hi = x[i * 2] >> 8; - - ir_basic[i].y1 = static_cast(y); - ir_basic[i].y1hi = y >> 8; - } - if (x[i * 2 + 1] < 1024 && y < 768) - { - ir_basic[i].x2 = static_cast(x[i * 2 + 1]); - ir_basic[i].x2hi = x[i * 2 + 1] >> 8; - - ir_basic[i].y2 = static_cast(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(ir_data); - for (size_t i = 0; i < x.size(); ++i) - { - if (x[i] < 1024 && y < 768) - { - ir_extended[i].x = static_cast(x[i]); - ir_extended[i].xhi = x[i] >> 8; - - ir_extended[i].y = static_cast(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(ext_data); - - GetSpinBoxU8(m_nunchuk_stick_x_value, nunchuk.jx); - GetSpinBoxU8(m_nunchuk_stick_y_value, nunchuk.jy); + GetWiimote()->ClearInputOverrideFunction(); + GetExtension()->ClearInputOverrideFunction(); +} - 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); +void WiiTASInputWindow::showEvent(QShowEvent* event) +{ + WiimoteEmu::Wiimote* wiimote = GetWiimote(); - u8 bt = nunchuk.GetButtons(); - GetButton(m_c_button, bt, WiimoteEmu::Nunchuk::BUTTON_C); - GetButton(m_z_button, bt, WiimoteEmu::Nunchuk::BUTTON_Z); - nunchuk.SetButtons(bt); + if (m_active_extension != WiimoteEmu::ExtensionNumber::CLASSIC) + wiimote->SetInputOverrideFunction(m_wiimote_overrider.GetInputOverrideFunction()); - key.Encrypt(reinterpret_cast(&nunchuk), 0, sizeof(nunchuk)); - } + if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK) + GetExtension()->SetInputOverrideFunction(m_nunchuk_overrider.GetInputOverrideFunction()); - if (m_classic_left_stick_box->isVisible()) - { - u8* const ext_data = rpt.GetExtDataPtr(); - - auto& cc = *reinterpret_cast(ext_data); - key.Decrypt(reinterpret_cast(&cc), 0, sizeof(cc)); - - u16 bt = cc.GetButtons(); - GetButton(m_classic_a_button, bt, WiimoteEmu::Classic::BUTTON_A); - GetButton(m_classic_b_button, bt, WiimoteEmu::Classic::BUTTON_B); - GetButton(m_classic_x_button, bt, WiimoteEmu::Classic::BUTTON_X); - GetButton(m_classic_y_button, bt, WiimoteEmu::Classic::BUTTON_Y); - GetButton(m_classic_plus_button, bt, WiimoteEmu::Classic::BUTTON_PLUS); - GetButton(m_classic_minus_button, bt, WiimoteEmu::Classic::BUTTON_MINUS); - GetButton(m_classic_l_button, bt, WiimoteEmu::Classic::TRIGGER_L); - GetButton(m_classic_r_button, bt, WiimoteEmu::Classic::TRIGGER_R); - GetButton(m_classic_zl_button, bt, WiimoteEmu::Classic::BUTTON_ZL); - GetButton(m_classic_zr_button, bt, WiimoteEmu::Classic::BUTTON_ZR); - GetButton(m_classic_home_button, bt, WiimoteEmu::Classic::BUTTON_HOME); - GetButton(m_classic_left_button, bt, WiimoteEmu::Classic::PAD_LEFT); - GetButton(m_classic_up_button, bt, WiimoteEmu::Classic::PAD_UP); - GetButton(m_classic_down_button, bt, WiimoteEmu::Classic::PAD_DOWN); - GetButton(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(&cc), 0, sizeof(cc)); - } + if (m_active_extension == WiimoteEmu::ExtensionNumber::CLASSIC) + GetExtension()->SetInputOverrideFunction(m_classic_overrider.GetInputOverrideFunction()); } diff --git a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h index 911322a649c7..a521301a602c 100644 --- a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h +++ b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h @@ -5,31 +5,48 @@ #include "DolphinQt/TAS/TASInputWindow.h" -namespace WiimoteCommon -{ -class DataReportBuilder; -} - -namespace WiimoteEmu -{ -class EncryptionKey; -} +#include "Core/HW/WiimoteEmu/ExtensionPort.h" class QGroupBox; +class QHideEvent; +class QShowEvent; class QSpinBox; class TASCheckBox; +namespace WiimoteEmu +{ +class Extension; +class Wiimote; +} // namespace WiimoteEmu + +namespace ControllerEmu +{ +class Attachments; +} + class WiiTASInputWindow : public TASInputWindow { Q_OBJECT public: 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: - void UpdateExt(u8 ext); + WiimoteEmu::Wiimote* GetWiimote(); + ControllerEmu::Attachments* GetAttachments(); + WiimoteEmu::Extension* GetExtension(); + + void UpdateExt(); + + WiimoteEmu::ExtensionNumber m_active_extension; int m_num; + + InputOverrider m_wiimote_overrider; + InputOverrider m_nunchuk_overrider; + InputOverrider m_classic_overrider; + TASCheckBox* m_a_button; TASCheckBox* m_b_button; TASCheckBox* m_1_button; diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h index b0e514d20ad2..e7e957e60875 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h @@ -20,8 +20,13 @@ class ControllerInterface; -const char* const named_directions[] = {_trans("Up"), _trans("Down"), _trans("Left"), - _trans("Right")}; +constexpr const char* DIRECTION_UP = _trans("Up"); +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; @@ -204,7 +209,7 @@ class EmulatedController std::vector> 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 static T MapFloat(F input_value, T zero_value, T neg_1_value = std::numeric_limits::min(), T pos_1_value = std::numeric_limits::max()) @@ -227,6 +232,21 @@ class EmulatedController 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 + static F MapToFloat(T input_value, T zero_value, T neg_1_value = std::numeric_limits::min(), + T pos_1_value = std::numeric_limits::max()) + { + static_assert(std::is_integral(), "T is only sane for int types."); + static_assert(std::is_floating_point(), "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: // 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).