Page principale   Liste des namespaces   Hiérarchie des classes   Liste par ordre alphabétique   Liste des composants   Liste des fichiers   Composants   Déclarations  

ExManagerConsole.cpp

Aller à la documentation de ce fichier.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020  * $Id: ExManagerConsole.cpp,v 1.28 2002/08/06 16:52:59 binny Exp $
00021  *
00022  */
00023 
00024 #include "ExManagerConsole.h"
00025 
00026 ExManagerConsole::ExManagerConsole(void)
00027 {
00028 Guard(ExManagerConsole::ExManagerConsole(void))
00029         m_ConsoleState=HIDE;
00030         m_LineCounter=2;
00031         PosIntoBuffOldCommand=0;
00032         m_ConsoleTransPalier=20;
00033         m_fBlending=0.3f;
00034         m_fBackGroundBlue=1.0f;
00035         m_fBackGroundRed=1.0f;
00036         m_fBackGroundGreen=1.0f;
00037         console_move = false;
00038         m_BackGroundTextureState=true;
00039         m_Blending = false;
00040         LogConsol =true;
00041         #ifdef UNIX_SRC
00042         logfilecsl.open("/tmp/logConsol.txt",ios::out);
00043         #else
00044         logfilecsl.open("logConsol.txt",ios::out);
00045         #endif
00046         logfilecsl.close();
00047 UnGuard
00048 }
00049 
00050 
00051 void ExManagerConsole::Reset(void)
00052 {
00053 Guard(ExManagerConsole::Reset(void))
00054         m_ConsoleState=HIDE;
00055         m_LineCounter=2;
00056         PosIntoBuffOldCommand=0;
00057         m_ConsoleTransPalier=20;
00058         //m_BufferConsol.clear();
00059         m_VecStringAction.clear();
00060 //      SetConsoleBackGroudTexture("back2.tga");
00061         console_move = false;
00062 UnGuard
00063 }
00064 
00065 ExManagerConsole::~ExManagerConsole(void)
00066 {
00067 Guard(ExManagerConsole::~ExManagerConsole(void))
00068 UnGuard
00069 }
00070 
00071 void ExManagerConsole::Init(void)
00072 {
00073 Guard(void ExManagerConsole::init(void))
00074         SetConsoleBackGroudTexture("back.bmp");
00075 UnGuard
00076 }
00077 
00078 
00079 void ExManagerConsole::SetConsoleBackGroudTexture(const char *FileName)
00080 {
00081 Guard(void ExManagerConsole::SetConsoleBackGroudTexture(const char *FileName))
00082         m_BackGroundTexture = new char[strlen(FileName)];
00083         memset(m_BackGroundTexture,0,strlen(FileName));
00084         sprintf(m_BackGroundTexture,"%s",FileName);
00085         ManagerTexture->AddTexture(m_BackGroundTexture);        
00086 UnGuard
00087 }
00088 void ExManagerConsole::DrawConsole(void)
00089 {
00090 Guard(void ExManagerConsole::DrawConsole(void))
00091         int i=0;
00092         float   textcoordy=0;
00093         float   cordy=0;
00094         char buffer[80];
00095         sprintf(buffer,"version %s ",VERSION);
00096         
00097         char bufferdata[255];
00098         sprintf(bufferdata,"]%s",m_BuffCommand.data());
00099 
00100         switch(m_ConsoleState)
00101         {
00102         case HIDE:
00103                 ManagerWindow->SetConsoleState(false);
00104                 break;
00105 
00106         case HALF:
00107                 textcoordy=0.5f;
00108                 cordy=ManagerWindow->GetResolutionY()/2;
00109                 break;
00110 
00111         case FULL:
00112                 textcoordy=1.0f;
00113                 cordy=ManagerWindow->GetResolutionY();
00114                 break;
00115 
00116         case HIDETOHALF:
00117                 //cout<<"Draw hide to half "<<endl;
00118                 textcoordy=(1.0f/m_ConsoleTransPalier)*m_ConsoleTrans;
00119                 cordy=(ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans;
00120                 m_ConsoleTrans++;
00121                 if(cordy>((ManagerWindow->GetResolutionY()/2)-(ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)))
00122                 {
00123                         m_ConsoleState=m_NextConsoleState;
00124                 }
00125                 break;
00126 
00127         case HIDETOFULL:
00128                 //cout<<"Draw hide to full "<<endl;
00129                 textcoordy=((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
00130                 cordy=(ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans;
00131                 m_ConsoleTrans++;
00132                 if(cordy>(ManagerWindow->GetResolutionY()))
00133                 {
00134                         m_ConsoleState=m_NextConsoleState;
00135                 }
00136                 break;
00137 
00138         case HALFTOFULL:
00139                 //cout<<"Draw half to full"<<endl;
00140                 textcoordy=((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans)+0.5f;
00141                 cordy=((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans)+ManagerWindow->GetResolutionY()/2;
00142                 m_ConsoleTrans++;
00143                 if(cordy>(ManagerWindow->GetResolutionY()))
00144                 {
00145                         m_ConsoleState=m_NextConsoleState;
00146                 }
00147                 break;
00148 
00149         case FULLTOHIDE:
00150                 //cout<<"Draw full to hide"<<endl;
00151                 textcoordy=1.0f-((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
00152                 cordy=ManagerWindow->GetResolutionY()-((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans);
00153                 m_ConsoleTrans++;
00154                 if(cordy<0)
00155                 {
00156                         m_ConsoleState=m_NextConsoleState;
00157                 }
00158                 break;
00159 
00160         case FULLTOHALF:
00161                 //cout<<"Draw full to half"<<endl;
00162                 textcoordy=1.0f-((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
00163                 cordy=(ManagerWindow->GetResolutionY())-((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans);
00164                 m_ConsoleTrans++;
00165                 if(cordy<ManagerWindow->GetResolutionY()/2)
00166                 {
00167                         m_ConsoleState=m_NextConsoleState;
00168                 }
00169                 break;
00170  
00171         case HALFTOHIDE:
00172                 //cout<<"Draw half to hide"<<endl;
00173                 textcoordy=0.5f-((1.0f/m_ConsoleTransPalier)*m_ConsoleTrans);
00174                 cordy=(ManagerWindow->GetResolutionY()/2)-((ManagerWindow->GetResolutionY()/m_ConsoleTransPalier)*m_ConsoleTrans);
00175                 m_ConsoleTrans++;
00176                 if(cordy<0)
00177                 {
00178                         m_ConsoleState=m_NextConsoleState;
00179                 }
00180                 break;
00181         }
00182         //-------------------
00183         //Draw back console
00184         //-------------------
00185         
00186         ManagerWindow->EnterOrthoMode(0,0,ManagerWindow->GetResolutionX(),ManagerWindow->GetResolutionY());
00187         glPushAttrib(GL_ALL_ATTRIB_BITS);
00188         if(m_BackGroundTextureState)glEnable(GL_TEXTURE_2D);
00189         glDisable(GL_LIGHTING);
00190         glDisable(GL_DEPTH_TEST);
00191         ManagerTexture->SetActiveTexture(m_BackGroundTexture);
00192         if(m_Blending)
00193         {
00194                 glColor4f(m_fBackGroundRed,m_fBackGroundGreen,m_fBackGroundBlue,m_fBlending);
00195                 glEnable(GL_BLEND);
00196                 glEnable(GL_ALPHA);
00197                 glBlendFunc(GL_ONE,GL_ONE);
00198                 glEnable(GL_ALPHA_TEST);
00199                 glAlphaFunc(GL_GREATER,0);
00200                 glDisable(GL_LIGHTING);
00201                 glBegin(GL_QUADS);
00202                         glTexCoord2f(0.0f, textcoordy);         glVertex2f(0, 0);
00203                         glTexCoord2f(0.0f, 0.0f);                       glVertex2f(0,cordy );
00204                         glTexCoord2f(1.0f, 0.0f);                       glVertex2f(ManagerWindow->GetResolutionX(),cordy);
00205                         glTexCoord2f(1.0f, textcoordy );        glVertex2f(ManagerWindow->GetResolutionX(),0);
00206                 glEnd();
00207         }else
00208         {
00209                 glColor4f(1,1,1,1);
00210                 glBegin(GL_QUADS);
00211                         glTexCoord2f(0.0f, textcoordy);         glVertex2f(0, 0);
00212                         glTexCoord2f(0.0f, 0.0f);                       glVertex2f(0,cordy );
00213                         glTexCoord2f(1.0f, 0.0f);                       glVertex2f(ManagerWindow->GetResolutionX(),cordy);
00214                         glTexCoord2f(1.0f, textcoordy );        glVertex2f(ManagerWindow->GetResolutionX(),0);
00215                 glEnd();
00216         }
00217         glPopAttrib();
00218 
00219     //-------------------
00220         //Draw credits
00221         //-------------------
00222         glColor4f(0,0,1,1);
00223         
00224         RenderBitmapString(ManagerWindow->GetResolutionX()-160,cordy-40,GLUT_BITMAP_8_BY_13,"ExNihilo Engine ");
00225         RenderBitmapString(ManagerWindow->GetResolutionX()-160,cordy-30,GLUT_BITMAP_8_BY_13,buffer);
00226         RenderBitmapString(ManagerWindow->GetResolutionX()-160,cordy-20,GLUT_BITMAP_8_BY_13,"Plok Software");
00227         //-------------------
00228         //Draw buffer console
00229         //-------------------
00230         glColor3f(0.2,0,0);
00231         
00232         std::string             bufferstring,bufferstring2;
00233         
00234         bufferstring=Consol->rdbuf( )->str();
00235         Consol->freeze(false);
00236         Consol->clear();
00237         Consol->flush();
00238         m_LineInConsol=0;
00239         do
00240         {
00241                 bufferstring2 = bufferstring.substr(0,bufferstring.find ( "\n" ,0));
00242                 bufferstring.erase(0,bufferstring.find ( "\n" ,0)+1);
00243                 do
00244                 {
00245                         if(bufferstring2.size()>(unsigned)(ManagerWindow->GetResolutionX()/8)-1)
00246                         {
00247                                 m_BufferConsol.push_back(bufferstring2.substr(0,((int)(ManagerWindow->GetResolutionX()/8))-1));
00248                                 bufferstring2=bufferstring2.substr(((int)(ManagerWindow->GetResolutionX()/8))-1,bufferstring2.size());
00249                                 m_LineInConsol++;
00250             }else
00251                         {
00252                                 m_BufferConsol.push_back(bufferstring2);
00253                                 m_LineInConsol++;
00254                                 break;
00255                         }
00256                 }while(1);
00257         }while((unsigned)-1 != bufferstring.find( "\n" ,0));
00258 
00259         if(LogConsol=true)
00260         {
00261                 logfilecsl.open("logConsol.txt",ios::out);
00262                 i=0;
00263                 for(m_ItBufferConsol=m_BufferConsol.begin();m_ItBufferConsol!=m_BufferConsol.end();m_ItBufferConsol++,i++)
00264                 {
00265                         logfilecsl<<i<<"::"<<m_ItBufferConsol->data()<<std::endl;                                       
00266                 }
00267                 logfilecsl.close();
00268         }
00269         i=0;
00270 
00271         for(m_RItBufferConsol=m_BufferConsol.rbegin();i<m_LineToStar;i++)
00272         {
00273                 m_RItBufferConsol++;    
00274         }
00275 
00276         for(i=0;m_RItBufferConsol!=m_BufferConsol.rend();m_RItBufferConsol++,i++)
00277         {
00278                 RenderBitmapString(10,cordy-(10*i)-20,GLUT_BITMAP_8_BY_13,m_RItBufferConsol->data());   
00279                 if(i*10>cordy)break;
00280         }
00281         m_BufferConsol.clear();
00282         
00283         RenderBitmapString(10,cordy-10,GLUT_BITMAP_8_BY_13,bufferdata);
00284         glEnable(GL_DEPTH_TEST);
00285         glEnable(GL_LIGHTING);
00286         glDisable(GL_TEXTURE_2D);
00287         ManagerWindow->LeaveOrthoMode();        
00288         
00289         if (m_ConsoleState == m_NextConsoleState && console_move == true) {
00290                 console_move = false;
00291         }
00292         
00293         //DrawBuffer(); 
00294 UnGuard
00295 }
00296 
00297 void ExManagerConsole::LineUp(void)
00298 {
00299         m_LineToStar++;
00300         if(m_LineToStar>m_LineInConsol)m_LineToStar=m_LineInConsol;
00301 }
00302 void ExManagerConsole::LineDown(void)
00303 {
00304         m_LineToStar--;
00305         if(m_LineToStar<0){m_LineToStar=0;}
00306 }
00307 
00308 void ExManagerConsole::ConsoleMove (bool p) {
00309         console_move = p;
00310 }
00311 
00312 void ExManagerConsole::SetConsoleState(int state)
00313 {
00314 Guard(void ExManagerConsole::SetConsoleState(int state))
00315         //cout<<"set console state :"<<state<<endl;
00316         ManagerWindow->SetConsoleState(true);
00317         switch(m_ConsoleState)
00318         {
00319         case HIDE:
00320                 m_NextConsoleState=state;
00321                 switch(state)
00322                 {
00323                 case HALF:
00324                         m_ConsoleState=HIDETOHALF;
00325                         break;
00326                 case FULL:
00327                         m_ConsoleState=HIDETOFULL;
00328                         break;
00329                 }
00330                 break;
00331         case HALF:
00332                 m_NextConsoleState=state;
00333                 switch(state)
00334                 {
00335                 case FULL:
00336                         m_ConsoleState=HALFTOFULL;
00337                         break;
00338                 case HIDE:
00339                         m_ConsoleState=HALFTOHIDE;
00340                         break;
00341                 }
00342                 break;
00343         case FULL:
00344                 m_NextConsoleState=state;
00345                 switch(state)
00346                 {
00347                 case HALF:
00348                         m_ConsoleState=FULLTOHALF;
00349                         break;
00350                 case HIDE:
00351                         m_ConsoleState=FULLTOHIDE;
00352                         break;
00353                 }
00354                 break;
00355         }
00356         m_ConsoleTrans=1;
00357 UnGuard
00358 }
00359 
00360 int ExManagerConsole::NextAviableState(void) {
00361 Guard(int ExManagerConsole::NextAviableState(void))
00362         switch(m_ConsoleState) {
00363                 case HIDE: return HALF;
00364                 case HALF: return FULL;
00365                 case FULL: return HIDE;
00366                 case HIDETOHALF : return HALF;
00367                 case HIDETOFULL : return FULL;
00368                 case HALFTOFULL : return FULL;
00369                 case FULLTOHALF : return HALF;
00370                 case FULLTOHIDE : return HIDE;
00371                 case HALFTOHIDE : return HIDE;
00372                 default: return HALF;
00373         }
00374 UnGuard
00375 }
00376 
00377 void ExManagerConsole::Write(const char *Label)
00378 {
00379 Guard(void ExManagerConsole::Write(const char *Label))
00380         //*Consol<<"<<==================Write to consol===========================>>"<<std::endl;
00381         *Consol << Label << std::endl;
00382         //*Consol<<"<<============================================================>>"<<std::endl;
00383 UnGuard
00384 }
00385 
00386 SAction ExManagerConsole::InputCommand(int command,int mousex,int mousey)
00387 {
00388 Guard(SAction ExManagerConsole::InputCommand(int command,int mousex,int mousey))
00389         switch(command)
00390         {
00391         case KEYBOARD_DOWN_EXP: 
00392                 return CONSOL_NEXT_AVIABLE_STATE;       
00393         
00394         case KEYBOARD_DOWN_ESC: 
00395                 return HIDE_CONSOL;
00396         
00397         case KEYBOARD_DOWN_A:
00398                 m_BuffCommand.append("a"); 
00399                 return NOTHING;
00400         
00401         case KEYBOARD_DOWN_Z:
00402                 m_BuffCommand.append("z");
00403                 return NOTHING;
00404         
00405         case KEYBOARD_DOWN_E:
00406                 m_BuffCommand.append("e");
00407                 return NOTHING;
00408         
00409         case KEYBOARD_DOWN_R:
00410                 m_BuffCommand.append("r");
00411                 return NOTHING;
00412         
00413         case KEYBOARD_DOWN_T:
00414                 m_BuffCommand.append("t");
00415                 return NOTHING;
00416         
00417         case KEYBOARD_DOWN_Y:
00418                 m_BuffCommand.append("y");
00419                 return NOTHING;
00420         
00421         case KEYBOARD_DOWN_U:
00422                 m_BuffCommand.append("u");
00423                 return NOTHING;
00424         case KEYBOARD_DOWN_I:
00425                 m_BuffCommand.append("i");
00426                 return NOTHING;
00427 
00428         case KEYBOARD_DOWN_O:
00429                 m_BuffCommand.append("o");
00430                 return NOTHING;
00431 
00432         case KEYBOARD_DOWN_P:
00433                 m_BuffCommand.append("p");
00434                 return NOTHING;
00435 
00436         case KEYBOARD_DOWN_Q:
00437                 m_BuffCommand.append("q");
00438                 return NOTHING;
00439 
00440         case KEYBOARD_DOWN_S:
00441                 m_BuffCommand.append("s");
00442                 return NOTHING;
00443 
00444         case KEYBOARD_DOWN_D:
00445                 m_BuffCommand.append("d");
00446                 return NOTHING;
00447 
00448         case KEYBOARD_DOWN_F:
00449                 m_BuffCommand.append("f");
00450                 return NOTHING;
00451 
00452         case KEYBOARD_DOWN_G:
00453                 m_BuffCommand.append("g");
00454                 return NOTHING;
00455 
00456         case KEYBOARD_DOWN_H:
00457                 m_BuffCommand.append("h");
00458                 return NOTHING;
00459 
00460         case KEYBOARD_DOWN_J:
00461                 m_BuffCommand.append("j");
00462                 return NOTHING;
00463 
00464         case KEYBOARD_DOWN_K:
00465                 m_BuffCommand.append("k");
00466                 return NOTHING;
00467 
00468         case KEYBOARD_DOWN_L:
00469                 m_BuffCommand.append("l");
00470                 return NOTHING;
00471 
00472         case KEYBOARD_DOWN_M:
00473                 m_BuffCommand.append("m");
00474                 return NOTHING;
00475 
00476         case KEYBOARD_DOWN_W:
00477                 m_BuffCommand.append("w");
00478                 return NOTHING;
00479 
00480         case KEYBOARD_DOWN_X:
00481                 m_BuffCommand.append("x");
00482                 return NOTHING;
00483 
00484         case KEYBOARD_DOWN_C:
00485                 m_BuffCommand.append("c");
00486                 return NOTHING;
00487 
00488         case KEYBOARD_DOWN_V:
00489                 m_BuffCommand.append("v");
00490                 return NOTHING;
00491 
00492         case KEYBOARD_DOWN_B:
00493                 m_BuffCommand.append("b");
00494                 return NOTHING;
00495 
00496         case KEYBOARD_DOWN_N:
00497                 m_BuffCommand.append("n");
00498                 return NOTHING;
00499         
00500         case KEYBOARD_DOWN_M_A:
00501                 m_BuffCommand.append("A"); 
00502                 return NOTHING;
00503         
00504         case KEYBOARD_DOWN_M_Z:
00505                 m_BuffCommand.append("Z");
00506                 return NOTHING;
00507         
00508         case KEYBOARD_DOWN_M_E:
00509                 m_BuffCommand.append("E");
00510                 return NOTHING;
00511         
00512         case KEYBOARD_DOWN_M_R:
00513                 m_BuffCommand.append("R");
00514                 return NOTHING;
00515         
00516         case KEYBOARD_DOWN_M_T:
00517                 m_BuffCommand.append("T");
00518                 return NOTHING;
00519         
00520         case KEYBOARD_DOWN_M_Y:
00521                 m_BuffCommand.append("Y");
00522                 return NOTHING;
00523         
00524         case KEYBOARD_DOWN_M_U:
00525                 m_BuffCommand.append("U");
00526                 return NOTHING;
00527         case KEYBOARD_DOWN_M_I:
00528                 m_BuffCommand.append("I");
00529                 return NOTHING;
00530 
00531         case KEYBOARD_DOWN_M_O:
00532                 m_BuffCommand.append("O");
00533                 return NOTHING;
00534 
00535         case KEYBOARD_DOWN_M_P:
00536                 m_BuffCommand.append("P");
00537                 return NOTHING;
00538 
00539         case KEYBOARD_DOWN_M_Q:
00540                 m_BuffCommand.append("Q");
00541                 return NOTHING;
00542 
00543         case KEYBOARD_DOWN_M_S:
00544                 m_BuffCommand.append("S");
00545                 return NOTHING;
00546 
00547         case KEYBOARD_DOWN_M_D:
00548                 m_BuffCommand.append("D");
00549                 return NOTHING;
00550 
00551         case KEYBOARD_DOWN_M_F:
00552                 m_BuffCommand.append("F");
00553                 return NOTHING;
00554 
00555         case KEYBOARD_DOWN_M_G:
00556                 m_BuffCommand.append("G");
00557                 return NOTHING;
00558 
00559         case KEYBOARD_DOWN_M_H:
00560                 m_BuffCommand.append("H");
00561                 return NOTHING;
00562 
00563         case KEYBOARD_DOWN_M_J:
00564                 m_BuffCommand.append("J");
00565                 return NOTHING;
00566 
00567         case KEYBOARD_DOWN_M_K:
00568                 m_BuffCommand.append("K");
00569                 return NOTHING;
00570 
00571         case KEYBOARD_DOWN_M_L:
00572                 m_BuffCommand.append("L");
00573                 return NOTHING;
00574 
00575         case KEYBOARD_DOWN_M_M:
00576                 m_BuffCommand.append("M");
00577                 return NOTHING;
00578 
00579         case KEYBOARD_DOWN_M_W:
00580                 m_BuffCommand.append("W");
00581                 return NOTHING;
00582 
00583         case KEYBOARD_DOWN_M_X:
00584                 m_BuffCommand.append("X");
00585                 return NOTHING;
00586 
00587         case KEYBOARD_DOWN_M_C:
00588                 m_BuffCommand.append("C");
00589                 return NOTHING;
00590 
00591         case KEYBOARD_DOWN_M_V:
00592                 m_BuffCommand.append("V");
00593                 return NOTHING;
00594 
00595         case KEYBOARD_DOWN_M_B:
00596                 m_BuffCommand.append("B");
00597                 return NOTHING;
00598 
00599         case KEYBOARD_DOWN_M_N:
00600                 m_BuffCommand.append("N");
00601                 return NOTHING;
00602 
00603         case KEYBOARD_DOWN_0:
00604                 m_BuffCommand.append("0");
00605                 return NOTHING;
00606 
00607         case KEYBOARD_DOWN_1:
00608                 m_BuffCommand.append("1");
00609                 return NOTHING;
00610 
00611         case KEYBOARD_DOWN_2:
00612                 m_BuffCommand.append("2");
00613                 return NOTHING;
00614 
00615         case KEYBOARD_DOWN_3:
00616                 m_BuffCommand.append("3");
00617                 return NOTHING;
00618 
00619         case KEYBOARD_DOWN_4:
00620                 m_BuffCommand.append("4");
00621                 return NOTHING;
00622 
00623         case KEYBOARD_DOWN_5:
00624                 m_BuffCommand.append("5");
00625                 return NOTHING;
00626 
00627         case KEYBOARD_DOWN_6:
00628                 m_BuffCommand.append("6");
00629                 return NOTHING;
00630 
00631         case KEYBOARD_DOWN_7:
00632                 m_BuffCommand.append("7");
00633                 return NOTHING;
00634 
00635         case KEYBOARD_DOWN_8:
00636                 m_BuffCommand.append("8");
00637                 return NOTHING;
00638 
00639         case KEYBOARD_DOWN_9:
00640                 m_BuffCommand.append("9");
00641                 return NOTHING;
00642 
00643         case KEYBOARD_DOWN__:
00644                 m_BuffCommand.append("_");
00645                 return NOTHING;
00646 
00647         case KEYBOARD_DOWN_2POINTS:
00648                 m_BuffCommand.append(":");
00649                 return NOTHING;
00650 
00651         case KEYBOARD_DOWN_POINT:
00652                 m_BuffCommand.append(".");
00653                 return NOTHING;
00654 
00655         case KEYBOARD_UP_PAGE_UP:
00656                 LineUp();
00657                 return NOTHING;
00658         
00659         case KEYBOARD_UP_PAGE_DOWN:
00660                 LineDown();
00661                 return NOTHING;
00662 
00663         case KEYBOARD_DOWN_SPACE:
00664                 m_BuffCommand.append(" ");
00665                 return NOTHING;
00666 
00667         case KEYBOARD_DOWN_ENTER:
00668                 return ApplyBuffCommand();
00669         
00670         case KEYBOARD_DOWN_TAB: {
00671                 std::vector<std::string> vec_tmp;
00672                 std::vector<std::string>::iterator i_tmp;
00673                 
00674                 vec_tmp.push_back ("load");
00675                 vec_tmp.push_back ("cmd");
00676                 vec_tmp.push_back ("help");
00677                 vec_tmp.push_back ("clear");
00678                 vec_tmp.push_back ("quit");
00679                 
00680                 for (m_ItVecStringAction = m_VecStringAction.begin(); m_ItVecStringAction != m_VecStringAction.end(); m_ItVecStringAction++) {
00681                         vec_tmp.push_back (m_ItVecStringAction->first);
00682                 }
00683                 
00684                 i_tmp = vec_tmp.begin ();
00685                 std::string tmp;
00686                 
00687                 while (i_tmp != vec_tmp.end ()) {
00688                         tmp = *i_tmp++;
00689                 
00690                         if (tmp.find (m_BuffCommand) == 0) {
00691                                 if (tmp.find (' ') < tmp.length ())
00692                                         m_BuffCommand = tmp.substr (0, tmp.find (' '));
00693                                 else m_BuffCommand = tmp;
00694                                 //m_BuffCommand += ' '; // this add a space after command
00695                                 // but it sucks with some commands like quit :/
00696                         }
00697                 }
00698                 return NOTHING;
00699         }
00700         case KEYBOARD_DOWN_CTRL_U:
00701                 m_BuffCommand = ""; 
00702                 return NOTHING;
00703         
00704         case KEYBOARD_UP_ARROW_DOWN:
00705                 PosIntoBuffOldCommand++;
00706                 if(PosIntoBuffOldCommand<(int)m_BuffOldCommand.size()&&PosIntoBuffOldCommand>=-1)
00707                 {
00708                         m_BuffCommand=m_BuffOldCommand.at(PosIntoBuffOldCommand);                       
00709                 }else
00710                 {
00711                         PosIntoBuffOldCommand=0;
00712                 }
00713 
00714 
00715                 return NOTHING;
00716         
00717         case KEYBOARD_UP_ARROW_UP:
00718                 PosIntoBuffOldCommand--;
00719                 if(PosIntoBuffOldCommand<(int)m_BuffOldCommand.size()&&PosIntoBuffOldCommand>=0)
00720                 {
00721                         m_BuffCommand=m_BuffOldCommand.at(PosIntoBuffOldCommand);                       
00722                 }else
00723                 {
00724                         PosIntoBuffOldCommand=0;
00725                 }
00726                 return NOTHING;
00727         
00728         case KEYBOARD_UP_ARROW_LEFT:
00729                 if(m_BuffCommand.size()>0)
00730                 {
00731                         m_BuffCommand.erase(m_BuffCommand.end()-1,m_BuffCommand.end());
00732                 }
00733                 return NOTHING;
00734         
00735         case KEYBOARD_UP_BACKSPACE:
00736                 if(m_BuffCommand.size()>0)
00737                 {
00738                         m_BuffCommand.erase(m_BuffCommand.end()-1,m_BuffCommand.end());
00739                 }
00740                 return NOTHING;
00741 
00742         default :return NOTHING;
00743         }
00744 UnGuard
00745 }
00746 
00747 void ExManagerConsole::ListConsoleCommand(void)
00748 {
00749 Guard(void ExManagerConsole::ListConsoleCommand(void))
00750         *Consol<<"*******************************"<<std::endl;
00751         *Consol<<"*List of all available command*"<<std::endl;
00752         *Consol<<"*******************************"<<std::endl;
00753         *Consol<<"load 'FILENAME'"<<std::endl;
00754         *Consol<<"cmd 'number of command'"<<std::endl;;
00755         *Consol<<"help 'command'"<<std::endl;
00756         *Consol<<"clear 'clear console screen'"<<std::endl;
00757         *Consol<<"quit 'exit ExNihilo'"<<std::endl;
00758         int i=PREDIFINEDCOMMAND;
00759         for(m_ItVecStringAction=m_VecStringAction.begin(); m_ItVecStringAction != m_VecStringAction.end(); m_ItVecStringAction++, i++) 
00760         {
00761                 *Consol<<i<<") "<<m_ItVecStringAction->first.data()<<std::endl;
00762         }
00763         *Consol<<"*****************************"<<std::endl;
00764 UnGuard
00765 }
00766 
00767 SAction ExManagerConsole::ApplyBuffCommand(void)
00768 {
00769 Guard(SAction ExManagerConsole::ApplyBuffCommand(void))
00770 bool findaction=false;
00771         SAction Action;
00772         Action.m_StartingLife=(double)((double)glutGet(GLUT_ELAPSED_TIME)/1000);
00773         *Consol<<m_BuffCommand.data()<<std::endl;
00774         for(m_ItVecStringAction=m_VecStringAction.begin();m_ItVecStringAction!=m_VecStringAction.end();m_ItVecStringAction++)
00775         {
00776                 if(m_BuffCommand.find(m_ItVecStringAction->first.data())==0)
00777                 {                        
00778                         findaction=true;
00779                         char buffer[255];
00780                         memset(buffer,0,255);
00781                         Action.m_Action=m_ItVecStringAction->second;
00782                         m_BuffCommand.copy(buffer,(m_BuffCommand.size())-(strlen(m_ItVecStringAction->first.data())),strlen(m_ItVecStringAction->first.data()));
00783                         Action.SetParam(buffer);
00784                         m_BuffOldCommand.push_back(m_BuffCommand);
00785                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00786                 }           
00787         }
00788         if(!findaction)
00789         {
00790                 if(strcmp(m_BuffCommand.data(),"clear")==0)
00791                 {
00792                         m_BuffOldCommand.push_back(m_BuffCommand);
00793                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00794                         m_BufferConsol.clear();
00795                         ClearConsol();
00796                         Action.m_Action= NOTHING;
00797                         return Action;
00798                 }
00799                 
00800                 if(m_BuffCommand.find("help")==0)
00801                 {
00802                         ListConsoleCommand();
00803                         m_BuffOldCommand.push_back(m_BuffCommand);
00804                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00805                         Action.m_Action= NOTHING;
00806                         return Action;
00807                 }
00808                 if(m_BuffCommand.find("cmd ")==0)
00809                 {
00810                         int cmd=0;
00811                         char *SBuffer;
00812                         SBuffer=new char[strlen(m_BuffCommand.data())-5] ;
00813                         memset(SBuffer,0,strlen(m_BuffCommand.data()));
00814                         m_BuffCommand.copy(SBuffer,m_BuffCommand.size()-4,4);
00815                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00816                         try
00817                         {
00818                                 cmd=atoi(SBuffer);
00819                                 Action.m_Action= m_VecStringAction.at(cmd-PREDIFINEDCOMMAND).second;
00820                         }catch(...)
00821                         {
00822                                 *Consol<<"Bad argument use list to show command list"<<std::endl;
00823                                 Action.m_Action= NOTHING;
00824                                 return Action;
00825                         }
00826                 }
00827 
00828                 if(strcmp(m_BuffCommand.data(),"quit")==0)
00829                 {
00830                         m_BuffOldCommand.push_back(m_BuffCommand);
00831                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00832                         Action.m_Action= QUIT;
00833                         return Action;
00834                 }
00835                 
00836                 if(strcmp(m_BuffCommand.data(),"reset")==0)
00837                 {
00838                         m_BuffOldCommand.push_back(m_BuffCommand);
00839                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00840                         Action.m_Action= RESET;
00841                         return Action;
00842                 }
00843 
00844                 if(m_BuffCommand.find("load")!=(unsigned)-1)
00845                 {
00846                         char buffer[255];
00847                         memset(buffer,0,255);
00848                         Action.m_Action=LOAD_FILE;
00849                         m_BuffCommand.copy(buffer,m_BuffCommand.size()-4,4);
00850                         Action.SetParam(buffer);
00851                         m_BuffOldCommand.push_back(m_BuffCommand);
00852                         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00853                         return Action;
00854                 }
00855                 
00856                 *Consol<<"Unknow command"<<std::endl;
00857                 m_BuffOldCommand.push_back(m_BuffCommand);
00858                 m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00859                 Action.m_Action= NOTHING;
00860         }
00861         return Action;
00862 UnGuard
00863 }
00864 
00865 void ExManagerConsole::AddStringAction(const char *String,int Action)
00866 {
00867 Guard(void ExManagerConsole::AddStringAction(const char *String,int Action))
00868         StringAction ac;
00869         ac.first=String;
00870         ac.second=Action;
00871         m_VecStringAction.push_back(ac);
00872         *Consol<<"Add new command to console command:"<<String<<" Action:"<<Action<<std::endl;
00873 UnGuard
00874 }
00875 
00876 void ExManagerConsole::AddStringAction(StringAction StrAction)
00877 {
00878 Guard(void ExManagerConsole::AddStringAction(StringAction StrAction))
00879         AddStringAction(StrAction.first.data(),StrAction.second);
00880 UnGuard
00881 }
00882 
00883 void ExManagerConsole::AddStringAction(ExCFileDataAction p) {
00884 Guard(void ExManagerConsole::AddStringAction(ExCFileDataAction p))
00885         StringAction foo;
00886         foo.first = p.getAction();
00887         foo.second = p.getCommand();
00888         AddStringAction(foo);
00889 UnGuard
00890 }
00891 
00892 void ExManagerConsole::LoadStringActionFile(const char *FileName)
00893 {
00894 Guard(void ExManagerConsole::LoadStringActionFile(const char *FileName))
00895     char                        buffer[255];
00896         
00897 #ifdef UNIX_SRC
00898         sprintf(buffer, PREFIX "/ExNihilo/Data/Console/%s", FileName);
00899 #else
00900         sprintf(buffer, "../Data/Console/%s", FileName);
00901 #endif
00902     
00903         ExCFileReader my_file (buffer);
00904         if (! my_file.exist()) 
00905         {
00906                 *Consol<<"File not found: "<<buffer<<std::endl;
00907         } else {
00908                 *Consol<<"Loading Command File: "<<FileName<<std::endl;
00909         
00910                 ExCFileData _data = my_file.getContent();
00911                 if (_data.getType() != FILE_CONSOLE) 
00912                 {
00913                         *Consol<<FileName<<" is not a valide console file"<<std::endl;
00914                 } else 
00915                 {
00916                         vector<ExCFileDataAction> dd = _data.getContent();
00917                         vector<ExCFileDataAction>::iterator i = dd.begin ();
00918                         ExCFileDataAction f;
00919                         while (i != dd.end ()) 
00920                         {
00921                                 f = *i++;
00922                                 AddStringAction (f);
00923                         }
00924                 }
00925         }
00926 UnGuard
00927 }
00928 
00929 void ExManagerConsole::ClearConsol(void)
00930 {
00931 Guard(void ExManagerConsole::ClearConsol(void))
00932         m_BuffOldCommand.push_back(m_BuffCommand);
00933         m_BuffCommand.erase(m_BuffCommand.begin(),m_BuffCommand.end());
00934         m_BufferConsol.clear();
00935 UnGuard
00936 }

Généré le Tue Aug 6 20:25:28 2002 pour ExNihilo par doxygen1.2.17