* Build the dropdown list for a specific widget. * @param widget Widget to build list for * @param selected_index Currently selected item * @return the built dropdown list, or nullptr if the widget has no dropdown menu. */
| 470 | * @return the built dropdown list, or nullptr if the widget has no dropdown menu. |
| 471 | */ |
| 472 | DropDownList BuildDropDownList(WidgetID widget, int *selected_index) const |
| 473 | { |
| 474 | DropDownList list; |
| 475 | switch (widget) { |
| 476 | case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown |
| 477 | *selected_index = this->opt->locale.currency; |
| 478 | uint64_t disabled = _game_mode == GM_MENU ? 0LL : ~GetMaskOfAllowedCurrencies(); |
| 479 | |
| 480 | /* Add non-custom currencies; sorted naturally */ |
| 481 | for (const CurrencySpec ¤cy : _currency_specs) { |
| 482 | int i = ¤cy - _currency_specs.data(); |
| 483 | if (i == CURRENCY_CUSTOM) continue; |
| 484 | if (currency.code.empty()) { |
| 485 | list.push_back(MakeDropDownListStringItem(currency.name, i, HasBit(disabled, i))); |
| 486 | } else { |
| 487 | list.push_back(MakeDropDownListStringItem(GetString(STR_GAME_OPTIONS_CURRENCY_CODE, currency.name, currency.code), i, HasBit(disabled, i))); |
| 488 | } |
| 489 | } |
| 490 | std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc); |
| 491 | |
| 492 | /* Append custom currency at the end */ |
| 493 | list.push_back(MakeDropDownListDividerItem()); // separator line |
| 494 | list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM))); |
| 495 | break; |
| 496 | } |
| 497 | |
| 498 | case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown |
| 499 | int index = 0; |
| 500 | for (auto &minutes : _autosave_dropdown_to_minutes) { |
| 501 | index++; |
| 502 | if (_settings_client.gui.autosave_interval <= minutes) break; |
| 503 | } |
| 504 | *selected_index = index - 1; |
| 505 | |
| 506 | const StringID *items = _autosave_dropdown; |
| 507 | for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) { |
| 508 | list.push_back(MakeDropDownListStringItem(*items, i)); |
| 509 | } |
| 510 | break; |
| 511 | } |
| 512 | |
| 513 | case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown |
| 514 | for (uint i = 0; i < _languages.size(); i++) { |
| 515 | bool hide_language = IsReleasedVersion() && !_languages[i].IsReasonablyFinished(); |
| 516 | if (hide_language) continue; |
| 517 | bool hide_percentage = IsReleasedVersion() || _languages[i].missing < _settings_client.gui.missing_strings_threshold; |
| 518 | std::string name; |
| 519 | if (&_languages[i] == _current_language) { |
| 520 | *selected_index = i; |
| 521 | name = _languages[i].own_name; |
| 522 | } else { |
| 523 | /* Especially with sprite-fonts, not all localized |
| 524 | * names can be rendered. So instead, we use the |
| 525 | * international names for anything but the current |
| 526 | * selected language. This avoids showing a few ???? |
| 527 | * entries in the dropdown list. */ |
| 528 | name = _languages[i].name; |
| 529 | } |
no test coverage detected