From 531512ddd1b17458281b27a6f21be83bc2a9c16c Mon Sep 17 00:00:00 2001 From: sf17k Date: Sun, 29 May 2011 12:27:39 -0400 Subject: [PATCH] major refactor of menu system, part 2 --- Source/Game.cpp | 3 +- Source/Game.h | 2 +- Source/GameDraw.cpp | 258 ------------------------------------- Source/GameInitDispose.cpp | 4 +- Source/GameTick.cpp | 253 ++++++++++++++++++++++++++++++++++-- Source/Globals.cpp | 1 - Source/Menu.cpp | 90 ++++++------- Source/Menu.h | 19 ++- 8 files changed, 293 insertions(+), 337 deletions(-) diff --git a/Source/Game.cpp b/Source/Game.cpp index 1c250ca..44c4e64 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -48,7 +48,6 @@ namespace Game{ bool entername; - char menustring[100][256]; char registrationname[256]; float registrationnumber; @@ -198,7 +197,6 @@ void Game::newGame() entername = 0; - memset(menustring, 0, sizeof(menustring)); memset(registrationname, 0, sizeof(registrationname)); registrationnumber = 0; @@ -473,6 +471,7 @@ int Game::setKeySelected_thread(void* data) { } keyselect=-1; waiting=false; + LoadMenu(); return 0; } diff --git a/Source/Game.h b/Source/Game.h index 500d9b6..32dbced 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -176,7 +176,6 @@ namespace Game extern bool entername; - extern char menustring[100][256]; extern char registrationname[256]; extern float registrationnumber; @@ -294,6 +293,7 @@ namespace Game int DrawGLScene(StereoSide side); void DrawMenu(); void DrawGL(); + void LoadMenu(); //factored from Tick() -sf17k void MenuTick(); void doTutorial(); diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index f5d0513..09bdb16 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -76,7 +76,6 @@ extern bool vertexweird[6]; extern bool velocityblur; extern bool debugmode; extern int mainmenu; -extern int oldmainmenu; extern int bloodtoggle; extern int difficulty; extern bool decals; @@ -2076,7 +2075,6 @@ void Game::LoadCampaign() { accountactive->setCampaignScore(0); accountactive->resetFasttime(); } - oldmainmenu=0; //reload menu } void Game::DrawMenu() { @@ -2088,12 +2086,6 @@ void Game::DrawMenu() { glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); ReSizeGLScene(90,.1f); - if(oldmainmenu!=mainmenu){ - if(mainmenu==5){ - LoadCampaign(); - } - } - //draw menu background glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_ALPHA_TEST); @@ -2147,257 +2139,7 @@ void Game::DrawMenu() { glPopMatrix(); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - /* - Values of mainmenu : - 1 Main menu - 2 Menu pause (resume/end game) - 3 Option menu - 4 Controls configuration menu - 5 Main game menu (choose level or challenge) - 6 Deleting user menu - 7 User managment menu (select/add) - 8 Choose difficulty menu - 9 Challenge level selection menu - 10 End of the campaign congratulation (is that really a menu?) - 11 Same that 9 ??? => unused - 18 stereo configuration - */ - - if(oldmainmenu!=mainmenu) - Menu::clearMenu(); - - switch(mainmenu) { - case 1: - case 2:{ - if(oldmainmenu!=mainmenu){ - Menu::addImage(0,Mainmenuitems[0],150,480-128,256,128); - Menu::addImageButton(1,Mainmenuitems[mainmenu==1?1:5],NULL,18,480-152-32,128,32); - Menu::addImageButton(2,Mainmenuitems[2],NULL,18,480-228-32,112,32); - Menu::addImageButton(3,Mainmenuitems[mainmenu==1?3:6],NULL,18,480-306-32,mainmenu==1?68:132,32); - } - } - break; - case 3: { - if(oldmainmenu!=mainmenu){ - Menu::addButton( 0,"",NULL,10+20,440,-1,-1); - Menu::addButton( 1,"",NULL,10+60,405,-1,-1); - Menu::addButton( 2,"",NULL,10+70,370,-1,-1); - Menu::addButton( 3,"",NULL,10+20-1000,335-1000,-1,-1); - Menu::addButton( 4,"",NULL,10 ,335,-1,-1); - Menu::addButton( 5,"",NULL,10+60,300,-1,-1); - Menu::addButton( 6,"",NULL,10+70,265,-1,-1); - Menu::addButton( 9,"",NULL,10 ,230,-1,-1); - Menu::addButton(10,"",NULL,20 ,195,-1,-1); - Menu::addButton(11,"",NULL,10+60,160,-1,-1); - Menu::addButton(13,"",NULL,30 ,125,-1,-1); - Menu::addButton( 7,"",NULL,10+15, 90,-1,-1); - Menu::addButton(12,"",NULL,10+15, 55,-1,-1); - Menu::addButton(8,"Back",NULL,10,10,-1,-1); - } - if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59) - sprintf (menustring[0], "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight); - else - sprintf (menustring[0], "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight); - - if(newdetail==2) sprintf (menustring[1], "Detail: High"); - else if(newdetail==1) sprintf (menustring[1], "Detail: Medium"); - else sprintf (menustring[1], "Detail: Low"); - - if(bloodtoggle==2) sprintf (menustring[2], "Blood: On, high detail (slower)"); - if(bloodtoggle==1) sprintf (menustring[2], "Blood: On, low detail"); - if(bloodtoggle==0) sprintf (menustring[2], "Blood: Off"); - - if(difficulty==2) sprintf (menustring[3], "Difficulty: Insane"); - if(difficulty==1) sprintf (menustring[3], "Difficulty: Difficult"); - if(difficulty==0) sprintf (menustring[3], "Difficulty: Easier"); - - if(ismotionblur==1) sprintf (menustring[4], "Blur Effects: Enabled (less compatible)"); - if(ismotionblur==0) sprintf (menustring[4], "Blur Effects: Disabled (more compatible)"); - - if(decals==1) sprintf (menustring[5], "Decals: Enabled (slower)"); - if(decals==0) sprintf (menustring[5], "Decals: Disabled"); - - if(musictoggle==1) sprintf (menustring[6], "Music: Enabled"); - if(musictoggle==0) sprintf (menustring[6], "Music: Disabled"); - - if(invertmouse==1) sprintf (menustring[9], "Invert mouse: Yes"); - if(invertmouse==0) sprintf (menustring[9], "Invert mouse: No"); - - sprintf (menustring[10], "Mouse Speed: %d", (int)(usermousesensitivity*5)); - - sprintf (menustring[11], "Volume: %d%%", (int)(volume*100)); - - sprintf (menustring[13], "Damage Bar: %s",(showdamagebar?"on":"off")); - - sprintf (menustring[7], "-Configure Controls-"); - - sprintf (menustring[12], "-Configure Stereo -"); - - if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)sprintf (menustring[8], "Back"); - else sprintf (menustring[8], "Back (some changes take effect next time Lugaru is opened)"); - - for(int i=0;i<=13;i++) - Menu::setButtonText(i,menustring[i]); - } - break; - case 4: { - if(oldmainmenu!=mainmenu){ - Menu::addButton(0,"",NULL,10 ,400,-1,-1); - Menu::addButton(1,"",NULL,10+40,360,-1,-1); - Menu::addButton(2,"",NULL,10+40,320,-1,-1); - Menu::addButton(3,"",NULL,10+30,280,-1,-1); - Menu::addButton(4,"",NULL,10+20,240,-1,-1); - Menu::addButton(5,"",NULL,10+40,200,-1,-1); - Menu::addButton(6,"",NULL,10+40,160,-1,-1); - Menu::addButton(7,"",NULL,10+30,120,-1,-1); - Menu::addButton(8,"",NULL,10+20,80,-1,-1); - if(debugmode) - Menu::addButton(9,"",NULL,10+10,40,-1,-1); - Menu::addButton(debugmode?10:9,"Back",NULL,10,10,-1,-1); - } - Menu::setButtonText(0,(string)"Forwards: "+(keyselect==0?"_":Input::keyToChar(forwardkey))); - Menu::setButtonText(1,(string)"Back: " +(keyselect==1?"_":Input::keyToChar(backkey))); - Menu::setButtonText(2,(string)"Left: " +(keyselect==2?"_":Input::keyToChar(leftkey))); - Menu::setButtonText(3,(string)"Right: " +(keyselect==3?"_":Input::keyToChar(rightkey))); - Menu::setButtonText(4,(string)"Crouch: " +(keyselect==4?"_":Input::keyToChar(crouchkey))); - Menu::setButtonText(5,(string)"Jump: " +(keyselect==5?"_":Input::keyToChar(jumpkey))); - Menu::setButtonText(6,(string)"Draw: " +(keyselect==6?"_":Input::keyToChar(drawkey))); - Menu::setButtonText(7,(string)"Throw: " +(keyselect==7?"_":Input::keyToChar(throwkey))); - Menu::setButtonText(8,(string)"Attack: " +(keyselect==8?"_":Input::keyToChar(attackkey))); - if(debugmode) - Menu::setButtonText(9,(string)"Console: "+(keyselect==9?"_":Input::keyToChar(consolekey))); - } - break; - case 5: { - if(oldmainmenu!=mainmenu){ - Menu::addLabel(-1,accountactive->getName(),5,400); - Menu::addButton(1,"Tutorial",NULL,5,300,-1,-1); - Menu::addButton(2,"Challenge",NULL,5,240,-1,-1); - Menu::addButton(3,"Delete User",NULL,400,10,-1,-1); - Menu::addButton(4,"Main Menu",NULL,5,10,-1,-1); - Menu::addButton(5,"Change User",NULL,5,180,-1,-1); - Menu::addButton(6,"Campaign : "+accountactive->getCurrentCampaign(),NULL,200,420,-1,-1); - - //show campaign map - //with (2,-5) offset from old code - Menu::addImage(-1,Mainmenuitems[7],150+2,60-5,400,400); - //show levels - int numlevels = accountactive->getCampaignChoicesMade(); - numlevels += numlevels>0 ? campaignlevels[numlevels-1].nextlevel.size() : 1; - for(int i=0;i=accountactive->getCampaignChoicesMade(); - if(!active) - itemsize/=2; - - if(i>=1){ - XYZ start=campaignlevels[i-1].getCenter(); - Menu::addMapLine(start.x,start.y,midpoint.x-start.x,midpoint.y-start.y,0.5,active?1:0.5,active?1:0.5,0,0); - } - Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM+i, Mapcircletexture, NULL, - midpoint.x-itemsize/2, midpoint.y-itemsize/2, itemsize, itemsize, active?1:0.5, 0, 0); - - if(active){ - Menu::addLabel(-2,campaignlevels[i].description, - campaignlevels[i].getStartX()+10, - campaignlevels[i].getStartY()-4); - Menu::setMapItem(-2); - } - } - } - } - break; - case 6: { - if(oldmainmenu!=mainmenu){ - Menu::addLabel(-1,"Are you sure you want to delete this user?",10,400); - Menu::addButton(1,"Yes",NULL,10,360,-1,-1); - Menu::addButton(2,"No",NULL,10,320,-1,-1); - } - } - break; - case 7: { - if(oldmainmenu!=mainmenu){ - Menu::addButton(0,Account::getNbAccounts()<8?"New User":"No More Users",NULL,10,400,-1,-1); - Menu::addLabel(-2,"",20,400); - Menu::addButton(Account::getNbAccounts()+1,"Back",NULL,10,10,-1,-1); - for(int i=0;igetName(),NULL,10,340-20*(i+1),-1,-1); - } - if(entername){ - Menu::setButtonText(0,displaytext[0],20,400,-1,-1); - Menu::setButtonText(-2,displayblink?"_":"",20+displayselected*10,400,-1,-1); - } - } - break; - case 8: { - if(oldmainmenu!=mainmenu){ - Menu::addButton(0,"Easier",NULL,10,400,-1,-1); - Menu::addButton(1,"Difficult",NULL,10,360,-1,-1); - Menu::addButton(2,"Insane",NULL,10,320,-1,-1); - } - } - break; - case 9: { - if(oldmainmenu!=mainmenu){ - for(int i=0;igetHighScore(i)); - for(int j=strlen(temp);j<(32-17);j++) - strcat(temp," "); - name+=temp; - sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(i)-(int)(accountactive->getFastTime(i))%60)/60)); - if((int)(accountactive->getFastTime(i))%60<10)strcat(temp,"0"); - name+=temp; - sprintf (temp, "%d",(int)(accountactive->getFastTime(i))%60); - name+=temp; - - Menu::addButton(i,name,NULL,10,400-i*25,-1,-1,i>accountactive->getProgress()?0.5:1,0,0); - } - - Menu::addButton(-1," High Score Best Time",NULL,10,440,-1,-1); - Menu::addButton(numchallengelevels,"Back",NULL,10,10,-1,-1); - } - } - break; - case 10: { - if(oldmainmenu!=mainmenu){ - Menu::addLabel(0,"Congratulations!",220,330); - Menu::addLabel(1,"You have avenged your family and",140,300); - Menu::addLabel(2,"restored peace to the island of Lugaru.",110,270); - Menu::addButton(3,"Back",NULL,10,10,-1,-1); - sprintf(menustring[4],"Your score: %d",(int)accountactive->getCampaignScore()); - sprintf(menustring[5],"Highest score: %d",(int)accountactive->getCampaignHighScore()); - Menu::addLabel(4,menustring[4],190,200); - Menu::addLabel(5,menustring[5],190,180); - } - } - break; - case 18: { - if(oldmainmenu!=mainmenu){ - Menu::addButton(0,"",NULL,70,400,-1,-1); - Menu::addButton(1,"",NULL,10,360,-1,-1); - Menu::addButton(2,"",NULL,40,320,-1,-1); - Menu::addButton(3,"Back",NULL,10,10,-1,-1); - } - sprintf(menustring[0], "Stereo mode: %s", StereoModeName(newstereomode)); - sprintf(menustring[1], "Stereo separation: %.3f", stereoseparation); - sprintf(menustring[2], "Reverse stereo: %s", stereoreverse ? "Yes" : "No"); - Menu::setButtonText(0,menustring[0]); - Menu::setButtonText(1,menustring[1]); - Menu::setButtonText(2,menustring[2]); - } - } - - oldmainmenu=mainmenu; - selected=Menu::getSelected(mousecoordh*640/screenwidth,480-mousecoordv*480/screenheight); - Menu::GUITick(); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glPushMatrix(); // Store The Projection Matrix diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index ba38ecb..f6fd203 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -60,7 +60,6 @@ extern TGAImageRec texture; extern short vRefNum; extern long dirID; extern int mainmenu; -extern int oldmainmenu; extern bool visibleloading; extern float flashamount,flashr,flashg,flashb; extern int flashdelay; @@ -733,11 +732,12 @@ void Game::InitGame() stillloading=0; firstload=0; - oldmainmenu=0; newdetail=detail; newscreenwidth=screenwidth; newscreenheight=screenheight; + + LoadMenu(); } diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 74419e6..75d1395 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Input.h" #include "Animation.h" #include "Awards.h" +#include "Menu.h" #include @@ -83,6 +84,7 @@ extern XYZ windvector; extern bool debugmode; static int leveltheme; extern int mainmenu; +extern int oldmainmenu; extern bool visibleloading; extern XYZ envsound[30]; extern float envsoundvol[30]; @@ -5393,6 +5395,64 @@ void Game::doAI(int i){ } } + + +void updateSettingsMenu(){ + char sbuf[256]; + if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59) + sprintf (sbuf, "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight); + else + sprintf (sbuf, "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight); + Menu::setText(0,sbuf); + if(newdetail==0) Menu::setText(1,"Detail: Low"); + if(newdetail==1) Menu::setText(1,"Detail: Medium"); + if(newdetail==2) Menu::setText(1,"Detail: High"); + if(bloodtoggle==0) Menu::setText(2,"Blood: Off"); + if(bloodtoggle==1) Menu::setText(2,"Blood: On, low detail"); + if(bloodtoggle==2) Menu::setText(2,"Blood: On, high detail (slower)"); + if(difficulty==0) Menu::setText(3,"Difficulty: Easier"); + if(difficulty==1) Menu::setText(3,"Difficulty: Difficult"); + if(difficulty==2) Menu::setText(3,"Difficulty: Insane"); + Menu::setText(4,ismotionblur?"Blur Effects: Enabled (less compatible)":"Blur Effects: Disabled (more compatible)"); + Menu::setText(5,decals?"Decals: Enabled (slower)":"Decals: Disabled"); + Menu::setText(6,musictoggle?"Music: Enabled":"Music: Disabled"); + Menu::setText(9,invertmouse?"Invert mouse: Yes":"Invert mouse: No"); + sprintf (sbuf, "Mouse Speed: %d", (int)(usermousesensitivity*5)); + Menu::setText(10,sbuf); + sprintf (sbuf, "Volume: %d%%", (int)(volume*100)); + Menu::setText(11,sbuf); + Menu::setText(13,showdamagebar?"Damage Bar: On":"Damage Bar: Off"); + if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth) + sprintf (sbuf, "Back"); + else + sprintf (sbuf, "Back (some changes take effect next time Lugaru is opened)"); + Menu::setText(8,sbuf); +} + +void updateStereoConfigMenu(){ + char sbuf[256]; + sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode)); + Menu::setText(0,sbuf); + sprintf(sbuf, "Stereo separation: %.3f", stereoseparation); + Menu::setText(1,sbuf); + sprintf(sbuf, "Reverse stereo: %s", stereoreverse ? "Yes" : "No"); + Menu::setText(2,sbuf); +} + +void updateControlsMenu(){ + Menu::setText(0,(string)"Forwards: "+(keyselect==0?"_":Input::keyToChar(forwardkey))); + Menu::setText(1,(string)"Back: " +(keyselect==1?"_":Input::keyToChar(backkey))); + Menu::setText(2,(string)"Left: " +(keyselect==2?"_":Input::keyToChar(leftkey))); + Menu::setText(3,(string)"Right: " +(keyselect==3?"_":Input::keyToChar(rightkey))); + Menu::setText(4,(string)"Crouch: " +(keyselect==4?"_":Input::keyToChar(crouchkey))); + Menu::setText(5,(string)"Jump: " +(keyselect==5?"_":Input::keyToChar(jumpkey))); + Menu::setText(6,(string)"Draw: " +(keyselect==6?"_":Input::keyToChar(drawkey))); + Menu::setText(7,(string)"Throw: " +(keyselect==7?"_":Input::keyToChar(throwkey))); + Menu::setText(8,(string)"Attack: " +(keyselect==8?"_":Input::keyToChar(attackkey))); + if(debugmode) + Menu::setText(9,(string)"Console: "+(keyselect==9?"_":Input::keyToChar(consolekey))); +} + /* Values of mainmenu : 1 Main menu @@ -5408,10 +5468,155 @@ Values of mainmenu : 11 Same that 9 ??? => unused 18 stereo configuration */ - + +void Game::LoadMenu(){ + Menu::clearMenu(); + switch(mainmenu) { + case 1: + case 2: + Menu::addImage(0,Mainmenuitems[0],150,480-128,256,128); + Menu::addButtonImage(1,Mainmenuitems[mainmenu==1?1:5],18,480-152-32,128,32); + Menu::addButtonImage(2,Mainmenuitems[2],18,480-228-32,112,32); + Menu::addButtonImage(3,Mainmenuitems[mainmenu==1?3:6],18,480-306-32,mainmenu==1?68:132,32); + break; + case 3: + Menu::addButton( 0,"",10+20,440); + Menu::addButton( 1,"",10+60,405); + Menu::addButton( 2,"",10+70,370); + Menu::addButton( 3,"",10+20-1000,335-1000); + Menu::addButton( 4,"",10 ,335); + Menu::addButton( 5,"",10+60,300); + Menu::addButton( 6,"",10+70,265); + Menu::addButton( 9,"",10 ,230); + Menu::addButton(10,"",20 ,195); + Menu::addButton(11,"",10+60,160); + Menu::addButton(13,"",30 ,125); + Menu::addButton( 7,"-Configure Controls-",10+15, 90); + Menu::addButton(12,"-Configure Stereo -",10+15, 55); + Menu::addButton(8,"Back",10,10); + updateSettingsMenu(); + break; + case 4: + Menu::addButton(0,"",10 ,400); + Menu::addButton(1,"",10+40,360); + Menu::addButton(2,"",10+40,320); + Menu::addButton(3,"",10+30,280); + Menu::addButton(4,"",10+20,240); + Menu::addButton(5,"",10+40,200); + Menu::addButton(6,"",10+40,160); + Menu::addButton(7,"",10+30,120); + Menu::addButton(8,"",10+20,80); + if(debugmode) + Menu::addButton(9,"",10+10,40); + Menu::addButton(debugmode?10:9,"Back",10,10); + updateControlsMenu(); + break; + case 5: { + LoadCampaign(); + Menu::addLabel(-1,accountactive->getName(),5,400); + Menu::addButton(1,"Tutorial",5,300); + Menu::addButton(2,"Challenge",5,240); + Menu::addButton(3,"Delete User",400,10); + Menu::addButton(4,"Main Menu",5,10); + Menu::addButton(5,"Change User",5,180); + Menu::addButton(6,"Campaign : "+accountactive->getCurrentCampaign(),200,420); + + //show campaign map + //with (2,-5) offset from old code + Menu::addImage(-1,Mainmenuitems[7],150+2,60-5,400,400); + //show levels + int numlevels = accountactive->getCampaignChoicesMade(); + numlevels += numlevels>0 ? campaignlevels[numlevels-1].nextlevel.size() : 1; + for(int i=0;i=accountactive->getCampaignChoicesMade(); + if(!active) + itemsize/=2; + + if(i>=1){ + XYZ start=campaignlevels[i-1].getCenter(); + Menu::addMapLine(start.x,start.y,midpoint.x-start.x,midpoint.y-start.y,0.5,active?1:0.5,active?1:0.5,0,0); + } + Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM+i, Mapcircletexture, + midpoint.x-itemsize/2, midpoint.y-itemsize/2, itemsize, itemsize, active?1:0.5, 0, 0); + + if(active){ + Menu::addMapLabel(-2,campaignlevels[i].description, + campaignlevels[i].getStartX()+10, + campaignlevels[i].getStartY()-4); + } + } + } break; + case 6: + Menu::addLabel(-1,"Are you sure you want to delete this user?",10,400); + Menu::addButton(1,"Yes",10,360); + Menu::addButton(2,"No",10,320); + break; + case 7: + if(Account::getNbAccounts()<8) + Menu::addButton(0,"New User",10,400); + else + Menu::addLabel(0,"No More Users",10,400); + Menu::addLabel(-2,"",20,400); + Menu::addButton(Account::getNbAccounts()+1,"Back",10,10); + for(int i=0;igetName(),10,340-20*(i+1)); + break; + case 8: + Menu::addButton(0,"Easier",10,400); + Menu::addButton(1,"Difficult",10,360); + Menu::addButton(2,"Insane",10,320); + break; + case 9: + for(int i=0;igetHighScore(i)); + for(int j=strlen(temp);j<(32-17);j++) + strcat(temp," "); + name+=temp; + sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(i)-(int)(accountactive->getFastTime(i))%60)/60)); + if((int)(accountactive->getFastTime(i))%60<10)strcat(temp,"0"); + name+=temp; + sprintf (temp, "%d",(int)(accountactive->getFastTime(i))%60); + name+=temp; + + Menu::addButton(i,name,10,400-i*25,i>accountactive->getProgress()?0.5:1,0,0); + } + + Menu::addButton(-1," High Score Best Time",10,440); + Menu::addButton(numchallengelevels,"Back",10,10); + break; + case 10: { + Menu::addLabel(0,"Congratulations!",220,330); + Menu::addLabel(1,"You have avenged your family and",140,300); + Menu::addLabel(2,"restored peace to the island of Lugaru.",110,270); + Menu::addButton(3,"Back",10,10); + char sbuf[256]; + sprintf(sbuf,"Your score: %d",(int)accountactive->getCampaignScore()); + Menu::addLabel(4,sbuf,190,200); + sprintf(sbuf,"Highest score: %d",(int)accountactive->getCampaignHighScore()); + Menu::addLabel(5,sbuf,190,180); + } break; + case 18: + Menu::addButton(0,"",70,400); + Menu::addButton(1,"",10,360); + Menu::addButton(2,"",40,320); + Menu::addButton(3,"Back",10,10); + updateStereoConfigMenu(); + break; + } +} + void Game::MenuTick(){ //menu buttons - + selected=Menu::getSelected(mousecoordh*640/screenwidth,480-mousecoordv*480/screenheight); + // some specific case where we do something even if the left mouse button is not pressed. if((mainmenu==5) && (endgame==2)) { accountactive->endGame(); @@ -5419,9 +5624,15 @@ void Game::MenuTick(){ } if(mainmenu==10) endgame=2; - if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) ) + if(mainmenu==18 && Input::isKeyPressed(MOUSEBUTTON2) && selected==1){ stereoseparation-=0.001; - + updateStereoConfigMenu(); + } + + static int oldmainmenu=mainmenu; + + char sbuf[256]; + if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus switch(mainmenu) { case 1: @@ -5521,7 +5732,6 @@ void Game::MenuTick(){ break; case 6: musictoggle = !musictoggle; - if(musictoggle) { emit_stream_np(stream_menutheme); } else { @@ -5534,7 +5744,6 @@ void Game::MenuTick(){ musicvolume[i]=0; } } - break; case 7: // controls flash(); @@ -5544,7 +5753,6 @@ void Game::MenuTick(){ break; case 8: flash(); - SaveSettings(); mainmenu=gameon?2:1; break; @@ -5553,16 +5761,17 @@ void Game::MenuTick(){ break; case 10: usermousesensitivity+=.2; - if(usermousesensitivity>2) usermousesensitivity=.2; + if(usermousesensitivity>2) + usermousesensitivity=.2; break; case 11: volume+=.1f; - if(volume>1.0001f) volume=0; + if(volume>1.0001f) + volume=0; OPENAL_SetSFXMasterVolume((int)(volume*255)); break; case 12: flash(); - newstereomode = stereomode; mainmenu=18; keyselect=-1; @@ -5571,6 +5780,7 @@ void Game::MenuTick(){ showdamagebar = !showdamagebar; break; } + updateSettingsMenu(); break; case 4: if(!waiting) { @@ -5584,6 +5794,7 @@ void Game::MenuTick(){ mainmenu=3; } } + updateControlsMenu(); break; case 5: fireSound(); @@ -5649,7 +5860,7 @@ void Game::MenuTick(){ c=campaigns.begin(); accountactive->setCurrentCampaign(*c); } - LoadCampaign(); + LoadMenu(); break; } break; @@ -5674,7 +5885,10 @@ void Game::MenuTick(){ accountactive=Account::get(selected-1); } else if (selected == Account::getNbAccounts()+1) { flash(); - mainmenu=5; + if(accountactive) + mainmenu=5; + else + mainmenu=1; for(int j=0;j<255;j++){ displaytext[0][j]=0; } @@ -5747,6 +5961,7 @@ void Game::MenuTick(){ InitStereo(stereomode); } } + updateStereoConfigMenu(); break; } } @@ -5760,7 +5975,7 @@ void Game::MenuTick(){ OPENAL_SetFrequency(channels[stream_menutheme], 22050); - if(entername) { + if(entername){ inputText(displaytext[0],&displayselected,&displaychars[0]); if(!waiting) { // the input as finished if(displaychars[0]){ // with enter @@ -5788,6 +6003,16 @@ void Game::MenuTick(){ displayblink=1-displayblink; } } + + if(entername){ + Menu::setText(0,displaytext[0],20,400,-1,-1); + Menu::setText(-2,displayblink?"_":"",20+displayselected*10,400,-1,-1); + } + + if(oldmainmenu!=mainmenu) + LoadMenu(); + oldmainmenu=mainmenu; + } void Game::Tick(){ @@ -5868,7 +6093,7 @@ void Game::Tick(){ emit_stream_np(stream_menutheme); pause_sound(leveltheme); } - LoadCampaign(); + LoadMenu(); } //escape key pressed //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 9331aec..ffc13d7 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -120,7 +120,6 @@ XYZ windvector; short vRefNum = 0; long dirID = 0; int mainmenu = 0; -int oldmainmenu = 0; int whichjointstartarray[26] = {0}; int whichjointendarray[26] = {0}; int kBitsPerPixel = 0; diff --git a/Source/Menu.cpp b/Source/Menu.cpp index a661b6d..1eb9b4b 100644 --- a/Source/Menu.cpp +++ b/Source/Menu.cpp @@ -10,9 +10,8 @@ extern float multiplier; struct MenuItem { enum MenuItemType{NONE,LABEL,BUTTON,IMAGE,IMAGEBUTTON,MAPMARKER,MAPLINE,MAPLABEL} type; int id; - string label; + string text; int texture; - MBCallback cb; int x,y,w,h; float r,g,b; float effectfade; @@ -20,14 +19,13 @@ struct MenuItem { float linestartsize; float lineendsize; - void init(MenuItemType _type, int _id, const string& _label, int _texture, MBCallback _cb, + void init(MenuItemType _type, int _id, const string& _text, int _texture, int _x, int _y, int _w, int _h, float _r, float _g, float _b, float _linestartsize=1, float _lineendsize=1){ type=_type; id=_id; - label=_label; + text=_text; texture=_texture; - cb=_cb; x=_x; y=_y; w=_w; h=_h; r=_r; g=_g; b=_b; effectfade=0; @@ -35,7 +33,7 @@ struct MenuItem { lineendsize=_lineendsize; if(type==MenuItem::BUTTON){ if(w==-1) - w=label.length()*10; + w=text.length()*10; if(h==-1) h=20; } @@ -47,75 +45,56 @@ vector items; -void Menu::GUITick(){ - for(vector::iterator it=items.begin();it!=items.end();it++){ - if(it->id==Game::selected){ - it->effectfade+=multiplier*5; - if(it->effectfade>1) - it->effectfade=1; - }else{ - it->effectfade-=multiplier*5; - if(it->effectfade<0) - it->effectfade=0; - } - } -} - void Menu::clearMenu(){ items.clear(); } -void Menu::addLabel(int id,const string& label,int x,int y){ +void Menu::addLabel(int id,const string& text,int x,int y,float r,float g,float b){ items.push_back(MenuItem()); - items.back().init(MenuItem::LABEL,id,label,0,NULL,x,y,-1,-1,1,0,0); + items.back().init(MenuItem::LABEL,id,text,0,x,y,-1,-1,r,g,b); } -void Menu::addButton(int id,const string& label,MBCallback cb,int x,int y,int w,int h,float r,float g,float b){ +void Menu::addButton(int id,const string& text,int x,int y,float r,float g,float b){ items.push_back(MenuItem()); - items.back().init(MenuItem::BUTTON,id,label,0,cb,x,y,w,h,r,g,b); + items.back().init(MenuItem::BUTTON,id,text,0,x,y,-1,-1,r,g,b); } -void Menu::addImage(int id,int texture,int x,int y,int w,int h){ +void Menu::addImage(int id,int texture,int x,int y,int w,int h,float r,float g,float b){ items.push_back(MenuItem()); - items.back().init(MenuItem::IMAGE,id,"",texture,NULL,x,y,w,h,1,1,1); + items.back().init(MenuItem::IMAGE,id,"",texture,x,y,w,h,r,g,b); } -void Menu::addImageButton(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r,float g,float b){ +void Menu::addButtonImage(int id,int texture,int x,int y,int w,int h,float r,float g,float b){ items.push_back(MenuItem()); - items.back().init(MenuItem::IMAGEBUTTON,id,"",texture,cb,x,y,w,h,r,g,b); + items.back().init(MenuItem::IMAGEBUTTON,id,"",texture,x,y,w,h,r,g,b); } void Menu::addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r,float g,float b){ items.push_back(MenuItem()); - items.back().init(MenuItem::MAPLINE,-1,"",0,NULL,x,y,w,h,r,g,b,startsize,endsize); + items.back().init(MenuItem::MAPLINE,-1,"",0,x,y,w,h,r,g,b,startsize,endsize); } -void Menu::addMapMarker(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r,float g,float b){ +void Menu::addMapMarker(int id,int texture,int x,int y,int w,int h,float r,float g,float b){ items.push_back(MenuItem()); - items.back().init(MenuItem::MAPMARKER,id,"",texture,cb,x,y,w,h,r,g,b); + items.back().init(MenuItem::MAPMARKER,id,"",texture,x,y,w,h,r,g,b); } - -void Menu::setMapItem(int id){ - for(vector::iterator it=items.begin();it!=items.end();it++) - if(it->id==id){ - if(it->type==MenuItem::LABEL) - it->type=MenuItem::MAPLABEL; - break; - } +void Menu::addMapLabel(int id,const string& text,int x,int y,float r,float g,float b){ + items.push_back(MenuItem()); + items.back().init(MenuItem::MAPLABEL,id,text,0,x,y,-1,-1,r,g,b); } -void Menu::setButtonText(int id,const string& label){ +void Menu::setText(int id,const string& text){ for(vector::iterator it=items.begin();it!=items.end();it++) if(it->id==id){ - it->label=label; - it->w=it->label.length()*10; + it->text=text; + it->w=it->text.length()*10; break; } } -void Menu::setButtonText(int id,const string& label,int x,int y,int w,int h){ +void Menu::setText(int id,const string& text,int x,int y,int w,int h){ for(vector::iterator it=items.begin();it!=items.end();it++) if(it->id==id){ - it->label=label; + it->text=text; it->x=x; it->y=y; if(w==-1) - it->w=it->label.length()*10; + it->w=it->text.length()*10; if(h==-1) it->h=20; break; @@ -137,7 +116,22 @@ int Menu::getSelected(int mousex, int mousey){ return -1; } +void GUITick(){ + for(vector::iterator it=items.begin();it!=items.end();it++){ + if(it->id==Game::selected){ + it->effectfade+=multiplier*5; + if(it->effectfade>1) + it->effectfade=1; + }else{ + it->effectfade-=multiplier*5; + if(it->effectfade<0) + it->effectfade=0; + } + } +} + void Menu::drawItems(){ + GUITick(); glEnable(GL_TEXTURE_2D); glEnable(GL_ALPHA_TEST); glEnable(GL_BLEND); @@ -191,20 +185,20 @@ void Menu::drawItems(){ case MenuItem::BUTTON: glColor4f(it->r,it->g,it->b,1); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - Game::text->glPrint(it->x,it->y,it->label.c_str(),0,1,640,480); + Game::text->glPrint(it->x,it->y,it->text.c_str(),0,1,640,480); if(it->type!=MenuItem::LABEL){ //mouseover highlight glBlendFunc(GL_SRC_ALPHA,GL_ONE); for(int i=0;i<15;i++){ if(1-((float)i)/15-(1-it->effectfade)>0){ glColor4f(it->r,it->g,it->b,(1-((float)i)/10-(1-it->effectfade))*.25); - Game::text->glPrint(it->x-((float)i),it->y,it->label.c_str(),0,1+((float)i)/70,640,480); + Game::text->glPrint(it->x-((float)i),it->y,it->text.c_str(),0,1+((float)i)/70,640,480); } } } break; case MenuItem::MAPLABEL: - Game::text->glPrintOutlined(0.9,0,0,it->x,it->y,it->label.c_str(),0,0.6,640,480); + Game::text->glPrintOutlined(0.9,0,0,it->x,it->y,it->text.c_str(),0,0.6,640,480); break; case MenuItem::MAPLINE: { XYZ linestart; diff --git a/Source/Menu.h b/Source/Menu.h index 49d009c..a4a2e9c 100644 --- a/Source/Menu.h +++ b/Source/Menu.h @@ -4,19 +4,16 @@ #include "Game.h" namespace Menu { - typedef void(*MBCallback)(int id); - - void GUITick(); void clearMenu(); - void addLabel(int id,const string& label,int x,int y); - void addButton(int id,const string& label,MBCallback cb,int x,int y,int w,int h,float r=1,float g=0,float b=0); - void addImage(int id,int texture,int x,int y,int w,int h); - void addImageButton(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r=1,float g=1,float b=1); + void addLabel(int id,const string& text,int x,int y,float r=1,float g=0,float b=0); + void addButton(int id,const string& text,int x,int y,float r=1,float g=0,float b=0); + void addImage(int id,int texture,int x,int y,int w,int h,float r=1,float g=1,float b=1); + void addButtonImage(int id,int texture,int x,int y,int w,int h,float r=1,float g=1,float b=1); void addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r,float g,float b); - void addMapMarker(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r,float g,float b); - void setMapItem(int id); - void setButtonText(int id,const string& label); - void setButtonText(int id,const string& label,int x,int y,int w,int h); + void addMapMarker(int id,int texture,int x,int y,int w,int h,float r,float g,float b); + void addMapLabel(int id,const string& text,int x,int y,float r=1,float g=0,float b=0); + void setText(int id,const string& text); + void setText(int id,const string& text,int x,int y,int w,int h); int getSelected(int mousex, int mousey); void drawItems(); } -- 2.39.2