diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 94e5ac9426..f2c8d77f23 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -54,35 +54,6 @@ enum GroupListWidgets { GRP_WIDGET_REPLACE_PROTECTION, }; -enum GroupActionListFunction { - GALF_REPLACE, - GALF_SERVICE, - GALF_DEPOT, - GALF_ADD_SHARED, - GALF_REMOVE_ALL, -}; - -/** - * Update/redraw the group action dropdown - * @param w the window the dropdown belongs to - * @param gid the currently selected group in the window - */ -static void ShowGroupActionDropdown(Window *w, GroupID gid) -{ - DropDownList *list = new DropDownList(); - - list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, GALF_REPLACE, false)); - list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, GALF_SERVICE, false)); - list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT, GALF_DEPOT, false)); - - if (Group::IsValidID(gid)) { - list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, GALF_ADD_SHARED, false)); - list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, GALF_REMOVE_ALL, false)); - } - - ShowDropDownList(w, list, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN); -} - static const NWidgetPart _nested_group_widgets[] = { NWidget(NWID_HORIZONTAL), // Window header NWidget(WWT_CLOSEBOX, COLOUR_GREY), @@ -505,9 +476,11 @@ public: ShowBuildVehicleWindow(INVALID_TILE, this->vehicle_type); break; - case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: - ShowGroupActionDropdown(this, this->group_sel); + case GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN: { + DropDownList *list = this->BuildActionDropdownList(Group::IsValidID(this->group_sel)); + ShowDropDownList(this, list, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN); break; + } case GRP_WIDGET_START_ALL: case GRP_WIDGET_STOP_ALL: { // Start/stop all vehicles of the list @@ -611,24 +584,24 @@ public: assert(this->vehicles.Length() != 0); switch (index) { - case GALF_REPLACE: // Replace window + case ADI_REPLACE: // Replace window ShowReplaceGroupVehicleWindow(this->group_sel, this->vehicle_type); break; - case GALF_SERVICE: // Send for servicing + case ADI_SERVICE: // Send for servicing DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) | DEPOT_MASS_SEND | DEPOT_SERVICE, GetCmdSendToDepot(this->vehicle_type)); break; - case GALF_DEPOT: // Send to Depots + case ADI_DEPOT: // Send to Depots DoCommandP(0, this->group_sel, ((IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST) & VLW_MASK) | DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type)); break; - case GALF_ADD_SHARED: // Add shared Vehicles + case ADI_ADD_SHARED: // Add shared Vehicles assert(Group::IsValidID(this->group_sel)); DoCommandP(0, this->group_sel, this->vehicle_type, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_SHARED_VEHICLE)); break; - case GALF_REMOVE_ALL: // Remove all Vehicles from the selected group + case ADI_REMOVE_ALL: // Remove all Vehicles from the selected group assert(Group::IsValidID(this->group_sel)); DoCommandP(0, this->group_sel, this->vehicle_type, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_REMOVE_ALL_VEHICLES)); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 9fe2073206..3cfbfc9114 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -125,6 +125,27 @@ void BaseVehicleListWindow::BuildVehicleList(Owner owner, uint16 index, uint16 w this->vscroll.SetCount(this->vehicles.Length()); } +/** + * Display the Action dropdown window. + * @param show_group If true include group-related stuff. + * @return Itemlist for dropdown + */ +DropDownList *BaseVehicleListWindow::BuildActionDropdownList(bool show_group) +{ + DropDownList *list = new DropDownList(); + + 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(STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT, 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)); + } + + return list; +} + /* cached values for VehicleNameSorter to spare many GetString() calls */ static const Vehicle *_last_vehicle[2] = { NULL, NULL }; diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h index 7918cb1776..eec4661a95 100644 --- a/src/vehicle_gui_base.h +++ b/src/vehicle_gui_base.h @@ -14,6 +14,7 @@ #include "sortlist_type.h" #include "window_gui.h" +#include "widgets/dropdown_type.h" typedef GUIList GUIVehicleList; @@ -23,6 +24,14 @@ struct BaseVehicleListWindow : public Window { VehicleType vehicle_type; ///< The vehicle type that is sorted byte unitnumber_digits; ///< The number of digits of the highest unit number + enum ActionDropdownItem { + ADI_REPLACE, + ADI_SERVICE, + ADI_DEPOT, + ADI_ADD_SHARED, + ADI_REMOVE_ALL, + }; + static const StringID vehicle_sorter_names[]; static GUIVehicleList::SortFunction * const vehicle_sorter_funcs[]; @@ -34,6 +43,7 @@ struct BaseVehicleListWindow : public Window { void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const; void SortVehicleList(); void BuildVehicleList(Owner owner, uint16 index, uint16 window_type); + DropDownList *BuildActionDropdownList(bool show_group); }; uint GetVehicleListHeight(VehicleType type, uint divisor = 1);