void LvlScene::ChangeSectionBG(int BG_Id, int SectionID, bool forceTiled) { int sctID=0; if(SectionID<0) sctID = LvlData->CurSection; else sctID = SectionID; foreach (QGraphicsItem * findBG, items() ) { if(findBG->data(ITEM_TYPE).toString()== QString("BackGround%1").arg(LvlData->sections[sctID].id) ) { #ifdef _DEBUG_ WriteToLog(QtDebugMsg, QString("Remove items "+findBG->data(ITEM_TYPE).toString()+" by id="+QString::number(sctID)+" by SctID="+QString::number(LvlData->sections[sctID].id)) ); #endif removeItem(findBG); if(findBG) delete findBG; } } if(pConfigs->main_bg.contains(BG_Id)) LvlData->sections[sctID].background = BG_Id; else LvlData->sections[sctID].background = 0; #ifdef _DEBUG_ WriteToLog(QtDebugMsg, "set Background to "+QString::number(BG_Id)); #endif setSectionBG(LvlData->sections[sctID], forceTiled); }
// //////////////////////////Apply used sections/////////////////////////////////////// void LvlScene::makeSectionBG(QProgressDialog &progress) //void LvlScene::makeSectionBG(int x, int y, int w, int h) { int i, total=0; WriteToLog(QtDebugMsg, QString("Applay Backgrounds")); //Load Backgrounds for(i=0; i<LvlData->sections.size(); i++) { setSectionBG(LvlData->sections[i]); total++; if(progress.wasCanceled()) /*progress.setValue(progress.value()+1); else*/ return; } }
void LvlScene::ChangeSectionBG(int BG_Id, int SectionID) { int sctID=0; if(SectionID<0) sctID = LvlData->CurSection; else sctID = SectionID; foreach (QGraphicsItem * findBG, items() ) { if(findBG->data(0).toString()== QString("BackGround%1").arg(LvlData->sections[sctID].id) ) { WriteToLog(QtDebugMsg, QString("Remove items "+findBG->data(0).toString()+" by id="+QString::number(sctID)+" by SctID="+QString::number(LvlData->sections[sctID].id)) ); removeItem(findBG); if(findBG) delete findBG; } } if((BG_Id>=0) && (BG_Id <= pConfigs->main_bg.size() )) // Deny unexist ID LvlData->sections[sctID].background = BG_Id; WriteToLog(QtDebugMsg, "set Background to "+QString::number(BG_Id)); setSectionBG(LvlData->sections[sctID]); }
// /////////////////////////Init unused Section space as empty section/////////////////////////////// void LvlScene::InitSection(int sect) { long leftA, leftB; long rightA, rightB; long topA, topB; long bottomA, bottomB; int i=0; bool collided=true; if( (sect >= LvlData->sections.size()) && (sect<0) ) return; //Protector long x,y,h,w; if( (LvlData->sections[sect].size_left==0) && (LvlData->sections[sect].size_top==0) && (LvlData->sections[sect].size_bottom==0) && (LvlData->sections[sect].size_right==0) ) { //set section size/position values x = -200000 + 20000*sect;//left y = -200600 + 20000*sect;//top h = -200000 + 20000*sect;//bottom w = -199200 + 20000*sect;//right bool found=false; WriteToLog(QtDebugMsg, QString("InitSection -> Checking for collisions with other sections")); //Looking for optimal section position while(collided) { leftA = x; topA = y; rightA = w; bottomA = h; found=false; //check crossing with other sections for(i=0; i<LvlData->sections.size(); i++) { if(i == sect) continue; leftB = LvlData->sections[i].size_left; rightB = LvlData->sections[i].size_right; topB = LvlData->sections[i].size_top; bottomB = LvlData->sections[i].size_bottom; if( bottomA <= topB ) { continue; } if( topA >= bottomB ) { continue; } if( rightA <= leftB ) { continue; } if( leftA >= rightB ) { continue; } WriteToLog(QtDebugMsg, QString("InitSection -> Collision found!")); found=true; } if(found) //If collision found, move section right and try check agan { x += 20000; // move section right w += 20000; // move section right } else { //end loop WriteToLog(QtDebugMsg, QString("InitSection -> Collision pass")); collided=false; } } //Apply section's data values LvlData->sections[sect].size_left = x; LvlData->sections[sect].size_top = y; LvlData->sections[sect].size_right = w; LvlData->sections[sect].size_bottom = h; //set position to initialized section LvlData->sections[sect].PositionY = y; LvlData->sections[sect].PositionX = x; LvlData->sections[sect].bgcolor = 16291944; WriteToLog(QtDebugMsg, QString("InitSection -> Data was applyed X%1 Y%2 W%3 H%4") .arg(x).arg(y).arg(w).arg(h)); } setSectionBG( LvlData->sections[sect] ); }
// /////////////////////////Init unused Section space as empty section/////////////////////////////// void LvlScene::InitSection(int sect) { long leftA, leftB; long rightA, rightB; long topA, topB; long bottomA, bottomB; int i=0; bool collided=true; if( (sect >= LvlData->sections.size()) && (sect<0) ) { //Expand sections int needToAdd = (LvlData->sections.size()-1) - sect; while(needToAdd > 0) { LevelSection dummySct = FileFormats::CreateLvlSection(); dummySct.id = LvlData->sections.size(); LvlData->sections.push_back(dummySct); needToAdd--; } } long x,y,h,w; if( (LvlData->sections[sect].size_left==0) && (LvlData->sections[sect].size_top==0) && (LvlData->sections[sect].size_bottom==0) && (LvlData->sections[sect].size_right==0) ) { //set section size/position values x = -200000 + 20000*sect;//left y = -200600 + 20000*sect;//top h = -200000 + 20000*sect;//bottom w = -199200 + 20000*sect;//right bool found=false; #ifdef _DEBUG_ WriteToLog(QtDebugMsg, QString("InitSection -> Checking for collisions with other sections")); #endif //Looking for optimal section position while(collided) { leftA = x; topA = y; rightA = w; bottomA = h; found=false; //check crossing with other sections for(i=0;i<LvlData->sections.size(); i++) { if(i == sect) continue; leftB = LvlData->sections[i].size_left; rightB = LvlData->sections[i].size_right; topB = LvlData->sections[i].size_top; bottomB = LvlData->sections[i].size_bottom; if( bottomA <= topB ) { continue; } if( topA >= bottomB ) { continue; } if( rightA <= leftB ) { continue; } if( leftA >= rightB ) { continue; } #ifdef _DEBUG_ WriteToLog(QtDebugMsg, QString("InitSection -> Collision found!")); #endif found=true; } if(found) //If collision found, move section right and try check agan { x += 20000; // move section right w += 20000; // move section right } else { //end loop #ifdef _DEBUG_ WriteToLog(QtDebugMsg, QString("InitSection -> Collision pass")); #endif collided=false; } } //Apply section's data values LvlData->sections[sect].size_left = x; LvlData->sections[sect].size_top = y; LvlData->sections[sect].size_right = w; LvlData->sections[sect].size_bottom = h; //set position to initialized section LvlData->sections[sect].PositionY = y-10; LvlData->sections[sect].PositionX = x-10; LvlData->sections[sect].bgcolor = 16291944; #ifdef _DEBUG_ WriteToLog(QtDebugMsg, QString("InitSection -> Data was applyed X%1 Y%2 W%3 H%4") .arg(x).arg(y).arg(w).arg(h)); #endif } setSectionBG( LvlData->sections[sect] ); }