simplify badge handling; remember enablement if XMB not available

This commit is contained in:
Jamiras 2020-02-23 10:38:27 -07:00
parent 8d6c7d6753
commit 5ecc426741
8 changed files with 74 additions and 99 deletions

View File

@ -14,60 +14,63 @@
*/ */
#include <file/file_path.h> #include <file/file_path.h>
#include <string/stdstring.h>
#ifdef HAVE_MENU
#include "../menu/menu_driver.h"
#endif
#include "../file_path_special.h" #include "../file_path_special.h"
#include "../configuration.h" #include "../configuration.h"
#include "../verbosity.h" #include "../gfx/gfx_display.h"
#include "../network/net_http_special.h"
#include "badges.h" #include "badges.h"
badges_ctx_t badges_ctx;
bool badge_exists(const char* filepath)
{
return path_is_valid(filepath);
}
void set_badge_menu_texture(badges_ctx_t * badges, int i)
{
char badge_file[16];
char fullpath[PATH_MAX_LENGTH];
snprintf(badge_file, sizeof(badge_file), "%s%s", badges->badge_id_list[i],
badges->badge_locked[i] ? "_lock.png" : ".png");
fill_pathname_application_special(fullpath,
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES);
#ifdef HAVE_MENU #ifdef HAVE_MENU
gfx_display_reset_textures_list(badge_file, fullpath,
&badges->menu_texture_list[i],TEXTURE_FILTER_MIPMAP_LINEAR, NULL, NULL);
#endif
}
void set_badge_info (badges_ctx_t *badge_struct, int id, #define CHEEVOS_MENU_BADGE_LIMIT 256
const char *badge_id, bool active) static uintptr_t cheevos_badge_menu_texture_list[CHEEVOS_MENU_BADGE_LIMIT] = { 0 };
void cheevos_reset_menu_badges(void)
{ {
if (!badge_struct) memset(&cheevos_badge_menu_texture_list, 0, sizeof(cheevos_badge_menu_texture_list));
return;
badge_struct->badge_id_list[id] = badge_id;
badge_struct->badge_locked[id] = active;
set_badge_menu_texture(badge_struct, id);
} }
uintptr_t get_badge_texture(int id) void cheevos_set_menu_badge(int index, const char *badge, bool locked)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
if (!settings || !settings->bools.cheevos_badges_enable)
return (uintptr_t)NULL;
return badges_ctx.menu_texture_list[id]; if (index >= CHEEVOS_MENU_BADGE_LIMIT)
return;
if (!settings || !settings->bools.cheevos_badges_enable)
cheevos_badge_menu_texture_list[index] = 0;
else
cheevos_badge_menu_texture_list[index] = cheevos_get_badge_texture(badge, locked);
}
uintptr_t cheevos_get_menu_badge_texture(int index)
{
if (index < CHEEVOS_MENU_BADGE_LIMIT)
return cheevos_badge_menu_texture_list[index];
return 0;
}
#endif
uintptr_t cheevos_get_badge_texture(const char *badge, bool locked)
{
char badge_file[24];
char fullpath[PATH_MAX_LENGTH];
uintptr_t tex;
if (!badge)
return 0;
snprintf(badge_file, sizeof(badge_file), "%s%s.png", badge, locked ? "_lock" : "");
fill_pathname_application_special(fullpath,
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES);
gfx_display_reset_textures_list(badge_file, fullpath,
&tex, TEXTURE_FILTER_MIPMAP_LINEAR, NULL, NULL);
return tex;
} }

View File

@ -22,26 +22,13 @@
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
#define CHEEVOS_BADGE_LIMIT 256 #ifdef HAVE_MENU
void cheevos_reset_menu_badges(void);
void cheevos_set_menu_badge(int index, const char *badge, bool locked);
uintptr_t cheevos_get_menu_badge_texture(int index);
#endif
typedef struct uintptr_t cheevos_get_badge_texture(const char* badge, bool locked);
{
bool badge_locked[CHEEVOS_BADGE_LIMIT];
const char * badge_id_list[CHEEVOS_BADGE_LIMIT];
uintptr_t menu_texture_list[CHEEVOS_BADGE_LIMIT];
} badges_ctx_t;
bool badge_exists(const char* filepath);
void set_badge_menu_texture(badges_ctx_t * badges, int i);
void set_badge_info(badges_ctx_t *badge_struct,
int id, const char *badge_id, bool active);
uintptr_t get_badge_texture(int id);
extern badges_ctx_t badges_ctx;
static badges_ctx_t new_badges_ctx;
RETRO_END_DECLS RETRO_END_DECLS

