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.
383 lines
10 KiB
383 lines
10 KiB
/*
|
|
multiwait.c - this manages only the network screen where
|
|
everyone have to select it's players and where even the basic chat is inside
|
|
*/
|
|
|
|
#include "bomberclone.h"
|
|
#include "network.h"
|
|
#include "packets.h"
|
|
#include "gamesrv.h"
|
|
#include "gfx.h"
|
|
#include "chat.h"
|
|
|
|
#define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (bman.players[__result].gfx_nr != __gfx_nr) && (__result >= 0); __result--);
|
|
|
|
extern int UpdateRects_nr;
|
|
|
|
static int mw_player = 0,
|
|
mw_chat = 0,
|
|
mw_frame = 0,
|
|
mw_frameto = 0;
|
|
static SDL_Surface *mw_plgfx[MAX_PLAYERS];
|
|
|
|
|
|
/* this will load some graphics and so other stuff */
|
|
void
|
|
mw_init ()
|
|
{
|
|
int i;
|
|
SDL_Surface *tmp;
|
|
draw_logo ();
|
|
|
|
menu_displaytext ("Please Wait", "Loading GFX Data", 64, 128, 64);
|
|
|
|
gfx_load_players (32, 32);
|
|
network_loop ();
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
network_loop ();
|
|
tmp = makegray_image (gfx.players[i].ani.image);
|
|
network_loop ();
|
|
mw_plgfx[i] = SDL_DisplayFormat (tmp);
|
|
network_loop ();
|
|
SDL_FreeSurface (tmp);
|
|
network_loop ();
|
|
}
|
|
|
|
bman.updatestatusbar = 1;
|
|
};
|
|
|
|
|
|
/* free all grafics */
|
|
void
|
|
mw_shutdown ()
|
|
{
|
|
int i;
|
|
|
|
chat_show (-1, -1, -1, -1);
|
|
chat_cleanup();
|
|
gfx_free_players ();
|
|
|
|
for (i = 0; i < MAX_PLAYERS; i++)
|
|
SDL_FreeSurface (mw_plgfx[i]);
|
|
};
|
|
|
|
|
|
void
|
|
mw_wait_for_connect ()
|
|
{
|
|
menu_displaytext ("Please Wait", "Wait For connection", 64, 128, 64);
|
|
};
|
|
|
|
|
|
void
|
|
mw_draw_status ()
|
|
{
|
|
int pnr,
|
|
x,
|
|
x1,
|
|
y,
|
|
px;
|
|
char text[255];
|
|
SDL_Rect src,
|
|
dest;
|
|
|
|
/* Draw Player List */
|
|
/* 1. the head */
|
|
px = gfx.res.x / 320;
|
|
x = (gfx.res.x - px * 320) / 2;
|
|
|
|
for (pnr = 0; pnr < px; pnr++) {
|
|
font_setcolor (128, 128, 128, 0);
|
|
font_draw (pnr * 320 + x - 2, 22, " Wins Points", 0);
|
|
font_setcolor (192, 192, 255, 0);
|
|
font_draw (pnr * 320 + x, 24, " Wins Points", 0);
|
|
}
|
|
|
|
/* 2. the names with points */
|
|
for (x1 = pnr = 0, y = 48; pnr < MAX_PLAYERS; pnr++) {
|
|
redraw_logo (x1 * 320, y - 4, 320, 32);
|
|
if (bman.players[pnr].gfx_nr != -1 && PS_IS_used (bman.players[pnr].state)) {
|
|
src.x = 3 * bman.players[pnr].gfx->smal_size.x;
|
|
src.y = 0;
|
|
src.w = dest.w = bman.players[pnr].gfx->smal_size.x;
|
|
src.h = dest.h = bman.players[pnr].gfx->smal_size.y;
|
|
|
|
dest.x = x1 * 320;
|
|
dest.y = y - 4;
|
|
|
|
SDL_BlitSurface (bman.players[pnr].gfx->smal_image, &src, gfx.screen, &dest);
|
|
}
|
|
|
|
sprintf (text, " %10s %2d %2d", bman.players[pnr].name, bman.players[pnr].wins,
|
|
bman.players[pnr].points);
|
|
if (PS_IS_used (bman.players[pnr].state)) {
|
|
|
|
if (bman.lastwinner == pnr)
|
|
font_setcolor (255, 255, 192, 0);
|
|
else
|
|
font_setcolor (192, 192, 192, 0);
|
|
font_draw (x + x1 * 320, y, text, 0);
|
|
}
|
|
x1++;
|
|
if (x1 >= px) {
|
|
y += 32;
|
|
x1 = 0;
|
|
}
|
|
if (pnr == MAX_PLAYERS - 1 && x1 != 0)
|
|
y += 32;
|
|
}
|
|
|
|
mw_player = y;
|
|
};
|
|
|
|
|
|
void
|
|
mw_draw_gfxselect (int selgfx)
|
|
{
|
|
int i,
|
|
select,
|
|
xstep;
|
|
SDL_Rect src,
|
|
dest;
|
|
|
|
xstep = gfx.res.x / MAX_PLAYERS;
|
|
|
|
if (bman.players[bman.p_nr].gfx_nr == -1) {
|
|
/* draw selection */
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
dest.w = src.w = gfx.players[i].size.x;
|
|
dest.h = src.h = gfx.players[i].size.y;
|
|
|
|
dest.x = i * xstep + (xstep >> 1) - (gfx.players[i].size.x >> 1);
|
|
dest.y = mw_player + 8;
|
|
|
|
redraw_logo (dest.x, dest.y, dest.w, dest.h);
|
|
|
|
src.x = 3 * gfx.players[i].size.x;
|
|
if (i == selgfx)
|
|
src.y = mw_frame * gfx.players[i].size.y;
|
|
else
|
|
src.y = 0;
|
|
|
|
MW_IS_GFX_SELECT (i, select);
|
|
|
|
if (select >= MAX_PLAYERS || select < 0) {
|
|
/* this player have not been selected */
|
|
if (selgfx == i) {
|
|
mw_frameto--;
|
|
|
|
if (mw_frameto <= 0 || mw_frameto > ANI_PLAYERTIMEOUT) {
|
|
mw_frameto = ANI_PLAYERTIMEOUT;
|
|
mw_frame++;
|
|
}
|
|
|
|
if (mw_frame >= gfx.players[i].ani.frames || mw_frame < 0) {
|
|
mw_frameto = ANI_PLAYERTIMEOUT;
|
|
mw_frame = 0;
|
|
}
|
|
|
|
SDL_BlitSurface (gfx.players[i].ani.image, &src, gfx.screen, &dest);
|
|
}
|
|
else
|
|
SDL_BlitSurface (mw_plgfx[i], &src, gfx.screen, &dest);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
/* draw selected players */
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
dest.w = src.w = gfx.players[i].size.x;
|
|
dest.h = src.h = gfx.players[i].size.y;
|
|
|
|
dest.x = i * xstep + (xstep >> 1) - (gfx.players[i].size.x >> 1);
|
|
dest.y = mw_player + 8;
|
|
|
|
redraw_logo (dest.x, dest.y, dest.w, dest.h);
|
|
|
|
src.x = 3 * gfx.players[i].size.x;
|
|
if (i == selgfx)
|
|
src.y = mw_frame * gfx.players[i].size.y;
|
|
else
|
|
src.y = 0;
|
|
|
|
MW_IS_GFX_SELECT (i, select);
|
|
|
|
if (select < MAX_PLAYERS && select >= 0) {
|
|
/* this player have been selected */
|
|
if (bman.players[bman.p_nr].gfx_nr == i)
|
|
SDL_BlitSurface (gfx.players[i].ani.image, &src, gfx.screen, &dest);
|
|
else
|
|
SDL_BlitSurface (mw_plgfx[i], &src, gfx.screen, &dest);
|
|
}
|
|
}
|
|
}
|
|
|
|
mw_chat = mw_player + 8 + gfx.players[0].size.y;
|
|
}
|
|
|
|
|
|
void
|
|
mw_draw_chat ()
|
|
{
|
|
if (chat.visible == 0) {
|
|
chat_show (16, mw_chat + 16, gfx.res.x - 16, gfx.res.y - 32);
|
|
chat_addstatusline ("Press [STRG] or [CTRL] - to select a player");
|
|
if (GT_MP_PTPM) {
|
|
chat_addstatusline ("F4 - to start the game");
|
|
chat_addstatusline ("F5 - to change map settings");
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
/* the loop itself */
|
|
void
|
|
wait_for_players ()
|
|
{
|
|
SDL_Event event;
|
|
Uint8 *keys;
|
|
int done = 0,
|
|
ready = 0,
|
|
keypressed = 0,
|
|
i,
|
|
selgfx = 0;
|
|
|
|
mw_init ();
|
|
draw_logo ();
|
|
|
|
while (!done && bman.state == GS_wait) {
|
|
|
|
i = bman.p_nr;
|
|
if (network_loop () < 0) {
|
|
done = 1;
|
|
bman.p_nr = -1;
|
|
}
|
|
if (i != bman.p_nr) /* clean the screen after we got our playernumber */
|
|
draw_logo ();
|
|
|
|
/* check if all players are ready, and more as one player is connected */
|
|
if (GT_MP_PTPM)
|
|
for (ready = 0, i = 0; i < MAX_PLAYERS; i++)
|
|
if (PS_IS_playing (bman.players[i].state))
|
|
ready++;
|
|
if (ready > 1)
|
|
ready = 1;
|
|
else
|
|
ready = 0;
|
|
|
|
/* draw the screeninformations */
|
|
if (bman.p_nr == -1) { /* we have no connect yet */
|
|
mw_wait_for_connect ();
|
|
SDL_Flip (gfx.screen);
|
|
}
|
|
else { /* we have a connect so draw status */
|
|
if (bman.updatestatusbar) {
|
|
mw_draw_status ();
|
|
gfx_AddUpdateRect (0, 0, gfx.res.x, mw_player);
|
|
bman.updatestatusbar = 0;
|
|
}
|
|
mw_draw_gfxselect (selgfx);
|
|
gfx_AddUpdateRect (0, mw_player, gfx.res.x, mw_chat);
|
|
mw_draw_chat ();
|
|
}
|
|
|
|
gfx_UpdateRects ();
|
|
|
|
/* do the keyboard handling */
|
|
if (SDL_PollEvent (&event) != 0)
|
|
switch (event.type) {
|
|
case (SDL_QUIT):
|
|
bman.state = GS_quit;
|
|
bman.p_nr = -1;
|
|
done = 1;
|
|
}
|
|
|
|
keys = SDL_GetKeyState (NULL);
|
|
|
|
if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) {
|
|
/* we want to quit */
|
|
done = 1;
|
|
bman.p_nr = -1;
|
|
keypressed = 1;
|
|
bman.state = GS_startup;
|
|
}
|
|
|
|
if (bman.p_nr != -1) {
|
|
|
|
if (keys[SDLK_LEFT] && (!keypressed) && bman.players[bman.p_nr].gfx_nr == -1) {
|
|
i = 0;
|
|
while (selgfx < 0 || selgfx >= MAX_PLAYERS || i != -1) {
|
|
selgfx--;
|
|
if (selgfx < 0)
|
|
selgfx = MAX_PLAYERS - 1;
|
|
MW_IS_GFX_SELECT (selgfx, i);
|
|
}
|
|
}
|
|
|
|
if (keys[SDLK_RIGHT] && (!keypressed) && bman.players[bman.p_nr].gfx_nr == -1) {
|
|
i = 0;
|
|
while (selgfx < 0 || selgfx >= MAX_PLAYERS || i != -1) {
|
|
selgfx++;
|
|
if (selgfx >= MAX_PLAYERS)
|
|
selgfx = 0;
|
|
MW_IS_GFX_SELECT (selgfx, i);
|
|
}
|
|
}
|
|
|
|
/* just make sure this player is not selected twice */
|
|
if (bman.players[bman.p_nr].gfx_nr == -1) {
|
|
MW_IS_GFX_SELECT (selgfx, i);
|
|
while (selgfx < 0 || selgfx >= MAX_PLAYERS || i != -1) {
|
|
selgfx++;
|
|
if (selgfx >= MAX_PLAYERS)
|
|
selgfx = 0;
|
|
MW_IS_GFX_SELECT (selgfx, i);
|
|
}
|
|
}
|
|
|
|
if ((keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed)) {
|
|
if (bman.players[bman.p_nr].gfx_nr == -1) {
|
|
/* select player */
|
|
bman.players[bman.p_nr].gfx_nr = selgfx;
|
|
}
|
|
else {
|
|
/* deselect player */
|
|
bman.players[bman.p_nr].gfx_nr = -1;
|
|
}
|
|
net_change_playerid (bman.p_nr, 1);
|
|
bman.updatestatusbar = 1;
|
|
}
|
|
|
|
if ((GT_MP_PTPM) && ready && keys[SDLK_F4] && (!keypressed)) {
|
|
done = 1;
|
|
bman.updatestatusbar = 1;
|
|
}
|
|
|
|
if ((GT_MP_PTPM) && keys[SDLK_F5] && (!keypressed)) {
|
|
/* Map modification */
|
|
mapmenu ();
|
|
draw_logo ();
|
|
mw_draw_status ();
|
|
mw_draw_gfxselect (selgfx);
|
|
UpdateRects_nr = 0;
|
|
gfx_AddUpdateRect (0, 0, gfx.res.x, gfx.res.y);
|
|
chat.changed = 1;
|
|
chat.lineschanged = 1;
|
|
chat_drawbox ();
|
|
mw_draw_chat ();
|
|
gfx_UpdateRects ();
|
|
}
|
|
chat_loop (&event);
|
|
}
|
|
|
|
if (event.type == SDL_KEYUP)
|
|
keypressed = 0;
|
|
else if (event.type == SDL_KEYDOWN)
|
|
keypressed = 1;
|
|
|
|
s_delay (25);
|
|
}
|
|
|
|
mw_shutdown ();
|
|
};
|