Notify the user when the language folder could not be read

This commit is contained in:
MysterD 2023-04-24 02:10:40 -07:00
parent 17efa994da
commit 59453c6165
2 changed files with 18 additions and 6 deletions

View file

@ -4,6 +4,8 @@
#include "pc/platform.h" #include "pc/platform.h"
#include "pc/mods/mods.h" #include "pc/mods/mods.h"
#include "pc/mods/mods_utils.h" #include "pc/mods/mods_utils.h"
#include "pc/djui/djui_language.h"
#include "pc/djui/djui_popup.h"
ini_t* sLang = NULL; ini_t* sLang = NULL;

View file

@ -78,9 +78,6 @@ void djui_panel_language_create(struct DjuiBase* caller) {
sLanguageChanged = false; sLanguageChanged = false;
{ {
struct DjuiPaginated* paginated = djui_paginated_create(body, 8);
sLayoutBase = &paginated->layout->base;
// construct lang path // construct lang path
char lpath[SYS_MAX_PATH] = ""; char lpath[SYS_MAX_PATH] = "";
snprintf(lpath, SYS_MAX_PATH, "%s/lang", sys_exe_path()); snprintf(lpath, SYS_MAX_PATH, "%s/lang", sys_exe_path());
@ -90,9 +87,20 @@ void djui_panel_language_create(struct DjuiBase* caller) {
DIR* d = opendir(lpath); DIR* d = opendir(lpath);
if (!d) { if (!d) {
LOG_ERROR("Could not open directory '%s'", lpath); LOG_ERROR("Could not open directory '%s'", lpath);
return;
char buffer[512] = "";
snprintf(buffer, 512, "\\#ffa0a0\\Failed to load language folder:\n\\#c8c8c8\\%s", lpath);
struct DjuiText* text = djui_text_create(body, buffer);
djui_text_set_alignment(text, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
djui_base_set_size_type(&text->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&text->base, 1.0f, 128.0f);
goto skip_langs;
} }
struct DjuiPaginated* paginated = djui_paginated_create(body, 8);
sLayoutBase = &paginated->layout->base;
struct DjuiCheckbox* chkEnglish = NULL; struct DjuiCheckbox* chkEnglish = NULL;
bool foundMatch = false; bool foundMatch = false;
@ -106,7 +114,7 @@ void djui_panel_language_create(struct DjuiBase* caller) {
// strip the name before the . // strip the name before the .
char* c = path; char* c = path;
while (*c != '\0') { while (*c != '\0') {
if (*c == '.') { *c = '\0'; break;} if (*c == '.') { *c = '\0'; break; }
c++; c++;
} }
if (strlen(path) == 0) { continue; } if (strlen(path) == 0) { continue; }
@ -125,12 +133,14 @@ void djui_panel_language_create(struct DjuiBase* caller) {
} }
djui_paginated_calculate_height(paginated); djui_paginated_calculate_height(paginated);
panel->bodySize.value = paginated->base.height.value + 16 + 64;
skip_langs:
djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back); djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
panel->bodySize.value = paginated->base.height.value + 16 + 64;
} }
struct DjuiPanel* p = djui_panel_add(caller, panel, NULL); struct DjuiPanel* p = djui_panel_add(caller, panel, NULL);
p->on_panel_destroy = djui_panel_language_destroy; p->on_panel_destroy = djui_panel_language_destroy;
} }