View File

@ -1147,7 +1147,7 @@ static void rcheevos_append_menu_achievement(menu_displaylist_info_t* info, size
cheevo->info->description, enum_idx, cheevo->info->description, enum_idx,
MENU_SETTINGS_CHEEVOS_START + idx, 0, 0); MENU_SETTINGS_CHEEVOS_START + idx, 0, 0);
set_badge_info(&badges_ctx, idx, cheevo->info->badge, active); cheevos_set_menu_badge(idx, cheevo->info->badge, active);
} }
#endif #endif
@ -2473,8 +2473,6 @@ found:
*************************************************************************/ *************************************************************************/
CORO_SUB(RCHEEVOS_GET_BADGES) CORO_SUB(RCHEEVOS_GET_BADGES)
badges_ctx = new_badges_ctx;
#if defined(HAVE_GFX_WIDGETS) #if defined(HAVE_GFX_WIDGETS)
if (false) /* we always want badges if menu widgets are enabled */ if (false) /* we always want badges if menu widgets are enabled */
#endif #endif
@ -2488,6 +2486,10 @@ found:
CORO_RET(); CORO_RET();
} }
#ifdef HAVE_MENU
cheevos_reset_menu_badges();
#endif
for (coro->i = 0; coro->i < 2; coro->i++) for (coro->i = 0; coro->i < 2; coro->i++)
{ {
if (coro->i == 0) if (coro->i == 0)
@ -2533,7 +2535,7 @@ found:
coro->badge_name, coro->badge_name,
sizeof(coro->badge_fullpath)); sizeof(coro->badge_fullpath));
if (!badge_exists(coro->badge_fullpath)) if (!path_is_valid(coro->badge_fullpath))
{ {
#ifdef CHEEVOS_LOG_BADGES #ifdef CHEEVOS_LOG_BADGES
CHEEVOS_LOG( CHEEVOS_LOG(

View File

@ -1588,10 +1588,8 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
SETTING_BOOL("cheevos_richpresence_enable", &settings->bools.cheevos_richpresence_enable, true, true, false); SETTING_BOOL("cheevos_richpresence_enable", &settings->bools.cheevos_richpresence_enable, true, true, false);
SETTING_BOOL("cheevos_verbose_enable", &settings->bools.cheevos_verbose_enable, true, false, false); SETTING_BOOL("cheevos_verbose_enable", &settings->bools.cheevos_verbose_enable, true, false, false);
SETTING_BOOL("cheevos_auto_screenshot", &settings->bools.cheevos_auto_screenshot, true, false, false); SETTING_BOOL("cheevos_auto_screenshot", &settings->bools.cheevos_auto_screenshot, true, false, false);
#ifdef HAVE_XMB
SETTING_BOOL("cheevos_badges_enable", &settings->bools.cheevos_badges_enable, true, false, false); SETTING_BOOL("cheevos_badges_enable", &settings->bools.cheevos_badges_enable, true, false, false);
#endif #endif
#endif
#ifdef HAVE_OVERLAY #ifdef HAVE_OVERLAY
SETTING_BOOL("input_overlay_enable", &settings->bools.input_overlay_enable, true, config_overlay_enable_default(), false); SETTING_BOOL("input_overlay_enable", &settings->bools.input_overlay_enable, true, config_overlay_enable_default(), false);
SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, true, false); SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, true, false);

View File

@ -34,6 +34,10 @@
#include "../tasks/task_content.h" #include "../tasks/task_content.h"
#ifdef HAVE_CHEEVOS
#include "../cheevos-new/badges.h"
#endif
/* TODO: Fix context reset freezing everything in place (probably kills animations when it shouldn't anymore) */ /* TODO: Fix context reset freezing everything in place (probably kills animations when it shouldn't anymore) */
static float msg_queue_background[16] = COLOR_HEX_TO_FLOAT(0x3A3A3A, 1.0f); static float msg_queue_background[16] = COLOR_HEX_TO_FLOAT(0x3A3A3A, 1.0f);
@ -2540,28 +2544,6 @@ static void gfx_widgets_start_achievement_notification(void)
gfx_animation_push(&entry); gfx_animation_push(&entry);
} }
static void gfx_widgets_get_badge_texture(
uintptr_t *tex, const char *badge)
{
char badge_file[16];
char fullpath[PATH_MAX_LENGTH];
if (!badge)
{
*tex = 0;
return;
}
strlcpy(badge_file, badge, sizeof(badge_file));
strlcat(badge_file, ".png", sizeof(badge_file));
fill_pathname_application_special(fullpath,
PATH_MAX_LENGTH * sizeof(char),
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES);
gfx_display_reset_textures_list(badge_file, fullpath,
tex, TEXTURE_FILTER_MIPMAP_LINEAR, NULL, NULL);
}
void gfx_widgets_push_achievement(const char *title, const char *badge) void gfx_widgets_push_achievement(const char *title, const char *badge)
{ {
gfx_widgets_achievement_free(NULL); gfx_widgets_achievement_free(NULL);
@ -2569,7 +2551,7 @@ void gfx_widgets_push_achievement(const char *title, const char *badge)
/* TODO: Make a queue of notifications to display */ /* TODO: Make a queue of notifications to display */
cheevo_title = strdup(title); cheevo_title = strdup(title);
gfx_widgets_get_badge_texture(&cheevo_badge, badge); cheevo_badge = cheevos_get_badge_texture(badge, 0);
gfx_widgets_start_achievement_notification(); gfx_widgets_start_achievement_notification();
} }

