Changeset - r27158:8d6feca48662
[Not reviewed]
master
0 1 0
Peter Nelson - 14 months ago 2023-04-19 00:50:36
peter1138@openttd.org
Change: Draw and size video driver info like base set info.

This allows very long video driver information strings to wrap instead
of making the game options window very wide.
1 file changed with 11 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -289,25 +289,24 @@ struct GameOptionsWindow : Window {
 

	
 
	void SetStringParameters(int widget) const override
 
	{
 
		switch (widget) {
 
			case WID_GO_CURRENCY_DROPDOWN:     SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
 
			case WID_GO_AUTOSAVE_DROPDOWN:     SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
 
			case WID_GO_LANG_DROPDOWN:         SetDParamStr(0, _current_language->own_name); break;
 
			case WID_GO_BASE_GRF_DROPDOWN:     SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
 
			case WID_GO_BASE_GRF_STATUS:       SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
 
			case WID_GO_BASE_SFX_DROPDOWN:     SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
 
			case WID_GO_BASE_MUSIC_DROPDOWN:   SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
 
			case WID_GO_BASE_MUSIC_STATUS:     SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
 
			case WID_GO_VIDEO_DRIVER_INFO:     SetDParamStr(0, VideoDriver::GetInstance()->GetInfoString()); break;
 
			case WID_GO_REFRESH_RATE_DROPDOWN: SetDParam(0, _settings_client.gui.refresh_rate); break;
 
			case WID_GO_RESOLUTION_DROPDOWN: {
 
				auto current_resolution = GetCurrentResolutionIndex();
 

	
 
				if (current_resolution == _resolutions.size()) {
 
					SetDParam(0, STR_GAME_OPTIONS_RESOLUTION_OTHER);
 
				} else {
 
					SetDParam(0, STR_GAME_OPTIONS_RESOLUTION_ITEM);
 
					SetDParam(1, _resolutions[current_resolution].width);
 
					SetDParam(2, _resolutions[current_resolution].height);
 
				}
 
				break;
 
@@ -328,24 +327,29 @@ struct GameOptionsWindow : Window {
 
				DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
 
				break;
 

	
 
			case WID_GO_BASE_MUSIC_DESCRIPTION:
 
				SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
 
				DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
 
				break;
 

	
 
			case WID_GO_GUI_SCALE:
 
				DrawSliderWidget(r, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, this->gui_scale, _scale_labels);
 
				break;
 

	
 
			case WID_GO_VIDEO_DRIVER_INFO:
 
				SetDParamStr(0, VideoDriver::GetInstance()->GetInfoString());
 
				DrawStringMultiLine(r, STR_GAME_OPTIONS_VIDEO_DRIVER_INFO);
 
				break;
 

	
 
			case WID_GO_BASE_SFX_VOLUME:
 
				DrawSliderWidget(r, 0, INT8_MAX, _settings_client.music.effect_vol, {});
 
				break;
 

	
 
			case WID_GO_BASE_MUSIC_VOLUME:
 
				DrawSliderWidget(r, 0, INT8_MAX, _settings_client.music.music_vol, {});
 
				break;
 
		}
 
	}
 

	
 
	void OnResize() override
 
	{
 
@@ -366,24 +370,29 @@ struct GameOptionsWindow : Window {
 
			y = std::max(y, GetStringHeight(STR_BLACK_RAW_STRING, wid->current_x));
 
		}
 
		changed |= wid->UpdateVerticalSize(y);
 

	
 
		wid = this->GetWidget<NWidgetResizeBase>(WID_GO_BASE_MUSIC_DESCRIPTION);
 
		y = 0;
 
		for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
 
			SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
 
			y = std::max(y, GetStringHeight(STR_BLACK_RAW_STRING, wid->current_x));
 
		}
 
		changed |= wid->UpdateVerticalSize(y);
 

	
 
		wid = this->GetWidget<NWidgetResizeBase>(WID_GO_VIDEO_DRIVER_INFO);
 
		SetDParamStr(0, VideoDriver::GetInstance()->GetInfoString());
 
		y = GetStringHeight(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, wid->current_x);
 
		changed |= wid->UpdateVerticalSize(y);
 

	
 
		if (changed) this->ReInit(0, 0, true);
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
		switch (widget) {
 
			case WID_GO_BASE_GRF_STATUS:
 
				/* Find the biggest description for the default size. */
 
				for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
 
					uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
 
					if (invalid_files == 0) continue;
 

	
 
@@ -723,25 +732,25 @@ static const NWidgetPart _nested_game_op
 
						NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetDataTip(STR_GAME_OPTIONS_VIDEO_ACCELERATION, STR_NULL),
 
						NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0),
 
						NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_ACCEL_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP),
 
					EndContainer(),
 
#ifndef __APPLE__
 
					NWidget(NWID_HORIZONTAL),
 
						NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetDataTip(STR_GAME_OPTIONS_VIDEO_VSYNC, STR_NULL),
 
						NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0),
 
						NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_VSYNC_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_VSYNC_TOOLTIP),
 
					EndContainer(),
 
#endif
 
					NWidget(NWID_HORIZONTAL),
 
						NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_VIDEO_DRIVER_INFO), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, STR_NULL),
 
						NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GO_VIDEO_DRIVER_INFO), SetMinimalTextLines(1, 0), SetFill(1, 0),
 
					EndContainer(),
 
				EndContainer(),
 
			EndContainer(),
 
		EndContainer(),
 

	
 
		NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
 
			NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
 
				NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
 
				NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
 
			EndContainer(),
 
			NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_NULL, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
 
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
0 comments (0 inline, 0 general)