]> git.jsancho.org Git - lugaru.git/commitdiff
bugfix about the console
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Wed, 18 May 2011 20:08:49 +0000 (22:08 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Wed, 18 May 2011 20:08:49 +0000 (22:08 +0200)
Source/Game.cpp
Source/GameTick.cpp

index 0cc5057361aa86855ff8ff42fa6fc2ddf0f29b6a..8bc4342f3ebf2eb234a07b7a9ddc87fc4fe59caf 100644 (file)
@@ -199,7 +199,6 @@ void Game::fireSound(int sound) {
 
 void Game::inputText(char* str, int* charselected, int* nb_chars) {
        SDL_Event evenement;
-       int i;
        
        if(!waiting) {
                waiting=true;
@@ -207,51 +206,52 @@ void Game::inputText(char* str, int* charselected, int* nb_chars) {
                SDL_EnableUNICODE(true);
        }
 
-       SDL_PollEvent(&evenement);
+       while(SDL_PollEvent(&evenement)) {
        
-       switch(evenement.type) {
-               case SDL_KEYDOWN:
-                       if(evenement.key.keysym.sym == SDLK_ESCAPE) {
-                               for(i=0;i<255;i++)
-                                       str[i]=0;
-                               *nb_chars=0;
-                               *charselected=0;
-                               waiting=false;
-                       } else if(evenement.key.keysym.sym==SDLK_BACKSPACE){
-                               if((*charselected)!=0) {
-                                       for(i=(*charselected)-1;i<255;i++)
-                                               str[i]=str[i+1];
-                                       str[255]=0;
-                                       (*charselected)--;
-                                       (*nb_chars)--;
-                               }
-                       } else if(evenement.key.keysym.sym==SDLK_DELETE){
-                               if((*charselected)<(*nb_chars)){
-                    for(i=(*charselected);i<255;i++)
-                        str[i]=str[i+1];
-                    str[255]=0;
-                    (*nb_chars)--;
-                }
-                       } else if(evenement.key.keysym.sym==SDLK_HOME){
-                (*charselected)=0;
-                       } else if(evenement.key.keysym.sym==SDLK_END){
-                (*charselected)=(*nb_chars);
-                       } else if(evenement.key.keysym.sym==SDLK_LEFT){
-                               if((*charselected)!=0)
-                                       (*charselected)--;
-                       } else if(evenement.key.keysym.sym==SDLK_RIGHT){
-                               if((*charselected)<(*nb_chars))
+               switch(evenement.type) {
+                       case SDL_KEYDOWN:
+                               if(evenement.key.keysym.sym == SDLK_ESCAPE) {
+                                       for(int i=0;i<255;i++)
+                                               str[i]=0;
+                                       *nb_chars=0;
+                                       *charselected=0;
+                                       waiting=false;
+                               } else if(evenement.key.keysym.sym==SDLK_BACKSPACE){
+                                       if((*charselected)!=0) {
+                                               for(int i=(*charselected)-1;i<255;i++)
+                                                       str[i]=str[i+1];
+                                               str[255]=0;
+                                               (*charselected)--;
+                                               (*nb_chars)--;
+                                       }
+                               } else if(evenement.key.keysym.sym==SDLK_DELETE){
+                                       if((*charselected)<(*nb_chars)){
+                                               for(int i=(*charselected);i<255;i++)
+                                                       str[i]=str[i+1];
+                                               str[255]=0;
+                                               (*nb_chars)--;
+                                       }
+                               } else if(evenement.key.keysym.sym==SDLK_HOME){
+                                       (*charselected)=0;
+                               } else if(evenement.key.keysym.sym==SDLK_END){
+                                       (*charselected)=(*nb_chars);
+                               } else if(evenement.key.keysym.sym==SDLK_LEFT){
+                                       if((*charselected)!=0)
+                                               (*charselected)--;
+                               } else if(evenement.key.keysym.sym==SDLK_RIGHT){
+                                       if((*charselected)<(*nb_chars))
+                                               (*charselected)++;
+                               } else if(evenement.key.keysym.sym==SDLK_RETURN) {
+                                       waiting=false;
+                               } else if(evenement.key.keysym.unicode>=32&&evenement.key.keysym.unicode<127&&(*nb_chars)<60){
+                                       for(int i=255;i>=(*charselected)+1;i--)
+                                               str[i]=str[i-1];
+                                       str[*charselected]=evenement.key.keysym.unicode;
                                        (*charselected)++;
-                       } else if(evenement.key.keysym.sym==SDLK_RETURN) {
-                               waiting=false;
-                       } else if(evenement.key.keysym.unicode>=32&&evenement.key.keysym.unicode<127&&(*nb_chars)<60){
-                               for(i=255;i>=(*charselected)+1;i--)
-                                       str[i]=str[i-1];
-                               str[*charselected]=evenement.key.keysym.unicode;
-                               (*charselected)++;
-                               (*nb_chars)++;
-                       }
-               break;
+                                       (*nb_chars)++;
+                               }
+                       break;
+               }
        }
        
        if(!waiting) {
index bad9674fb81c63be55af796b50a4af93c6d50bc6..181802316c8c6d66aba7c43b2739f463763e68b1 100644 (file)
@@ -1101,14 +1101,15 @@ static void ch_skybox(Game *game, const char *args)
   objects.DoShadows();
 }
 
-static void cmd_dispatch(Game *game, const char *cmd)
+static void cmd_dispatch(Game *game, const string cmd)
 {
   int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
 
   for (i = 0; i < n_cmds; i++)
-    if (stripfx(cmd, cmd_names[i]))
+    if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
       {
-               cmd_handlers[i](game, cmd + strlen(cmd_names[i])+1);
+                 cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
+               cmd_handlers[i](game, cmd.substr(cmd.find(' ')+1).c_str());
                break;
       }
   emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);