From 7386e93e32575bae21006d0300cbff4cf7a40926 Mon Sep 17 00:00:00 2001 From: oroborus Date: Tue, 8 Jul 2008 16:35:02 +0000 Subject: - oprava chyby v configFile.h - chat sa zapina/vypina ENTERom - prepisany readKey() - widget_textfiled obsahuje filter na znaky :) - lasser je netrhany ale prestreluje pen v arene "na dobru noc", ked sa uplne priblizite git-svn-id: http://opensvn.csie.org/tuxanci_ng@124 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/client/chat.c | 151 +++++++++++++++++++++--------------------------------- 1 file changed, 58 insertions(+), 93 deletions(-) (limited to 'src/client/chat.c') diff --git a/src/client/chat.c b/src/client/chat.c index 7d425dd..b599853 100644 --- a/src/client/chat.c +++ b/src/client/chat.c @@ -26,6 +26,8 @@ static int timeBlick; static bool_t chat_active; static bool_t revicedNewMsg; +static my_time_t lastActive; + void initChat() { g_chat = addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER); @@ -37,6 +39,7 @@ void initChat() line_time = 0; line_atime = 0; timeBlick = 0; + lastActive = 0; } void drawChat() @@ -84,8 +87,8 @@ void drawChat() static void readKey() { Uint8 *mapa; - int len; int w, h; + int len; int i; if (line_atime < 100) @@ -93,134 +96,96 @@ static void readKey() mapa = SDL_GetKeyState(NULL); len = strlen(line); - getTextSize(line, &w, &h); - - // mazanie posledneho klavesu - if( mapa[SDLK_BACKSPACE] == SDL_PRESSED ) + + for( i = SDLK_FIRST ; i <= SDLK_F15 ; i++ ) { - if( len > 0 ) + if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) { - line_time = 0; - line[len-1]='\0'; - } + char *name = (char *) SDL_GetKeyName(i); + char c = '\0'; - return; - } + if( name == NULL )continue; - if( w > CHAT_LINE_WIDTH-40 ) - { - return; - } + if( strlen(name) == 1 )c = name[0]; + if( strlen(name) == 3 )c = name[1]; + if( strcmp(name, "space") == 0 )c = ' '; - // klavesy abecedy - for(i=SDLK_SPACE /*SDLK_a*/;i<=SDLK_z;i++) - { - //if(width 0 ) { - strcat( line, " " ); + line_time = 0; + line[len-1]='\0'; return; } - const char *c = (const char *) SDL_GetKeyName(i); + if( c == '\0' || w > CHAT_SIZE_X-40 ) + { + continue; + } - if (len) { - if (line[len-1] == *c) { - line_time ++; + if( len > 0 ) + { + if( line[len-1] == c ) + { + line_time++; - if ( line_time < CHAT_TIME_MULTIPLE) { - if ( line_atime < 3) - return; + if( line_time < CHAT_TIME_MULTIPLE ) + { + if( line_atime < 3 )return; } - } else + } + else + { line_time = 0; + } } line_atime = 0; - strcat( line, c ); - getTextSize(line, &w, &h); - + line[len] = c; + if( mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { - line[ strlen( line ) - 1 ] -= 32; - return; + line[len] -= 32; } + + return; } } +} - // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice - for( i = SDLK_0 ; i <= SDLK_9 ; i++ ) +static void switchChatActive() +{ + if( chat_active == TRUE ) { - if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) - { - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - if (line[len-1] == *c) { - line_time ++; - - if (line_time < CHAT_TIME_MULTIPLE) { - if (line_atime < 3) - return; - } - } else - line_time = 0; - } - - line_atime = 0; - - strcat( line, c ); - return; - } + chat_active = FALSE; } - - // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici - for( i=SDLK_KP0 ; i<=SDLK_KP9 ; i++ ) + else { - if( mapa[i] == SDL_PRESSED && len < STR_SIZE ) - { - const char *c = (const char *) SDL_GetKeyName(i)+1; - - if (len) { - if (line[len-1] == *c) { - line_time ++; - - if (line_time < CHAT_TIME_MULTIPLE) { - if (line_atime < 3) - return; - } - } else - line_time = 0; - } - - line_atime = 0; - - strncat( line, c, 1 ); // napr. "[4]" - return; - } + chat_active = TRUE; } } void eventChat() { Uint8 *mapa; - - mapa = SDL_GetKeyState(NULL); + my_time_t currentTime; - if( mapa[SDLK_RETURN] == SDL_PRESSED && chat_active == FALSE ) + mapa = SDL_GetKeyState(NULL); + currentTime = getMyTime(); + + if( mapa[SDLK_RETURN] == SDL_PRESSED && + strcmp(line, "") == 0 && + currentTime - lastActive > CHAT_LAST_ENTER_INTERVAL ) { + lastActive = getMyTime(); revicedNewMsg = FALSE; - chat_active = TRUE; - } - - if( mapa[SDLK_ESCAPE] == SDL_PRESSED && chat_active == TRUE ) - { - chat_active = FALSE; + switchChatActive(); + memset(line, '\0', STR_SIZE); + return; } if( chat_active == FALSE ) @@ -245,7 +210,7 @@ void eventChat() proto_send_chat_server(PROTO_SEND_ALL, NULL, out); } - strcpy(line, ""); + memset(line, '\0', STR_SIZE); return; } -- cgit v1.2.3