/** * Moves all the items (as much as possible) to the craft on right-click. * @param action Pointer to an action. */ void CraftEquipmentState::lstEquipmentRightArrowClick(Action *action) { if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) moveRightByValue(INT_MAX); if (action->getDetails()->button.button == SDL_BUTTON_LEFT) { moveRightByValue(1); _timerRight->setInterval(250); _timerLeft->setInterval(250); } }
/** * Handles the mouse-wheels on the arrow-buttons. * @param action Pointer to an action. */ void CraftEquipmentState::lstEquipmentMousePress(Action *action) { _sel = _lstEquipment->getSelectedRow(); if (action->getDetails()->button.button == SDL_BUTTON_WHEELUP) { _timerRight->stop(); _timerLeft->stop(); if (_allowChangeListValuesByMouseWheel && action->getAbsoluteXMouse() >= _lstEquipment->getArrowsLeftEdge() && action->getAbsoluteXMouse() <= _lstEquipment->getArrowsRightEdge()) { moveRightByValue(_changeValueByMouseWheel); } } else if (action->getDetails()->button.button == SDL_BUTTON_WHEELDOWN) { _timerRight->stop(); _timerLeft->stop(); if (_allowChangeListValuesByMouseWheel && action->getAbsoluteXMouse() >= _lstEquipment->getArrowsLeftEdge() && action->getAbsoluteXMouse() <= _lstEquipment->getArrowsRightEdge()) { moveLeftByValue(_changeValueByMouseWheel); } } }
/** * Moves the selected item to the craft. */ void CraftEquipmentState::moveRight() { _timerLeft->setInterval(50); _timerRight->setInterval(50); moveRightByValue(1); }
/** * Moves the given number of items (selected) to the base. * @param change Item difference. */ void CraftEquipmentState::moveLeftByValue(int change) { Craft *c = _base->getCrafts()->at(_craft); RuleItem *item = _game->getMod()->getItem(_items[_sel]); int cQty = 0; if (item->isFixed()) cQty = c->getVehicleCount(_items[_sel]); else cQty = c->getItems()->getItem(_items[_sel]); if (change <= 0 || cQty <= 0) return; change = std::min(cQty, change); // Convert vehicle to item if (item->isFixed()) { if (!item->getCompatibleAmmo()->empty()) { // First we remove all vehicles because we want to redistribute the ammo RuleItem *ammo = _game->getMod()->getItem(item->getCompatibleAmmo()->front()); for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { _base->getStorageItems()->addItem(ammo->getType(), (*i)->getAmmo()); delete (*i); i = c->getVehicles()->erase(i); } else ++i; } if (_game->getSavedGame()->getMonthsPassed() != -1) { _base->getStorageItems()->addItem(_items[_sel], cQty); } // And now reAdd the count we want to keep in the craft (and redistribute the ammo among them) if (cQty > change) moveRightByValue(cQty - change); } else { if (_game->getSavedGame()->getMonthsPassed() != -1) { _base->getStorageItems()->addItem(_items[_sel], change); } for (std::vector<Vehicle*>::iterator i = c->getVehicles()->begin(); i != c->getVehicles()->end(); ) { if ((*i)->getRules() == item) { delete (*i); i = c->getVehicles()->erase(i); if (0 >= --change) break; } else ++i; } } } else { c->getItems()->removeItem(_items[_sel], change); _totalItems -= change; if (_game->getSavedGame()->getMonthsPassed() > -1) { _base->getStorageItems()->addItem(_items[_sel], change); } } updateQuantity(); }