diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 676774f152..8bcc41455d 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -476,7 +476,7 @@ struct AISettingsWindow : public Window { DropDownList *list = new DropDownList(); for (int i = config_item.min_value; i <= config_item.max_value; i++) { - list->push_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false)); + *list->Append() = new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false); } ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true); diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 29ca6b1537..ca40f35ae0 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -205,7 +205,7 @@ class BuildAirportWindow : public PickerWindowBase { DropDownList *list = new DropDownList(); for (uint i = 0; i < AirportClass::GetClassCount(); i++) { - list->push_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false)); + *list->Append() = new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false); } return list; diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 6b9d067478..1cf38fc521 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -574,7 +574,7 @@ private: DropDownList *list = new DropDownList(); for (uint i = 0; i < lengthof(_colour_dropdown); i++) { - list->push_back(new DropDownListColourItem(i, HasBit(used_colours, i))); + *list->Append() = new DropDownListColourItem(i, HasBit(used_colours, i)); } ShowDropDownList(this, list, widget == WID_SCL_PRI_COL_DROPDOWN ? livery->colour1 : livery->colour2, widget); diff --git a/src/date_gui.cpp b/src/date_gui.cpp index 2866d175ec..a0c4bc38c0 100644 --- a/src/date_gui.cpp +++ b/src/date_gui.cpp @@ -73,14 +73,14 @@ struct SetDateWindow : Window { case WID_SD_DAY: for (uint i = 0; i < 31; i++) { - list->push_back(new DropDownListStringItem(STR_ORDINAL_NUMBER_1ST + i, i + 1, false)); + *list->Append() = new DropDownListStringItem(STR_ORDINAL_NUMBER_1ST + i, i + 1, false); } selected = this->date.day; break; case WID_SD_MONTH: for (uint i = 0; i < 12; i++) { - list->push_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false)); + *list->Append() = new DropDownListStringItem(STR_MONTH_JAN + i, i, false); } selected = this->date.month; break; @@ -89,7 +89,7 @@ struct SetDateWindow : Window { for (Year i = this->min_year; i <= this->max_year; i++) { DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false); item->SetParam(0, i); - list->push_back(item); + *list->Append() = item; } selected = this->date.year; break; diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index b1ecc68eee..f1b561ef18 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -284,7 +284,7 @@ static DropDownList *BuildMapsizeDropDown() for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) { DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false); item->SetParam(0, 1 << i); - list->push_back(item); + *list->Append() = item; } return list; diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 6f13dfeaf4..b21ab70ca0 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -2590,9 +2590,9 @@ struct IndustryCargoesWindow : public Window { DropDownList *lst = new DropDownList; const CargoSpec *cs; FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { - lst->push_back(new DropDownListStringItem(cs->name, cs->Index(), false)); + *lst->Append() = new DropDownListStringItem(cs->name, cs->Index(), false); } - if (lst->size() == 0) { + if (lst->Length() == 0) { delete lst; break; } @@ -2607,9 +2607,9 @@ struct IndustryCargoesWindow : public Window { IndustryType ind = _sorted_industry_types[i]; const IndustrySpec *indsp = GetIndustrySpec(ind); if (!indsp->enabled) continue; - lst->push_back(new DropDownListStringItem(indsp->name, ind, false)); + *lst->Append() = new DropDownListStringItem(indsp->name, ind, false); } - if (lst->size() == 0) { + if (lst->Length() == 0) { delete lst; break; } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index a1c9676637..47cca029a9 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -378,7 +378,7 @@ struct NewGRFParametersWindow : public Window { DropDownList *list = new DropDownList(); for (uint32 i = par_info->min_value; i <= par_info->max_value; i++) { - list->push_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false)); + *list->Append() = new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false); } ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true); @@ -884,11 +884,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { DropDownList *list = new DropDownList(); /* Add 'None' option for clearing list */ - list->push_back(new DropDownListStringItem(STR_NONE, -1, false)); + *list->Append() = new DropDownListStringItem(STR_NONE, -1, false); for (uint i = 0; i < _grf_preset_list.Length(); i++) { if (_grf_preset_list[i] != NULL) { - list->push_back(new DropDownListPresetItem(i)); + *list->Append() = new DropDownListPresetItem(i); } } diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 8123013a44..e62cf595f9 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1319,7 +1319,7 @@ public: case WID_O_COND_VARIABLE: { DropDownList *list = new DropDownList(); for (uint i = 0; i < lengthof(_order_conditional_variable); i++) { - list->push_back(new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false)); + *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false); } ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE); break; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 5dafb83f8e..bac1b3bd17 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1941,9 +1941,9 @@ void InitializeRailGUI() * @param second The railtype to compare. * @return True iff the first should be sorted before the second. */ -static bool CompareRailTypes(const DropDownListItem *first, const DropDownListItem *second) +static CDECL int CompareRailTypes(const DropDownListItem * const *first, const DropDownListItem * const *second) { - return GetRailTypeInfo((RailType)first->result)->sorting_order < GetRailTypeInfo((RailType)second->result)->sorting_order; + return GetRailTypeInfo((RailType)(*first)->result)->sorting_order - GetRailTypeInfo((RailType)(*second)->result)->sorting_order; } /** @@ -1980,8 +1980,8 @@ DropDownList *GetRailTypeDropDownList(bool for_replacement) DropDownListParamStringItem *item = new DropDownListParamStringItem(str, rt, !HasBit(c->avail_railtypes, rt)); item->SetParam(0, rti->strings.menu_text); item->SetParam(1, rti->max_speed); - list->push_back(item); + *list->Append() = item; } - list->sort(CompareRailTypes); + QSortT(list->Begin(), list->Length(), CompareRailTypes); return list; } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index abeb78a31c..dbb7a8ae2c 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -109,7 +109,7 @@ static DropDownList *BuiltSetDropDownList(int *selected_index) DropDownList *list = new DropDownList(); for (int i = 0; i < n; i++) { - list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i))); + *list->Append() = new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i)); } return list; @@ -187,13 +187,13 @@ struct GameOptionsWindow : Window { /* Add non-custom currencies; sorted naturally */ for (uint i = 0; i < CURRENCY_END; items++, i++) { if (i == CURRENCY_CUSTOM) continue; - list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i))); + *list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i)); } - list->sort(DropDownListStringItem::NatSortFunc); + QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc); /* Append custom currency at the end */ - list->push_back(new DropDownListItem(-1, false)); // separator line - list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM))); + *list->Append() = new DropDownListItem(-1, false); // separator line + *list->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM)); break; } @@ -211,7 +211,7 @@ struct GameOptionsWindow : Window { } for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) { - list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i))); + *list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i)); } break; } @@ -222,25 +222,25 @@ struct GameOptionsWindow : Window { int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index; - /* Add and sort original townnames generators */ - for (int i = 0; i < _nb_orig_names; i++) { - list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0)); - } - list->sort(DropDownListStringItem::NatSortFunc); - /* Add and sort newgrf townnames generators */ - DropDownList newgrf_names; for (int i = 0; i < _nb_grf_names; i++) { int result = _nb_orig_names + i; - newgrf_names.push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0)); + *list->Append() = new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0); } - newgrf_names.sort(DropDownListStringItem::NatSortFunc); + QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc); + int newgrf_size = list->Length(); /* Insert newgrf_names at the top of the list */ - if (newgrf_names.size() > 0) { - newgrf_names.push_back(new DropDownListItem(-1, false)); // separator line - list->splice(list->begin(), newgrf_names); + if (newgrf_size > 0) { + *list->Append() = 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); } + QSortT(list->Begin() + newgrf_size, list->Length() - newgrf_size, DropDownListStringItem::NatSortFunc); break; } @@ -249,7 +249,7 @@ struct GameOptionsWindow : Window { *selected_index = _settings_client.gui.autosave; const StringID *items = _autosave_dropdown; for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) { - list->push_back(new DropDownListStringItem(*items, i, false)); + *list->Append() = new DropDownListStringItem(*items, i, false); } break; } @@ -258,9 +258,9 @@ struct GameOptionsWindow : Window { list = new DropDownList(); for (uint i = 0; i < _languages.Length(); i++) { if (&_languages[i] == _current_language) *selected_index = i; - list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false)); + *list->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false); } - list->sort(DropDownListStringItem::NatSortFunc); + QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc); break; } @@ -268,7 +268,7 @@ struct GameOptionsWindow : Window { list = new DropDownList(); *selected_index = GetCurRes(); for (int i = 0; i < _num_resolutions; i++) { - list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false)); + *list->Append() = new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false); } break; @@ -277,7 +277,7 @@ struct GameOptionsWindow : Window { *selected_index = _cur_screenshot_format; for (uint i = 0; i < _num_screenshot_formats; i++) { if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) continue; - list->push_back(new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false)); + *list->Append() = new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false); } break; @@ -392,13 +392,12 @@ struct GameOptionsWindow : Window { DropDownList *list = this->BuildDropDownList(widget, &selected); if (list != NULL) { /* Find the biggest item for the default size. */ - for (DropDownList::iterator it = list->begin(); it != list->end(); it++) { + for (const DropDownListItem * const *it = list->Begin(); it != list->End(); it++) { Dimension string_dim; int width = (*it)->Width(); string_dim.width = width + padding.width; string_dim.height = (*it)->Height(width) + padding.height; *size = maxdim(*size, string_dim); - delete *it; } delete list; } @@ -1839,16 +1838,16 @@ struct GameSettingsWindow : Window { * we don't want to allow comparing with new game's settings. */ bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame; - list->push_back(new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled)); + *list->Append() = new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled); } break; case WID_GS_TYPE_DROPDOWN: list = new DropDownList(); - list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false)); - list->push_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->push_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->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false)); + *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); break; } return list; @@ -1998,7 +1997,7 @@ struct GameSettingsWindow : Window { DropDownList *list = new DropDownList(); for (int i = sdb->min; i <= (int)sdb->max; i++) { - list->push_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false)); + *list->Append() = new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false); } ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true); diff --git a/src/story_gui.cpp b/src/story_gui.cpp index d7856add13..9f84e57b0a 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -246,12 +246,12 @@ protected: item = str_item; } - list->push_back(item); + *list->Append() = item; page_num++; } /* Check if list is empty. */ - if (list->size() == 0) { + if (list->Length() == 0) { delete list; list = NULL; } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 767811c352..f4cb584b1e 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -185,7 +185,7 @@ static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count { DropDownList *list = new DropDownList(); for (int i = 0; i < count; i++) { - list->push_back(new DropDownListStringItem(string + i, i, false)); + *list->Append() = new DropDownListStringItem(string + i, i, false); } PopupMainToolbMenu(w, widget, list, 0); } @@ -211,18 +211,18 @@ static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0, bool if (_networking) { if (widget == WID_TN_COMPANIES) { /* Add the client list button for the companies menu */ - list->push_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false)); + *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false); } if (include_spectator) { if (widget == WID_TN_COMPANIES) { if (_local_company == COMPANY_SPECTATOR) { - list->push_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached())); + *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached()); } else { - list->push_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached())); + *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached()); } } else { - list->push_back(new DropDownListStringItem(STR_NETWORK_TOOLBAR_LIST_SPECTATOR, CTMN_SPECTATOR, false)); + *list->Append() = new DropDownListStringItem(STR_NETWORK_TOOLBAR_LIST_SPECTATOR, CTMN_SPECTATOR, false); } } } @@ -230,7 +230,7 @@ static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0, bool for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { if (!Company::IsValidID(c)) continue; - list->push_back(new DropDownListCompanyItem(c, false, HasBit(grey, c))); + *list->Append() = new DropDownListCompanyItem(c, false, HasBit(grey, c)); } PopupMainToolbMenu(w, widget, list, _local_company == COMPANY_SPECTATOR ? CTMN_CLIENT_LIST : (int)_local_company); @@ -304,24 +304,24 @@ enum OptionMenuEntries { static CallBackFunction ToolbarOptionsClick(Window *w) { DropDownList *list = new DropDownList(); - list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false)); - list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS, OME_SETTINGS, false)); + *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false); + *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS, OME_SETTINGS, false); /* Changes to the per-AI settings don't get send from the server to the clients. Clients get * the settings once they join but never update it. As such don't show the window at all * to network clients. */ - if (!_networking || _network_server) list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false)); - list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false)); - list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false)); - list->push_back(new DropDownListItem(-1, false)); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES))); - list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS))); + if (!_networking || _network_server) *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false); + *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false); + *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false); + *list->Append() = new DropDownListItem(-1, false); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)); + *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS)); ShowDropDownList(w, list, 0, WID_TN_SETTINGS, 140, true, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); @@ -450,10 +450,10 @@ enum MapMenuEntries { static CallBackFunction ToolbarMapClick(Window *w) { DropDownList *list = new DropDownList(); - list->push_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false)); - list->push_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false)); - list->push_back(new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false)); - list->push_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false)); + *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false); + *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false); + *list->Append() = new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false); + *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false); PopupMainToolbMenu(w, WID_TN_SMALL_MAP, list, 0); return CBF_NONE; } @@ -461,11 +461,11 @@ static CallBackFunction ToolbarMapClick(Window *w) static CallBackFunction ToolbarScenMapTownDir(Window *w) { DropDownList *list = new DropDownList(); - list->push_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false)); - list->push_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false)); - list->push_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false)); - list->push_back(new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false)); - list->push_back(new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false)); + *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false); + *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false); + *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false); + *list->Append() = new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false); + *list->Append() = new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false); PopupMainToolbMenu(w, WID_TE_SMALL_MAP, list, 0); return CBF_NONE; } @@ -885,7 +885,7 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w) DropDownList *list = new DropDownList(); /* Road is always visible and available. */ - list->push_back(new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false)); + *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false); /* Tram is only visible when there will be a tram, and available when that has been introduced. */ Engine *e; @@ -893,7 +893,7 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w) if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue; - list->push_back(new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM))); + *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM)); break; } ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index bf7da6b37a..b1cd7ce2be 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -156,13 +156,13 @@ DropDownList *BaseVehicleListWindow::BuildActionDropdownList(bool show_autorepla { DropDownList *list = new DropDownList(); - if (show_autoreplace) list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false)); - list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false)); - list->push_back(new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false)); + if (show_autoreplace) *list->Append() = new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false); + *list->Append() = new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false); + *list->Append() = new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false); if (show_group) { - list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false)); - list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false)); + *list->Append() = new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false); + *list->Append() = new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false); } return list; diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index fd9d765e88..4005148224 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -48,12 +48,12 @@ void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool * @return true if \a first precedes \a second. * @warning All items in the list need to be derivates of DropDownListStringItem. */ -/* static */ bool DropDownListStringItem::NatSortFunc(const DropDownListItem *first, const DropDownListItem *second) +/* static */ int DropDownListStringItem::NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const * second) { char buffer1[512], buffer2[512]; - GetString(buffer1, static_cast(first)->String(), lastof(buffer1)); - GetString(buffer2, static_cast(second)->String(), lastof(buffer2)); - return strnatcmp(buffer1, buffer2) < 0; + GetString(buffer1, static_cast(*first)->String(), lastof(buffer1)); + GetString(buffer2, static_cast(*second)->String(), lastof(buffer2)); + return strnatcmp(buffer1, buffer2); } StringID DropDownListParamStringItem::String() const @@ -68,19 +68,6 @@ StringID DropDownListCharStringItem::String() const return this->string; } -/** - * Delete all items of a drop down list and the list itself - * @param list List to delete. - */ -static void DeleteDropDownList(DropDownList *list) -{ - for (DropDownList::iterator it = list->begin(); it != list->end(); ++it) { - DropDownListItem *item = *it; - delete item; - } - delete list; -} - static const NWidgetPart _nested_dropdown_menu_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetMinimalSize(1, 1), SetScrollbar(WID_DM_SCROLL), EndContainer(), @@ -102,7 +89,7 @@ struct DropdownWindow : Window { WindowClass parent_wnd_class; ///< Parent window class. WindowNumber parent_wnd_num; ///< Parent window number. int parent_button; ///< Parent widget number where the window is dropped from. - DropDownList *list; ///< List with dropdown menu items. + const DropDownList *list; ///< List with dropdown menu items. int selected_index; ///< Index of the selected item in the list. byte click_delay; ///< Timer to delay selection. bool drag_mode; @@ -124,7 +111,7 @@ struct DropdownWindow : Window { * @param scroll Dropdown menu has a scrollbar. * @param widget Widgets of the dropdown menu window. */ - DropdownWindow(Window *parent, DropDownList *list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll) + DropdownWindow(Window *parent, const DropDownList *list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll) : Window(&_dropdown_desc) { this->position = position; @@ -148,14 +135,14 @@ struct DropdownWindow : Window { /* Total length of list */ int list_height = 0; - for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) { - DropDownListItem *item = *it; + for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) { + const DropDownListItem *item = *it; list_height += item->Height(items_width); } /* Capacity is the average number of items visible */ - this->vscroll->SetCapacity(size.height * (uint16)list->size() / list_height); - this->vscroll->SetCount((uint16)list->size()); + this->vscroll->SetCapacity(size.height * (uint16)list->Length() / list_height); + this->vscroll->SetCount((uint16)list->Length()); this->parent_wnd_class = parent->window_class; this->parent_wnd_num = parent->window_number; @@ -181,7 +168,7 @@ struct DropdownWindow : Window { pt.y -= w2->top; w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close); } - DeleteDropDownList(this->list); + delete this->list; } virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) @@ -205,7 +192,7 @@ struct DropdownWindow : Window { const DropDownList *list = this->list; - for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) { + for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) { /* Skip items that are scrolled up */ if (--pos >= 0) continue; @@ -232,7 +219,7 @@ struct DropdownWindow : Window { int y = r.top + 2; int pos = this->vscroll->GetPosition(); - for (DropDownList::const_iterator it = this->list->begin(); it != this->list->end(); ++it) { + for (const DropDownListItem * const *it = this->list->Begin(); it != this->list->End(); ++it) { const DropDownListItem *item = *it; int item_height = item->Height(r.right - r.left + 1); @@ -343,7 +330,7 @@ struct DropdownWindow : Window { * @param instant_close Set to true if releasing mouse button should close the * list regardless of where the cursor is. */ -void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close) +void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close) { DeleteWindowById(WC_DROPDOWN_MENU, 0); @@ -357,7 +344,7 @@ void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, if (auto_width) { /* Find the longest item in the list */ - for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) { + for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) { const DropDownListItem *item = *it; max_item_width = max(max_item_width, item->Width() + 5); } @@ -366,8 +353,8 @@ void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, /* Total length of list */ int list_height = 0; - for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) { - DropDownListItem *item = *it; + for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) { + const DropDownListItem *item = *it; list_height += item->Height(width); } @@ -386,7 +373,7 @@ void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, } else { /* ... and lastly if it won't, enable the scroll bar and fit the * list in below the widget */ - int avg_height = list_height / (int)list->size(); + int avg_height = list_height / (int)list->Length(); int rows = (screen_bottom - 4 - top) / avg_height; height = rows * avg_height; scroll = true; @@ -416,7 +403,7 @@ void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, * @param instant_close Set to true if releasing mouse button should close the * list regardless of where the cursor is. */ -void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close) +void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close) { /* Our parent's button widget is used to determine where to place the drop * down list window. */ @@ -463,13 +450,13 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) { if (!HasBit(hidden_mask, i)) { - list->push_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i))); + *list->Append() = new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)); } } /* No entries in the list? */ - if (list->size() == 0) { - DeleteDropDownList(list); + if (list->Length() == 0) { + delete list; return; } diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h index b923445bb2..90ecef1fbb 100644 --- a/src/widgets/dropdown_type.h +++ b/src/widgets/dropdown_type.h @@ -14,8 +14,8 @@ #include "../window_type.h" #include "../gfx_func.h" +#include "../core/smallvec_type.hpp" #include "table/strings.h" -#include /** * Base list item class from which others are derived. If placed in a list it @@ -50,7 +50,7 @@ public: virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const; virtual StringID String() const { return this->string; } - static bool NatSortFunc(const DropDownListItem *first, const DropDownListItem *second); + static CDECL int NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const *second); }; /** @@ -83,10 +83,10 @@ public: /** * A drop down list is a collection of drop down list items. */ -typedef std::list DropDownList; +typedef AutoDeleteSmallVector DropDownList; -void ShowDropDownListAt(Window *w, DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false); +void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false); -void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false); +void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false); #endif /* WIDGETS_DROPDOWN_TYPE_H */