Commit c6516e2a authored by 神楽坂玲奈's avatar 神楽坂玲奈

auto load thumb when failed to load full card image, and auto load full image...

auto load thumb when failed to load full card image, and auto load full image when faild to load thumb.
parent e8edb598
......@@ -703,11 +703,21 @@ void Game::WaitFrameSignal(int frame) {
frameSignal.Wait();
}
void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist) {
const int width = 44; //standard pic size, maybe it should be defined in game.h
const int height = 64;
int code = cp->first;
int lcode = cp->second.alias;
if(lcode == 0)
lcode = code;
driver->draw2DImage(imageManager.GetTextureThumb(code), pos);
irr::video::ITexture* img = imageManager.GetTextureThumb(code);
if(img == NULL)
return; //NULL->getSize() will cause a crash
dimension2d<u32> size = img->getSize();
if(size.Width == width and size.Height == height)
driver->draw2DImage(img, pos);
else
driver->draw2DImage(img, rect<s32>(pos.X, pos.Y,pos.X+width,pos.Y+height), rect<s32>(0,0,size.Width,size.Height));
if(lflist->count(lcode)) {
switch((*lflist)[lcode]) {
case 0:
......
......@@ -710,7 +710,8 @@ void Game::ShowCardInfo(int code) {
CardData cd;
wchar_t formatBuffer[256];
dataManager.GetData(code, &cd);
imgCard->setImage(imageManager.GetTexture(code));
imgCard->setImage(imageManager.GetTexture(code));
imgCard->setScaleImage(true); //I don't know weather check size or not will be faster; if Irrlicht don't check size internal and cause slow, check size like Game::DrawThumb()
if(cd.alias != 0 && (cd.alias - code < 10 || code - cd.alias < 10))
myswprintf(formatBuffer, L"%ls[%08d]", dataManager.GetName(cd.alias), cd.alias);
else myswprintf(formatBuffer, L"%ls[%08d]", dataManager.GetName(code), code);
......
......@@ -42,7 +42,7 @@ void ImageManager::ClearTexture() {
}
void ImageManager::RemoveTexture(int code) {
auto tit = tMap.find(code);
if(tit != tMap.end()) {
if(tit != tMap.end() and tThumb.find(code)->second != tit->second) { //if member of tThumb point to this; don't remove
if(tit->second)
driver->removeTexture(tit->second);
tMap.erase(tit);
......@@ -54,8 +54,14 @@ irr::video::ITexture* ImageManager::GetTexture(int code) {
auto tit = tMap.find(code);
if(tit == tMap.end()) {
char file[256];
sprintf(file, "pics/%d.jpg", code);
sprintf(file, "pics/%d.jpg", code); //suggest that define the path in game.h
irr::video::ITexture* img = driver->getTexture(file);
if(img == NULL){
sprintf(file, "pics/thumbnail/%d.jpg", code);
img = driver->getTexture(file);
if(img)
tThumb[code] = img;
}
tMap[code] = img;
return img;
}
......@@ -66,15 +72,24 @@ irr::video::ITexture* ImageManager::GetTexture(int code) {
}
irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(code == 0)
return 0;
return tUnknown;
auto tit = tThumb.find(code);
if(tit == tThumb.end()) {
char file[32];
sprintf(file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* img = driver->getTexture(file);
if(img == NULL){
sprintf(file, "pics/%d.jpg", code);
img = driver->getTexture(file);
if(img)
tMap[code] = img;
}
tThumb[code] = img;
return img;
}
return tit->second;
if(tit->second)
return tit->second;
else
return tUnknown;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment