Example #1
0
void Spellbook::calculateSpellSlots() {
	float yOffset = GUIConstants::TOP + SPELL_OFFSET;
	float xOffset = GUIConstants::LEFT + GUIConstants::TEXT_OFFSET / 2.f + SpellSlot::ICON_OFFSET;

	for (auto& it : m_core->getData().spellsLearned) {
		for (auto& it2 : it.second) {
			SpellSlot slot = SpellSlot(it2);
			slot.setPosition(sf::Vector2f(xOffset, yOffset));

			BitmapText text;
			text.setCharacterSize(GUIConstants::CHARACTER_SIZE_M);
			text.setColor(COLOR_WHITE);
			text.setString(g_textProvider->getText(EnumNames::getSpellIDName(it2)));
			text.setPosition(sf::Vector2f(xOffset + SpellSlot::ICON_SIZE + SpellSlot::ICON_OFFSET + MARGIN, yOffset));

			BitmapText textDesc;
			textDesc.setCharacterSize(GUIConstants::CHARACTER_SIZE_S);
			textDesc.setColor(COLOR_LIGHT_GREY);
			textDesc.setString(g_textProvider->getCroppedText(
				EnumNames::getSpellIDName(it2) + "Desc", GUIConstants::CHARACTER_SIZE_S,
				static_cast<int>(WIDTH - (SpellSlot::SIZE + 4 * MARGIN))));
			textDesc.setPosition(sf::Vector2f(xOffset + SpellSlot::ICON_SIZE + SpellSlot::ICON_OFFSET + MARGIN, yOffset + GUIConstants::CHARACTER_SIZE_M + 4.f));

			std::pair<BitmapText, BitmapText> texts = std::pair<BitmapText, BitmapText>(text, textDesc);
			m_typeMap.at(it.first)->push_back(std::pair<SpellSlot, std::pair<BitmapText, BitmapText>>(slot, texts));
			yOffset += SpellSlot::SIZE + MARGIN;
		}

		yOffset = GUIConstants::TOP + SPELL_OFFSET;
	}
}
Example #2
0
void WeaponWindow::reload()
{
	m_requireReload = false;
	// reload slot and text
	delete m_weaponSlot;
	m_weapon = m_core->getWeapon();
	if (m_weapon == nullptr)
	{
		m_weaponSlot = new InventorySlot(g_resourceManager->getTexture(ResourceID::Texture_equipmentplaceholders), sf::Vector2i(0, 0));
		m_weaponName.setString(g_textProvider->getText("NoWeapon"));
		m_weaponDescription.setString("");
	}
	else
	{
		m_weaponSlot = new InventorySlot(*m_weapon, -1);
		m_weaponName.setString(g_textProvider->getText(m_weapon->getID()));
		m_weaponDescription.setString(g_textProvider->getCroppedText(m_weapon->getDescription(), GUIConstants::CHARACTER_SIZE_M,
			static_cast<int>(WIDTH - (GUIConstants::TEXT_OFFSET + 2 * MARGIN + InventorySlot::SIDE_LENGTH))));
	}
	m_weaponSlot->setPosition(sf::Vector2f(LEFT + GUIConstants::TEXT_OFFSET, TOP + GUIConstants::TEXT_OFFSET));

	clearAllSlots();

	if (m_weapon == nullptr) return;

	float xOffset = LEFT + GUIConstants::TEXT_OFFSET;
	float yOffset = m_weaponSlot->getPosition().y + 2 * InventorySlot::SIDE_LENGTH;
	int slotNr = 0;
	for (auto& it : m_weapon->getWeaponSlots())
	{
		SpellSlot spellSlot = SpellSlot();
		if (it.first.second == SpellID::VOID)
		{
			spellSlot = SpellSlot(it.first.first);
		}
		else
		{
			spellSlot = SpellSlot(it.first.second);
		}
		spellSlot.setPosition(sf::Vector2f(xOffset, yOffset) + sf::Vector2f(SpellSlot::RADIUS, SpellSlot::RADIUS));
		spellSlot.setNr(slotNr);
		xOffset += 2 * SpellSlot::RADIUS + 2 * MARGIN;

		std::vector<ModifierSlot> modifiers;
		for (auto& it2 : it.second.second)
		{
			modifiers.push_back(ModifierSlot(it2.second));
		}
		int emptyModifierCount = it.second.first - static_cast<int>(modifiers.size());
		for (int i = 0; i < emptyModifierCount; i++)
		{
			modifiers.push_back(ModifierSlot());
		}
		for (auto& it2 : modifiers)
		{
			it2.setPosition(sf::Vector2f(xOffset, yOffset));
			it2.setNr(slotNr);
			xOffset += ModifierSlot::SIDE_LENGTH + MARGIN;
		}

		yOffset += 2 * SpellSlot::RADIUS + 2 * MARGIN;
		xOffset = LEFT + GUIConstants::TEXT_OFFSET;
		slotNr++;
		m_weaponSlots.push_back(std::pair<SpellSlot, std::vector<ModifierSlot>>({spellSlot, modifiers}));
	}
}