Merge branch 'master' into jgrpp

# Conflicts:
#	src/company_cmd.cpp
#	src/core/geometry_func.cpp
#	src/date.cpp
#	src/genworld_gui.cpp
#	src/gfx.cpp
#	src/object_gui.cpp
#	src/openttd.cpp
#	src/settings_type.h
#	src/video/allegro_v.cpp
#	src/video/dedicated_v.cpp
#	src/video/null_v.cpp
#	src/video/sdl2_v.cpp
#	src/video/sdl_v.cpp
#	src/video/win32_v.cpp
This commit is contained in:
Jonathan G Rennison
2021-02-19 15:38:34 +00:00
176 changed files with 4275 additions and 3826 deletions

View File

@@ -16,7 +16,6 @@
#include "network/network.h"
#include "town.h"
#include "settings_internal.h"
#include "newgrf_townname.h"
#include "strings_func.h"
#include "window_func.h"
#include "string_func.h"
@@ -44,12 +43,6 @@
extern void FlushDeparturesWindowTextCaches();
static const StringID _driveside_dropdown[] = {
STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT,
STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT,
INVALID_STRING_ID
};
static const StringID _autosave_dropdown[] = {
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
@@ -60,6 +53,7 @@ static const StringID _autosave_dropdown[] = {
};
static const StringID _gui_zoom_dropdown[] = {
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_AUTO,
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL,
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM,
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM,
@@ -67,42 +61,17 @@ static const StringID _gui_zoom_dropdown[] = {
};
static const StringID _font_zoom_dropdown[] = {
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_AUTO,
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL,
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM,
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM,
INVALID_STRING_ID,
};
int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Number of original town names.
static StringID *_grf_names = nullptr; ///< Pointer to town names defined by NewGRFs.
static int _nb_grf_names = 0; ///< Number of town names defined by NewGRFs.
static Dimension _circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd);
/** Allocate memory for the NewGRF town names. */
void InitGRFTownGeneratorNames()
{
free(_grf_names);
_grf_names = GetGRFTownNameList();
_nb_grf_names = 0;
for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
}
/**
* Get a town name.
* @param town_name Number of the wanted town name.
* @return Name of the town as string ID.
*/
static inline StringID TownName(int town_name)
{
if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
town_name -= _nb_orig_names;
if (town_name < _nb_grf_names) return _grf_names[town_name];
return STR_UNDEFINED;
}
/**
* Get index of the current screen resolution.
* @return Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise.
@@ -220,51 +189,6 @@ struct GameOptionsWindow : Window {
break;
}
case WID_GO_ROADSIDE_DROPDOWN: { // Setup road-side dropdown
*selected_index = this->opt->vehicle.road_side;
const StringID *items = _driveside_dropdown;
uint disabled = 0;
/* You can only change the drive side if you are in the menu or ingame with
* no vehicles present. In a networking game only the server can change it */
extern bool RoadVehiclesAreBuilt();
if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !(_network_server || _network_settings_access))) {
disabled = ~(1 << this->opt->vehicle.road_side); // disable the other value
}
for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
list.emplace_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
}
break;
}
case WID_GO_TOWNNAME_DROPDOWN: { // Setup townname dropdown
*selected_index = this->opt->game_creation.town_name;
int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
/* Add and sort newgrf townnames generators */
for (int i = 0; i < _nb_grf_names; i++) {
int result = _nb_orig_names + i;
list.emplace_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
}
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
size_t newgrf_size = list.size();
/* Insert newgrf_names at the top of the list */
if (newgrf_size > 0) {
list.emplace_back(new DropDownListItem(-1, false)); // separator line
newgrf_size++;
}
/* Add and sort original townnames generators */
for (int i = 0; i < _nb_orig_names; i++) {
list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
}
std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
break;
}
case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
*selected_index = _settings_client.gui.autosave;
const StringID *items = _autosave_dropdown;
@@ -293,16 +217,16 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_GUI_ZOOM_DROPDOWN: {
*selected_index = ZOOM_LVL_OUT_4X - _gui_zoom;
*selected_index = _gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom + 1 : 0;
const StringID *items = _gui_zoom_dropdown;
for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
list.emplace_back(new DropDownListStringItem(*items, i, _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i));
list.emplace_back(new DropDownListStringItem(*items, i, i != 0 && _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i + 1));
}
break;
}
case WID_GO_FONT_ZOOM_DROPDOWN: {
*selected_index = ZOOM_LVL_OUT_4X - _font_zoom;
*selected_index = _font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom + 1 : 0;
const StringID *items = _font_zoom_dropdown;
for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
list.emplace_back(new DropDownListStringItem(*items, i, false));
@@ -330,13 +254,11 @@ struct GameOptionsWindow : Window {
{
switch (widget) {
case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
case WID_GO_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
case WID_GO_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_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[ZOOM_LVL_OUT_4X - _gui_zoom]); break;
case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[ZOOM_LVL_OUT_4X - _font_zoom]); 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;
@@ -502,22 +424,6 @@ struct GameOptionsWindow : Window {
ReInitAllWindows();
break;
case WID_GO_ROADSIDE_DROPDOWN: // Road side
if (this->opt->vehicle.road_side != index) { // only change if setting changed
uint i;
if (GetSettingFromName("vehicle.road_side", &i) == nullptr) NOT_REACHED();
SetSettingValue(i, index);
MarkWholeScreenDirty();
}
break;
case WID_GO_TOWNNAME_DROPDOWN: // Town names
if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
this->opt->game_creation.town_name = index;
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
}
break;
case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
_settings_client.gui.autosave = index;
this->SetDirty();
@@ -539,26 +445,34 @@ struct GameOptionsWindow : Window {
}
break;
case WID_GO_GUI_ZOOM_DROPDOWN:
GfxClearSpriteCache();
_gui_zoom = (ZoomLevel)(ZOOM_LVL_OUT_4X - index);
UpdateCursorSize();
UpdateAllVirtCoords();
FixTitleGameZoom();
ReInitAllWindows();
FlushDeparturesWindowTextCaches();
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) {
GfxClearSpriteCache();
_gui_zoom_cfg = new_zoom;
UpdateGUIZoom();
UpdateCursorSize();
UpdateAllVirtCoords();
FixTitleGameZoom();
ReInitAllWindows();
FlushDeparturesWindowTextCaches();
}
break;
}
case WID_GO_FONT_ZOOM_DROPDOWN:
extern void UpdateFontHeightCache();
GfxClearSpriteCache();
_font_zoom = (ZoomLevel)(ZOOM_LVL_OUT_4X - index);
ClearFontCache();
UpdateFontHeightCache();
LoadStringWidthTable();
UpdateAllVirtCoords();
FlushDeparturesWindowTextCaches();
case WID_GO_FONT_ZOOM_DROPDOWN: {
int8 new_zoom = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
if (new_zoom != _font_zoom_cfg) {
GfxClearSpriteCache();
_font_zoom_cfg = new_zoom;
UpdateGUIZoom();
ClearFontCache();
LoadStringWidthTable();
UpdateAllVirtCoords();
FlushDeparturesWindowTextCaches();
}
break;
}
case WID_GO_BASE_GRF_DROPDOWN:
this->SetMediaSet<BaseGraphics>(index);
@@ -606,9 +520,6 @@ static const NWidgetPart _nested_game_options_widgets[] = {
NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_ROADSIDE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_AUTOSAVE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
@@ -625,9 +536,6 @@ static const NWidgetPart _nested_game_options_widgets[] = {
EndContainer(),
NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_TOWNNAME_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
EndContainer(),