(Menu) Implement action_start callback as well

This commit is contained in:
twinaphex 2014-10-12 20:11:45 +02:00
parent 0245be3193
commit bbb28c06e6
3 changed files with 54 additions and 22 deletions

View File

@ -9,6 +9,7 @@ typedef struct menu_file_list_cbs
{ {
int (*action_ok)(const char *path, const char *label, unsigned type, int (*action_ok)(const char *path, const char *label, unsigned type,
size_t index); size_t index);
int (*action_start)(unsigned type, const char *label, unsigned action);
int (*action_toggle)(unsigned type, const char *label, unsigned action); int (*action_toggle)(unsigned type, const char *label, unsigned action);
} menu_file_list_cbs_t; } menu_file_list_cbs_t;

View File

@ -215,30 +215,15 @@ static int menu_start_screen_iterate(unsigned action)
} }
static int menu_setting_start_pressed(unsigned type, static int menu_setting_start_pressed(unsigned type,
const char *dir, const char *label, const char *label, unsigned action)
unsigned action)
{ {
if (type >= MENU_SETTINGS_BIND_BEGIN && menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)
type <= MENU_SETTINGS_BIND_ALL_LAST) file_list_get_actiondata_at_offset(driver.menu->selection_buf,
{ driver.menu->selection_ptr);
struct retro_keybind *bind = (struct retro_keybind*)
&g_settings.input.binds[driver.menu->current_pad]
[type - MENU_SETTINGS_BIND_BEGIN];
if (driver.menu->bind_mode_keyboard) if (cbs && cbs->action_start)
{ return cbs->action_start(type, label, action);
const struct retro_keybind *def_binds = driver.menu->current_pad ?
retro_keybinds_rest : retro_keybinds_1;
bind->key = def_binds[type - MENU_SETTINGS_BIND_BEGIN].key;
}
else
{
bind->joykey = NO_BTN;
bind->joyaxis = AXIS_NONE;
}
return 0;
}
return -1; return -1;
} }
@ -300,7 +285,7 @@ static int menu_settings_iterate(unsigned action)
return 0; return 0;
/* fall-through */ /* fall-through */
case MENU_ACTION_START: case MENU_ACTION_START:
if (menu_setting_start_pressed(type, path, label, action) == 0) if (menu_setting_start_pressed(type, label, action) == 0)
return 0; return 0;
/* fall-through */ /* fall-through */
case MENU_ACTION_LEFT: case MENU_ACTION_LEFT:

View File

@ -653,6 +653,38 @@ static int core_setting_toggle(unsigned type, const char *label,
return 0; return 0;
} }
static int action_start_bind(unsigned type, const char *label,
unsigned action)
{
struct retro_keybind *def_binds = (struct retro_keybind *)retro_keybinds_1;
struct retro_keybind *bind = (struct retro_keybind*)
&g_settings.input.binds[driver.menu->current_pad]
[type - MENU_SETTINGS_BIND_BEGIN];
if (!bind)
return -1;
(void)label;
(void)action;
if (!driver.menu->bind_mode_keyboard)
{
bind->joykey = NO_BTN;
bind->joyaxis = AXIS_NONE;
return 0;
}
if (driver.menu->current_pad)
def_binds = (struct retro_keybind*)retro_keybinds_rest;
if (!def_binds)
return -1;
bind->key = def_binds[type - MENU_SETTINGS_BIND_BEGIN].key;
return 0;
}
/* Bind the OK callback function */ /* Bind the OK callback function */
static int menu_entries_cbs_init_bind_ok_first(menu_file_list_cbs_t *cbs, static int menu_entries_cbs_init_bind_ok_first(menu_file_list_cbs_t *cbs,
@ -740,6 +772,19 @@ static int menu_entries_cbs_init_bind_ok_first(menu_file_list_cbs_t *cbs,
return 0; return 0;
} }
static void menu_entries_cbs_init_bind_start(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t index)
{
if (!cbs)
return;
cbs->action_start = NULL;
if (type >= MENU_SETTINGS_BIND_BEGIN &&
type <= MENU_SETTINGS_BIND_ALL_LAST)
cbs->action_start = action_start_bind;
}
static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t index) const char *path, const char *label, unsigned type, size_t index)
{ {
@ -825,6 +870,7 @@ void menu_entries_cbs_init(void *data,
if (cbs) if (cbs)
{ {
menu_entries_cbs_init_bind_ok(cbs, path, label, type, index); menu_entries_cbs_init_bind_ok(cbs, path, label, type, index);
menu_entries_cbs_init_bind_start(cbs, path, label, type, index);
menu_entries_cbs_init_bind_toggle(cbs, path, label, type, index); menu_entries_cbs_init_bind_toggle(cbs, path, label, type, index);
} }
} }