From 1430917c8b614eae086952a9babb0919cbfde776 Mon Sep 17 00:00:00 2001 From: Tom Pritchard Date: Fri, 15 Nov 2024 11:20:31 +0000 Subject: [PATCH] Add optional game count text (#1362) * Add optional game count text theme option only --- lng_tmpl/_base.yml | 2 ++ src/opl.c | 2 +- src/themes.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lng_tmpl/_base.yml b/lng_tmpl/_base.yml index 6ed89c347..2ad5f52d0 100644 --- a/lng_tmpl/_base.yml +++ b/lng_tmpl/_base.yml @@ -688,3 +688,5 @@ gui_strings: string: Analog X-Axis Sensitivity - label: YSENSITIVITY string: Analog Y-Axis Sensitivity +- label: FILE_COUNT + string: 'Files found: %i' diff --git a/src/opl.c b/src/opl.c index 290b9638f..cd6098353 100644 --- a/src/opl.c +++ b/src/opl.c @@ -893,7 +893,7 @@ static void _loadConfig() if (!(getKeyPressed(KEY_TRIANGLE) && getKeyPressed(KEY_CROSS))) { configGetInt(configOPL, CONFIG_OPL_VMODE, &gVMode); } else { - LOG("--- Select held at boot - setting Video Mode to Auto ---\n"); + LOG("--- Triangle + Cross held at boot - setting Video Mode to Auto ---\n"); gVMode = 0; configSetInt(configOPL, CONFIG_OPL_VMODE, gVMode); } diff --git a/src/themes.c b/src/themes.c index 2e5a58649..f3ccdb4f1 100644 --- a/src/themes.c +++ b/src/themes.c @@ -47,7 +47,7 @@ enum ELEM_ATTRIBUTE_TYPE { ELEM_TYPE_INFO_HINT_TEXT, ELEM_TYPE_LOADING_ICON, ELEM_TYPE_BDM_INDEX, - + ELEM_TYPE_GAME_COUNT_TEXT, ELEM_TYPE_COUNT }; @@ -76,7 +76,7 @@ static const char *elementsType[ELEM_TYPE_COUNT] = { "InfoHintText", "LoadingIcon", "BdmIndex", -}; + "GameCountText"}; // Common functions for Text //////////////////////////////////////////////////////////////////////////////////////////////// @@ -198,6 +198,42 @@ static void initStaticText(const char *themePath, config_set_t *themeConfig, the LOG("THEMES StaticText %s: NO value, elem disabled !!\n", name); } +// GameCountText //////////////////////////////////////////////////////////////////////////////////////////////////////////// + +static int getGameCount(void *support) +{ + item_list_t *list = (item_list_t *)support; + return list->itemGetCount(list); +} + +static void drawGameCountText(struct menu_list *menu, struct submenu_list *item, config_set_t *config, struct theme_element *elem) +{ + mutable_text_t *mutableText = (mutable_text_t *)elem->extended; + + if (config) { + if (mutableText->currentConfigId != config->uid) { + // force refresh + mutableText->currentConfigId = config->uid; + + int count = getGameCount(menu->item->userdata); + snprintf(mutableText->value, sizeof(char) * 60, _l(_STR_FILE_COUNT), count); + } + } + + fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, 0, 0, mutableText->value, elem->color); +} + +static void initGameCountText(const char *themePath, config_set_t *themeConfig, theme_t *theme, theme_element_t *elem, const char *name) +{ + int length = 60; + char *countStr = (char *)malloc(length * sizeof(char)); + memset(countStr, 0, length * sizeof(char)); + + elem->extended = initMutableText(themePath, themeConfig, theme, name, ELEM_TYPE_ATTRIBUTE_TEXT, elem, countStr, NULL, DISPLAY_ALWAYS, SIZING_NONE); + elem->endElem = &endMutableText; + elem->drawElem = &drawGameCountText; +} + // AttributeText //////////////////////////////////////////////////////////////////////////////////////////////////////////// static void drawAttributeText(struct menu_list *menu, struct submenu_list *item, config_set_t *config, struct theme_element *elem) @@ -990,6 +1026,9 @@ static int addGUIElem(const char *themePath, config_set_t *themeConfig, theme_t } else if (!strcmp(elementsType[ELEM_TYPE_STATIC_TEXT], type)) { elem = initBasic(themePath, themeConfig, theme, name, ELEM_TYPE_STATIC_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]); initStaticText(themePath, themeConfig, theme, elem, name); + } else if (!strcmp(elementsType[ELEM_TYPE_GAME_COUNT_TEXT], type)) { + elem = initBasic(themePath, themeConfig, theme, name, ELEM_TYPE_STATIC_TEXT, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, theme->textColor, theme->fonts[0]); + initGameCountText(themePath, themeConfig, theme, elem, name); } else if (!strcmp(elementsType[ELEM_TYPE_ATTRIBUTE_IMAGE], type)) { elem = initBasic(themePath, themeConfig, theme, name, ELEM_TYPE_ATTRIBUTE_IMAGE, 0, 0, ALIGN_CENTER, DIM_UNDEF, DIM_UNDEF, SCALING_RATIO, gDefaultCol, theme->fonts[0]); initAttributeImage(themePath, themeConfig, theme, elem, name);