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

This commit is contained in:
kreatordxx 2010-01-27 09:11:47 +00:00
parent 3a116769be
commit 71c656200b
5 changed files with 76 additions and 65 deletions

View file

@ -3,6 +3,7 @@ D2X-Rebirth Changelog
20100127 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/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 20100126
-------- --------

View file

@ -687,17 +687,17 @@ int RegisterPlayer()
do_menu_again: do_menu_again:
; ;
if (!get_filename(TXT_SELECT_PILOT, ".plr", filename, allow_abort_flag)) if (get_filename(TXT_SELECT_PILOT, ".plr", filename, allow_abort_flag))
goto do_menu_again; // They hit Esc in file selector {
if ( filename[0] == '<' ) {
if ( filename[0] == '<' ) { // They selected 'create new pilot'
// They selected 'create new pilot' if (!MakeNewPlayerFile(allow_abort_flag))
if (!MakeNewPlayerFile(allow_abort_flag)) //return 0; // They hit Esc during enter name stage
//return 0; // They hit Esc during enter name stage goto do_menu_again;
goto do_menu_again; } else {
} else { strncpy(Players[Player_num].callsign,filename, CALLSIGN_LEN);
strncpy(Players[Player_num].callsign,filename, CALLSIGN_LEN); strlwr(Players[Player_num].callsign);
strlwr(Players[Player_num].callsign); }
} }
if (read_player_file() != EZERO) if (read_player_file() != EZERO)

View file

@ -344,6 +344,8 @@ int main(int argc, char *argv[])
con_printf( CON_DEBUG, "\nRunning game...\n" ); con_printf( CON_DEBUG, "\nRunning game...\n" );
init_game(); init_game();
Players[Player_num].callsign[0] = '\0';
// If built with editor, option to auto-load a level and quit game // If built with editor, option to auto-load a level and quit game
// to write certain data. // to write certain data.
#ifdef EDITOR #ifdef EDITOR
@ -377,11 +379,7 @@ int main(int argc, char *argv[])
read_player_file(); read_player_file();
WriteConfigFile(); WriteConfigFile();
} }
else //pilot doesn't exist. get pilot.
RegisterPlayer();
} }
else
RegisterPlayer();
} }
Game_mode = GM_GAME_OVER; Game_mode = GM_GAME_OVER;

View file

@ -128,57 +128,69 @@ extern void ReorderSecondary();
int newdemo_count_demos(); 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; int curtime;
menu = menu; switch (event->type)
userdata = userdata;
if (event->type == EVENT_KEY_COMMAND)
{ {
// Don't allow them to hit ESC in the main menu. case EVENT_WINDOW_ACTIVATED:
if (((d_event_keycommand *)event)->keycode==KEY_ESC) if ( Players[Player_num].callsign[0]==0 )
return 1; RegisterPlayer();
} else
else if (event->type != EVENT_IDLE) keyd_time_when_last_pressed = timer_get_fixed_seconds(); // .. 20 seconds from now!
return 0; break;
curtime = timer_get_fixed_seconds(); case EVENT_KEY_COMMAND:
if ( keyd_time_when_last_pressed+i2f(25) < curtime || GameArg.SysAutoDemo ) // Don't allow them to hit ESC in the main menu.
{ if (((d_event_keycommand *)event)->keycode==KEY_ESC)
int n_demos; break;
n_demos = newdemo_count_demos(); else
return 0;
try_again:;
if (((d_rand() % (n_demos+1)) == 0) && !GameArg.SysAutoDemo) 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 #ifndef SHAREWARE
#ifdef OGL #ifdef OGL
Screen_mode = -1; Screen_mode = -1;
#endif #endif
PlayMovie("intro.mve",0); PlayMovie("intro.mve",0);
songs_play_song(SONG_TITLE,1); songs_play_song(SONG_TITLE,1);
set_screen_mode(SCREEN_MENU); 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 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 #endif // end of ifndef shareware
} }
else else
{ {
if (curtime < 0) curtime = 0; if (curtime < 0) curtime = 0;
keyd_time_when_last_pressed = curtime; // Reset timer so that disk won't thrash if no demos. 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) newdemo_start_playback(NULL); // Randomly pick a file, assume native endian (crashes if not)
if (Newdemo_state == ND_STATE_PLAYBACK) if (Newdemo_state == ND_STATE_PLAYBACK)
{ {
Function_mode = FMODE_GAME; Function_mode = FMODE_GAME;
return -3; //exit menu to get into game mode. -3 tells menu system not to restore 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 return 0;
goto try_again; //keep trying until we get a demo that works break;
}
default:
return 0;
break;
} }
return 0; return 1;
} }
static int main_menu_choice = 0; static int main_menu_choice = 0;
@ -235,20 +247,14 @@ int DoMenu()
newmenu_item m[25]; newmenu_item m[25];
int num_options = 0; int num_options = 0;
if ( Players[Player_num].callsign[0]==0 ) {
RegisterPlayer();
return 0;
}
load_palette(MENU_PALETTE,0,1); //get correct palette load_palette(MENU_PALETTE,0,1); //get correct palette
do { do {
create_main_menu(m, menu_choice, &num_options); // may have to change, eg, maybe selected pilot and no save games. 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 ) if (main_menu_choice < 0 )
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]); if ( main_menu_choice > -1 ) do_option(menu_choice[main_menu_choice]);
} while( Function_mode==FMODE_MENU ); } 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]) ) if (!stricmp(Players[Player_num].callsign, m[i]) )
citem = 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 ) if ( citem > -1 )
strncpy( filename, m[citem] + (((l->mode == FILE_PLAYER_MODE) && m[citem][0]=='$')?1:0), PATH_MAX ); strncpy( filename, m[citem] + (((l->mode == FILE_PLAYER_MODE) && m[citem][0]=='$')?1:0), PATH_MAX );

View file

@ -1264,7 +1264,10 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu)
break; break;
default: default:
return 0; if (menu->subfunction)
return (*menu->subfunction)(menu, event, menu->userdata);
else
return 0;
break; break;
} }
@ -1947,7 +1950,10 @@ int listbox_handler(window *wind, d_event *event, listbox *lb)
break; break;
default: default:
return 0; if (lb->listbox_callback)
return (*lb->listbox_callback)(lb, event, lb->userdata);
else
return 0;
break; break;
} }