vector<pair<string,string> > LevelPackManager::enumLevelPacks(int type) { //The vector that will be returned. //NOTE: The names of the levelpacks are translated before adding them to the vector. vector<pair<string,string> > v; //Now do the type dependent adding. switch(type) { case ALL_PACKS: { std::map<std::string,LevelPack*>::iterator i; for(i=levelpacks.begin(); i!=levelpacks.end(); ++i) { //We add everything except the "Custom Levels" pack since that's also in "Levels". if(i->second->levelpackName!="Custom Levels") v.push_back(pair<string,string>(i->first,_CC(i->second->getDictionaryManager(),i->second->levelpackName))); } break; } case CUSTOM_PACKS: { std::map<std::string,LevelPack*>::iterator i; for(i=levelpacks.begin(); i!=levelpacks.end(); ++i) { //Only add levelpacks that are of the custom type, one exception is the "Custom Levels" pack. if(i->second->type==CUSTOM || i->second->levelpackName=="Custom Levels") v.push_back(pair<string,string>(i->first,_CC(i->second->getDictionaryManager(),i->second->levelpackName))); } break; } } //And return the vector. return v; }
void LevelPlaySelect::refresh(ImageManager& imageManager, SDL_Renderer& renderer, bool /*change*/){ int m=levels->getLevelCount(); numbers.clear(); levelInfoRender.resetText(renderer, *fontText, themeTextColor); //Clear the selected level. if(selectedNumber!=NULL){ delete selectedNumber; selectedNumber=NULL; } //Recreate the non selected number. selectedNumber=new Number(imageManager, renderer); SDL_Rect box={40,SCREEN_HEIGHT-130,50,50}; selectedNumber->init(renderer," ",box); selectedNumber->setLocked(true); bestTimeFilePath.clear(); bestRecordingFilePath.clear(); //Disable the play button. play->enabled=false; for(int n=0; n<m; n++){ numbers.emplace_back(imageManager, renderer); } for(int n=0; n<m; n++){ SDL_Rect box={(n%LEVELS_PER_ROW)*64+static_cast<int>(SCREEN_WIDTH*0.2)/2,(n/LEVELS_PER_ROW)*64+184,0,0}; numbers[n].init(renderer,n,box); numbers[n].setLocked(levels->getLocked(n)); int medal=levels->getLevel(n)->won; if(medal){ if(levels->getLevel(n)->targetTime<0 || levels->getLevel(n)->time<=levels->getLevel(n)->targetTime) medal++; if(levels->getLevel(n)->targetRecordings<0 || levels->getLevel(n)->recordings<=levels->getLevel(n)->targetRecordings) medal++; } numbers[n].setMedal(medal); } if(m>LEVELS_DISPLAYED_IN_SCREEN){ levelScrollBar->maxValue=(m-LEVELS_DISPLAYED_IN_SCREEN+(LEVELS_PER_ROW-1))/LEVELS_PER_ROW; levelScrollBar->visible=true; }else{ levelScrollBar->maxValue=0; levelScrollBar->visible=false; } if(!levels->levelpackDescription.empty()) levelpackDescription->caption=_CC(levels->getDictionaryManager(),levels->levelpackDescription); else levelpackDescription->caption=""; }
void LevelPlaySelect::renderTooltip(SDL_Renderer &renderer, unsigned int number, int dy){ if (!toolTip.name || toolTip.number != number) { SDL_Color themeTextColor={0,0,0}; const int SLEN = 64; char s[SLEN]; //Render the name of the level. toolTip.name=textureFromText(renderer,*fontText,_CC(levels->getDictionaryManager(),levels->getLevelName(number)),themeTextColor); toolTip.time=nullptr; toolTip.recordings=nullptr; toolTip.number=number; //The time it took. if(levels->getLevel(number)->time>0){ snprintf(s,SLEN,"%-.2fs",levels->getLevel(number)->time/40.0f); toolTip.time=textureFromText(renderer,*fontText,s,themeTextColor);//TTF_RenderUTF8_Blended(fontText,s,themeTextColor); } //The number of recordings it took. if(levels->getLevel(number)->recordings>=0){ snprintf(s,SLEN,"%d",levels->getLevel(number)->recordings); toolTip.recordings = textureFromText(renderer,*fontText,s,themeTextColor); } } const SDL_Rect nameSize = rectFromTexture(*toolTip.name); //Now draw a square the size of the three texts combined. SDL_Rect r=numbers[number].box; r.y-=dy*64; if(toolTip.time && toolTip.recordings){ const int recW = textureWidth(*toolTip.recordings); const int timeW = textureWidth(*toolTip.time); r.w=(nameSize.w)>(25+timeW+40+recW)?(nameSize.w):(25+timeW+40+recW); r.h=nameSize.h+5+20; }else{ r.w=nameSize.w; r.h=nameSize.h; } //Make sure the tooltip doesn't go outside the window. if(r.y>SCREEN_HEIGHT-200){ r.y-=nameSize.h+4; }else{ r.y+=numbers[number].box.h+2; } if(r.x+r.w>SCREEN_WIDTH-50) r.x=SCREEN_WIDTH-50-r.w; //Draw a rectange Uint32 color=0xFFFFFFFF; drawGUIBox(r.x-5,r.y-5,r.w+10,r.h+10,renderer,color); //Calc the position to draw. SDL_Rect r2=r; //Now we render the name if the surface isn't null. if(toolTip.name){ //Draw the name. applyTexture(r2.x, r2.y, toolTip.name, renderer); } //Increase the height to leave a gap between name and stats. r2.y+=30; if(toolTip.time){ //Now draw the time. applyTexture(r2.x,r2.y,levelInfoRender.timeIcon,renderer); r2.x+=25; applyTexture(r2.x, r2.y, toolTip.time, renderer); r2.x+=textureWidth(*toolTip.time)+15; } if(toolTip.recordings){ //Now draw the recordings. applyTexture(r2.x,r2.y,levelInfoRender.recordingsIcon,renderer); r2.x+=25; applyTexture(r2.x, r2.y, toolTip.recordings, renderer); } }