Hello Maas!
Thanks a lot! Did you enjoyed the game? Let me know what you think about it!!!
About the code, we are going to release the changes via bitbucket as Mnemonic suggest us.
In the meantime, I'll share some of those changes here.
If you find a way to improve this, please let us know!! We have made changes to the ios_utils.m file, so we can identify the device that the player is using and the language that it's configured.
void IOS_GetCurrentLanguage(char* buffer)
{
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString* forceLang = [infoDict objectForKey:@"3fForceLang"];
//Obtenemos el codigo del lenguaje
NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0];
if (forceLang != nil && !([forceLang isEqualToString:@""])) {
language = forceLang;
}
// Ver: http://kb.applingua.com/2011/07/which-languages-does-ios-support/
if ([language isEqualToString:@"es"]) {
strcpy(buffer, "es");
} else if ([language isEqualToString:@"pt"]) {
strcpy(buffer, "pt");
} else if ([language isEqualToString:@"zh-Hant"] || [language isEqualToString:@"zh-Hans"]) {
// zh-Hant - T. Chinese
// zh-Hans - S. Chinese
strcpy(buffer, "nz");
} else if ([language isEqualToString:@"de"]) {
strcpy(buffer, "de");
} else if ([language isEqualToString:@"fr"]) {
strcpy(buffer, "fr");
} else if ([language isEqualToString:@"it"]) {
strcpy(buffer, "it");
} else {
strcpy(buffer, "en");
}
}
void IOS_GetDeviceType(char* buffer, int hd)
{
//if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// strcpy(buffer, "tablet");
//else
// strcpy(buffer, "phone");
struct utsname systemInfo;
uname(&systemInfo);
NSString *system = [NSString stringWithFormat:@"%s", systemInfo.machine];
if ([system isEqualToString:(@"i386")] || [system isEqualToString:(@"x86_64")]) {
strcpy( buffer, "iphone5" );
} else if ( [system hasPrefix:@"iPhone3"] || [system hasPrefix:@"iPhone4"] ) {
(hd==1) ? strcpy( buffer, "iphone4" ) : strcpy( buffer, "iphone3g" );
} else if ( [system hasPrefix:@"iPod"] || [system hasPrefix:@"iPhone1"] || [system hasPrefix:@"iPhone2"]) {
strcpy( buffer, "iphone3g" );
} else if ( [system hasPrefix:@"iPad1"] || [system hasPrefix:@"iPad2"]) {
strcpy( buffer, "ipad" );
} else if ( [system hasPrefix:@"iPad3"] || [system hasPrefix:@"iPad4"]) {
(hd==1) ? strcpy( buffer, "ipad3" ) : strcpy( buffer, "ipad" ) ;
} else if ( [system hasPrefix:@"iPhone5"] ) {
strcpy( buffer, "iphone5" );
}
}
For the devices, the changes on the ios_utils are enough, because Mnemonic already coded the rest.
For the languages, we make changes to the BFileManager.cpp of the wmelite code.
we use the same idea that Mnemonic used with the devices, so we have one package for every device/language called "xLanguage_iphone4_en.dcp" "xLanguage_ipad3_en.dcp" ... "xLanguage_iphone4_it.dcp" ... and so on.
Everyone of this packages has priority = 0 in the file. The data.dcp package, has priority = 1, and the devices packages has priority = 2.
The data package and the devices packages are with the default language (spanish in our case), and with the changes to BFilemanager we managed to change the priority of the language packages at run time, if it was necesary.
#ifdef __IPHONEOS__
AnsiString deviceType = Game->GetDeviceType();
IOS_GetUserSelectedLanguage(language);
//La idea es que todos los paquetes de idioma tengan prioridad 0.
//Si de repente estamos en ingles, forzamos una prioridad que sabemos que va a cargarlo.
char lang_pattern[128];
//Reconstruimos el paquete de idiomas que esperamos. Si encontramos algo con este patron... le damos prioridad
sprintf( lang_pattern, "xlanguage_%s_%s.dcp", deviceType.c_str() , language );
//Game->LOG(0, "Main package will be %s", lang_pattern);
#else
...
...
...
BYTE priority = hdr.Priority;
#ifdef __IPHONEOS__
if( !strcmp( Name, lang_pattern ) )
//Le damos prioridad al paquete.
priority = 3;
#else
...
For the resolucions, we had to make a hack on the BGame.cpp file, because the resolution you specify in the startup.settings file can't be changed for every package.
case TOKEN_RESOLUTION:
{
//El siguiente codigo es solo para iphone, en Mac no hace falta modificar la resolucion.
#ifdef __IPHONEOS__
//HACK: 3f. Como el archivo de configuracion de la aplicacion es el mismo
// para todos los paquetes
// no se puede tener resoluciones diferentes para iphone3G y iphone4.
// No se me ocurre otra cosa.
AnsiString device = this->GetDeviceType();
LOG(0, "Detected device is: %s", device.c_str());
if( StringUtil::CompareNoCase(device, "iphone3g" ) )
{
m_SettingsResWidth = 480;
m_SettingsResHeight = 320;
}
else if( StringUtil::CompareNoCase(device, "iphone5" ) )
{
m_SettingsResWidth = 1136;
m_SettingsResHeight = 640;
}
else if( StringUtil::CompareNoCase(device, "iphone4" ) )
{
m_SettingsResWidth = 960;
m_SettingsResHeight = 640;
}
else if( StringUtil::CompareNoCase(device, "ipad" ) )
{
m_SettingsResWidth = 1024;
m_SettingsResHeight = 768;
}
else if( StringUtil::CompareNoCase(device, "ipad3" ) )
{
m_SettingsResWidth = 1280;
m_SettingsResHeight = 960;
}
else
{
LOG(0, "Engine will use default DCP resolution", m_SettingsResWidth, m_SettingsResHeight);
parser.ScanStr((char*)params, "%d,%d", &m_SettingsResWidth, &m_SettingsResHeight);
}
#else
parser.ScanStr((char*)params, "%d,%d", &m_SettingsResWidth, &m_SettingsResHeight);
#endif
LOG(0, "Resolution is set at %d x %d", m_SettingsResWidth, m_SettingsResHeight);
}
break;
I hope you find this helpful.
Cheers.
Fran.-