Exemplo n.º 1
0
void InventoryEquipment::reload() {
	m_slots.clear();

	const sf::Texture* tex = g_resourceManager->getTexture(ResourceID::Texture_equipmentplaceholders);

	std::vector<ItemType> types;
	types.push_back(ItemType::Equipment_weapon);
	types.push_back(ItemType::Equipment_head);
	types.push_back(ItemType::Equipment_neck);
	types.push_back(ItemType::Equipment_body);
	types.push_back(ItemType::Equipment_back);
	types.push_back(ItemType::Equipment_ring_1);
	types.push_back(ItemType::Equipment_ring_2);

	sf::Vector2i texPos(0, 0);
	float xOffset = GUIConstants::LEFT + ((WIDTH - InventorySlot::SIZE) / 2.f);
	float yOffset = GUIConstants::TOP + YOFFSET;

	for (auto& it : types) {
		if (m_core->getEquippedItem(it) == nullptr) {
			m_slots.insert({ it, InventorySlot(tex, texPos) });
		}
		else {
			m_slots.insert({ it, InventorySlot(*(m_core->getEquippedItem(it)), -1) });
		}
		texPos.x += 50;
		m_slots.at(it).setItemType(it);
		m_slots.at(it).setPosition(sf::Vector2f(xOffset, yOffset));
		yOffset += InventorySlot::SIZE + MARGIN;
	}
}
Exemplo n.º 2
0
void Creature::reloadEquipment() {
	for (int i = static_cast<int>(kInventorySlotHead); i < static_cast<int>(kInventorySlotMAX); ++i) {
		InventorySlot slot = InventorySlot(i);
		if (_info.isInventorySlotEquipped(slot))
			addItemToEquipment(_info.getEquippedItem(slot), slot);
	}
}
Exemplo n.º 3
0
void Inventory::notifyChange(const std::string& itemID) {
	if (itemID.compare("gold") == 0) {
		reloadGold();
		return;
	}
	ItemBean bean = g_databaseManager->getItemBean(itemID);
	if (bean.status != BeanStatus::Filled) return;
	if (m_typeMap.find(bean.item_type) == m_typeMap.end()) return;

	std::map<std::string, InventorySlot>* tab = m_typeMap.at(bean.item_type);

	// search for the slot
	if (tab->find(bean.item_id) != tab->end()) {
		if (m_core->getData().items.find(itemID) == m_core->getData().items.end()) {
			// the item was removed. check if it is selected.
			if (m_selectedSlotId.first.compare(bean.item_id) == 0) {
				deselectCurrentSlot();
			}
			tab->erase(bean.item_id);
			calculateSlotPositions(*(m_typeMap.at(bean.item_type)));
		}
		else {
			tab->at(bean.item_id).setAmount(m_core->getData().items.at(itemID));
		}
		return;
	}
	
	// the slot for that item has not been found. The slot is added with the current amount in the core
	if (m_core->getData().items.find(itemID) == m_core->getData().items.end()) return;

	(*tab).insert({ bean.item_id, InventorySlot(Item(itemID), m_core->getData().items.at(itemID)) });

	calculateSlotPositions(*tab);
}
Exemplo n.º 4
0
GInventory::GInventory(ACharacter* ch, GGUI& iGui, GContainerSystem *iCs)
    : GContainer(ch->Slots[IS_Bag], iGui, iCs), noBag(*mWindow) {
  character = ch;
  sf::Vector2u size = Game::Window->getSize();
  mWindow->load(Game::GuiConfFileName);
  mWindow->setPosition(20, size.y / 3);
  sf::Vector2u panelSize(size.x * 4 / 9, size.y * 2 / 3 - 40);
  mWindow->setSize(panelSize.x, panelSize.y);
  mWindow->hide();
  double contLen = panelSize.x / 2 - 40;
  objList->setSize(contLen, panelSize.y - 120);
  objList->setPosition(panelSize.x / 2 + 20, 20);
  lWeight->setPosition(panelSize.x / 2 + 20, panelSize.y - 90);
  lWeight->setSize(contLen, 30);
  freeSpace->setPosition(panelSize.x / 2 + 20, panelSize.y - 50);
  freeSpace->setSize(contLen, 30);
  noBag->setPosition(panelSize.x / 2 + 20, 20);
  noBag->setSize(contLen, 30);
  noBag->setText("no bag");

  invCells = static_cast<ItemButton::Ptr*>(operator new[](InventorySize * sizeof(ItemButton::Ptr)));
  cellLabels = static_cast<tgui::Label::Ptr*>(operator new[](InventorySize * sizeof(tgui::Label::Ptr)));
  for(int i = 0; i < InventorySize; i++) {
    new ((void*)(invCells + i)) ItemButton::Ptr(*mWindow);
    invCells[i]->Init(this, character->Slots[i], InventorySlot(i));
    invCells[i]->setSize(panelSize.x / 4 - 30, (panelSize.y - 20) * 2 / 3 / InventorySize);
    invCells[i]->setPosition(panelSize.x / 4 + 10, 10 + i*(panelSize.y - 20) / InventorySize);
    new ((void*)(cellLabels + i)) tgui::Label::Ptr(*mWindow);
    cellLabels[i]->setSize(panelSize.x / 4 - 30, (panelSize.y - 20) * 2 / 3 / InventorySize);
    cellLabels[i]->setPosition(20, 10 + i*(panelSize.y - 20) / InventorySize);
    cellLabels[i]->setText(SlotName[i]);
    cellLabels[i]->setTextSize(20);
  }
  Refresh();
}
Exemplo n.º 5
0
void Creature::loadEquipment(const Aurora::GFF3Struct &gff) {
	if (!gff.hasField("Equip_ItemList"))
		return;

	for (const auto &i : gff.getList("Equip_ItemList")) {
		InventorySlot slot = InventorySlot(static_cast<int>(std::log2f(i->getID())));
		Common::UString tag = i->getString("EquippedRes");
		equipItem(tag, slot, false);
	}
}
Exemplo n.º 6
0
void Inventory::reload() {
	// reload gold
	reloadGold();

	// reload items
	clearAllSlots();
	hideDescription();
	hideDocument();
	m_core->loadItems();
	for (auto& itemData : m_core->getData().items) {
		const Item* item = m_core->getItem(itemData.first);
		if (item == nullptr || m_typeMap.find(item->getType()) == m_typeMap.end()) continue;
		m_typeMap.at(item->getType())->insert({ item->getID(), InventorySlot(*item, itemData.second) });
	}

	calculateSlotPositions(m_consumableItems);
	calculateSlotPositions(m_equipmentItems);
	calculateSlotPositions(m_questItems);
	calculateSlotPositions(m_documentItems);
	calculateSlotPositions(m_miscItems);

	// reload equipment
	m_equipment->reload();
}