Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- struct CharInMenu{
- int key , posx, posy; //the key position values and the real position of the pic
- int id; //the id of the character
- spritegrid tex; //the texture stored in a custom class "spritegrid"
- int up=4321, down=4321; //the value of the key to go to when the corressponding button is pressed
- int left=4321, right=4321;
- };
- //Renders textures into the screen
- void BlitTexture(spritegrid griddy, int x, int y){
- glBindTexture( GL_TEXTURE_2D, griddy.grid );
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(x, y);
- glTexCoord2f(1, 0);
- glVertex2f(x+griddy.gw, y);
- glTexCoord2f(1, 1);
- glVertex2f(x+griddy.gw, y+griddy.gh);
- glTexCoord2f(0, 1);
- glVertex2f(x, y+griddy.gh);
- glEnd();
- glColor4f(1.0f, 1.f, 1.f, 1.0f);
- }
- class LoadMenuStuff{
- public:
- CharInMenu Chars[100]; //chars in selection data
- spritegrid CharMenuBG; //stores the charater menu texture
- int MenuID=10; //this var tells what menu you're currently on
- int Chars_index=0;
- int CharMenuBG_x=0, CharMenuBG_y=0;
- int SelectionCurr_key=0;
- int P1_INPUTDATA[8]={0, 0, 0, 0, 0, 0, 0, 0};
- int P2_INPUTDATA[8]={0, 0, 0, 0, 0, 0, 0, 0};
- LoadMenuStuff();
- void LoadIntros();
- void LoadCharacterSelection(LOAD*LOADED);
- void LoadMainMenu();
- void LoadBGSelection();
- void LoadOptions();
- void LoadCredits();
- void Update_Interface();
- };
- LoadMenuStuff::LoadMenuStuff(){
- //Load system.a
- fstream SYS_FILE("obj\\system.a");
- string tempqwer; //stores the the data of a statement in the tag
- string tempabcd; //stores the content of a tag inside {}
- string tempasdf; //stores the lines of a tag..etc
- string systemd; //stores the whole text in system.a
- while (SYS_FILE.good()){
- getline(SYS_FILE, tempasdf);
- systemd += tempasdf; //add lines of system.a into this var
- }
- if (systemd.find("{selection_menu}")!=string::npos){ //if this tag was found in system.a
- //set tempasdf to the content of the tag
- tempasdf=systemd.substr(systemd.find("{selection_menu}")+16, systemd.find("{/selection_menu}")-16-systemd.find("{selection_menu}"));
- }
- /*Loads the menu BG from tempasdf which contains the content
- of the tag "{selection_menu}*/
- size_t tagposition=tempasdf.find("menu_bg["); //store the position of the tag
- if (tagposition!=string::npos){ //if this tag was found in the {selection_menu} block
- tempabcd=tempasdf.substr(tagposition+8, tempasdf.find("]", tagposition)-8-tagposition); //copy the content of "menu_bg"
- tempasdf.erase(tagposition, tempasdf.find("]", tagposition)-tagposition+1); //erase what copied
- tagposition=tempabcd.find("directory="); //store the position of the tag "directory="
- tempqwer=tempabcd.substr(tagposition+10, tempabcd.find(";", tagposition)-10-tagposition);//content of tag "directory="
- //Load texture to CharMenuBG
- int placeholderint;
- CharMenuBG.ini(tempqwer, 4321, 4321, 1, 1, ",-", &placeholderint /*this parameter is useless here, just a place holder*/);
- tagposition=tempabcd.find("position="); //store the position of the tag "position="
- tempqwer=tempabcd.substr(tagposition+9, tempabcd.find(";", tagposition)-9-tagposition); //content of tag "position="
- CharMenuBG_x=Evaluate(tempqwer.substr(0, tempqwer.find(","))); //Evaluate the first x parameter and assign it
- CharMenuBG_y=Evaluate(tempqwer.substr(tempqwer.find(",")+1)); //Evaluate the second y parameter and assign it
- }
- tagposition=tempasdf.find("]", tempasdf.find("[id="));
- while (tagposition!=string::npos){
- tempabcd=tempasdf.substr(tagposition+1,tempasdf.find("[/id]",tagposition)-1-tagposition); //copy the content of "menu_bg"
- tempasdf.erase(tempasdf.find("[id="), tempasdf.find("[/id]", tagposition)-tempasdf.find("[id=")+1);//erase what copied
- tagposition=tempabcd.find("[id="); //store the position of the tag "[id="
- tempqwer=tempabcd.substr(tagposition+4, tempabcd.find("]", tagposition)-4-tagposition); //content of tag "[id="
- Chars[Chars_index].id=Evaluate(tempqwer); //Evaluate the parameter and assign it
- tagposition=tempabcd.find("directory="); //store the position of the tag "directory="
- tempqwer=tempabcd.substr(tagposition+10, tempabcd.find(";", tagposition)-10-tagposition); //content of tag "directory="
- //Load texture to CharMenuBG
- int placeholderint;
- Chars[Chars_index].tex.ini(tempqwer, 4321, 4321, 1, 1, ",-", &placeholderint /*this parameter is useless here, just a place holder*/);
- tagposition=tempabcd.find("position="); //store the position of the tag "position="
- tempqwer=tempabcd.substr(tagposition+9, tempabcd.find(";", tagposition)-9-tagposition); //content of tag "position="
- Chars[Chars_index].posx=Evaluate(tempqwer.substr(0, tempqwer.find(","))); //Evaluate the first x parameter and assign it
- Chars[Chars_index].posy=Evaluate(tempqwer.substr(tempqwer.find(",")+1)); //Evaluate the second y parameter and assign it
- tagposition=tempabcd.find("key="); //store the position of the tag "key="
- tempqwer=tempabcd.substr(tagposition+4, tempabcd.find(";", tagposition)-4-tagposition); //content of tag "key="
- Chars[Chars_index].key=Evaluate(tempqwer); //Evaluate and assign
- tagposition=tempabcd.find("left="); //store the position of the tag "left="
- if (tagposition!=string::npos){
- tempqwer=tempabcd.substr(tagposition+5, tempabcd.find(";", tagposition)-5-tagposition); //content of tag "left="
- Chars[Chars_index].left=Evaluate(tempqwer); //Evaluate and assign
- }
- tagposition=tempabcd.find("right="); //store the position of the tag "right="
- if (tagposition!=string::npos){
- tempqwer=tempabcd.substr(tagposition+6, tempabcd.find(";", tagposition)-6-tagposition); //content of tag "right="
- Chars[Chars_index].right=Evaluate(tempqwer); //Evaluate and assign
- }
- tagposition=tempabcd.find("up="); //store the position of the tag "up="
- if (tagposition!=string::npos){
- tempqwer=tempabcd.substr(tagposition+3, tempabcd.find(";", tagposition)-3-tagposition); //content of tag "up="
- Chars[Chars_index].up=Evaluate(tempqwer); //Evaluate and assign
- }
- tagposition=tempabcd.find("down="); //store the position of the tag "down="
- if (tagposition!=string::npos){
- tempqwer=tempabcd.substr(tagposition+5, tempabcd.find(";", tagposition)-5-tagposition); //content of tag "down="
- Chars[Chars_index].down=Evaluate(tempqwer); //Evaluate and assign
- }
- Chars_index++; //done, so we increment the index value
- tagposition=tempasdf.find("]", tempasdf.find("[id=")); //we check again if any other [id= tags exists
- }
- }
- void LoadMenuStuff::Update_Interface(){
- if (MenuID==10){
- BlitTexture(CharMenuBG, CharMenuBG_x, CharMenuBG_y);
- for (int indx=0; indx<Chars_index; indx++){ //we loop on every character on the selection
- if (SelectionCurr_key==Chars[indx].key){ //if this character is highlighted
- BlitTexture(Chars[indx].tex, Chars[indx].posx, Chars[indx].posy); //we render the highligting image here.
- /*0 means that the buttons isn't held nor clicked,
- 1 means that the buttons is clicked
- 2 means that the buttons has been clicked but is still being held */
- P1_INPUTDATA[0]=A_UP&&P1_INPUTDATA[0]==0?1:P1_INPUTDATA[0];
- P1_INPUTDATA[0]=!A_UP&&P1_INPUTDATA[0]==2?0:P1_INPUTDATA[0];
- P1_INPUTDATA[1]=A_DOWN&&P1_INPUTDATA[1]==0?1:P1_INPUTDATA[1];
- P1_INPUTDATA[1]=!A_DOWN&&P1_INPUTDATA[1]==2?0:P1_INPUTDATA[1];
- P1_INPUTDATA[2]=A_LEFT&&P1_INPUTDATA[2]==0?1:P1_INPUTDATA[2];
- P1_INPUTDATA[2]=!A_LEFT&&P1_INPUTDATA[2]==2?0:P1_INPUTDATA[2];
- P1_INPUTDATA[3]=A_RIGHT&&P1_INPUTDATA[3]==0?1:P1_INPUTDATA[3];
- P1_INPUTDATA[3]=!A_RIGHT&&P1_INPUTDATA[3]==2?0:P1_INPUTDATA[3];
- if (Chars[indx].up!=4321){
- if (P1_INPUTDATA[0]==1){
- SelectionCurr_key=Chars[indx].up;
- P1_INPUTDATA[0]=2;
- }
- }
- if (Chars[indx].down!=4321){
- if (P1_INPUTDATA[1]==1){
- SelectionCurr_key=Chars[indx].down;
- P1_INPUTDATA[1]=2;
- }
- }
- if (Chars[indx].left!=4321){
- if (P1_INPUTDATA[2]==1){
- SelectionCurr_key=Chars[indx].left;
- P1_INPUTDATA[2]=2;
- }
- }
- if (Chars[indx].right!=4321){
- if (P1_INPUTDATA[3]==1){
- SelectionCurr_key=Chars[indx].right;
- P1_INPUTDATA[3]=2;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement