mirror of
https://github.com/libretro/RetroArch
synced 2025-04-18 05:43:34 +00:00
(Menu) Refactor two input settings
This commit is contained in:
parent
b42ed89d23
commit
1c1194cdca
@ -90,32 +90,7 @@ static int menu_info_screen_iterate(unsigned action)
|
|||||||
strlcpy(needle, label, sizeof(needle));
|
strlcpy(needle, label, sizeof(needle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setting_data_get_description(needle, msg, sizeof(msg));
|
||||||
if (needle[0] == '\0' || setting_data_get_description(needle, msg, sizeof(msg)) == -1)
|
|
||||||
{
|
|
||||||
switch (info_type)
|
|
||||||
{
|
|
||||||
case MENU_SETTINGS_BIND_DEVICE:
|
|
||||||
snprintf(msg, sizeof(msg),
|
|
||||||
" -- Input Device. \n"
|
|
||||||
" \n"
|
|
||||||
"Picks which gamepad to use for player N. \n"
|
|
||||||
"The name of the pad is available."
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case MENU_SETTINGS_BIND_DEVICE_TYPE:
|
|
||||||
snprintf(msg, sizeof(msg),
|
|
||||||
" -- Input Device Type. \n"
|
|
||||||
" \n"
|
|
||||||
"Picks which device type to use. This is \n"
|
|
||||||
"relevant for the libretro core itself."
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
snprintf(msg, sizeof(msg),
|
|
||||||
"-- No info on this item available. --\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (driver.video_data && driver.menu_ctx &&
|
if (driver.video_data && driver.menu_ctx &&
|
||||||
driver.menu_ctx->render_messagebox)
|
driver.menu_ctx->render_messagebox)
|
||||||
@ -613,6 +588,89 @@ static int menu_setting_set(unsigned id, const char *label,
|
|||||||
if (driver.menu->need_refresh)
|
if (driver.menu->need_refresh)
|
||||||
gfx_shader_resolve_parameters(NULL, driver.menu->shader);
|
gfx_shader_resolve_parameters(NULL, driver.menu->shader);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else if (!strcmp(label, "input_bind_device_id"))
|
||||||
|
{
|
||||||
|
int *p = &g_settings.input.joypad_map[port];
|
||||||
|
if (action == MENU_ACTION_START)
|
||||||
|
*p = port;
|
||||||
|
else if (action == MENU_ACTION_LEFT)
|
||||||
|
(*p)--;
|
||||||
|
else if (action == MENU_ACTION_RIGHT)
|
||||||
|
(*p)++;
|
||||||
|
|
||||||
|
if (*p < -1)
|
||||||
|
*p = -1;
|
||||||
|
else if (*p >= MAX_PLAYERS)
|
||||||
|
*p = MAX_PLAYERS - 1;
|
||||||
|
}
|
||||||
|
else if (!strcmp(label, "input_bind_device_type"))
|
||||||
|
{
|
||||||
|
unsigned current_device, current_index, i, devices[128];
|
||||||
|
const struct retro_controller_info *desc;
|
||||||
|
unsigned types = 0;
|
||||||
|
|
||||||
|
devices[types++] = RETRO_DEVICE_NONE;
|
||||||
|
devices[types++] = RETRO_DEVICE_JOYPAD;
|
||||||
|
|
||||||
|
/* Only push RETRO_DEVICE_ANALOG as default if we use an
|
||||||
|
* older core which doesn't use SET_CONTROLLER_INFO. */
|
||||||
|
if (!g_extern.system.num_ports)
|
||||||
|
devices[types++] = RETRO_DEVICE_ANALOG;
|
||||||
|
|
||||||
|
desc = port < g_extern.system.num_ports ?
|
||||||
|
&g_extern.system.ports[port] : NULL;
|
||||||
|
if (desc)
|
||||||
|
{
|
||||||
|
for (i = 0; i < desc->num_types; i++)
|
||||||
|
{
|
||||||
|
unsigned id = desc->types[i].id;
|
||||||
|
if (types < ARRAY_SIZE(devices) &&
|
||||||
|
id != RETRO_DEVICE_NONE &&
|
||||||
|
id != RETRO_DEVICE_JOYPAD)
|
||||||
|
devices[types++] = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current_device = g_settings.input.libretro_device[port];
|
||||||
|
current_index = 0;
|
||||||
|
for (i = 0; i < types; i++)
|
||||||
|
{
|
||||||
|
if (current_device == devices[i])
|
||||||
|
{
|
||||||
|
current_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool updated = true;
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case MENU_ACTION_START:
|
||||||
|
current_device = RETRO_DEVICE_JOYPAD;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MENU_ACTION_LEFT:
|
||||||
|
current_device = devices
|
||||||
|
[(current_index + types - 1) % types];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MENU_ACTION_RIGHT:
|
||||||
|
case MENU_ACTION_OK:
|
||||||
|
current_device = devices
|
||||||
|
[(current_index + 1) % types];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
updated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updated)
|
||||||
|
{
|
||||||
|
g_settings.input.libretro_device[port] = current_device;
|
||||||
|
pretro_set_controller_port_device(port, current_device);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -635,22 +693,6 @@ static int menu_setting_set(unsigned id, const char *label,
|
|||||||
driver.menu->need_refresh = true;
|
driver.menu->need_refresh = true;
|
||||||
port = driver.menu->current_pad;
|
port = driver.menu->current_pad;
|
||||||
break;
|
break;
|
||||||
case MENU_SETTINGS_BIND_DEVICE:
|
|
||||||
{
|
|
||||||
int *p = &g_settings.input.joypad_map[port];
|
|
||||||
if (action == MENU_ACTION_START)
|
|
||||||
*p = port;
|
|
||||||
else if (action == MENU_ACTION_LEFT)
|
|
||||||
(*p)--;
|
|
||||||
else if (action == MENU_ACTION_RIGHT)
|
|
||||||
(*p)++;
|
|
||||||
|
|
||||||
if (*p < -1)
|
|
||||||
*p = -1;
|
|
||||||
else if (*p >= MAX_PLAYERS)
|
|
||||||
*p = MAX_PLAYERS - 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MENU_SETTINGS_BIND_ANALOG_MODE:
|
case MENU_SETTINGS_BIND_ANALOG_MODE:
|
||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
@ -675,75 +717,6 @@ static int menu_setting_set(unsigned id, const char *label,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MENU_SETTINGS_BIND_DEVICE_TYPE:
|
|
||||||
{
|
|
||||||
unsigned current_device, current_index, i, devices[128];
|
|
||||||
const struct retro_controller_info *desc;
|
|
||||||
unsigned types = 0;
|
|
||||||
|
|
||||||
devices[types++] = RETRO_DEVICE_NONE;
|
|
||||||
devices[types++] = RETRO_DEVICE_JOYPAD;
|
|
||||||
|
|
||||||
/* Only push RETRO_DEVICE_ANALOG as default if we use an
|
|
||||||
* older core which doesn't use SET_CONTROLLER_INFO. */
|
|
||||||
if (!g_extern.system.num_ports)
|
|
||||||
devices[types++] = RETRO_DEVICE_ANALOG;
|
|
||||||
|
|
||||||
desc = port < g_extern.system.num_ports ?
|
|
||||||
&g_extern.system.ports[port] : NULL;
|
|
||||||
if (desc)
|
|
||||||
{
|
|
||||||
for (i = 0; i < desc->num_types; i++)
|
|
||||||
{
|
|
||||||
unsigned id = desc->types[i].id;
|
|
||||||
if (types < ARRAY_SIZE(devices) &&
|
|
||||||
id != RETRO_DEVICE_NONE &&
|
|
||||||
id != RETRO_DEVICE_JOYPAD)
|
|
||||||
devices[types++] = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_device = g_settings.input.libretro_device[port];
|
|
||||||
current_index = 0;
|
|
||||||
for (i = 0; i < types; i++)
|
|
||||||
{
|
|
||||||
if (current_device == devices[i])
|
|
||||||
{
|
|
||||||
current_index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool updated = true;
|
|
||||||
switch (action)
|
|
||||||
{
|
|
||||||
case MENU_ACTION_START:
|
|
||||||
current_device = RETRO_DEVICE_JOYPAD;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MENU_ACTION_LEFT:
|
|
||||||
current_device = devices
|
|
||||||
[(current_index + types - 1) % types];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MENU_ACTION_RIGHT:
|
|
||||||
case MENU_ACTION_OK:
|
|
||||||
current_device = devices
|
|
||||||
[(current_index + 1) % types];
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
updated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updated)
|
|
||||||
{
|
|
||||||
g_settings.input.libretro_device[port] = current_device;
|
|
||||||
pretro_set_controller_port_device(port, current_device);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MENU_SETTINGS_CUSTOM_BIND_MODE:
|
case MENU_SETTINGS_CUSTOM_BIND_MODE:
|
||||||
if (action == MENU_ACTION_LEFT || action == MENU_ACTION_RIGHT)
|
if (action == MENU_ACTION_LEFT || action == MENU_ACTION_RIGHT)
|
||||||
driver.menu->bind_mode_keyboard =
|
driver.menu->bind_mode_keyboard =
|
||||||
|
@ -104,8 +104,6 @@ typedef enum
|
|||||||
MENU_SETTINGS_SHADER_PASS_SCALE_LAST = MENU_SETTINGS_SHADER_PASS_SCALE_0 + (GFX_MAX_SHADERS - 1),
|
MENU_SETTINGS_SHADER_PASS_SCALE_LAST = MENU_SETTINGS_SHADER_PASS_SCALE_0 + (GFX_MAX_SHADERS - 1),
|
||||||
|
|
||||||
MENU_SETTINGS_BIND_PLAYER,
|
MENU_SETTINGS_BIND_PLAYER,
|
||||||
MENU_SETTINGS_BIND_DEVICE,
|
|
||||||
MENU_SETTINGS_BIND_DEVICE_TYPE,
|
|
||||||
MENU_SETTINGS_BIND_ANALOG_MODE,
|
MENU_SETTINGS_BIND_ANALOG_MODE,
|
||||||
|
|
||||||
// Match up with libretro order for simplicity.
|
// Match up with libretro order for simplicity.
|
||||||
|
@ -442,10 +442,8 @@ int menu_entries_push_list(menu_handle_t *menu,
|
|||||||
file_list_clear(list);
|
file_list_clear(list);
|
||||||
file_list_push(list, "Player", "",
|
file_list_push(list, "Player", "",
|
||||||
MENU_SETTINGS_BIND_PLAYER, 0);
|
MENU_SETTINGS_BIND_PLAYER, 0);
|
||||||
file_list_push(list, "Device", "",
|
file_list_push(list, "Device", "input_bind_device_id", 0, 0);
|
||||||
MENU_SETTINGS_BIND_DEVICE, 0);
|
file_list_push(list, "Device Type", "input_bind_device_type", 0, 0);
|
||||||
file_list_push(list, "Device Type", "",
|
|
||||||
MENU_SETTINGS_BIND_DEVICE_TYPE, 0);
|
|
||||||
file_list_push(list, "Analog D-pad Mode", "",
|
file_list_push(list, "Analog D-pad Mode", "",
|
||||||
MENU_SETTINGS_BIND_ANALOG_MODE, 0);
|
MENU_SETTINGS_BIND_ANALOG_MODE, 0);
|
||||||
add_setting_entry(menu,list,"input_axis_threshold", 0, setting_data);
|
add_setting_entry(menu,list,"input_axis_threshold", 0, setting_data);
|
||||||
|
120
settings_data.c
120
settings_data.c
@ -1507,6 +1507,20 @@ int setting_data_get_description(const char *label, char *msg,
|
|||||||
else if (!strcmp(label, "menu_toggle"))
|
else if (!strcmp(label, "menu_toggle"))
|
||||||
snprintf(msg, sizeof_msg,
|
snprintf(msg, sizeof_msg,
|
||||||
" -- Toggles menu.");
|
" -- Toggles menu.");
|
||||||
|
else if (!strcmp(label, "input_bind_device_id"))
|
||||||
|
snprintf(msg, sizeof_msg,
|
||||||
|
" -- Input Device. \n"
|
||||||
|
" \n"
|
||||||
|
"Picks which gamepad to use for player N. \n"
|
||||||
|
"The name of the pad is available."
|
||||||
|
);
|
||||||
|
else if (!strcmp(label, "input_bind_device_type"))
|
||||||
|
snprintf(msg, sizeof_msg,
|
||||||
|
" -- Input Device Type. \n"
|
||||||
|
" \n"
|
||||||
|
"Picks which device type to use. This is \n"
|
||||||
|
"relevant for the libretro core itself."
|
||||||
|
);
|
||||||
else
|
else
|
||||||
snprintf(msg, sizeof_msg,
|
snprintf(msg, sizeof_msg,
|
||||||
"-- No info on this item is available. --\n");
|
"-- No info on this item is available. --\n");
|
||||||
@ -1732,6 +1746,58 @@ void setting_data_get_label(char *type_str,
|
|||||||
driver.menu->shader, type_str, type_str_size,
|
driver.menu->shader, type_str, type_str_size,
|
||||||
menu_label, label, type);
|
menu_label, label, type);
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(label, "input_bind_device_id"))
|
||||||
|
{
|
||||||
|
int map = g_settings.input.joypad_map
|
||||||
|
[driver.menu->current_pad];
|
||||||
|
if (map >= 0 && map < MAX_PLAYERS)
|
||||||
|
{
|
||||||
|
const char *device_name =
|
||||||
|
g_settings.input.device_names[map];
|
||||||
|
|
||||||
|
if (*device_name)
|
||||||
|
strlcpy(type_str, device_name, type_str_size);
|
||||||
|
else
|
||||||
|
snprintf(type_str, type_str_size,
|
||||||
|
"N/A (port #%d)", map);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
strlcpy(type_str, "Disabled", type_str_size);
|
||||||
|
}
|
||||||
|
else if (!strcmp(label, "input_bind_device_type"))
|
||||||
|
{
|
||||||
|
const struct retro_controller_description *desc = NULL;
|
||||||
|
if (driver.menu->current_pad < g_extern.system.num_ports)
|
||||||
|
desc = libretro_find_controller_description(
|
||||||
|
&g_extern.system.ports[driver.menu->current_pad],
|
||||||
|
g_settings.input.libretro_device
|
||||||
|
[driver.menu->current_pad]);
|
||||||
|
|
||||||
|
const char *name = desc ? desc->desc : NULL;
|
||||||
|
if (!name)
|
||||||
|
{
|
||||||
|
/* Find generic name. */
|
||||||
|
|
||||||
|
switch (g_settings.input.libretro_device
|
||||||
|
[driver.menu->current_pad])
|
||||||
|
{
|
||||||
|
case RETRO_DEVICE_NONE:
|
||||||
|
name = "None";
|
||||||
|
break;
|
||||||
|
case RETRO_DEVICE_JOYPAD:
|
||||||
|
name = "RetroPad";
|
||||||
|
break;
|
||||||
|
case RETRO_DEVICE_ANALOG:
|
||||||
|
name = "RetroPad w/ Analog";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
name = "Unknown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcpy(type_str, name, type_str_size);
|
||||||
|
}
|
||||||
else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN
|
else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN
|
||||||
&& type <= MENU_SETTINGS_PERF_COUNTERS_END)
|
&& type <= MENU_SETTINGS_PERF_COUNTERS_END)
|
||||||
menu_common_setting_set_label_perf(type_str, type_str_size, w, type,
|
menu_common_setting_set_label_perf(type_str, type_str_size, w, type,
|
||||||
@ -1806,25 +1872,6 @@ void setting_data_get_label(char *type_str,
|
|||||||
snprintf(type_str, type_str_size, "#%u",
|
snprintf(type_str, type_str_size, "#%u",
|
||||||
driver.menu->current_pad + 1);
|
driver.menu->current_pad + 1);
|
||||||
break;
|
break;
|
||||||
case MENU_SETTINGS_BIND_DEVICE:
|
|
||||||
{
|
|
||||||
int map = g_settings.input.joypad_map
|
|
||||||
[driver.menu->current_pad];
|
|
||||||
if (map >= 0 && map < MAX_PLAYERS)
|
|
||||||
{
|
|
||||||
const char *device_name =
|
|
||||||
g_settings.input.device_names[map];
|
|
||||||
|
|
||||||
if (*device_name)
|
|
||||||
strlcpy(type_str, device_name, type_str_size);
|
|
||||||
else
|
|
||||||
snprintf(type_str, type_str_size,
|
|
||||||
"N/A (port #%d)", map);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strlcpy(type_str, "Disabled", type_str_size);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MENU_SETTINGS_BIND_ANALOG_MODE:
|
case MENU_SETTINGS_BIND_ANALOG_MODE:
|
||||||
{
|
{
|
||||||
static const char *modes[] = {
|
static const char *modes[] = {
|
||||||
@ -1839,41 +1886,6 @@ void setting_data_get_label(char *type_str,
|
|||||||
type_str_size);
|
type_str_size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MENU_SETTINGS_BIND_DEVICE_TYPE:
|
|
||||||
{
|
|
||||||
const struct retro_controller_description *desc = NULL;
|
|
||||||
if (driver.menu->current_pad < g_extern.system.num_ports)
|
|
||||||
desc = libretro_find_controller_description(
|
|
||||||
&g_extern.system.ports[driver.menu->current_pad],
|
|
||||||
g_settings.input.libretro_device
|
|
||||||
[driver.menu->current_pad]);
|
|
||||||
|
|
||||||
const char *name = desc ? desc->desc : NULL;
|
|
||||||
if (!name)
|
|
||||||
{
|
|
||||||
/* Find generic name. */
|
|
||||||
|
|
||||||
switch (g_settings.input.libretro_device
|
|
||||||
[driver.menu->current_pad])
|
|
||||||
{
|
|
||||||
case RETRO_DEVICE_NONE:
|
|
||||||
name = "None";
|
|
||||||
break;
|
|
||||||
case RETRO_DEVICE_JOYPAD:
|
|
||||||
name = "RetroPad";
|
|
||||||
break;
|
|
||||||
case RETRO_DEVICE_ANALOG:
|
|
||||||
name = "RetroPad w/ Analog";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
name = "Unknown";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
strlcpy(type_str, name, type_str_size);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MENU_SETTINGS_CUSTOM_BIND_MODE:
|
case MENU_SETTINGS_CUSTOM_BIND_MODE:
|
||||||
strlcpy(type_str, driver.menu->bind_mode_keyboard ?
|
strlcpy(type_str, driver.menu->bind_mode_keyboard ?
|
||||||
"RetroKeyboard" : "RetroPad", type_str_size);
|
"RetroKeyboard" : "RetroPad", type_str_size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user