MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / mouseClick

Method mouseClick

src/Battlescape/Inventory.cpp:455–742  ·  view source on GitHub ↗

* Picks up / drops an item. * @param action Pointer to an action. * @param state State that the action handlers belong to. */

Source from the content-addressed store, hash-verified

453 * @param state State that the action handlers belong to.
454 */
455void Inventory::mouseClick(Action *action, State *state)
456{
457 if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
458 {
459 if (_selUnit == 0)
460 return;
461 // Pickup item
462 if (_selItem == 0)
463 {
464 int x = (int)floor(action->getAbsoluteXMouse()) - getX(),
465 y = (int)floor(action->getAbsoluteYMouse()) - getY();
466 RuleInventory *slot = getSlotInPosition(&x, &y);
467 if (slot != 0)
468 {
469 if (slot->getType() == INV_GROUND)
470 {
471 x += _groundOffset;
472 }
473 BattleItem *item = _selUnit->getItem(slot, x, y);
474 if (item != 0)
475 {
476 if ((SDL_GetModState() & KMOD_CTRL))
477 {
478 RuleInventory *newSlot = _game->getRuleset()->getInventory("STR_GROUND");
479 std::string warning = "STR_NOT_ENOUGH_SPACE";
480 bool placed = false;
481
482 if (slot->getType() == INV_GROUND)
483 {
484 switch (item->getRules()->getBattleType())
485 {
486 case BT_FIREARM:
487 newSlot = _game->getRuleset()->getInventory("STR_RIGHT_HAND");
488 break;
489 case BT_MINDPROBE:
490 case BT_PSIAMP:
491 case BT_MELEE:
492 case BT_CORPSE:
493 newSlot = _game->getRuleset()->getInventory("STR_LEFT_HAND");
494 break;
495 default:
496 if (item->getRules()->getInventoryHeight() > 2)
497 {
498 newSlot = _game->getRuleset()->getInventory("STR_BACK_PACK");
499 }
500 else
501 {
502 newSlot = _game->getRuleset()->getInventory("STR_BELT");
503 }
504 break;
505 }
506 }
507
508 if (newSlot->getType() != INV_GROUND)
509 {
510 _stackLevel[item->getSlotX()][item->getSlotY()] -= 1;
511
512 placed = fitItem(newSlot, item, warning);

Callers

nothing calls this directly

Calls 15

getDetailsMethod · 0.80
getAbsoluteXMouseMethod · 0.80
getAbsoluteYMouseMethod · 0.80
getBattleTypeMethod · 0.80
getInventoryHeightMethod · 0.80
getInventoriesMethod · 0.80
spendTimeUnitsMethod · 0.80
showMessageMethod · 0.80
getLanguageMethod · 0.80
getInventoryWidthMethod · 0.80
fitItemInSlotMethod · 0.80
getCompatibleAmmoMethod · 0.80

Tested by

no test coverage detected