Advertisement
Mr-A

Interface.h

Mar 10th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.53 KB | None | 0 0
  1. #include <string>
  2.  
  3.  
  4. struct CharInMenu{
  5.         int key , posx, posy;           //the key position values and the real position of the pic
  6.         int id;                         //the id of the character
  7.         spritegrid tex;                 //the texture stored in a custom class "spritegrid"
  8.         int up=4321, down=4321;         //the value of the key to go to when the corressponding button is pressed
  9.         int left=4321, right=4321;
  10. };
  11.  
  12.  
  13. //Renders textures into the screen
  14. void BlitTexture(spritegrid griddy, int x, int y){
  15.     glBindTexture( GL_TEXTURE_2D, griddy.grid );
  16.    
  17.     glBegin(GL_QUADS);
  18.         glTexCoord2f(0, 0);
  19.         glVertex2f(x, y);
  20.        
  21.         glTexCoord2f(1, 0);
  22.         glVertex2f(x+griddy.gw, y);
  23.        
  24.         glTexCoord2f(1, 1);
  25.         glVertex2f(x+griddy.gw, y+griddy.gh);
  26.        
  27.         glTexCoord2f(0, 1);
  28.         glVertex2f(x, y+griddy.gh);
  29.     glEnd();
  30.    
  31.     glColor4f(1.0f, 1.f, 1.f, 1.0f);
  32. }
  33.  
  34. class LoadMenuStuff{
  35.     public:
  36.         CharInMenu Chars[100];         //chars in selection data
  37.         spritegrid CharMenuBG;         //stores the charater menu texture
  38.         int MenuID=10;                 //this var tells what menu you're currently on
  39.         int Chars_index=0;
  40.         int CharMenuBG_x=0, CharMenuBG_y=0;
  41.         int SelectionCurr_key=0;
  42.        
  43.         int P1_INPUTDATA[8]={0, 0, 0, 0, 0, 0, 0, 0};
  44.         int P2_INPUTDATA[8]={0, 0, 0, 0, 0, 0, 0, 0};
  45.        
  46.         LoadMenuStuff();
  47.         void LoadIntros();
  48.         void LoadCharacterSelection(LOAD*LOADED);
  49.         void LoadMainMenu();
  50.         void LoadBGSelection();
  51.         void LoadOptions();
  52.         void LoadCredits();
  53.         void Update_Interface();
  54. };
  55.  
  56. LoadMenuStuff::LoadMenuStuff(){
  57.     //Load system.a
  58.     fstream SYS_FILE("obj\\system.a");
  59.     string tempqwer; //stores the the data of a statement in the tag
  60.     string tempabcd; //stores the content of a tag inside {}
  61.     string tempasdf; //stores the lines of a tag..etc
  62.     string systemd;  //stores the whole text in system.a
  63.    
  64.  
  65.     while (SYS_FILE.good()){
  66.                     getline(SYS_FILE, tempasdf);
  67.                     systemd += tempasdf; //add lines of system.a into this var
  68.     }
  69.    
  70.    
  71.     if (systemd.find("{selection_menu}")!=string::npos){ //if this tag was found in system.a
  72.     //set tempasdf to the content of the tag
  73.         tempasdf=systemd.substr(systemd.find("{selection_menu}")+16, systemd.find("{/selection_menu}")-16-systemd.find("{selection_menu}"));
  74.     }
  75.    
  76.     /*Loads the menu BG from tempasdf which contains the content
  77.     of the tag "{selection_menu}*/
  78.     size_t tagposition=tempasdf.find("menu_bg[");                                                //store the position of the tag
  79.     if (tagposition!=string::npos){                                                              //if this tag was found in the {selection_menu} block
  80.    
  81.         tempabcd=tempasdf.substr(tagposition+8, tempasdf.find("]", tagposition)-8-tagposition);  //copy the content of "menu_bg"
  82.         tempasdf.erase(tagposition, tempasdf.find("]", tagposition)-tagposition+1);              //erase what copied   
  83.         tagposition=tempabcd.find("directory=");                                                 //store the position of the tag "directory="
  84.         tempqwer=tempabcd.substr(tagposition+10, tempabcd.find(";", tagposition)-10-tagposition);//content of tag "directory="
  85.         //Load texture to CharMenuBG
  86.         int placeholderint;
  87.         CharMenuBG.ini(tempqwer, 4321, 4321, 1, 1, ",-", &placeholderint /*this parameter is useless here, just a place holder*/);
  88.        
  89.         tagposition=tempabcd.find("position=");                                                  //store the position of the tag "position="
  90.         tempqwer=tempabcd.substr(tagposition+9, tempabcd.find(";", tagposition)-9-tagposition);  //content of tag "position="
  91.         CharMenuBG_x=Evaluate(tempqwer.substr(0, tempqwer.find(",")));                           //Evaluate the first x parameter and assign it    
  92.         CharMenuBG_y=Evaluate(tempqwer.substr(tempqwer.find(",")+1));                            //Evaluate the second y parameter and assign it  
  93.        
  94.     }
  95.        
  96.     tagposition=tempasdf.find("]", tempasdf.find("[id="));    
  97.     while (tagposition!=string::npos){
  98.         tempabcd=tempasdf.substr(tagposition+1,tempasdf.find("[/id]",tagposition)-1-tagposition);          //copy the content of "menu_bg"
  99.         tempasdf.erase(tempasdf.find("[id="), tempasdf.find("[/id]", tagposition)-tempasdf.find("[id=")+1);//erase what copied 
  100.         tagposition=tempabcd.find("[id=");                                                                 //store the position of the tag "[id="
  101.         tempqwer=tempabcd.substr(tagposition+4, tempabcd.find("]", tagposition)-4-tagposition);            //content of tag "[id="
  102.         Chars[Chars_index].id=Evaluate(tempqwer);                                                          //Evaluate the parameter and assign it  
  103.        
  104.         tagposition=tempabcd.find("directory=");                                                           //store the position of the tag "directory="
  105.         tempqwer=tempabcd.substr(tagposition+10, tempabcd.find(";", tagposition)-10-tagposition);          //content of tag "directory="
  106.         //Load texture to CharMenuBG
  107.         int placeholderint;
  108.         Chars[Chars_index].tex.ini(tempqwer, 4321, 4321, 1, 1, ",-", &placeholderint /*this parameter is useless here, just a place holder*/);
  109.        
  110.         tagposition=tempabcd.find("position=");                                                            //store the position of the tag "position="
  111.         tempqwer=tempabcd.substr(tagposition+9, tempabcd.find(";", tagposition)-9-tagposition);            //content of tag "position="
  112.         Chars[Chars_index].posx=Evaluate(tempqwer.substr(0, tempqwer.find(",")));                          //Evaluate the first x parameter and assign it    
  113.         Chars[Chars_index].posy=Evaluate(tempqwer.substr(tempqwer.find(",")+1));                           //Evaluate the second y parameter and assign it  
  114.  
  115.         tagposition=tempabcd.find("key=");                                                                 //store the position of the tag "key="
  116.         tempqwer=tempabcd.substr(tagposition+4, tempabcd.find(";", tagposition)-4-tagposition);            //content of tag "key="
  117.         Chars[Chars_index].key=Evaluate(tempqwer);                                                         //Evaluate and assign
  118.        
  119.         tagposition=tempabcd.find("left=");                                                                //store the position of the tag "left="
  120.         if (tagposition!=string::npos){
  121.             tempqwer=tempabcd.substr(tagposition+5, tempabcd.find(";", tagposition)-5-tagposition);        //content of tag "left="
  122.             Chars[Chars_index].left=Evaluate(tempqwer);                                                    //Evaluate and assign           
  123.         }
  124.        
  125.         tagposition=tempabcd.find("right=");                                                               //store the position of the tag "right="
  126.         if (tagposition!=string::npos){
  127.             tempqwer=tempabcd.substr(tagposition+6, tempabcd.find(";", tagposition)-6-tagposition);        //content of tag "right="
  128.             Chars[Chars_index].right=Evaluate(tempqwer);                                                   //Evaluate and assign           
  129.         }
  130.        
  131.         tagposition=tempabcd.find("up=");                                                                  //store the position of the tag "up="
  132.         if (tagposition!=string::npos){
  133.             tempqwer=tempabcd.substr(tagposition+3, tempabcd.find(";", tagposition)-3-tagposition);        //content of tag "up="
  134.             Chars[Chars_index].up=Evaluate(tempqwer);                                                      //Evaluate and assign           
  135.         }
  136.        
  137.         tagposition=tempabcd.find("down=");                                                                //store the position of the tag "down="
  138.         if (tagposition!=string::npos){
  139.             tempqwer=tempabcd.substr(tagposition+5, tempabcd.find(";", tagposition)-5-tagposition);        //content of tag "down="
  140.             Chars[Chars_index].down=Evaluate(tempqwer);                                                    //Evaluate and assign           
  141.         }
  142.        
  143.         Chars_index++;                                                                                     //done, so we increment the index value
  144.         tagposition=tempasdf.find("]", tempasdf.find("[id="));                                             //we check again if any other [id= tags exists
  145.     }
  146.    
  147.    
  148.    
  149. }
  150.  
  151.  
  152. void LoadMenuStuff::Update_Interface(){
  153.     if (MenuID==10){
  154.         BlitTexture(CharMenuBG, CharMenuBG_x, CharMenuBG_y);
  155.         for (int indx=0; indx<Chars_index; indx++){                                    //we loop on every character on the selection
  156.             if (SelectionCurr_key==Chars[indx].key){                                   //if this character is highlighted
  157.                 BlitTexture(Chars[indx].tex, Chars[indx].posx, Chars[indx].posy);      //we render the highligting image here.
  158.                
  159.                 /*0 means that the buttons isn't held nor clicked,
  160.                 1 means that the buttons is clicked
  161.                 2 means that the buttons has been clicked but is still being held */
  162.                
  163.                 P1_INPUTDATA[0]=A_UP&&P1_INPUTDATA[0]==0?1:P1_INPUTDATA[0];        
  164.                 P1_INPUTDATA[0]=!A_UP&&P1_INPUTDATA[0]==2?0:P1_INPUTDATA[0];
  165.                
  166.                 P1_INPUTDATA[1]=A_DOWN&&P1_INPUTDATA[1]==0?1:P1_INPUTDATA[1];        
  167.                 P1_INPUTDATA[1]=!A_DOWN&&P1_INPUTDATA[1]==2?0:P1_INPUTDATA[1];
  168.                
  169.                 P1_INPUTDATA[2]=A_LEFT&&P1_INPUTDATA[2]==0?1:P1_INPUTDATA[2];        
  170.                 P1_INPUTDATA[2]=!A_LEFT&&P1_INPUTDATA[2]==2?0:P1_INPUTDATA[2];
  171.                
  172.                 P1_INPUTDATA[3]=A_RIGHT&&P1_INPUTDATA[3]==0?1:P1_INPUTDATA[3];        
  173.                 P1_INPUTDATA[3]=!A_RIGHT&&P1_INPUTDATA[3]==2?0:P1_INPUTDATA[3];
  174.    
  175.                    
  176.                 if (Chars[indx].up!=4321){
  177.                     if (P1_INPUTDATA[0]==1){
  178.                         SelectionCurr_key=Chars[indx].up;
  179.                         P1_INPUTDATA[0]=2;
  180.                     }
  181.                 }
  182.                
  183.                 if (Chars[indx].down!=4321){
  184.                     if (P1_INPUTDATA[1]==1){
  185.                         SelectionCurr_key=Chars[indx].down;
  186.                         P1_INPUTDATA[1]=2;
  187.                     }
  188.                 }
  189.                
  190.                 if (Chars[indx].left!=4321){
  191.                     if (P1_INPUTDATA[2]==1){
  192.                         SelectionCurr_key=Chars[indx].left;
  193.                         P1_INPUTDATA[2]=2;
  194.                     }
  195.                 }
  196.                
  197.                 if (Chars[indx].right!=4321){
  198.                     if (P1_INPUTDATA[3]==1){
  199.                         SelectionCurr_key=Chars[indx].right;
  200.                         P1_INPUTDATA[3]=2;
  201.                     }
  202.                 }
  203.             }
  204.         }
  205.     }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement