]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameDraw.cpp
little cleanup about campaign level handling
[lugaru.git] / Source / GameDraw.cpp
index 6031cf5f21a8387db64c7a7079562adefa1f807d..2795bd75b159eb39152747bdf3224d3dadbd34b0 100644 (file)
@@ -2050,37 +2050,22 @@ void Game::LoadCampaign() {
        }
        ipstream.close();
 
-       for(int i=0;i<campaignnumlevels;i++){
-               levelvisible[i]=0;
-               levelhighlight[i]=0;
+       if(!Mainmenuitems[7]) {
+               ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
+               if(test.good()) {
+                       LoadTextureData((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
+               } else {
+                       LoadTextureData(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
+               }
        }
 
-       levelorder[0]=0;
-       levelvisible[0]=1;
-       for(int i=0;i<accountactive->getCampaignChoicesMade();i++){
-               levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
-               levelvisible[levelorder[i+1]]=1;
-       }
-       int whichlevelstart = accountactive->getCampaignChoicesMade()-1;
-       if(whichlevelstart<0){
+       if(accountactive->getCampaignChoicesMade()==0) {
                accountactive->setCampaignScore(0);
                accountactive->resetFasttime();
-               campaignchoicenum=1;
-               campaignchoicewhich[0]=0;
-       }
-       else
-       {
-               campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
-               for(int i=0;i<campaignchoicenum;i++){
-                       campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
-                       levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                       levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-               }
        }
 }
 
-void Game::DrawMenu()
-{
+void Game::DrawMenu() {
        int i,j;
        static float lastcheck;
 
@@ -2357,7 +2342,7 @@ void Game::DrawMenu()
                }
                
                if(mainmenu==5){                        
-                       nummenuitems=NB_CAMPAIGN_MENU_ITEM+1+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;
+                       nummenuitems=NB_CAMPAIGN_MENU_ITEM+1+accountactive->getCampaignChoicesMade()+(accountactive->getCampaignChoicesMade()>0?campaignnumnext[accountactive->getCampaignChoicesMade()-1]:1);
 
                        sprintf (menustring[0], "%s",accountactive->getName());
                        startx[0]=5;
@@ -2396,7 +2381,7 @@ void Game::DrawMenu()
                        endy[5]=starty[5]+20;
                        
                        sprintf (menustring[6], "Campaign : %s", accountactive->getCurrentCampaign().c_str());
-                       startx[6]=100;
+                       startx[6]=200;
                        endx[6]=startx[6]+strlen(menustring[6])*10;
                        starty[6]=420;
                        endy[6]=starty[6]+20;
@@ -2409,24 +2394,28 @@ void Game::DrawMenu()
                        endx[NB_CAMPAIGN_MENU_ITEM]=startx[NB_CAMPAIGN_MENU_ITEM]+400;
                        endy[NB_CAMPAIGN_MENU_ITEM]=30+480-50;
 
-                       if((accountactive?accountactive->getCampaignChoicesMade():0)) {
-                               for(i=0;i<(accountactive?accountactive->getCampaignChoicesMade():0);i++) {
-                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaigndescription[levelorder[i]]);
-                                       startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlocationx[levelorder[i]]*400/512;
-                                       starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlocationy[levelorder[i]])*400/512;
+                       if(accountactive->getCampaignChoicesMade()) {
+                               for(i=0;i<accountactive->getCampaignChoicesMade();i++) {
+                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaigndescription[i]);
+                                       startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlocationx[i]*400/512;
+                                       starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlocationy[i])*400/512;
                                        endx[NB_CAMPAIGN_MENU_ITEM+1+i]=startx[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
                                        endy[NB_CAMPAIGN_MENU_ITEM+1+i]=starty[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
                                }
-                       }
-
-                       if(campaignchoicenum>0) {
-                               for(i=(accountactive?accountactive->getCampaignChoicesMade():0);i<(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum;i++){
-                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+i], "%s", campaigndescription[levelorder[i]]);
-                                       startx[NB_CAMPAIGN_MENU_ITEM+1+i]=30+120+campaignlocationx[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]]*400/512;
-                                       starty[NB_CAMPAIGN_MENU_ITEM+1+i]=30+30+(512-campaignlocationy[campaignchoicewhich[i-((accountactive?accountactive->getCampaignChoicesMade():0))]])*400/512;
-                                       endx[NB_CAMPAIGN_MENU_ITEM+1+i]=startx[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
-                                       endy[NB_CAMPAIGN_MENU_ITEM+1+i]=starty[NB_CAMPAIGN_MENU_ITEM+1+i]+10;
+                               for(i=0;i<campaignnumnext[accountactive->getCampaignChoicesMade()-1];i++) {
+                                       int j = campaignnextlevel[accountactive->getCampaignChoicesMade()-1][i];
+                                       sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1+j], "%s", campaigndescription[j]);
+                                       startx[NB_CAMPAIGN_MENU_ITEM+1+j]=30+120+campaignlocationx[j]*400/512;
+                                       starty[NB_CAMPAIGN_MENU_ITEM+1+j]=30+30+(512-campaignlocationy[j])*400/512;
+                                       endx[NB_CAMPAIGN_MENU_ITEM+1+j]=startx[NB_CAMPAIGN_MENU_ITEM+1+j]+10;
+                                       endy[NB_CAMPAIGN_MENU_ITEM+1+j]=starty[NB_CAMPAIGN_MENU_ITEM+1+j]+10;
                                }
+                       } else {
+                               sprintf (menustring[NB_CAMPAIGN_MENU_ITEM+1], "%s", campaigndescription[0]);
+                               startx[NB_CAMPAIGN_MENU_ITEM+1]=30+120+campaignlocationx[0]*400/512;
+                               starty[NB_CAMPAIGN_MENU_ITEM+1]=30+30+(512-campaignlocationy[0])*400/512;
+                               endx[NB_CAMPAIGN_MENU_ITEM+1]=startx[NB_CAMPAIGN_MENU_ITEM+1]+10;
+                               endy[NB_CAMPAIGN_MENU_ITEM+1]=starty[NB_CAMPAIGN_MENU_ITEM+1]+10;
                        }
                        
                }
@@ -2684,12 +2673,12 @@ void Game::DrawMenu()
 
        for(i=0;i<nummenuitems;i++) {
                if((mousecoordh/screenwidth*640)>startx[i]&&(mousecoordh/screenwidth*640)<endx[i]&&480-(mousecoordv/screenheight*480)>starty[i]&&480-(mousecoordv/screenheight*480)<endy[i]) {
-                       if(mainmenu!=5) selected=i;
+                       if((mainmenu!=5) && (mainmenu!=1) && (mainmenu!=2)) selected=i; // username in menu 5 and game title in menu 1&2 can't be selected
                        else if( (i>0) && (i!=NB_CAMPAIGN_MENU_ITEM) ) selected=i;
                }
        }
 
-       for(i=0;i<nummenuitems;i++){
+       for(i=0;i<nummenuitems;i++) {
                if(selected==i) {
                        selectedlong[i]+=multiplier*5;
                        if(selectedlong[i]>1) selectedlong[i]=1;
@@ -2930,10 +2919,10 @@ void Game::DrawMenu()
                                                                //float linestartx,lineendx,linestarty,lineendy,offsetx,offsety;
                                                                linestart.x=(startx[j]+endx[j])/2;
                                                                linestart.y=(starty[j]+endy[j])/2;
-                                                               if(j>=NB_CAMPAIGN_MENU_ITEM+(accountactive?accountactive->getCampaignChoicesMade():0)){
-                                                                       linestart.x=(startx[6+(accountactive?accountactive->getCampaignChoicesMade():0)]+endx[6+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
-                                                                       linestart.y=(starty[6+(accountactive?accountactive->getCampaignChoicesMade():0)]+endy[6+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
-                                                               }
+                                                               //~ if(j>=NB_CAMPAIGN_MENU_ITEM-1+(accountactive?accountactive->getCampaignChoicesMade():0)){
+                                                                       //~ linestart.x=(startx[NB_CAMPAIGN_MENU_ITEM-1+(accountactive?accountactive->getCampaignChoicesMade():0)]+endx[NB_CAMPAIGN_MENU_ITEM-1+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
+                                                                       //~ linestart.y=(starty[NB_CAMPAIGN_MENU_ITEM-1+(accountactive?accountactive->getCampaignChoicesMade():0)]+endy[NB_CAMPAIGN_MENU_ITEM-1+(accountactive?accountactive->getCampaignChoicesMade():0)])/2;
+                                                               //~ } // what was this if for?
                                                                lineend.x=(startx[j+1]+endx[j+1])/2;
                                                                lineend.y=(starty[j+1]+endy[j+1])/2;
                                                                offset=lineend-linestart;
@@ -2943,7 +2932,7 @@ void Game::DrawMenu()
                                                                Normalise(&offset);
                                                                glDisable(GL_TEXTURE_2D);                                                       
 
-                                                               if(j<NB_CAMPAIGN_MENU_ITEM+(accountactive?accountactive->getCampaignChoicesMade():0)){
+                                                               if(j<NB_CAMPAIGN_MENU_ITEM+accountactive->getCampaignChoicesMade()){
                                                                        glColor4f(0.5,0,0,1);
                                                                        endsize=.5;
                                                                } else {
@@ -2955,7 +2944,7 @@ void Game::DrawMenu()
                                                                linestart+=fac*4*startsize;
                                                                lineend-=fac*4*endsize;
 
-                                                               if(!(j>NB_CAMPAIGN_MENU_ITEM+1+(accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum)){
+                                                               //~ if(!(j>NB_CAMPAIGN_MENU_ITEM+1+accountactive->getCampaignChoicesMade()+campaignchoicenum)){
                                                                        glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
                                                                        glPushMatrix();
                                                                                glBegin(GL_QUADS);
@@ -2969,7 +2958,7 @@ void Game::DrawMenu()
                                                                                glVertex3f(lineend.x-offset.x*endsize,          lineend.y-offset.y*endsize, 0.0f);
                                                                                glEnd();
                                                                        glPopMatrix();
-                                                               }
+                                                               //~ }
                                                                glEnable(GL_TEXTURE_2D);
                                                        }
 
@@ -2988,11 +2977,11 @@ void Game::DrawMenu()
                                                        midpoint.x=(startx[j]+endx[j])/2;
                                                        midpoint.y=(starty[j]+endy[j])/2;
                                                        if      (j>NB_CAMPAIGN_MENU_ITEM &&
-                                                               (j-NB_CAMPAIGN_MENU_ITEM-1 < (accountactive?accountactive->getCampaignChoicesMade():0))) {
+                                                               (j-NB_CAMPAIGN_MENU_ITEM-1 < accountactive->getCampaignChoicesMade())) {
                                                                        itemsize*=.5;
                                                        }
-                                                       if(!(j-NB_CAMPAIGN_MENU_ITEM-1 > (accountactive?accountactive->getCampaignChoicesMade():0)+campaignchoicenum))
-                                                       {
+                                                       //~ if(!(j-NB_CAMPAIGN_MENU_ITEM-1 > accountactive->getCampaignChoicesMade()+campaignnumnext[accountactive->getCampaignChoicesMade()]))
+                                                       //~ {
                                                                glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
                                                                glPushMatrix();
                                                                        glBegin(GL_QUADS);
@@ -3029,7 +3018,7 @@ void Game::DrawMenu()
                                                                                glPopMatrix();
                                                                        }
                                                                }
-                                                       }
+                                                       //~ }
                                                glPopMatrix();
                                        glPopMatrix();
                                        glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix