From edb101d12f1066f2c5ad423ecb1565aa23423eb3 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 21 Mar 2025 00:10:15 +0000 Subject: [PATCH] Codechange: Use free function get BaseSet list label. This avoids using StringIDs in a header file. --- src/base_media_base.h | 13 ------------- src/settings_gui.cpp | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/base_media_base.h b/src/base_media_base.h index ae678adb2e..341e8b1941 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -122,19 +122,6 @@ struct BaseSet { return this->description.at(std::string{}); } - /** - * Get string to use when listing this set in the settings window. - * If there are no invalid files, then this is just the set name, - * otherwise a string is formatted including the number of invalid files. - * @return the string to display. - */ - std::string GetListLabel() const - { - if (this->GetNumInvalid() == 0) return GetString(STR_JUST_RAW_STRING, this->name); - - return GetString(STR_BASESET_STATUS, this->name, this->GetNumInvalid()); - } - /** * Calculate and check the MD5 hash of the supplied file. * @param file The file get the hash of. diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 2664fe25a0..1003501d25 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -125,6 +125,19 @@ void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet *baseset, new BaseSetTextfileWindow(file_type, baseset->name, *baseset->GetTextfile(file_type), content_type); } +/** + * Get string to use when listing this set in the settings window. + * If there are no invalid files, then this is just the set name, + * otherwise a string is formatted including the number of invalid files. + * @return the string to display. + */ +template +static std::string GetListLabel(const TBaseSet *baseset) +{ + if (baseset->GetNumInvalid() == 0) return GetString(STR_JUST_RAW_STRING, baseset->name); + return GetString(STR_BASESET_STATUS, baseset->name, baseset->GetNumInvalid()); +} + template DropDownList BuildSetDropDownList(int *selected_index) { @@ -132,7 +145,7 @@ DropDownList BuildSetDropDownList(int *selected_index) *selected_index = T::GetIndexOfUsedSet(); DropDownList list; for (int i = 0; i < n; i++) { - list.push_back(MakeDropDownListStringItem(T::GetSet(i)->GetListLabel(), i)); + list.push_back(MakeDropDownListStringItem(GetListLabel(T::GetSet(i)), i)); } return list; } @@ -493,9 +506,9 @@ struct GameOptionsWindow : Window { } case WID_GO_LANG_DROPDOWN: return _current_language->own_name; - case WID_GO_BASE_GRF_DROPDOWN: return BaseGraphics::GetUsedSet()->GetListLabel(); - case WID_GO_BASE_SFX_DROPDOWN: return BaseSounds::GetUsedSet()->GetListLabel(); - case WID_GO_BASE_MUSIC_DROPDOWN: return BaseMusic::GetUsedSet()->GetListLabel(); + case WID_GO_BASE_GRF_DROPDOWN: return GetListLabel(BaseGraphics::GetUsedSet()); + case WID_GO_BASE_SFX_DROPDOWN: return GetListLabel(BaseSounds::GetUsedSet()); + case WID_GO_BASE_MUSIC_DROPDOWN: return GetListLabel(BaseMusic::GetUsedSet()); case WID_GO_REFRESH_RATE_DROPDOWN: return GetString(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, _settings_client.gui.refresh_rate); case WID_GO_RESOLUTION_DROPDOWN: { auto current_resolution = GetCurrentResolutionIndex();