From 71c656200b36c2c5b9c6842e32073b9d7d4ef764 Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Wed, 27 Jan 2010 09:11:47 +0000 Subject: [PATCH] Allow escape from player listbox if appropriate; call RegisterPlayer only from main menu for more flexibility; actually use file_list block so deleting players/demos doesn't crash it --- CHANGELOG.txt | 1 + main/gameseq.c | 22 +++++------ main/inferno.c | 6 +-- main/menu.c | 102 ++++++++++++++++++++++++++----------------------- main/newmenu.c | 10 ++++- 5 files changed, 76 insertions(+), 65 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 426f7491f..53c15cc6a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D2X-Rebirth Changelog 20100127 -------- main/game.c, main/game.h, main/gamecntl.c, main/gameseq.c, main/kmatrix.c, main/multi.c, main/net_ipx.c, main/net_udp.c, main/newdemo.c, main/render.c: Remove all uses of LeaveGame jmpbuf to allow more changing of main loop +main/gameseq.c, main/inferno.c, main/menu.c, main/newmenu.c: Allow escape from player listbox if appropriate; call RegisterPlayer only from main menu for more flexibility; actually use file_list block so deleting players/demos doesn't crash it 20100126 -------- diff --git a/main/gameseq.c b/main/gameseq.c index 8cae33894..236fcbc3e 100644 --- a/main/gameseq.c +++ b/main/gameseq.c @@ -687,17 +687,17 @@ int RegisterPlayer() do_menu_again: ; - if (!get_filename(TXT_SELECT_PILOT, ".plr", filename, allow_abort_flag)) - goto do_menu_again; // They hit Esc in file selector - - if ( filename[0] == '<' ) { - // They selected 'create new pilot' - if (!MakeNewPlayerFile(allow_abort_flag)) - //return 0; // They hit Esc during enter name stage - goto do_menu_again; - } else { - strncpy(Players[Player_num].callsign,filename, CALLSIGN_LEN); - strlwr(Players[Player_num].callsign); + if (get_filename(TXT_SELECT_PILOT, ".plr", filename, allow_abort_flag)) + { + if ( filename[0] == '<' ) { + // They selected 'create new pilot' + if (!MakeNewPlayerFile(allow_abort_flag)) + //return 0; // They hit Esc during enter name stage + goto do_menu_again; + } else { + strncpy(Players[Player_num].callsign,filename, CALLSIGN_LEN); + strlwr(Players[Player_num].callsign); + } } if (read_player_file() != EZERO) diff --git a/main/inferno.c b/main/inferno.c index d99dcf4ab..156234f3c 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -344,6 +344,8 @@ int main(int argc, char *argv[]) con_printf( CON_DEBUG, "\nRunning game...\n" ); init_game(); + Players[Player_num].callsign[0] = '\0'; + // If built with editor, option to auto-load a level and quit game // to write certain data. #ifdef EDITOR @@ -377,11 +379,7 @@ int main(int argc, char *argv[]) read_player_file(); WriteConfigFile(); } - else //pilot doesn't exist. get pilot. - RegisterPlayer(); } - else - RegisterPlayer(); } Game_mode = GM_GAME_OVER; diff --git a/main/menu.c b/main/menu.c index e32e3e444..867805abf 100644 --- a/main/menu.c +++ b/main/menu.c @@ -128,57 +128,69 @@ extern void ReorderSecondary(); int newdemo_count_demos(); // ------------------------------------------------------------------------ -int autodemo_menu_check(newmenu *menu, d_event *event, void *userdata ) +int main_menu_handler(newmenu *menu, d_event *event, int *menu_choice ) { int curtime; - menu = menu; - userdata = userdata; - - if (event->type == EVENT_KEY_COMMAND) + switch (event->type) { - // Don't allow them to hit ESC in the main menu. - if (((d_event_keycommand *)event)->keycode==KEY_ESC) - return 1; - } - else if (event->type != EVENT_IDLE) - return 0; - - curtime = timer_get_fixed_seconds(); - if ( keyd_time_when_last_pressed+i2f(25) < curtime || GameArg.SysAutoDemo ) - { - int n_demos; - n_demos = newdemo_count_demos(); - -try_again:; - if (((d_rand() % (n_demos+1)) == 0) && !GameArg.SysAutoDemo) - { + case EVENT_WINDOW_ACTIVATED: + if ( Players[Player_num].callsign[0]==0 ) + RegisterPlayer(); + else + keyd_time_when_last_pressed = timer_get_fixed_seconds(); // .. 20 seconds from now! + break; + + case EVENT_KEY_COMMAND: + // Don't allow them to hit ESC in the main menu. + if (((d_event_keycommand *)event)->keycode==KEY_ESC) + break; + else + return 0; + + case EVENT_IDLE: + curtime = timer_get_fixed_seconds(); + if ( keyd_time_when_last_pressed+i2f(25) < curtime || GameArg.SysAutoDemo ) + { + int n_demos; + n_demos = newdemo_count_demos(); + + try_again:; + if (((d_rand() % (n_demos+1)) == 0) && !GameArg.SysAutoDemo) + { #ifndef SHAREWARE #ifdef OGL - Screen_mode = -1; + Screen_mode = -1; #endif - PlayMovie("intro.mve",0); - songs_play_song(SONG_TITLE,1); - set_screen_mode(SCREEN_MENU); - return -3; //exit menu to force redraw even if not going to game mode. -3 tells menu system not to restore + PlayMovie("intro.mve",0); + songs_play_song(SONG_TITLE,1); + set_screen_mode(SCREEN_MENU); + return -3; //exit menu to force redraw even if not going to game mode. -3 tells menu system not to restore #endif // end of ifndef shareware - } - else - { - if (curtime < 0) curtime = 0; - keyd_time_when_last_pressed = curtime; // Reset timer so that disk won't thrash if no demos. - newdemo_start_playback(NULL); // Randomly pick a file, assume native endian (crashes if not) - if (Newdemo_state == ND_STATE_PLAYBACK) - { - Function_mode = FMODE_GAME; - return -3; //exit menu to get into game mode. -3 tells menu system not to restore + } + else + { + if (curtime < 0) curtime = 0; + keyd_time_when_last_pressed = curtime; // Reset timer so that disk won't thrash if no demos. + newdemo_start_playback(NULL); // Randomly pick a file, assume native endian (crashes if not) + if (Newdemo_state == ND_STATE_PLAYBACK) + { + Function_mode = FMODE_GAME; + return -3; //exit menu to get into game mode. -3 tells menu system not to restore + } + else + goto try_again; //keep trying until we get a demo that works + } } - else - goto try_again; //keep trying until we get a demo that works - } + return 0; + break; + + default: + return 0; + break; } - return 0; + return 1; } static int main_menu_choice = 0; @@ -235,20 +247,14 @@ int DoMenu() newmenu_item m[25]; int num_options = 0; - if ( Players[Player_num].callsign[0]==0 ) { - RegisterPlayer(); - return 0; - } - load_palette(MENU_PALETTE,0,1); //get correct palette do { create_main_menu(m, menu_choice, &num_options); // may have to change, eg, maybe selected pilot and no save games. - keyd_time_when_last_pressed = timer_get_fixed_seconds(); // .. 20 seconds from now! if (main_menu_choice < 0 ) main_menu_choice = 0; - main_menu_choice = newmenu_do2( "", NULL, num_options, m, autodemo_menu_check, NULL, main_menu_choice, Menu_pcx_name); + main_menu_choice = newmenu_do2( "", NULL, num_options, m, (int (*)(newmenu *, d_event *, void *))main_menu_handler, NULL, main_menu_choice, Menu_pcx_name); if ( main_menu_choice > -1 ) do_option(menu_choice[main_menu_choice]); } while( Function_mode==FMODE_MENU ); @@ -612,7 +618,7 @@ int get_filename(char *title, char *type, char *filename, int allow_abort_flag) if (!stricmp(Players[Player_num].callsign, m[i]) ) citem = i; - citem = newmenu_listbox1(title, NumItems, m, allow_abort_flag, citem, (int (*)(listbox *, d_event *, void *))filename_menu_handler, (void *)l->mode); + citem = newmenu_listbox1(title, NumItems, m, allow_abort_flag, citem, (int (*)(listbox *, d_event *, void *))filename_menu_handler, l); if ( citem > -1 ) strncpy( filename, m[citem] + (((l->mode == FILE_PLAYER_MODE) && m[citem][0]=='$')?1:0), PATH_MAX ); diff --git a/main/newmenu.c b/main/newmenu.c index cfec4cc44..0340e4b25 100644 --- a/main/newmenu.c +++ b/main/newmenu.c @@ -1264,7 +1264,10 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu) break; default: - return 0; + if (menu->subfunction) + return (*menu->subfunction)(menu, event, menu->userdata); + else + return 0; break; } @@ -1947,7 +1950,10 @@ int listbox_handler(window *wind, d_event *event, listbox *lb) break; default: - return 0; + if (lb->listbox_callback) + return (*lb->listbox_callback)(lb, event, lb->userdata); + else + return 0; break; }