| 565 | } |
| 566 | |
| 567 | void AEquipScreen::handleItemPlacement(Vec2<int> mousePos) |
| 568 | { |
| 569 | // Expecting to have an agent |
| 570 | auto currentAgent = selectedAgents.front(); |
| 571 | |
| 572 | // Are we over the grid? If so try to place it on the agent. |
| 573 | auto paperDollControl = paperDoll; |
| 574 | Vec2<int> equipOffset = paperDollControl->Location + formMain->Location; |
| 575 | Vec2<int> equipmentPos = mousePos + draggedEquipmentOffset; |
| 576 | // If this is within the grid try to snap it |
| 577 | Vec2<int> equipmentGridPos = equipmentPos - equipOffset; |
| 578 | equipmentGridPos /= EQUIP_GRID_SLOT_SIZE; |
| 579 | |
| 580 | auto draggedFrom = draggedEquipmentOrigin; |
| 581 | auto draggedType = |
| 582 | (draggedFrom.x == -1 && draggedFrom.y == -1) ? draggedEquipment->type : nullptr; |
| 583 | auto draggedAlternative = draggedEquipmentAlternativePickup; |
| 584 | |
| 585 | bool insufficientTU = false; |
| 586 | bool alienArtifact = false; |
| 587 | if (tryPlaceItem(currentAgent, equipmentGridPos, &insufficientTU, &alienArtifact)) |
| 588 | { |
| 589 | displayAgent(currentAgent); |
| 590 | updateAgentControl(currentAgent); |
| 591 | this->paperDoll->updateEquipment(); |
| 592 | } |
| 593 | else |
| 594 | { |
| 595 | refreshInventoryItems(); |
| 596 | } |
| 597 | if (insufficientTU) |
| 598 | { |
| 599 | auto message_box = mksp<MessageBox>( |
| 600 | tr("NOT ENOUGH TU'S"), |
| 601 | format("%s %d", tr("TU cost per item picked up:"), currentAgent->unit->getPickupCost()), |
| 602 | MessageBox::ButtonOptions::Ok); |
| 603 | fw().stageQueueCommand({StageCmd::Command::PUSH, message_box}); |
| 604 | } |
| 605 | else if (alienArtifact) |
| 606 | { |
| 607 | auto message_box = mksp<MessageBox>( |
| 608 | tr("Alien Artifact"), tr("You must research Alien technology before you can use it."), |
| 609 | MessageBox::ButtonOptions::Ok); |
| 610 | fw().stageQueueCommand({StageCmd::Command::PUSH, message_box}); |
| 611 | } |
| 612 | // Other agents |
| 613 | for (auto &agent : selectedAgents) |
| 614 | { |
| 615 | if (agent == currentAgent) |
| 616 | { |
| 617 | continue; |
| 618 | } |
| 619 | bool pickedUp = draggedType ? tryPickUpItem(*draggedType) |
| 620 | : tryPickUpItem(agent, draggedFrom, draggedAlternative); |
| 621 | if (!pickedUp) |
| 622 | { |
| 623 | continue; |
| 624 | } |
nothing calls this directly
no test coverage detected