remap-redux part 2: add controller sublabel

This commit is contained in:
radius 2018-04-01 20:57:33 -05:00
parent 052887d8b0
commit 7f5fe5ebff
8 changed files with 158 additions and 115 deletions

View File

@ -634,7 +634,8 @@ void input_poll(void)
int16_t input_state(unsigned port, unsigned device, int16_t input_state(unsigned port, unsigned device,
unsigned idx, unsigned id) unsigned idx, unsigned id)
{ {
int16_t res = 0; int16_t res = 0;
bool clear = false;
device &= RETRO_DEVICE_MASK; device &= RETRO_DEVICE_MASK;
@ -657,8 +658,11 @@ int16_t input_state(unsigned port, unsigned device,
switch (device) switch (device)
{ {
case RETRO_DEVICE_JOYPAD: case RETRO_DEVICE_JOYPAD:
if (id < RARCH_FIRST_CUSTOM_BIND) if (id != settings->uints.input_remap_ids[port][id])
id = settings->uints.input_remap_ids[port][id]; {
clear = true;
}
break; break;
case RETRO_DEVICE_ANALOG: case RETRO_DEVICE_ANALOG:
if (idx < 2 && id < 2) if (idx < 2 && id < 2)
@ -676,11 +680,9 @@ int16_t input_state(unsigned port, unsigned device,
if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD))) if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD)))
{ {
bool bind_valid = libretro_input_binds[port] && libretro_input_binds[port][id].valid; bool bind_valid = libretro_input_binds[port] && libretro_input_binds[port][id].valid;
rarch_joypad_info_t joypad_info;
if (bind_valid || device == RETRO_DEVICE_KEYBOARD) if (bind_valid || device == RETRO_DEVICE_KEYBOARD)
{ {
rarch_joypad_info_t joypad_info;
joypad_info.axis_threshold = input_driver_axis_threshold; joypad_info.axis_threshold = input_driver_axis_threshold;
joypad_info.joy_idx = settings->uints.input_joypad_map[port]; joypad_info.joy_idx = settings->uints.input_joypad_map[port];
joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx]; joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx];
@ -690,6 +692,12 @@ int16_t input_state(unsigned port, unsigned device,
} }
} }
#ifdef HAVE_KEYMAPPER
if (input_driver_mapper)
input_mapper_state(input_driver_mapper,
&res, port, device, idx, id, clear);
#endif
#ifdef HAVE_OVERLAY #ifdef HAVE_OVERLAY
if (overlay_ptr) if (overlay_ptr)
input_state_overlay(overlay_ptr, &res, port, device, idx, id); input_state_overlay(overlay_ptr, &res, port, device, idx, id);
@ -700,12 +708,6 @@ int16_t input_state(unsigned port, unsigned device,
input_remote_state(&res, port, device, idx, id); input_remote_state(&res, port, device, idx, id);
#endif #endif
#ifdef HAVE_KEYMAPPER
if (input_driver_mapper)
input_mapper_state(input_driver_mapper,
&res, port, device, idx, id);
#endif
/* Don't allow turbo for D-pad. */ /* Don't allow turbo for D-pad. */
if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP || if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP ||
id > RETRO_DEVICE_ID_JOYPAD_RIGHT)) id > RETRO_DEVICE_ID_JOYPAD_RIGHT))

View File

