DolphinQt: Use input override system for TAS input windows

This lets the TAS input code use a higher-level interface for
overriding inputs instead of having to fiddle with raw bits.
WiiTASInputWindow in particular was messy with how much
controller code it had to re-implement.
This commit is contained in:
JosJuice
2022-10-03 22:04:09 +02:00
parent 8fd25259ee
commit b296248b49
21 changed files with 553 additions and 503 deletions
+13 -28
View File
@@ -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
+27
View File
@@ -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;
+9 -13
View File
@@ -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();
-25
View File
@@ -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()
{ {
-11
View File
@@ -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
-9
View File
@@ -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);
+54 -57
View File
@@ -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);
} }
+10 -3
View File
@@ -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;
+4 -4
View File
@@ -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));
+2
View File
@@ -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;
+103 -35
View File
@@ -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;
} }
+46 -14
View File
@@ -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;
}; };
File diff suppressed because it is too large Load Diff
+29 -12
View File
@@ -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;

Some files were not shown because too many files have changed in this diff Show More