Skip to content

Commit

Permalink
Add sublabels for "port x controls" entries
Browse files Browse the repository at this point in the history
Due to the port-specific indexes, sublabels for these entries
are handled specially. Some simplification/generalization  was
applied and hand-crafted string joining was removed from a few
places, though it remains still in other places.

Preparation for libretro#16121 (this commit does not do anything yet with
file names).
  • Loading branch information
zoltanvb committed Feb 15, 2024
1 parent b209a26 commit 3a29050
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 48 deletions.
16 changes: 16 additions & 0 deletions intl/msg_hash_lbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,22 @@ MSG_HASH(
MENU_ENUM_LABEL_INPUT_MOUSE_INDEX,
"input_player%u_mouse_index"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX,
"input_player%u_joypad_index"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX,
"input_player%u_bind_all"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX,
"input_player%u_bind_all_save_autoconfig"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX,
"input_player%u_bind_all_bind_defaults"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_REMAP_PORT,
"input_remap_port_p%u"
Expand Down
16 changes: 16 additions & 0 deletions intl/msg_hash_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -4101,6 +4101,10 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_DEVICE_INDEX,
"Device Index"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_DEVICE_INDEX,
"The physical controller as recognized by RetroArch."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_REMAP_PORT,
"Mapped Port"
Expand All @@ -4113,14 +4117,26 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_BIND_ALL,
"Set All Controls"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_BIND_ALL,
"Assign all directions and buttons, one after the other, in the order they appear in this menu."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_BIND_DEFAULT_ALL,
"Reset to Default Controls"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_BIND_DEFAULTS,
"Clear input bind settings to their default values."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SAVE_AUTOCONFIG,
"Save Controller Profile"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_SAVE_AUTOCONFIG,
"Save an autoconfiguration file that will be applied automatically whenever this controller is detected again."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_INDEX,
"Mouse Index"
Expand Down
116 changes: 80 additions & 36 deletions menu/cbs/menu_cbs_sublabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,11 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_netplay_fade_chat_toggle,
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_hotkey_block_delay, MENU_ENUM_SUBLABEL_INPUT_HOTKEY_BLOCK_DELAY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_hotkey_device_merge, MENU_ENUM_SUBLABEL_INPUT_HOTKEY_DEVICE_MERGE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_device_type, MENU_ENUM_SUBLABEL_INPUT_DEVICE_TYPE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_device_index, MENU_ENUM_SUBLABEL_INPUT_DEVICE_INDEX)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_adc_type, MENU_ENUM_SUBLABEL_INPUT_ADC_TYPE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_bind_all, MENU_ENUM_SUBLABEL_INPUT_BIND_ALL)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_save_autoconfig, MENU_ENUM_SUBLABEL_INPUT_SAVE_AUTOCONFIG)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_bind_defaults, MENU_ENUM_SUBLABEL_INPUT_BIND_DEFAULTS)
#ifdef HAVE_MATERIALUI
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_materialui_icons_enable, MENU_ENUM_SUBLABEL_MATERIALUI_ICONS_ENABLE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_materialui_switch_icons, MENU_ENUM_SUBLABEL_MATERIALUI_SWITCH_ICONS)
Expand Down Expand Up @@ -2180,6 +2184,17 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
action_bind_sublabel_cheat_desc
},
#endif
{
MENU_SETTINGS_CORE_OPTION_START,
MENU_SETTINGS_CHEEVOS_START - 1,
action_bind_sublabel_core_option
},
{
MENU_SETTINGS_REMAPPING_PORT_BEGIN,
MENU_SETTINGS_REMAPPING_PORT_END,
action_bind_sublabel_user_remap_settings
},

};

if (!cbs)
Expand All @@ -2196,30 +2211,14 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
}
}

if ((type >= MENU_SETTINGS_CORE_OPTION_START) &&
(type < MENU_SETTINGS_CHEEVOS_START))
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_core_option);
return 0;
}


