Skip to content

Commit

Permalink
Add optional game count text (#1362)
Browse files Browse the repository at this point in the history
* Add optional game count text theme option only
  • Loading branch information
Pritchy96 authored Nov 15, 2024
1 parent 0032c50 commit 1430917
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lng_tmpl/_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
43 changes: 41 additions & 2 deletions src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -76,7 +76,7 @@ static const char *elementsType[ELEM_TYPE_COUNT] = {
"InfoHintText",
"LoadingIcon",
"BdmIndex",
};
"GameCountText"};

// Common functions for Text ////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1430917

Please sign in to comment.