From 263e1dbb16324083174e068b65d9596af6e1db7b Mon Sep 17 00:00:00 2001 From: oroborus Date: Sun, 6 Jul 2008 19:42:01 +0000 Subject: - zabudnute subory git-svn-id: http://opensvn.csie.org/tuxanci_ng@110 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/client/chat.c | 285 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/client/chat.h | 25 +++++ 2 files changed, 310 insertions(+) create mode 100644 src/client/chat.c create mode 100644 src/client/chat.h (limited to 'src') diff --git a/src/client/chat.c b/src/client/chat.c new file mode 100644 index 0000000..d08a502 --- /dev/null +++ b/src/client/chat.c @@ -0,0 +1,285 @@ + +#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); +} diff --git a/src/client/chat.h b/src/client/chat.h new file mode 100644 index 0000000..fc6abc3 --- /dev/null +++ b/src/client/chat.h @@ -0,0 +1,25 @@ + +#ifndef CHAT_H + +#define CHAT_H + +#define CHAT_MAX_LINES 10 +#define CHAT_TIME_MULTIPLE 10 +#define CHAT_TIME_BLICK_CURSOR 20 +#define CHAT_LINE_WIDTH 320 + +#define CHAT_SIZE_X 320 +#define CHAT_SIZE_Y 240 + +#define CHAT_LOCATION_X (WINDOW_SIZE_X/2 - CHAT_SIZE_X/2) +#define CHAT_LOCATION_Y (WINDOW_SIZE_Y/2 - CHAT_SIZE_Y/2) + +extern void initChat(); +extern void drawChat(); +extern void eventChat(); +extern void addToChat(char *s); +extern bool_t isChatActive(); +extern bool_t isRecivedNewMsg(); +extern void quitChat(); + +#endif -- cgit v1.2.3