Exemplo n.º 1
0
/**
 * Get the size of a GUI image according to the table in <tt>table/gui_sprites.h</tt>.
 * @param number Number of the sprite to get.
 * @return The size of the sprite (which may be a default if there is no sprite).
 * @note Return value is kept until the next call.
 */
const Rectangle16 &SpriteManager::GetTableSpriteSize(uint16 number)
{
	static Rectangle16 result;
	static Rectangle16 slopes;
	static Rectangle16 arrows;
	static Rectangle16 bends;
	static Rectangle16 banks;
	static Rectangle16 platforms;
	static Rectangle16 powers;
	static Rectangle16 compasses;
	static Rectangle16 weathers;

	if (number >= SPR_GUI_COMPASS_START && number < SPR_GUI_COMPASS_END) {
		if (compasses.width == 0) SetSpriteSize(SPR_GUI_COMPASS_START, SPR_GUI_COMPASS_END, compasses);
		return compasses;
	}
	if (number >= SPR_GUI_WEATHER_START && number < SPR_GUI_WEATHER_END) {
		if (weathers.width == 0) SetSpriteSize(SPR_GUI_WEATHER_START, SPR_GUI_WEATHER_END, weathers);
		return weathers;
	}
	if (number >= SPR_GUI_SLOPES_START && number < SPR_GUI_SLOPES_END) {
		if (slopes.width == 0) SetSpriteSize(SPR_GUI_SLOPES_START, SPR_GUI_SLOPES_END, slopes);
		return slopes;
	}
	if (number >= SPR_GUI_BUILDARROW_START && number < SPR_GUI_BUILDARROW_END) {
		if (arrows.width== 0) SetSpriteSize(SPR_GUI_BUILDARROW_START, SPR_GUI_BUILDARROW_END, arrows);
		return arrows;
	}
	if (number >= SPR_GUI_BEND_START && number < SPR_GUI_BEND_END) {
		if (bends.width== 0) SetSpriteSize(SPR_GUI_BEND_START, SPR_GUI_BEND_END, bends);
		return bends;
	}
	if (number >= SPR_GUI_BANK_START && number < SPR_GUI_BANK_END) {
		if (banks.width== 0) SetSpriteSize(SPR_GUI_BANK_START, SPR_GUI_BANK_END, banks);
		return banks;
	}
	if (number >= SPR_GUI_HAS_PLATFORM && number <= SPR_GUI_NO_PLATFORM) {
		if (platforms.width == 0) SetSpriteSize(SPR_GUI_HAS_PLATFORM, SPR_GUI_NO_PLATFORM + 1, platforms);
		return platforms;
	}
	if (number >= SPR_GUI_HAS_POWER && number <= SPR_GUI_NO_POWER) {
		if (powers.width == 0) SetSpriteSize(SPR_GUI_HAS_POWER, SPR_GUI_NO_POWER + 1, powers);
		return powers;
	}

	/* 'Simple' single sprites. */
	const ImageData *imd = this->GetTableSprite(number);
	if (imd != nullptr && imd->width != 0 && imd->height != 0) {
		result.width = 0; result.height = 0;
		result.AddPoint(imd->xoffset, imd->yoffset);
		result.AddPoint(imd->xoffset + (int16)imd->width - 1, imd->yoffset + (int16)imd->height - 1);
		return result;
	}

	/* No useful match, return a dummy size. */
	result.base.x = 0; result.base.y = 0;
	result.width = 10; result.height = 10;
	return result;
}
bool SpriteSheet::LoadSheet(const std::string& l_file){
	std::ifstream sheet;
	sheet.open(Utils::GetWorkingDirectory() + l_file);
	if (!sheet.is_open()){
		std::cout << "! Failed loading spritesheet: "
			<< l_file << std::endl;
		return false;
	}
	// Release the current spritesheet resources.
	ReleaseSheet();
	std::string line;
	while(std::getline(sheet,line)){
		if (line[0] == '|'){ continue; }
		std::stringstream keystream(line);
		std::string type;
		keystream >> type;
		if(type == "Texture"){
			if (m_texture != ""){
				std::cout << "! Duplicate texture entries in: " << l_file << std::endl;
				continue;
			}
			std::string texture;
			keystream >> texture;
			if(!m_textureManager->RequireResource(texture))
			{
				std::cout << "! Could not set up the texture: " << texture << std::endl;
				continue;
			}
			m_texture = texture;
			m_sprite.setTexture(*m_textureManager->GetResource(m_texture));
		} else if(type == "Size"){
			keystream >> m_spriteSize.x >> m_spriteSize.y;
			SetSpriteSize(m_spriteSize);
		} else if(type == "Scale"){