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

Method OnClick

src/order_gui.cpp:1162–1320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1160 }
1161
1162 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1163 {
1164 switch (widget) {
1165 case WID_O_ORDER_LIST: {
1166 if (this->goto_type == OPOS_CONDITIONAL) {
1167 VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1168 if (order_id != INVALID_VEH_ORDER_ID) {
1169 Order order{};
1170 order.MakeConditional(order_id);
1171
1172 Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
1173 }
1174 ResetObjectToPlace();
1175 break;
1176 }
1177
1178 VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1179
1180 if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1181 TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1182 if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1183 return;
1184 }
1185
1186 /* This order won't be selected any more, close all child windows and dropdowns */
1187 this->CloseChildWindows();
1188
1189 if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1190 /* Deselect clicked order */
1191 this->selected_order = -1;
1192 } else if (sel == this->selected_order && click_count > 1) {
1193 if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1194 Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
1195 this->vehicle->tile, this->vehicle->index, sel,
1196 MOF_STOP_LOCATION, (to_underlying(this->vehicle->GetOrder(sel)->GetStopLocation()) + 1) % to_underlying(OrderStopLocation::End));
1197 }
1198 } else {
1199 /* Select clicked order */
1200 this->selected_order = sel;
1201
1202 if (this->vehicle->owner == _local_company) {
1203 /* Activate drag and drop */
1204 SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1205 }
1206 }
1207
1208 this->UpdateButtonState();
1209 break;
1210 }
1211
1212 case WID_O_SKIP:
1213 this->OrderClick_Skip();
1214 break;
1215
1216 case WID_O_DELETE:
1217 this->OrderClick_Delete();
1218 break;
1219

Callers

nothing calls this directly

Calls 15

GetOrderFromPtMethod · 0.95
OrderGetSelMethod · 0.95
UpdateButtonStateMethod · 0.95
OrderClick_SkipMethod · 0.95
OrderClick_DeleteMethod · 0.95
OrderClick_NonstopMethod · 0.95
OrderClick_GotoMethod · 0.95
OrderClick_FullLoadMethod · 0.95
OrderClick_UnloadMethod · 0.95
OrderClick_RefitMethod · 0.95
ResetObjectToPlaceFunction · 0.85

Tested by

no test coverage detected