Update to 1.10.0-beta1

This commit is contained in:
dP
2019-10-31 22:24:28 +03:00
parent b84a475e14
commit 599ccf0c2b
1470 changed files with 354219 additions and 16795 deletions

View File

@@ -74,7 +74,7 @@ static const StringID _font_zoom_dropdown[] = {
};
int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Number of original town names.
static StringID *_grf_names = NULL; ///< Pointer to town names defined by NewGRFs.
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.
@@ -105,17 +105,14 @@ static inline StringID TownName(int town_name)
/**
* Get index of the current screen resolution.
* @return Index of the current screen resolution if it is a known resolution, #_num_resolutions otherwise.
* @return Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise.
*/
static int GetCurRes()
static uint GetCurRes()
{
int i;
uint i;
for (i = 0; i != _num_resolutions; i++) {
if ((int)_resolutions[i].width == _screen.width &&
(int)_resolutions[i].height == _screen.height) {
break;
}
for (i = 0; i != _resolutions.size(); i++) {
if (_resolutions[i] == Dimension(_screen.width, _screen.height)) break;
}
return i;
}
@@ -123,20 +120,20 @@ static int GetCurRes()
static void ShowCustCurrency();
template <class T>
static DropDownList *BuildSetDropDownList(int *selected_index, bool allow_selection)
static DropDownList BuildSetDropDownList(int *selected_index, bool allow_selection)
{
int n = T::GetNumSets();
*selected_index = T::GetIndexOfUsedSet();
DropDownList *list = new DropDownList();
DropDownList list;
for (int i = 0; i < n; i++) {
*list->Append() = new DropDownListCharStringItem(T::GetSet(i)->name, i, !allow_selection && (*selected_index != i));
list.emplace_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, !allow_selection && (*selected_index != i)));
}
return list;
}
DropDownList *BuildMusicSetDropDownList(int *selected_index)
DropDownList BuildMusicSetDropDownList(int *selected_index)
{
return BuildSetDropDownList<BaseMusic>(selected_index, true);
}
@@ -153,7 +150,7 @@ struct BaseSetTextfileWindow : public TextfileWindow {
this->LoadTextfile(textfile, BASESET_DIR);
}
/* virtual */ void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_TF_CAPTION) {
SetDParam(0, content_type);
@@ -199,14 +196,13 @@ struct GameOptionsWindow : Window {
* Build the dropdown list for a specific widget.
* @param widget Widget to build list for
* @param selected_index Currently selected item
* @return the built dropdown list, or NULL if the widget has no dropdown menu.
* @return the built dropdown list, or nullptr if the widget has no dropdown menu.
*/
DropDownList *BuildDropDownList(int widget, int *selected_index) const
DropDownList BuildDropDownList(int widget, int *selected_index) const
{
DropDownList *list = NULL;
DropDownList list;
switch (widget) {
case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown
list = new DropDownList();
*selected_index = this->opt->locale.currency;
StringID *items = BuildCurrencyDropdown();
uint64 disabled = _game_mode == GM_MENU ? 0LL : ~GetMaskOfAllowedCurrencies();
@@ -214,18 +210,17 @@ struct GameOptionsWindow : Window {
/* Add non-custom currencies; sorted naturally */
for (uint i = 0; i < CURRENCY_END; items++, i++) {
if (i == CURRENCY_CUSTOM) continue;
*list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i));
list.emplace_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
}
QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc);
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
/* Append custom currency at the end */
*list->Append() = new DropDownListItem(-1, false); // separator line
*list->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM));
list.emplace_back(new DropDownListItem(-1, false)); // separator line
list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM)));
break;
}
case WID_GO_ROADSIDE_DROPDOWN: { // Setup road-side dropdown
list = new DropDownList();
*selected_index = this->opt->vehicle.road_side;
const StringID *items = _driveside_dropdown;
uint disabled = 0;
@@ -238,13 +233,12 @@ struct GameOptionsWindow : Window {
}
for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
*list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i));
list.emplace_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
}
break;
}
case WID_GO_TOWNNAME_DROPDOWN: { // Setup townname dropdown
list = new DropDownList();
*selected_index = this->opt->game_creation.town_name;
int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
@@ -252,71 +246,66 @@ struct GameOptionsWindow : Window {
/* Add and sort newgrf townnames generators */
for (int i = 0; i < _nb_grf_names; i++) {
int result = _nb_orig_names + i;
*list->Append() = new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0);
list.emplace_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
}
QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc);
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
int newgrf_size = list->Length();
size_t newgrf_size = list.size();
/* Insert newgrf_names at the top of the list */
if (newgrf_size > 0) {
*list->Append() = new DropDownListItem(-1, false); // separator line
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->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0);
list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
}
QSortT(list->Begin() + newgrf_size, list->Length() - newgrf_size, DropDownListStringItem::NatSortFunc);
std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
break;
}
case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
list = new DropDownList();
*selected_index = _settings_client.gui.autosave;
const StringID *items = _autosave_dropdown;
for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
*list->Append() = new DropDownListStringItem(*items, i, false);
list.emplace_back(new DropDownListStringItem(*items, i, false));
}
break;
}
case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
list = new DropDownList();
for (uint i = 0; i < _languages.Length(); i++) {
for (uint i = 0; i < _languages.size(); i++) {
if (&_languages[i] == _current_language) *selected_index = i;
*list->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false);
list.emplace_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
}
QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc);
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
break;
}
case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
if (_num_resolutions == 0) break;
if (_resolutions.empty()) break;
list = new DropDownList();
*selected_index = GetCurRes();
for (int i = 0; i < _num_resolutions; i++) {
*list->Append() = new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false);
for (uint i = 0; i < _resolutions.size(); i++) {
list.emplace_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
}
break;
case WID_GO_GUI_ZOOM_DROPDOWN: {
list = new DropDownList();
*selected_index = ZOOM_LVL_OUT_4X - _gui_zoom;
const StringID *items = _gui_zoom_dropdown;
for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
*list->Append() = new DropDownListStringItem(*items, i, _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i);
list.emplace_back(new DropDownListStringItem(*items, i, _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i));
}
break;
}
case WID_GO_FONT_ZOOM_DROPDOWN: {
list = new DropDownList();
*selected_index = ZOOM_LVL_OUT_4X - _font_zoom;
const StringID *items = _font_zoom_dropdown;
for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
*list->Append() = new DropDownListStringItem(*items, i, false);
list.emplace_back(new DropDownListStringItem(*items, i, false));
}
break;
}
@@ -332,15 +321,12 @@ struct GameOptionsWindow : Window {
case WID_GO_BASE_MUSIC_DROPDOWN:
list = BuildMusicSetDropDownList(selected_index);
break;
default:
return NULL;
}
return list;
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
@@ -348,7 +334,7 @@ struct GameOptionsWindow : Window {
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() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); 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_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
@@ -359,7 +345,7 @@ struct GameOptionsWindow : Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_GO_BASE_GRF_DESCRIPTION:
@@ -379,7 +365,7 @@ struct GameOptionsWindow : Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_GO_BASE_GRF_DESCRIPTION:
@@ -430,38 +416,37 @@ struct GameOptionsWindow : Window {
default: {
int selected;
DropDownList *list = this->BuildDropDownList(widget, &selected);
if (list != NULL) {
DropDownList list = this->BuildDropDownList(widget, &selected);
if (!list.empty()) {
/* Find the biggest item for the default size. */
for (const DropDownListItem * const *it = list->Begin(); it != list->End(); it++) {
for (const auto &ddli : list) {
Dimension string_dim;
int width = (*it)->Width();
int width = ddli->Width();
string_dim.width = width + padding.width;
string_dim.height = (*it)->Height(width) + padding.height;
string_dim.height = ddli->Height(width) + padding.height;
*size = maxdim(*size, string_dim);
}
delete list;
}
}
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
if (BaseGraphics::GetUsedSet() == NULL) return;
if (BaseGraphics::GetUsedSet() == nullptr) return;
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
return;
}
if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
if (BaseSounds::GetUsedSet() == NULL) return;
if (BaseSounds::GetUsedSet() == nullptr) return;
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
return;
}
if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
if (BaseMusic::GetUsedSet() == NULL) return;
if (BaseMusic::GetUsedSet() == nullptr) return;
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
return;
@@ -478,9 +463,9 @@ struct GameOptionsWindow : Window {
default: {
int selected;
DropDownList *list = this->BuildDropDownList(widget, &selected);
if (list != NULL) {
ShowDropDownList(this, list, selected, widget);
DropDownList list = this->BuildDropDownList(widget, &selected);
if (!list.empty()) {
ShowDropDownList(this, std::move(list), selected, widget);
} else {
if (widget == WID_GO_RESOLUTION_DROPDOWN) ShowErrorMessage(STR_ERROR_RESOLUTION_LIST_FAILED, INVALID_STRING_ID, WL_ERROR);
}
@@ -509,7 +494,7 @@ struct GameOptionsWindow : Window {
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_GO_CURRENCY_DROPDOWN: // Currency
@@ -521,7 +506,7 @@ struct GameOptionsWindow : Window {
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) == NULL) NOT_REACHED();
if (GetSettingFromName("vehicle.road_side", &i) == nullptr) NOT_REACHED();
SetSettingValue(i, index);
MarkWholeScreenDirty();
}
@@ -548,7 +533,7 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
if ((uint)index < _resolutions.size() && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
this->SetDirty();
}
break;
@@ -589,7 +574,7 @@ struct GameOptionsWindow : Window {
* @param data Information about the changed data. @see GameOptionsInvalidationData
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
@@ -598,9 +583,9 @@ struct GameOptionsWindow : Window {
this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->GetTextfile(tft) == NULL);
this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == NULL || BaseSounds::GetUsedSet()->GetTextfile(tft) == NULL);
this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == NULL || BaseMusic::GetUsedSet()->GetTextfile(tft) == NULL);
this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->GetTextfile(tft) == nullptr);
this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == nullptr || BaseSounds::GetUsedSet()->GetTextfile(tft) == nullptr);
this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == nullptr || BaseMusic::GetUsedSet()->GetTextfile(tft) == nullptr);
}
missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
@@ -893,14 +878,14 @@ bool BaseSettingEntry::IsVisible(const BaseSettingEntry *item) const
* Find setting entry at row \a row_num
* @param row_num Index of entry to return
* @param cur_row Current row number
* @return The requested setting entry or \c NULL if it not found (folded or filtered)
* @return The requested setting entry or \c nullptr if it not found (folded or filtered)
*/
BaseSettingEntry *BaseSettingEntry::FindEntry(uint row_num, uint *cur_row)
{
if (this->IsFiltered()) return NULL;
if (this->IsFiltered()) return nullptr;
if (row_num == *cur_row) return this;
(*cur_row)++;
return NULL;
return nullptr;
}
/**
@@ -975,7 +960,7 @@ uint BaseSettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int
SettingEntry::SettingEntry(const char *name)
{
this->name = name;
this->setting = NULL;
this->setting = nullptr;
this->index = 0;
}
@@ -987,7 +972,7 @@ void SettingEntry::Init(byte level)
{
BaseSettingEntry::Init(level);
this->setting = GetSettingFromName(this->name, &this->index);
assert(this->setting != NULL);
assert(this->setting != nullptr);
}
/**
@@ -1267,14 +1252,14 @@ uint SettingsContainer::Length() const
* Find the setting entry at row number \a row_num
* @param row_num Index of entry to return
* @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
* @return The requested setting entry or \c NULL if it does not exist
* @return The requested setting entry or \c nullptr if it does not exist
*/
BaseSettingEntry *SettingsContainer::FindEntry(uint row_num, uint *cur_row)
{
BaseSettingEntry *pe = NULL;
BaseSettingEntry *pe = nullptr;
for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
pe = (*it)->FindEntry(row_num, cur_row);
if (pe != NULL) {
if (pe != nullptr) {
break;
}
}
@@ -1430,14 +1415,14 @@ uint SettingsPage::Length() const
* Find setting entry at row \a row_num
* @param row_num Index of entry to return
* @param cur_row Current row number
* @return The requested setting entry or \c NULL if it not found (folded or filtered)
* @return The requested setting entry or \c nullptr if it not found (folded or filtered)
*/
BaseSettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row)
{
if (this->IsFiltered()) return NULL;
if (this->IsFiltered()) return nullptr;
if (row_num == *cur_row) return this;
(*cur_row)++;
if (this->folded) return NULL;
if (this->folded) return nullptr;
return SettingsContainer::FindEntry(row_num, cur_row);
}
@@ -1493,9 +1478,9 @@ void SettingsPage::DrawSetting(GameSettings *settings_ptr, int left, int right,
/** Construct settings tree */
static SettingsContainer &GetSettingsTree()
{
static SettingsContainer *main = NULL;
static SettingsContainer *main = nullptr;
if (main == NULL)
if (main == nullptr)
{
/* Build up the dynamic settings-array only once per OpenTTD session */
main = new SettingsContainer();
@@ -1735,6 +1720,7 @@ static SettingsContainer &GetSettingsTree()
towns->Add(new SettingEntry("economy.allow_town_roads"));
towns->Add(new SettingEntry("economy.allow_town_level_crossings"));
towns->Add(new SettingEntry("economy.found_town"));
towns->Add(new SettingEntry("economy.town_cargogen_mode"));
}
SettingsPage *industries = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_INDUSTRIES));
@@ -1744,6 +1730,7 @@ static SettingsContainer &GetSettingsTree()
industries->Add(new SettingEntry("economy.multiple_industry_per_town"));
industries->Add(new SettingEntry("game_creation.oil_refinery_limit"));
industries->Add(new SettingEntry("economy.smooth_economy"));
industries->Add(new SettingEntry("station.serve_neutral_industries"));
}
SettingsPage *cdist = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST));
@@ -1770,6 +1757,7 @@ static SettingsContainer &GetSettingsTree()
{
npc->Add(new SettingEntry("script.settings_profile"));
npc->Add(new SettingEntry("script.script_max_opcode_till_suspend"));
npc->Add(new SettingEntry("script.script_max_memory_megabytes"));
npc->Add(new SettingEntry("difficulty.competitor_speed"));
npc->Add(new SettingEntry("ai.ai_in_multiplayer"));
npc->Add(new SettingEntry("ai.ai_disable_veh_train"));
@@ -1780,6 +1768,7 @@ static SettingsContainer &GetSettingsTree()
ai->Add(new SettingEntry("economy.give_money"));
ai->Add(new SettingEntry("economy.allow_shares"));
ai->Add(new SettingEntry("economy.min_years_for_shares"));
}
main->Init();
@@ -1813,10 +1802,10 @@ struct GameSettingsWindow : Window {
static GameSettings *settings_ptr; ///< Pointer to the game settings being displayed and modified.
SettingEntry *valuewindow_entry; ///< If non-NULL, pointer to setting for which a value-entering window has been opened.
SettingEntry *clicked_entry; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
SettingEntry *last_clicked; ///< If non-NULL, pointer to the last clicked setting.
SettingEntry *valuedropdown_entry; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
SettingEntry *valuewindow_entry; ///< If non-nullptr, pointer to setting for which a value-entering window has been opened.
SettingEntry *clicked_entry; ///< If non-nullptr, pointer to a clicked numeric setting (with a depressed left or right button).
SettingEntry *last_clicked; ///< If non-nullptr, pointer to the last clicked setting.
SettingEntry *valuedropdown_entry; ///< If non-nullptr, pointer to the value for which a dropdown window is currently opened.
bool closing_dropdown; ///< True, if the dropdown list is currently closing.
SettingFilter filter; ///< Filter for the list.
@@ -1840,10 +1829,10 @@ struct GameSettingsWindow : Window {
_circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
GetSettingsTree().FoldAll(); // Close all sub-pages
this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
this->clicked_entry = NULL; // No numeric setting buttons are depressed
this->last_clicked = NULL;
this->valuedropdown_entry = NULL;
this->valuewindow_entry = nullptr; // No setting entry for which a entry window is opened
this->clicked_entry = nullptr; // No numeric setting buttons are depressed
this->last_clicked = nullptr;
this->valuedropdown_entry = nullptr;
this->closing_dropdown = false;
this->manually_changed_folding = false;
@@ -1858,7 +1847,7 @@ struct GameSettingsWindow : Window {
this->InvalidateData();
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_GS_OPTIONSPANEL:
@@ -1893,13 +1882,13 @@ struct GameSettingsWindow : Window {
}
}
virtual void OnPaint()
void OnPaint() override
{
if (this->closing_dropdown) {
this->closing_dropdown = false;
assert(this->valuedropdown_entry != NULL);
assert(this->valuedropdown_entry != nullptr);
this->valuedropdown_entry->SetButtons(0);
this->valuedropdown_entry = NULL;
this->valuedropdown_entry = nullptr;
}
/* Reserve the correct number of lines for the 'some search results are hidden' notice in the central settings display panel. */
@@ -1934,7 +1923,7 @@ struct GameSettingsWindow : Window {
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_GS_RESTRICT_DROPDOWN:
@@ -1952,34 +1941,31 @@ struct GameSettingsWindow : Window {
}
}
DropDownList *BuildDropDownList(int widget) const
DropDownList BuildDropDownList(int widget) const
{
DropDownList *list = NULL;
DropDownList list;
switch (widget) {
case WID_GS_RESTRICT_DROPDOWN:
list = new DropDownList();
for (int mode = 0; mode != RM_END; mode++) {
/* If we are in adv. settings screen for the new game's settings,
* we don't want to allow comparing with new game's settings. */
bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
*list->Append() = new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled);
list.emplace_back(new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled));
}
break;
case WID_GS_TYPE_DROPDOWN:
list = new DropDownList();
*list->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false);
*list->Append() = new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false);
*list->Append() = new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false);
*list->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false);
list.emplace_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false));
list.emplace_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false));
list.emplace_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false));
list.emplace_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false));
break;
}
return list;
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_GS_OPTIONSPANEL: {
@@ -1992,7 +1978,7 @@ struct GameSettingsWindow : Window {
}
case WID_GS_HELP_TEXT:
if (this->last_clicked != NULL) {
if (this->last_clicked != nullptr) {
const SettingDesc *sd = this->last_clicked->setting;
int y = r.top;
@@ -2021,7 +2007,7 @@ struct GameSettingsWindow : Window {
/**
* Set the entry that should have its help text displayed, and mark the window dirty so it gets repainted.
* @param pe Setting to display help text of, use \c NULL to stop displaying help of the currently displayed setting.
* @param pe Setting to display help text of, use \c nullptr to stop displaying help of the currently displayed setting.
*/
void SetDisplayedHelpText(SettingEntry *pe)
{
@@ -2029,7 +2015,7 @@ struct GameSettingsWindow : Window {
this->last_clicked = pe;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_GS_EXPAND_ALL:
@@ -2045,17 +2031,17 @@ struct GameSettingsWindow : Window {
break;
case WID_GS_RESTRICT_DROPDOWN: {
DropDownList *list = this->BuildDropDownList(widget);
if (list != NULL) {
ShowDropDownList(this, list, this->filter.mode, widget);
DropDownList list = this->BuildDropDownList(widget);
if (!list.empty()) {
ShowDropDownList(this, std::move(list), this->filter.mode, widget);
}
break;
}
case WID_GS_TYPE_DROPDOWN: {
DropDownList *list = this->BuildDropDownList(widget);
if (list != NULL) {
ShowDropDownList(this, list, this->filter.type, widget);
DropDownList list = this->BuildDropDownList(widget);
if (!list.empty()) {
ShowDropDownList(this, std::move(list), this->filter.type, widget);
}
break;
}
@@ -2070,14 +2056,14 @@ struct GameSettingsWindow : Window {
uint cur_row = 0;
BaseSettingEntry *clicked_entry = GetSettingsTree().FindEntry(btn, &cur_row);
if (clicked_entry == NULL) return; // Clicked below the last setting of the page
if (clicked_entry == nullptr) return; // Clicked below the last setting of the page
int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (clicked_entry->level + 1) * LEVEL_WIDTH; // Shift x coordinate
if (x < 0) return; // Clicked left of the entry
SettingsPage *clicked_page = dynamic_cast<SettingsPage*>(clicked_entry);
if (clicked_page != NULL) {
this->SetDisplayedHelpText(NULL);
if (clicked_page != nullptr) {
this->SetDisplayedHelpText(nullptr);
clicked_page->folded = !clicked_page->folded; // Flip 'folded'-ness of the sub-page
this->manually_changed_folding = true;
@@ -2087,7 +2073,7 @@ struct GameSettingsWindow : Window {
}
SettingEntry *pe = dynamic_cast<SettingEntry*>(clicked_entry);
assert(pe != NULL);
assert(pe != nullptr);
const SettingDesc *sd = pe->setting;
/* return if action is only active in network, or only settable by server */
@@ -2109,9 +2095,9 @@ struct GameSettingsWindow : Window {
HideDropDownMenu(this);
this->closing_dropdown = false;
this->valuedropdown_entry->SetButtons(0);
this->valuedropdown_entry = NULL;
this->valuedropdown_entry = nullptr;
} else {
if (this->valuedropdown_entry != NULL) this->valuedropdown_entry->SetButtons(0);
if (this->valuedropdown_entry != nullptr) this->valuedropdown_entry->SetButtons(0);
this->closing_dropdown = false;
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
@@ -2128,12 +2114,12 @@ struct GameSettingsWindow : Window {
this->valuedropdown_entry = pe;
this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
DropDownList *list = new DropDownList();
DropDownList list;
for (int i = sdb->min; i <= (int)sdb->max; i++) {
*list->Append() = new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false);
list.emplace_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false));
}
ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true);
ShowDropDownListAt(this, std::move(list), value, -1, wi_rect, COLOUR_ORANGE, true);
}
}
this->SetDirty();
@@ -2176,7 +2162,7 @@ struct GameSettingsWindow : Window {
/* Set up scroller timeout for numeric values */
if (value != oldvalue) {
if (this->clicked_entry != NULL) { // Release previous buttons if any
if (this->clicked_entry != nullptr) { // Release previous buttons if any
this->clicked_entry->SetButtons(0);
}
this->clicked_entry = pe;
@@ -2212,21 +2198,21 @@ struct GameSettingsWindow : Window {
}
}
virtual void OnTimeout()
void OnTimeout() override
{
if (this->clicked_entry != NULL) { // On timeout, release any depressed buttons
if (this->clicked_entry != nullptr) { // On timeout, release any depressed buttons
this->clicked_entry->SetButtons(0);
this->clicked_entry = NULL;
this->clicked_entry = nullptr;
this->SetDirty();
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
/* The user pressed cancel */
if (str == NULL) return;
if (str == nullptr) return;
assert(this->valuewindow_entry != NULL);
assert(this->valuewindow_entry != nullptr);
const SettingDesc *sd = this->valuewindow_entry->setting;
int32 value;
@@ -2247,7 +2233,7 @@ struct GameSettingsWindow : Window {
this->SetDirty();
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_GS_RESTRICT_DROPDOWN:
@@ -2275,7 +2261,7 @@ struct GameSettingsWindow : Window {
default:
if (widget < 0) {
/* Deal with drop down boxes on the panel. */
assert(this->valuedropdown_entry != NULL);
assert(this->valuedropdown_entry != nullptr);
const SettingDesc *sd = this->valuedropdown_entry->setting;
assert(sd->desc.flags & SGF_MULTISTRING);
@@ -2291,7 +2277,7 @@ struct GameSettingsWindow : Window {
}
}
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
{
if (widget >= 0) {
/* Normally the default implementation of OnDropdownClose() takes care of
@@ -2304,13 +2290,13 @@ struct GameSettingsWindow : Window {
* the same dropdown button was clicked again, and then not open the dropdown again.
* So, we only remember that it was closed, and process it on the next OnPaint, which is
* after OnClick. */
assert(this->valuedropdown_entry != NULL);
assert(this->valuedropdown_entry != nullptr);
this->closing_dropdown = true;
this->SetDirty();
}
}
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -2329,8 +2315,8 @@ struct GameSettingsWindow : Window {
}
this->vscroll->SetCount(GetSettingsTree().Length() + this->warn_lines);
if (this->last_clicked != NULL && !GetSettingsTree().IsVisible(this->last_clicked)) {
this->SetDisplayedHelpText(NULL);
if (this->last_clicked != nullptr && !GetSettingsTree().IsVisible(this->last_clicked)) {
this->SetDisplayedHelpText(nullptr);
}
bool all_folded = true;
@@ -2340,7 +2326,7 @@ struct GameSettingsWindow : Window {
this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
if (wid == WID_GS_FILTER) {
this->filter.string.SetFilterTerm(this->filter_editbox.text.buf);
@@ -2353,13 +2339,13 @@ struct GameSettingsWindow : Window {
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
}
};
GameSettings *GameSettingsWindow::settings_ptr = NULL;
GameSettings *GameSettingsWindow::settings_ptr = nullptr;
static const NWidgetPart _nested_settings_selection_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -2497,7 +2483,7 @@ struct CustomCurrencyWindow : Window {
this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
@@ -2515,7 +2501,7 @@ struct CustomCurrencyWindow : Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
/* Set the appropriate width for the edit 'buttons' */
@@ -2534,7 +2520,7 @@ struct CustomCurrencyWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
int line = 0;
int len = 0;
@@ -2616,9 +2602,9 @@ struct CustomCurrencyWindow : Window {
this->SetDirty();
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str == NULL) return;
if (str == nullptr) return;
switch (this->query_widget) {
case WID_CC_RATE:
@@ -2648,7 +2634,7 @@ struct CustomCurrencyWindow : Window {
SetButtonState();
}
virtual void OnTimeout()
void OnTimeout() override
{
this->SetDirty();
}
@@ -2695,7 +2681,7 @@ static const NWidgetPart _nested_cust_currency_widgets[] = {
};
static WindowDesc _cust_currency_desc(
WDP_CENTER, NULL, 0, 0,
WDP_CENTER, nullptr, 0, 0,
WC_CUSTOM_CURRENCY, WC_NONE,
0,
_nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)