summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/network.h36
-rw-r--r--src/network/network_gui.cpp57
-rw-r--r--src/strings.cpp15
-rw-r--r--src/strings.h2
4 files changed, 69 insertions, 41 deletions
diff --git a/src/network/network.h b/src/network/network.h
index da8b52c01..df2dbbfca 100644
--- a/src/network/network.h
+++ b/src/network/network.h
@@ -76,12 +76,38 @@ enum NetworkJoinStatus {
NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
};
-// language ids for server_lang and client_lang
+/* Language ids for server_lang and client_lang. Do NOT modify the order. */
enum NetworkLanguage {
- NETLANG_ANY = 0,
- NETLANG_ENGLISH = 1,
- NETLANG_GERMAN = 2,
- NETLANG_FRENCH = 3,
+ NETLANG_ANY = 0,
+ NETLANG_ENGLISH,
+ NETLANG_GERMAN,
+ NETLANG_FRENCH,
+ NETLANG_BRAZILIAN,
+ NETLANG_BULGARIAN,
+ NETLANG_CHINESE,
+ NETLANG_CZECH,
+ NETLANG_DANISH,
+ NETLANG_DUTCH,
+ NETLANG_ESPERANTO,
+ NETLANG_FINNISH,
+ NETLANG_HUNGARIAN,
+ NETLANG_ICELANDIC,
+ NETLANG_ITALIAN,
+ NETLANG_JAPANESE,
+ NETLANG_KOREAN,
+ NETLANG_LITHUANIAN,
+ NETLANG_NORWEGIAN,
+ NETLANG_POLISH,
+ NETLANG_PORTUGUESE,
+ NETLANG_ROMANIAN,
+ NETLANG_RUSSIAN,
+ NETLANG_SLOVAK,
+ NETLANG_SLOVENIAN,
+ NETLANG_SPANISH,
+ NETLANG_SWEDISH,
+ NETLANG_TURKISH,
+ NETLANG_UKRAINIAN,
+ NETLANG_LAST
};
VARDEF NetworkGameInfo _network_game_info;
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 80ef20b86..2bc3cc27e 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -84,20 +84,20 @@ static const StringID _players_dropdown[] = {
STR_NETWORK_10_PLAYERS,
INVALID_STRING_ID
};
-/* The strings are in alphabetical order (in English). */
-static const StringID _language_dropdown[] = {
+
+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_ENGLISH,
STR_NETWORK_LANG_ESPERANTO,
STR_NETWORK_LANG_FINNISH,
- STR_NETWORK_LANG_FRENCH,
- STR_NETWORK_LANG_GERMAN,
STR_NETWORK_LANG_HUNGARIAN,
STR_NETWORK_LANG_ICELANDIC,
STR_NETWORK_LANG_ITALIAN,
@@ -119,37 +119,22 @@ static const StringID _language_dropdown[] = {
};
/* Used to map the _server_lang value to the sorted string. */
-static const int _server_lang_to_string[] = {
- 0, // Any
- 7, // English
- 11, // German
- 10, // French
- 1, // Brazilian
- 2, // Bulgarian
- 3, // Chinese
- 4, // Czech
- 5, // Danish
- 6, // Dutch
- 8, // Esperanto
- 9, // Finnish
- 12, // Hungarian
- 13, // Icelandic
- 14, // Italian
- 15, // Japanese
- 16, // Korean
- 17, // Lithuanian
- 18, // Norwegian
- 19, // Polish
- 20, // Portuguese
- 21, // Romanian
- 22, // Russian
- 23, // Slovak
- 24, // Slovenian
- 25, // Spanish
- 26, // Swedish
- 27, // Turkish
- 28, // Ukrainian
-};
+static int _server_lang_to_string[NETLANG_LAST] = {0};
+
+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;
+ }
+ }
+ }
+}
enum {
NET_PRC__OFFSET_TOP_WIDGET = 54,
diff --git a/src/strings.cpp b/src/strings.cpp
index eae48281a..57b3111c2 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -1101,6 +1101,8 @@ StringID RemapOldStringID(StringID s)
}
}
+extern void SortNetworkLanguages();
+
bool ReadLanguagePack(int lang_index)
{
int tot_count, i;
@@ -1156,6 +1158,7 @@ bool ReadLanguagePack(int lang_index)
_dynlang.curr = lang_index;
SetCurrentGrfLangID(_langpack->isocode);
+ SortNetworkLanguages();
return true;
}
@@ -1191,6 +1194,18 @@ static int CDECL LanguageCompareFunc(const void *a, const void *b)
return strcmp(cmp1->file, cmp2->file);
}
+int CDECL StringIDSorter(const void *a, const void *b)
+{
+ const StringID va = *(const StringID*)a;
+ const StringID vb = *(const StringID*)b;
+ char stra[512];
+ char strb[512];
+ GetString(stra, va, lastof(stra));
+ GetString(strb, vb, lastof(strb));
+
+ return strcmp(stra, strb);
+}
+
/**
* Checks whether the given language is already found.
* @param langs languages we've found so fa
diff --git a/src/strings.h b/src/strings.h
index 3b220f4ba..22ec9f39d 100644
--- a/src/strings.h
+++ b/src/strings.h
@@ -16,4 +16,6 @@ int32 GetParamInt32();
bool ReadLanguagePack(int index);
void InitializeLanguagePacks();
+int CDECL StringIDSorter(const void *a, const void *b);
+
#endif /* STRINGS_H */