Changeset - r25021:b2c0ccc09d1f
[Not reviewed]
master
0 5 0
Patric Stout - 3 years ago 2021-03-09 09:58:33
truebrain@openttd.org
Codechange: remove special strings for language and resolutions (#8824)

As OpenTTD grew, we found other ways to do this, and we are no
longer in need for a hack like this.
5 files changed with 35 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -1000,6 +1000,7 @@ STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP     
 
STR_GAME_OPTIONS_RESOLUTION                                     :{BLACK}Screen resolution
 
STR_GAME_OPTIONS_RESOLUTION_TOOLTIP                             :{BLACK}Select the screen resolution to use
 
STR_GAME_OPTIONS_RESOLUTION_OTHER                               :other
 
STR_GAME_OPTIONS_RESOLUTION_ITEM                                :{NUM}x{NUM}
 

	
 
STR_GAME_OPTIONS_VIDEO_ACCELERATION                             :{BLACK}Hardware acceleration
 
STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP                     :{BLACK}Check this box to allow OpenTTD to try to use hardware acceleration. A changed setting will only be applied upon game restart
src/settings_gui.cpp
Show inline comments
 
@@ -77,14 +77,10 @@ static const void *ResolveVariableAddres
 
 * Get index of the current screen resolution.
 
 * @return Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise.
 
 */
 
static uint GetCurRes()
 
static uint GetCurrentResolutionIndex()
 
{
 
	uint i;
 

	
 
	for (i = 0; i != _resolutions.size(); i++) {
 
		if (_resolutions[i] == Dimension(_screen.width, _screen.height)) break;
 
	}
 
	return i;
 
	auto it = std::find(_resolutions.begin(), _resolutions.end(), Dimension(_screen.width, _screen.height));
 
	return std::distance(_resolutions.begin(), it);
 
}
 

	
 
static void ShowCustCurrency();
 
@@ -219,8 +215,19 @@ struct GameOptionsWindow : Window {
 

	
 
			case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
 
				for (uint i = 0; i < _languages.size(); i++) {
 
					if (&_languages[i] == _current_language) *selected_index = i;
 
					list.emplace_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
 
					auto item = new DropDownListParamStringItem(STR_JUST_RAW_STRING, i, false);
 
					if (&_languages[i] == _current_language) {
 
						*selected_index = i;
 
						item->SetParamStr(0, _languages[i].own_name);
 
					} else {
 
						/* Especially with sprite-fonts, not all localized
 
						 * names can be rendered. So instead, we use the
 
						 * international names for anything but the current
 
						 * selected language. This avoids showing a few ????
 
						 * entries in the dropdown list. */
 
						item->SetParamStr(0, _languages[i].name);
 
					}
 
					list.emplace_back(item);
 
				}
 
				std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
 
				break;
 
@@ -229,9 +236,12 @@ struct GameOptionsWindow : Window {
 
			case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
 
				if (_resolutions.empty()) break;
 

	
 
				*selected_index = GetCurRes();
 
				*selected_index = GetCurrentResolutionIndex();
 
				for (uint i = 0; i < _resolutions.size(); i++) {
 
					list.emplace_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
 
					auto item = new DropDownListParamStringItem(STR_GAME_OPTIONS_RESOLUTION_ITEM, i, false);
 
					item->SetParam(0, _resolutions[i].width);
 
					item->SetParam(1, _resolutions[i].height);
 
					list.emplace_back(item);
 
				}
 
				break;
 

	
 
@@ -285,7 +295,6 @@ struct GameOptionsWindow : Window {
 
			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_RESOLUTION_DROPDOWN:   SetDParam(0, GetCurRes() == _resolutions.size() ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
 
			case WID_GO_GUI_ZOOM_DROPDOWN:     SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
 
			case WID_GO_FONT_ZOOM_DROPDOWN:    SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
 
			case WID_GO_BASE_GRF_DROPDOWN:     SetDParamStr(0, BaseGraphics::GetUsedSet()->name.c_str()); break;
 
@@ -294,6 +303,18 @@ struct GameOptionsWindow : Window {
 
			case WID_GO_BASE_MUSIC_DROPDOWN:   SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str()); break;
 
			case WID_GO_BASE_MUSIC_STATUS:     SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); 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;
 
			}
 
		}
 
	}
 

	
src/strings.cpp
Show inline comments
 
@@ -1678,22 +1678,6 @@ static char *GetSpecialNameString(char *
 
		return strecpy(buff, " Transport", last);
 
	}
 

	
 
	/* language name? */
 
	if (IsInsideMM(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
 
		int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
 
		return strecpy(buff,
 
			&_languages[i] == _current_language ? _current_language->own_name : _languages[i].name, last);
 
	}
 

	
 
	/* resolution size? */
 
	if (IsInsideBS(ind, (SPECSTR_RESOLUTION_START - 0x70E4), _resolutions.size())) {
 
		int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
 
		buff += seprintf(
 
			buff, last, "%ux%u", _resolutions[i].width, _resolutions[i].height
 
		);
 
		return buff;
 
	}
 

	
 
	NOT_REACHED();
 
}
 

	
src/strings_type.h
Show inline comments
 
@@ -86,13 +86,6 @@ enum SpecialStrings {
 
	SPECSTR_SILLY_NAME         = 0x70E5,
 
	SPECSTR_ANDCO_NAME         = 0x70E6,
 
	SPECSTR_PRESIDENT_NAME     = 0x70E7,
 

	
 
	/* reserve MAX_LANG strings for the *.lng files */
 
	SPECSTR_LANGUAGE_START     = 0x7100,
 
	SPECSTR_LANGUAGE_END       = SPECSTR_LANGUAGE_START + MAX_LANG - 1,
 

	
 
	/* reserve strings for various screen resolutions MUST BE THE LAST VALUE IN THIS ENUM */
 
	SPECSTR_RESOLUTION_START   = SPECSTR_LANGUAGE_END + 1,
 
};
 

	
 
#endif /* STRINGS_TYPE_H */
src/widgets/dropdown_type.h
Show inline comments
 
@@ -61,6 +61,7 @@ public:
 

	
 
	StringID String() const override;
 
	void SetParam(uint index, uint64 value) { decode_params[index] = value; }
 
	void SetParamStr(uint index, const char *str) { this->SetParam(index, (uint64)(size_t)str); }
 
};
 

	
 
/**
0 comments (0 inline, 0 general)