/* Quick Menu Port Controls require special handling */
if ( type >= MENU_SETTINGS_REMAPPING_PORT_BEGIN
&& type <= MENU_SETTINGS_REMAPPING_PORT_END)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_user_remap_settings);
return 0;
}
else if (type == MENU_SETTINGS_INPUT_LIBRETRO_DEVICE)
if (type == MENU_SETTINGS_INPUT_LIBRETRO_DEVICE)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_device_type);
return 0;
}
else if (type == MENU_SETTINGS_INPUT_ANALOG_DPAD_MODE)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_adc_type);
return 0;
}
else if (type == MENU_SETTINGS_INPUT_INPUT_REMAP_PORT)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_remap_port);
Expand Down Expand Up @@ -5555,26 +5554,71 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
}
else
{
/* Per-port 'Analog to Digital Type' entries
* require special handling */
if ( string_starts_with_size(label, "input_player",
STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "_analog_dpad_mode",
lbl_len, STRLEN_CONST("_analog_dpad_mode")))
/* Per-port entries require string match against label.
* Some cases may be detected above by "type", but not all. */
typedef struct info_single_list
{
unsigned label_idx;
int (*cb)(file_list_t *list,
unsigned type, unsigned i,
const char *label, const char *path,
char *s, size_t len);
} info_single_list_t;

info_single_list_t info_list[] = {
/* {
MENU_ENUM_LABEL_INPUT_LIBRETRO_DEVICE,
NULL
},*/
{
MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE,
action_bind_sublabel_input_adc_type
},
/* {
MENU_ENUM_LABEL_INPUT_DEVICE_INDEX,
NULL
},
{
MENU_ENUM_LABEL_INPUT_MOUSE_INDEX,
NULL
},
{
MENU_ENUM_LABEL_INPUT_REMAP_PORT,
NULL
},*/
{
MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX,
action_bind_sublabel_input_device_index
},
{
MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX,
action_bind_sublabel_input_bind_all
},
{
MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX,
action_bind_sublabel_input_save_autoconfig
},
{
MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX,
action_bind_sublabel_input_bind_defaults
},
};

const char* idx_placeholder = "%u";
for (i = 0; i < ARRAY_SIZE(info_list); i++)
{
unsigned i;
char key_input_adc_type[64];
size_t _len = strlcpy(key_input_adc_type, "input_player", sizeof(key_input_adc_type));
for (i = 0; i < MAX_USERS; i++)
int idxpos = -1;
idxpos = string_find_index_substring_string(msg_hash_to_str(info_list[i].label_idx), idx_placeholder);
if ( idxpos > 0 &&
string_starts_with_size(label, msg_hash_to_str(info_list[i].label_idx), idxpos) &&
(( (size_t) idxpos == strlen(msg_hash_to_str(info_list[i].label_idx)) - 2) ||
( (size_t) idxpos < strlen(msg_hash_to_str(info_list[i].label_idx)) - 2 &&
string_ends_with_size(label,
msg_hash_to_str(info_list[i].label_idx)+idxpos+2,
lbl_len,
strlen(msg_hash_to_str(info_list[i].label_idx))-idxpos-2))))
{
size_t _len2 = snprintf(key_input_adc_type + _len,
sizeof(key_input_adc_type) - _len, "%u", i + 1);
strlcpy(key_input_adc_type + _len2,
"_analog_dpad_mode",
sizeof(key_input_adc_type) - _len2);
if (!string_is_equal(label, key_input_adc_type))
continue;
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_adc_type);
BIND_ACTION_SUBLABEL(cbs, info_list[i].cb);
return 0;
}
}
Expand Down
22 changes: 10 additions & 12 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -9300,18 +9300,16 @@ static bool setting_append_list_input_player_options(

snprintf(analog_to_digital[user], sizeof(analog_to_digital[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE), user + 1);
fill_pathname_join_delim(device_index[user], tmp_string, "joypad_index", '_',
sizeof(device_index[user]));
fill_pathname_join_delim(mouse_index[user], tmp_string, "mouse_index", '_',
sizeof(mouse_index[user]));
fill_pathname_join_delim(bind_all[user], tmp_string, "bind_all", '_',
sizeof(bind_all[user]));
fill_pathname_join_delim(bind_all_save_autoconfig[user],
tmp_string, "bind_all_save_autoconfig", '_',
sizeof(bind_all_save_autoconfig[user]));
fill_pathname_join_delim(bind_defaults[user],
tmp_string, "bind_defaults", '_',
sizeof(bind_defaults[user]));
snprintf(device_index[user], sizeof(device_index[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX), user + 1);
snprintf(mouse_index[user], sizeof(mouse_index[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_MOUSE_INDEX), user + 1);
snprintf(bind_all[user], sizeof(bind_all[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX), user + 1);
snprintf(bind_all_save_autoconfig[user], sizeof(bind_all_save_autoconfig[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX), user + 1);
snprintf(bind_defaults[user], sizeof(bind_defaults[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX), user + 1);

strlcpy(label_analog_to_digital[user],
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ADC_TYPE),
Expand Down
8 changes: 8 additions & 0 deletions msg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1148,11 +1148,19 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_INPUT_BIND_DEFAULT_ALL,
MENU_ENUM_LABEL_VALUE_INPUT_SAVE_AUTOCONFIG,
MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_INDEX,
MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX,
MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX,
MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX,
MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX,
MENU_ENUM_LABEL_VALUE_INPUT_REMAP_PORT,

MENU_ENUM_SUBLABEL_INPUT_DEVICE_TYPE,
MENU_ENUM_SUBLABEL_INPUT_DEVICE_INDEX,
MENU_ENUM_SUBLABEL_INPUT_ADC_TYPE,
MENU_ENUM_LABEL_HELP_INPUT_ADC_TYPE,
MENU_ENUM_SUBLABEL_INPUT_BIND_ALL,
MENU_ENUM_SUBLABEL_INPUT_SAVE_AUTOCONFIG,
MENU_ENUM_SUBLABEL_INPUT_BIND_DEFAULTS,
MENU_ENUM_SUBLABEL_INPUT_REMAP_PORT,

MENU_ENUM_SUBLABEL_INPUT_META_ENABLE_HOTKEY,
Expand Down

0 comments on commit 3a29050

Please sign in to comment.