add ability to externally load fonts and activate japanese/korean

translations.
This commit is contained in:
Daryl Borth 2019-01-05 17:07:07 -07:00
parent 5160445ae8
commit 9e038bee04
8 changed files with 110 additions and 7 deletions

BIN
fonts/jp.ttf Normal file

Binary file not shown.

BIN
fonts/ko.ttf Normal file

Binary file not shown.

View File

@ -34,6 +34,13 @@ Wii homebrew is WiiBrew (www.wiibrew.org).
| UPDATE HISTORY | | UPDATE HISTORY |
•˜———–—––-- - —————————––––– ———–—––-- - —————————––––– ———–—––-- - ————————• •˜———–—––-- - —————————––––– ———–—––-- - —————————––––– ———–—––-- - ————————•
[4.4.2]
* Fixed Wii U GamePad support
* Added ability to load external fonts and activated Japanese/Korean
translations. Simply put the ko.ttf or jp.ttf in the app directory
* Added ability to change preview image source with + button (thanks Zalo!)
[4.4.1 - January 4, 2019] [4.4.1 - January 4, 2019]
* Fixed controllers with no analog sticks * Fixed controllers with no analog sticks

View File

@ -33,9 +33,14 @@
#include "filebrowser.h" #include "filebrowser.h"
#include "gui/gui.h" #include "gui/gui.h"
#ifdef HW_RVL
#include "mem2.h"
#endif
#define THREAD_SLEEP 100 #define THREAD_SLEEP 100
unsigned char *savebuffer = NULL; unsigned char *savebuffer = NULL;
u8 *ext_font_ttf = NULL;
static mutex_t bufferLock = LWP_MUTEX_NULL; static mutex_t bufferLock = LWP_MUTEX_NULL;
FILE * file; // file pointer - the only one we should ever use! FILE * file; // file pointer - the only one we should ever use!
bool unmountRequired[7] = { false, false, false, false, false, false, false }; bool unmountRequired[7] = { false, false, false, false, false, false, false };
@ -850,6 +855,43 @@ size_t LoadFile(char * filepath, bool silent)
return LoadFile((char *)savebuffer, filepath, 0, SAVEBUFFERSIZE, silent); return LoadFile((char *)savebuffer, filepath, 0, SAVEBUFFERSIZE, silent);
} }
#ifdef HW_RVL
size_t LoadFont(char * filepath)
{
FILE *file = fopen (filepath, "rb");
if(!file) {
ErrorPrompt("Font file not found!");
return 0;
}
fseeko(file,0,SEEK_END);
size_t loadSize = ftello(file);
if(loadSize == 0) {
ErrorPrompt("Error loading font!");
return 0;
}
if(ext_font_ttf) {
mem2_free(ext_font_ttf);
}
ext_font_ttf = (u8 *)mem2_malloc(loadSize);
if(!ext_font_ttf) {
ErrorPrompt("Font file is too large!");
fclose(file);
return 0;
}
fseeko(file,0,SEEK_SET);
fread (ext_font_ttf, 1, loadSize, file);
fclose(file);
return loadSize;
}
#endif
/**************************************************************************** /****************************************************************************
* SaveFile * SaveFile
* Write buffer to file * Write buffer to file

View File

@ -36,10 +36,12 @@ void FreeSaveBuffer();
size_t LoadFile(char * rbuffer, char *filepath, size_t length, size_t buffersize, bool silent); size_t LoadFile(char * rbuffer, char *filepath, size_t length, size_t buffersize, bool silent);
size_t LoadFile(char * filepath, bool silent); size_t LoadFile(char * filepath, bool silent);
size_t LoadSzFile(char * filepath, unsigned char * rbuffer); size_t LoadSzFile(char * filepath, unsigned char * rbuffer);
size_t LoadFont(char *filepath);
size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent); size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent);
size_t SaveFile(char * filepath, size_t datasize, bool silent); size_t SaveFile(char * filepath, size_t datasize, bool silent);
extern unsigned char *savebuffer; extern unsigned char *savebuffer;
extern u8 *ext_font_ttf;
extern FILE * file; extern FILE * file;
extern bool unmountRequired[]; extern bool unmountRequired[];
extern bool isMounted[]; extern bool isMounted[];

View File

@ -37,6 +37,7 @@
#include "gui/gui.h" #include "gui/gui.h"
#include "menu.h" #include "menu.h"
#include "utils/gettext.h" #include "utils/gettext.h"
#include "utils/FreeTypeGX.h"
#include "snes9x/snes9x.h" #include "snes9x/snes9x.h"
#include "snes9x/fxemu.h" #include "snes9x/fxemu.h"
@ -129,7 +130,7 @@ HaltGui()
usleep(THREAD_SLEEP); usleep(THREAD_SLEEP);
} }
void ResetText() static void ResetText()
{ {
LoadLanguage(); LoadLanguage();
@ -137,6 +138,58 @@ void ResetText()
mainWindow->ResetText(); mainWindow->ResetText();
} }
static int currentLanguage = -1;
void ChangeLanguage() {
if(currentLanguage == GCSettings.language) {
return;
}
if(GCSettings.language == LANG_JAPANESE || GCSettings.language == LANG_KOREAN) {
#ifdef HW_RVL
char filepath[MAXPATHLEN];
switch(GCSettings.language) {
case LANG_KOREAN:
sprintf(filepath, "%s/ko.ttf", appPath);
break;
case LANG_JAPANESE:
sprintf(filepath, "%s/jp.ttf", appPath);
break;
}
size_t fontSize = LoadFont(filepath);
if(fontSize > 0) {
HaltGui();
DeinitFreeType();
InitFreeType((u8*)ext_font_ttf, fontSize);
}
else {
GCSettings.language = currentLanguage;
}
#else
GCSettings.language = currentLanguage;
ErrorPrompt("Unsupported language!");
#endif
}
#ifdef HW_RVL
else {
if(ext_font_ttf != NULL) {
HaltGui();
DeinitFreeType();
mem2_free(ext_font_ttf);
ext_font_ttf = NULL;
InitFreeType((u8*)font_ttf, font_ttf_size);
}
}
#endif
HaltGui();
ResetText();
currentLanguage = GCSettings.language;
ResumeGui();
}
/**************************************************************************** /****************************************************************************
* WindowPrompt * WindowPrompt
* *
@ -3844,6 +3897,7 @@ static int MenuSettingsMenu()
int i = 0; int i = 0;
bool firstRun = true; bool firstRun = true;
OptionList options; OptionList options;
currentLanguage = GCSettings.language;
sprintf(options.name[i++], "Exit Action"); sprintf(options.name[i++], "Exit Action");
sprintf(options.name[i++], "Wiimote Orientation"); sprintf(options.name[i++], "Wiimote Orientation");
@ -3931,9 +3985,7 @@ static int MenuSettingsMenu()
GCSettings.language = LANG_JAPANESE; GCSettings.language = LANG_JAPANESE;
if(GCSettings.language == LANG_SIMP_CHINESE) if(GCSettings.language == LANG_SIMP_CHINESE)
GCSettings.language = LANG_PORTUGUESE; GCSettings.language = LANG_KOREAN;
else if(GCSettings.language == LANG_JAPANESE)
GCSettings.language = LANG_ENGLISH;
break; break;
@ -4030,11 +4082,11 @@ static int MenuSettingsMenu()
menu = MENU_SETTINGS; menu = MENU_SETTINGS;
} }
} }
ChangeLanguage();
HaltGui(); HaltGui();
mainWindow->Remove(&optionBrowser); mainWindow->Remove(&optionBrowser);
mainWindow->Remove(&w); mainWindow->Remove(&w);
mainWindow->Remove(&titleTxt); mainWindow->Remove(&titleTxt);
ResetText();
return menu; return menu;
} }

View File

@ -21,7 +21,7 @@ void InfoPrompt(const char * msg);
void ShowAction (const char *msg); void ShowAction (const char *msg);
void CancelAction(); void CancelAction();
void ShowProgress (const char *msg, int done, int total); void ShowProgress (const char *msg, int done, int total);
void ResetText(); void ChangeLanguage();
enum enum
{ {

View File

@ -728,6 +728,6 @@ bool LoadPrefs()
CreateDirectory(dirPath); CreateDirectory(dirPath);
} }
ResetText(); ChangeLanguage();
return prefFound; return prefFound;
} }