Changeset - r23631:f1d3190f874f
[Not reviewed]
master
0 3 0
glx - 5 years ago 2019-04-13 20:53:18
glx@openttd.org
Codechange: use std::vector for _language_dropdown
3 files changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -63,18 +63,18 @@ static const StringID _lan_internet_type
 
	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
 

	
 
			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;
 
			}
 

	
src/strings.cpp
Show inline comments
 
@@ -1864,14 +1864,14 @@ const char *GetCurrentLocale(const char 
 
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;
 
}
 

	
 
/**
src/strings_func.h
Show inline comments
 
@@ -238,7 +238,7 @@ extern TextDirection _current_text_dir; 
 
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.
0 comments (0 inline, 0 general)