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

Method OnDragDrop

src/depot_gui.cpp:1070–1121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1068 }
1069
1070 void OnDragDrop(Point pt, WidgetID widget) override
1071 {
1072 switch (widget) {
1073 case WID_D_MATRIX: {
1074 const Vehicle *v = nullptr;
1075 VehicleID sel = this->sel;
1076
1077 this->sel = VehicleID::Invalid();
1078 this->SetDirty();
1079
1080 if (this->type == VEH_TRAIN) {
1081 GetDepotVehiclePtData gdvp = { nullptr, nullptr };
1082
1083 if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != VehicleID::Invalid()) {
1084 if (gdvp.wagon != nullptr && gdvp.wagon->index == sel && _ctrl_pressed) {
1085 Command<CMD_REVERSE_TRAIN_DIRECTION>::Post(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true);
1086 } else if (gdvp.wagon == nullptr || gdvp.wagon->index != sel) {
1087 this->vehicle_over = VehicleID::Invalid();
1088 TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
1089 } else if (gdvp.head != nullptr && gdvp.head->IsFrontEngine()) {
1090 ShowVehicleViewWindow(gdvp.head);
1091 }
1092 }
1093 } else if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, nullptr) == MODE_DRAG_VEHICLE && v != nullptr && sel == v->index) {
1094 ShowVehicleViewWindow(v);
1095 }
1096 break;
1097 }
1098
1099 case WID_D_SELL: case WID_D_SELL_CHAIN: {
1100 if (this->IsWidgetDisabled(widget)) return;
1101 if (this->sel == VehicleID::Invalid()) return;
1102
1103 this->HandleButtonClick(widget);
1104
1105 const Vehicle *v = Vehicle::Get(this->sel);
1106 this->sel = VehicleID::Invalid();
1107 this->SetDirty();
1108
1109 bool sell_cmd = (v->type == VEH_TRAIN && (widget == WID_D_SELL_CHAIN || _ctrl_pressed));
1110 Command<CMD_SELL_VEHICLE>::Post(GetCmdSellVehMsg(v->type), v->tile, v->index, sell_cmd, true, INVALID_CLIENT_ID);
1111 break;
1112 }
1113
1114 default:
1115 this->sel = VehicleID::Invalid();
1116 this->SetDirty();
1117 break;
1118 }
1119 this->hovered_widget = INVALID_WIDGET;
1120 _cursor.vehchain = false;
1121 }
1122
1123 void OnTimeout() override
1124 {

Callers

nothing calls this directly

Calls 9

InvalidFunction · 0.85
TrainDepotMoveVehicleFunction · 0.85
ShowVehicleViewWindowFunction · 0.85
GetCmdSellVehMsgFunction · 0.85
IsFrontEngineMethod · 0.80
IsWidgetDisabledMethod · 0.80
HandleButtonClickMethod · 0.80
SetDirtyMethod · 0.45

Tested by

no test coverage detected