diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 3e40208db18b0..a6e4109f5946d 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -23,6 +23,7 @@ #include "newgrf_airport.h" #include "newgrf_callbacks.h" #include "dropdown_type.h" +#include "dropdown_func.h" #include "core/geometry_func.hpp" #include "hotkeys.h" #include "vehicle_func.h" @@ -241,7 +242,7 @@ class BuildAirportWindow : public PickerWindowBase { DropDownList list; for (uint i = 0; i < AirportClass::GetClassCount(); i++) { - list.push_back(std::make_unique(AirportClass::Get((AirportClassID)i)->name, i, false)); + list.push_back(MakeDropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i)); } return list; diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index a69786dc2f04b..93f2ae7825db3 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -24,6 +24,7 @@ #include "core/geometry_func.hpp" #include "rail_gui.h" #include "road_gui.h" +#include "dropdown_type.h" #include "dropdown_func.h" #include "autoreplace_cmd.h" #include "group_cmd.h" @@ -563,8 +564,8 @@ class ReplaceVehicleWindow : public Window { case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: { DropDownList list; - list.push_back(std::make_unique(STR_REPLACE_ENGINES, 1, false)); - list.push_back(std::make_unique(STR_REPLACE_WAGONS, 0, false)); + list.push_back(MakeDropDownListStringItem(STR_REPLACE_ENGINES, 1)); + list.push_back(MakeDropDownListStringItem(STR_REPLACE_WAGONS, 0)); ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN); break; } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 0b458f3868146..50244c24ebc14 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -25,6 +25,7 @@ #include "window_func.h" #include "timer/timer_game_calendar.h" #include "vehicle_func.h" +#include "dropdown_type.h" #include "dropdown_func.h" #include "engine_gui.h" #include "cargotype.h" @@ -1565,20 +1566,20 @@ struct BuildVehicleWindow : Window { DropDownList list; /* Add item for disabling filtering. */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY)); /* Specific filters for trains. */ if (this->vehicle_type == VEH_TRAIN) { /* Add item for locomotives only in case of trains. */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ENGINES), CargoFilterCriteria::CF_ENGINES, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ENGINES), CargoFilterCriteria::CF_ENGINES)); /* Add item for vehicles not carrying anything, e.g. train engines. * This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE)); } /* Add cargos */ Dimension d = GetLargestCargoIconSize(); for (const CargoSpec *cs : _sorted_standard_cargo_specs) { - list.push_back(std::make_unique(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false)); + list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index())); } return list; diff --git a/src/date_gui.cpp b/src/date_gui.cpp index e5c2438cd2542..57b2c076a8f0d 100644 --- a/src/date_gui.cpp +++ b/src/date_gui.cpp @@ -15,6 +15,7 @@ #include "date_gui.h" #include "core/geometry_func.hpp" #include "dropdown_type.h" +#include "dropdown_func.h" #include "widgets/date_widget.h" @@ -75,14 +76,14 @@ struct SetDateWindow : Window { case WID_SD_DAY: for (uint i = 0; i < 31; i++) { - list.push_back(std::make_unique(STR_DAY_NUMBER_1ST + i, i + 1, false)); + list.push_back(MakeDropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1)); } selected = this->date.day; break; case WID_SD_MONTH: for (uint i = 0; i < 12; i++) { - list.push_back(std::make_unique(STR_MONTH_JAN + i, i, false)); + list.push_back(MakeDropDownListStringItem(STR_MONTH_JAN + i, i)); } selected = this->date.month; break; @@ -90,7 +91,7 @@ struct SetDateWindow : Window { case WID_SD_YEAR: for (TimerGameEconomy::Year i = this->min_year; i <= this->max_year; i++) { SetDParam(0, i); - list.push_back(std::make_unique(STR_JUST_INT, i.base(), false)); + list.push_back(MakeDropDownListStringItem(STR_JUST_INT, i.base())); } selected = this->date.year.base(); break; diff --git a/src/dropdown.cpp b/src/dropdown.cpp index 2e70120069a8d..1e334e365e15c 100644 --- a/src/dropdown.cpp +++ b/src/dropdown.cpp @@ -9,6 +9,7 @@ #include "stdafx.h" #include "dropdown_type.h" +#include "dropdown_func.h" #include "strings_func.h" #include "timer/timer.h" #include "timer/timer_window.h" @@ -20,6 +21,35 @@ #include "safeguards.h" +std::unique_ptr MakeDropDownListDividerItem() +{ + return std::make_unique(-1); +} + +std::unique_ptr MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded) +{ + return std::make_unique(str, value, masked, shaded); +} + +std::unique_ptr MakeDropDownListStringItem(const std::string &str, int value, bool masked, bool shaded) +{ + return std::make_unique(str, value, masked, shaded); +} + +std::unique_ptr MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded) +{ + return std::make_unique(sprite, palette, str, value, masked, shaded); +} + +std::unique_ptr MakeDropDownListIconItem(const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded) +{ + return std::make_unique(dim, sprite, palette, str, value, masked, shaded); +} + +std::unique_ptr MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked, bool shaded) +{ + return std::make_unique(checked, str, value, masked, shaded); +} static constexpr NWidgetPart _nested_dropdown_menu_widgets[] = { NWidget(NWID_HORIZONTAL), @@ -408,7 +438,7 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) { if (!HasBit(hidden_mask, i)) { - list.push_back(std::make_unique(strings[i], i, HasBit(disabled_mask, i))); + list.push_back(MakeDropDownListStringItem(strings[i], i, HasBit(disabled_mask, i))); } } diff --git a/src/dropdown_func.h b/src/dropdown_func.h index 65e4d272afe6a..dee640e00faf8 100644 --- a/src/dropdown_func.h +++ b/src/dropdown_func.h @@ -15,4 +15,12 @@ /* Show drop down menu containing a fixed list of strings */ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width = 0); +/* Helper functions for commonly used drop down list items. */ +std::unique_ptr MakeDropDownListDividerItem(); +std::unique_ptr MakeDropDownListStringItem(StringID str, int value, bool masked = false, bool shaded = false); +std::unique_ptr MakeDropDownListStringItem(const std::string &str, int value, bool masked = false, bool shaded = false); +std::unique_ptr MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked = false, bool shaded = false); +std::unique_ptr MakeDropDownListIconItem(const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked = false, bool shaded = false); +std::unique_ptr MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked = false, bool shaded = false); + #endif /* DROPDOWN_FUNC_H */ diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index b6c6c7588a040..aae47f76e8093 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -14,6 +14,7 @@ #include "../window_func.h" #include "../network/network.h" #include "../network/network_content.h" +#include "../dropdown_type.h" #include "../dropdown_func.h" #include "../timer/timer.h" #include "../timer/timer_window.h" @@ -317,7 +318,7 @@ struct GSConfigWindow : public Window { DropDownList list; for (int i = config_item.min_value; i <= config_item.max_value; i++) { - list.push_back(std::make_unique(config_item.labels.find(i)->second, i, false)); + list.push_back(MakeDropDownListStringItem(config_item.labels.find(i)->second, i)); } ShowDropDownListAt(this, std::move(list), old_val, WID_GSC_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index d0071b63ca279..723df35436ef5 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -338,7 +338,7 @@ static DropDownList BuildMapsizeDropDown() for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) { SetDParam(0, 1LL << i); - list.push_back(std::make_unique(STR_JUST_INT, i, false)); + list.push_back(MakeDropDownListStringItem(STR_JUST_INT, i)); } return list; @@ -351,20 +351,20 @@ static DropDownList BuildTownNameDropDown() /* Add and sort newgrf townnames generators */ const auto &grf_names = GetGRFTownNameList(); for (uint i = 0; i < grf_names.size(); i++) { - list.push_back(std::make_unique(grf_names[i], BUILTIN_TOWNNAME_GENERATOR_COUNT + i, false)); + list.push_back(MakeDropDownListStringItem(grf_names[i], BUILTIN_TOWNNAME_GENERATOR_COUNT + i)); } 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.push_back(std::make_unique(-1, false)); // separator line + list.push_back(MakeDropDownListDividerItem()); // separator line newgrf_size++; } /* Add and sort original townnames generators */ for (uint i = 0; i < BUILTIN_TOWNNAME_GENERATOR_COUNT; i++) { - list.push_back(std::make_unique(STR_MAPGEN_TOWN_NAME_ORIGINAL_ENGLISH + i, i, false)); + list.push_back(MakeDropDownListStringItem(STR_MAPGEN_TOWN_NAME_ORIGINAL_ENGLISH + i, i)); } std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 6beffe9a73a8e..7bd64396cff87 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1759,14 +1759,14 @@ class IndustryDirectoryWindow : public Window { DropDownList list; /* Add item for disabling filtering. */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY)); /* Add item for industries not producing anything, e.g. power plants */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE)); /* Add cargos */ Dimension d = GetLargestCargoIconSize(); for (const CargoSpec *cs : _sorted_standard_cargo_specs) { - list.push_back(std::make_unique(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false)); + list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index())); } return list; @@ -3101,7 +3101,7 @@ struct IndustryCargoesWindow : public Window { DropDownList lst; Dimension d = GetLargestCargoIconSize(); for (const CargoSpec *cs : _sorted_standard_cargo_specs) { - lst.push_back(std::make_unique(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false)); + lst.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index())); } if (!lst.empty()) { int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1; @@ -3115,7 +3115,7 @@ struct IndustryCargoesWindow : public Window { for (IndustryType ind : _sorted_industry_types) { const IndustrySpec *indsp = GetIndustrySpec(ind); if (!indsp->enabled) continue; - lst.push_back(std::make_unique(indsp->name, ind, false)); + lst.push_back(MakeDropDownListStringItem(indsp->name, ind)); } if (!lst.empty()) { int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 13e1c76effb7c..548c29387b9d5 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -72,9 +72,9 @@ static DropDownList BuildVisibilityDropDownList() { DropDownList list; - list.push_back(std::make_unique(STR_NETWORK_SERVER_VISIBILITY_LOCAL, SERVER_GAME_TYPE_LOCAL, false)); - list.push_back(std::make_unique(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY, SERVER_GAME_TYPE_INVITE_ONLY, false)); - list.push_back(std::make_unique(STR_NETWORK_SERVER_VISIBILITY_PUBLIC, SERVER_GAME_TYPE_PUBLIC, false)); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_LOCAL, SERVER_GAME_TYPE_LOCAL)); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY, SERVER_GAME_TYPE_INVITE_ONLY)); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_SERVER_VISIBILITY_PUBLIC, SERVER_GAME_TYPE_PUBLIC)); return list; } @@ -1496,8 +1496,8 @@ struct NetworkClientListWindow : Window { static void OnClickClientAdmin([[maybe_unused]] NetworkClientListWindow *w, [[maybe_unused]] Point pt, ClientID client_id) { DropDownList list; - list.push_back(std::make_unique(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_KICK, DD_CLIENT_ADMIN_KICK, false)); - list.push_back(std::make_unique(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_BAN, DD_CLIENT_ADMIN_BAN, false)); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_KICK, DD_CLIENT_ADMIN_KICK)); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_BAN, DD_CLIENT_ADMIN_BAN)); Rect wi_rect; wi_rect.left = pt.x; @@ -1518,8 +1518,8 @@ struct NetworkClientListWindow : Window { static void OnClickCompanyAdmin([[maybe_unused]] NetworkClientListWindow *w, [[maybe_unused]] Point pt, CompanyID company_id) { DropDownList list; - list.push_back(std::make_unique(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_RESET, DD_COMPANY_ADMIN_RESET, NetworkCompanyHasClients(company_id))); - list.push_back(std::make_unique(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_UNLOCK, DD_COMPANY_ADMIN_UNLOCK, !NetworkCompanyIsPassworded(company_id))); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_RESET, DD_COMPANY_ADMIN_RESET, NetworkCompanyHasClients(company_id))); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_UNLOCK, DD_COMPANY_ADMIN_UNLOCK, !NetworkCompanyIsPassworded(company_id))); Rect wi_rect; wi_rect.left = pt.x; diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index d70cfda897ce7..e311fad3c695f 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -394,7 +394,7 @@ struct NewGRFParametersWindow : public Window { DropDownList list; for (uint32_t i = par_info.min_value; i <= par_info.max_value; i++) { - list.push_back(std::make_unique(GetGRFStringFromGRFText(par_info.value_names.find(i)->second), i, false)); + list.push_back(MakeDropDownListStringItem(GetGRFStringFromGRFText(par_info.value_names.find(i)->second), i)); } ShowDropDownListAt(this, std::move(list), old_val, WID_NP_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE); @@ -955,10 +955,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { DropDownList list; /* Add 'None' option for clearing list */ - list.push_back(std::make_unique(STR_NONE, -1, false)); + list.push_back(MakeDropDownListStringItem(STR_NONE, -1)); for (uint i = 0; i < this->grf_presets.size(); i++) { - list.push_back(std::make_unique(this->grf_presets[i], i, false)); + list.push_back(MakeDropDownListStringItem(this->grf_presets[i], i)); } this->CloseChildWindows(WC_QUERY_STRING); // Remove the parameter query window diff --git a/src/order_gui.cpp b/src/order_gui.cpp index f6ee4d9421f28..95d0d6f941496 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1350,7 +1350,7 @@ struct OrdersWindow : public Window { case WID_O_COND_VARIABLE: { DropDownList list; for (uint i = 0; i < lengthof(_order_conditional_variable); i++) { - list.push_back(std::make_unique(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false)); + list.push_back(MakeDropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i])); } ShowDropDownList(this, std::move(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 71fc9c6c4994b..16a0e985b617a 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -22,6 +22,7 @@ #include "sound_func.h" #include "company_func.h" #include "dropdown_type.h" +#include "dropdown_func.h" #include "tunnelbridge.h" #include "tilehighlight_func.h" #include "spritecache.h" @@ -2385,7 +2386,7 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option) DropDownList list; if (all_option) { - list.push_back(std::make_unique(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE, false)); + list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE)); } Dimension d = { 0, 0 }; @@ -2407,16 +2408,16 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option) SetDParam(0, rti->strings.menu_text); SetDParam(1, rti->max_speed); if (for_replacement) { - list.push_back(std::make_unique(rti->strings.replace_text, rt, !HasBit(avail_railtypes, rt))); + list.push_back(MakeDropDownListStringItem(rti->strings.replace_text, rt, !HasBit(avail_railtypes, rt))); } else { StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING; - list.push_back(std::make_unique(d, rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt))); + list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt))); } } if (list.empty()) { /* Empty dropdowns are not allowed */ - list.push_back(std::make_unique(STR_NONE, INVALID_RAILTYPE, true)); + list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_RAILTYPE, true)); } return list; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 766a3434c44e0..e966d9b7703a4 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -27,6 +27,8 @@ #include "hotkeys.h" #include "road_gui.h" #include "zoom_func.h" +#include "dropdown_type.h" +#include "dropdown_func.h" #include "engine_base.h" #include "strings_func.h" #include "core/geometry_func.hpp" @@ -1830,7 +1832,7 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b DropDownList list; if (all_option) { - list.push_back(std::make_unique(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE, false)); + list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE)); } Dimension d = { 0, 0 }; @@ -1852,16 +1854,16 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b SetDParam(0, rti->strings.menu_text); SetDParam(1, rti->max_speed / 2); if (for_replacement) { - list.push_back(std::make_unique(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt))); + list.push_back(MakeDropDownListStringItem(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt))); } else { StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING; - list.push_back(std::make_unique(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt))); + list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt))); } } if (list.empty()) { /* Empty dropdowns are not allowed */ - list.push_back(std::make_unique(STR_NONE, INVALID_ROADTYPE, true)); + list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true)); } return list; @@ -1894,12 +1896,12 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts) SetDParam(0, rti->strings.menu_text); SetDParam(1, rti->max_speed / 2); StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING; - list.push_back(std::make_unique(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt))); + list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt))); } if (list.empty()) { /* Empty dropdowns are not allowed */ - list.push_back(std::make_unique(STR_NONE, -1, true)); + list.push_back(MakeDropDownListStringItem(STR_NONE, -1, true)); } return list; diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index d6855bdd6c226..21d0a5af0a331 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -15,9 +15,10 @@ #include "../stringfilter_type.h" #include "../company_base.h" #include "../company_gui.h" +#include "../dropdown_type.h" +#include "../dropdown_func.h" #include "../window_func.h" #include "../network/network.h" -#include "../dropdown_func.h" #include "../hotkeys.h" #include "../company_cmd.h" #include "../misc_cmd.h" @@ -467,7 +468,7 @@ struct ScriptSettingsWindow : public Window { DropDownList list; for (int i = config_item.min_value; i <= config_item.max_value; i++) { - list.push_back(std::make_unique(config_item.labels.find(i)->second, i, false)); + list.push_back(MakeDropDownListStringItem(config_item.labels.find(i)->second, i)); } ShowDropDownListAt(this, std::move(list), old_val, WID_SCRS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE); diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index bdcc5e5fcd7d7..8c467dc90a331 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -126,6 +126,18 @@ void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet *baseset, new BaseSetTextfileWindow(file_type, baseset, content_type); } +template +DropDownList BuildSetDropDownList(int *selected_index) +{ + int n = T::GetNumSets(); + *selected_index = T::GetIndexOfUsedSet(); + DropDownList list; + for (int i = 0; i < n; i++) { + list.push_back(MakeDropDownListStringItem(T::GetSet(i)->GetListLabel(), i)); + } + return list; +} + std::set _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 }; /** @@ -401,18 +413,18 @@ struct GameOptionsWindow : Window { int i = ¤cy - _currency_specs.data(); if (i == CURRENCY_CUSTOM) continue; if (currency.code.empty()) { - list.push_back(std::make_unique(currency.name, i, HasBit(disabled, i))); + list.push_back(MakeDropDownListStringItem(currency.name, i, HasBit(disabled, i))); } else { SetDParam(0, currency.name); SetDParamStr(1, currency.code); - list.push_back(std::make_unique(STR_GAME_OPTIONS_CURRENCY_CODE, i, HasBit(disabled, i))); + list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CODE, i, HasBit(disabled, i))); } } std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc); /* Append custom currency at the end */ - list.push_back(std::make_unique(-1, false)); // separator line - list.push_back(std::make_unique(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM))); + list.push_back(MakeDropDownListDividerItem()); // separator line + list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM))); break; } @@ -426,7 +438,7 @@ struct GameOptionsWindow : Window { const StringID *items = _autosave_dropdown; for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) { - list.push_back(std::make_unique(*items, i, false)); + list.push_back(MakeDropDownListStringItem(*items, i)); } break; } @@ -448,7 +460,7 @@ struct GameOptionsWindow : Window { SetDParamStr(0, _languages[i].name); } SetDParam(1, (LANGUAGE_TOTAL_STRINGS - _languages[i].missing) * 100 / LANGUAGE_TOTAL_STRINGS); - list.push_back(std::make_unique(hide_percentage ? STR_JUST_RAW_STRING : STR_GAME_OPTIONS_LANGUAGE_PERCENTAGE, i, false)); + list.push_back(MakeDropDownListStringItem(hide_percentage ? STR_JUST_RAW_STRING : STR_GAME_OPTIONS_LANGUAGE_PERCENTAGE, i)); } std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc); break; @@ -461,7 +473,7 @@ struct GameOptionsWindow : Window { for (uint i = 0; i < _resolutions.size(); i++) { SetDParam(0, _resolutions[i].width); SetDParam(1, _resolutions[i].height); - list.push_back(std::make_unique(STR_GAME_OPTIONS_RESOLUTION_ITEM, i, false)); + list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_RESOLUTION_ITEM, i)); } break; @@ -470,7 +482,7 @@ struct GameOptionsWindow : Window { auto i = std::distance(_refresh_rates.begin(), it); if (*it == _settings_client.gui.refresh_rate) *selected_index = i; SetDParam(0, *it); - list.push_back(std::make_unique(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, i, false)); + list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, i)); } break; @@ -2447,15 +2459,15 @@ 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(std::make_unique(_game_settings_restrict_dropdown[mode], mode, disabled)); + list.push_back(MakeDropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled)); } break; case WID_GS_TYPE_DROPDOWN: - list.push_back(std::make_unique(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false)); - list.push_back(std::make_unique(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false)); - list.push_back(std::make_unique(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false)); - list.push_back(std::make_unique(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false)); + list.push_back(MakeDropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL)); + list.push_back(MakeDropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME)); + list.push_back(MakeDropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY)); + list.push_back(MakeDropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT)); break; } return list; @@ -2620,7 +2632,7 @@ struct GameSettingsWindow : Window { DropDownList list; for (int i = sd->min; i <= (int)sd->max; i++) { sd->SetValueDParams(0, i); - list.push_back(std::make_unique(STR_JUST_STRING2, i, false)); + list.push_back(MakeDropDownListStringItem(STR_JUST_STRING2, i)); } ShowDropDownListAt(this, std::move(list), value, WID_GS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE); diff --git a/src/settings_gui.h b/src/settings_gui.h index c95345b00ae4e..bca6888ac7888 100644 --- a/src/settings_gui.h +++ b/src/settings_gui.h @@ -23,17 +23,7 @@ void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool cl void DrawBoolButton(int x, int y, bool state, bool clickable); template -DropDownList BuildSetDropDownList(int *selected_index) -{ - int n = T::GetNumSets(); - *selected_index = T::GetIndexOfUsedSet(); - DropDownList list; - for (int i = 0; i < n; i++) { - list.push_back(std::make_unique(T::GetSet(i)->GetListLabel(), i, false)); - } - return list; -} - +DropDownList BuildSetDropDownList(int *selected_index); /* Actually implemented in music_gui.cpp */ void ChangeMusicSet(int index); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 44b90c0714e38..3f03a1ae68f53 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -20,6 +20,7 @@ #include "string_func.h" #include "window_func.h" #include "viewport_func.h" +#include "dropdown_type.h" #include "dropdown_func.h" #include "station_base.h" #include "waypoint_base.h" @@ -542,8 +543,8 @@ class CompanyStationsWindow : public Window using DropDownListCargoItem = DropDownCheck>; DropDownList list; - list.push_back(std::make_unique(STR_STATION_LIST_CARGO_FILTER_SELECT_ALL, CargoFilterCriteria::CF_SELECT_ALL)); - list.push_back(std::make_unique(-1)); + list.push_back(MakeDropDownListStringItem(STR_STATION_LIST_CARGO_FILTER_SELECT_ALL, CargoFilterCriteria::CF_SELECT_ALL)); + list.push_back(MakeDropDownListDividerItem()); bool any_hidden = false; @@ -565,8 +566,8 @@ class CompanyStationsWindow : public Window } if (!expanded && any_hidden) { - if (list.size() > 2) list.push_back(std::make_unique(-1)); - list.push_back(std::make_unique(STR_STATION_LIST_CARGO_FILTER_EXPAND, CargoFilterCriteria::CF_EXPAND_LIST)); + if (list.size() > 2) list.push_back(MakeDropDownListDividerItem()); + list.push_back(MakeDropDownListStringItem(STR_STATION_LIST_CARGO_FILTER_EXPAND, CargoFilterCriteria::CF_EXPAND_LIST)); } return list; diff --git a/src/story_gui.cpp b/src/story_gui.cpp index 61e8e209651ad..1ed4e950d94fa 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -253,11 +253,11 @@ struct StoryBookWindow : Window { for (const StoryPage *p : this->story_pages) { bool current_page = p->index == this->selected_page_id; if (!p->title.empty()) { - list.push_back(std::make_unique(p->title, p->index, current_page)); + list.push_back(MakeDropDownListStringItem(p->title, p->index, current_page)); } else { /* No custom title => use a generic page title with page number. */ SetDParam(0, page_num); - list.push_back(std::make_unique(STR_STORY_BOOK_GENERIC_PAGE_ITEM, p->index, current_page)); + list.push_back(MakeDropDownListStringItem(STR_STORY_BOOK_GENERIC_PAGE_ITEM, p->index, current_page)); } page_num++; } diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 843a28faac4d8..194c3c6a4c821 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -16,6 +16,7 @@ #include "string_func.h" #include "textfile_gui.h" #include "dropdown_type.h" +#include "dropdown_func.h" #include "gfx_layout.h" #include "debug.h" #include "openttd.h" @@ -534,7 +535,7 @@ void TextfileWindow::AfterLoadMarkdown() DropDownList list; for (size_t line : this->jumplist) { SetDParamStr(0, this->lines[line].text); - list.push_back(std::make_unique(STR_TEXTFILE_JUMPLIST_ITEM, (int)line, false)); + list.push_back(MakeDropDownListStringItem(STR_TEXTFILE_JUMPLIST_ITEM, (int)line)); } ShowDropDownList(this, std::move(list), -1, widget); break; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index c45db8a0b63b6..04d7387cb99a5 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -13,6 +13,8 @@ #include "window_func.h" #include "viewport_func.h" #include "command_func.h" +#include "dropdown_type.h" +#include "dropdown_func.h" #include "vehicle_gui.h" #include "rail_gui.h" #include "road.h" @@ -127,9 +129,9 @@ static void PopupMainToolbarMenu(Window *w, WidgetID widget, const std::initiali int i = 0; for (StringID string : strings) { if (string == STR_NULL) { - list.push_back(std::make_unique(-1, false)); + list.push_back(MakeDropDownListDividerItem()); } else { - list.push_back(std::make_unique(string, i, false)); + list.push_back(MakeDropDownListStringItem(string, i)); i++; } } @@ -156,18 +158,18 @@ static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask gr if (!_networking) break; /* Add the client list button for the companies menu */ - list.push_back(std::make_unique(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false)); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST)); if (_local_company != COMPANY_SPECTATOR) { - list.push_back(std::make_unique(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, false)); + list.push_back(MakeDropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE)); } break; case WID_TN_STORY: - list.push_back(std::make_unique(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false)); + list.push_back(MakeDropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR)); break; case WID_TN_GOAL: - list.push_back(std::make_unique(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false)); + list.push_back(MakeDropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR)); break; } @@ -250,30 +252,30 @@ enum OptionMenuEntries { static CallBackFunction ToolbarOptionsClick(Window *w) { DropDownList list; - list.push_back(std::make_unique(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false)); - list.push_back(std::make_unique(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false)); + list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS)); + list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS)); /* 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(std::make_unique(STR_SETTINGS_MENU_AI_SETTINGS, OME_AI_SETTINGS, false)); - list.push_back(std::make_unique(STR_SETTINGS_MENU_GAMESCRIPT_SETTINGS, OME_GAMESCRIPT_SETTINGS, false)); + list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_AI_SETTINGS, OME_AI_SETTINGS)); + list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_GAMESCRIPT_SETTINGS, OME_GAMESCRIPT_SETTINGS)); } - list.push_back(std::make_unique(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false)); + list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS)); if (_game_mode != GM_EDITOR && !_networking) { - list.push_back(std::make_unique(STR_SETTINGS_MENU_SANDBOX_OPTIONS, OME_SANDBOX, false)); - } - list.push_back(std::make_unique(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false)); - list.push_back(std::make_unique(-1, false)); - list.push_back(std::make_unique(HasBit(_display_opt, DO_SHOW_TOWN_NAMES), STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false)); - list.push_back(std::make_unique(HasBit(_display_opt, DO_SHOW_STATION_NAMES), STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false)); - list.push_back(std::make_unique(HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES), STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false)); - list.push_back(std::make_unique(HasBit(_display_opt, DO_SHOW_SIGNS), STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false)); - list.push_back(std::make_unique(HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS), STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false)); - list.push_back(std::make_unique(HasBit(_display_opt, DO_FULL_ANIMATION), STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false)); - list.push_back(std::make_unique(HasBit(_display_opt, DO_FULL_DETAIL), STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false)); - list.push_back(std::make_unique(IsTransparencySet(TO_HOUSES), STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false)); - list.push_back(std::make_unique(IsTransparencySet(TO_SIGNS), STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false)); + list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_SANDBOX_OPTIONS, OME_SANDBOX)); + } + list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES)); + list.push_back(MakeDropDownListDividerItem()); + list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_TOWN_NAMES), STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES)); + list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_STATION_NAMES), STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES)); + list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES), STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES)); + list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_SIGNS), STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS)); + list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS), STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS)); + list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_FULL_ANIMATION), STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION)); + list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_FULL_DETAIL), STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS)); + list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_HOUSES), STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS)); + list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_SIGNS), STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS)); ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); @@ -405,10 +407,10 @@ enum MapMenuEntries { static CallBackFunction ToolbarMapClick(Window *w) { DropDownList list; - list.push_back(std::make_unique(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false)); - list.push_back(std::make_unique(STR_MAP_MENU_EXTRA_VIEWPORT, MME_SHOW_EXTRAVIEWPORTS, false)); - list.push_back(std::make_unique(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false)); - list.push_back(std::make_unique(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false)); + list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP)); + list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_EXTRA_VIEWPORT, MME_SHOW_EXTRAVIEWPORTS)); + list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH)); + list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS)); PopupMainToolbarMenu(w, WID_TN_SMALL_MAP, std::move(list), 0); return CBF_NONE; } @@ -416,11 +418,11 @@ static CallBackFunction ToolbarMapClick(Window *w) static CallBackFunction ToolbarScenMapTownDir(Window *w) { DropDownList list; - list.push_back(std::make_unique(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false)); - list.push_back(std::make_unique(STR_MAP_MENU_EXTRA_VIEWPORT, MME_SHOW_EXTRAVIEWPORTS, false)); - list.push_back(std::make_unique(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false)); - list.push_back(std::make_unique(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false)); - list.push_back(std::make_unique(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false)); + list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP)); + list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_EXTRA_VIEWPORT, MME_SHOW_EXTRAVIEWPORTS)); + list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS)); + list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY)); + list.push_back(MakeDropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY)); PopupMainToolbarMenu(w, WID_TE_SMALL_MAP, std::move(list), 0); return CBF_NONE; } @@ -628,13 +630,13 @@ static void AddDropDownLeagueTableOptions(DropDownList &list) { if (LeagueTable::GetNumItems() > 0) { for (LeagueTable *lt : LeagueTable::Iterate()) { - list.push_back(std::make_unique(lt->title, lt->index, false)); + list.push_back(MakeDropDownListStringItem(lt->title, lt->index)); } } else { - list.push_back(std::make_unique(STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, LTMN_PERFORMANCE_LEAGUE, false)); - list.push_back(std::make_unique(STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING, LTMN_PERFORMANCE_RATING, false)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, LTMN_PERFORMANCE_LEAGUE)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING, LTMN_PERFORMANCE_RATING)); if (!_networking) { - list.push_back(std::make_unique(STR_GRAPH_MENU_HIGHSCORE, LTMN_HIGHSCORE, false)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_HIGHSCORE, LTMN_HIGHSCORE)); } } } @@ -643,12 +645,12 @@ static CallBackFunction ToolbarGraphsClick(Window *w) { DropDownList list; - list.push_back(std::make_unique(STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, GRMN_OPERATING_PROFIT_GRAPH, false)); - list.push_back(std::make_unique(STR_GRAPH_MENU_INCOME_GRAPH, GRMN_INCOME_GRAPH, false)); - list.push_back(std::make_unique(STR_GRAPH_MENU_DELIVERED_CARGO_GRAPH, GRMN_DELIVERED_CARGO_GRAPH, false)); - list.push_back(std::make_unique(STR_GRAPH_MENU_PERFORMANCE_HISTORY_GRAPH, GRMN_PERFORMANCE_HISTORY_GRAPH, false)); - list.push_back(std::make_unique(STR_GRAPH_MENU_COMPANY_VALUE_GRAPH, GRMN_COMPANY_VALUE_GRAPH, false)); - list.push_back(std::make_unique(STR_GRAPH_MENU_CARGO_PAYMENT_RATES, GRMN_CARGO_PAYMENT_RATES, false)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, GRMN_OPERATING_PROFIT_GRAPH)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_INCOME_GRAPH, GRMN_INCOME_GRAPH)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_DELIVERED_CARGO_GRAPH, GRMN_DELIVERED_CARGO_GRAPH)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_PERFORMANCE_HISTORY_GRAPH, GRMN_PERFORMANCE_HISTORY_GRAPH)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_VALUE_GRAPH, GRMN_COMPANY_VALUE_GRAPH)); + list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_CARGO_PAYMENT_RATES, GRMN_CARGO_PAYMENT_RATES)); if (_toolbar_mode != TB_NORMAL) AddDropDownLeagueTableOptions(list); @@ -913,7 +915,7 @@ static CallBackFunction MenuClickBuildTram(int index) static CallBackFunction ToolbarBuildWaterClick(Window *w) { DropDownList list; - list.push_back(std::make_unique(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false)); + list.push_back(MakeDropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0)); ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; @@ -935,7 +937,7 @@ static CallBackFunction MenuClickBuildWater(int) static CallBackFunction ToolbarBuildAirClick(Window *w) { DropDownList list; - list.push_back(std::make_unique(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false)); + list.push_back(MakeDropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0)); ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; @@ -957,9 +959,9 @@ static CallBackFunction MenuClickBuildAir(int) static CallBackFunction ToolbarForestClick(Window *w) { DropDownList list; - list.push_back(std::make_unique(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0, false)); - list.push_back(std::make_unique(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1, false)); - list.push_back(std::make_unique(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2, false)); + list.push_back(MakeDropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0)); + list.push_back(MakeDropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1)); + list.push_back(MakeDropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2)); ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 0768c64b499a2..e0f9e0dee546f 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -26,6 +26,7 @@ #include "vehicle_func.h" #include "autoreplace_gui.h" #include "string_func.h" +#include "dropdown_type.h" #include "dropdown_func.h" #include "timetable.h" #include "articulated_vehicles.h" @@ -427,17 +428,17 @@ DropDownList BaseVehicleListWindow::BuildCargoDropDownList(bool full) const DropDownList list; /* Add item for disabling filtering. */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY)); /* Add item for freight (i.e. vehicles with cargo capacity and with no passenger capacity). */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_FREIGHT), CargoFilterCriteria::CF_FREIGHT, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_FREIGHT), CargoFilterCriteria::CF_FREIGHT)); /* Add item for vehicles not carrying anything, e.g. train engines. */ - list.push_back(std::make_unique(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false)); + list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE)); /* Add cargos */ Dimension d = GetLargestCargoIconSize(); for (const CargoSpec *cs : _sorted_cargo_specs) { if (!full && !HasBit(this->used_cargoes, cs->Index())) continue; - list.push_back(std::make_unique(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false, !HasBit(this->used_cargoes, cs->Index()))); + list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false, !HasBit(this->used_cargoes, cs->Index()))); } return list; @@ -456,23 +457,23 @@ DropDownList BaseVehicleListWindow::BuildActionDropdownList(bool show_autoreplac /* Autoreplace actions. */ if (show_autoreplace) { - list.push_back(std::make_unique(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false)); - list.push_back(std::make_unique(-1, false)); + list.push_back(MakeDropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE)); + list.push_back(MakeDropDownListDividerItem()); } /* Group actions. */ if (show_group) { - list.push_back(std::make_unique(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false)); - list.push_back(std::make_unique(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false)); - list.push_back(std::make_unique(-1, false)); + list.push_back(MakeDropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED)); + list.push_back(MakeDropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL)); + list.push_back(MakeDropDownListDividerItem()); } else if (show_create) { - list.push_back(std::make_unique(STR_VEHICLE_LIST_CREATE_GROUP, ADI_CREATE_GROUP, false)); - list.push_back(std::make_unique(-1, false)); + list.push_back(MakeDropDownListStringItem(STR_VEHICLE_LIST_CREATE_GROUP, ADI_CREATE_GROUP)); + list.push_back(MakeDropDownListDividerItem()); } /* Depot actions. */ - list.push_back(std::make_unique(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false)); - list.push_back(std::make_unique(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false)); + list.push_back(MakeDropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE)); + list.push_back(MakeDropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT)); return list; }