summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-07-08 16:35:02 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-07-08 16:35:02 +0000
commit7386e93e32575bae21006d0300cbff4cf7a40926 (patch)
tree5cec5aeddc3263880caf0a09f679ccd68586d4db /src/client
parent776577985a056407645a448f8332d6ce69d645a3 (diff)
- 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
Diffstat (limited to 'src/client')
-rw-r--r--src/client/chat.c151
-rw-r--r--src/client/chat.h2
2 files changed, 60 insertions, 93 deletions
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<TEXTFIELD_SIZE_X-20 && mapa[i]==SDL_PRESSED)
- if( mapa[i] == SDL_PRESSED && len < STR_SIZE )
- {
- if (i == SDLK_SPACE)
+ //printf("name %s\n", name);
+
+ if( strcmp(name, "backspace") == 0 && len > 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;
}
diff --git a/src/client/chat.h b/src/client/chat.h
index fc6abc3..f2e1770 100644
--- a/src/client/chat.h
+++ b/src/client/chat.h
@@ -14,6 +14,8 @@
#define CHAT_LOCATION_X (WINDOW_SIZE_X/2 - CHAT_SIZE_X/2)
#define CHAT_LOCATION_Y (WINDOW_SIZE_Y/2 - CHAT_SIZE_Y/2)
+#define CHAT_LAST_ENTER_INTERVAL 50
+
extern void initChat();
extern void drawChat();
extern void eventChat();