Skip to content

Commit

Permalink
Reduce notifications code (#12)
Browse files Browse the repository at this point in the history
* sfx: code clean up

* lng: fix font not being rendered if loading translations at boot from a device other than MC, and if lang is changed by manually initalising a device

* gui: add notifications

* gui: reduce notifications code
  • Loading branch information
KrahJohlito authored and Tupakaveli committed Sep 22, 2019
1 parent 2f8cc62 commit 8837305
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions src/gui.c
Expand Up @@ -264,13 +264,26 @@ static void guiResetNotifications(void)
showLngPopup = 0;
}

static void guiShowNotifications(void)
static void guiRenderNotifications(char *type, char *path, int y)
{
char notification[32];
char *col_pos;
int x;

snprintf(notification, sizeof(notification), _l(_STR_NOTIFICATIONS), type, path);
if ((col_pos = strchr(notification, ':')) != NULL)
*(col_pos + 1) = '\0';

x = screenWidth - rmUnScaleX(fntCalcDimensions(gTheme->fonts[0], notification)) - 10;

rmDrawRect(x, y, screenWidth - x, MENU_ITEM_HEIGHT + 10, gColDarker);
fntRenderString(gTheme->fonts[0], x + 5, y + 5, ALIGN_NONE, 0, 0, notification, gTheme->textColor);
}

static void guiShowNotifications(void)
{
int y = 10;
int yadd = 35;
char notification[32];
char *col_pos;

if (showThmPopup || showLngPopup || showCfgPopup)
popupTimer++;
Expand All @@ -280,43 +293,18 @@ static void guiShowNotifications(void)
popupSfxPlayed = 1;
}

if (showCfgPopup && popupTimer >= 20) {
char *path = configGetDir();
snprintf(notification, sizeof(notification), _l(_STR_NOTIFICATIONS), "CFG", path);
if ((col_pos = strchr(notification, ':')) != NULL)
*(col_pos + 1) = '\0';

x = screenWidth - rmUnScaleX(fntCalcDimensions(gTheme->fonts[0], notification)) - 10;
if (showCfgPopup && popupTimer >= 20)
guiRenderNotifications("CFG", configGetDir(), y);

rmDrawRect(x, y, screenWidth - x, MENU_ITEM_HEIGHT + 10, gColDarker);
fntRenderString(gTheme->fonts[0], x + 5, y + 5, ALIGN_NONE, 0, 0, notification, gTheme->textColor);
}
y += yadd;

if (showThmPopup && popupTimer >= 20) {
char *path = thmGetFilePath(thmGetGuiValue());
snprintf(notification, sizeof(notification), _l(_STR_NOTIFICATIONS), "THM", path);
if ((col_pos = strchr(notification, ':')) != NULL)
*(col_pos + 1) = '\0';

x = screenWidth - rmUnScaleX(fntCalcDimensions(gTheme->fonts[0], notification)) - 10;
if (showThmPopup && popupTimer >= 20)
guiRenderNotifications("THM", thmGetFilePath(thmGetGuiValue()), y);

rmDrawRect(x, y, screenWidth - x, MENU_ITEM_HEIGHT + 10, gColDarker);
fntRenderString(gTheme->fonts[0], x + 5, y + 5, ALIGN_NONE, 0, 0, notification, gTheme->textColor);
}
y += yadd;

if (showLngPopup && popupTimer >= 20) {
char *path = lngGetFilePath(lngGetGuiValue());
snprintf(notification, sizeof(notification), _l(_STR_NOTIFICATIONS), "LNG", path);
if ((col_pos = strchr(notification, ':')) != NULL)
*(col_pos + 1) = '\0';

x = screenWidth - rmUnScaleX(fntCalcDimensions(gTheme->fonts[0], notification)) - 10;

rmDrawRect(x, y, screenWidth - x, MENU_ITEM_HEIGHT + 10, gColDarker);
fntRenderString(gTheme->fonts[0], x + 5, y + 5, ALIGN_NONE, 0, 0, notification, gTheme->textColor);
}
if (showLngPopup && popupTimer >= 20)
guiRenderNotifications("LNG", lngGetFilePath(lngGetGuiValue()), y);

if (popupTimer >= CLOCKS_PER_SEC / 2000) {
guiResetNotifications();
Expand Down

0 comments on commit 8837305

Please sign in to comment.