mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r20169) -Codechange: Replace ShowGroupActionDropdown() with BaseVehicleListWindow::BuildActionDropdownList().
This commit is contained in:
parent
c5665202e1
commit
c79d4f46a3
|
@ -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));
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "sortlist_type.h"
|
||||
#include "window_gui.h"
|
||||
#include "widgets/dropdown_type.h"
|
||||
|
||||
typedef GUIList<const Vehicle*> 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);
|
||||
|
|
Loading…
Reference in New Issue