]> git.jsancho.org Git - lugaru.git/commitdiff
improved text input handling
authorsf17k <sf171k@gmail.com>
Sat, 7 May 2011 05:35:31 +0000 (01:35 -0400)
committersf17k <sf171k@gmail.com>
Sat, 7 May 2011 05:35:31 +0000 (01:35 -0400)
Source/Game.cpp
Source/GameTick.cpp

index 66aafdf565c0afcc003bf3f63e820fb659f39980..9cdf9eb1ca3a5164dd904b29c2a4b7cc6c6c3c20 100644 (file)
@@ -243,27 +243,30 @@ void Game::inputText(char* str, int* charselected, int* nb_chars) {
        switch(evenement.type) {
                case SDL_KEYDOWN:
                        if(evenement.key.keysym.sym == SDLK_ESCAPE) {
-                               for(i=0;i<255;i++){
-                                       str[i]=' ';
-                               }
+                               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++){
+                                       for(i=(*charselected)-1;i<255;i++)
                                                str[i]=str[i+1];
-                                       }
-                                       str[255]=' ';
+                                       str[255]=0;
                                        (*charselected)--;
                                        (*nb_chars)--;
                                }
                        } else if(evenement.key.keysym.sym==SDLK_DELETE){
-                               for(i=(*charselected);i<255;i++){
-                                       str[i]=str[i+1];
-                               }
-                               str[255]=' ';
-                               (*nb_chars)--;
+                               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)--;
@@ -272,10 +275,9 @@ void Game::inputText(char* str, int* charselected, int* nb_chars) {
                                        (*charselected)++;
                        } else if(evenement.key.keysym.sym==SDLK_RETURN) {
                                waiting=false;
-                       } else if((evenement.key.keysym.unicode<127)&&((*nb_chars)<60)&&(evenement.key.keysym.sym!=SDLK_LSHIFT)&&(evenement.key.keysym.sym!=SDLK_RSHIFT)) {
-                               for(i=255;i>=(*charselected)+1;i--){
+                       } 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)++;
index 9314be18ddbb6bbb42f1e4cde6c6cf9ccf2a809c..326d9fd1c07b55b94356db20c5ba085576e8f761 100644 (file)
@@ -2451,7 +2451,7 @@ void Game::MenuTick(){
                     mainmenu=1;
 
                     for(int j=0;j<255;j++){
-                        displaytext[0][j]=' ';
+                        displaytext[0][j]=0;
                     }
                     displaychars[0]=0;
                     displayselected=0;
@@ -2536,7 +2536,7 @@ void Game::MenuTick(){
                 fireSound(firestartsound);
 
                 for(int i=0;i<255;i++){
-                    displaytext[0][i]=' ';
+                    displaytext[0][i]=0;
                 }
                 displaychars[0]=0;
 
@@ -6047,13 +6047,6 @@ void Game::Tick(){
                if(!winfreeze)leveltime+=multiplier;
 
         //keys
-               if(Input::isKeyDown(SDLK_ESCAPE)){
-                       chatting=0;
-                       console=0;
-                       freeze=0;
-                       displaychars[0]=0;
-               }
-
                if(Input::isKeyPressed(SDLK_v)&&debugmode){
                        freeze=1-freeze;
                        if(freeze){
@@ -6068,9 +6061,8 @@ void Game::Tick(){
                        inputText(displaytext[0],&displayselected,&displaychars[0]);
                        if(!waiting) {
                                if(displaychars[0]){
-                                       for(int j=0;j<255;j++){
-                                               displaytext[0][j]=' ';
-                                       }
+                                       for(int j=0;j<255;j++)
+                                               displaytext[0][j]=0;
                                        displaychars[0]=0;
                                        displayselected=0;
                                }       
@@ -6102,18 +6094,16 @@ void Game::Tick(){
                        inputText(consoletext[0],&consoleselected,&consolechars[0]);
                        if(!waiting) {
                                archiveselected=0;
-                               cmd_dispatch(this, consoletext[0]);
                                if(consolechars[0]>0){
-
+                    consoletext[0][consolechars[0]]=' ';
+                    cmd_dispatch(this, consoletext[0]);
                                        for(int k=14;k>=1;k--){
-                                               for(int j=0;j<255;j++){
+                                               for(int j=0;j<255;j++)
                                                        consoletext[k][j]=consoletext[k-1][j];
-                                               }
                                                consolechars[k]=consolechars[k-1];
                                        }
-                                       for(int j=0;j<255;j++){
-                                               consoletext[0][j]=' ';
-                                       }
+                                       for(int j=0;j<255;j++)
+                                               consoletext[0][j]=0;
                                        consolechars[0]=0;
                                        consoleselected=0;
                                }
@@ -6153,11 +6143,15 @@ void Game::Tick(){
                if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
                        if(winfreeze)
                 winfreeze=0;
-               if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon)
-                       if(winfreeze){
+               if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
+            if(console){
+                console=0;
+                freeze=0;
+            }else if(winfreeze){
                                mainmenu=9;
                                gameon=0;
                        }
+        }