#include #include #include "main.h" #include "list.h" #include "myTimer.h" #include "image.h" #include "net_multiplayer.h" #include "screen_world.h" #include "proto.h" #include "interface.h" #include "chat.h" #include "font.h" static SDL_Surface *g_chat; static list_t *listText; static char line[STR_SIZE]; static int line_time, line_atime; static int timeBlick; static bool_t chat_active; static bool_t revicedNewMsg; void initChat() { g_chat = addImageData("chat.png", IMAGE_NO_ALPHA, "chat", IMAGE_GROUP_USER); listText = newList(); strcpy(line, ""); chat_active = FALSE; revicedNewMsg = FALSE; line_time = 0; line_atime = 0; timeBlick = 0; } void drawChat() { char str[STR_SIZE]; int i; if( chat_active == FALSE ) { return; } drawImage(g_chat, CHAT_LOCATION_X, CHAT_LOCATION_Y, 0, 0, CHAT_SIZE_X, CHAT_SIZE_Y); for( i = 0 ; i < listText->count ; i++ ) { char *s; s = (char *)listText->list[i]; drawFontMaxSize(s, CHAT_LOCATION_X+5, CHAT_LOCATION_Y+5 + i*20, CHAT_SIZE_X-10, 20, COLOR_WHITE); } strcpy(str, line); if( timeBlick > CHAT_TIME_BLICK_CURSOR/2 ) { strcat(str, "\f"); } timeBlick++; if( timeBlick == CHAT_TIME_BLICK_CURSOR ) { timeBlick = 0; } drawFont(str, CHAT_LOCATION_X+5, CHAT_LOCATION_Y+5 + CHAT_MAX_LINES*20, COLOR_WHITE); } static void readKey() { Uint8 *mapa; int len; int w, h; int i; if (line_atime < 100) line_atime ++; mapa = SDL_GetKeyState(NULL); len = strlen(line); getTextSize(line, &w, &h); // mazanie posledneho klavesu if( mapa[SDLK_BACKSPACE] == SDL_PRESSED ) { if( len > 0 ) { line_time = 0; line[len-1]='\0'; } return; } if( w > CHAT_LINE_WIDTH-40 ) { return; } // klavesy abecedy for(i=SDLK_SPACE /*SDLK_a*/;i<=SDLK_z;i++) { //if(widthname, line); proto_send_chat_server(PROTO_SEND_ALL, NULL, out); } strcpy(line, ""); return; } readKey(); } bool_t isChatActive() { return chat_active; } bool_t isRecivedNewMsg() { return revicedNewMsg; } void addToChat(char *s) { addList(listText, strdup(s) ); if( listText->count > CHAT_MAX_LINES ) { delListItem(listText, 0, free); } if( chat_active == FALSE ) { revicedNewMsg = TRUE; } } void quitChat() { assert( listText != NULL ); destroyListItem(listText, free); }