Example #1
0
int IconImageList::GetSideIcon( const std::string& modname, int side )
{
	const auto sides = LSL::usync().GetSides(modname);
	std::string sidename;
	if( side < (int)sides.size() ) {
		sidename = sides[side];
	}
	const std::string cachestring = modname + "_" + sidename;
	if ( m_cached_side_icons.find(cachestring) != m_cached_side_icons.end()){ //already cached
		return m_cached_side_icons[cachestring];
	}

	try {
		const LSL::UnitsyncImage img = LSL::usync().GetSidePicture(modname, sidename);
		int IconPosition = Add(wxBitmap( img.wxbitmap() ), wxNullBitmap);
		m_cached_side_icons[cachestring] = IconPosition;
		return IconPosition;
	} catch (...) {}
	if ( side == 0 ) { //failed to load, store dummies in cache
		m_cached_side_icons[cachestring] = ICON_SIDEPIC_0;
	} else {
		m_cached_side_icons[cachestring] = ICON_SIDEPIC_1;
	}
	return m_cached_side_icons[cachestring];
}
Example #2
0
wxBitmap& IconsCollection::GetFractionBmp(const std::string& gameName, size_t fractionId)
{

	if (gameName.empty() || !LSL::usync().GameExists(gameName)) {
		wxLogWarning("SideIcon %zu for game %s not found!", fractionId, gameName.c_str());
		// game doesn't exist, dl needed?!
		return BMP_EMPTY;
	}

	const auto sides = LSL::usync().GetSides(gameName);

	//This can happen whenever in time, so must be caught in release build too
	if (sides.empty()) {
		wxLogWarning("IconsCollection::GetFractionBmp(): sides.empty()");
		return BMP_EMPTY;
	}

	if (fractionId >= sides.size()) {
		wxLogWarning("Invalid side requested: %s:%d", gameName.c_str(), fractionId);
		return BMP_EMPTY;
	}

	std::string sideName;

	sideName = sides[fractionId];

	const std::string cacheString = gameName + "_" + sideName;

	//Check if image already in cache
	if (m_cachedFractionBmps.find(cacheString) != m_cachedFractionBmps.end()) {
		return m_cachedFractionBmps[cacheString];
		//Create one and add to cache
	} else {
		try {
			const LSL::UnitsyncImage img = LSL::usync().GetSidePicture(gameName, sideName);
			m_cachedFractionBmps[cacheString] = img.wxbitmap();
		} catch (...) {
			//unitsync can fail!
			ASSERT_LOGIC(false, "LSL::usync().GetSidePicture() failed!");
		}
		return m_cachedFractionBmps[cacheString];
	}
}
Example #3
0
wxBitmap& IconsCollection::GetFractionBmp(const std::string& modName, int fractionId) {

	wxASSERT(-1 < fractionId);
	wxASSERT(modName.empty() == false);

	if (!LSL::usync().GameExists(modName)){
		// game doesn't exist, dl needed?!
		return BMP_EMPTY;
	}

	const auto sides = LSL::usync().GetSides(modName);

	//This can happen whenever in time, so must be caught in release build too
	if (sides.empty()) {
		wxLogWarning("IconsCollection::GetFractionBmp(): sides.empty()");
		return BMP_EMPTY;
	}
	ASSERT_LOGIC(fractionId < static_cast<int>(sides.size()), "LSL::usync().GetSides() < fractionID!");

	std::string sideName;

	sideName = sides[fractionId];

	const std::string cacheString = modName + "_" + sideName;

	//Check if image already in cache
	if (m_cachedFractionBmps.find(cacheString) != m_cachedFractionBmps.end()) {
		return m_cachedFractionBmps[cacheString];
	//Create one and add to cache
	} else {
		try {
			const LSL::UnitsyncImage img = LSL::usync().GetSidePicture(modName, sideName);
			m_cachedFractionBmps[cacheString] = img.wxbitmap();
		} catch (...) {
		//unitsync can fail!
			ASSERT_LOGIC(false, "LSL::usync().GetSidePicture() failed!");
		}
		return m_cachedFractionBmps[cacheString];
	}
}