diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 332cf1a..9395207 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -303,6 +303,8 @@ class NetworkContentListWindow : public Window, ContentCallback { uint filesize_sum; ///< The sum of all selected file sizes Scrollbar *vscroll; ///< Cache of the vertical scrollbar + static char content_type_strs[CONTENT_TYPE_END][64]; ///< Cached strings for all content types. + /** Search external websites for content */ void OpenExternalSearch() { @@ -400,11 +402,7 @@ class NetworkContentListWindow : public Window, ContentCallback { { int r = 0; if ((*a)->type != (*b)->type) { - char a_str[64]; - char b_str[64]; - GetString(a_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*a)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(a_str)); - GetString(b_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*b)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(b_str)); - r = strnatcmp(a_str, b_str); + r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]); } if (r == 0) r = NameSorter(a, b); return r; @@ -468,6 +466,7 @@ class NetworkContentListWindow : public Window, ContentCallback { this->vscroll->ScrollTowards(this->list_pos); } + friend void BuildContentTypeStringList(); public: /** * Create the content list window. @@ -959,6 +958,18 @@ class NetworkContentListWindow : public Window, ContentCallback { &TagNameFilter, }; +char NetworkContentListWindow::content_type_strs[CONTENT_TYPE_END][64]; + +/** + * Build array if all strings corresponding to the content types. + */ +void BuildContentTypeStringList() +{ + for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) { + GetString(NetworkContentListWindow::content_type_strs[i], STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS, lastof(NetworkContentListWindow::content_type_strs[i])); + } +} + /** The widgets for the content list. */ static const NWidgetPart _nested_network_content_list_widgets[] = { NWidget(NWID_HORIZONTAL), diff --git a/src/network/network_content_gui.h b/src/network/network_content_gui.h index 212fcec..1397010 100644 --- a/src/network/network_content_gui.h +++ b/src/network/network_content_gui.h @@ -43,4 +43,6 @@ class BaseNetworkContentDownloadStatusWindow : public Window, ContentCallback { virtual void OnDownloadProgress(const ContentInfo *ci, int bytes); }; +void BuildContentTypeStringList(); + #endif /* NETWORK_CONTENT_GUI_H */ diff --git a/src/strings.cpp b/src/strings.cpp index c12695c..0526b12 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -35,6 +35,7 @@ #include "window_func.h" #include "debug.h" #include "game/game_text.hpp" +#include "network/network_content_gui.h" #include #include "table/strings.h" @@ -1814,6 +1815,7 @@ bool ReadLanguagePack(const LanguageMetadata *lang) SortIndustryTypes(); BuildIndustriesLegend(); SortNetworkLanguages(); + BuildContentTypeStringList(); InvalidateWindowClassesData(WC_BUILD_VEHICLE); // Build vehicle window. InvalidateWindowClassesData(WC_TRAINS_LIST); // Train group window. InvalidateWindowClassesData(WC_ROADVEH_LIST); // Road vehicle group window.