@ -81,6 +81,13 @@ void input_mapper_free(input_mapper_t *handle)
free (handle); free (handle);
} }
bool flag = false;
bool input_mapper_button_pressed(input_mapper_t *handle, int id)
{
return (handle->buttons >> id) & 1U;
}
void input_mapper_poll(input_mapper_t *handle) void input_mapper_poll(input_mapper_t *handle)
{ {
int i, j; int i, j;
@ -93,9 +100,6 @@ void input_mapper_poll(input_mapper_t *handle)
device &= RETRO_DEVICE_MASK; device &= RETRO_DEVICE_MASK;
/* for now we only handle keyboard inputs */
if (device != RETRO_DEVICE_KEYBOARD)
return;
#ifdef HAVE_MENU #ifdef HAVE_MENU
if (menu_is_alive) if (menu_is_alive)
return; return;
@ -103,31 +107,56 @@ void input_mapper_poll(input_mapper_t *handle)
memset(handle->keys, 0, sizeof(handle->keys)); memset(handle->keys, 0, sizeof(handle->keys));
i = 0; i = 0;
for (i = 0; i < MAX_USERS; i++) if (device == RETRO_DEVICE_KEYBOARD)
{ {
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++) for (i = 0; i < MAX_USERS; i++)
{ {
if (j < RETROK_LAST) for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
{ {
if (input_state(i, RETRO_DEVICE_JOYPAD, 0, j) && if (j < RETROK_LAST)
settings->uints.input_keymapper_ids[i][j] != RETROK_UNKNOWN)
{ {
MAPPER_SET_KEY (handle, if (input_state(i, RETRO_DEVICE_JOYPAD, 0, j) &&
settings->uints.input_keymapper_ids[i][j]);
input_keyboard_event(true,
settings->uints.input_keymapper_ids[i][j],
0, 0, RETRO_DEVICE_KEYBOARD);
key_event[j] = true;
}
else
{
if (key_event[j] == false &&
settings->uints.input_keymapper_ids[i][j] != RETROK_UNKNOWN) settings->uints.input_keymapper_ids[i][j] != RETROK_UNKNOWN)
{ {
input_keyboard_event(false, MAPPER_SET_KEY (handle,
settings->uints.input_keymapper_ids[i][j]);
input_keyboard_event(true,
settings->uints.input_keymapper_ids[i][j], settings->uints.input_keymapper_ids[i][j],
0, 0, RETRO_DEVICE_KEYBOARD); 0, 0, RETRO_DEVICE_KEYBOARD);
key_event[j] = true;
} }
else
{
if (key_event[j] == false &&
settings->uints.input_keymapper_ids[i][j] != RETROK_UNKNOWN)
{
input_keyboard_event(false,
settings->uints.input_keymapper_ids[i][j],
0, 0, RETRO_DEVICE_KEYBOARD);
}
}
}
}
}
}
if (device == RETRO_DEVICE_JOYPAD)
{
for (i = 0; i < MAX_USERS; i++)
{
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
{
if(input_state(i, RETRO_DEVICE_JOYPAD, i, j))
{
if (j != settings->uints.input_remap_ids[i][j])
{
RARCH_LOG("remapped button pressed: old:%d new: %d\n", j, settings->uints.input_remap_ids[i][j]);
handle->buttons |= 1 << settings->uints.input_remap_ids[i][j];
}
}
if(!input_state(i, RETRO_DEVICE_JOYPAD, i, j))
{
if (j != settings->uints.input_remap_ids[i][j])
handle->buttons &= ~(1 << settings->uints.input_remap_ids[i][j]);
} }
} }
} }
@ -140,24 +169,23 @@ void input_mapper_state(
unsigned port, unsigned port,
unsigned device, unsigned device,
unsigned idx, unsigned idx,
unsigned id) unsigned id,
bool clear)
{ {
if (!handle) if (!handle)
return; return;
switch (device) switch (device)
{ {
case RETRO_DEVICE_JOYPAD:
/* we should get the new buttons here via input_remapper_button_pressed but it doesn't work because the old state is still there
so both actions trigger */
if (input_mapper_button_pressed(handle, id))
*ret = 1;
break;
case RETRO_DEVICE_KEYBOARD: case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST) if (id < RETROK_LAST)
{ {
/*
RARCH_LOG("State: UDLR %u %u %u %u\n",
MAPPER_GET_KEY(handle, RETROK_UP),
MAPPER_GET_KEY(handle, RETROK_DOWN),
MAPPER_GET_KEY(handle, RETROK_LEFT),
MAPPER_GET_KEY(handle, RETROK_RIGHT)
);*/
if (MAPPER_GET_KEY(handle, id)) if (MAPPER_GET_KEY(handle, id))
*ret |= 1; *ret |= 1;
} }
@ -165,4 +193,5 @@ void input_mapper_state(
default: default:
break; break;
} }
return;
} }

View File

@ -37,7 +37,7 @@ void input_mapper_free(input_mapper_t *handle);
void input_mapper_poll(input_mapper_t *handle); void input_mapper_poll(input_mapper_t *handle);
bool input_mapper_key_pressed(int key); bool input_mapper_key_pressed(input_mapper_t *handle, int key);
void input_mapper_state( void input_mapper_state(
input_mapper_t *handle, input_mapper_t *handle,
@ -45,7 +45,8 @@ void input_mapper_state(
unsigned port, unsigned port,
unsigned device, unsigned device,
unsigned idx, unsigned idx,
unsigned id); unsigned id,
bool clear);
RETRO_END_DECLS RETRO_END_DECLS

View File

@ -552,56 +552,29 @@ static void menu_action_setting_disp_set_label_input_desc(
const struct retro_keybind *auto_bind = NULL; const struct retro_keybind *auto_bind = NULL;
const struct retro_keybind *keybind = NULL; const struct retro_keybind *keybind = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
unsigned inp_desc_index_offset =
type - MENU_SETTINGS_INPUT_DESC_BEGIN; unsigned key_id, id, offset;
unsigned inp_desc_user = inp_desc_index_offset / unsigned remap_id = 0;
(RARCH_FIRST_CUSTOM_BIND + 8);
unsigned inp_desc_button_index_offset = inp_desc_index_offset - if (!settings)
(inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 8)); return 0;
unsigned remap_id = 0;
offset = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
id = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * offset;
remap_id =
settings->uints.input_remap_ids[offset][id];
system = runloop_get_system_info(); system = runloop_get_system_info();
if (!system) if (!system)
return; return;
descriptor = system->input_desc_btn[inp_desc_user][inp_desc_button_index_offset]; descriptor = system->input_desc_btn[offset][remap_id];
if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND + 8) if (!string_is_empty(descriptor))
strlcpy(s, descriptor ? descriptor : "---", len); strlcpy(s, descriptor, len);
else
{
switch (remap_id)
{
case 0:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_X_PLUS);
break;
case 1:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_X_MINUS);
break;
case 2:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_Y_PLUS);
break;
case 3:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_Y_MINUS);
break;
case 4:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_X_PLUS);
break;
case 5:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_X_MINUS);
break;
case 6:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_Y_PLUS);
break;
case 7:
descriptor = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_Y_MINUS);
break;
}
if (!string_is_empty(descriptor))
strlcpy(s, descriptor, len);
}
*w = 19; *w = 19;
strlcpy(s2, path, len2); strlcpy(s2, path, len2);

