MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetGRFStringFromGRFText

Function GetGRFStringFromGRFText

src/newgrf_text.cpp:599–615  ·  view source on GitHub ↗

* Get a C-string from a GRFText-list. If there is a translation for the * current language it is returned, otherwise the default translation * is returned. If there is neither a default nor a translation for the * current language nullptr is returned. * @param text_list The GRFTextList to get the string from. */

Source from the content-addressed store, hash-verified

597 * @param text_list The GRFTextList to get the string from.
598 */
599std::optional<std::string_view> GetGRFStringFromGRFText(const GRFTextList &text_list)
600{
601 std::optional<std::string_view> default_text;
602
603 /* Search the list of lang-strings of this stringid for current lang */
604 for (const auto &text : text_list) {
605 if (text.langid == _current_lang_id) return text.text;
606
607 /* If the current string is English or American, set it as the
608 * fallback language if the specific language isn't available. */
609 if (text.langid == GRFLX_UNSPECIFIED || (!default_text.has_value() && (text.langid == GRFLX_ENGLISH || text.langid == GRFLX_AMERICAN))) {
610 default_text = text.text;
611 }
612 }
613
614 return default_text;
615}
616
617/**
618 * Get a C-string from a GRFText-list. If there is a translation for the

Callers 9

UpdateWidgetSizeMethod · 0.85
GetValueParamsMethod · 0.85
GetSettingStringMethod · 0.85
DrawWidgetMethod · 0.85
OnClickMethod · 0.85
GetGRFStringPtrFunction · 0.85
GetNameMethod · 0.85
GetDescriptionMethod · 0.85
GetURLMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected