|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
chat.c - this file will do everything what have to do with the chat..
|
|
|
|
|
* chat.c - this file will do everything what have to do with the chat..
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "bomberclone.h"
|
|
|
|
@ -11,19 +11,22 @@
|
|
|
|
|
|
|
|
|
|
_chat chat;
|
|
|
|
|
|
|
|
|
|
static void chat_drawlines ();
|
|
|
|
|
static void chat_drawinput ();
|
|
|
|
|
|
|
|
|
|
/* find a free line or delete the oldest one */
|
|
|
|
|
int
|
|
|
|
|
chat_findfreeline ()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
i = chat.lastline;
|
|
|
|
|
i = chat.curline;
|
|
|
|
|
|
|
|
|
|
if (i >= CHAT_MAX_LINES) {
|
|
|
|
|
if (i >= CHAT_MAX_LINES-1) {
|
|
|
|
|
memcpy (&chat.lines[0], &chat.lines[1], sizeof (chat.lines[1]) * (CHAT_MAX_LINES - 1));
|
|
|
|
|
i = CHAT_MAX_LINES - 1;
|
|
|
|
|
i = CHAT_MAX_LINES - 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
chat.lastline++;
|
|
|
|
|
chat.curline++;
|
|
|
|
|
|
|
|
|
|
chat.changed = 1;
|
|
|
|
|
|
|
|
|
@ -31,196 +34,200 @@ chat_findfreeline ()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
chat_cleanup ()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < CHAT_MAX_LINES; i++) {
|
|
|
|
|
if (chat.lines[i].status > 0)
|
|
|
|
|
chat.lines[i].status = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* add a new line to the chat
|
|
|
|
|
* add a new line to the chat, if a line is bigger as the X Space,
|
|
|
|
|
* split the line in more
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_addline (char *text)
|
|
|
|
|
chat_addline (char *text, int color)
|
|
|
|
|
{
|
|
|
|
|
int l;
|
|
|
|
|
char *pos = text;
|
|
|
|
|
int l, i;
|
|
|
|
|
int maxlen = chat.window.x/font[0].size.x;
|
|
|
|
|
if (maxlen > KEYBI_LINE_LEN-1 || maxlen <= 0) maxlen = KEYBI_LINE_LEN;
|
|
|
|
|
|
|
|
|
|
while (pos != NULL) {
|
|
|
|
|
l = chat_findfreeline ();
|
|
|
|
|
chat.lines[l].status = 0;
|
|
|
|
|
strncpy (chat.lines[l].text, text, 255);
|
|
|
|
|
chat.lineschanged = 1;
|
|
|
|
|
if (color == -1)
|
|
|
|
|
chat.lines[l].color = CHAT_TEXTCOLOR;
|
|
|
|
|
else
|
|
|
|
|
chat.lines[l].color = color;
|
|
|
|
|
chat.lines[l].end = 1;
|
|
|
|
|
strncpy (chat.lines[l].text, pos, maxlen);
|
|
|
|
|
if ((i = strlen (pos)) > maxlen) {
|
|
|
|
|
pos = pos + maxlen;
|
|
|
|
|
chat.lines[l].end = 0;
|
|
|
|
|
chat.lines[l].text[maxlen] = 0;
|
|
|
|
|
}
|
|
|
|
|
else pos = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* add a new line to the chat
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_addstatusline (char *text)
|
|
|
|
|
{
|
|
|
|
|
int l;
|
|
|
|
|
l = chat_findfreeline ();
|
|
|
|
|
chat.lines[l].status = 1;
|
|
|
|
|
strncpy (chat.lines[l].text, text, 255);
|
|
|
|
|
chat.lineschanged = 1;
|
|
|
|
|
chat.changed = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* draw the empty chat box
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_drawbox ()
|
|
|
|
|
{
|
|
|
|
|
SDL_Rect src;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (chat.visible == 0)
|
|
|
|
|
chat.oldscreen = gfx_copyscreen (&chat.window);
|
|
|
|
|
|
|
|
|
|
chat.visible = 1;
|
|
|
|
|
|
|
|
|
|
if (gfx_locksurface (gfx.screen))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
src = chat.window;
|
|
|
|
|
SDL_BlitSurface (chat.oldscreen, NULL, gfx.screen, &src);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
src.x = chat.window.x + i;
|
|
|
|
|
src.w = src.x + chat.window.w - 2;
|
|
|
|
|
src.y = chat.window.y + i;
|
|
|
|
|
src.h = src.y + chat.window.h - 2;
|
|
|
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_BRIGHT);
|
|
|
|
|
if (chat.active) draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_BRIGHT);
|
|
|
|
|
else draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfx_unlocksurface (gfx.screen);
|
|
|
|
|
src = chat.window;
|
|
|
|
|
src.x += 2;
|
|
|
|
|
src.y += 2;
|
|
|
|
|
src.h -= 4;
|
|
|
|
|
src.w -= 4;
|
|
|
|
|
SDL_BlitSurface (chat.oldscreen, NULL, gfx.screen, &src);
|
|
|
|
|
|
|
|
|
|
src.x = chat.window.x + 2;
|
|
|
|
|
src.y = chat.window.y + 2;
|
|
|
|
|
src.w = src.x + chat.window.w - 4;
|
|
|
|
|
src.h = src.y + chat.window.h - 4 - font[0].size.y;
|
|
|
|
|
src.h = src.y + chat.window.h - 4;
|
|
|
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK);
|
|
|
|
|
src.x = chat.window.x + 2;
|
|
|
|
|
src.y = chat.window.y + chat.window.h - 18;
|
|
|
|
|
src.w = src.x + chat.window.w - 4;
|
|
|
|
|
src.h = src.y + font[0].size.y;
|
|
|
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1);
|
|
|
|
|
gfx_blitupdaterectadd (&chat.window);
|
|
|
|
|
|
|
|
|
|
gfx_unlocksurface (gfx.screen);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Draw the chatscreen
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_deletebox ()
|
|
|
|
|
chat_draw ()
|
|
|
|
|
{
|
|
|
|
|
SDL_Rect src,
|
|
|
|
|
dest;
|
|
|
|
|
|
|
|
|
|
src.x = 0;
|
|
|
|
|
src.y = 0;
|
|
|
|
|
src.w = dest.w = chat.oldscreen->w;
|
|
|
|
|
src.h = dest.h = chat.oldscreen->h;
|
|
|
|
|
|
|
|
|
|
dest.x = chat.window.x;
|
|
|
|
|
dest.y = chat.window.y;
|
|
|
|
|
|
|
|
|
|
SDL_BlitSurface (chat.oldscreen, &src, gfx.screen, &dest);
|
|
|
|
|
gfx_blitupdaterectadd (&chat.window);
|
|
|
|
|
if (chat.oldscreen != NULL) {
|
|
|
|
|
chat_drawbox ();
|
|
|
|
|
chat_drawlines ();
|
|
|
|
|
chat_drawinput ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chat.visible = 0;
|
|
|
|
|
SDL_FreeSurface (chat.oldscreen);
|
|
|
|
|
chat.oldscreen = NULL;
|
|
|
|
|
chat.changed = 0;
|
|
|
|
|
chat.input.changed = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* set a new position for the chat window,
|
|
|
|
|
* or delete the chat windows if it's out of range
|
|
|
|
|
* Draw all the textlines
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_show (int x1, int y1, int x2, int y2)
|
|
|
|
|
chat_drawlines ()
|
|
|
|
|
{
|
|
|
|
|
if (chat.visible != 0)
|
|
|
|
|
chat_deletebox ();
|
|
|
|
|
int vislines = (chat.window.h - 20) / font[0].size.y; // number of visible lines
|
|
|
|
|
int i = chat.curline - vislines;
|
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
|
|
if (x1 == -1 || x2 == -1 || y1 == -1 || y2 == -1 || x2 <= x1 || y2 <= y1)
|
|
|
|
|
chat.visible = 0;
|
|
|
|
|
else {
|
|
|
|
|
chat.window.x = x1;
|
|
|
|
|
chat.window.y = y1;
|
|
|
|
|
chat.window.w = x2 - x1;
|
|
|
|
|
chat.window.h = y2 - y1;
|
|
|
|
|
chat_drawbox ();
|
|
|
|
|
chat.changed = 1;
|
|
|
|
|
chat.lineschanged = 1;
|
|
|
|
|
}
|
|
|
|
|
if (i < 0) i = 0;
|
|
|
|
|
|
|
|
|
|
for (nr = 0; i <= chat.curline; i++, nr++)
|
|
|
|
|
font_gfxdraw (chat.window.x + 4, chat.window.y + 4 + font[0].size.y * nr, chat.lines[i].text, 0, chat.lines[i].color, 0x1000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* redraw the empty chat box
|
|
|
|
|
* draw the input field
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_clearscreen (signed char all)
|
|
|
|
|
chat_drawinput ()
|
|
|
|
|
{
|
|
|
|
|
SDL_Rect src,
|
|
|
|
|
dest;
|
|
|
|
|
SDL_Rect src, dest;
|
|
|
|
|
int maxlen = chat.window.x / font[0].size.x;
|
|
|
|
|
int start;
|
|
|
|
|
if (maxlen > KEYBI_LINE_LEN-1 || maxlen <= 0) maxlen = KEYBI_LINE_LEN;
|
|
|
|
|
|
|
|
|
|
if (all == 1) {
|
|
|
|
|
dest.x = chat.window.x + 2;
|
|
|
|
|
dest.y = chat.window.y + 2;
|
|
|
|
|
dest.w = dest.x + chat.window.w - 4;
|
|
|
|
|
dest.h = dest.y + chat.window.h - 4;
|
|
|
|
|
dest.y = chat.window.y + chat.window.h - (font[0].size.y + 2);
|
|
|
|
|
dest.w = chat.window.w - 4;
|
|
|
|
|
dest.h = font[0].size.y;
|
|
|
|
|
|
|
|
|
|
src.x = 2;
|
|
|
|
|
src.y = 2;
|
|
|
|
|
src.y = chat.window.h - (font[0].size.y + 2);
|
|
|
|
|
src.w = chat.window.w - 4;
|
|
|
|
|
src.h = chat.window.h - 4;
|
|
|
|
|
src.h = font[0].size.y;
|
|
|
|
|
d_printsdlrect ("c.w: ", &chat.window);
|
|
|
|
|
d_printsdlrect ("src: ", &src);
|
|
|
|
|
d_printsdlrect ("dst: ", &dest);
|
|
|
|
|
SDL_BlitSurface (chat.oldscreen, &src, gfx.screen, &dest);
|
|
|
|
|
|
|
|
|
|
src.x = chat.window.x + 2;
|
|
|
|
|
src.y = chat.window.y + chat.window.h - (font[0].size.y + 2);
|
|
|
|
|
src.w = chat.window.x + chat.window.w - 4;
|
|
|
|
|
src.h = chat.window.y + chat.window.h - 4;
|
|
|
|
|
d_printsdlrect ("src: ", &src);
|
|
|
|
|
|
|
|
|
|
if (chat.active)
|
|
|
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_BRIGHT);
|
|
|
|
|
else
|
|
|
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK);
|
|
|
|
|
gfx_blitupdaterectadd (&chat.window);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* redraw only the textline of out input box */
|
|
|
|
|
dest.x = chat.window.x + 2;
|
|
|
|
|
dest.y = chat.window.y + chat.window.h - 17;
|
|
|
|
|
dest.w = src.w = chat.window.w - 4;
|
|
|
|
|
dest.h = src.h = font[0].size.y;
|
|
|
|
|
|
|
|
|
|
src.x = 2;
|
|
|
|
|
src.y = chat.window.h - 18;
|
|
|
|
|
gfx_blitupdaterectadd (&dest);
|
|
|
|
|
start = strlen (chat.input.text) - maxlen;
|
|
|
|
|
if (start < 0) start = 0;
|
|
|
|
|
|
|
|
|
|
font_gfxdraw (chat.window.x + 2, (chat.window.y + chat.window.h) - (2 + font[0].size.y), chat.input.text, 0, COLOR_black, 0x1000);
|
|
|
|
|
|
|
|
|
|
chat.input.changed = 0;
|
|
|
|
|
}
|
|
|
|
|
SDL_BlitSurface (chat.oldscreen, &src, gfx.screen, &dest);
|
|
|
|
|
|
|
|
|
|
if (all == 1) {
|
|
|
|
|
dest.w = dest.x + chat.window.w - 4;
|
|
|
|
|
dest.h = dest.y + chat.window.h - 4 - font[0].size.y;
|
|
|
|
|
draw_shadefield (gfx.screen, &dest, CHAT_BG_SHADE_DARK);
|
|
|
|
|
/*
|
|
|
|
|
* set a new position for the chat window,
|
|
|
|
|
* or delete the chat windows if it's out of range
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_show (int x, int y, int w, int h)
|
|
|
|
|
{
|
|
|
|
|
/* restore the old screen */
|
|
|
|
|
if (chat.oldscreen != NULL) {
|
|
|
|
|
gfx_blitupdaterectadd (&chat.window);
|
|
|
|
|
SDL_BlitSurface (chat.oldscreen, NULL, gfx.screen, &chat.window);
|
|
|
|
|
SDL_FreeSurface (chat.oldscreen);
|
|
|
|
|
chat.oldscreen = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
src.x = chat.window.x + 2;
|
|
|
|
|
src.y = chat.window.y + chat.window.h - 18;
|
|
|
|
|
src.w = src.x + chat.window.w - 4;
|
|
|
|
|
src.h = src.y + font[0].size.y;
|
|
|
|
|
if (chat.active)
|
|
|
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK << 1);
|
|
|
|
|
else
|
|
|
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1);
|
|
|
|
|
/* 1) save the old screen
|
|
|
|
|
* 2) draw chatbox
|
|
|
|
|
*/
|
|
|
|
|
if (x >= 0 && x < gfx.res.x && y >= 0 && y < gfx.res.y && w > 0 && h > 0) {
|
|
|
|
|
chat.window.x = x;
|
|
|
|
|
chat.window.y = y;
|
|
|
|
|
chat.window.w = w;
|
|
|
|
|
chat.window.h = h;
|
|
|
|
|
|
|
|
|
|
chat.oldscreen = gfx_copyscreen (&chat.window);
|
|
|
|
|
|
|
|
|
|
chat_draw ();
|
|
|
|
|
|
|
|
|
|
gfx_blitupdaterectadd (&chat.window);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* loop through the chat and draw it
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_loop (SDL_Event * event)
|
|
|
|
|
{
|
|
|
|
|
int i,
|
|
|
|
|
y,
|
|
|
|
|
l,
|
|
|
|
|
p1,
|
|
|
|
|
p2,
|
|
|
|
|
maxchar;
|
|
|
|
|
int i;
|
|
|
|
|
char text[255];
|
|
|
|
|
|
|
|
|
|
if (chat.active) { /* the chat mode is active */
|
|
|
|
@ -234,62 +241,37 @@ chat_loop (SDL_Event * event)
|
|
|
|
|
if (i == 1 && chat.input.text[0] != 0) {
|
|
|
|
|
sprintf (text, "%s: %s", bman.playername, chat.input.text);
|
|
|
|
|
net_send_chat (text, 1);
|
|
|
|
|
chat_addline (text);
|
|
|
|
|
chat_addline (text, CHAT_TEXTCOLOR);
|
|
|
|
|
keybinput_new (&chat.input, KEYBI_text, 255);
|
|
|
|
|
i = 0;
|
|
|
|
|
chat.active = 0; // to let everything redraw
|
|
|
|
|
if (!chat.keepactive)
|
|
|
|
|
chat.active = 0;
|
|
|
|
|
chat.changed = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else i = 0;
|
|
|
|
|
else
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* draw everything again if it's need to
|
|
|
|
|
* check if we have to redraw the input line
|
|
|
|
|
*/
|
|
|
|
|
if (((i == 0 && chat.input.changed == 1) || chat.changed == 1) && chat.visible == 1) {
|
|
|
|
|
/* draw the new field */
|
|
|
|
|
chat_clearscreen (chat.lineschanged);
|
|
|
|
|
p1 = p2 = 0;
|
|
|
|
|
maxchar = (chat.window.w - 4) / font[0].size.x;
|
|
|
|
|
if (chat.lineschanged) {
|
|
|
|
|
y = chat.window.y + 4;
|
|
|
|
|
l = chat.startline;
|
|
|
|
|
while (y < (chat.window.y + chat.window.h - 32) && chat.lines[l].text[0] != 0) {
|
|
|
|
|
if (chat.lines[l].status < 0) {
|
|
|
|
|
l++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (p1 = 0; (p1 < maxchar && chat.lines[l].text[p2] != 0); p1++)
|
|
|
|
|
text[p1] = chat.lines[l].text[p2++];
|
|
|
|
|
text[p1] = 0;
|
|
|
|
|
font_draw (chat.window.x + 4, y, text, 0, COLOR_white);
|
|
|
|
|
if (chat.lines[l].text[p2] == 0) { // the end of the line
|
|
|
|
|
l++;
|
|
|
|
|
p2 = 0;
|
|
|
|
|
}
|
|
|
|
|
y = y + font[0].size.y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (chat.lines[l].text[0] != 0) {
|
|
|
|
|
chat.startline++;
|
|
|
|
|
if (chat.changed)
|
|
|
|
|
chat_draw ();
|
|
|
|
|
|
|
|
|
|
if (chat.input.changed)
|
|
|
|
|
chat_drawinput ();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* activeate the chat and set up that the chat keeps
|
|
|
|
|
* active after we have pressed the Return Key
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
chat_setactive (int active, int keepactive)
|
|
|
|
|
{
|
|
|
|
|
chat.active = 1;
|
|
|
|
|
chat.changed = 1;
|
|
|
|
|
chat.lineschanged = 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
chat.changed = 0;
|
|
|
|
|
chat.lineschanged = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (chat.startline >= CHAT_MAX_LINES)
|
|
|
|
|
chat.startline = CHAT_MAX_LINES - 5;
|
|
|
|
|
|
|
|
|
|
/* draw the input line */
|
|
|
|
|
if (chat.input.len > maxchar)
|
|
|
|
|
p2 = chat.input.len - maxchar;
|
|
|
|
|
|
|
|
|
|
for (p1 = 0; (p1 < maxchar && chat.input.text[p2] != 0); p1++)
|
|
|
|
|
text[p1] = chat.input.text[p2++];
|
|
|
|
|
text[p1] = 0;
|
|
|
|
|
font_draw (chat.window.x + 4, (chat.window.y + chat.window.h) - 4 - font[0].size.y,
|
|
|
|
|
text, 0, COLOR_white);
|
|
|
|
|
}
|
|
|
|
|
chat_draw ();
|
|
|
|
|
chat.keepactive = keepactive;
|
|
|
|
|
};
|
|
|
|
|