View File

@ -90,19 +90,24 @@ static int action_left_cheat(unsigned type, const char *label,
wraparound); wraparound);
} }
/* fix-me: incomplete, lacks error checking */
static int action_left_input_desc(unsigned type, const char *label, static int action_left_input_desc(unsigned type, const char *label,
bool wraparound) bool wraparound)
{ {
unsigned inp_desc_index_offset = type -
MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset /
(RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset
- (inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
settings_t *settings = config_get_ptr();
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] > 0) unsigned key_id, id, offset;
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]--; unsigned remap_id = 0;
settings_t *settings = config_get_ptr();
if (!settings)
return 0;
offset = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
id = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * offset;
if (settings->uints.input_remap_ids[offset][id] > 0)
settings->uints.input_remap_ids[offset][id]--;
return 0; return 0;
} }

View File

@ -107,7 +107,6 @@ int action_right_input_desc_kbd(unsigned type, const char *label,
{ {
unsigned key_id, id, offset; unsigned key_id, id, offset;
unsigned remap_id; unsigned remap_id;
char desc[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
if (!settings) if (!settings)
@ -129,6 +128,8 @@ int action_right_input_desc_kbd(unsigned type, const char *label,
break; break;
} }
RARCH_LOG("o:%u t:%u i:%u r:%u\n", offset, type, id, remap_id);
if (key_id < RARCH_MAX_KEYS + MENU_SETTINGS_INPUT_DESC_KBD_BEGIN) if (key_id < RARCH_MAX_KEYS + MENU_SETTINGS_INPUT_DESC_KBD_BEGIN)
key_id++; key_id++;
else else
@ -140,26 +141,28 @@ int action_right_input_desc_kbd(unsigned type, const char *label,
} }
#endif #endif
/* fix-me: incomplete, lacks error checking */
int action_right_input_desc(unsigned type, const char *label, int action_right_input_desc(unsigned type, const char *label,
bool wraparound) bool wraparound)
{ {
unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset / (RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
settings_t *settings = config_get_ptr();
if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND) unsigned key_id, id, offset;
{ unsigned remap_id = 0;
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < RARCH_FIRST_CUSTOM_BIND - 1) settings_t *settings = config_get_ptr();
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}
else
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < 4 - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}
return 0; if (!settings)
return 0;
offset = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
id = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * offset;
if (settings->uints.input_remap_ids[offset][id] < RARCH_FIRST_CUSTOM_BIND)
settings->uints.input_remap_ids[offset][id]++;
RARCH_LOG("o:%u t:%u i:%u r:%u\n", offset, type, id, remap_id);
return 0;
} }
static int action_right_scroll(unsigned type, const char *label, static int action_right_scroll(unsigned type, const char *label,

View File

@ -426,7 +426,7 @@ static int action_bind_sublabel_subsystem_add(
return 0; return 0;
} }
static int action_bind_sublabel_remap_sublabel( static int action_bind_sublabel_remap_kbd_sublabel(
file_list_t *list, file_list_t *list,
unsigned type, unsigned i, unsigned type, unsigned i,
const char *label, const char *path, const char *label, const char *path,
@ -451,6 +451,30 @@ static int action_bind_sublabel_remap_sublabel(
return 0; return 0;
} }
static int action_bind_sublabel_remap_sublabel(
file_list_t *list,
unsigned type, unsigned i,
const char *label, const char *path,
char *s, size_t len)
{
char desc[PATH_MAX_LENGTH];
unsigned offset;
settings_t *settings = config_get_ptr();
if (!settings)
return 0;
offset = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
snprintf(s, len, "User #%d: %s", offset + 1,
input_config_get_device_display_name(offset) ?
input_config_get_device_display_name(offset) :
(input_config_get_device_name(offset) ?
input_config_get_device_name(offset) : "N/A"));
return 0;
}
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
static int action_bind_sublabel_netplay_room( static int action_bind_sublabel_netplay_room(
file_list_t *list, file_list_t *list,
@ -513,10 +537,16 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END) && type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
{ {
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_remap_sublabel); BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_remap_kbd_sublabel);
} }
#endif #endif
if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_END)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_remap_sublabel);
}
if (cbs->enum_idx != MSG_UNKNOWN) if (cbs->enum_idx != MSG_UNKNOWN)
{ {
switch (cbs->enum_idx) switch (cbs->enum_idx)

View File

@ -206,9 +206,9 @@ enum menu_settings_type
MENU_SETTINGS_CHEAT_BEGIN, MENU_SETTINGS_CHEAT_BEGIN,
MENU_SETTINGS_CHEAT_END = MENU_SETTINGS_CHEAT_BEGIN + (MAX_CHEAT_COUNTERS - 1), MENU_SETTINGS_CHEAT_END = MENU_SETTINGS_CHEAT_BEGIN + (MAX_CHEAT_COUNTERS - 1),
MENU_SETTINGS_INPUT_DESC_BEGIN, MENU_SETTINGS_INPUT_DESC_BEGIN,
MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + (MAX_USERS * (RARCH_FIRST_CUSTOM_BIND + 4)), MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + ((RARCH_FIRST_CUSTOM_BIND + 8) * MAX_USERS),
MENU_SETTINGS_INPUT_DESC_KBD_BEGIN, MENU_SETTINGS_INPUT_DESC_KBD_BEGIN,
MENU_SETTINGS_INPUT_DESC_KBD_END = (MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + RARCH_MAX_KEYS) * MAX_USERS, MENU_SETTINGS_INPUT_DESC_KBD_END = MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + (RARCH_MAX_KEYS * MAX_USERS),
MENU_SETTINGS_SUBSYSTEM_LOAD, MENU_SETTINGS_SUBSYSTEM_LOAD,