| 506 | } |
| 507 | |
| 508 | void AgentAssignment::addVehiclesToList(sp<MultilistBox> list, const int listOffset) |
| 509 | { |
| 510 | const int offset = 20; |
| 511 | for (auto &v : vehicles) |
| 512 | { |
| 513 | auto vehicleControl = ControlGenerator::createVehicleAssignmentControl(*state, v); |
| 514 | vehicleControl->setFuncPreRender(funcVehicleUpdate); |
| 515 | vehicleControl->Size.x -= listOffset; |
| 516 | vehicleControl->SelectionSize.x -= listOffset; |
| 517 | // MouseUp - drop dragged list |
| 518 | vehicleControl->addCallback( |
| 519 | FormEventType::MouseUp, |
| 520 | [vehicleControl, this](FormsEvent *e) |
| 521 | { |
| 522 | if (!isDragged || e->forms().RaisedBy == sourceRaisedBy) |
| 523 | return; |
| 524 | |
| 525 | isDragged = false; |
| 526 | draggedList->setVisible(false); |
| 527 | |
| 528 | auto vehicle = vehicleControl->getData<Vehicle>(); |
| 529 | bool success = false; |
| 530 | for (auto &agentControl : draggedList->Controls) |
| 531 | { |
| 532 | auto agent = agentControl->getData<Agent>(); |
| 533 | auto currentBuilding = agent->currentVehicle |
| 534 | ? agent->currentVehicle->currentBuilding |
| 535 | : agent->currentBuilding; |
| 536 | success = vehicle->currentBuilding == currentBuilding && |
| 537 | agent->currentVehicle != vehicle; |
| 538 | if (!success) |
| 539 | break; |
| 540 | agent->enterVehicle(*state, {state.get(), vehicle}); |
| 541 | } |
| 542 | |
| 543 | if (success) |
| 544 | { |
| 545 | vehicleControl->findControl(AGENT_LIST_NAME)->setDirty(); |
| 546 | sourceRaisedBy->clearSelection(); |
| 547 | } |
| 548 | }); |
| 549 | list->addItem(vehicleControl); |
| 550 | |
| 551 | auto agentRightList = vehicleControl->createChild<MultilistBox>(); |
| 552 | agentRightList->Name = AGENT_LIST_NAME; |
| 553 | agentRightList->Location.x = offset; |
| 554 | agentRightList->Location.y = vehicleControl->SelectionSize.y + list->ItemSpacing; |
| 555 | agentRightList->ItemSpacing = list->ItemSpacing; |
| 556 | // set visibility filter |
| 557 | agentRightList->setFuncIsVisibleItem( |
| 558 | [](sp<Control> c) |
| 559 | { |
| 560 | auto agent = c->getData<Agent>(); |
| 561 | bool visible = |
| 562 | agent->currentVehicle == c->getParent()->getParent()->getData<Vehicle>(); |
| 563 | c->setVisible(visible); |
| 564 | return visible; |
| 565 | }); |
nothing calls this directly
no test coverage detected