From 3f2f61c49b82dfa192ffb6500796ca42550f3659 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 15 Jul 2026 23:21:59 +0100 Subject: [PATCH] Codechange: Make TextfileType a scoped enum (#15864) --- src/ai/ai_gui.cpp | 10 +++++----- src/game/game_gui.cpp | 10 +++++----- src/help_gui.cpp | 2 +- src/network/network_content_gui.cpp | 10 +++++----- src/network/network_gui.cpp | 4 ++-- src/newgrf_gui.cpp | 10 +++++----- src/settings_gui.cpp | 26 +++++++++++++------------- src/textfile_gui.cpp | 7 +++---- src/textfile_type.h | 20 +++++++++++--------- src/widgets/ai_widget.h | 2 +- src/widgets/game_widget.h | 2 +- src/widgets/network_content_widget.h | 2 +- src/widgets/newgrf_widget.h | 2 +- src/widgets/settings_widget.h | 6 +++--- 14 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 07a4d3aa13..d281fe3512 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -70,11 +70,11 @@ static constexpr std::initializer_list _nested_ai_config_widgets = NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_AIC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_AIC_TEXTFILE + TextfileType::Readme), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_AIC_TEXTFILE + TextfileType::Changelog), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_AIC_TEXTFILE + TextfileType::License), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), EndContainer(), EndContainer(), EndContainer(), @@ -215,7 +215,7 @@ struct AIConfigWindow : public Window { void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { - if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) { + if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TextfileType::ContentEnd) { if (this->selected_slot == CompanyID::Invalid() || AIConfig::GetConfig(this->selected_slot) == nullptr) return; ShowScriptTextfileWindow(this, static_cast(widget - WID_AIC_TEXTFILE), this->selected_slot); @@ -326,7 +326,7 @@ struct AIConfigWindow : public Window { this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, !IsEditable(this->selected_slot) || !IsEditable(static_cast(this->selected_slot + 1))); this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == CompanyID::Invalid() || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty()); - for (TextfileType tft : EnumRange(TFT_CONTENT_BEGIN, TFT_CONTENT_END)) { + for (TextfileType tft : EnumRange(TextfileType::ContentBegin, TextfileType::ContentEnd)) { this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == CompanyID::Invalid() || !config->GetTextfile(tft, this->selected_slot).has_value()); } } diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index 8400156617..aa5c34ff21 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -59,11 +59,11 @@ static constexpr std::initializer_list _nested_gs_config_widgets = NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TFT_README), SetFill(1, 1), SetResize(1, 0), SetMinimalSize(93, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TextfileType::Readme), SetFill(1, 1), SetResize(1, 0), SetMinimalSize(93, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TFT_LICENSE), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TextfileType::Changelog), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_GSC_TEXTFILE + TextfileType::License), SetFill(1, 1), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), EndContainer(), EndContainer(), EndContainer(), @@ -225,7 +225,7 @@ struct GSConfigWindow : public Window { void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { - if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TFT_CONTENT_END) { + if (widget >= WID_GSC_TEXTFILE && widget < WID_GSC_TEXTFILE + TextfileType::ContentEnd) { if (GameConfig::GetConfig() == nullptr) return; ShowScriptTextfileWindow(this, static_cast(widget - WID_GSC_TEXTFILE), OWNER_DEITY); @@ -396,7 +396,7 @@ struct GSConfigWindow : public Window { const GameConfig *config = GameConfig::GetConfig(); this->SetWidgetDisabledState(WID_GSC_OPEN_URL, config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty()); - for (TextfileType tft : EnumRange(TFT_CONTENT_BEGIN, TFT_CONTENT_END)) { + for (TextfileType tft : EnumRange(TextfileType::ContentBegin, TextfileType::ContentEnd)) { this->SetWidgetDisabledState(WID_GSC_TEXTFILE + tft, !config->GetTextfile(tft, OWNER_DEITY).has_value()); } this->RebuildVisibleSettings(); diff --git a/src/help_gui.cpp b/src/help_gui.cpp index a2cf35ee0e..4b55e22d1b 100644 --- a/src/help_gui.cpp +++ b/src/help_gui.cpp @@ -62,7 +62,7 @@ static std::optional FindGameManualFilePath(std::string_view filena /** Window class displaying the game manual textfile viewer. */ struct GameManualTextfileWindow : public TextfileWindow { - GameManualTextfileWindow(std::string_view filename, Subdirectory subdir) : TextfileWindow(nullptr, TFT_GAME_MANUAL) + GameManualTextfileWindow(std::string_view filename, Subdirectory subdir) : TextfileWindow(nullptr, TextfileType::GameManual) { this->ConstructWindow(); diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 8f00f9487c..297fb4aea4 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -796,7 +796,7 @@ public: void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { - if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_CONTENT_END) { + if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TextfileType::ContentEnd) { if (this->selected == nullptr || this->selected->state != ContentInfo::State::AlreadyHere) return; ShowContentTextfileWindow(this, (TextfileType)(widget - WID_NCL_TEXTFILE), this->selected); @@ -1003,7 +1003,7 @@ public: this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all); this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade || !this->filter_data.string_filter.IsEmpty()); this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || this->selected->url.empty()); - for (TextfileType tft : EnumRange(TFT_CONTENT_BEGIN, TFT_CONTENT_END)) { + for (TextfileType tft : EnumRange(TextfileType::ContentBegin, TextfileType::ContentEnd)) { this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::State::AlreadyHere || !this->selected->GetTextfile(tft).has_value()); } } @@ -1085,11 +1085,11 @@ static constexpr std::initializer_list _nested_network_content_list NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, Colours::White, WID_NCL_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), EndContainer(), EndContainer(), EndContainer(), diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index c31299cf00..f71a1fc943 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2480,6 +2480,6 @@ struct SurveyResultTextfileWindow : public TextfileWindow { */ void ShowSurveyResultTextfileWindow(Window *parent) { - parent->CloseChildWindowById(WindowClass::Textfile, TFT_SURVEY_RESULT); - new SurveyResultTextfileWindow(parent, TFT_SURVEY_RESULT); + parent->CloseChildWindowById(WindowClass::Textfile, TextfileType::SurveyResult); + new SurveyResultTextfileWindow(parent, TextfileType::SurveyResult); } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 6c762c63bb..706142b8a0 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -925,7 +925,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { - if (widget >= WID_NS_NEWGRF_TEXTFILE && widget < WID_NS_NEWGRF_TEXTFILE + TFT_CONTENT_END) { + if (widget >= WID_NS_NEWGRF_TEXTFILE && widget < WID_NS_NEWGRF_TEXTFILE + TextfileType::ContentEnd) { if (this->active_sel == nullptr && this->avail_sel == nullptr) return; ShowNewGRFTextfileWindow(this, (TextfileType)(widget - WID_NS_NEWGRF_TEXTFILE), this->active_sel != nullptr ? this->active_sel : this->avail_sel); @@ -1252,7 +1252,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { ); const GRFConfig *selected_config = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel; - for (TextfileType tft : EnumRange(TFT_CONTENT_BEGIN, TFT_CONTENT_END)) { + for (TextfileType tft : EnumRange(TextfileType::ContentBegin, TextfileType::ContentEnd)) { this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, selected_config == nullptr || !selected_config->GetTextfile(tft).has_value()); } this->SetWidgetDisabledState(WID_NS_OPEN_URL, selected_config == nullptr || !selected_config->GetURL().has_value()); @@ -1846,13 +1846,13 @@ static constexpr std::initializer_list _nested_newgrf_infopanel_wid NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NS_OPEN_URL), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NS_NEWGRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NS_NEWGRF_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NS_NEWGRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NS_NEWGRF_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NS_NEWGRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), + NWidget(WWT_PUSHTXTBTN, Colours::Yellow, WID_NS_NEWGRF_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), EndContainer(), EndContainer(), diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 59156268d5..40f6c79285 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -932,19 +932,19 @@ struct GameOptionsWindow : Window { void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { - if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END) { + if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TextfileType::ContentEnd) { if (BaseGraphics::GetUsedSet() == nullptr) return; ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS); return; } - if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_CONTENT_END) { + if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TextfileType::ContentEnd) { if (BaseSounds::GetUsedSet() == nullptr) return; ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS); return; } - if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_CONTENT_END) { + if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TextfileType::ContentEnd) { if (BaseMusic::GetUsedSet() == nullptr) return; ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC); @@ -1568,7 +1568,7 @@ struct GameOptionsWindow : Window { this->SetWidgetDisabledState(WID_GO_BASE_SFX_OPEN_URL, BaseSounds::GetUsedSet() == nullptr || BaseSounds::GetUsedSet()->url.empty()); this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_OPEN_URL, BaseMusic::GetUsedSet() == nullptr || BaseMusic::GetUsedSet()->url.empty()); - for (TextfileType tft : EnumRange(TFT_CONTENT_BEGIN, TFT_CONTENT_END)) { + for (TextfileType tft : EnumRange(TextfileType::ContentBegin, TextfileType::ContentEnd)) { this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == nullptr || !BaseGraphics::GetUsedSet()->GetTextfile(tft).has_value()); this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == nullptr || !BaseSounds::GetUsedSet()->GetTextfile(tft).has_value()); this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == nullptr || !BaseMusic::GetUsedSet()->GetTextfile(tft).has_value()); @@ -1734,11 +1734,11 @@ static constexpr std::initializer_list _nested_game_options_widgets NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), EndContainer(), EndContainer(), EndContainer(), @@ -1769,11 +1769,11 @@ static constexpr std::initializer_list _nested_game_options_widgets NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), EndContainer(), EndContainer(), EndContainer(), @@ -1792,11 +1792,11 @@ static constexpr std::initializer_list _nested_game_options_widgets NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP), EndContainer(), EndContainer(), EndContainer(), diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index d62e5140bb..37160956a8 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -95,7 +95,7 @@ void TextfileWindow::ConstructWindow() this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_TF_VSCROLLBAR); this->hscroll = this->GetScrollbar(WID_TF_HSCROLLBAR); - this->GetWidget(WID_TF_CAPTION)->SetStringTip(STR_TEXTFILE_README_CAPTION + this->file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); + this->GetWidget(WID_TF_CAPTION)->SetStringTip(STR_TEXTFILE_README_CAPTION + to_underlying(this->file_type), STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); this->GetWidget(WID_TF_SEL_JUMPLIST)->SetDisplayedPlane(SZSP_HORIZONTAL); this->FinishInitNested(this->file_type); @@ -927,15 +927,14 @@ void TextfileWindow::LoadText(std::string_view buf) */ std::optional GetTextfile(TextfileType type, Subdirectory dir, std::string_view filename) { - static const std::string_view prefixes[] = { + static const EnumIndexArray prefixes = { "readme", "changelog", "license", }; - static_assert(lengthof(prefixes) == TFT_CONTENT_END); /* Only the generic text file types allowed for this function */ - if (type >= TFT_CONTENT_END) return std::nullopt; + if (type >= TextfileType::ContentEnd) return std::nullopt; std::string_view prefix = prefixes[type]; diff --git a/src/textfile_type.h b/src/textfile_type.h index 94fcb42997..02d11b6696 100644 --- a/src/textfile_type.h +++ b/src/textfile_type.h @@ -10,20 +10,22 @@ #ifndef TEXTFILE_TYPE_H #define TEXTFILE_TYPE_H +#include "core/enum_type.hpp" + /** Additional text files accompanying Tar archives */ -enum TextfileType : uint8_t { - TFT_CONTENT_BEGIN, +enum class TextfileType : uint8_t { + ContentBegin, ///< This marker is used to generate the below three buttons in sequence by various of places in the code. - TFT_README = TFT_CONTENT_BEGIN, ///< Content readme - TFT_CHANGELOG, ///< Content changelog - TFT_LICENSE, ///< Content license + Readme = TextfileType::ContentBegin, ///< Content readme + Changelog, ///< Content changelog + License, ///< Content license - TFT_CONTENT_END, ///< This marker is used to generate the above three buttons in sequence by various of places in the code. + ContentEnd, ///< This marker is used to generate the above three buttons in sequence by various of places in the code. - TFT_SURVEY_RESULT = TFT_CONTENT_END, ///< Survey result (preview) - TFT_GAME_MANUAL, ///< Game manual/documentation file + SurveyResult = TextfileType::ContentEnd, ///< Survey result (preview) + GameManual, ///< Game manual/documentation file - TFT_END, + End, ///< End marker. }; DECLARE_ENUM_AS_ADDABLE(TextfileType) diff --git a/src/widgets/ai_widget.h b/src/widgets/ai_widget.h index 59cbe3389e..5e790f1f19 100644 --- a/src/widgets/ai_widget.h +++ b/src/widgets/ai_widget.h @@ -29,7 +29,7 @@ enum AIConfigWidgets : WidgetID { WID_AIC_CONFIGURE, ///< Change AI settings button. WID_AIC_OPEN_URL, ///< Open AI URL. WID_AIC_TEXTFILE, ///< Open AI readme, changelog (+1) or license (+2). - WID_AIC_CONTENT_DOWNLOAD = WID_AIC_TEXTFILE + TFT_CONTENT_END, ///< Download content button. + WID_AIC_CONTENT_DOWNLOAD = WID_AIC_TEXTFILE + to_underlying(TextfileType::ContentEnd), ///< Download content button. }; #endif /* WIDGETS_AI_WIDGET_H */ diff --git a/src/widgets/game_widget.h b/src/widgets/game_widget.h index 31362c7489..8e7a197597 100644 --- a/src/widgets/game_widget.h +++ b/src/widgets/game_widget.h @@ -21,7 +21,7 @@ enum GSConfigWidgets : WidgetID { WID_GSC_CHANGE, ///< Select another Game Script button. WID_GSC_OPEN_URL, ///< Open GS URL. WID_GSC_TEXTFILE, ///< Open GS readme, changelog (+1) or license (+2). - WID_GSC_CONTENT_DOWNLOAD = WID_GSC_TEXTFILE + TFT_CONTENT_END, ///< Download content button. + WID_GSC_CONTENT_DOWNLOAD = WID_GSC_TEXTFILE + to_underlying(TextfileType::ContentEnd), ///< Download content button. WID_GSC_RESET, ///< Reset button. WID_GSC_SETTING_DROPDOWN = INVALID_WIDGET, ///< Dynamically created dropdown for changing setting value. diff --git a/src/widgets/network_content_widget.h b/src/widgets/network_content_widget.h index 9f9a6bb199..6b80512ffb 100644 --- a/src/widgets/network_content_widget.h +++ b/src/widgets/network_content_widget.h @@ -36,7 +36,7 @@ enum NetworkContentListWidgets : WidgetID { WID_NCL_DETAILS, ///< Panel with content details. WID_NCL_TEXTFILE, ///< Open readme, changelog (+1) or license (+2) of a file in the content window. - WID_NCL_SELECT_ALL = WID_NCL_TEXTFILE + TFT_CONTENT_END, ///< 'Select all' button. + WID_NCL_SELECT_ALL = WID_NCL_TEXTFILE + to_underlying(TextfileType::ContentEnd), ///< 'Select all' button. WID_NCL_SELECT_UPDATE, ///< 'Select updates' button. WID_NCL_UNSELECT, ///< 'Unselect all' button. WID_NCL_OPEN_URL, ///< 'Open url' button. diff --git a/src/widgets/newgrf_widget.h b/src/widgets/newgrf_widget.h index 288041882e..1809a2c4bd 100644 --- a/src/widgets/newgrf_widget.h +++ b/src/widgets/newgrf_widget.h @@ -49,7 +49,7 @@ enum NewGRFStateWidgets : WidgetID { WID_NS_NEWGRF_INFO, ///< Panel for Info on selected NewGRF. WID_NS_OPEN_URL, ///< Open URL of NewGRF. WID_NS_NEWGRF_TEXTFILE, ///< Open NewGRF readme, changelog (+1) or license (+2). - WID_NS_SET_PARAMETERS = WID_NS_NEWGRF_TEXTFILE + TFT_CONTENT_END, ///< Open Parameters Window for selected NewGRF for editing parameters. + WID_NS_SET_PARAMETERS = WID_NS_NEWGRF_TEXTFILE + to_underlying(TextfileType::ContentEnd), ///< Open Parameters Window for selected NewGRF for editing parameters. WID_NS_VIEW_PARAMETERS, ///< Open Parameters Window for selected NewGRF for viewing parameters. WID_NS_TOGGLE_PALETTE, ///< Toggle Palette of selected, active NewGRF. WID_NS_APPLY_CHANGES, ///< Apply changes to NewGRF config. diff --git a/src/widgets/settings_widget.h b/src/widgets/settings_widget.h index 5ea226a00a..9088724697 100644 --- a/src/widgets/settings_widget.h +++ b/src/widgets/settings_widget.h @@ -39,14 +39,14 @@ enum GameOptionsWidgets : WidgetID { WID_GO_BASE_GRF_CONTENT_DOWNLOAD, ///< 'Get Content' button for base GRF. WID_GO_BASE_GRF_OPEN_URL, ///< Open base GRF URL. WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2). - WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base GRF. + WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + to_underlying(TextfileType::ContentEnd), ///< Description of selected base GRF. WID_GO_BASE_SFX_DROPDOWN, ///< Use to select a base SFX. WID_GO_BASE_SFX_CONTENT_DOWNLOAD, ///< 'Get Content' button for base SFX. WID_GO_TEXT_SFX_VOLUME, ///< Sound effects volume label. WID_GO_BASE_SFX_VOLUME, ///< Change sound effects volume. WID_GO_BASE_SFX_OPEN_URL, ///< Open base SFX URL. WID_GO_BASE_SFX_TEXTFILE, ///< Open base SFX readme, changelog (+1) or license (+2). - WID_GO_BASE_SFX_DESCRIPTION = WID_GO_BASE_SFX_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base SFX. + WID_GO_BASE_SFX_DESCRIPTION = WID_GO_BASE_SFX_TEXTFILE + to_underlying(TextfileType::ContentEnd), ///< Description of selected base SFX. WID_GO_BASE_MUSIC_DROPDOWN, ///< Use to select a base music set. WID_GO_BASE_MUSIC_CONTENT_DOWNLOAD, ///< 'Get Content' button for base music. WID_GO_TEXT_MUSIC_VOLUME, ///< Music volume label. @@ -54,7 +54,7 @@ enum GameOptionsWidgets : WidgetID { WID_GO_BASE_MUSIC_JUKEBOX, ///< Open the jukebox. WID_GO_BASE_MUSIC_OPEN_URL, ///< Open base music URL. WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2). - WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base music set. + WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + to_underlying(TextfileType::ContentEnd), ///< Description of selected base music set. WID_GO_VIDEO_ACCEL_BUTTON, ///< Toggle for video acceleration. WID_GO_VIDEO_ACCEL_TEXT, ///< Text for video acceleration toggle. WID_GO_VIDEO_VSYNC_BUTTON, ///< Toggle for video vsync.