From 29af5d7305ee4695104e145b87df62171cfb0287 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Sun, 18 May 2003 03:55:30 +0000 Subject: [PATCH] automatic language selection support --- src/freespace2/freespace.cpp | 63 +++++++++++++++++++++- src/hud/hud.cpp | 46 +++++++++------- src/io/key.cpp | 64 +++++++++++------------ src/localization/localize.cpp | 20 +++---- src/mission/missiongoals.cpp | 98 ++++++++++++++++++++--------------- 5 files changed, 185 insertions(+), 106 deletions(-) diff --git a/src/freespace2/freespace.cpp b/src/freespace2/freespace.cpp index 9240e56..c3ecc21 100644 --- a/src/freespace2/freespace.cpp +++ b/src/freespace2/freespace.cpp @@ -15,6 +15,9 @@ * Freespace main body * * $Log$ + * Revision 1.28 2003/05/18 03:55:30 taylor + * automatic language selection support + * * Revision 1.27 2003/03/03 04:54:44 theoddone33 * Commit Taylor's ShowFPS fix * @@ -1048,6 +1051,9 @@ static char *Game_demo_title_screen_fname[GR_NUM_RESOLUTIONS] = { }; #endif +// auto-lang stuff +int detect_lang(); + // cdrom stuff char Game_CDROM_dir[MAX_PATH_LEN]; int init_cdrom(); @@ -2171,7 +2177,7 @@ void game_init() // initialize localization module. Make sure this is down AFTER initialzing OS. // int t1 = timer_get_milliseconds(); - lcl_init(); + lcl_init( detect_lang() ); lcl_xstr_init(); // mprintf(("LCL_INIT() TOOK %d MS\n", timer_get_milliseconds()-t1)); @@ -8601,6 +8607,61 @@ int game_do_cd_mission_check(char *filename) // // ---------------------------------------------------------------- +// ---------------------------------------------------------------- +// +// Language Autodetection stuff +// + +// this layout order must match Lcl_languages in localize.cpp in order for the +// correct language to be detected +int Lang_auto_detect_checksums[LCL_NUM_LANGUAGES] = { + 589986744, // English + -1132430286, // German + 0, // French +}; + +// default setting is "-1" to use config file with English as fall back +// DO NOT change the default setting here or something uncouth might happen +// in the localization code +int detect_lang() +{ + uint file_checksum; + int idx; + + // try and open the file to verify + CFILE *detect = cfopen("font01.vf", "rb"); + + // will use default setting if something went wrong + if (!detect) { + return -1; + } + + // get the long checksum of the file + file_checksum = 0; + cfseek(detect, 0, SEEK_SET); + cf_chksum_long(detect, &file_checksum); + cfclose(detect); + detect = NULL; + + // now compare the checksum/filesize against known #'s + for (idx=0; idxstats.m_kill_count_ok); gr_get_string_size(&w, &h, num_kills_string); - gr_string(Kills_text_val_coords[gr_screen.res][0]-w, Kills_text_val_coords[gr_screen.res][1], num_kills_string); + if (Lcl_gr) { + gr_string(Kills_text_val_coords_gr[gr_screen.res][0]-w, Kills_text_val_coords_gr[gr_screen.res][1], num_kills_string); + } else { + gr_string(Kills_text_val_coords[gr_screen.res][0]-w, Kills_text_val_coords[gr_screen.res][1], num_kills_string); + } } // maybe show the netlag icon on the hud diff --git a/src/io/key.cpp b/src/io/key.cpp index 462b2d8..50e1d81 100644 --- a/src/io/key.cpp +++ b/src/io/key.cpp @@ -15,6 +15,9 @@ * * * $Log$ + * Revision 1.10 2003/05/18 03:55:30 taylor + * automatic language selection support + * * Revision 1.9 2003/01/30 19:55:01 relnev * add German keys (this is mostly a patch already sent in by someone else that hasn't made it into cvs yet) (Taylor Richards) * @@ -284,36 +287,36 @@ void FillSDLArray () SDLtoFS2[SDLK_y] = KEY_Y; SDLtoFS2[SDLK_z] = KEY_Z; -#ifdef GERMAN_BUILD - SDLtoFS2[SDLK_WORLD_63] = KEY_MINUS; - SDLtoFS2[SDLK_WORLD_20] = KEY_EQUAL; - SDLtoFS2[SDLK_MINUS] = KEY_DIVIDE; - SDLtoFS2[SDLK_HASH] = KEY_SLASH; - SDLtoFS2[SDLK_COMMA] = KEY_COMMA; - SDLtoFS2[SDLK_PERIOD] = KEY_PERIOD; - SDLtoFS2[SDLK_WORLD_86] = KEY_SEMICOL; + if (Lcl_gr) { + SDLtoFS2[SDLK_WORLD_63] = KEY_MINUS; + SDLtoFS2[SDLK_WORLD_20] = KEY_EQUAL; + SDLtoFS2[SDLK_MINUS] = KEY_DIVIDE; + SDLtoFS2[SDLK_HASH] = KEY_SLASH; + SDLtoFS2[SDLK_COMMA] = KEY_COMMA; + SDLtoFS2[SDLK_PERIOD] = KEY_PERIOD; + SDLtoFS2[SDLK_WORLD_86] = KEY_SEMICOL; - SDLtoFS2[SDLK_WORLD_92] = KEY_LBRACKET; - SDLtoFS2[SDLK_PLUS] = KEY_RBRACKET; + SDLtoFS2[SDLK_WORLD_92] = KEY_LBRACKET; + SDLtoFS2[SDLK_PLUS] = KEY_RBRACKET; - SDLtoFS2[SDLK_CARET] = KEY_LAPOSTRO; - SDLtoFS2[SDLK_WORLD_68] = KEY_RAPOSTRO; -#else - SDLtoFS2[SDLK_MINUS] = KEY_MINUS; - SDLtoFS2[SDLK_EQUALS] = KEY_EQUAL; - SDLtoFS2[SDLK_SLASH] = KEY_DIVIDE; // No idea - DDOI - SDLtoFS2[SDLK_BACKSLASH] = KEY_SLASH; - //SDLtoFS2[SDLK_BACKSLASH] = KEY_SLASH_UK; // ? - SDLtoFS2[SDLK_COMMA] = KEY_COMMA; - SDLtoFS2[SDLK_PERIOD] = KEY_PERIOD; - SDLtoFS2[SDLK_SEMICOLON] = KEY_SEMICOL; - - SDLtoFS2[SDLK_LEFTBRACKET] = KEY_LBRACKET; - SDLtoFS2[SDLK_RIGHTBRACKET] = KEY_RBRACKET; - - SDLtoFS2[SDLK_BACKQUOTE] = KEY_LAPOSTRO; - SDLtoFS2[SDLK_QUOTE] = KEY_RAPOSTRO; -#endif + SDLtoFS2[SDLK_CARET] = KEY_LAPOSTRO; + SDLtoFS2[SDLK_WORLD_68] = KEY_RAPOSTRO; + } else { + SDLtoFS2[SDLK_MINUS] = KEY_MINUS; + SDLtoFS2[SDLK_EQUALS] = KEY_EQUAL; + SDLtoFS2[SDLK_SLASH] = KEY_DIVIDE; // No idea - DDOI + SDLtoFS2[SDLK_BACKSLASH] = KEY_SLASH; + //SDLtoFS2[SDLK_BACKSLASH] = KEY_SLASH_UK; // ? + SDLtoFS2[SDLK_COMMA] = KEY_COMMA; + SDLtoFS2[SDLK_PERIOD] = KEY_PERIOD; + SDLtoFS2[SDLK_SEMICOLON] = KEY_SEMICOL; + + SDLtoFS2[SDLK_LEFTBRACKET] = KEY_LBRACKET; + SDLtoFS2[SDLK_RIGHTBRACKET] = KEY_RBRACKET; + + SDLtoFS2[SDLK_BACKQUOTE] = KEY_LAPOSTRO; + SDLtoFS2[SDLK_QUOTE] = KEY_RAPOSTRO; + } SDLtoFS2[SDLK_ESCAPE] = KEY_ESC; SDLtoFS2[SDLK_RETURN] = KEY_ENTER; @@ -833,7 +836,6 @@ void key_mark( uint code, int state, uint latency ) code = KEY_Y; break; } - } if ( (code == 0xc5) && !Key_running_NT ) { @@ -1366,7 +1368,3 @@ void di_cleanup() } #endif - - - - diff --git a/src/localization/localize.cpp b/src/localization/localize.cpp index 8d39775..2b422b9 100644 --- a/src/localization/localize.cpp +++ b/src/localization/localize.cpp @@ -14,6 +14,9 @@ * * * $Log$ + * Revision 1.4 2003/05/18 03:55:30 taylor + * automatic language selection support + * * Revision 1.3 2002/06/09 04:41:22 relnev * added copyright header * @@ -436,14 +439,11 @@ void lcl_init(int lang_init) // read the language from the registry if(lang_init < 0){ memset(lang_string, 0, 128); -#if defined(GERMAN_BUILD) - // defualt lang to German, mein herr - ret = os_config_read_string(NULL, "Language", "German"); -#else + // default to DEFAULT_LANGUAGE (which should be english so we dont have to put German text // in tstrings in the #default section ret = os_config_read_string(NULL, "Language", DEFAULT_LANGUAGE); -#endif + if(ret == NULL){ Int3(); strcpy(lang_string, DEFAULT_LANGUAGE); @@ -1066,11 +1066,11 @@ int lcl_ext_lookup(char *out, int id) // found a matching string/id pair case 2 : // success -#if defined(GERMAN_BUILD) - // this is because tstrings.tbl reads in as ANSI for some reason - // opening tstrings with "rb" mode didnt seem to help, so its now still "rt" like before - lcl_fix_umlauts(out, LCL_TO_ASCII); -#endif + if (Lcl_gr) { + // this is because tstrings.tbl reads in as ANSI for some reason + // opening tstrings with "rb" mode didnt seem to help, so its now still "rt" like before + lcl_fix_umlauts(out, LCL_TO_ASCII); + } return 1; // end of language found diff --git a/src/mission/missiongoals.cpp b/src/mission/missiongoals.cpp index 1ff4750..37aee57 100644 --- a/src/mission/missiongoals.cpp +++ b/src/mission/missiongoals.cpp @@ -15,6 +15,9 @@ * Module for working with Mission goals * * $Log$ + * Revision 1.4 2003/05/18 03:55:30 taylor + * automatic language selection support + * * Revision 1.3 2002/06/09 04:41:22 relnev * added copyright header * @@ -354,6 +357,7 @@ #include "gamesnd.h" #include "alphacolors.h" #include "multi_team.h" +#include "localize.h" // timestamp stuff for evaluating mission goals #define GOAL_TIMESTAMP 0 // make immediately eval @@ -391,23 +395,22 @@ static int Goal_screen_icon_xcoord[GR_NUM_RESOLUTIONS] = { }; -#if defined(GERMAN_BUILD) - // german version gets slightly diff coords - static int Objective_key_text_coords[GR_NUM_RESOLUTIONS][3][2] = { - { - // GR_640 - {175, 344}, - {316, 344}, - {432, 344} - }, - { - // GR_1024 - {310, 546}, - {536, 546}, - {688, 546} - } - }; - static int Objective_key_icon_coords[GR_NUM_RESOLUTIONS][3][2] = { +// german version gets slightly diff coords +static int Objective_key_text_coords_gr[GR_NUM_RESOLUTIONS][3][2] = { + { + // GR_640 + {175, 344}, + {316, 344}, + {432, 344} + }, + { + // GR_1024 + {310, 546}, + {536, 546}, + {688, 546} + } +}; +static int Objective_key_icon_coords_gr[GR_NUM_RESOLUTIONS][3][2] = { { // GR_640 {150, 339}, @@ -421,22 +424,22 @@ static int Goal_screen_icon_xcoord[GR_NUM_RESOLUTIONS] = { {650, 542} } }; -#else - static int Objective_key_text_coords[GR_NUM_RESOLUTIONS][3][2] = { - { - // GR_640 - {195, 344}, - {306, 344}, - {432, 344} - }, - { - // GR_1024 - {310, 546}, - {486, 546}, - {688, 546} - } - }; - static int Objective_key_icon_coords[GR_NUM_RESOLUTIONS][3][2] = { + +static int Objective_key_text_coords[GR_NUM_RESOLUTIONS][3][2] = { + { + // GR_640 + {195, 344}, + {306, 344}, + {432, 344} + }, + { + // GR_1024 + {310, 546}, + {486, 546}, + {688, 546} + } +}; +static int Objective_key_icon_coords[GR_NUM_RESOLUTIONS][3][2] = { { // GR_640 {170, 339}, @@ -450,7 +453,6 @@ static int Goal_screen_icon_xcoord[GR_NUM_RESOLUTIONS] = { {650, 542} } }; -#endif #define NUM_GOAL_SCREEN_BUTTONS 3 // total number of buttons @@ -1018,15 +1020,27 @@ void ML_render_objectives_key() { // display icon key at the bottom gr_set_bitmap(Goal_complete_bitmap); - gr_bitmap(Objective_key_icon_coords[gr_screen.res][0][0], Objective_key_icon_coords[gr_screen.res][0][1]); - gr_set_bitmap(Goal_incomplete_bitmap); - gr_bitmap(Objective_key_icon_coords[gr_screen.res][1][0], Objective_key_icon_coords[gr_screen.res][1][1]); - gr_set_bitmap(Goal_failed_bitmap); - gr_bitmap(Objective_key_icon_coords[gr_screen.res][2][0], Objective_key_icon_coords[gr_screen.res][2][1]); + if (Lcl_gr) { + gr_bitmap(Objective_key_icon_coords_gr[gr_screen.res][0][0], Objective_key_icon_coords_gr[gr_screen.res][0][1]); + gr_set_bitmap(Goal_incomplete_bitmap); + gr_bitmap(Objective_key_icon_coords_gr[gr_screen.res][1][0], Objective_key_icon_coords_gr[gr_screen.res][1][1]); + gr_set_bitmap(Goal_failed_bitmap); + gr_bitmap(Objective_key_icon_coords_gr[gr_screen.res][2][0], Objective_key_icon_coords_gr[gr_screen.res][2][1]); - gr_string(Objective_key_text_coords[gr_screen.res][0][0], Objective_key_text_coords[gr_screen.res][0][1] , XSTR("Complete", 1437)); - gr_string(Objective_key_text_coords[gr_screen.res][1][0], Objective_key_text_coords[gr_screen.res][1][1] , XSTR("Incomplete", 1438)); - gr_string(Objective_key_text_coords[gr_screen.res][2][0], Objective_key_text_coords[gr_screen.res][2][1] , XSTR("Failed", 1439)); + gr_string(Objective_key_text_coords_gr[gr_screen.res][0][0], Objective_key_text_coords_gr[gr_screen.res][0][1] , XSTR("Complete", 1437)); + gr_string(Objective_key_text_coords_gr[gr_screen.res][1][0], Objective_key_text_coords_gr[gr_screen.res][1][1] , XSTR("Incomplete", 1438)); + gr_string(Objective_key_text_coords_gr[gr_screen.res][2][0], Objective_key_text_coords_gr[gr_screen.res][2][1] , XSTR("Failed", 1439)); + } else { + gr_bitmap(Objective_key_icon_coords[gr_screen.res][0][0], Objective_key_icon_coords[gr_screen.res][0][1]); + gr_set_bitmap(Goal_incomplete_bitmap); + gr_bitmap(Objective_key_icon_coords[gr_screen.res][1][0], Objective_key_icon_coords[gr_screen.res][1][1]); + gr_set_bitmap(Goal_failed_bitmap); + gr_bitmap(Objective_key_icon_coords[gr_screen.res][2][0], Objective_key_icon_coords[gr_screen.res][2][1]); + + gr_string(Objective_key_text_coords[gr_screen.res][0][0], Objective_key_text_coords[gr_screen.res][0][1] , XSTR("Complete", 1437)); + gr_string(Objective_key_text_coords[gr_screen.res][1][0], Objective_key_text_coords[gr_screen.res][1][1] , XSTR("Incomplete", 1438)); + gr_string(Objective_key_text_coords[gr_screen.res][2][0], Objective_key_text_coords[gr_screen.res][2][1] , XSTR("Failed", 1439)); + } } -- 2.39.2