Skip to content

Commit

Permalink
Fix OpenTTD#11087: Disable base graphics/sound dropdown outside main …
Browse files Browse the repository at this point in the history
…menu
  • Loading branch information
merni-ns authored and rubidium42 committed Jul 1, 2023
1 parent 4ae9ebf commit 161cc04
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/music_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ struct MusicTrackSelectionWindow : public Window {

case WID_MTS_MUSICSET: {
int selected = 0;
ShowDropDownList(this, BuildMusicSetDropDownList(&selected), selected, widget);
ShowDropDownList(this, BuildSetDropDownList<BaseMusic>(&selected), selected, widget);
break;
}

Expand Down
28 changes: 6 additions & 22 deletions src/settings_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,6 @@ static uint GetCurrentResolutionIndex()

static void ShowCustCurrency();

template <class T>
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<BaseMusic>(selected_index, true);
}

/** Window for displaying the textfile of a BaseSet. */
template <class TBaseSet>
struct BaseSetTextfileWindow : public TextfileWindow {
Expand Down Expand Up @@ -291,15 +272,15 @@ struct GameOptionsWindow : Window {
break;

case WID_GO_BASE_GRF_DROPDOWN:
list = BuildSetDropDownList<BaseGraphics>(selected_index, (_game_mode == GM_MENU));
list = BuildSetDropDownList<BaseGraphics>(selected_index);
break;

case WID_GO_BASE_SFX_DROPDOWN:
list = BuildSetDropDownList<BaseSounds>(selected_index, (_game_mode == GM_MENU));
list = BuildSetDropDownList<BaseSounds>(selected_index);
break;

case WID_GO_BASE_MUSIC_DROPDOWN:
list = BuildMusicSetDropDownList(selected_index);
list = BuildSetDropDownList<BaseMusic>(selected_index);
break;
}

Expand Down Expand Up @@ -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<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);

Expand Down
13 changes: 12 additions & 1 deletion src/settings_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
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);
Expand Down

0 comments on commit 161cc04

Please sign in to comment.