MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / OnDragDrop_Vehicle

Method OnDragDrop_Vehicle

src/group_gui.cpp:946–1010  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

944 }
945
946 void OnDragDrop_Vehicle(Point pt, WidgetID widget)
947 {
948 switch (widget) {
949 case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles
950 Command<CMD_ADD_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE, DEFAULT_GROUP, this->vehicle_sel, _ctrl_pressed || this->grouping == GB_SHARED_ORDERS, VehicleListIdentifier{});
951
952 this->vehicle_sel = VehicleID::Invalid();
953 this->group_over = GroupID::Invalid();
954
955 this->SetDirty();
956 break;
957
958 case WID_GL_LIST_GROUP: { // Matrix group
959 const VehicleID vindex = this->vehicle_sel;
960 this->vehicle_sel = VehicleID::Invalid();
961 this->group_over = GroupID::Invalid();
962 this->SetDirty();
963
964 auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP);
965 GroupID new_g = it == this->groups.end() ? NEW_GROUP : it->group->index;
966
967 Command<CMD_ADD_VEHICLE_GROUP>::Post(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE, new_g == NEW_GROUP ? CcAddVehicleNewGroup : nullptr, new_g, vindex, _ctrl_pressed || this->grouping == GB_SHARED_ORDERS, VehicleListIdentifier{});
968 break;
969 }
970
971 case WID_GL_LIST_VEHICLE: { // Matrix vehicle
972 const VehicleID vindex = this->vehicle_sel;
973 this->vehicle_sel = VehicleID::Invalid();
974 this->group_over = GroupID::Invalid();
975 this->SetDirty();
976
977 auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE);
978 if (it == this->vehgroups.end()) return; // click out of list bound
979
980 const GUIVehicleGroup &vehgroup = *it;
981 switch (this->grouping) {
982 case GB_NONE: {
983 const Vehicle *v = vehgroup.GetSingleVehicle();
984 if (!VehicleClicked(v) && vindex == v->index) {
985 ShowVehicleViewWindow(v);
986 }
987 break;
988 }
989
990 case GB_SHARED_ORDERS: {
991 if (!VehicleClicked(vehgroup)) {
992 const Vehicle *v = vehgroup.vehicles_begin[0];
993 if (vindex == v->index) {
994 if (vehgroup.NumVehicles() == 1) {
995 ShowVehicleViewWindow(v);
996 } else {
997 ShowVehicleListWindow(v);
998 }
999 }
1000 }
1001 break;
1002 }
1003

Callers

nothing calls this directly

Calls 10

InvalidFunction · 0.85
VehicleClickedFunction · 0.85
ShowVehicleViewWindowFunction · 0.85
ShowVehicleListWindowFunction · 0.85
NOT_REACHEDFunction · 0.85
GetSingleVehicleMethod · 0.80
NumVehiclesMethod · 0.80
SetDirtyMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected