From ff9f433243bc17c814ac69b5f0f86a48c5ff6067 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 13 Feb 2016 06:30:39 +0100 Subject: [PATCH] Create CHEEVOS_CTL_GET_DESCRIPTION --- cheevos.c | 31 +++++++++++++++---------------- cheevos.h | 9 ++++++++- menu/drivers/menu_generic.c | 8 +++++++- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/cheevos.c b/cheevos.c index 5041e63315..f74c1dfddc 100644 --- a/cheevos.c +++ b/cheevos.c @@ -2146,22 +2146,6 @@ static void cheevos_populate_menu(void *data) } #endif -void cheevos_get_description(unsigned idx, char *str, size_t len) -{ - cheevo_t *cheevos = NULL; - - if (idx >= cheevos_locals.core.count) - { - cheevos = cheevos_locals.unofficial.cheevos; - idx -= cheevos_locals.unofficial.count; - } - else - cheevos = cheevos_locals.core.cheevos; - - strncpy(str, cheevos[idx].description, len); - str[len - 1] = 0; -} - bool cheevos_ctl(enum cheevos_ctl_state state, void *data) { static int cheats_are_enabled = 0; @@ -2170,6 +2154,21 @@ bool cheevos_ctl(enum cheevos_ctl_state state, void *data) switch (state) { + case CHEEVOS_CTL_GET_DESCRIPTION: + { + cheevos_ctx_desc_t *desc = (cheevos_ctx_desc_t*)data; + cheevo_t *cheevos = cheevos_locals.core.cheevos; + + if (desc->idx >= cheevos_locals.core.count) + { + cheevos = cheevos_locals.unofficial.cheevos; + desc->idx -= cheevos_locals.unofficial.count; + } + + strncpy(desc->s, cheevos[desc->idx].description, desc->len); + desc->s[desc->len - 1] = 0; + } + break; case CHEEVOS_CTL_APPLY_CHEATS: { bool *data_bool = (bool*)data; diff --git a/cheevos.h b/cheevos.h index 33939681b4..3058da7dd9 100644 --- a/cheevos.h +++ b/cheevos.h @@ -34,10 +34,17 @@ enum cheevos_ctl_state * the game has content. */ CHEEVOS_CTL_SET_CHEATS, + CHEEVOS_CTL_GET_DESCRIPTION, + CHEEVOS_CTL_POPULATE_MENU }; -void cheevos_get_description(unsigned idx, char *str, size_t len); +typedef struct cheevos_ctx_desc +{ + unsigned idx; + char *s; + size_t len; +} cheevos_ctx_desc_t; bool cheevos_ctl(enum cheevos_ctl_state state, void *data); diff --git a/menu/drivers/menu_generic.c b/menu/drivers/menu_generic.c index fb1e2085a9..ef1cd72963 100644 --- a/menu/drivers/menu_generic.c +++ b/menu/drivers/menu_generic.c @@ -38,6 +38,9 @@ static int action_iterate_help(menu_handle_t *menu, char *s, size_t len, const char *label) { +#ifdef HAVE_CHEEVOS + cheevos_ctx_desc_t desc_info; +#endif bool do_exit = false; settings_t *settings = config_get_ptr(); @@ -172,7 +175,10 @@ static int action_iterate_help(menu_handle_t *menu, #ifdef HAVE_CHEEVOS case MENU_HELP_CHEEVOS_DESCRIPTION: - cheevos_get_description(menu->help_screen_id, s, len); + desc_info.idx = menu->help_screen_id; + desc_info.s = s; + desc_info.len = len; + cheevos_ctl(CHEEVOS_CTL_GET_DESCRIPTION, &desc_info); break; #endif