示例#1
0
/**
 * Handles updating the visual inventory in the user interface
 */
void UIElements::updateInventory() {
	_score.updateScore();
	updateInvList();

	// Enable scroll buttons if the player has more than four items
	if (_itemList.size() > 4) {
		_scrollLeft.setEnabled(true);
		_scrollRight.setEnabled(true);
	} else {
		_scrollLeft.setEnabled(false);
		_scrollRight.setEnabled(false);
	}

	// Handle cropping the slots start within inventory
	int lastPage  = (_itemList.size() - 1) / 4 + 1;
	if (_slotStart < 0)
		_slotStart = lastPage - 1;
	else if (_slotStart > (lastPage - 1))
		_slotStart = 0;

	// Handle refreshing slot graphics
	UIInventorySlot *slotList[4] = { &_slot1, &_slot2, &_slot3, &_slot4 };

	// Loop through the inventory objects
	SynchronizedList<InvObject *>::iterator i;
	int objIndex = 0;
	for (i = BF_INVENTORY._itemList.begin(); i != BF_INVENTORY._itemList.end(); ++i, ++objIndex) {
		InvObject *obj = *i;

		// Check whether the object is in any of the four inventory slots
		for (int slotIndex = 0; slotIndex < 4; ++slotIndex) {
			int idx = _slotStart * 4 + slotIndex;
			int objectIdx = (idx < (int)_itemList.size()) ? _itemList[idx] : 0;

			if (objectIdx == objIndex) {
				UIInventorySlot *slot = slotList[slotIndex];

				slot->_objIndex = objIndex;
				slot->_object = obj;
				slot->setVisage(obj->_visage);
				slot->setStrip(obj->_strip);
				slot->setFrame(obj->_frame);
			}
		}
	}

	// Refresh the display if necessary
	if (_active)
		draw();
}
示例#2
0
/**
 * Handles updating the visual inventory in the user interface
 */
void UIElements::updateInventory(int objectNumber) {
	switch (g_vm->getGameID()) {
	case GType_BlueForce:
		// Update the score
		_score.updateScore();
		break;
	case GType_Ringworld2:
		_character.setFrame(R2_GLOBALS._player._characterIndex);
		break;
	}

	updateInvList();

	// Enable scroll buttons if the player has more than four items
	if (_itemList.size() > 4) {
		_scrollLeft.setEnabled(true);
		_scrollRight.setEnabled(true);
	} else {
		_scrollLeft.setEnabled(false);
		_scrollRight.setEnabled(false);
	}

	// Handle cropping the slots start within inventory
	int lastPage  = (_itemList.size() - 1) / 4 + 1;
	if (_slotStart < 0)
		_slotStart = lastPage - 1;
	else if (_slotStart > (lastPage - 1))
		_slotStart = 0;

	// Handle changing the page, if necessary, to ensure an optionally supplied
	// object number will be on-screen
	if (objectNumber != 0) {
		for (uint idx = 0; idx < _itemList.size(); ++idx) {
			if (_itemList[idx] == objectNumber) {
				_slotStart = idx / 4;
				break;
			}
		}
	}

	// Handle refreshing slot graphics
	UIInventorySlot *slotList[4] = { &_slot1, &_slot2, &_slot3, &_slot4 };

	// Loop through the inventory objects
	SynchronizedList<InvObject *>::iterator i;
	int objIndex = 0;
	for (i = GLOBALS._inventory->_itemList.begin(); i != GLOBALS._inventory->_itemList.end(); ++i, ++objIndex) {
		InvObject *obj = *i;

		// Check whether the object is in any of the four inventory slots
		for (int slotIndex = 0; slotIndex < 4; ++slotIndex) {
			int idx = _slotStart * 4 + slotIndex;
			int objectIdx = (idx < (int)_itemList.size()) ? _itemList[idx] : 0;

			if (objectIdx == objIndex) {
				UIInventorySlot *slot = slotList[slotIndex];

				slot->_objIndex = objIndex;
				slot->_object = obj;
				slot->setVisage(obj->_visage);
				slot->setStrip(obj->_strip);
				slot->setFrame(obj->_frame);

				slot->reposition();
			}
		}
	}

	// Refresh the display if necessary
	if (_active)
		draw();
}