Skip to content

Commit

Permalink
gui: try to standardise hint strings, add theme option to center alig…
Browse files Browse the repository at this point in the history
…n hints
  • Loading branch information
KrahJohlito committed Oct 19, 2019
1 parent 6f167c7 commit a881747
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 13 deletions.
4 changes: 4 additions & 0 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ void guiUpdateScreenScale(void);

void guiDrawBGPlasma();
int guiDrawIconAndText(int iconId, int textId, int font, int x, int y, u64 color);
void guiDrawSubMenuHints(void);

int guiAlignMenuHints(menu_hint_item_t *hint, int font, int width);
int guiAlignSubMenuHints(int hintCount, int *textID, int *iconID, int font, int width, int align);

void guiShowNetCompatUpdate(void);
void guiShowNetCompatUpdateSingle(int id, item_list_t *support, config_set_t *configSet);
Expand Down
1 change: 1 addition & 0 deletions include/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ enum _STR_IDS {
_STR_GAME_MENU,
_STR_GAME_SETTINGS_SAVED,
_STR_GAME_SETTINGS_REMOVED,
_STR_NET_UPDATE_HINT,

LANG_STR_COUNT
};
Expand Down
5 changes: 3 additions & 2 deletions lng/lang_English.lng
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Error: failed to load cheat file.
No cheats found.
Download Defaults
Network Update
Redownload existing records?
Overwrite Existing Records
Update failed.
Failed to connect to update server.
Update completed.
Expand Down Expand Up @@ -288,4 +288,5 @@ Enable Notifications
%s loaded from %s
Game Menu
Game settings saved.
Game settings removed.
Game settings removed.
Overwrites existing game compatibility settings when enabled.
3 changes: 1 addition & 2 deletions misc/conf_theme_OPL.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,4 @@ info7:
info8:
type=InfoHintText
color=#E6E6E6
x=272
y=-28
aligned=1
12 changes: 9 additions & 3 deletions src/dia.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static void diaDrawHint(int text_id)

// the width of the hint text string will be scaled by the Vmode, we need to unscale it.
x = screenWidth - rmUnScaleX(fntCalcDimensions(gTheme->fonts[0], text)) - 10;
y = gTheme->usedHeight - 40;
y = gTheme->usedHeight - 62;

// render hint on the lower side of the screen.
rmDrawRect(x, y, screenWidth - x, MENU_ITEM_HEIGHT + 10, gColDarker);
Expand Down Expand Up @@ -611,8 +611,14 @@ void diaRenderUI(struct UIItem *ui, short inMenu, struct UIItem *cur, int haveFo
diaDrawHint(cur->hintId);
}

guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CIRCLE_ICON : CROSS_ICON, _STR_SELECT, gTheme->fonts[0], 420, 417, gTheme->selTextColor);
guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CROSS_ICON : CIRCLE_ICON, _STR_BACK, gTheme->fonts[0], 500, 417, gTheme->selTextColor);
int uiHints[2] = {_STR_SELECT, _STR_BACK};
int uiIcons[2] = {CIRCLE_ICON, CROSS_ICON};
int uiY = gTheme->usedHeight - 32;
int uiX = guiAlignSubMenuHints(2, uiHints, uiIcons, gTheme->fonts[0], 12, 2);

uiX = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? uiIcons[0] : uiIcons[1], uiHints[0], gTheme->fonts[0], uiX, uiY, gTheme->textColor);
uiX += 12;
uiX = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? uiIcons[1] : uiIcons[0], uiHints[1], gTheme->fonts[0], uiX, uiY, gTheme->textColor);
}

