From 59cb4da62817d04c62103d40261b5b3040f6302d Mon Sep 17 00:00:00 2001 From: glx Date: Mon, 4 Jun 2007 19:49:00 +0000 Subject: (svn r10035) -Change: simplified network language string sorting --- src/network/network.h | 2 +- src/network/network_gui.cpp | 76 +++++++++++++-------------------------------- 2 files changed, 22 insertions(+), 56 deletions(-) diff --git a/src/network/network.h b/src/network/network.h index df2dbbfca..6cd534ec9 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -107,7 +107,7 @@ enum NetworkLanguage { NETLANG_SWEDISH, NETLANG_TURKISH, NETLANG_UKRAINIAN, - NETLANG_LAST + NETLANG_COUNT }; VARDEF NetworkGameInfo _network_game_info; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 2bc3cc27e..241796852 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -85,55 +85,17 @@ static const StringID _players_dropdown[] = { INVALID_STRING_ID }; -static StringID _language_dropdown[] = { - STR_NETWORK_LANG_ANY, - STR_NETWORK_LANG_ENGLISH, - STR_NETWORK_LANG_GERMAN, - STR_NETWORK_LANG_FRENCH, - STR_NETWORK_LANG_BRAZILIAN, - STR_NETWORK_LANG_BULGARIAN, - STR_NETWORK_LANG_CHINESE, - STR_NETWORK_LANG_CZECH, - STR_NETWORK_LANG_DANISH, - STR_NETWORK_LANG_DUTCH, - STR_NETWORK_LANG_ESPERANTO, - STR_NETWORK_LANG_FINNISH, - STR_NETWORK_LANG_HUNGARIAN, - STR_NETWORK_LANG_ICELANDIC, - STR_NETWORK_LANG_ITALIAN, - STR_NETWORK_LANG_JAPANESE, - STR_NETWORK_LANG_KOREAN, - STR_NETWORK_LANG_LITHUANIAN, - STR_NETWORK_LANG_NORWEGIAN, - STR_NETWORK_LANG_POLISH, - STR_NETWORK_LANG_PORTUGUESE, - STR_NETWORK_LANG_ROMANIAN, - STR_NETWORK_LANG_RUSSIAN, - STR_NETWORK_LANG_SLOVAK, - STR_NETWORK_LANG_SLOVENIAN, - STR_NETWORK_LANG_SPANISH, - STR_NETWORK_LANG_SWEDISH, - STR_NETWORK_LANG_TURKISH, - STR_NETWORK_LANG_UKRAINIAN, - INVALID_STRING_ID -}; - -/* Used to map the _server_lang value to the sorted string. */ -static int _server_lang_to_string[NETLANG_LAST] = {0}; +static StringID _language_dropdown[NETLANG_COUNT + 1] = {STR_NULL}; void SortNetworkLanguages() { - /* Sort the strings (we don't move 'any' and the 'invalid' one) */ - qsort(&_language_dropdown[1], NETLANG_LAST - 1, sizeof(StringID), &StringIDSorter); - - /* Update the lookup table */ - for (int i = NETLANG_ANY; i < NETLANG_LAST; i++) { - for (int j = NETLANG_ANY; j < NETLANG_LAST; j++) { - if (_language_dropdown[j] - STR_NETWORK_LANG_ANY == i) { - _server_lang_to_string[i] = j; - break; - } - } + /* Init the strings */ + if (_language_dropdown[0] == STR_NULL) { + for (int i = 0; i < NETLANG_COUNT; i++) _language_dropdown[i] = STR_NETWORK_LANG_ANY + i; + _language_dropdown[NETLANG_COUNT] = INVALID_STRING_ID; } + + /* Sort the strings (we don't move 'any' and the 'invalid' one) */ + qsort(&_language_dropdown[1], NETLANG_COUNT - 1, sizeof(StringID), &StringIDSorter); } enum { @@ -385,7 +347,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) DrawString(x, y, STR_NETWORK_CLIENTS, 2); y += 10; - SetDParam(0, _language_dropdown[_server_lang_to_string[sel->info.server_lang]]); + SetDParam(0, STR_NETWORK_LANG_ANY + sel->info.server_lang); DrawString(x, y, STR_NETWORK_LANGUAGE, 2); // server language y += 10; @@ -652,7 +614,7 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e) SetDParam( 9, _players_dropdown[_network_game_info.clients_max]); SetDParam(11, _players_dropdown[_network_game_info.companies_max]); SetDParam(13, _players_dropdown[_network_game_info.spectators_max]); - SetDParam(15, _language_dropdown[_server_lang_to_string[_network_game_info.server_lang]]); + SetDParam(15, STR_NETWORK_LANG_ANY + _network_game_info.server_lang); DrawWindowWidgets(w); GfxFillRect(11, 63, 258, 215, 0xD7); @@ -722,9 +684,17 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e) case 13: case 14: /* Number of Spectators */ ShowDropDownMenu(w, _players_dropdown, _network_game_info.spectators_max, 14, 0, 0); break; - case 15: case 16: /* Language */ - ShowDropDownMenu(w, _language_dropdown, _server_lang_to_string[_network_game_info.server_lang], 16, 0, 0); + case 15: case 16: { /* Language */ + int sel; + for (uint i = 0; i < lengthof(_language_dropdown) - 1; i++) { + if (_language_dropdown[i] == STR_NETWORK_LANG_ANY + _network_game_info.server_lang) { + sel = i; + break; + } + } + ShowDropDownMenu(w, _language_dropdown, sel, 16, 0, 0); break; + } case 17: /* Start game */ _is_network_server = true; @@ -759,11 +729,7 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e) case 12: _network_game_info.companies_max = e->we.dropdown.index; break; case 14: _network_game_info.spectators_max = e->we.dropdown.index; break; case 16: - for (uint i = 0; i < lengthof(_server_lang_to_string); i++) { - if (_server_lang_to_string[i] == e->we.dropdown.index) { - _network_game_info.server_lang = i; - } - } + _network_game_info.server_lang = _language_dropdown[e->we.dropdown.index] - STR_NETWORK_LANG_ANY; break; } -- cgit v1.2.3-70-g09d2