input: per controller instance mapping file. Hide DPad U/D/L/R
Try to load a per-controller instance mapping file first, then fallback to the per device type file. Hide DPad U/D/L/R and DPad2 U/D/L/R in analog axes mapping to avoid confusion.
This commit is contained in:
parent
ed1a9fabd0
commit
c364d6379b
|
@ -49,11 +49,11 @@ static FILE *record_input;
|
|||
|
||||
bool GamepadDevice::gamepad_btn_input(u32 code, bool pressed)
|
||||
{
|
||||
if (_input_detected != NULL && _detecting_button
|
||||
if (_input_detected != nullptr && _detecting_button
|
||||
&& os_GetSeconds() >= _detection_start_time && pressed)
|
||||
{
|
||||
_input_detected(code);
|
||||
_input_detected = NULL;
|
||||
_input_detected = nullptr;
|
||||
}
|
||||
if (!input_mapper || _maple_port < 0 || _maple_port >= (int)ARRAY_SIZE(kcode))
|
||||
return false;
|
||||
|
@ -260,9 +260,11 @@ unsigned int GamepadDevice::get_axis_range(u32 axis) {
|
|||
return it->second;
|
||||
}
|
||||
|
||||
std::string GamepadDevice::make_mapping_filename()
|
||||
std::string GamepadDevice::make_mapping_filename(bool instance)
|
||||
{
|
||||
std::string mapping_file = api_name() + "_" + name();
|
||||
if (instance)
|
||||
mapping_file += "-" + _unique_id;
|
||||
std::replace(mapping_file.begin(), mapping_file.end(), '/', '-');
|
||||
std::replace(mapping_file.begin(), mapping_file.end(), '\\', '-');
|
||||
std::replace(mapping_file.begin(), mapping_file.end(), ':', '-');
|
||||
|
@ -277,15 +279,20 @@ std::string GamepadDevice::make_mapping_filename()
|
|||
return mapping_file;
|
||||
}
|
||||
|
||||
bool GamepadDevice::find_mapping(const char *custom_mapping /* = NULL */)
|
||||
bool GamepadDevice::find_mapping(const char *custom_mapping /* = nullptr */)
|
||||
{
|
||||
std::string mapping_file;
|
||||
if (custom_mapping != NULL)
|
||||
if (custom_mapping != nullptr)
|
||||
mapping_file = custom_mapping;
|
||||
else
|
||||
mapping_file = make_mapping_filename();
|
||||
mapping_file = make_mapping_filename(true);
|
||||
|
||||
input_mapper = InputMapping::LoadMapping(mapping_file.c_str());
|
||||
if (!input_mapper && custom_mapping == nullptr)
|
||||
{
|
||||
mapping_file = make_mapping_filename(false);
|
||||
input_mapper = InputMapping::LoadMapping(mapping_file.c_str());
|
||||
}
|
||||
return !!input_mapper;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
void detect_axis_input(input_detected_cb axis_moved);
|
||||
void cancel_detect_input()
|
||||
{
|
||||
_input_detected = NULL;
|
||||
_input_detected = nullptr;
|
||||
}
|
||||
std::shared_ptr<InputMapping> get_input_mapping() { return input_mapper; }
|
||||
void save_mapping();
|
||||
|
@ -67,7 +67,7 @@ protected:
|
|||
: _api_name(api_name), _maple_port(maple_port), _input_detected(nullptr), _remappable(remappable)
|
||||
{
|
||||
}
|
||||
bool find_mapping(const char *custom_mapping = NULL);
|
||||
bool find_mapping(const char *custom_mapping = nullptr);
|
||||
|
||||
virtual void load_axis_min_max(u32 axis) {}
|
||||
|
||||
|
@ -81,7 +81,7 @@ protected:
|
|||
private:
|
||||
int get_axis_min_value(u32 axis);
|
||||
unsigned int get_axis_range(u32 axis);
|
||||
std::string make_mapping_filename();
|
||||
std::string make_mapping_filename(bool instance = false);
|
||||
|
||||
std::string _api_name;
|
||||
int _maple_port;
|
||||
|
|
|
@ -438,24 +438,42 @@ static const char *maple_expansion_device_name(MapleDeviceType type)
|
|||
}
|
||||
|
||||
const char *maple_ports[] = { "None", "A", "B", "C", "D" };
|
||||
const DreamcastKey button_keys[] = { DC_BTN_START, DC_BTN_A, DC_BTN_B, DC_BTN_X, DC_BTN_Y, DC_DPAD_UP, DC_DPAD_DOWN, DC_DPAD_LEFT, DC_DPAD_RIGHT,
|
||||
const DreamcastKey button_keys[] = {
|
||||
DC_BTN_START, DC_BTN_A, DC_BTN_B, DC_BTN_X, DC_BTN_Y, DC_DPAD_UP, DC_DPAD_DOWN, DC_DPAD_LEFT, DC_DPAD_RIGHT,
|
||||
EMU_BTN_MENU, EMU_BTN_ESCAPE, EMU_BTN_FFORWARD, EMU_BTN_TRIGGER_LEFT, EMU_BTN_TRIGGER_RIGHT,
|
||||
DC_BTN_C, DC_BTN_D, DC_BTN_Z, DC_DPAD2_UP, DC_DPAD2_DOWN, DC_DPAD2_LEFT, DC_DPAD2_RIGHT,
|
||||
EMU_BTN_ANA_UP, EMU_BTN_ANA_DOWN, EMU_BTN_ANA_LEFT, EMU_BTN_ANA_RIGHT };
|
||||
const char *button_names[] = { "Start", "A", "B", "X", "Y", "DPad Up", "DPad Down", "DPad Left", "DPad Right",
|
||||
EMU_BTN_ANA_UP, EMU_BTN_ANA_DOWN, EMU_BTN_ANA_LEFT, EMU_BTN_ANA_RIGHT
|
||||
};
|
||||
const char *button_names[] = {
|
||||
"Start", "A", "B", "X", "Y", "DPad Up", "DPad Down", "DPad Left", "DPad Right",
|
||||
"Menu", "Exit", "Fast-forward", "Left Trigger", "Right Trigger",
|
||||
"C", "D", "Z", "Right Dpad Up", "Right DPad Down", "Right DPad Left", "Right DPad Right",
|
||||
"Left Stick Up", "Left Stick Down", "Left Stick Left", "Left Stick Right" };
|
||||
const char *arcade_button_names[] = { "Start", "Button 1", "Button 2", "Button 3", "Button 4", "Up", "Down", "Left", "Right",
|
||||
"Left Stick Up", "Left Stick Down", "Left Stick Left", "Left Stick Right"
|
||||
};
|
||||
const char *arcade_button_names[] = {
|
||||
"Start", "Button 1", "Button 2", "Button 3", "Button 4", "Up", "Down", "Left", "Right",
|
||||
"Menu", "Exit", "Fast-forward", "N/A", "N/A",
|
||||
"Service", "Coin", "Test", "Button 5", "Button 6", "Button 7", "Button 8", "N/A", "N/A", "N/A", "N/A" };
|
||||
const DreamcastKey axis_keys[] = { DC_AXIS_X, DC_AXIS_Y, DC_AXIS_LT, DC_AXIS_RT, DC_AXIS_X2, DC_AXIS_Y2, EMU_AXIS_DPAD1_X, EMU_AXIS_DPAD1_Y, EMU_AXIS_DPAD2_X, EMU_AXIS_DPAD2_Y,
|
||||
EMU_AXIS_BTN_START, EMU_AXIS_BTN_A, EMU_AXIS_BTN_B, EMU_AXIS_BTN_X, EMU_AXIS_BTN_Y, EMU_AXIS_DPAD_UP, EMU_AXIS_DPAD_DOWN, EMU_AXIS_DPAD_LEFT, EMU_AXIS_DPAD_RIGHT,
|
||||
EMU_AXIS_BTN_C, EMU_AXIS_BTN_D, EMU_AXIS_BTN_Z, EMU_AXIS_DPAD2_UP, EMU_AXIS_DPAD2_DOWN, EMU_AXIS_DPAD2_LEFT, EMU_AXIS_DPAD2_RIGHT};
|
||||
const char *axis_names[] = { "Left Stick X", "Left Stick Y", "Left Trigger", "Right Trigger", "Right Stick X", "Right Stick Y", "DPad X", "DPad Y", "Right DPad X", "Right DPad Y",
|
||||
"Start", "A", "B", "X", "Y", "DPad Up", "DPad Down", "DPad Left", "DPad Right", "C", "D", "Z", "Right DPad Up", "Right DPad Down", "Right DPad Left", "Right DPad Right"};
|
||||
const char *arcade_axis_names[] = { "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "Start", "Button 1", "Button 2", "Button 3", "Button 4", "Up", "Down", "Left", "Right",
|
||||
"Service", "Coin", "Test", "Button 5", "Button 6", "Button 7", "Button 8"};
|
||||
"Service", "Coin", "Test", "Button 5", "Button 6", "Button 7", "Button 8", "N/A", "N/A", "N/A", "N/A"
|
||||
};
|
||||
const DreamcastKey axis_keys[] = {
|
||||
DC_AXIS_X, DC_AXIS_Y, DC_AXIS_LT, DC_AXIS_RT, DC_AXIS_X2, DC_AXIS_Y2, EMU_AXIS_DPAD1_X, EMU_AXIS_DPAD1_Y,
|
||||
EMU_AXIS_DPAD2_X, EMU_AXIS_DPAD2_Y, EMU_AXIS_BTN_START, EMU_AXIS_BTN_A, EMU_AXIS_BTN_B, EMU_AXIS_BTN_X, EMU_AXIS_BTN_Y,
|
||||
EMU_AXIS_BTN_C, EMU_AXIS_BTN_D, EMU_AXIS_BTN_Z, EMU_AXIS_DPAD2_UP, EMU_AXIS_DPAD2_DOWN, EMU_AXIS_DPAD2_LEFT, EMU_AXIS_DPAD2_RIGHT
|
||||
};
|
||||
const char *axis_names[] = {
|
||||
"Left Stick X", "Left Stick Y", "Left Trigger", "Right Trigger", "Right Stick X", "Right Stick Y", "DPad X", "DPad Y",
|
||||
"Right DPad X", "Right DPad Y", "Start", "A", "B", "X", "Y",
|
||||
"C", "D", "Z", "N/A", "N/A", "N/A", "N/A"
|
||||
};
|
||||
const char *arcade_axis_names[] = {
|
||||
"Left Stick X", "Left Stick Y", "Left Trigger", "Right Trigger", "Right Stick X", "Right Stick Y", "DPad X", "DPad Y",
|
||||
"Right DPad X", "Right DPad Y", "Start", "Button 1", "Button 2", "Button 3", "Button 4",
|
||||
"Service", "Coin", "Test", "Button 5", "Button 6", "Button 7", "Button 8"
|
||||
};
|
||||
static_assert(ARRAY_SIZE(button_keys) == ARRAY_SIZE(button_names), "invalid size");
|
||||
static_assert(ARRAY_SIZE(button_keys) == ARRAY_SIZE(arcade_button_names), "invalid size");
|
||||
static_assert(ARRAY_SIZE(axis_keys) == ARRAY_SIZE(axis_names), "invalid size");
|
||||
static_assert(ARRAY_SIZE(axis_keys) == ARRAY_SIZE(arcade_axis_names), "invalid size");
|
||||
|
||||
static MapleDeviceType maple_expansion_device_type_from_index(int idx)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue