mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: pass options to ShowDropDownMenu using a span
This commit is contained in:
parent
ad50c4f298
commit
546a996d95
|
@ -402,7 +402,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_RV_SORT_DROPDOWN:
|
case WID_RV_SORT_DROPDOWN:
|
||||||
SetDParam(0, _engine_sort_listing[this->window_number][this->sort_criteria]);
|
SetDParam(0, std::data(_engine_sort_listing[this->window_number])[this->sort_criteria]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
||||||
|
|
|
@ -484,7 +484,7 @@ EngList_SortTypeFunction * const _engine_sort_functions[][11] = {{
|
||||||
}};
|
}};
|
||||||
|
|
||||||
/** Dropdown menu strings for the vehicle sort criteria. */
|
/** Dropdown menu strings for the vehicle sort criteria. */
|
||||||
const StringID _engine_sort_listing[][12] = {{
|
const std::initializer_list<const StringID> _engine_sort_listing[] = {{
|
||||||
/* Trains */
|
/* Trains */
|
||||||
STR_SORT_BY_ENGINE_ID,
|
STR_SORT_BY_ENGINE_ID,
|
||||||
STR_SORT_BY_COST,
|
STR_SORT_BY_COST,
|
||||||
|
@ -1747,7 +1747,7 @@ struct BuildVehicleWindow : Window {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_BV_SORT_DROPDOWN:
|
case WID_BV_SORT_DROPDOWN:
|
||||||
SetDParam(0, _engine_sort_listing[this->vehicle_type][this->sort_criteria]);
|
SetDParam(0, std::data(_engine_sort_listing[this->vehicle_type])[this->sort_criteria]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_BV_CARGO_FILTER_DROPDOWN:
|
case WID_BV_CARGO_FILTER_DROPDOWN:
|
||||||
|
|
|
@ -438,7 +438,7 @@ void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID but
|
||||||
* @param hidden_mask Bitmask for hidden items (items with their bit set are not copied to the dropdown list).
|
* @param hidden_mask Bitmask for hidden items (items with their bit set are not copied to the dropdown list).
|
||||||
* @param width Minimum width of the dropdown menu.
|
* @param width Minimum width of the dropdown menu.
|
||||||
*/
|
*/
|
||||||
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
|
void ShowDropDownMenu(Window *w, std::span<const StringID> strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
|
||||||
{
|
{
|
||||||
DropDownList list;
|
DropDownList list;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "window_gui.h"
|
#include "window_gui.h"
|
||||||
|
|
||||||
/* Show drop down menu containing a fixed list of strings */
|
/* 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);
|
void ShowDropDownMenu(Window *w, std::span<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. */
|
/* Helper functions for commonly used drop down list items. */
|
||||||
std::unique_ptr<DropDownListItem> MakeDropDownListDividerItem();
|
std::unique_ptr<DropDownListItem> MakeDropDownListDividerItem();
|
||||||
|
|
|
@ -49,7 +49,7 @@ extern bool _engine_sort_direction;
|
||||||
extern uint8_t _engine_sort_last_criteria[];
|
extern uint8_t _engine_sort_last_criteria[];
|
||||||
extern bool _engine_sort_last_order[];
|
extern bool _engine_sort_last_order[];
|
||||||
extern bool _engine_sort_show_hidden_engines[];
|
extern bool _engine_sort_show_hidden_engines[];
|
||||||
extern const StringID _engine_sort_listing[][12];
|
extern const std::initializer_list<const StringID> _engine_sort_listing[];
|
||||||
extern EngList_SortTypeFunction * const _engine_sort_functions[][11];
|
extern EngList_SortTypeFunction * const _engine_sort_functions[][11];
|
||||||
|
|
||||||
/* Functions in build_vehicle_gui.cpp */
|
/* Functions in build_vehicle_gui.cpp */
|
||||||
|
|
|
@ -868,10 +868,10 @@ Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize)
|
||||||
* @param fontsize Font size to use.
|
* @param fontsize Font size to use.
|
||||||
* @return Width of longest string within the list.
|
* @return Width of longest string within the list.
|
||||||
*/
|
*/
|
||||||
uint GetStringListWidth(const StringID *list, FontSize fontsize)
|
uint GetStringListWidth(std::span<const StringID> list, FontSize fontsize)
|
||||||
{
|
{
|
||||||
uint width = 0;
|
uint width = 0;
|
||||||
for (const StringID *str = list; *str != INVALID_STRING_ID; str++) {
|
for (const StringID *str = list.data(); *str != INVALID_STRING_ID; str++) {
|
||||||
width = std::max(width, GetStringBoundingBox(*str, fontsize).width);
|
width = std::max(width, GetStringBoundingBox(*str, fontsize).width);
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
|
|
|
@ -133,7 +133,7 @@ inline void GfxFillRect(const Rect &r, int colour, FillRectMode mode = FILLRECT_
|
||||||
|
|
||||||
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize = FS_NORMAL);
|
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize = FS_NORMAL);
|
||||||
Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize = FS_NORMAL);
|
Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize = FS_NORMAL);
|
||||||
uint GetStringListWidth(const StringID *list, FontSize fontsize = FS_NORMAL);
|
uint GetStringListWidth(std::span<const StringID> list, FontSize fontsize = FS_NORMAL);
|
||||||
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize = FS_NORMAL);
|
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize = FS_NORMAL);
|
||||||
int GetStringHeight(StringID str, int maxw);
|
int GetStringHeight(StringID str, int maxw);
|
||||||
int GetStringLineCount(StringID str, int maxw);
|
int GetStringLineCount(StringID str, int maxw);
|
||||||
|
|
|
@ -588,7 +588,7 @@ public:
|
||||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
|
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
|
||||||
|
|
||||||
/* Set text of "group by" dropdown widget. */
|
/* Set text of "group by" dropdown widget. */
|
||||||
this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->widget_data = this->vehicle_group_by_names[this->grouping];
|
this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping];
|
||||||
|
|
||||||
/* Set text of "sort by" dropdown widget. */
|
/* Set text of "sort by" dropdown widget. */
|
||||||
this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
|
this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
|
||||||
|
|
|
@ -94,7 +94,7 @@ const std::initializer_list<BaseVehicleListWindow::VehicleGroupSortFunction * co
|
||||||
&VehicleIndividualToGroupSorterWrapper<VehicleTimetableDelaySorter>,
|
&VehicleIndividualToGroupSorterWrapper<VehicleTimetableDelaySorter>,
|
||||||
};
|
};
|
||||||
|
|
||||||
const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar[] = {
|
const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar = {
|
||||||
STR_SORT_BY_NUMBER,
|
STR_SORT_BY_NUMBER,
|
||||||
STR_SORT_BY_NAME,
|
STR_SORT_BY_NAME,
|
||||||
STR_SORT_BY_AGE,
|
STR_SORT_BY_AGE,
|
||||||
|
@ -111,7 +111,7 @@ const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar[]
|
||||||
INVALID_STRING_ID
|
INVALID_STRING_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock[] = {
|
const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock = {
|
||||||
STR_SORT_BY_NUMBER,
|
STR_SORT_BY_NUMBER,
|
||||||
STR_SORT_BY_NAME,
|
STR_SORT_BY_NAME,
|
||||||
STR_SORT_BY_AGE,
|
STR_SORT_BY_AGE,
|
||||||
|
@ -136,7 +136,7 @@ const std::initializer_list<BaseVehicleListWindow::VehicleGroupSortFunction * co
|
||||||
&VehicleGroupAverageProfitLastYearSorter,
|
&VehicleGroupAverageProfitLastYearSorter,
|
||||||
};
|
};
|
||||||
|
|
||||||
const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_calendar[] = {
|
const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_calendar = {
|
||||||
STR_SORT_BY_NUM_VEHICLES,
|
STR_SORT_BY_NUM_VEHICLES,
|
||||||
STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR,
|
STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR,
|
||||||
STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR,
|
STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR,
|
||||||
|
@ -145,7 +145,7 @@ const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_c
|
||||||
INVALID_STRING_ID
|
INVALID_STRING_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock[] = {
|
const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock = {
|
||||||
STR_SORT_BY_NUM_VEHICLES,
|
STR_SORT_BY_NUM_VEHICLES,
|
||||||
STR_SORT_BY_TOTAL_PROFIT_THIS_PERIOD,
|
STR_SORT_BY_TOTAL_PROFIT_THIS_PERIOD,
|
||||||
STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD,
|
STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD,
|
||||||
|
@ -154,7 +154,7 @@ const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_w
|
||||||
INVALID_STRING_ID
|
INVALID_STRING_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
const StringID BaseVehicleListWindow::vehicle_group_by_names[] = {
|
const std::initializer_list<const StringID> BaseVehicleListWindow::vehicle_group_by_names = {
|
||||||
STR_GROUP_BY_NONE,
|
STR_GROUP_BY_NONE,
|
||||||
STR_GROUP_BY_SHARED_ORDERS,
|
STR_GROUP_BY_SHARED_ORDERS,
|
||||||
INVALID_STRING_ID
|
INVALID_STRING_ID
|
||||||
|
@ -174,7 +174,7 @@ BaseVehicleListWindow::BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno)
|
||||||
this->UpdateSortingFromGrouping();
|
this->UpdateSortingFromGrouping();
|
||||||
}
|
}
|
||||||
|
|
||||||
const StringID *BaseVehicleListWindow::GetVehicleSorterNames()
|
std::span<const StringID> BaseVehicleListWindow::GetVehicleSorterNames()
|
||||||
{
|
{
|
||||||
switch (this->grouping) {
|
switch (this->grouping) {
|
||||||
case GB_NONE:
|
case GB_NONE:
|
||||||
|
@ -2048,7 +2048,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set text of group by dropdown widget. */
|
/* Set text of group by dropdown widget. */
|
||||||
this->GetWidget<NWidgetCore>(WID_VL_GROUP_BY_PULLDOWN)->widget_data = this->vehicle_group_by_names[this->grouping];
|
this->GetWidget<NWidgetCore>(WID_VL_GROUP_BY_PULLDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping];
|
||||||
|
|
||||||
/* Set text of sort by dropdown widget. */
|
/* Set text of sort by dropdown widget. */
|
||||||
this->GetWidget<NWidgetCore>(WID_VL_SORT_BY_PULLDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
|
this->GetWidget<NWidgetCore>(WID_VL_SORT_BY_PULLDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
|
||||||
|
|
|
@ -98,11 +98,11 @@ struct BaseVehicleListWindow : public Window {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const StringID vehicle_depot_name[];
|
static const StringID vehicle_depot_name[];
|
||||||
static const StringID vehicle_group_by_names[];
|
static const std::initializer_list<const StringID> vehicle_group_by_names;
|
||||||
static const StringID vehicle_group_none_sorter_names_calendar[];
|
static const std::initializer_list<const StringID> vehicle_group_none_sorter_names_calendar;
|
||||||
static const StringID vehicle_group_none_sorter_names_wallclock[];
|
static const std::initializer_list<const StringID> vehicle_group_none_sorter_names_wallclock;
|
||||||
static const StringID vehicle_group_shared_orders_sorter_names_calendar[];
|
static const std::initializer_list<const StringID> vehicle_group_shared_orders_sorter_names_calendar;
|
||||||
static const StringID vehicle_group_shared_orders_sorter_names_wallclock[];
|
static const std::initializer_list<const StringID> vehicle_group_shared_orders_sorter_names_wallclock;
|
||||||
static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_none_sorter_funcs;
|
static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_none_sorter_funcs;
|
||||||
static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_shared_orders_sorter_funcs;
|
static const std::initializer_list<VehicleGroupSortFunction * const> vehicle_group_shared_orders_sorter_funcs;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ struct BaseVehicleListWindow : public Window {
|
||||||
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create);
|
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create);
|
||||||
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create);
|
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create);
|
||||||
|
|
||||||
const StringID *GetVehicleSorterNames();
|
std::span<const StringID> GetVehicleSorterNames();
|
||||||
|
|
||||||
std::span<VehicleGroupSortFunction * const> GetVehicleSorterFuncs()
|
std::span<VehicleGroupSortFunction * const> GetVehicleSorterFuncs()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue