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; } }
void Game::showFPSText(sf::RenderTarget& target, float frameTimeSeconds) { sf::View oldView = target.getView(); target.setView(target.getDefaultView()); m_fpsList.push_back(frameTimeSeconds); if (static_cast<int>(m_fpsList.size()) > FPS_AVERAGE_NR) { m_fpsList.pop_front(); } // calc average float sum = 0.f; for (float f : m_fpsList) { sum += f; } int fps = static_cast<int>(1.f / (sum / FPS_AVERAGE_NR)); BitmapText fpsText = BitmapText( "FPS: " + std::to_string(fps)); fpsText.setColor(COLOR_BAD); fpsText.setPosition(sf::Vector2f(1050.f, 10.f)); fpsText.setCharacterSize(16); target.draw(fpsText); target.setView(oldView); }
void Spellbook::calculateModifierSlots() { float yOffset = GUIConstants::TOP + SPELL_OFFSET; float xOffset = GUIConstants::LEFT + 2 * GUIConstants::TEXT_OFFSET; float modifierXOffset = 213.f; float textYOffset = SpellSlot::ICON_SIZE / 2.f - GUIConstants::CHARACTER_SIZE_S / 2.f; for (auto& it : m_core->getData().modfiersLearned) { BitmapText text; text.setCharacterSize(GUIConstants::CHARACTER_SIZE_S); text.setColor(COLOR_WHITE); text.setPosition(sf::Vector2f(xOffset, yOffset + textYOffset)); text.setString(g_textProvider->getText(EnumNames::getSpellModifierTypeName(it.first))); m_modifierTexts.push_back(text); for (int i = 0; i < it.second; i++) { SpellModifier modifier; modifier.level = i + 1; modifier.type = it.first; ModifierSlot slot(modifier); slot.setPosition(sf::Vector2f(modifierXOffset + (i * (ModifierSlot::SIZE + MARGIN)), yOffset)); m_modifierSlots.push_back(slot); } yOffset += ModifierSlot::SIZE + 6.f; } }
void Spellbook::calculateModifierSlots() { float yOffset = GUIConstants::TOP + GUIConstants::TEXT_OFFSET + 2 * GUIConstants::CHARACTER_SIZE_M + 2 * MARGIN + 2 * BUTTON_SIZE.y; float xOffset = GUIConstants::LEFT + GUIConstants::TEXT_OFFSET; int maxY = 4; int y = 1; for (auto& it : m_core->getData().modfiersLearned) { BitmapText text; text.setCharacterSize(GUIConstants::CHARACTER_SIZE_M); text.setColor(CENDRIC_COLOR_WHITE); text.setPosition(sf::Vector2f(xOffset, yOffset)); text.setString(g_textProvider->getText(EnumNames::getSpellModifierTypeName(it.first))); m_modifierTexts.push_back(text); yOffset += GUIConstants::CHARACTER_SIZE_M * 2; for (int i = 0; i < it.second; i++) { SpellModifier modifier; modifier.level = i + 1; modifier.type = it.first; ModifierSlot slot(modifier); slot.setPosition(sf::Vector2f(xOffset + (i * (ModifierSlot::SIDE_LENGTH + MARGIN)), yOffset)); m_modifierSlots.push_back(slot); } if (y >= maxY) { yOffset = GUIConstants::TOP + GUIConstants::TEXT_OFFSET + 2 * GUIConstants::CHARACTER_SIZE_M + 2 * MARGIN + 2 * BUTTON_SIZE.y; xOffset = GUIConstants::LEFT + WIDTH - (3 * ModifierSlot::SIDE_LENGTH + 2 * MARGIN + GUIConstants::TEXT_OFFSET); y = 0; } else { y++; yOffset += GUIConstants::CHARACTER_SIZE_M + ModifierSlot::SIDE_LENGTH; } } }