diff --git a/configure.in b/configure.in index 11888f4..d4d8852 100644 --- a/configure.in +++ b/configure.in @@ -5,7 +5,7 @@ dnl Please disable it in the Anjuta project configuration AC_INIT(configure.in) AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE(bomberclone, 0.11.3) +AM_INIT_AUTOMAKE(bomberclone, 0.11.3t4) AM_CONFIG_HEADER(config.h) diff --git a/include/bomberclone.h b/include/bomberclone.h index c6ac8cd..cb5a2f4 100644 --- a/include/bomberclone.h +++ b/include/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.26 2004/05/20 16:55:30 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.27 2004/06/15 15:04:37 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -119,6 +119,10 @@ extern void game_end (); extern void game_start(); extern void game_showresult (); +extern void game_menu_create (); +extern void game_menu_loop (SDL_Event *event, int eventstate); + + // everything is declared in field.c extern void draw_field (); extern void field_clear(int x, int y); diff --git a/include/menu.h b/include/menu.h index bc58ef8..e9afc8d 100644 --- a/include/menu.h +++ b/include/menu.h @@ -1,4 +1,4 @@ -/* $Id: menu.h,v 1.11 2004/06/08 22:35:20 stpohle Exp $ +/* $Id: menu.h,v 1.12 2004/06/15 15:04:37 stpohle Exp $ * GUI for menuhandling */ @@ -54,6 +54,7 @@ struct { _menuitem *focus; SDL_Surface *oldscreen; // hold old screendata SDL_Rect oldscreenpos; + int oldkey; float focusto; int focusvis; _menuitem menuitems[MENU_MAXENTRYS]; diff --git a/src/chat.c b/src/chat.c index 818d830..bfa64fd 100644 --- a/src/chat.c +++ b/src/chat.c @@ -162,16 +162,12 @@ chat_drawinput () src.y = chat.window.h - (font[0].size.y + 2); src.w = chat.window.w - 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); diff --git a/src/game.c b/src/game.c index 5944985..dbfc617 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,4 @@ -/* $Id: game.c,v 1.86 2004/06/11 20:29:10 stpohle Exp $ +/* $Id: game.c,v 1.87 2004/06/15 15:04:37 stpohle Exp $ game.c - procedures for the game. */ #include @@ -20,6 +20,7 @@ extern int blitdb_nr, Uint32 game_timediff, game_timediff1; static float hurrywarn_to; static int hurrywarn_state; +static _menu *menu; void game_draw_info () @@ -148,42 +149,56 @@ game_draw_info () * in the GS_wait mode the chat will always be active. */ void game_keys_loop () { - if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) { - /* Server is starting the game */ + + if (menu != NULL) { + + /* delete all movement keys */ + + int i; + for (i = 0; i < BCPK_max * 2; i++) + keyb_gamekeys.state[i] = 0; + } + else { + + /* don't go into the game_keys if there is no menu displayed */ + + if (GT_MP_PTPM && bman.state == GS_ready && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) { + /* Server is starting the game */ bman.state = GS_running; net_send_servermode (); bman.updatestatusbar = 1; // force an update - } + } - if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) { + if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) { /* Switch Fullscreen */ SDL_WM_ToggleFullScreen(gfx.screen); gfx.fullscreen = !gfx.fullscreen; bman.updatestatusbar = 1; // force an update - } + } - /* - if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) { + /* + if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) { // Switch Debugmode debug = !debug; bman.updatestatusbar = 1; // force an update - } - */ + } + */ - if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) { - if (chat.active && (bman.state == GS_ready || bman.state == GS_running)) { - chat.active = 0; - d_printf ("Chatmode Disabled\n"); + if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) { + if (chat.active && (bman.state == GS_ready || bman.state == GS_running)) { + chat.active = 0; + d_printf ("Chatmode Disabled\n"); + } + else + game_menu_create (); } - else - bman.state = GS_startup; - } - if ((GT_MP_PTPM || GT_MP_PTPS) && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) { - chat_setactive (1, 0); - chat.changed = 1; - d_printf ("Chatmode Enabled\n"); - } + if ((GT_MP_PTPM || GT_MP_PTPS) && keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) { + chat_setactive (1, 0); + chat.changed = 1; + d_printf ("Chatmode Enabled\n"); + } + } }; @@ -192,7 +207,7 @@ void game_loop () { SDL_Event event; - int done = 0, i; + int done = 0, i, eventstate; gfx_blitupdaterectclear (); @@ -202,13 +217,15 @@ game_loop () net_game_fillsockaddr (); SDL_Flip (gfx.screen); + menu = NULL; + bman.updatestatusbar = 1; // force an update timestamp = SDL_GetTicks (); // needed for time sync. d_gamedetail ("GAME START"); draw_players (); while (!done && (bman.state == GS_running || bman.state == GS_ready)) { - if (SDL_PollEvent (&event) != 0) + if ((eventstate = SDL_PollEvent (&event)) != 0) switch (event.type) { case (SDL_QUIT): done = 1; @@ -269,6 +286,11 @@ game_loop () } stonelist_draw (); + + /* if there is any menu displayed do so */ + if (menu != NULL) + game_menu_loop (&event, eventstate); + gfx_blitdraw (); s_calctimesync (); bman.timeout -= timediff; @@ -495,7 +517,6 @@ void game_showresult () { if ((keys[SDLK_RETURN] || keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed) && (event.type = SDL_KEYDOWN)) { done = 1; keypressed = 1; - bman.state = GS_running; } if (keys[SDLK_F8] && event.type == SDL_KEYDOWN) { @@ -512,4 +533,66 @@ void game_showresult () { s_delay (25); } + + if (bman.state != GS_quit && bman.state != GS_startup) + bman.state = GS_running; +}; + + +/* + * create the in game menu + */ +void game_menu_create () { + if (menu != NULL) + return; + + menu = menu_new ("Gamemenu", 300, 150); + + menu_create_button (menu, "Back to the Game", -1, 50, 200, 1); + if (GT_SP || GT_MP_PTPM) + menu_create_button (menu, "End this Round", -1, 80, 200, 2); + menu_create_button (menu, "Quit the Game", -1, 110, 200, 3); + + menu_focus_id (menu, 1); + menu->looprunning = 1; +}; + + +/* + * in game menu_loop, will called every game loop. + * As long as this menu is displayed the gamekeys will not work. + * + * the drawings will be done from the main loop. So we won't + * have to draw anything on our own. + * + * Pressing ESC will bring you back to the game. + */ +void game_menu_loop (SDL_Event *event, int eventstate) { + int done; + + if (menu == NULL) + return; + + menu_draw (menu); + + done = menu_event_loop (menu, event, eventstate); + /* + * check if one of the buttons was pressed + */ + + if (done != 0) { + if (menu->focus->id == 2 && (GT_MP_PTPM || GT_SP)) { /* End Round */ + bman.timeout = -GAME_OVERTIMEOUT; + } + + else if (menu->focus->id == 3) /* End Game */ + bman.state = GS_startup; + + else { /* Quit Menu */ + menu_delete (menu); + menu = NULL; + gfx_blitdraw (); + draw_field (); + } + } }; diff --git a/src/menu.c b/src/menu.c index 7621ea6..acbaeb9 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.44 2004/06/08 22:35:26 stpohle Exp $ +/* $Id: menu.c,v 1.45 2004/06/15 15:04:37 stpohle Exp $ * Menuhandling */ #include "basic.h" @@ -45,6 +45,8 @@ menu_new (char *title, int x, int y) menu->focus = NULL; menu->looprunning = 0; + menu->oldkey = 1; + return menu; }; @@ -433,8 +435,13 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate) { Uint8 *keys; int done = 0; - + if (eventstate >= 1) { + + /* make sure no old key is disturbing us */ + if (event->type != SDL_KEYDOWN) + menu->oldkey = 0; + switch (event->type) { case (SDL_QUIT): bman.state = GS_quit; @@ -442,7 +449,7 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate) return 1; break; case (SDL_KEYDOWN): /* focus next element */ - if (event->key.keysym.sym == SDLK_TAB) { + if (menu->oldkey == 0 && event->key.keysym.sym == SDLK_TAB) { keys = SDL_GetKeyState (NULL); if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) menu_focus_prev (menu); @@ -450,7 +457,7 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate) menu_focus_next (menu); break; } - else if (event->key.keysym.sym == SDLK_ESCAPE) { + else if (menu->oldkey == 0 && event->key.keysym.sym == SDLK_ESCAPE) { return -1; break; } @@ -476,6 +483,8 @@ menu_event_loop (_menu * menu, SDL_Event * event, int eventstate) } } } + else + menu->oldkey = 0; menu->focusto -= timediff; if (menu->focusto <= 0.0f) { diff --git a/src/single.c b/src/single.c index 7cb8f17..2f4f881 100644 --- a/src/single.c +++ b/src/single.c @@ -1,4 +1,4 @@ -/* $Id: single.c,v 1.66 2004/06/13 23:34:10 stpohle Exp $ */ +/* $Id: single.c,v 1.67 2004/06/15 15:04:37 stpohle Exp $ */ /* single player */ #include "basic.h" @@ -637,9 +637,12 @@ single_playergame (int second_player, int ai_players) game_start (); bman.state = GS_running; game_loop (); - bman.state = GS_ready; game_end (); } + + gfx_blitdraw (); + draw_logo (); + gfx_blitdraw (); };