mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r11886) -Add: sort the strings in languages dropdown
This commit is contained in:
parent
4d9a9bf6ff
commit
69c18efdca
|
@ -24,6 +24,7 @@
|
||||||
#include "core/alloc_func.hpp"
|
#include "core/alloc_func.hpp"
|
||||||
#include "string_func.h"
|
#include "string_func.h"
|
||||||
#include "gfx_func.h"
|
#include "gfx_func.h"
|
||||||
|
#include "widgets/dropdown_type.h"
|
||||||
#include "widgets/dropdown_func.h"
|
#include "widgets/dropdown_func.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
|
@ -157,6 +158,26 @@ enum GameOptionsWidgets {
|
||||||
GAMEOPT_SCREENSHOT_BTN,
|
GAMEOPT_SCREENSHOT_BTN,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update/redraw the languages dropdown
|
||||||
|
* @param w the window the dropdown belongs to
|
||||||
|
*/
|
||||||
|
static void ShowLangDropdown(Window *w)
|
||||||
|
{
|
||||||
|
typedef std::map<StringID, int, StringIDCompare> LangList;
|
||||||
|
|
||||||
|
/* Sort language names */
|
||||||
|
LangList langs;
|
||||||
|
for (int i = 0; i < _dynlang.num; i++) langs[SPECSTR_LANGUAGE_START + i] = i;
|
||||||
|
|
||||||
|
DropDownList *list = new DropDownList();
|
||||||
|
for (LangList::iterator it = langs.begin(); it != langs.end(); it++) {
|
||||||
|
list->push_back(new DropDownListStringItem((*it).first, (*it).second, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowDropDownList(w, list, _dynlang.curr, GAMEOPT_LANG_BTN);
|
||||||
|
}
|
||||||
|
|
||||||
static void ShowCustCurrency();
|
static void ShowCustCurrency();
|
||||||
|
|
||||||
static void GameOptionsWndProc(Window *w, WindowEvent *e)
|
static void GameOptionsWndProc(Window *w, WindowEvent *e)
|
||||||
|
@ -228,7 +249,7 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
|
||||||
break; // not implemented
|
break; // not implemented
|
||||||
|
|
||||||
case GAMEOPT_LANG_TXT: case GAMEOPT_LANG_BTN: /* Setup interface language dropdown */
|
case GAMEOPT_LANG_TXT: case GAMEOPT_LANG_BTN: /* Setup interface language dropdown */
|
||||||
ShowDropDownMenu(w, _dynlang.dropdown, _dynlang.curr, GAMEOPT_LANG_BTN, 0, 0);
|
ShowLangDropdown(w);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GAMEOPT_RESOLUTION_TXT: case GAMEOPT_RESOLUTION_BTN: /* Setup resolution dropdown */
|
case GAMEOPT_RESOLUTION_TXT: case GAMEOPT_RESOLUTION_BTN: /* Setup resolution dropdown */
|
||||||
|
|
|
@ -1318,14 +1318,6 @@ const char *GetCurrentLocale(const char *param)
|
||||||
}
|
}
|
||||||
#endif /* !(defined(WIN32) || defined(__APPLE__)) */
|
#endif /* !(defined(WIN32) || defined(__APPLE__)) */
|
||||||
|
|
||||||
static int CDECL LanguageCompareFunc(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
const Language *cmp1 = (const Language*)a;
|
|
||||||
const Language *cmp2 = (const Language*)b;
|
|
||||||
|
|
||||||
return strcmp(cmp1->file, cmp2->file);
|
|
||||||
}
|
|
||||||
|
|
||||||
int CDECL StringIDSorter(const void *a, const void *b)
|
int CDECL StringIDSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const StringID va = *(const StringID*)a;
|
const StringID va = *(const StringID*)a;
|
||||||
|
@ -1432,9 +1424,6 @@ void InitializeLanguagePacks()
|
||||||
}
|
}
|
||||||
if (language_count == 0) error("No available language packs (invalid versions?)");
|
if (language_count == 0) error("No available language packs (invalid versions?)");
|
||||||
|
|
||||||
/* Sort the language names alphabetically */
|
|
||||||
qsort(files, language_count, sizeof(Language), LanguageCompareFunc);
|
|
||||||
|
|
||||||
/* Acquire the locale of the current system */
|
/* Acquire the locale of the current system */
|
||||||
const char *lang = GetCurrentLocale("LC_MESSAGES");
|
const char *lang = GetCurrentLocale("LC_MESSAGES");
|
||||||
if (lang == NULL) lang = "en_GB";
|
if (lang == NULL) lang = "en_GB";
|
||||||
|
@ -1453,7 +1442,6 @@ void InitializeLanguagePacks()
|
||||||
|
|
||||||
dl->ent[dl->num].file = files[i].file;
|
dl->ent[dl->num].file = files[i].file;
|
||||||
dl->ent[dl->num].name = strdup(hdr.name);
|
dl->ent[dl->num].name = strdup(hdr.name);
|
||||||
dl->dropdown[dl->num] = SPECSTR_LANGUAGE_START + dl->num;
|
|
||||||
|
|
||||||
/* We are trying to find a default language. The priority is by
|
/* We are trying to find a default language. The priority is by
|
||||||
* configuration file, local environment and last, if nothing found,
|
* configuration file, local environment and last, if nothing found,
|
||||||
|
@ -1469,8 +1457,6 @@ void InitializeLanguagePacks()
|
||||||
|
|
||||||
dl->num++;
|
dl->num++;
|
||||||
}
|
}
|
||||||
/* Terminate the dropdown list */
|
|
||||||
dl->dropdown[dl->num] = INVALID_STRING_ID;
|
|
||||||
|
|
||||||
if (dl->num == 0) error("Invalid version of language packs");
|
if (dl->num == 0) error("Invalid version of language packs");
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,12 @@ void InitializeLanguagePacks();
|
||||||
|
|
||||||
int CDECL StringIDSorter(const void *a, const void *b);
|
int CDECL StringIDSorter(const void *a, const void *b);
|
||||||
|
|
||||||
|
/** Key comparison function for std::map */
|
||||||
|
struct StringIDCompare
|
||||||
|
{
|
||||||
|
bool operator()(StringID s1, StringID s2) { return StringIDSorter(&s1, &s2) < 0; }
|
||||||
|
};
|
||||||
|
|
||||||
void CheckForMissingGlyphsInLoadedLanguagePack();
|
void CheckForMissingGlyphsInLoadedLanguagePack();
|
||||||
|
|
||||||
#endif /* STRINGS_TYPE_H */
|
#endif /* STRINGS_TYPE_H */
|
||||||
|
|
|
@ -20,11 +20,10 @@ struct Language {
|
||||||
|
|
||||||
/** Used for dynamic language support */
|
/** Used for dynamic language support */
|
||||||
struct DynamicLanguages {
|
struct DynamicLanguages {
|
||||||
int num; ///< Number of languages
|
int num; ///< Number of languages
|
||||||
int curr; ///< Currently selected language index
|
int curr; ///< Currently selected language index
|
||||||
char curr_file[MAX_PATH]; ///< Currently selected language file name without path (needed for saving the filename of the loaded language).
|
char curr_file[MAX_PATH]; ///< Currently selected language file name without path (needed for saving the filename of the loaded language).
|
||||||
StringID dropdown[MAX_LANG + 1]; ///< List of languages in the settings gui
|
Language ent[MAX_LANG]; ///< Information about the languages
|
||||||
Language ent[MAX_LANG]; ///< Information about the languages
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// special string constants
|
// special string constants
|
||||||
|
|
Loading…
Reference in New Issue