Exemple #1
0
void Building::generate()
{
    clearTiles();

    std::vector<std::pair<sf::Vector2i,sf::IntRect>> tiles = getTiles(mCoords);
    for (std::size_t i = 0; i < tiles.size(); i++)
    {
        sf::IntRect rect;
        if (mBuilt)
        {
            rect = tiles[i].second;
        }
        else
        {
            rect = sf::IntRect(1536,0,256,256);
        }
        std::cout << rect.left << " " << mType << std::endl;
        addTile(tiles[i].first,"building",rect);
    }
}
QQuickContext2DTexture::~QQuickContext2DTexture()
{
   clearTiles();
}
Exemple #3
0
IsometricBase::~IsometricBase()
{
    clearTiles();
}
Exemple #4
0
void IsometricBase::setCoords(sf::Vector2i const& coords)
{
    mCoords = coords;
    clearTiles();
}
Renderer::~Renderer() {
  clearTiles();
}
Exemple #6
0
Building::~Building()
{
    clearTiles();
}
void SFMLCursesTextBox::updateTextBox()
{
	/*
	std::string word = "";
	int col = 0;
	int line = 0;
	for(std::string::iterator stringIt(m_text.begin()); stringIt != m_text.end(); stringIt++)
	{
		if(*stringIt == ' ' || stringIt == m_text.end() - 1) //word is complete
		{
			//WARNING: If a word is longer than the width that word and any after will not be printed
			//needs mid-word linebreaking
			//left justified
			if(stringIt == m_text.end() - 1)
				word += *stringIt;
			if(word.length() > static_cast<unsigned int>(m_cursesSize.y))
				break;
			if(word.length() > static_cast<unsigned int>(m_cursesSize.y - col)) //word too long for this line, move onto next one
			{
				line++;
				col = 0;
			}
			if(line >= m_cursesSize.x) //past the last line
				break;
			for(std::string::iterator wordIt(word.begin()); wordIt != word.end(); wordIt++)
			{
				setTile(SFMLCursesChar(m_window, std::string("") + *wordIt), sf::Vector2i(line,col));
				col++;
			}
			if(col < m_cursesSize.y - 1)
			{
				setTile(SFMLCursesChar(m_window, " "), sf::Vector2i(line,col));
				col++;
			}
			word = "";
		}
		else
		{
			word += *stringIt;
		}

	}
	*/
	clearTiles(" ", m_textColor, m_backColor);
	std::string::const_iterator lineBegin(m_text.begin());
	std::string::const_iterator lineEnd(m_text.begin());
	unsigned int line = 0;
	while(lineBegin != m_text.end())
	{
		std::string::const_iterator lastLineEnd(lineEnd);
		unsigned int position = m_text.find(" ", lineEnd - m_text.begin() + 1);
		if(position != std::string::npos)
			lineEnd = m_text.begin() + position;
		else
			lineEnd = m_text.end();
		if(lineEnd - lineBegin  > m_cursesSize.y || lineEnd == m_text.end()) //too much for this line
		{
			if(!(lineEnd - lineBegin > m_cursesSize.y))
				lastLineEnd = lineEnd;
			//backtrack, print, next line
			unsigned int col = 0;
			//unsigned int spacePadding = 0;
			unsigned int wordCount = std::count(lineBegin, lastLineEnd, ' ') + 1;
			unsigned int wordCountRemaining = wordCount;
			unsigned int extraSpace = m_cursesSize.y - (lastLineEnd - lineBegin);
			unsigned int extraSpaceRemaining = extraSpace;
			//print with proper alignment
			switch(m_alignment)
			{
			case Alignment::Left:
				col = 0;
				break;
			case Alignment::Right:
				col = m_cursesSize.y - (lastLineEnd - lineBegin);
				break;
			case Alignment::Center:
				col = m_cursesSize.y/2 - (lastLineEnd - lineBegin)/2;
				break;
			case Alignment::Justify:
				col = 0;
				break;
			}
			for(lineBegin; lineBegin != lastLineEnd; lineBegin++)
			{
				setTile(SFMLCursesChar(m_window, std::string("") + *lineBegin, m_textColor, m_backColor), sf::Vector2i(line,col));
				switch(m_alignment)
				{
				case Alignment::Left:
				case Alignment::Right:
				case Alignment::Center:
					col++;
					break;
				case Alignment::Justify:
					col++;
					if(extraSpaceRemaining > 0 && *lineBegin == ' ' && lastLineEnd != m_text.end())
					{
						col++;
						extraSpaceRemaining--;
						if(extraSpaceRemaining >= wordCountRemaining - 1)
						{
							col++;
							extraSpaceRemaining--;
						}
						wordCountRemaining--;
					}
					break;
				}
			}
			if(lineBegin != m_text.end())
				lineBegin++;
			else 
				break;
			line++;
			wordCount = 0;
		}
		if(line >= static_cast<unsigned int>(m_cursesSize.x))
			break;
	}

}