diff --git a/skeleton/BASE/Theme/.keep b/skeleton/BASE/Theme/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/workspace/all/common/api.c b/workspace/all/common/api.c index 0a4ac041f..87bc4a522 100644 --- a/workspace/all/common/api.c +++ b/workspace/all/common/api.c @@ -321,7 +321,10 @@ SDL_Surface* GFX_init(int mode) asset_rects[ASSET_GAMEPAD] = (SDL_Rect){SCALE4(92,51,18,10)}; char asset_path[MAX_PATH]; - sprintf(asset_path, RES_PATH "/assets@%ix.png", FIXED_SCALE); + // first see if there is an assets file in the Theme folder otherwise just load up default + sprintf(asset_path, THEME_PATH "/assets@%ix.png", FIXED_SCALE); + if (!exists(asset_path)) + sprintf(asset_path, RES_PATH "/assets@%ix.png", FIXED_SCALE); if (!exists(asset_path)) LOG_info("missing assets, you're about to segfault dummy!\n"); gfx.assets = IMG_Load(asset_path); diff --git a/workspace/all/common/config.c b/workspace/all/common/config.c index b56b9ae91..00d4a8e79 100644 --- a/workspace/all/common/config.c +++ b/workspace/all/common/config.c @@ -1,7 +1,9 @@ #include "config.h" #include "defines.h" #include "utils.h" - +#include +#include +#include NextUISettings settings = {0}; // deprecated @@ -87,38 +89,7 @@ void CFG_init(FontLoad_callback_t cb, ColorSet_callback_t ccb) fontLoaded = true; continue; } - if (sscanf(line, "color1=%x", &temp_color) == 1) - { - char hexColor[7]; - snprintf(hexColor, sizeof(hexColor), "%06x", temp_color); - CFG_setColor(1, HexToUint32_unmapped(hexColor)); - continue; - } - if (sscanf(line, "color2=%x", &temp_color) == 1) - { - CFG_setColor(2, temp_color); - continue; - } - if (sscanf(line, "color3=%x", &temp_color) == 1) - { - CFG_setColor(3, temp_color); - continue; - } - if (sscanf(line, "color4=%x", &temp_color) == 1) - { - CFG_setColor(4, temp_color); - continue; - } - if (sscanf(line, "color5=%x", &temp_color) == 1) - { - CFG_setColor(5, temp_color); - continue; - } - if (sscanf(line, "color6=%x", &temp_color) == 1) - { - CFG_setColor(6, temp_color); - continue; - } + if (sscanf(line, "radius=%i", &temp_value) == 1) { CFG_setThumbnailRadius(temp_value); @@ -212,6 +183,60 @@ void CFG_init(FontLoad_callback_t cb, ColorSet_callback_t ccb) } fclose(file); } + // Check for theme.txt settings file and overwrite configs if found + sprintf(settingsPath, "%s/theme.txt", THEME_PATH); + file = fopen(settingsPath, "r"); + if (file == NULL) + { + printf("[CFG] Unable to open settings file, loading defaults\n"); + } + else + { + char line[256]; + while (fgets(line, sizeof(line), file)) + { + int temp_value; + uint32_t temp_color; + if (sscanf(line, "color1=%x", &temp_color) == 1) + { + char hexColor[7]; + snprintf(hexColor, sizeof(hexColor), "%06x", temp_color); + CFG_setColor(1, HexToUint32_unmapped(hexColor)); + continue; + } + if (sscanf(line, "color2=%x", &temp_color) == 1) + { + CFG_setColor(2, temp_color); + continue; + } + if (sscanf(line, "color3=%x", &temp_color) == 1) + { + CFG_setColor(3, temp_color); + continue; + } + if (sscanf(line, "color4=%x", &temp_color) == 1) + { + CFG_setColor(4, temp_color); + continue; + } + if (sscanf(line, "color5=%x", &temp_color) == 1) + { + CFG_setColor(5, temp_color); + continue; + } + if (sscanf(line, "color6=%x", &temp_color) == 1) + { + CFG_setColor(6, temp_color); + continue; + } + if (sscanf(line, "radius=%i", &temp_value) == 1) + { + CFG_setThumbnailRadius(temp_value); + continue; + } + } + fclose(file); + } // load gfx related stuff until we drop the indirection CFG_setColor(1, CFG_getColor(1)); @@ -234,13 +259,21 @@ void CFG_setFontId(int id) { settings.font = clamp(id, 0, 2); + const char *themeFontPath = THEME_PATH "/font.ttf"; char *fontPath; - if (settings.font == 1) - fontPath = RES_PATH "/font1.ttf"; - else - fontPath = RES_PATH "/font2.ttf"; - if(settings.onFontChange) + // Check if THEME_PATH/font.ttf exists + if (access(themeFontPath, F_OK) == 0) { + fontPath = (char *)themeFontPath; + } else { + // Fallback to default fonts + if (settings.font == 1) + fontPath = RES_PATH "/font1.ttf"; + else + fontPath = RES_PATH "/font2.ttf"; + } + + if (settings.onFontChange) settings.onFontChange(fontPath); } @@ -618,14 +651,7 @@ void CFG_sync(void) } fprintf(file, "font=%i\n", settings.font); - fprintf(file, "color1=0x%06X\n", settings.color1_255); - fprintf(file, "color2=0x%06X\n", settings.color2_255); - fprintf(file, "color3=0x%06X\n", settings.color3_255); - fprintf(file, "color4=0x%06X\n", settings.color4_255); - fprintf(file, "color5=0x%06X\n", settings.color5_255); - fprintf(file, "color6=0x%06X\n", settings.color6_255); fprintf(file, "bgcolor=0x%06X\n", settings.backgroundColor_255); - fprintf(file, "radius=%i\n", settings.thumbRadius); fprintf(file, "showclock=%i\n", settings.showClock); fprintf(file, "clock24h=%i\n", settings.clock24h); fprintf(file, "batteryperc=%i\n", settings.showBatteryPercent); @@ -645,6 +671,25 @@ void CFG_sync(void) fprintf(file, "wifi=%i\n", settings.wifi); fclose(file); + sprintf(settingsPath, "%s/theme.txt", THEME_PATH); + + if (!exists(THEME_PATH)) { + mkdir(THEME_PATH, 0755); + } + file = fopen(settingsPath, "w"); + if (file == NULL) + { + printf("[CFG] Unable to open settings file, cant write\n"); + return; + } + fprintf(file, "color1=0x%06X\n", settings.color1_255); + fprintf(file, "color2=0x%06X\n", settings.color2_255); + fprintf(file, "color3=0x%06X\n", settings.color3_255); + fprintf(file, "color4=0x%06X\n", settings.color4_255); + fprintf(file, "color5=0x%06X\n", settings.color5_255); + fprintf(file, "color6=0x%06X\n", settings.color6_255); + fprintf(file, "radius=%i\n", settings.thumbRadius); + fclose(file); } void CFG_print(void) diff --git a/workspace/all/common/defines.h b/workspace/all/common/defines.h index 453e6dcea..846155fe1 100644 --- a/workspace/all/common/defines.h +++ b/workspace/all/common/defines.h @@ -30,6 +30,7 @@ #define FAUX_RECENT_PATH SDCARD_PATH "/Recently Played" #define COLLECTIONS_PATH SDCARD_PATH "/Collections" +#define THEME_PATH SDCARD_PATH "/Theme" #define LAST_PATH "/tmp/last.txt" // transient #define CHANGE_DISC_PATH "/tmp/change_disc.txt" diff --git a/workspace/all/common/utils.c b/workspace/all/common/utils.c index bea1fbd12..4d16a82f2 100644 --- a/workspace/all/common/utils.c +++ b/workspace/all/common/utils.c @@ -353,6 +353,7 @@ void getEmuName(const char* in_name, char* out_name) { // NOTE: both char arrays // printf("--------\n in_name: %s\n",in_name); fflush(stdout); // extract just the Roms folder name if necessary + if (prefixMatch(ROMS_PATH, tmp)) { tmp += strlen(ROMS_PATH) + 1; char* tmp2 = strchr(tmp, '/'); @@ -360,6 +361,13 @@ void getEmuName(const char* in_name, char* out_name) { // NOTE: both char arrays // printf(" tmp1: %s\n", tmp); strcpy(out_name, tmp); tmp = out_name; + } else if (prefixMatch(SDCARD_PATH, tmp)) { // doing this to also grab non systems like Tools, Collections etc + tmp += strlen(SDCARD_PATH) + 1; + char* tmp2 = strchr(tmp, '/'); + if (tmp2) tmp2[0] = '\0'; + // printf(" tmp1: %s\n", tmp); + strcpy(out_name, tmp); + tmp = out_name; } // finally extract pak name from parenths if present diff --git a/workspace/all/nextui/nextui.c b/workspace/all/nextui/nextui.c index e97211659..3527cb8f2 100644 --- a/workspace/all/nextui/nextui.c +++ b/workspace/all/nextui/nextui.c @@ -1361,12 +1361,25 @@ static int remember_selection = 0; SDL_Surface* loadFolderBackground(char* rompath, int type) { + char emutag[255]; + getEmuName(rompath,emutag); + LOG_info("romath ais: %s\n",emutag); char imagePath[MAX_PATH]; if(type == ENTRY_DIR) - snprintf(imagePath, sizeof(imagePath), "%s/.media/bg.png", rompath); + snprintf(imagePath, sizeof(imagePath), "%s/%s/bg.png", THEME_PATH,emutag); else if(type == ENTRY_ROM) - snprintf(imagePath, sizeof(imagePath), "%s/.media/bglist.png", rompath); - + snprintf(imagePath, sizeof(imagePath), "%s/%s/bglist.png", THEME_PATH,emutag); + + LOG_info("background path: %s\n",imagePath); + // fallback for old .media system + if(!exists(imagePath)) { + if(type == ENTRY_DIR) + snprintf(imagePath, sizeof(imagePath), "%s/.media/bg.png", rompath); + else if(type == ENTRY_ROM) + snprintf(imagePath, sizeof(imagePath), "%s/.media/bglist.png", rompath); + } + + //LOG_info("Loading folder bg from %s\n", imagePath); if(exists(imagePath)) { SDL_Surface *image = IMG_Load(imagePath); @@ -1462,7 +1475,10 @@ int main (int argc, char *argv[]) { char folderBgPath[1024]; folderbgbmp = NULL; - SDL_Surface* bgbmp = IMG_Load(SDCARD_PATH "/bg.png"); + SDL_Surface* bgbmp = IMG_Load(THEME_PATH "/bg.png"); + if(!bgbmp) + bgbmp = IMG_Load(SDCARD_PATH "/bg.png"); + SDL_Surface* convertedbg = SDL_ConvertSurfaceFormat(bgbmp, SDL_PIXELFORMAT_RGBA8888, 0); if (convertedbg) { SDL_FreeSurface(bgbmp); @@ -1980,11 +1996,14 @@ int main (int argc, char *argv[]) { // draw background static int lastType = -1; - if(((entry->type == ENTRY_DIR || entry->type == ENTRY_ROM) && CFG_getRomsUseFolderBackground())) { + static int lastTotal = 0; + if((CFG_getRomsUseFolderBackground())) { LOG_info("entry path %s %s\n",entry->path,rompath); + LOG_info("Totals %i %i\n",lastTotal,total); char *newBg = entry->type == ENTRY_DIR ? entry->path:rompath; - if((strcmp(newBg, folderBgPath) != 0 || lastType != entry->type) && sizeof(folderBgPath) != 1) { + if((strcmp(newBg, folderBgPath) != 0 || lastType != entry->type || lastTotal != total) && sizeof(folderBgPath) != 1) { lastType = entry->type; + lastTotal = total; strncpy(folderBgPath, newBg, sizeof(folderBgPath) - 1); SDL_FreeSurface(folderbgbmp); folderbgbmp = loadFolderBackground(folderBgPath,entry->type); @@ -2003,9 +2022,20 @@ int main (int argc, char *argv[]) { if (total > 0) { char thumbpath[1024]; - if(CFG_getShowGameArt()) - snprintf(thumbpath, sizeof(thumbpath), "%s/.media/%s.png", rompath, res_copy); - + if(CFG_getShowGameArt()) { + char emutag[255]; + getEmuName(rompath,emutag); + char *newBg = entry->type == ENTRY_DIR ? entry->path:rompath; + snprintf(thumbpath, sizeof(thumbpath), entry->type == ENTRY_DIR ? "":"%s/.media/%s.png", rompath, res_copy); + + if( entry->type == ENTRY_DIR) + snprintf(thumbpath, sizeof(thumbpath), "%s/%s/icon.png", THEME_PATH,emutag); + else + snprintf(thumbpath, sizeof(thumbpath),"%s/.media/%s.png", rompath, res_copy); + + LOG_info("gamearth path: %s\n",thumbpath); + + } had_thumb = 0; GFX_clearLayers(3); if (exists(thumbpath)) {