diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c209d2c6e..e8ad8ab61 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20100206 -------- main/newmenu.c: Set the correct scroll position for the listbox when it's shown +main/gameseq.c, main/gameseq.h, main/menu.c, main/menu.h: Handle player selection and demo playing in filename_menu_handler, fixing bug where it won't leave the player listbox if there's no LastPlayer; close do_options dialog when changing resolution 20100205 -------- diff --git a/main/gameseq.c b/main/gameseq.c index 42b09fcbc..e3fa89872 100644 --- a/main/gameseq.c +++ b/main/gameseq.c @@ -590,37 +590,18 @@ try_again: //Inputs the player's name, without putting up the background screen int RegisterPlayer() { - char filename[PATH_MAX]; int allow_abort_flag = 1; - if ( Players[Player_num].callsign[0] == 0 ) { + if ( Players[Player_num].callsign[0] == 0 ) + { // Read the last player's name from config file, not lastplr.txt strncpy( Players[Player_num].callsign, GameCfg.LastPlayer, CALLSIGN_LEN ); if (GameCfg.LastPlayer[0]==0) allow_abort_flag = 0; - } - -do_menu_again: - ; - - 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) - goto do_menu_again; - - WriteConfigFile(); // Update lastplr + select_filename(TXT_SELECT_PILOT, ".plr", allow_abort_flag); return 1; } diff --git a/main/gameseq.h b/main/gameseq.h index ed2f9043c..cb1d1a93c 100644 --- a/main/gameseq.h +++ b/main/gameseq.h @@ -1,3 +1,4 @@ +/* $Id: gameseq.h,v 1.1.1.1 2006/03/17 19:57:54 zicodxx Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -7,164 +8,15 @@ IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ -/* - * $Source: /cvsroot/dxx-rebirth/d1x-rebirth/main/gameseq.h,v $ - * $Revision: 1.1.1.1 $ - * $Author: zicodxx $ - * $Date: 2006/03/17 19:45:04 $ - * - * Prototypes for functions for game sequencing. - * - * $Log: gameseq.h,v $ - * Revision 1.1.1.1 2006/03/17 19:45:04 zicodxx - * initial import - * - * Revision 1.1.1.1 1999/06/14 22:12:27 donut - * Import of d1x 1.37 source. - * - * Revision 2.0 1995/02/27 11:32:03 john - * New version 2.0, which has no anonymous unions, builds with - * Watcom 10.0, and doesn't require parsing BITMAPS.TBL. - * - * Revision 1.41 1995/02/07 10:51:54 rob - * fix typo. - * - * Revision 1.40 1995/02/06 20:10:16 rob - * Extern'ed DoEndLevelScoreGlitz. - * - * Revision 1.39 1995/02/01 16:34:13 john - * Linted. - * - * Revision 1.38 1995/01/27 11:15:03 rob - * Added extern for player position vars. - * - * Revision 1.37 1995/01/20 22:47:38 matt - * Mission system implemented, though imcompletely - * - * Revision 1.36 1995/01/17 13:36:08 john - * Moved pig loading into StartNewLevelSub. - * - * Revision 1.35 1995/01/04 12:21:28 john - * *** empty log message *** - * - * Revision 1.34 1995/01/04 12:20:47 john - * Declearations to work better with game state save. - * - * - * Revision 1.33 1994/12/08 09:46:35 matt - * Made level name len a multiple of 4 for alignment - * - * Revision 1.32 1994/11/29 16:33:29 rob - * Added new defines for last_secret_level based on shareware or not shareware. - * - * Revision 1.31 1994/11/26 15:30:20 matt - * Allow escape out of change pilot menu - * - * Revision 1.30 1994/11/21 17:29:38 matt - * Cleaned up sequencing & game saving for secret levels - * - * Revision 1.29 1994/11/21 15:55:03 matt - * Corrected LAST_LEVEL - * - * Revision 1.28 1994/11/20 22:12:43 mike - * set LAST_LEVEL based on SHAREWARE. - * - * Revision 1.27 1994/11/09 10:55:51 matt - * Cleaned up initialization for editor -> game transitions - * - * Revision 1.26 1994/11/08 17:50:48 rob - * ADded prototype for StartNewLEvel. - * - * - * Revision 1.25 1994/11/07 17:50:57 rob - * Added extern prototype for init_player_stats_level called for - * network games. - * - * Revision 1.24 1994/10/25 15:40:03 yuan - * *** empty log message *** - * - * Revision 1.23 1994/10/22 00:08:52 matt - * Fixed up problems with bonus & game sequencing - * Player doesn't get credit for hostages unless he gets them out alive - * - * Revision 1.22 1994/10/18 18:57:08 matt - * Added main menu option to enter new player name - * - * Revision 1.21 1994/10/07 23:37:32 matt - * Added prototype - * - * Revision 1.20 1994/10/07 16:02:53 matt - * Loading saved game no longer clears players weapons & other stats - * - * Revision 1.19 1994/10/06 14:12:46 matt - * Added flash effect when player appears - * - * Revision 1.18 1994/10/03 13:34:44 matt - * Added new (and hopefully better) game sequencing functions - * - * Revision 1.17 1994/09/30 15:19:53 matt - * Added new game sequencing functions, but left them disabled for now. - * - * Revision 1.16 1994/09/28 17:24:34 matt - * Added first draft of game save/load system - * - * Revision 1.15 1994/09/27 12:29:42 matt - * Changed level naming - * - * Revision 1.14 1994/09/02 11:53:55 mike - * Rename init_player_stats to init_player_stats_game. - * - * Revision 1.13 1994/08/31 20:57:34 matt - * Cleaned up endlevel/death code - * - * Revision 1.12 1994/08/23 18:45:06 yuan - * Added level 10 capability.. (LEDGES) - * - * Revision 1.11 1994/08/18 10:47:38 john - * Cleaned up game sequencing and player death stuff - * in preparation for making the player explode into - * pieces when dead. - * - * Revision 1.10 1994/08/15 15:24:45 john - * Made players know who killed them; Disabled cheat menu - * during net player; fixed bug with not being able to turn - * of invulnerability; Made going into edit/starting new leve - * l drop you out of a net game; made death dialog box. - * - * Revision 1.9 1994/08/13 12:20:56 john - * Made the networking uise the Players array. - * - * Revision 1.8 1994/07/22 12:36:24 matt - * Cleaned up editor/game interactions some more. - * - * Revision 1.7 1994/07/19 20:15:33 matt - * Name for each level now saved in the .SAV file & stored in Current_level_name - * - * Revision 1.6 1994/07/02 13:49:33 matt - * Cleaned up includes - * - * Revision 1.5 1994/07/02 13:09:52 matt - * Moved player stats struct from gameseq.h to player.h - * - * Revision 1.4 1994/07/01 16:35:35 yuan - * Added key system - * - * Revision 1.3 1994/06/26 14:07:35 matt - * Added prototypes - * - * Revision 1.2 1994/06/24 17:03:56 john - * Added VFX support. Also took all game sequencing stuff like - * EndGame out and put it into gameseq.c - * - * Revision 1.1 1994/06/24 14:13:53 john - * Initial revision - * - * - */ +/* + * + * Prototypes for functions for game sequencing. + * + */ #ifndef _GAMESEQ_H @@ -173,10 +25,10 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "player.h" #include "mission.h" -#define SUPER_MISSILE 0 -#define SUPER_SEEKER 1 -#define SUPER_SMARTBOMB 2 -#define SUPER_SHOCKWAVE 3 +#define SUPER_MISSILE 0 +#define SUPER_SEEKER 1 +#define SUPER_SMARTBOMB 2 +#define SUPER_SHOCKWAVE 3 #ifdef SHAREWARE #define Last_level 7 //the number of the very last level for shareware @@ -187,86 +39,87 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. // extern int Secret_level_table[MAX_SECRET_LEVELS_PER_MISSION]; -#define LEVEL_NAME_LEN 36 //make sure this is multipe of 4! +#define LEVEL_NAME_LEN 36 //make sure this is multiple of 4! -//Current_level_num starts at 1 for the first level -//-1,-2,-3 are secret levels -//0 means not a real level loaded -extern int Current_level_num,Next_level_num; +// Current_level_num starts at 1 for the first level +// -1,-2,-3 are secret levels +// 0 means not a real level loaded +extern int Current_level_num, Next_level_num; extern char Current_level_name[LEVEL_NAME_LEN]; -extern obj_position Player_init[MAX_PLAYERS]; +extern obj_position Player_init[MAX_PLAYERS]; -//This is the highest level the player has ever reached +// This is the highest level the player has ever reached extern int Player_highest_level; // -// New game sequencing functions +// New game sequencing functions // -//called once at program startup to get the player's name +// called once at program startup to get the player's name int RegisterPlayer(); +int MakeNewPlayerFile(int allow_abort); -//Inputs the player's name, without putting up the background screen +// Inputs the player's name, without putting up the background screen void RegisterPlayerSub(int allow_abort_flag); -//starts a new game on the given level +// starts a new game on the given level void StartNewGame(int start_level); -//starts the next level +// starts the next level void StartNewLevel(int level_num); // Actually does the work to start new level void StartNewLevelSub(int level_num, int page_in_textures); -void InitPlayerObject(); //make sure player's object set up -void init_player_stats_game(); //clear all stats +void InitPlayerObject(); //make sure player's object set up +void init_player_stats_game(); //clear all stats -//starts a resumed game loaded from disk +// starts a resumed game loaded from disk void ResumeSavedGame(int start_level); -//called when the player has finished a level -//if secret flag is true, advance to secret level, else next normal level +// called when the player has finished a level +// if secret flag is true, advance to secret level, else next normal level void PlayerFinishedLevel(int secret_flag); -//called when the player has died -void DoPlayerDead(); +// called when the player has died +void DoPlayerDead(void); -//load a level off disk. level numbers start at 1. -//Secret levels are -1,-2,-3 +// load a level off disk. level numbers start at 1. +// Secret levels are -1,-2,-3 void LoadLevel(int level_num); extern void gameseq_remove_unused_players(); -extern void show_help(); +extern void show_help(); extern void update_player_stats(); -//from scores.c +// from scores.c -extern void show_high_scores( int place ); -extern void draw_high_scores( int place ); +extern void show_high_scores(int place); +extern void draw_high_scores(int place); extern int add_player_to_high_scores(player *pp); -extern void input_name ( int place ); +extern void input_name (int place); extern int reset_high_scores(); extern void init_player_stats_level(); void open_message_window(void); void close_message_window(void); -//create flash for player appearance +// create flash for player appearance extern void create_player_appearance_effect(object *player_obj); -//goto whatever secrect level is appropriate given the current level +// goto whatever secrect level is appropriate given the current level //extern int goto_secret_level(); -//reset stuff so game is semi-normal when playing from editor +// reset stuff so game is semi-normal when playing from editor void editor_reset_stuff_on_level(); -//Show endlevel bonus scores +// Show endlevel bonus scores extern void DoEndLevelScoreGlitz(int network); -//stuff for multiplayer +// stuff for multiplayer extern int MaxNumNetPlayers; extern int NumNetPlayerPositions; -#endif +#endif /* _GAMESEQ_H */ diff --git a/main/menu.c b/main/menu.c index 3ab7af0ab..3104c6411 100644 --- a/main/menu.c +++ b/main/menu.c @@ -257,12 +257,8 @@ void do_option ( int select) case MENU_GAME: break; case MENU_DEMO_PLAY: - { - char demo_file[PATH_MAX]; - if (get_filename(TXT_SELECT_DEMO, ".dem", demo_file, 1)) - newdemo_start_playback(demo_file); + select_filename(TXT_SELECT_DEMO, ".dem", 1); break; - } case MENU_LOAD_GAME: state_restore_all(0); break; @@ -420,13 +416,10 @@ typedef struct file_list char **list; // just to free it in below callback } file_list; -int filename_menu_handler( listbox *lb, d_event *event, file_list *l ) +int filename_menu_keycommand( listbox *lb, d_event *event, file_list *l ) { char **items = listbox_get_items(lb); int citem = listbox_get_citem(lb); - - if (event->type != EVENT_KEY_COMMAND) - return 0; switch (((d_event_keycommand *)event)->keycode) { @@ -438,7 +431,7 @@ int filename_menu_handler( listbox *lb, d_event *event, file_list *l ) x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_PILOT, items[citem]+(((l->mode == FILE_PLAYER_MODE) && items[citem][0]=='$')?1:0) ); else if (l->mode == FILE_DEMO_MODE) x = nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "%s %s?", TXT_DELETE_DEMO, items[citem]+(((l->mode == FILE_DEMO_MODE) && items[citem][0]=='$')?1:0) ); - if (x==0) { + if (x==0) { char * p; char plxfile[PATH_MAX], efffile[PATH_MAX]; int ret; @@ -476,12 +469,12 @@ int filename_menu_handler( listbox *lb, d_event *event, file_list *l ) else listbox_delete_item(lb, citem); } - + return 1; } break; - - case KEY_CTRLED+KEY_C: + + case KEY_CTRLED+KEY_C: if (l->mode == FILE_DEMO_MODE) { int x = 1; @@ -502,11 +495,69 @@ int filename_menu_handler( listbox *lb, d_event *event, file_list *l ) } break; } + + return 0; +} + +int filename_menu_handler( listbox *lb, d_event *event, file_list *l ) +{ + char **items = listbox_get_items(lb); + int citem = listbox_get_citem(lb); + + switch (event->type) + { + case EVENT_KEY_COMMAND: + return filename_menu_keycommand(lb, event, l); + break; + + case EVENT_NEWMENU_SELECTED: + if (citem < 0) + return 0; // shouldn't happen + + switch (l->mode) + { + case FILE_PLAYER_MODE: + if (citem == 0) + { + // They selected 'create new pilot' + return !MakeNewPlayerFile(1); + } + else + { + strncpy(Players[Player_num].callsign,items[citem] + ((items[citem][0]=='$')?1:0), CALLSIGN_LEN); + strlwr(Players[Player_num].callsign); + } + break; + + case FILE_DEMO_MODE: + newdemo_start_playback(items[citem]); + // return 1; // later - when the listbox uses the main loop + break; + } + break; + + case EVENT_WINDOW_CLOSE: + if (l->mode == FILE_PLAYER_MODE) + { + if (read_player_file() != EZERO) + return 1; // abort close! + + WriteConfigFile(); // Update lastplr + } + + PHYSFS_freeList(l->list); + d_free(items); + d_free(l); + break; + + default: + break; + } return 0; } -int get_filename(char *title, char *type, char *filename, int allow_abort_flag) +int select_filename(char *title, char *type, int allow_abort_flag) { char **m; char **f; @@ -539,7 +590,7 @@ int get_filename(char *title, char *type, char *filename, int allow_abort_flag) return 0; } else if ( !*l->list && (l->mode == FILE_PLAYER_MODE) ) { - strcpy(filename, TXT_CREATE_NEW); // make a new player without showing listbox + MakeNewPlayerFile(allow_abort_flag); // make a new player without showing listbox PHYSFS_freeList(l->list); d_free(l); return 0; @@ -591,18 +642,8 @@ 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, l); - - if ( citem > -1 ) - strncpy( filename, m[citem] + (((l->mode == FILE_PLAYER_MODE) && m[citem][0]=='$')?1:0), PATH_MAX ); - - PHYSFS_freeList(l->list); - d_free(m); - d_free(l); + newmenu_listbox1(title, NumItems, m, allow_abort_flag, citem, (int (*)(listbox *, d_event *, void *))filename_menu_handler, l); - if (citem < 0) - return 0; // aborted - return 1; } @@ -821,6 +862,8 @@ void change_res() gr_set_mode(Game_screen_mode); init_cockpit(); game_init_render_buffers(SM_W(screen_mode), SM_H(screen_mode), VR_NONE); + window_close(window_get_front()); // close options dialog - it will be messy with a different resolution + //do_options_menu(); // reopen it. D'OH: Can't yet, not until we have a main event loop for it } int input_menuset(newmenu *menu, d_event *event, void *userdata) diff --git a/main/menu.h b/main/menu.h index e4fe6f64f..9c7f3dc50 100644 --- a/main/menu.h +++ b/main/menu.h @@ -23,7 +23,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. // returns number of item chosen extern int DoMenu(); extern void do_options_menu(); -extern int get_filename(char *title, char *type, char *filename, int allow_abort_flag); +extern int select_filename(char *title, char *type, int allow_abort_flag); #define Menu_pcx_name (((SWIDTH>=640&&SHEIGHT>=480) && cfexist("menuh.pcx"))?"menuh.pcx":"menu.pcx") #define STARS_BACKGROUND (((SWIDTH>=640&&SHEIGHT>=480) && cfexist("starsb.pcx"))?"starsb.pcx":"stars.pcx")