コード例 #1
0
/**
 * Moves all the items to the base on right-click.
 * @param action Pointer to an action.
 */
void CraftEquipmentState::lstEquipmentLeftArrowClick(Action *action)
{
	if (action->getDetails()->button.button == SDL_BUTTON_RIGHT) moveLeftByValue(INT_MAX);
	if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
	{
		moveLeftByValue(1);
		_timerRight->setInterval(250);
		_timerLeft->setInterval(250);
	}
}
コード例 #2
0
/**
 * Empties the contents of the craft, moving all of the items back to the base.
 */
void CraftEquipmentState::btnClearClick(Action *)
{
	for (_sel = 0; _sel != _items.size(); ++_sel)
	{
		moveLeftByValue(INT_MAX);
	}
}
コード例 #3
0
ファイル: CraftEquipmentState.cpp プロジェクト: 2xG/OpenXcom
/**
 * 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);
		}
	}
}
コード例 #4
0
/**
 * Moves the selected item to the base.
 */
void CraftEquipmentState::moveLeft()
{
	_timerLeft->setInterval(50);
	_timerRight->setInterval(50);
	moveLeftByValue(1);
}
コード例 #5
0
ファイル: CraftEquipmentState.cpp プロジェクト: 2xG/OpenXcom
/**
 * Moves the given number of items (selected) to the craft.
 * @param change Item difference.
 */
void CraftEquipmentState::moveRightByValue(int change)
{
	Craft *c = _base->getCrafts()->at(_craft);
	RuleItem *item = _game->getRuleset()->getItem(_items[_sel]);
	int bqty = _base->getItems()->getItem(_items[_sel]);
	if (_game->getSavedGame()->getMonthsPassed() == -1)
	{
		if (change == INT_MAX)
		{
			change = 10;
		}
		bqty = change;
	}
	if (0 >= change || 0 >= bqty) return;
	change = std::min(bqty, change);
	// Do we need to convert item to vehicle?
	if (item->isFixed())
	{
		// Check if there's enough room
		int room = std::min(c->getRules()->getVehicles() - c->getNumVehicles(), c->getSpaceAvailable() / 4);
		if (room > 0)
		{
			change = std::min(room, change);
			if(item->getClipSize() != -1)
			{
				// We want to redistribute all the available ammo among the vehicles,
				// so first we note the total number of vehicles we want in the craft
				int oldVehiclesCount = c->getVehicleCount(_items[_sel]);
				int newVehiclesCount = oldVehiclesCount + change;
				// ...and we move back all of this vehicle-type to the base.
				if (0 < oldVehiclesCount) moveLeftByValue(INT_MAX);
				// And now let's see if we can add the total number of vehicles.
				RuleItem *ammo = _game->getRuleset()->getItem(item->getCompatibleAmmo()->front());
				int baqty = _base->getItems()->getItem(ammo->getType()); // Ammo Quantity for this vehicle-type on the base
				int canBeAdded = std::min(newVehiclesCount, baqty);
				if (canBeAdded > 0)
				{
					int newAmmoPerVehicle = std::min(baqty / canBeAdded, ammo->getClipSize());;
					int remainder = 0;
					if (ammo->getClipSize() > newAmmoPerVehicle) remainder = baqty - (canBeAdded * newAmmoPerVehicle);
					int newAmmo;
					for (int i=0; i < canBeAdded; ++i)
					{
						newAmmo = newAmmoPerVehicle;
						if (i<remainder) ++newAmmo;
						c->getVehicles()->push_back(new Vehicle(item, newAmmo));
						if (_game->getSavedGame()->getMonthsPassed() != -1)
						{
							_base->getItems()->removeItem(ammo->getType(), newAmmo);
							_base->getItems()->removeItem(_items[_sel]);
						}
					}
				}
				if (oldVehiclesCount >= canBeAdded)
				{
					// So we haven't managed to increase the count of vehicles because of the ammo
					_timerRight->stop();
					LocalizedText msg(tr("STR_NOT_ENOUGH_AMMO_TO_ARM_HWP").arg(tr(ammo->getType())));
					_game->pushState(new ErrorMessageState(_game, msg, Palette::blockOffset(15)+1, "BACK04.SCR", 2));
				}
			}
			else
				for (int i=0; i < change; ++i)
				{
					c->getVehicles()->push_back(new Vehicle(item, 255));
						if (_game->getSavedGame()->getMonthsPassed() != -1)
						{
							_base->getItems()->removeItem(_items[_sel]);
						}
				}
		}
	}
	else
	{
		c->getItems()->addItem(_items[_sel],change);
		if (_game->getSavedGame()->getMonthsPassed() == -1)
		{
				Options::setInt("NewBattle_" + _items[_sel], Options::getInt("NewBattle_" + _items[_sel]) + change);
		}
		else
		{
			_base->getItems()->removeItem(_items[_sel],change);
		}
	}
	updateQuantity();
}