Codechange: use std::vector for _language_dropdown

This commit is contained in:
glx 2019-04-13 22:53:18 +02:00 committed by glx22
parent 9195f2337a
commit 8899272614
3 changed files with 12 additions and 12 deletions

View File

@ -63,18 +63,18 @@ static const StringID _lan_internet_types_dropdown[] = {
INVALID_STRING_ID
};
static StringID _language_dropdown[NETLANG_COUNT + 1] = {STR_NULL};
static std::vector<StringID> _language_dropdown;
void SortNetworkLanguages()
{
/* 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;
if (_language_dropdown.empty()) {
for (int i = 0; i < NETLANG_COUNT; i++) _language_dropdown.emplace_back(STR_NETWORK_LANG_ANY + i);
_language_dropdown.emplace_back(INVALID_STRING_ID);
}
/* Sort the strings (we don't move 'any' and the 'invalid' one) */
QSortT(_language_dropdown + 1, NETLANG_COUNT - 1, &StringIDSorter);
std::sort(_language_dropdown.begin() + 1, _language_dropdown.end() - 1, StringIDSorter);
}
/**
@ -1172,13 +1172,13 @@ struct NetworkStartServerWindow : public Window {
case WID_NSS_LANGUAGE_BTN: { // Language
uint sel = 0;
for (uint i = 0; i < lengthof(_language_dropdown) - 1; i++) {
for (uint i = 0; i < _language_dropdown.size() - 1; i++) {
if (_language_dropdown[i] == STR_NETWORK_LANG_ANY + _settings_client.network.server_lang) {
sel = i;
break;
}
}
ShowDropDownMenu(this, _language_dropdown, sel, WID_NSS_LANGUAGE_BTN, 0, 0);
ShowDropDownMenu(this, _language_dropdown.data(), sel, WID_NSS_LANGUAGE_BTN, 0, 0);
break;
}

View File

@ -1864,14 +1864,14 @@ const char *GetCurrentLocale(const char *param)
const char *GetCurrentLocale(const char *param);
#endif /* !(defined(_WIN32) || defined(__APPLE__)) */
int CDECL StringIDSorter(const StringID *a, const StringID *b)
bool StringIDSorter(const StringID &a, const StringID &b)
{
char stra[512];
char strb[512];
GetString(stra, *a, lastof(stra));
GetString(strb, *b, lastof(strb));
GetString(stra, a, lastof(stra));
GetString(strb, b, lastof(strb));
return strnatcmp(stra, strb);
return strnatcmp(stra, strb) < 0;
}
/**

View File

@ -238,7 +238,7 @@ extern TextDirection _current_text_dir; ///< Text direction of the currently sel
void InitializeLanguagePacks();
const char *GetCurrentLanguageIsoCode();
int CDECL StringIDSorter(const StringID *a, const StringID *b);
bool StringIDSorter(const StringID &a, const StringID &b);
/**
* A searcher for missing glyphs.