From 55b9188087248e41adc8ce60f4dd1bfadbc179af Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20BERNIGAUD?= Date: Wed, 18 May 2011 22:08:49 +0200 Subject: [PATCH] bugfix about the console --- Source/Game.cpp | 88 ++++++++++++++++++++++----------------------- Source/GameTick.cpp | 7 ++-- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/Source/Game.cpp b/Source/Game.cpp index 0cc5057..8bc4342 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -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) { diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index bad9674..1818023 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -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); -- 2.39.5