diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index db58477657..f6d819d612 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -71,7 +71,6 @@ void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type) static const StringID _start_replace_dropdown[] = { STR_REPLACE_VEHICLES_NOW, STR_REPLACE_VEHICLES_WHEN_OLD, - INVALID_STRING_ID }; /** diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 9683b59d33..023411b115 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -79,7 +79,6 @@ private: STR_SORT_BY_NUMBER, STR_SORT_BY_COST, STR_SORT_BY_MAX_SPEED, - INVALID_STRING_ID }; static const std::initializer_list sorter_funcs; diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 6c587e794b..12934979ef 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -497,7 +497,6 @@ const std::initializer_list _engine_sort_listing[] = {{ STR_SORT_BY_POWER_VS_RUNNING_COST, STR_SORT_BY_RELIABILITY, STR_SORT_BY_CARGO_CAPACITY, - INVALID_STRING_ID }, { /* Road vehicles */ STR_SORT_BY_ENGINE_ID, @@ -511,7 +510,6 @@ const std::initializer_list _engine_sort_listing[] = {{ STR_SORT_BY_POWER_VS_RUNNING_COST, STR_SORT_BY_RELIABILITY, STR_SORT_BY_CARGO_CAPACITY, - INVALID_STRING_ID }, { /* Ships */ STR_SORT_BY_ENGINE_ID, @@ -522,7 +520,6 @@ const std::initializer_list _engine_sort_listing[] = {{ STR_SORT_BY_RUNNING_COST, STR_SORT_BY_RELIABILITY, STR_SORT_BY_CARGO_CAPACITY, - INVALID_STRING_ID }, { /* Aircraft */ STR_SORT_BY_ENGINE_ID, @@ -534,7 +531,6 @@ const std::initializer_list _engine_sort_listing[] = {{ STR_SORT_BY_RELIABILITY, STR_SORT_BY_CARGO_CAPACITY, STR_SORT_BY_RANGE, - INVALID_STRING_ID }}; /** Filters vehicles by cargo and engine (in case of rail vehicle). */ diff --git a/src/dropdown.cpp b/src/dropdown.cpp index da92a0c765..2e1cd43452 100644 --- a/src/dropdown.cpp +++ b/src/dropdown.cpp @@ -431,7 +431,7 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID but * Show a dropdown menu window near a widget of the parent window. * The result code of the items is their index in the \a strings list. * @param w Parent window that wants the dropdown menu. - * @param strings Menu list, end with #INVALID_STRING_ID + * @param strings Menu list. * @param selected Index of initial selected item. * @param button Button widget number of the parent window \a w that wants the dropdown menu. * @param disabled_mask Bitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list). @@ -442,10 +442,12 @@ void ShowDropDownMenu(Window *w, std::span strings, int selected { DropDownList list; - for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) { + uint i = 0; + for (auto string : strings) { if (!HasBit(hidden_mask, i)) { - list.push_back(MakeDropDownListStringItem(strings[i], i, HasBit(disabled_mask, i))); + list.push_back(MakeDropDownListStringItem(string, i, HasBit(disabled_mask, i))); } + ++i; } if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 4ac2bbae36..cd203da979 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -373,16 +373,16 @@ static DropDownList BuildTownNameDropDown() } -static const StringID _elevations[] = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, STR_TERRAIN_TYPE_CUSTOM, INVALID_STRING_ID}; -static const StringID _sea_lakes[] = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, STR_SEA_LEVEL_CUSTOM, INVALID_STRING_ID}; -static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID}; -static const StringID _smoothness[] = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, INVALID_STRING_ID}; -static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID}; -static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID}; -static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID}; -static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID}; +static const StringID _elevations[] = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, STR_TERRAIN_TYPE_CUSTOM}; +static const StringID _sea_lakes[] = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, STR_SEA_LEVEL_CUSTOM}; +static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT}; +static const StringID _smoothness[] = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_ROUGH}; +static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE}; +static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM}; +static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM}; +static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH}; -static_assert(lengthof(_num_inds) == ID_END + 1); +static_assert(std::size(_num_inds) == ID_END); struct GenerateLandscapeWindow : public Window { WidgetID widget_id; diff --git a/src/gfx.cpp b/src/gfx.cpp index 64bfc4a807..3d652ab18d 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -865,15 +865,15 @@ Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize) /** * Get maximum width of a list of strings. - * @param list List of strings, terminated with INVALID_STRING_ID. + * @param list List of strings. * @param fontsize Font size to use. * @return Width of longest string within the list. */ uint GetStringListWidth(std::span list, FontSize fontsize) { uint width = 0; - for (const StringID *str = list.data(); *str != INVALID_STRING_ID; str++) { - width = std::max(width, GetStringBoundingBox(*str, fontsize).width); + for (auto str : list) { + width = std::max(width, GetStringBoundingBox(str, fontsize).width); } return width; } @@ -887,8 +887,8 @@ uint GetStringListWidth(std::span list, FontSize fontsize) Dimension GetStringListBoundingBox(std::span list, FontSize fontsize) { Dimension d{0, 0}; - for (const StringID *str = list.data(); *str != INVALID_STRING_ID; str++) { - d = maxdim(d, GetStringBoundingBox(*str, fontsize)); + for (auto str : list) { + d = maxdim(d, GetStringBoundingBox(str, fontsize)); } return d; } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 863789f250..35cc27d837 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1330,7 +1330,6 @@ protected: STR_SORT_BY_TYPE, STR_SORT_BY_PRODUCTION, STR_SORT_BY_TRANSPORTED, - INVALID_STRING_ID }; static const std::initializer_list sorter_funcs; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 06fb5318af..43101d1cd1 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -116,7 +116,6 @@ static const StringID _order_non_stop_drowdown[] = { STR_ORDER_GO_NON_STOP_TO, STR_ORDER_GO_VIA, STR_ORDER_GO_NON_STOP_VIA, - INVALID_STRING_ID }; static const StringID _order_full_load_drowdown[] = { @@ -125,7 +124,6 @@ static const StringID _order_full_load_drowdown[] = { STR_ORDER_DROP_FULL_LOAD_ALL, STR_ORDER_DROP_FULL_LOAD_ANY, STR_ORDER_DROP_NO_LOADING, - INVALID_STRING_ID }; static const StringID _order_unload_drowdown[] = { @@ -134,7 +132,6 @@ static const StringID _order_unload_drowdown[] = { STR_ORDER_DROP_TRANSFER, STR_EMPTY, STR_ORDER_DROP_NO_UNLOADING, - INVALID_STRING_ID }; static const StringID _order_goto_dropdown[] = { @@ -142,7 +139,6 @@ static const StringID _order_goto_dropdown[] = { STR_ORDER_GO_TO_NEAREST_DEPOT, STR_ORDER_CONDITIONAL, STR_ORDER_SHARE, - INVALID_STRING_ID }; static const StringID _order_goto_dropdown_aircraft[] = { @@ -150,7 +146,6 @@ static const StringID _order_goto_dropdown_aircraft[] = { STR_ORDER_GO_TO_NEAREST_HANGAR, STR_ORDER_CONDITIONAL, STR_ORDER_SHARE, - INVALID_STRING_ID }; /** Variables for conditional orders; this defines the order of appearance in the dropdown box */ @@ -174,7 +169,6 @@ static const StringID _order_conditional_condition[] = { STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS, STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE, STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE, - INVALID_STRING_ID, }; extern uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type); @@ -185,7 +179,6 @@ static const StringID _order_depot_action_dropdown[] = { STR_ORDER_DROP_SERVICE_DEPOT, STR_ORDER_DROP_HALT_DEPOT, STR_ORDER_DROP_UNBUNCH, - INVALID_STRING_ID }; static int DepotActionStringIndex(const Order *order) @@ -204,7 +197,6 @@ static int DepotActionStringIndex(const Order *order) static const StringID _order_refit_action_dropdown[] = { STR_ORDER_DROP_REFIT_AUTO, STR_ORDER_DROP_REFIT_AUTO_ANY, - INVALID_STRING_ID }; /** diff --git a/src/station_gui.cpp b/src/station_gui.cpp index d538fa33a2..c5de52e2e9 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -251,7 +251,6 @@ protected: STR_SORT_BY_WAITING_AVAILABLE, STR_SORT_BY_RATING_MAX, STR_SORT_BY_RATING_MIN, - INVALID_STRING_ID }; static const std::initializer_list sorter_funcs; @@ -1291,7 +1290,6 @@ struct StationViewWindow : public Window { STR_STATION_VIEW_WAITING_AMOUNT, STR_STATION_VIEW_PLANNED_STATION, STR_STATION_VIEW_PLANNED_AMOUNT, - INVALID_STRING_ID }; /** Names of the grouping options in the dropdown. */ static inline const StringID group_names[] = { @@ -1301,7 +1299,6 @@ struct StationViewWindow : public Window { STR_STATION_VIEW_GROUP_V_D_S, STR_STATION_VIEW_GROUP_D_S_V, STR_STATION_VIEW_GROUP_D_V_S, - INVALID_STRING_ID }; /** diff --git a/src/town_gui.cpp b/src/town_gui.cpp index e030111cdb..a4d9f40761 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -724,7 +724,6 @@ private: STR_SORT_BY_NAME, STR_SORT_BY_POPULATION, STR_SORT_BY_RATING, - INVALID_STRING_ID }; static const std::initializer_list sorter_funcs; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 2b7e9c00ff..e4bcdb93fd 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -108,7 +108,6 @@ const std::initializer_list BaseVehicleListWindow::vehicle_group STR_SORT_BY_LENGTH, STR_SORT_BY_LIFE_TIME, STR_SORT_BY_TIMETABLE_DELAY, - INVALID_STRING_ID }; const std::initializer_list BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock = { @@ -125,7 +124,6 @@ const std::initializer_list BaseVehicleListWindow::vehicle_group STR_SORT_BY_LENGTH, STR_SORT_BY_LIFE_TIME, STR_SORT_BY_TIMETABLE_DELAY, - INVALID_STRING_ID }; const std::initializer_list BaseVehicleListWindow::vehicle_group_shared_orders_sorter_funcs = { @@ -142,7 +140,6 @@ const std::initializer_list BaseVehicleListWindow::vehicle_group STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR, STR_SORT_BY_AVERAGE_PROFIT_THIS_YEAR, STR_SORT_BY_AVERAGE_PROFIT_LAST_YEAR, - INVALID_STRING_ID }; const std::initializer_list BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock = { @@ -151,13 +148,11 @@ const std::initializer_list BaseVehicleListWindow::vehicle_group STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD, STR_SORT_BY_AVERAGE_PROFIT_THIS_PERIOD, STR_SORT_BY_AVERAGE_PROFIT_LAST_PERIOD, - INVALID_STRING_ID }; const std::initializer_list BaseVehicleListWindow::vehicle_group_by_names = { STR_GROUP_BY_NONE, STR_GROUP_BY_SHARED_ORDERS, - INVALID_STRING_ID }; const StringID BaseVehicleListWindow::vehicle_depot_name[] = { @@ -2362,14 +2357,12 @@ static StringID _service_interval_dropdown_calendar[] = { STR_VEHICLE_DETAILS_DEFAULT, STR_VEHICLE_DETAILS_DAYS, STR_VEHICLE_DETAILS_PERCENT, - INVALID_STRING_ID, }; static StringID _service_interval_dropdown_wallclock[] = { STR_VEHICLE_DETAILS_DEFAULT, STR_VEHICLE_DETAILS_MINUTES, STR_VEHICLE_DETAILS_PERCENT, - INVALID_STRING_ID, }; /** Class for managing the vehicle details window. */