Merge tag '1.11.0-RC1' into master

This commit is contained in:
Sergii Pylypenko
2021-03-15 21:01:22 +02:00
170 changed files with 4755 additions and 2816 deletions

View File

@@ -36,10 +36,13 @@
#include "fontcache.h"
#include "settings_func.h"
#include "zoom_func.h"
#include "video/video_driver.hpp"
#include <vector>
#include <iterator>
#include "safeguards.h"
#include "video/video_driver.hpp"
#ifdef __ANDROID__
#include <SDL_android.h>
@@ -80,14 +83,10 @@ static const void *ResolveVariableAddress(const GameSettings *settings_ptr, cons
* 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();
@@ -147,6 +146,22 @@ void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset,
new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
}
std::set<int> _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 };
/**
* Add the refresh rate from the config and the refresh rates from all the monitors to
* our list of refresh rates shown in the GUI.
*/
static void AddCustomRefreshRates()
{
/* Add the refresh rate as selected in the config. */
_refresh_rates.insert(_settings_client.gui.refresh_rate);
/* Add all the refresh rates of all monitors connected to the machine. */
std::vector<int> monitorRates = VideoDriver::GetInstance()->GetListOfMonitorRefreshRates();
std::copy(monitorRates.begin(), monitorRates.end(), std::inserter(_refresh_rates, _refresh_rates.end()));
}
struct GameOptionsWindow : Window {
GameSettings *opt;
bool reload;
@@ -156,6 +171,8 @@ struct GameOptionsWindow : Window {
this->opt = &GetGameSettings();
this->reload = false;
AddCustomRefreshRates();
this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS);
this->OnInvalidateData(0);
}
@@ -207,8 +224,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;
@@ -217,9 +245,22 @@ 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;
case WID_GO_REFRESH_RATE_DROPDOWN: // Setup refresh rate dropdown
for (auto it = _refresh_rates.begin(); it != _refresh_rates.end(); it++) {
auto i = std::distance(_refresh_rates.begin(), it);
if (*it == _settings_client.gui.refresh_rate) *selected_index = i;
auto item = new DropDownListParamStringItem(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, i, false);
item->SetParam(0, *it);
list.emplace_back(item);
}
break;
@@ -273,19 +314,31 @@ 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_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _resolutions.size() ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
case WID_GO_BUTTON_SIZE_DROPDOWN:SetDParam(0, _settings_client.gui.min_button); break;
case WID_GO_TEXT_SIZE_DROPDOWN: SetDParam(0, _freetype.medium.size); 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;
case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
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_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_BUTTON_SIZE_DROPDOWN: SetDParam(0, _settings_client.gui.min_button); break;
case WID_GO_TEXT_SIZE_DROPDOWN: SetDParam(0, _freetype.medium.size); 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;
case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
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;
}
}
}
@@ -450,6 +503,13 @@ struct GameOptionsWindow : Window {
#endif
break;
case WID_GO_VIDEO_ACCEL_BUTTON:
_video_hw_accel = !_video_hw_accel;
ShowErrorMessage(STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART, INVALID_STRING_ID, WL_INFO);
this->SetWidgetLoweredState(WID_GO_VIDEO_ACCEL_BUTTON, _video_hw_accel);
this->SetDirty();
break;
default: {
int selected;
DropDownList list = this->BuildDropDownList(widget, &selected);
@@ -527,6 +587,16 @@ struct GameOptionsWindow : Window {
ReconstructUserInterface();
break;
case WID_GO_REFRESH_RATE_DROPDOWN: {
_settings_client.gui.refresh_rate = *std::next(_refresh_rates.begin(), index);
if (_settings_client.gui.refresh_rate > 60) {
/* Show warning to the user that this refresh rate might not be suitable on
* larger maps with many NewGRFs and vehicles. */
ShowErrorMessage(STR_GAME_OPTIONS_REFRESH_RATE_WARNING, INVALID_STRING_ID, WL_INFO);
}
break;
}
case WID_GO_GUI_ZOOM_DROPDOWN: {
int8 new_zoom = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
if (new_zoom != _gui_zoom_cfg) {
@@ -579,11 +649,11 @@ struct GameOptionsWindow : Window {
this->SetWidgetLoweredState(WID_GO_WINDOWS_TITLEBARS, _settings_client.gui.windows_titlebars);
#ifdef WIN32
this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
#else
#endif
this->SetWidgetLoweredState(WID_GO_8BPP_BUTTON, _ini_blitter == "8bpp-optimized");
this->SetWidgetLoweredState(WID_GO_16BPP_BUTTON, _ini_blitter == "16bpp-simple");
this->SetWidgetLoweredState(WID_GO_32BPP_BUTTON, _ini_blitter == "32bpp-anim" || _ini_blitter == "");
#endif
this->SetWidgetLoweredState(WID_GO_VIDEO_ACCEL_BUTTON, _video_hw_accel);
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);
@@ -616,11 +686,10 @@ static const NWidgetPart _nested_game_options_widgets[] = {
#ifdef WIN32
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
#else
#endif
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_8BPP_BUTTON), SetMinimalSize(9, 9), SetDataTip(STR_CONFIG_SETTING_VIDEO_8BPP, STR_CONFIG_SETTING_VIDEO_8BPP_HELPTEXT),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_16BPP_BUTTON), SetMinimalSize(9, 9), SetDataTip(STR_CONFIG_SETTING_VIDEO_16BPP, STR_CONFIG_SETTING_VIDEO_16BPP_HELPTEXT),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_32BPP_BUTTON), SetMinimalSize(9, 9), SetDataTip(STR_CONFIG_SETTING_VIDEO_24BPP, STR_CONFIG_SETTING_VIDEO_24BPP_HELPTEXT),
#endif
EndContainer(),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GUI_ZOOM_FRAME, STR_NULL),
@@ -646,9 +715,10 @@ static const NWidgetPart _nested_game_options_widgets[] = {
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_CONFIG_SETTING_FONT_SIZE, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_TEXT_SIZE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_JUST_INT, STR_CONFIG_SETTING_FONT_SIZE_TOOLTIP), SetFill(1, 0),
EndContainer(),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_FONT_ZOOM, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_FONT_ZOOM_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
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),
@@ -1514,6 +1584,7 @@ static SettingsContainer &GetSettingsTree()
{
graphics->Add(new SettingEntry("gui.zoom_min"));
graphics->Add(new SettingEntry("gui.zoom_max"));
graphics->Add(new SettingEntry("gui.sprite_zoom_min"));
graphics->Add(new SettingEntry("gui.smallmap_land_colour"));
graphics->Add(new SettingEntry("gui.graph_line_thickness"));
}