Add starred favourites at start of list (#91)
* Add starred favourites at start of list
This commit is contained in:
parent
dcad6f2afa
commit
d6c780256f
@ -43,6 +43,10 @@ static bool FontSetType(u32 font)
|
||||
case interuimedium30:
|
||||
scale = 8;
|
||||
break;
|
||||
|
||||
case largestar:
|
||||
scale = 18;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
@ -43,3 +43,4 @@ extern const ffnt_header_t interuiregular18_nxfnt;*/
|
||||
#define interuiregular14 0//&interuiregular14_nxfnt
|
||||
#define interuiregular18 1//&interuiregular18_nxfnt
|
||||
#define fontscale7 4
|
||||
#define largestar 5
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "language.h"
|
||||
#include "language.h"
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#define STR_JP(_str) [SetLanguage_JA] = _str
|
||||
@ -331,6 +331,18 @@ const char* const g_strings[StrId_Max][16] =
|
||||
STR_TW("应用"),
|
||||
},
|
||||
|
||||
[StrId_Actions_Star] =
|
||||
{
|
||||
STR_EN("Star"),
|
||||
STR_ES("Agregar a favoritos"),
|
||||
},
|
||||
|
||||
[StrId_Actions_Unstar] =
|
||||
{
|
||||
STR_EN("Unstar"),
|
||||
STR_ES("Borrar de favoritos"),
|
||||
},
|
||||
|
||||
[StrId_ThemeMenu] =
|
||||
{
|
||||
STR_EN("Theme Menu"),
|
||||
|
@ -23,6 +23,8 @@ typedef enum
|
||||
StrId_Actions_Open,
|
||||
StrId_Actions_Back,
|
||||
StrId_Actions_Apply,
|
||||
StrId_Actions_Star,
|
||||
StrId_Actions_Unstar,
|
||||
|
||||
StrId_MsgBox_OK,
|
||||
|
||||
|
@ -490,6 +490,13 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//check for .filename.star in same path
|
||||
strptr = getSlash(me->path);
|
||||
if (strptr[0] == '/') strptr++;
|
||||
int strptrLen = strlen(strptr);
|
||||
snprintf(me->starpath, sizeof(me->starpath)-1, "%.*s.%.*s.star", (int)(strlen(me->path) - strptrLen), me->path, (int)strptrLen, strptr);
|
||||
me->starred = fileExists(me->starpath);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -96,20 +96,34 @@ static void menuSort(void) {
|
||||
menu_s* m = &s_menu[!s_curMenu];
|
||||
int nEntries = m->nEntries;
|
||||
if (nEntries==0) return;
|
||||
int nEntriesStar = 0, nEntriesNoStar = 0;
|
||||
|
||||
menuEntry_s** list = (menuEntry_s**)calloc(nEntries, sizeof(menuEntry_s*));
|
||||
if(list == NULL) return;
|
||||
menuEntry_s** listStar = (menuEntry_s**)calloc(nEntries, sizeof(menuEntry_s*));
|
||||
if(listStar == NULL) {
|
||||
free(list);
|
||||
return;
|
||||
}
|
||||
|
||||
menuEntry_s* p = m->firstEntry;
|
||||
for(i = 0; i < nEntries; ++i) {
|
||||
list[i] = p;
|
||||
if (p->starred)
|
||||
listStar[nEntriesStar++] = p;
|
||||
else
|
||||
list[nEntriesNoStar++] = p;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
qsort(list, nEntries, sizeof(menuEntry_s*), menuEntryCmp);
|
||||
qsort(listStar, nEntriesStar, sizeof(menuEntry_s*), menuEntryCmp);
|
||||
qsort(list, nEntriesNoStar, sizeof(menuEntry_s*), menuEntryCmp);
|
||||
|
||||
menuEntry_s** pp = &m->firstEntry;
|
||||
for(i = 0; i < nEntries; ++i) {
|
||||
for(i = 0; i < nEntriesStar; ++i) {
|
||||
*pp = listStar[i];
|
||||
pp = &(*pp)->next;
|
||||
}
|
||||
for(i = 0; i < nEntriesNoStar; ++i) {
|
||||
*pp = list[i];
|
||||
pp = &(*pp)->next;
|
||||
}
|
||||
@ -117,6 +131,14 @@ static void menuSort(void) {
|
||||
*pp = NULL;
|
||||
|
||||
free(list);
|
||||
free(listStar);
|
||||
}
|
||||
|
||||
void menuReorder (void) {
|
||||
s_curMenu = !s_curMenu;
|
||||
menuSort();
|
||||
s_curMenu = !s_curMenu;
|
||||
menuClear();
|
||||
}
|
||||
|
||||
int menuScan(const char* target) {
|
||||
|
@ -29,6 +29,35 @@ void launchMenuEntryTask(menuEntry_s* arg) {
|
||||
launchMenuEntry(me);
|
||||
}
|
||||
|
||||
void toggleStarState(menuEntry_s* arg) {
|
||||
menuEntry_s* me = arg;
|
||||
if (me->starred) {
|
||||
if (fileExists(me->starpath))
|
||||
remove(me->starpath);
|
||||
} else {
|
||||
if (!fileExists(me->starpath)) {
|
||||
FILE* f = fopen(me->starpath, "w");
|
||||
if (f) fclose(f);
|
||||
}
|
||||
}
|
||||
me->starred = fileExists(me->starpath);
|
||||
//todo: error handling/message?
|
||||
|
||||
menuReorder();
|
||||
menu_s* menu = menuGetCurrent();
|
||||
menuEntry_s* meSearch = menu->firstEntry;
|
||||
menu->curEntry = -1;
|
||||
int i = 0;
|
||||
while (menu->curEntry < 0) {
|
||||
if (me == meSearch)
|
||||
menu->curEntry = i;
|
||||
else {
|
||||
meSearch = meSearch->next;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static enum
|
||||
{
|
||||
HBMENU_DEFAULT,
|
||||
@ -73,6 +102,18 @@ void menuHandleAButton(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void menuHandleXButton(void) {
|
||||
menu_s* menu = menuGetCurrent();
|
||||
|
||||
if (menu->nEntries > 0 && hbmenu_state == HBMENU_DEFAULT) {
|
||||
int i;
|
||||
menuEntry_s* me;
|
||||
for (i = 0, me = menu->firstEntry; i != menu->curEntry; i ++, me = me->next);
|
||||
toggleStarState(me);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void launchApplyThemeTask(menuEntry_s* arg) {
|
||||
const char* themePath = arg->path;
|
||||
SetThemePathToConfig(themePath);
|
||||
@ -246,6 +287,8 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) {
|
||||
|
||||
if (smallimg) {
|
||||
drawImage(start_x, start_y + 32, 140, 140, smallimg, IMAGE_MODE_RGB24);
|
||||
if (me->starred)
|
||||
DrawText(interuimedium30, start_x + 105 + 16, start_y + 16, themeCurrent.borderTextColor, themeCurrent.labelStarOnText);
|
||||
}
|
||||
|
||||
if (is_active && largeimg) {
|
||||
@ -283,6 +326,12 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) {
|
||||
snprintf(tmpstr, sizeof(tmpstr)-1, "%s: %s", textGetString(StrId_AppInfo_Version), me->version);
|
||||
DrawText(interuiregular14, start_x, start_y + 28 + 30 + 18 + 6 + 18, themeCurrent.textColor, tmpstr);
|
||||
}
|
||||
|
||||
if (me->starred)
|
||||
DrawText(largestar, start_x - 68, 160, themeCurrent.textColor, themeCurrent.labelStarOnText);
|
||||
else
|
||||
if (me->type != ENTRY_TYPE_THEME)
|
||||
DrawText(largestar, start_x - 68, 160, themeCurrent.textColor, themeCurrent.labelStarOffText);
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,8 +532,8 @@ void drawButtons(menu_s* menu, bool emptyDir, int *x_image_out) {
|
||||
#endif
|
||||
{
|
||||
//drawImage(x_image, 720 - 48, 32, 32, themeCurrent.buttonBImage, IMAGE_MODE_RGBA32);
|
||||
DrawText(fontscale7, x_image, 720 - 47 + 26, themeCurrent.textColor, themeCurrent.buttonBText);//Display the 'B' button from SharedFont.
|
||||
DrawText(interuimedium20, x_text, 720 - 47 + 26, themeCurrent.textColor, textGetString(StrId_Actions_Back));
|
||||
DrawText(fontscale7, x_image, 720 - 47 + 24, themeCurrent.textColor, themeCurrent.buttonBText);//Display the 'B' button from SharedFont.
|
||||
DrawText(interuimedium20, x_text, 720 - 47 + 24, themeCurrent.textColor, textGetString(StrId_Actions_Back));
|
||||
}
|
||||
|
||||
if(hbmenu_state == HBMENU_DEFAULT)
|
||||
@ -666,6 +715,20 @@ void menuLoop(void) {
|
||||
}
|
||||
|
||||
drawButtons(menu, false, &menupath_x_endpos);
|
||||
|
||||
if (active_entry && active_entry->type != ENTRY_TYPE_THEME) {
|
||||
if (active_entry->starred) {
|
||||
getX = GetTextXCoordinate(interuiregular18, menupath_x_endpos + 8, textGetString(StrId_Actions_Unstar), 'r');
|
||||
DrawText(fontscale7, getX - 36, 720 - 47 + 24, themeCurrent.textColor, themeCurrent.buttonXText);
|
||||
DrawText(interuiregular18, getX, 720 - 47 + 24, themeCurrent.textColor, textGetString(StrId_Actions_Unstar));
|
||||
} else {
|
||||
getX = GetTextXCoordinate(interuiregular18, menupath_x_endpos + 8, textGetString(StrId_Actions_Star), 'r');
|
||||
DrawText(fontscale7, getX - 36, 720 - 47 + 24, themeCurrent.textColor, themeCurrent.buttonXText);
|
||||
DrawText(interuiregular18, getX, 720 - 47 + 24, themeCurrent.textColor, textGetString(StrId_Actions_Star));
|
||||
}
|
||||
menupath_x_endpos = getX - 36 - 40;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DrawTextTruncate(interuiregular18, 40, 720 - 47 + 24, themeCurrent.textColor, menu->dirname, menupath_x_endpos - 40, "...");
|
||||
|
@ -51,6 +51,7 @@ struct menuEntry_s_tag
|
||||
MenuEntryType type;
|
||||
|
||||
char path[PATH_MAX+8];
|
||||
char starpath[PATH_MAX+8];
|
||||
argData_s args;
|
||||
|
||||
bool fileassoc_type;//0=file_extension, 1 = filename
|
||||
@ -64,6 +65,8 @@ struct menuEntry_s_tag
|
||||
size_t icon_size;
|
||||
uint8_t *icon_gfx;
|
||||
uint8_t *icon_gfx_small;
|
||||
|
||||
bool starred;
|
||||
|
||||
NacpStruct *nacp;
|
||||
};
|
||||
@ -97,11 +100,13 @@ void menuDeleteEntry(menuEntry_s* me, bool skip_icongfx);
|
||||
|
||||
menu_s* menuGetCurrent(void);
|
||||
menu_s* menuFileassocGetCurrent(void);
|
||||
void menuReorder (void);
|
||||
int menuScan(const char* target);
|
||||
int themeMenuScan(const char* target);
|
||||
int menuFileassocScan(const char* target);
|
||||
|
||||
void launchMenuEntryTask(menuEntry_s* arg);
|
||||
void toggleStarState(menuEntry_s* arg);
|
||||
void launchApplyThemeTask(menuEntry_s* arg);
|
||||
void launchMenuBackTask();
|
||||
void launchMenuNetloaderTask();
|
||||
@ -109,6 +114,7 @@ char *menuGetRootPath(void);
|
||||
char *menuGetRootBasePath(void);
|
||||
|
||||
void menuHandleAButton(void);
|
||||
void menuHandleXButton(void);
|
||||
|
||||
bool menuIsNetloaderActive(void);
|
||||
|
||||
|
@ -26,10 +26,13 @@ void themeStartup(ThemePreset preset) {
|
||||
.enableWaveBlending = 0,
|
||||
.buttonAText = "\uE0E0",
|
||||
.buttonBText = "\uE0E1",
|
||||
.buttonXText = "\uE0E2",
|
||||
.buttonYText = "\uE0E3",
|
||||
.buttonPText = "\uE0EF",
|
||||
.buttonMText = "\uE0F0",
|
||||
.hbmenuLogoImage = assetsGetDataBuffer(AssetId_hbmenu_logo_light)
|
||||
.labelStarOnText = "\u2605",
|
||||
.labelStarOffText = "\u2606",
|
||||
.hbmenuLogoImage = assetsGetDataBuffer(AssetId_hbmenu_logo_light),
|
||||
};
|
||||
|
||||
theme_t themeDark = (theme_t) {
|
||||
@ -46,10 +49,13 @@ void themeStartup(ThemePreset preset) {
|
||||
.enableWaveBlending = 0,
|
||||
.buttonAText = "\uE0A0",
|
||||
.buttonBText = "\uE0A1",
|
||||
.buttonXText = "\uE0A2",
|
||||
.buttonYText = "\uE0A3",
|
||||
.buttonPText = "\uE0B3",
|
||||
.buttonMText = "\uE0B4",
|
||||
.hbmenuLogoImage = assetsGetDataBuffer(AssetId_hbmenu_logo_dark)
|
||||
.labelStarOnText = "\u2605",
|
||||
.labelStarOffText = "\u2606",
|
||||
.hbmenuLogoImage = assetsGetDataBuffer(AssetId_hbmenu_logo_dark),
|
||||
};
|
||||
|
||||
char themePath[PATH_MAX] = {0};
|
||||
@ -61,7 +67,7 @@ void themeStartup(ThemePreset preset) {
|
||||
config_setting_t *theme = NULL;
|
||||
color_t text, frontWave, middleWave, backWave, background, highlight, separator, borderColor, borderTextColor, progressBarColor;
|
||||
int waveBlending;
|
||||
const char *AText, *BText, *YText, *PText, *MText;
|
||||
const char *AText, *BText, *XText, *YText, *PText, *MText, *starOnText, *starOffText;
|
||||
bool good_cfg = false;
|
||||
|
||||
if(themePath[0]!=0)
|
||||
@ -110,13 +116,19 @@ void themeStartup(ThemePreset preset) {
|
||||
AText = themeDefault->buttonAText;
|
||||
if (!config_setting_lookup_string(theme, "buttonBText", &BText))
|
||||
BText = themeDefault->buttonBText;
|
||||
if (!config_setting_lookup_string(theme, "buttonXText", &XText))
|
||||
XText = themeDefault->buttonXText;
|
||||
if (!config_setting_lookup_string(theme, "buttonYText", &YText))
|
||||
YText = themeDefault->buttonYText;
|
||||
if (!config_setting_lookup_string(theme, "buttonPText", &PText))
|
||||
PText = themeDefault->buttonPText;
|
||||
if (!config_setting_lookup_string(theme, "buttonMText", &MText))
|
||||
MText = themeDefault->buttonMText;
|
||||
themeCurrent = (theme_t) {
|
||||
if (!config_setting_lookup_string(theme, "labelStarOnText", &starOnText))
|
||||
starOnText = themeDefault->labelStarOnText;
|
||||
if (!config_setting_lookup_string(theme, "labelStarOffText", &starOffText))
|
||||
starOffText = themeDefault->labelStarOffText;
|
||||
themeCurrent = (theme_t) {
|
||||
.textColor = text,
|
||||
.frontWaveColor = frontWave,
|
||||
.middleWaveColor = middleWave,
|
||||
@ -132,6 +144,7 @@ void themeStartup(ThemePreset preset) {
|
||||
};
|
||||
strncpy(themeCurrent.buttonAText, AText, sizeof(themeCurrent.buttonAText)-1);
|
||||
strncpy(themeCurrent.buttonBText, BText, sizeof(themeCurrent.buttonBText)-1);
|
||||
strncpy(themeCurrent.buttonXText, XText, sizeof(themeCurrent.buttonXText)-1);
|
||||
strncpy(themeCurrent.buttonYText, YText, sizeof(themeCurrent.buttonYText)-1);
|
||||
strncpy(themeCurrent.buttonPText, PText, sizeof(themeCurrent.buttonPText)-1);
|
||||
strncpy(themeCurrent.buttonMText, MText, sizeof(themeCurrent.buttonMText)-1);
|
||||
|
@ -18,9 +18,12 @@ typedef struct
|
||||
bool enableWaveBlending;
|
||||
char buttonAText[32];
|
||||
char buttonBText[32];
|
||||
char buttonXText[32];
|
||||
char buttonYText[32];
|
||||
char buttonPText[32];
|
||||
char buttonMText[32];
|
||||
char labelStarOnText[32];
|
||||
char labelStarOffText[32];
|
||||
const uint8_t *hbmenuLogoImage;
|
||||
} theme_t;
|
||||
|
||||
|
@ -204,6 +204,10 @@ bool menuUpdate(void) {
|
||||
{
|
||||
launchMenuNetloaderTask();
|
||||
}
|
||||
else if (down & KEY_X)
|
||||
{
|
||||
menuHandleXButton();
|
||||
}
|
||||
else if (down & KEY_A)
|
||||
{
|
||||
menuHandleAButton();
|
||||
|
@ -13,6 +13,11 @@
|
||||
#define BACK_BUTTON_END_X 1048
|
||||
#define LAUNCH_BUTTON_START_X 1092
|
||||
#define LAUNCH_BUTTON_END_X 1200
|
||||
#define STAR_BUTTON_START_X 426
|
||||
#define STAR_BUTTON_END_X 490
|
||||
#define STAR_BUTTON_START_Y 100
|
||||
#define STAR_BUTTON_END_Y 161
|
||||
|
||||
|
||||
#define distance(x1, y1, x2, y2) (int) sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))
|
||||
|
||||
@ -127,6 +132,16 @@ void handleTouch(menu_s* menu) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Star
|
||||
else {
|
||||
int i;
|
||||
menuEntry_s* me;
|
||||
for (i = 0, me = menu->firstEntry; i != menu->curEntry; i ++, me = me->next);
|
||||
if (me->type != ENTRY_TYPE_THEME && x1 > STAR_BUTTON_START_X && x1 < STAR_BUTTON_END_X
|
||||
&& y1 > STAR_BUTTON_START_Y && y1 < STAR_BUTTON_END_Y) {
|
||||
menuHandleXButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Vertical Swipe
|
||||
else if (abs(x1 - x2) < VERTICAL_SWIPE_HORIZONTAL_PLAY && distance(x1, y1, x2, y2) > VERTICAL_SWIPE_MINIMUM_DISTANCE) {
|
||||
|
@ -74,6 +74,8 @@ extern "C" bool menuUpdate(void) {
|
||||
int new_esc_state = sf::Keyboard::isKeyPressed(sf::Keyboard::Escape);
|
||||
static int return_state = 0;
|
||||
int new_return_state = sf::Keyboard::isKeyPressed(sf::Keyboard::Return);
|
||||
static int x_state = 0;
|
||||
int new_x_state = sf::Keyboard::isKeyPressed(sf::Keyboard::X);
|
||||
static int y_state = 0;
|
||||
int new_y_state = sf::Keyboard::isKeyPressed(sf::Keyboard::Y);
|
||||
static int t_state = 0;
|
||||
@ -82,7 +84,11 @@ extern "C" bool menuUpdate(void) {
|
||||
if(!new_y_state && y_state)
|
||||
{
|
||||
launchMenuNetloaderTask();
|
||||
}
|
||||
|
||||
if(!new_x_state && x_state)
|
||||
{
|
||||
menuHandleXButton();
|
||||
}
|
||||
|
||||
if (!new_esc_state && esc_state)
|
||||
|
Loading…
Reference in New Issue
Block a user