From 161cc04b8adc0c2c350d304544f62e90065bf31e Mon Sep 17 00:00:00 2001 From: merni-ns Date: Sat, 1 Jul 2023 17:27:06 +0530 Subject: [PATCH] Fix #11087: Disable base graphics/sound dropdown outside main menu --- src/music_gui.cpp | 2 +- src/settings_gui.cpp | 28 ++++++---------------------- src/settings_gui.h | 13 ++++++++++++- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 63f8e50242632..b995776f4ba56 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -577,7 +577,7 @@ struct MusicTrackSelectionWindow : public Window { case WID_MTS_MUSICSET: { int selected = 0; - ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget); + ShowDropDownList(this, BuildSetDropDownList(&selected), selected, widget); break; } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 62fce17f55d31..1ece5c0be8203 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -74,25 +74,6 @@ static uint GetCurrentResolutionIndex() static void ShowCustCurrency(); -template -static DropDownList BuildSetDropDownList(int *selected_index, bool allow_selection) -{ - int n = T::GetNumSets(); - *selected_index = T::GetIndexOfUsedSet(); - - DropDownList list; - for (int i = 0; i < n; i++) { - list.emplace_back(new DropDownListStringItem(T::GetSet(i)->name, i, !allow_selection && (*selected_index != i))); - } - - return list; -} - -DropDownList BuildMusicSetDropDownList(int *selected_index) -{ - return BuildSetDropDownList(selected_index, true); -} - /** Window for displaying the textfile of a BaseSet. */ template struct BaseSetTextfileWindow : public TextfileWindow { @@ -291,15 +272,15 @@ struct GameOptionsWindow : Window { break; case WID_GO_BASE_GRF_DROPDOWN: - list = BuildSetDropDownList(selected_index, (_game_mode == GM_MENU)); + list = BuildSetDropDownList(selected_index); break; case WID_GO_BASE_SFX_DROPDOWN: - list = BuildSetDropDownList(selected_index, (_game_mode == GM_MENU)); + list = BuildSetDropDownList(selected_index); break; case WID_GO_BASE_MUSIC_DROPDOWN: - list = BuildMusicSetDropDownList(selected_index); + list = BuildSetDropDownList(selected_index); break; } @@ -740,6 +721,9 @@ struct GameOptionsWindow : Window { this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, _gui_scale_cfg == -1); this->SetWidgetLoweredState(WID_GO_GUI_SCALE_BEVEL_BUTTON, _settings_client.gui.scale_bevels); + this->SetWidgetDisabledState(WID_GO_BASE_GRF_DROPDOWN, _game_mode != GM_MENU); + this->SetWidgetDisabledState(WID_GO_BASE_SFX_DROPDOWN, _game_mode != GM_MENU); + bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0; this->GetWidget(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL); diff --git a/src/settings_gui.h b/src/settings_gui.h index a292347e1fad5..7a3f69e364770 100644 --- a/src/settings_gui.h +++ b/src/settings_gui.h @@ -22,7 +22,18 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable); void DrawBoolButton(int x, int y, bool state, bool clickable); -DropDownList BuildMusicSetDropDownList(int *selected_index); +template +DropDownList BuildSetDropDownList(int *selected_index) +{ + int n = T::GetNumSets(); + *selected_index = T::GetIndexOfUsedSet(); + DropDownList list; + for (int i = 0; i < n; i++) { + list.emplace_back(new DropDownListStringItem(T::GetSet(i)->name, i, false)); + } + return list; +} + /* Actually implemented in music_gui.cpp */ void ChangeMusicSet(int index);