View File

@ -412,9 +412,10 @@ uintptr_t ozone_entries_icon_get_texture(ozone_handle_t *ozone,
(type < MENU_SETTINGS_NETPLAY_ROOMS_START) (type < MENU_SETTINGS_NETPLAY_ROOMS_START)
) )
{ {
int new_id = type - MENU_SETTINGS_CHEEVOS_START; int index = type - MENU_SETTINGS_CHEEVOS_START;
if (get_badge_texture(new_id) != 0) uintptr_t badge_texture = cheevos_get_menu_badge_texture(index);
return get_badge_texture(new_id); if (badge_texture)
return badge_texture;
/* Should be replaced with placeholder badge icon. */ /* Should be replaced with placeholder badge icon. */
return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_ACHIEVEMENTS]; return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_ACHIEVEMENTS];
} }

View File

@ -2270,9 +2270,10 @@ static uintptr_t stripes_icon_get_id(stripes_handle_t *stripes,
(type < MENU_SETTINGS_NETPLAY_ROOMS_START) (type < MENU_SETTINGS_NETPLAY_ROOMS_START)
) )
{ {
int new_id = type - MENU_SETTINGS_CHEEVOS_START; int index = type - MENU_SETTINGS_CHEEVOS_START;
if (get_badge_texture(new_id) != 0) uintptr_t badge_texture = cheevos_get_menu_badge_texture(index);
return get_badge_texture(new_id); if (badge_texture)
return badge_texture;
/* Should be replaced with placeholder badge icon. */ /* Should be replaced with placeholder badge icon. */
return stripes->textures.list[STRIPES_TEXTURE_SUBSETTING]; return stripes->textures.list[STRIPES_TEXTURE_SUBSETTING];
} }

View File

@ -2711,9 +2711,10 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb,
(type < MENU_SETTINGS_NETPLAY_ROOMS_START) (type < MENU_SETTINGS_NETPLAY_ROOMS_START)
) )
{ {
int new_id = type - MENU_SETTINGS_CHEEVOS_START; int index = type - MENU_SETTINGS_CHEEVOS_START;
if (get_badge_texture(new_id) != 0) uintptr_t badge_texture = cheevos_get_menu_badge_texture(index);
return get_badge_texture(new_id); if (badge_texture)
return badge_texture;
/* Should be replaced with placeholder badge icon. */ /* Should be replaced with placeholder badge icon. */
return xmb->textures.list[XMB_TEXTURE_ACHIEVEMENTS]; return xmb->textures.list[XMB_TEXTURE_ACHIEVEMENTS];
} }