Implement MKXP.user_language, return more LANGIDs

This commit is contained in:
Inori 2019-08-31 14:41:21 -04:00 committed by Inori
parent 6b007ed8d9
commit 9b70f18c8c
3 changed files with 46 additions and 5 deletions

View file

@ -29,6 +29,7 @@
#include "debugwriter.h" #include "debugwriter.h"
#include "graphics.h" #include "graphics.h"
#include "audio.h" #include "audio.h"
#include "lang-fun.h"
#include "boost-hash.h" #include "boost-hash.h"
#include <ruby.h> #include <ruby.h>
@ -95,6 +96,7 @@ RB_METHOD(mkxpPuts);
RB_METHOD(mkxpRawKeyStates); RB_METHOD(mkxpRawKeyStates);
RB_METHOD(mkxpMouseInWindow); RB_METHOD(mkxpMouseInWindow);
RB_METHOD(mkxpPlatform); RB_METHOD(mkxpPlatform);
RB_METHOD(mkxpUserLanguage);
RB_METHOD(mriRgssMain); RB_METHOD(mriRgssMain);
RB_METHOD(mriRgssStop); RB_METHOD(mriRgssStop);
@ -165,6 +167,7 @@ static void mriBindingInit()
_rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates); _rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates);
_rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow); _rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow);
_rb_define_module_function(mod, "platform", mkxpPlatform); _rb_define_module_function(mod, "platform", mkxpPlatform);
_rb_define_module_function(mod, "user_language", mkxpUserLanguage);
/* Load global constants */ /* Load global constants */
rb_gv_set("MKXP", Qtrue); rb_gv_set("MKXP", Qtrue);
@ -270,6 +273,13 @@ RB_METHOD(mkxpPlatform)
return rb_str_new_cstr(SDL_GetPlatform()); return rb_str_new_cstr(SDL_GetPlatform());
} }
RB_METHOD(mkxpUserLanguage)
{
RB_UNUSED_PARAM;
return rb_str_new_cstr(getUserLanguage());
}
static VALUE rgssMainCb(VALUE block) static VALUE rgssMainCb(VALUE block)
{ {
rb_funcall2(block, rb_intern("call"), 0, 0); rb_funcall2(block, rb_intern("call"), 0, 0);

View file

@ -13,6 +13,7 @@
#include "eventthread.h" #include "eventthread.h"
#include "filesystem.h" #include "filesystem.h"
#include "input.h" #include "input.h"
#include "lang-fun.h"
#include "fake-api.h" #include "fake-api.h"
@ -594,11 +595,38 @@ MKXP_GetPrivateProfileString(LPCTSTR lpAppName,
} }
// Only supports English, other languages are too // Does not handle sublanguages, only returns a few
// much work to keep in hacky code like this // common languages
// Use MKXP.user_language instead
PREFABI short // I know it's a LANGID but I don't care PREFABI short // I know it's a LANGID but I don't care
MKXP_GetUserDefaultLangID(void) MKXP_GetUserDefaultLangID(void)
NOP_VAL(0xC09); {
char buf[50];
strncpy(buf, getUserLanguage(), sizeof(buf));
for (int i = 0; i < strlen(buf); i++)
{
if (buf[i] == '_')
{
buf[i] = 0;
break;
}
}
#define MATCH(l, c) if (!strcmp(l, buf)) return (c & 0x3ff);
MATCH("ja", 0x11);
MATCH("en", 0x09);
MATCH("fr", 0x0c);
MATCH("it", 0x10);
MATCH("de", 0x07);
MATCH("es", 0x0a);
MATCH("ko", 0x12);
MATCH("pt", 0x16);
MATCH("zh", 0x04);
#undef MATCH
return 0x09;
}
#endif #endif

View file

@ -15,6 +15,7 @@ zlib = dependency('zlib')
main_dependencies = [sigcxx, openal, opengl, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound] main_dependencies = [sigcxx, openal, opengl, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound]
if host_system == 'darwin' if host_system == 'darwin'
main_dependencies += compiler.find_library('iconv') main_dependencies += compiler.find_library('iconv')
main_dependencies += dependency('CoreFoundation')
if openal.type_name() != 'pkgconfig' if openal.type_name() != 'pkgconfig'
add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp') add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp')
@ -96,7 +97,8 @@ main_headers = files(
'tileatlasvx.h', 'tileatlasvx.h',
'sharedmidistate.h', 'sharedmidistate.h',
'fluid-fun.h', 'fluid-fun.h',
'sdl-util.h' 'sdl-util.h',
'lang-fun.h'
) )
main_source = files( main_source = files(
@ -142,7 +144,8 @@ main_source = files(
'tileatlasvx.cpp', 'tileatlasvx.cpp',
'autotilesvx.cpp', 'autotilesvx.cpp',
'midisource.cpp', 'midisource.cpp',
'fluid-fun.cpp' 'fluid-fun.cpp',
'lang-fun.cpp'
) )
main = [main_source, main_headers] main = [main_source, main_headers]