/// sets the ui item value to the default again
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ struct UIItem diaNetCompatUpdate[] = {

{UI_LABEL, NETUPD_OPT_UPD_ALL_LBL, 1, 1, -1, -40, 0, {.label = {NULL, _STR_NET_UPDATE_ALL}}},
{UI_SPACER},
{UI_BOOL, NETUPD_OPT_UPD_ALL, 0, 1, -1, 0, 0, {.intvalue = {0, 0, 0, 1}}},
{UI_BOOL, NETUPD_OPT_UPD_ALL, 0, 1, _STR_NET_UPDATE_HINT, 0, 0, {.intvalue = {0, 0, 0, 1}}},
{UI_BREAK},

{UI_LABEL, NETUPD_PROGRESS_LBL, 1, 1, -1, -40, 0, {.label = {NULL, _STR_VMC_PROGRESS}}},
Expand Down
60 changes: 60 additions & 0 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,66 @@ int guiDrawIconAndText(int iconId, int textId, int font, int x, int y, u64 color
return x;
}

int guiAlignMenuHints(menu_hint_item_t *hint, int font, int width)
{
int x = screenWidth;
int w;

for (; hint; hint = hint->next) {
GSTEXTURE *iconTex = thmGetTexture(hint->icon_id);
w = (iconTex->Width * 20) / iconTex->Height;
char *text = _l(hint->text_id);

x -= rmWideScale(w) + 2;
x -= rmUnScaleX(fntCalcDimensions(font, text));
if (hint->next != NULL)
x -= width;
}

// align center
x /= 2;

return x;
}

int guiAlignSubMenuHints(int hintCount, int *textID, int *iconID, int font, int width, int align)
{
int x = screenWidth;
int i, w;

for (i = 0; i < hintCount; i++) {
GSTEXTURE *iconTex = thmGetTexture(iconID[i]);
w = (iconTex->Width * 20) / iconTex->Height;
char *text = _l(textID[i]);

x -= rmWideScale(w) + 2;
x -= rmUnScaleX(fntCalcDimensions(font, text));
if (i != (hintCount - 1))
x -= width;
}

if (align == 1) // align center
x /= 2;

if (align == 2) // align right
x -= 20;

return x;
}

void guiDrawSubMenuHints(void)
{
int subMenuHints[2] = {_STR_SELECT, _STR_GAMES_LIST};
int subMenuIcons[2] = {CROSS_ICON, CIRCLE_ICON};

int x = guiAlignSubMenuHints(2, subMenuHints, subMenuIcons, gTheme->fonts[0], 12, 2);
int y = gTheme->usedHeight - 32;

x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? subMenuIcons[1] : subMenuIcons[0], subMenuHints[0], gTheme->fonts[0], x, y, gTheme->textColor);
x += 12;
x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? subMenuIcons[0] : subMenuIcons[1], subMenuHints[1], gTheme->fonts[0], x, y, gTheme->textColor);
}

static void guiDrawOverlays()
{
// are there any pending operations?
Expand Down
3 changes: 2 additions & 1 deletion src/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static char *internalEnglish[LANG_STR_COUNT] = {
"No cheats found.",
"Download Defaults",
"Network Update",
"Redownload existing records?",
"Overwrite Existing Records",
"Update failed.",
"Failed to connect to update server.",
"Update completed.",
Expand Down Expand Up @@ -275,6 +275,7 @@ static char *internalEnglish[LANG_STR_COUNT] = {
"Game Menu",
"Game settings saved.",
"Game settings removed.",
"Overwrites existing game compatibility settings when enabled.",
};

static int guiLangID = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/menusys.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ void menuRenderMenu()
y += spacing;
}

guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CROSS_ICON : CIRCLE_ICON, _STR_GAMES_LIST, gTheme->fonts[0], 500, 417, gTheme->selTextColor);
//hints
guiDrawSubMenuHints();
}

int menuSetParentalLockCheckState(int enabled)
Expand Down Expand Up @@ -988,7 +989,8 @@ void menuRenderGameMenu()
y += spacing;
}

guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CROSS_ICON : CIRCLE_ICON, _STR_GAMES_LIST, gTheme->fonts[0], 500, 417, gTheme->selTextColor);
//hints
guiDrawSubMenuHints();
}

void menuHandleInputGameMenu()
Expand Down
13 changes: 11 additions & 2 deletions src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ static void drawHintText(struct menu_list *menu, struct submenu_list *item, conf
if (hint) {
int x = elem->posX;

if (elem->aligned)
x = guiAlignMenuHints(hint, elem->font, elem->width);

for (; hint; hint = hint->next) {
x = guiDrawIconAndText(hint->icon_id, hint->text_id, elem->font, x, elem->posY, elem->color);
x += elem->width;
Expand All @@ -789,10 +792,16 @@ static void drawHintText(struct menu_list *menu, struct submenu_list *item, conf

static void drawInfoHintText(struct menu_list *menu, struct submenu_list *item, config_set_t *config, struct theme_element *elem)
{
int infoHints[2] = {_STR_RUN, _STR_BACK};
int infoIcons[2] = {CIRCLE_ICON, CROSS_ICON};
int x = elem->posX;
x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CIRCLE_ICON : CROSS_ICON, _STR_RUN, elem->font, x, elem->posY, elem->color);

if (elem->aligned)
x = guiAlignSubMenuHints(2, infoHints, infoIcons, elem->font, elem->width, 1);

x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? infoIcons[0] : infoIcons[1], infoHints[0], elem->font, x, elem->posY, elem->color);
x += elem->width;
x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? CROSS_ICON : CIRCLE_ICON, _STR_BACK, elem->font, x, elem->posY, elem->color);
x = guiDrawIconAndText(gSelectButton == KEY_CIRCLE ? infoIcons[1] : infoIcons[0], infoHints[1], elem->font, x, elem->posY, elem->color);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit a881747

Please sign in to comment.