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

Method OnClick

src/vehicle_gui.cpp:1234–1274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1232 }
1233
1234 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1235 {
1236 switch (widget) {
1237 case WID_VR_VEHICLE_PANEL_DISPLAY: { // Vehicle image.
1238 if (this->order != INVALID_VEH_ORDER_ID) break;
1239 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_VR_VEHICLE_PANEL_DISPLAY);
1240 this->click_x = GetClickPosition(pt.x - nwi->pos_x);
1241 this->SetSelectedVehicles(pt.x - nwi->pos_x);
1242 this->SetWidgetDirty(WID_VR_VEHICLE_PANEL_DISPLAY);
1243 if (!_ctrl_pressed) {
1244 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1245 } else {
1246 /* The vehicle selection has changed. */
1247 this->InvalidateData(2);
1248 }
1249 break;
1250 }
1251
1252 case WID_VR_MATRIX: { // listbox
1253 this->SetSelection(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_VR_MATRIX));
1254 this->SetWidgetDisabledState(WID_VR_REFIT, this->selected_refit == nullptr);
1255 this->InvalidateData(1);
1256
1257 if (click_count == 1) break;
1258 [[fallthrough]];
1259 }
1260
1261 case WID_VR_REFIT: // refit button
1262 if (this->selected_refit != nullptr) {
1263 const Vehicle *v = Vehicle::Get(this->window_number);
1264
1265 if (this->order == INVALID_VEH_ORDER_ID) {
1266 bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
1267 if (Command<CMD_REFIT_VEHICLE>::Post(GetCmdRefitVehMsg(v), v->tile, this->selected_vehicle, this->selected_refit->cargo, this->selected_refit->subtype, false, false, this->num_vehicles) && delete_window) this->Close();
1268 } else {
1269 if (Command<CMD_ORDER_REFIT>::Post(v->tile, v->index, this->order, this->selected_refit->cargo)) this->Close();
1270 }
1271 }
1272 break;
1273 }
1274 }
1275
1276 void OnMouseDrag(Point pt, WidgetID widget) override
1277 {

Callers

nothing calls this directly

Calls 10

SetSelectedVehiclesMethod · 0.95
SetSelectionMethod · 0.95
SetObjectToPlaceWndFunction · 0.85
GetCmdRefitVehMsgFunction · 0.85
SetWidgetDirtyMethod · 0.80
InvalidateDataMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected