You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
5.7 KiB
234 lines
5.7 KiB
/*
|
|
chat.c - this file will do everything what have to do with the chat..
|
|
*/
|
|
|
|
#include "bomberclone.h"
|
|
#include "network.h"
|
|
#include "packets.h"
|
|
#include "gfx.h"
|
|
#include "keybinput.h"
|
|
#include "chat.h"
|
|
|
|
_chat chat;
|
|
|
|
/* find a free line or delete the oldest one */
|
|
int
|
|
chat_findfreeline ()
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; (i < CHAT_MAX_LINES && chat.lines[i][0] != 0); i++);
|
|
|
|
if (i >= CHAT_MAX_LINES) {
|
|
memcpy (chat.lines[1], chat.lines[0], 255);
|
|
i = 255;
|
|
}
|
|
|
|
chat.changed = 1;
|
|
|
|
return i;
|
|
}
|
|
|
|
void
|
|
chat_addline (char *text)
|
|
{
|
|
int l;
|
|
|
|
l = chat_findfreeline ();
|
|
|
|
strncpy (chat.lines[l], text, 255);
|
|
chat.lineschanged = 1;
|
|
}
|
|
|
|
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;
|
|
|
|
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);
|
|
}
|
|
|
|
gfx_unlocksurface (gfx.screen);
|
|
|
|
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 - 16;
|
|
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 + 16;
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1);
|
|
};
|
|
|
|
|
|
void
|
|
chat_deletebox ()
|
|
{
|
|
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_AddUpdateRect (chat.window.x, chat.window.y, chat.window.w, chat.window.h);
|
|
|
|
chat.visible = 0;
|
|
SDL_FreeSurface (chat.oldscreen);
|
|
chat.oldscreen = NULL;
|
|
};
|
|
|
|
|
|
void
|
|
chat_show (int x1, int y1, int x2, int y2)
|
|
{
|
|
if (chat.visible != 0)
|
|
chat_deletebox ();
|
|
|
|
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 ();
|
|
keybinput_new (&chat.input);
|
|
gfx_AddUpdateRect (chat.window.x, chat.window.y, chat.window.w, chat.window.h);
|
|
chat.changed = 1;
|
|
chat.lineschanged = 1;
|
|
}
|
|
};
|
|
|
|
|
|
void
|
|
chat_clearscreen (signed char all)
|
|
{
|
|
SDL_Rect src,
|
|
dest;
|
|
|
|
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;
|
|
|
|
src.x = 2;
|
|
src.y = 2;
|
|
src.w = chat.window.w - 4;
|
|
src.h = chat.window.h - 4;
|
|
}
|
|
else {
|
|
/* redraw only the textline of out input box */
|
|
dest.x = chat.window.x + 2;
|
|
dest.y = chat.window.y + chat.window.h - 18;
|
|
dest.w = src.w = chat.window.w - 4;
|
|
dest.h = src.h = 16;
|
|
|
|
src.x = 2;
|
|
src.y = chat.window.h - 18;
|
|
}
|
|
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 - 16;
|
|
draw_shadefield (gfx.screen, &dest, 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 + 16;
|
|
draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1);
|
|
|
|
gfx_AddUpdateRect (chat.window.x, chat.window.y, chat.window.w, chat.window.h);
|
|
};
|
|
|
|
|
|
void
|
|
chat_loop (SDL_Event * event)
|
|
{
|
|
int i,
|
|
y,
|
|
l,
|
|
p1,
|
|
p2,
|
|
maxchar;
|
|
char text[255];
|
|
|
|
i = keybinput_loop (&chat.input, 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);
|
|
keybinput_new (&chat.input);
|
|
i = 0;
|
|
}
|
|
|
|
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) / (gfx.font.size.x - 4);
|
|
if (chat.lineschanged) {
|
|
y = chat.window.y + 4;
|
|
l = chat.startline;
|
|
while (y < (chat.window.y + chat.window.h - 32) && chat.lines[l][0] != 0) {
|
|
for (p1 = 0; (p1 < maxchar && chat.lines[l][p2] != 0); p1++)
|
|
text[p1] = chat.lines[l][p2++];
|
|
text[p1] = 0;
|
|
draw_text (chat.window.x + 4, y, text, 1);
|
|
if (chat.lines[l][p2] == 0) { // the end of the line
|
|
l++;
|
|
p2 = 0;
|
|
}
|
|
y = y + gfx.font.size.y;
|
|
}
|
|
if (chat.lines[l][0] != 0) {
|
|
chat.startline++;
|
|
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;
|
|
draw_text (chat.window.x + 4, (chat.window.y + chat.window.h) - 4 - gfx.font.size.y, text,
|
|
1);
|
|
}
|
|
};
|