diff options
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/client/components/menus.cpp | 29 | ||||
| -rw-r--r-- | src/game/client/components/menus_browser.cpp | 3 | ||||
| -rw-r--r-- | src/game/client/components/menus_settings.cpp | 49 | ||||
| -rw-r--r-- | src/game/client/gameclient.cpp | 13 | ||||
| -rw-r--r-- | src/game/client/gameclient.hpp | 1 | ||||
| -rw-r--r-- | src/game/localization.cpp | 44 | ||||
| -rw-r--r-- | src/game/localization.hpp | 2 |
7 files changed, 87 insertions, 54 deletions
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 398bd1ae..932597f7 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -12,9 +12,7 @@ #include "skins.hpp" #include <engine/e_client_interface.h> -extern "C" { -#include <engine/e_linereader.h> -} + #include <game/version.hpp> #include <game/generated/g_protocol.hpp> @@ -622,32 +620,7 @@ void MENUS::render_news(RECT main_view) void MENUS::on_init() { - LINEREADER lr; - IOHANDLE io = io_open("swedish.txt", IOFLAG_READ); - linereader_init(&lr, io); - char *line; - while((line = linereader_get(&lr))) - { - if(!str_length(line)) - continue; - - char *replacement = linereader_get(&lr); - if(!replacement) - { - dbg_msg("", "unexpected end of file"); - break; - } - - if(replacement[0] != '=' || replacement[1] != '=' || replacement[2] != ' ') - { - dbg_msg("", "malform replacement line for '%s'", line); - continue; - } - replacement += 3; - localization.add_string(line, replacement); - } - /* array<string> my_strings; array<string>::range r2; diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index a7751347..3d58af93 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -9,6 +9,7 @@ #include <game/client/ui.hpp> #include <game/client/render.hpp> #include "menus.hpp" +#include <game/localization.hpp> #include <game/version.hpp> void MENUS::render_serverbrowser_serverlist(RECT view) @@ -27,7 +28,7 @@ void MENUS::render_serverbrowser_serverlist(RECT view) { int id; int sort; - const char *caption; + LOC_CONSTSTRING caption; int direction; float width; int flags; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index beeab046..58678b80 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -13,6 +13,7 @@ #include <game/client/render.hpp> #include <game/client/gameclient.hpp> #include <game/client/animstate.hpp> +#include <game/localization.hpp> #include "binds.hpp" #include "menus.hpp" @@ -248,35 +249,35 @@ typedef void (*assign_func_callback)(CONFIGURATION *config, int value); typedef struct { - const char *name; + LOC_CONSTSTRING name; const char *command; int keyid; } KEYINFO; -// TODO: localize KEYINFO keys[] = { - { "Move Left:", "+left", 0}, - { "Move Right:", "+right", 0 }, - { "Jump:", "+jump", 0 }, - { "Fire:", "+fire", 0 }, - { "Hook:", "+hook", 0 }, - { "Hammer:", "+weapon1", 0 }, - { "Pistol:", "+weapon2", 0 }, - { "Shotgun:", "+weapon3", 0 }, - { "Grenade:", "+weapon4", 0 }, - { "Rifle:", "+weapon5", 0 }, - { "Next Weapon:", "+nextweapon", 0 }, - { "Prev. Weapon:", "+prevweapon", 0 }, - { "Vote Yes:", "vote yes", 0 }, - { "Vote No:", "vote no", 0 }, - { "Chat:", "chat all", 0 }, - { "Team Chat:", "chat team", 0 }, - { "Emoticon:", "+emote", 0 }, - { "Console:", "toggle_local_console", 0 }, - { "Remote Console:", "toggle_remote_console", 0 }, - { "Screenshot:", "screenshot", 0 }, - { "Scoreboard:", "+scoreboard", 0 }, + // we need to do localize so the scripts can pickup the string + { localize("Move Left:"), "+left", 0}, + { localize("Move Right:"), "+right", 0 }, + { localize("Jump:"), "+jump", 0 }, + { localize("Fire:"), "+fire", 0 }, + { localize("Hook:"), "+hook", 0 }, + { localize("Hammer:"), "+weapon1", 0 }, + { localize("Pistol:"), "+weapon2", 0 }, + { localize("Shotgun:"), "+weapon3", 0 }, + { localize("Grenade:"), "+weapon4", 0 }, + { localize("Rifle:"), "+weapon5", 0 }, + { localize("Next Weapon:"), "+nextweapon", 0 }, + { localize("Prev. Weapon:"), "+prevweapon", 0 }, + { localize("Vote Yes:"), "vote yes", 0 }, + { localize("Vote No:"), "vote no", 0 }, + { localize("Chat:"), "chat all", 0 }, + { localize("Team Chat:"), "chat team", 0 }, + { localize("Emoticon:"), "+emote", 0 }, + { localize("Console:"), "toggle_local_console", 0 }, + { localize("Remote Console:"), "toggle_remote_console", 0 }, + { localize("Screenshot:"), "screenshot", 0 }, + { localize("Scoreboard:"), "+scoreboard", 0 }, }; const int key_count = sizeof(keys) / sizeof(KEYINFO); @@ -292,7 +293,7 @@ void MENUS::ui_do_getbuttons(int start, int stop, RECT view) ui_do_label(&label, key.name, 14.0f, -1); int oldid = key.keyid; - int newid = ui_do_key_reader((void *)keys[i].name, &button, oldid); + int newid = ui_do_key_reader((void *)&keys[i].name, &button, oldid); if(newid != oldid) { gameclient.binds->bind(oldid, ""); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index ae501fa2..834aa29b 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -6,6 +6,7 @@ #include <game/generated/gc_data.hpp> #include <game/layers.hpp> +#include <game/localization.hpp> #include "render.hpp" #include "gameclient.hpp" @@ -158,7 +159,10 @@ void GAMECLIENT::on_console_init() input.add(&emoticon); input.add(controls); input.add(binds); - + + // + MACRO_REGISTER_COMMAND("language", "s", CFGFLAG_CLIENT, con_language, this, "Sets the language"); + // add the some console commands MACRO_REGISTER_COMMAND("team", "i", CFGFLAG_CLIENT, con_team, this, "Switch team"); MACRO_REGISTER_COMMAND("kill", "", CFGFLAG_CLIENT, con_kill, this, "Kill yourself"); @@ -881,3 +885,10 @@ void GAMECLIENT::con_kill(void *result, void *user_data) { ((GAMECLIENT*)user_data)->send_kill(-1); } + +void GAMECLIENT::con_language(void *result, void *user_data) +{ + char buf[128]; + str_format(buf, sizeof(buf), "data/languages/%s.txt", console_arg_string(result, 0)); + localization.load(buf); +} diff --git a/src/game/client/gameclient.hpp b/src/game/client/gameclient.hpp index 35b95f27..7d8c3701 100644 --- a/src/game/client/gameclient.hpp +++ b/src/game/client/gameclient.hpp @@ -31,6 +31,7 @@ class GAMECLIENT int predicted_tick; int last_new_predicted_tick; + static void con_language(void *result, void *user_data); static void con_team(void *result, void *user_data); static void con_kill(void *result, void *user_data); diff --git a/src/game/localization.cpp b/src/game/localization.cpp index cfc659f5..58ec539c 100644 --- a/src/game/localization.cpp +++ b/src/game/localization.cpp @@ -1,6 +1,10 @@ #include "localization.hpp" +extern "C" { +#include <engine/e_linereader.h> +} + static unsigned str_hash(const char *str) { unsigned hash = 5381; @@ -43,8 +47,48 @@ void LOCALIZATIONDATABASE::add_string(const char *org_str, const char *new_str) s.hash = str_hash(org_str); s.replacement = new_str; strings.add(s); +} + +bool LOCALIZATIONDATABASE::load(const char *filename) +{ + LINEREADER lr; + IOHANDLE io = io_open(filename, IOFLAG_READ); + if(!io) + return false; + + dbg_msg("localization", "loaded '%s'", filename); + strings.clear(); + + linereader_init(&lr, io); + char *line; + while((line = linereader_get(&lr))) + { + if(!str_length(line)) + continue; + + if(line[0] == '#') // skip comments + continue; + + char *replacement = linereader_get(&lr); + if(!replacement) + { + dbg_msg("", "unexpected end of file"); + break; + } + + if(replacement[0] != '=' || replacement[1] != '=' || replacement[2] != ' ') + { + dbg_msg("", "malform replacement line for '%s'", line); + continue; + } + + replacement += 3; + localization.add_string(line, replacement); + } + current_version++; + return true; } const char *LOCALIZATIONDATABASE::find_string(unsigned hash) diff --git a/src/game/localization.hpp b/src/game/localization.hpp index 87b6e2f8..de6849d4 100644 --- a/src/game/localization.hpp +++ b/src/game/localization.hpp @@ -18,6 +18,8 @@ class LOCALIZATIONDATABASE public: LOCALIZATIONDATABASE(); + bool load(const char *filename); + int version() { return current_version; } void add_string(const char *org_str, const char *new_str); |