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
--------
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
--------

View file

@ -687,9 +687,8 @@ 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 (get_filename(TXT_SELECT_PILOT, ".plr", filename, allow_abort_flag))
{
if ( filename[0] == '<' ) {
// They selected 'create new pilot'
if (!MakeNewPlayerFile(allow_abort_flag))
@ -699,6 +698,7 @@ do_menu_again:
strncpy(Players[Player_num].callsign,filename, CALLSIGN_LEN);
strlwr(Players[Player_num].callsign);
}
}
if (read_player_file() != EZERO)
goto do_menu_again;

View file

@ -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;

View file

@ -128,22 +128,27 @@ 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)
{
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)
return 1;
}
else if (event->type != EVENT_IDLE)
break;
else
return 0;
case EVENT_IDLE:
curtime = timer_get_fixed_seconds();
if ( keyd_time_when_last_pressed+i2f(25) < curtime || GameArg.SysAutoDemo )
{
@ -177,8 +182,15 @@ try_again:;
goto try_again; //keep trying until we get a demo that works
}
}
return 0;
break;
default:
return 0;
break;
}
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 );

View file

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