diff --git a/src/menu.c b/src/menu.c index e4ca12c..d5d887d 100644 --- a/src/menu.c +++ b/src/menu.c @@ -53,30 +53,28 @@ int menu_open = 0; /**< Store the opened/closed menus. */ /* Main menu. */ void menu_main_close(void); /**< Externed in save.c */ -static void menu_main_load(char* str); -static void menu_main_new(char* str); -static void menu_main_exit(char* str); +static void menu_main_load(unsigned int wid, char* str); +static void menu_main_new(unsigned int wid, char* str); +static void menu_main_exit(unsigned int wid, char* str); /* Small menu. */ -static void menu_small_close(char* str); -static void menu_small_exit(char* str); +static void menu_small_close(unsigned int wid, char* str); +static void menu_small_exit(unsigned int wid, char* str); static void exit_game(void); /* Information menu. */ -static void menu_info_close(char* str); +static void menu_info_close(unsigned int wid, char* str); /* Outfits submenu. */ -static void info_outfits_menu(char* str); +static void info_outfits_menu(unsigned int parent, char* str); /* Cargo submenu. */ -static void info_cargo_menu(char* str); -static void cargo_update(char* str); -static void cargo_jettison(char* str); +static void info_cargo_menu(unsigned int parent, char* str); +static void cargo_update(unsigned int wid, char* str); +static void cargo_jettison(unsigned int wid, char* str); /* Mission submenu. */ -static void info_missions_menu(char* str); -static void mission_menu_abort(char* str); -static void mission_menu_genList(int first); -static void mission_menu_update(char* str); +static void info_missions_menu(unsigned int parent, char* str); +static void mission_menu_abort(unsigned int wid, char* str); +static void mission_menu_genList(unsigned int wid, int first); +static void mission_menu_update(unsigned int wid, char* str); /* Death menu. */ -static void menu_death_main(char* str); -/* Generic. */ -static void menu_generic_close(char* str); +static void menu_death_main(unsigned int parent, char* str); /** * @fn void menu_main(void) @@ -132,41 +130,38 @@ void menu_main_close(void) { } /** - * @fn static void menu_main_load(char* str) - * * @brief Function to activate the load game menu. * @param str Unused. */ -static void menu_main_load(char* str) { +static void menu_main_load(unsigned int wid, char* str) { (void)str; + (void)wid; load_game_menu(); } /** - * @fn static void menu_main_new(char* str) - * * @brief Function to activate the new game menu. * @param str Unused. */ -static void menu_main_new(char* str) { +static void menu_main_new(unsigned int wid, char* str) { (void)str; + (void)wid; menu_main_close(); player_new(); } /** - * @fn static void menu_main_new(char* str) - * * @brief Function to exit the main menu and game. * @param str Unused. */ -static void menu_main_exit(char* str) { +static void menu_main_exit(unsigned int wid, char* str) { (void)str; - unsigned int wid; + (void)wid; + unsigned int bg; - wid = window_get("BG"); + bg = window_get("BG"); /* * Ugly hack to prevent player.c from segfaulting due to the fact @@ -175,8 +170,8 @@ static void menu_main_exit(char* str) { * nor anything of the likes (nor toolkit to stop rendering) while not * leaking any texture. */ - gl_freeTexture(window_getImage(wid, "imgLogo")); - window_modifyImage(wid, "imgLogo", NULL); + gl_freeTexture(window_getImage(bg, "imgLogo")); + window_modifyImage(bg, "imgLogo", NULL); exit_game(); } @@ -218,33 +213,27 @@ void menu_small(void) { } /** - * @fn static void menu_small_close(char* str) - * * @brief Close the small ingame menu. * @param str Unused. */ -static void menu_small_close(char* str) { +static void menu_small_close(unsigned int wid, char* str) { (void)str; - window_destroy(window_get("Menu")); + window_destroy(wid); menu_Close(MENU_SMALL); } /** - * @fn static void menu_small_exit(char* str) - * * @brief Close the small ingame menu and go back to the main menu. * @param str Unused. */ -static void menu_small_exit(char* str) { +static void menu_small_exit(unsigned int wid, char* str) { (void)str; - window_destroy(window_get("Menu")); + window_destroy(wid); menu_Close(MENU_SMALL); menu_main(); } /** - * @fn static void exit_game(void) - * * @brief Exit the game. */ static void exit_game(void) { @@ -323,26 +312,22 @@ void menu_info(void) { } /** - * @fn static void menu_info_close(char* str) - * * @brief Close the information menu. * @param str Unused. */ -static void menu_info_close(char* str) { - if(strcmp(str, "btnClose")==0) - window_destroy(window_get("Info")); - +static void menu_info_close(unsigned int wid, char* str) { + (void)str; + window_destroy(wid); menu_Close(MENU_INFO); } /** - * @fn static void info_outfits_menu(char* str) - * * @brief Show the player what outfits she has. * @param str Unused. */ -static void info_outfits_menu(char* str) { +static void info_outfits_menu(unsigned int parent, char* str) { (void) str; + (void) parent; char* buf; unsigned int wid; @@ -364,17 +349,16 @@ static void info_outfits_menu(char* str) { /* Buttons. */ window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, - "closeOutfits", "Close", menu_generic_close); + "closeOutfits", "Close", window_close); } /** - * @fn static void info_cargo_menu(char* str) - * * @brief Show the player her cargo. * @param str Unused. */ -static void info_cargo_menu(char* str) { +static void info_cargo_menu(unsigned int parent, char* str) { (void)str; + (void)parent; unsigned int wid; char** buf; int nbuf; @@ -385,7 +369,7 @@ static void info_cargo_menu(char* str) { /* Buttons. */ window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, - "closeCargo", "Back", menu_generic_close); + "closeCargo", "Back", window_close); window_addButton(wid, -40 - BUTTON_WIDTH, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnJettisonCargo", "Jettison", cargo_jettison); @@ -414,23 +398,19 @@ static void info_cargo_menu(char* str) { CARGO_WIDTH - 40, CARGO_HEIGHT - BUTTON_HEIGHT - 80, "lstCargo", buf, nbuf, 0, cargo_update); - cargo_update(NULL); + cargo_update(wid, NULL); } /** - * @fn static void cargo_update(char* str) - * * @brief Update the players cargo in the cargo menu. * @param str Unused. */ -static void cargo_update(char* str) { +static void cargo_update(unsigned int wid, char* str) { (void)str; - unsigned int wid; int pos; if(player->ncommodities == 0) return; /* No cargo. */ - wid = window_get("Cargo"); pos = toolkit_getListPos(wid, "lstCargo"); /* Can jettison all but mission cargo when not landed. */ @@ -441,19 +421,15 @@ static void cargo_update(char* str) { } /** - * @fn static void cargo_jettison(char* str) - * * @brief Make the player jettison the currently selected cargo. * @param str Unused. */ -static void cargo_jettison(char* str) { +static void cargo_jettison(unsigned int wid, char* str) { (void)str; - unsigned int wid; int pos; if(player->ncommodities == 0) return; /* No cargo, redundant check. */ - wid = window_get("Cargo"); pos = toolkit_getListPos(wid, "lstCargo"); /* Remove the cargo. */ @@ -463,25 +439,24 @@ static void cargo_jettison(char* str) { player->commodities[pos].quantity); /* We reopen the menu to recreate the list now. */ - menu_generic_close("closeCargo"); - info_cargo_menu(NULL); + window_destroy(wid); + info_cargo_menu(0, NULL); } /** - * @fn static void info_missions_menu(char* str) - * * @brief Show the players active missions. * @param str Unused. */ -static void info_missions_menu(char* str) { +static void info_missions_menu(unsigned int parent, char* str) { (void)str; + (void)parent; unsigned int wid; wid = window_create("Missions", -1, -1, MISSIONS_WIDTH, MISSIONS_HEIGHT); /* Buttons. */ window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, - "closeMissions", "Back", menu_generic_close); + "closeMissions", "Back", window_close); window_addButton(wid, -20, 40+BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, "btnAbortMission", "Abort", @@ -500,21 +475,16 @@ static void info_missions_menu(char* str) { "txtDesc", &gl_smallFont, &cBlack, NULL); /* List. */ - mission_menu_genList(1); + mission_menu_genList(wid, 1); } /** - * @fn static void mission_menu_genList(int first) - * * @brief Create the current mission list for the mission menu. * @param first 1 if it's the first time run. */ -static void mission_menu_genList(int first) { +static void mission_menu_genList(unsigned int wid, int first) { int i, j; char** misn_names; - unsigned int wid; - - wid = window_get("Missions"); if(!first) window_destroyWidget(wid, "lstMission"); @@ -536,23 +506,17 @@ static void mission_menu_genList(int first) { 300, MISSIONS_HEIGHT-60, "lstMission", misn_names, j, 0, mission_menu_update); - mission_menu_update(NULL); + mission_menu_update(wid, NULL); } /** - * @fn static void mission_menu_update(char* str) - * * @brief Update the mission menu mission info based on what's selected. * @param str Unused. */ -static void mission_menu_update(char* str) { +static void mission_menu_update(unsigned int wid, char* str) { + (void)str; char* active_misn; Mission* misn; - unsigned int wid; - - (void)str; - - wid = window_get("Missions"); active_misn = toolkit_getList(wid, "lstMission"); if(strcmp(active_misn, "No Missions")==0) { @@ -568,20 +532,15 @@ static void mission_menu_update(char* str) { } /** - * @fn static void mission_menu_abort(char* str) - * * @brief Abort a mission in the mission menu. * @param str Unused. */ -static void mission_menu_abort(char* str) { +static void mission_menu_abort(unsigned int wid, char* str) { (void)str; char* selected_misn; int pos; - unsigned int wid; Mission* misn; - wid = window_get("Missions"); - selected_misn = toolkit_getList(wid, "lstMission"); if(dialogue_YesNo("Abort Mission", @@ -591,7 +550,7 @@ static void mission_menu_abort(char* str) { mission_cleanup(misn); memmove(misn, &player_missions[pos+1], sizeof(Mission) * (MISSION_MAX-pos-1)); - mission_menu_genList(0); + mission_menu_genList(wid, 0); } } @@ -608,7 +567,7 @@ void menu_death(void) { BUTTON_WIDTH, BUTTON_HEIGHT, "btnMain", "Main Menu", menu_death_main); window_addButton(wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, - "btnExit", "Exit Game", (void(*)(char*)) exit_game); + "btnExit", "Exit Game", (void(*)(unsigned int,char*)) exit_game); menu_Open(MENU_DEATH); @@ -617,12 +576,11 @@ void menu_death(void) { } /** - * @fn static void menu_death_main(char* str) - * * @brief Close the player death menu. * @param str Unused. */ -static void menu_death_main(char* str) { +static void menu_death_main(unsigned int parent, char* str) { + (void)parent; (void)str; unsigned int wid; @@ -634,16 +592,3 @@ static void menu_death_main(char* str) { menu_main(); } -/** - * @fn static void menu_generic_close(char* str) - * - * @brief Generic function to close the current window. - * - * Only works if the button is labeled "closeFoo", where "Foo" would be the - * window name. - * @param str Used by the button it's assigned to internally. - */ -static void menu_generic_close(char* str) { - window_destroy(window_get(str+5)); /* closeFoo -> Foo. */ -} -