diff --git a/bygfoot.glade b/bygfoot.glade index 71e30d8c..4d11a453 100644 --- a/bygfoot.glade +++ b/bygfoot.glade @@ -55,6 +55,27 @@ + + + True + Load last save + True + + + + + True + gtk-open + 1 + 0.5 + 0.5 + 0 + 0 + + + + + True @@ -110,7 +131,7 @@ - + True gtk-preferences 1 @@ -246,7 +267,7 @@ True All Out Defend True - True + False @@ -256,7 +277,7 @@ True Defend True - True + False menu_all_out_defend @@ -267,7 +288,7 @@ True Balanced True - True + False menu_all_out_defend @@ -278,7 +299,7 @@ True Attack True - True + False menu_all_out_defend @@ -313,7 +334,7 @@ True Best True - True + False @@ -323,7 +344,7 @@ True Good True - True + False menu_scout_best @@ -334,7 +355,7 @@ True Average True - True + False menu_scout_best @@ -369,7 +390,7 @@ True Best True - True + False @@ -379,7 +400,7 @@ True Good True - True + False menu_physio_best @@ -390,7 +411,7 @@ True Average True - True + False menu_physio_best @@ -425,7 +446,7 @@ True On True - True + False @@ -435,7 +456,7 @@ True Off True - True + False menu_boost_on @@ -456,6 +477,12 @@ + + + True + + + True @@ -465,6 +492,17 @@ + + + True + Try to put the startup players onto their favoured positions and sort the substitutes (Ctrl-R or middle click) + Rearrange team + True + + + + + True @@ -609,7 +647,7 @@ - + True gtk-go-forward 1 @@ -631,7 +669,7 @@ - + True gtk-go-back 1 @@ -653,7 +691,7 @@ - + True gtk-justify-fill 1 @@ -743,11 +781,10 @@ 2 True - Load game (L or Ctrl - O) + Load game (Ctrl - O) True GTK_RELIEF_NORMAL - @@ -776,7 +813,6 @@ True GTK_RELIEF_NORMAL - diff --git a/bygfoot_misc.glade b/bygfoot_misc.glade index c72abe64..1dbe90db 100644 --- a/bygfoot_misc.glade +++ b/bygfoot_misc.glade @@ -715,7 +715,7 @@ True - Resume last game + _Resume last game True False GTK_JUSTIFY_LEFT @@ -1452,6 +1452,7 @@ False True False + diff --git a/src/Makefile.am b/src/Makefile.am index b4d259ac..ae866793 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,7 @@ bygfoot_SOURCES = \ interface.c callbacks.h interface.h support.h \ league.c cup.h league.h table.h team.h variables.h \ live_game.c fixture.h free.h game.h game_gui.h live_game.h maths.h misc_callback_func.h option.h player.h support.h team.h treeview.h user.h variables.h window.h \ - load_save.c file.h game_gui.h gui.h load_save.h option.h support.h variables.h xml_loadsave_misc.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_transfers.h xml_loadsave_users.h xml.h \ + load_save.c callbacks.h file.h game_gui.h gui.h load_save.h option.h support.h variables.h xml_loadsave_misc.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_transfers.h xml_loadsave_users.h xml.h \ main.c cup_struct.h misc_callbacks.h file.h free.h league_struct.h live_game.h main.h transfer_struct.h variables.h window.h \ maths.c maths.h misc.h \ misc.c main.h maths.h misc.h \ @@ -33,7 +33,7 @@ bygfoot_SOURCES = \ misc2_callback_func.c file.h finance.h game_gui.h maths.h misc2_callback_func.h option.h player.h support.h team.h treeview.h transfer.h user.h window.h \ misc2_interface.c misc2_interface.h misc2_callbacks.h support.h \ option.c option.h variables.h \ - option_gui.c file.h option_gui.h option.h support.h user.h variables.h \ + option_gui.c file.h callbacks.h option_gui.h option.h support.h user.h variables.h \ options_callbacks.c file.h options_callbacks.h options_interface.h option_gui.h support.h user.h variables.h window.h \ options_interface.c options_interface.h options_callbacks.h support.h \ player.c cup.h free.h game_gui.h league.h maths.h misc.h option.h player.h team.h user.h \ @@ -45,7 +45,7 @@ bygfoot_SOURCES = \ treeview.c cup.h file.h finance.h fixture.h free.h game.h league.h live_game.h maths.h misc.h player.h option.h support.h team.h transfer.h treeview.h treeview_cell.h user.h \ treeview_cell.c cup.h league.h misc.h option.h player.h team.h treeview.h treeview_cell.h user.h variables.h \ user.c fixture.h free.h game_gui.h live_game.h maths.h misc.h option.h player.h team.h transfer.h treeview.h user.h window.h \ - window.c file.h finance.h free.h game_gui.h gui.h interface.h misc_interface.h misc2_interface.h option.h support.h user.h window.h \ + window.c file.h finance.h free.h game_gui.h gui.h interface.h main.h misc_interface.h misc2_interface.h option.h support.h user.h window.h \ xml.c cup.h file.h free.h gui.h league.h misc.h support.h table.h transfer_struct.h user.h variables.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_teams.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_transfers.h xml_loadsave_users.h \ xml_loadsave_misc.c file.h misc.h variables.h xml.h xml_loadsave_misc.h xml_loadsave_cup.h xml_loadsave_league.h \ xml_loadsave_cup.c cup.h file.h misc.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \ diff --git a/src/bygfoot.h b/src/bygfoot.h index 6c77a356..25403e5c 100644 --- a/src/bygfoot.h +++ b/src/bygfoot.h @@ -58,7 +58,7 @@ enum ExitCodes { EXIT_OK = 0, /**< Normal exit. */ - EXIT_DIR_OPEN_FAILED, /**< Exit when the $HOME/.bygfoot/definitions directory can't be opened. */ + EXIT_NO_COUNTRY_FILES, /**< Exit when no country files have been found. */ EXIT_FILE_OPEN_FAILED, /** A file could not be opened. */ EXIT_PRINT_ERROR, /**< Exit when the print_error function is called on a set error.*/ EXIT_NO_LEAGUES, /**< The game must contain at least one league. */ diff --git a/src/callback_func.c b/src/callback_func.c index c23d8220..b94d6c32 100644 --- a/src/callback_func.c +++ b/src/callback_func.c @@ -130,6 +130,10 @@ callback_show_last_match(void) window_create(WINDOW_LIVE); + current_user.live_game.fix = + &g_array_index(league_cup_get_fixtures(current_user.live_game.fix_clid), + Fixture, current_user.live_game.fix_idx); + treeview_show_game_stats(GTK_TREE_VIEW(lookup_widget(window.live, "treeview_stats")), ¤t_user.live_game); live_game_set_match(¤t_user.live_game); @@ -138,6 +142,18 @@ callback_show_last_match(void) game_gui_live_game_show_unit(&g_array_index(current_user.live_game.units, LiveGameUnit, i)); } +/** Show the last match stats of the current user. */ +void +callback_show_last_match_stats(void) +{ + current_user.live_game.fix = + &g_array_index(league_cup_get_fixtures(current_user.live_game.fix_clid), + Fixture, current_user.live_game.fix_idx); + + treeview_show_game_stats(GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right")), + ¤t_user.live_game); +} + /** Show some fixtures. @param type An integer telling us which league/cup and which week and round to show. */ diff --git a/src/callback_func.h b/src/callback_func.h index d62da031..b020e36a 100644 --- a/src/callback_func.h +++ b/src/callback_func.h @@ -39,4 +39,7 @@ callback_show_player_list(gint type); void callback_fire_player(gint idx); +void +callback_show_last_match_stats(void); + #endif diff --git a/src/callbacks.c b/src/callbacks.c index e47f27c3..f2c15650 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -108,6 +108,7 @@ on_button_back_to_main_clicked (GtkButton *button, gpointer user_data) { stat0 = STATUS_MAIN; + gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(window.main, "notebook_player")), 0); game_gui_show_main(); } @@ -119,6 +120,7 @@ on_button_transfers_clicked (GtkButton *button, stat0 = STATUS_SHOW_TRANSFER_LIST; game_gui_print_message(_("Left click to make an offer. Right click to remove offer.")); treeview_show_transfer_list(GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right"))); + gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(window.main, "notebook_player")), 1); } @@ -161,6 +163,12 @@ on_player_list1_button_press_event (GtkWidget *widget, { gint idx = -1; + if(event->button == 2) + { + on_menu_rearrange_team_activate(NULL, NULL); + return TRUE; + } + if(treeview_select_row(GTK_TREE_VIEW(widget), event)) idx = treeview_get_index(GTK_TREE_VIEW(widget), 0); @@ -187,6 +195,10 @@ on_button_browse_forward_clicked (GtkButton *button, case STATUS_BROWSE_TEAMS: callback_show_team(SHOW_NEXT); break; + case STATUS_SHOW_PLAYER_INFO: + selected_row[0] = (selected_row[0] + 1) % current_user.tm->players->len; + on_menu_show_info_activate(NULL, NULL); + break; } } @@ -202,11 +214,14 @@ on_button_browse_back_clicked (GtkButton *button, break; case STATUS_BROWSE_TEAMS: callback_show_team(SHOW_PREVIOUS); + break; + case STATUS_SHOW_PLAYER_INFO: + selected_row[0] = (selected_row[0] == 0) ? current_user.tm->players->len - 1 : selected_row[0] - 1; + on_menu_show_info_activate(NULL, NULL); + break; } } - - void on_button_cl_back_clicked (GtkButton *button, gpointer user_data) @@ -398,6 +413,16 @@ on_treeview_right_button_press_event (GtkWidget *widget, { gint idx; + if(stat0 == STATUS_SHOW_FINANCES) + { + if(event->button == 1) + callback_get_loan(); + else if(event->button == 3) + callback_pay_loan(); + else if(event->button == 2) + on_menu_show_stadium_activate(NULL, NULL); + } + if(gtk_tree_selection_get_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(widget))) == GTK_SELECTION_NONE) @@ -410,12 +435,6 @@ on_treeview_right_button_press_event (GtkWidget *widget, switch(stat0) { - case STATUS_SHOW_FINANCES: - if(event->button == 1) - callback_get_loan(); - else if(event->button == 3) - callback_pay_loan(); - break; case STATUS_SHOW_TRANSFER_LIST: if(event->button == 1 || trans(idx - 1).tm == current_user.tm) callback_transfer_list_clicked(idx - 1); @@ -519,8 +538,7 @@ on_menu_user_show_last_stats_activate (GtkMenuItem *menuitem, } stat0 = STATUS_SHOW_LAST_MATCH_STATS; - treeview_show_game_stats(GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right")), - ¤t_user.live_game); + callback_show_last_match_stats(); } gboolean @@ -593,7 +611,7 @@ on_menu_show_finances_activate (GtkMenuItem *menuitem, gpointer user_data) { stat0 = STATUS_SHOW_FINANCES; - game_gui_print_message("Left-click on the list to get a loan. Right-click to pay back."); + game_gui_print_message("Left-click: get loan; Right-click: pay back; Middle click: stadium window."); treeview_show_finances(GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right")), ¤t_user); } @@ -708,3 +726,19 @@ on_player_menu_show_info_activate (GtkMenuItem *menuitem, on_menu_show_info_activate(NULL, NULL); } + +void +on_menu_rearrange_team_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + team_rearrange(current_user.tm); + treeview_show_user_player_list(); +} + + +void +on_menu_load_last_save_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + load_save_load_game("last_save"); +} diff --git a/src/callbacks.h b/src/callbacks.h index e15c956a..7e2b932f 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -233,4 +233,11 @@ on_menu_browse_players_activate (GtkMenuItem *menuitem, void on_player_menu_show_info_activate (GtkMenuItem *menuitem, gpointer user_data); +void +on_menu_rearrange_team_activate (GtkMenuItem *menuitem, + gpointer user_data); #endif + +void +on_menu_load_last_save_activate (GtkMenuItem *menuitem, + gpointer user_data); diff --git a/src/file.c b/src/file.c index 25aad79a..4ecfae76 100644 --- a/src/file.c +++ b/src/file.c @@ -53,13 +53,14 @@ file_add_support_directory_recursive (const gchar *directo the full path name. The return value must be freed. @param filename The name of the file we look for (without path). + @param warning Whether to show a warning if we don't find the file. @return A pointer to the full path string of the file or NULL if we didn't find the file. The gchar* must be freed. @see #support_directories @see file_add_support_directory_recursive() */ gchar* -file_find_support_file (const gchar *filename) +file_find_support_file (const gchar *filename, gboolean warning) { GList *elem = support_directories; @@ -74,8 +75,8 @@ file_find_support_file (const gchar *filename) elem = elem->next; } -/* if(opt_int("int_opt_debug")) */ -/* g_warning("file_find_support_file: file '%s' not found.", filename); */ + if(warning) + g_warning("file_find_support_file: file '%s' not found.", filename); return NULL; } @@ -104,7 +105,7 @@ gboolean file_my_fopen(const gchar *filename, gchar *bits, FILE **fil, gboolean abort_program) { gchar buf[SMALL]; - gchar *support_file = file_find_support_file(filename); + gchar *support_file = file_find_support_file(filename, FALSE); *fil = fopen(filename, bits); if(*fil != NULL) @@ -171,7 +172,7 @@ file_check_home_dir_copy_conf_files(void) sprintf(buf, "%s/%s/%s", home, HOMEDIRNAME, conf_files[i]); if(!g_file_test(buf, G_FILE_TEST_EXISTS)) { - conf_file = file_find_support_file(conf_files[i]); + conf_file = file_find_support_file(conf_files[i], TRUE); sprintf(buf, "cp -v %s %s/%s/%s", conf_file, home, HOMEDIRNAME, conf_files[i]); file_my_system(buf); } @@ -239,19 +240,19 @@ file_dir_get_contents(const gchar *dir_name, const gchar *prefix, const gchar *s { GError *error = NULL; GDir *dir = g_dir_open(dir_name, 0, &error); - GPtrArray *contents = NULL; + GPtrArray *contents = g_ptr_array_new(); GString *new = NULL; const gchar *file = NULL; misc_print_error(&error, FALSE); if(dir == NULL) - return NULL; + return contents; file = g_dir_read_name(dir); - if(file != NULL) - contents = g_ptr_array_new(); + if(file == NULL) + return contents; while(file != NULL) { @@ -269,26 +270,34 @@ file_dir_get_contents(const gchar *dir_name, const gchar *prefix, const gchar *s return contents; } -/** Return the first directory called 'definitions' from the support - directories array. */ -const gchar* -file_get_definitions_dir(void) +/** Return the country definition files found in the support dirs. */ +GPtrArray* +file_get_country_files(void) { + gint i; GList *elem = support_directories; - + GPtrArray *country_files = g_ptr_array_new(); + GPtrArray *dir_contents = NULL; + GString *new_string = NULL; + while(elem != NULL) { - if(g_str_has_suffix((gchar*)elem->data, "definitions") || - g_str_has_suffix((gchar*)elem->data, "definitions/")) - return (gchar*)elem->data; - + dir_contents = file_dir_get_contents((gchar*)elem->data, "country_", ".xml"); + + for(i=0;ilen;i++) + if(!query_misc_string_in_array(((GString*)g_ptr_array_index(dir_contents, i))->str, + country_files)) + { + new_string = g_string_new(((GString*)g_ptr_array_index(dir_contents, i))->str); + g_ptr_array_add(country_files, new_string); + } + + free_g_string_array(&dir_contents); + elem = elem->next; } - main_exit_program(EXIT_DIR_OPEN_FAILED, - "Didn't find definitions directory.\n"); - - return NULL; + return country_files; } /** Read the file until the next line that's not a comment or @@ -404,7 +413,7 @@ file_load_opt_file(const gchar *filename, OptionList *optionlist) void file_load_conf_files(void) { - gchar *conf_file = file_find_support_file("bygfoot.conf"); + gchar *conf_file = file_find_support_file("bygfoot.conf", TRUE); file_load_opt_file(conf_file, &options); g_free(conf_file); @@ -421,13 +430,13 @@ file_load_user_conf_file(User *user) gchar *conf_file = NULL, buf[SMALL]; sprintf(buf, "bygfoot_%s.conf", user->name->str); - conf_file = file_find_support_file(buf); + conf_file = file_find_support_file(buf, FALSE); if(conf_file == NULL || !file_my_fopen(conf_file, "r", &fil, FALSE)) { g_free(conf_file); - conf_file = file_find_support_file(opt_str("string_opt_default_user_conf_file")); + conf_file = file_find_support_file(opt_str("string_opt_default_user_conf_file"), TRUE); } file_load_opt_file(conf_file, &user->options); diff --git a/src/file.h b/src/file.h index b9ec60c1..d7d54ff7 100644 --- a/src/file.h +++ b/src/file.h @@ -9,7 +9,7 @@ void file_add_support_directory_recursive (const gchar *directory); gchar* -file_find_support_file (const gchar *filename); +file_find_support_file (const gchar *filename, gboolean warning); gboolean file_get_next_opt_line(FILE *fil, gchar *opt_name, gchar *opt_value); @@ -29,8 +29,8 @@ file_get_player_names(gint number_of_names); gboolean file_my_fopen(const gchar *filename, gchar *bits, FILE **fil, gboolean abort_program); -const gchar* -file_get_definitions_dir(void); +GPtrArray* +file_get_country_files(void); void file_load_conf_files(void); diff --git a/src/finance.c b/src/finance.c index a1f5e36e..4e31ab26 100644 --- a/src/finance.c +++ b/src/finance.c @@ -144,9 +144,9 @@ finance_get_loan(gint value) sprintf(buf, _("You have %d weeks to pay back your loan."), current_user.counters[COUNT_USER_LOAN]); - game_gui_print_message(buf); on_menu_show_finances_activate(NULL, NULL); + game_gui_print_message(buf); } @@ -176,8 +176,8 @@ finance_pay_loan(gint value) current_user.counters[COUNT_USER_LOAN]); } - game_gui_print_message(buf); on_menu_show_finances_activate(NULL, NULL); + game_gui_print_message(buf); } /** Return the cost of a stadium improvement. diff --git a/src/fixture.c b/src/fixture.c index f365def9..967aa09a 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -216,7 +216,6 @@ fixture_get_round_robin_advance(const Cup *cup, gint round) Team* fixture_winner_of(const Fixture *fix) { - gint i; const Fixture *first_leg; const CupRound *cupround = &g_array_index(cup_from_clid(fix->clid)->rounds, CupRound, fix->round); diff --git a/src/game.c b/src/game.c index 10a18726..e00996eb 100644 --- a/src/game.c +++ b/src/game.c @@ -274,10 +274,9 @@ game_initialize(Fixture *fix) if(g_array_index(fix->teams[i]->players, Player, j).cskill > 0) player_games_goals_set(&g_array_index(fix->teams[i]->players, Player, j), fix->clid, PLAYER_VALUE_GAMES, 1, TRUE); - } - g_array_index(fix->teams[i]->players, Player, j).participation = - (j < 11 && g_array_index(fix->teams[i]->players, Player, j).cskill > 0); + g_array_index(fix->teams[i]->players, Player, j).participation = TRUE; + } } if(user_idx[i] != -1) @@ -875,8 +874,7 @@ game_post_match(Fixture *fix) for(i=0;i<2;i++) { - if(team_is_user(fix->teams[i]) == -1 && - fix->teams[i]->clid == fix->clid) + if(team_is_user(fix->teams[i]) == -1) team_update_cpu_team(fix->teams[i], (fixture_user_team_involved(fix) != -1)); else diff --git a/src/game_gui.c b/src/game_gui.c index d061144b..9f73d435 100644 --- a/src/game_gui.c +++ b/src/game_gui.c @@ -246,15 +246,15 @@ game_gui_write_meters(void) GtkImage *image_style = GTK_IMAGE(lookup_widget(window.main, "image_style")), *image_boost = GTK_IMAGE(lookup_widget(window.main, "image_boost")); gchar *image_style_files[5] = - {file_find_support_file(const_str("string_game_gui_style_all_out_defend_icon")), - file_find_support_file(const_str("string_game_gui_style_defend_icon")), - file_find_support_file(const_str("string_game_gui_style_balanced_icon")), - file_find_support_file(const_str("string_game_gui_style_attack_icon")), - file_find_support_file(const_str("string_game_gui_style_all_out_attack_icon"))}; + {file_find_support_file(const_str("string_game_gui_style_all_out_defend_icon"), TRUE), + file_find_support_file(const_str("string_game_gui_style_defend_icon"), TRUE), + file_find_support_file(const_str("string_game_gui_style_balanced_icon"), TRUE), + file_find_support_file(const_str("string_game_gui_style_attack_icon"), TRUE), + file_find_support_file(const_str("string_game_gui_style_all_out_attack_icon"), TRUE)}; gchar *image_boost_files[3] = - {file_find_support_file(const_str("string_game_gui_boost_anti_icon")), - file_find_support_file(const_str("string_game_gui_boost_off_icon")), - file_find_support_file(const_str("string_game_gui_boost_on_icon"))}; + {file_find_support_file(const_str("string_game_gui_boost_anti_icon"), TRUE), + file_find_support_file(const_str("string_game_gui_boost_off_icon"), TRUE), + file_find_support_file(const_str("string_game_gui_boost_on_icon"), TRUE)}; gtk_image_set_from_file(image_style, image_style_files[current_user.tm->style + 2]); gtk_image_set_from_file(image_boost, image_boost_files[current_user.tm->boost + 1]); diff --git a/src/interface.c b/src/interface.c index 16f35964..386a9f99 100644 --- a/src/interface.c +++ b/src/interface.c @@ -37,6 +37,8 @@ create_main_window (void) GtkWidget *menu_file_menu; GtkWidget *menu_new; GtkWidget *menu_open; + GtkWidget *menu_load_last_save; + GtkWidget *image277; GtkWidget *menu_save; GtkWidget *menu_save_as; GtkWidget *trennlinie1; @@ -44,7 +46,7 @@ create_main_window (void) GtkWidget *menu_options; GtkWidget *menu_options_menu; GtkWidget *menu_preferences; - GtkWidget *image264; + GtkWidget *image278; GtkWidget *trennlinie7; GtkWidget *menu_job_offers; GtkWidget *menu_live_game; @@ -86,7 +88,9 @@ create_main_window (void) GtkWidget *menu_boost_on; GtkWidget *menu_boost_off; GtkWidget *menu_boost_anti; + GtkWidget *trennlinie11; GtkWidget *menu_custom_structure; + GtkWidget *menu_rearrange_team; GtkWidget *trennlinie8; GtkWidget *menu_browse_teams; GtkWidget *menu_player; @@ -105,11 +109,11 @@ create_main_window (void) GtkWidget *menu_user_show_last_stats; GtkWidget *trennlinie9; GtkWidget *menu_next_user; - GtkWidget *image265; + GtkWidget *image279; GtkWidget *menu_previous_user; - GtkWidget *image266; + GtkWidget *image280; GtkWidget *menu_manage_users; - GtkWidget *image267; + GtkWidget *image281; GtkWidget *menu_finances_stadium; GtkWidget *menu_finances_stadium_menu; GtkWidget *menu_show_finances; @@ -232,6 +236,14 @@ create_main_window (void) gtk_widget_show (menu_open); gtk_container_add (GTK_CONTAINER (menu_file_menu), menu_open); + menu_load_last_save = gtk_image_menu_item_new_with_mnemonic (_("Load last save")); + gtk_widget_show (menu_load_last_save); + gtk_container_add (GTK_CONTAINER (menu_file_menu), menu_load_last_save); + + image277 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU); + gtk_widget_show (image277); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_load_last_save), image277); + menu_save = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group); gtk_widget_show (menu_save); gtk_container_add (GTK_CONTAINER (menu_file_menu), menu_save); @@ -263,9 +275,9 @@ create_main_window (void) GDK_p, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); - image264 = gtk_image_new_from_stock ("gtk-preferences", GTK_ICON_SIZE_MENU); - gtk_widget_show (image264); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_preferences), image264); + image278 = gtk_image_new_from_stock ("gtk-preferences", GTK_ICON_SIZE_MENU); + gtk_widget_show (image278); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_preferences), image278); trennlinie7 = gtk_menu_item_new (); gtk_widget_show (trennlinie7); @@ -337,25 +349,21 @@ create_main_window (void) menu_all_out_defend_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_all_out_defend)); gtk_widget_show (menu_all_out_defend); gtk_container_add (GTK_CONTAINER (menu_playing_style_menu), menu_all_out_defend); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_all_out_defend), TRUE); menu_defend = gtk_radio_menu_item_new_with_mnemonic (menu_all_out_defend_group, _("Defend")); menu_all_out_defend_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_defend)); gtk_widget_show (menu_defend); gtk_container_add (GTK_CONTAINER (menu_playing_style_menu), menu_defend); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_defend), TRUE); menu_balanced = gtk_radio_menu_item_new_with_mnemonic (menu_all_out_defend_group, _("Balanced")); menu_all_out_defend_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_balanced)); gtk_widget_show (menu_balanced); gtk_container_add (GTK_CONTAINER (menu_playing_style_menu), menu_balanced); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_balanced), TRUE); menu_attack = gtk_radio_menu_item_new_with_mnemonic (menu_all_out_defend_group, _("Attack")); menu_all_out_defend_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_attack)); gtk_widget_show (menu_attack); gtk_container_add (GTK_CONTAINER (menu_playing_style_menu), menu_attack); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_attack), TRUE); menu_all_out_attack = gtk_radio_menu_item_new_with_mnemonic (menu_all_out_defend_group, _("All Out Attack")); menu_all_out_defend_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_all_out_attack)); @@ -374,19 +382,16 @@ create_main_window (void) menu_scout_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_scout_best)); gtk_widget_show (menu_scout_best); gtk_container_add (GTK_CONTAINER (menu_scout_menu), menu_scout_best); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_scout_best), TRUE); menu_scout_good = gtk_radio_menu_item_new_with_mnemonic (menu_scout_best_group, _("Good")); menu_scout_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_scout_good)); gtk_widget_show (menu_scout_good); gtk_container_add (GTK_CONTAINER (menu_scout_menu), menu_scout_good); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_scout_good), TRUE); menu_scout_average = gtk_radio_menu_item_new_with_mnemonic (menu_scout_best_group, _("Average")); menu_scout_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_scout_average)); gtk_widget_show (menu_scout_average); gtk_container_add (GTK_CONTAINER (menu_scout_menu), menu_scout_average); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_scout_average), TRUE); menu_scout_bad = gtk_radio_menu_item_new_with_mnemonic (menu_scout_best_group, _("Bad")); menu_scout_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_scout_bad)); @@ -405,19 +410,16 @@ create_main_window (void) menu_physio_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_physio_best)); gtk_widget_show (menu_physio_best); gtk_container_add (GTK_CONTAINER (menu_physio_menu), menu_physio_best); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_physio_best), TRUE); menu_physio_good = gtk_radio_menu_item_new_with_mnemonic (menu_physio_best_group, _("Good")); menu_physio_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_physio_good)); gtk_widget_show (menu_physio_good); gtk_container_add (GTK_CONTAINER (menu_physio_menu), menu_physio_good); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_physio_good), TRUE); menu_physio_average = gtk_radio_menu_item_new_with_mnemonic (menu_physio_best_group, _("Average")); menu_physio_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_physio_average)); gtk_widget_show (menu_physio_average); gtk_container_add (GTK_CONTAINER (menu_physio_menu), menu_physio_average); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_physio_average), TRUE); menu_physio_bad = gtk_radio_menu_item_new_with_mnemonic (menu_physio_best_group, _("Bad")); menu_physio_best_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_physio_bad)); @@ -436,13 +438,11 @@ create_main_window (void) menu_boost_on_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_boost_on)); gtk_widget_show (menu_boost_on); gtk_container_add (GTK_CONTAINER (menu_boost_menu), menu_boost_on); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_boost_on), TRUE); menu_boost_off = gtk_radio_menu_item_new_with_mnemonic (menu_boost_on_group, _("Off")); menu_boost_on_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_boost_off)); gtk_widget_show (menu_boost_off); gtk_container_add (GTK_CONTAINER (menu_boost_menu), menu_boost_off); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_boost_off), TRUE); menu_boost_anti = gtk_radio_menu_item_new_with_mnemonic (menu_boost_on_group, _("Anti")); menu_boost_on_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_boost_anti)); @@ -450,10 +450,23 @@ create_main_window (void) gtk_container_add (GTK_CONTAINER (menu_boost_menu), menu_boost_anti); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_boost_anti), TRUE); + trennlinie11 = gtk_menu_item_new (); + gtk_widget_show (trennlinie11); + gtk_container_add (GTK_CONTAINER (menu_team_menu), trennlinie11); + gtk_widget_set_sensitive (trennlinie11, FALSE); + menu_custom_structure = gtk_menu_item_new_with_mnemonic (_("Enter custom structure")); gtk_widget_show (menu_custom_structure); gtk_container_add (GTK_CONTAINER (menu_team_menu), menu_custom_structure); + menu_rearrange_team = gtk_menu_item_new_with_mnemonic (_("Rearrange team")); + gtk_widget_show (menu_rearrange_team); + gtk_container_add (GTK_CONTAINER (menu_team_menu), menu_rearrange_team); + gtk_tooltips_set_tip (tooltips, menu_rearrange_team, _("Try to put the startup players onto their favoured positions and sort the substitutes (Ctrl-R or middle click)"), NULL); + gtk_widget_add_accelerator (menu_rearrange_team, "activate", accel_group, + GDK_r, GDK_CONTROL_MASK, + GTK_ACCEL_VISIBLE); + trennlinie8 = gtk_menu_item_new (); gtk_widget_show (trennlinie8); gtk_container_add (GTK_CONTAINER (menu_team_menu), trennlinie8); @@ -533,9 +546,9 @@ create_main_window (void) GDK_F9, 0, GTK_ACCEL_VISIBLE); - image265 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_MENU); - gtk_widget_show (image265); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_next_user), image265); + image279 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_MENU); + gtk_widget_show (image279); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_next_user), image279); menu_previous_user = gtk_image_menu_item_new_with_mnemonic (_("Previous user")); gtk_widget_show (menu_previous_user); @@ -544,9 +557,9 @@ create_main_window (void) GDK_F8, 0, GTK_ACCEL_VISIBLE); - image266 = gtk_image_new_from_stock ("gtk-go-back", GTK_ICON_SIZE_MENU); - gtk_widget_show (image266); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_previous_user), image266); + image280 = gtk_image_new_from_stock ("gtk-go-back", GTK_ICON_SIZE_MENU); + gtk_widget_show (image280); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_previous_user), image280); menu_manage_users = gtk_image_menu_item_new_with_mnemonic (_("Manage users")); gtk_widget_show (menu_manage_users); @@ -555,9 +568,9 @@ create_main_window (void) GDK_F12, 0, GTK_ACCEL_VISIBLE); - image267 = gtk_image_new_from_stock ("gtk-justify-fill", GTK_ICON_SIZE_MENU); - gtk_widget_show (image267); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_manage_users), image267); + image281 = gtk_image_new_from_stock ("gtk-justify-fill", GTK_ICON_SIZE_MENU); + gtk_widget_show (image281); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_manage_users), image281); menu_finances_stadium = gtk_menu_item_new_with_mnemonic (_("FinStad")); gtk_widget_show (menu_finances_stadium); @@ -599,10 +612,7 @@ create_main_window (void) gtk_widget_show (button_load); gtk_box_pack_start (GTK_BOX (hbox1), button_load, FALSE, FALSE, 2); gtk_container_set_border_width (GTK_CONTAINER (button_load), 2); - gtk_tooltips_set_tip (tooltips, button_load, _("Load game (L or Ctrl - O)"), NULL); - gtk_widget_add_accelerator (button_load, "clicked", accel_group, - GDK_l, 0, - GTK_ACCEL_VISIBLE); + gtk_tooltips_set_tip (tooltips, button_load, _("Load game (Ctrl - O)"), NULL); image11 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_BUTTON); gtk_widget_show (image11); @@ -613,9 +623,6 @@ create_main_window (void) gtk_box_pack_start (GTK_BOX (hbox1), button_save, FALSE, FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (button_save), 2); gtk_tooltips_set_tip (tooltips, button_save, _("Save game (Ctrl - S)"), NULL); - gtk_widget_add_accelerator (button_save, "clicked", accel_group, - GDK_s, 0, - GTK_ACCEL_VISIBLE); image12 = gtk_image_new_from_stock ("gtk-save", GTK_ICON_SIZE_BUTTON); gtk_widget_show (image12); @@ -996,6 +1003,9 @@ create_main_window (void) g_signal_connect ((gpointer) menu_open, "activate", G_CALLBACK (on_menu_open_activate), NULL); + g_signal_connect ((gpointer) menu_load_last_save, "activate", + G_CALLBACK (on_menu_load_last_save_activate), + NULL); g_signal_connect ((gpointer) menu_save, "activate", G_CALLBACK (on_menu_save_activate), NULL); @@ -1083,6 +1093,9 @@ create_main_window (void) g_signal_connect ((gpointer) menu_custom_structure, "activate", G_CALLBACK (on_menu_custom_structure_activate), NULL); + g_signal_connect ((gpointer) menu_rearrange_team, "activate", + G_CALLBACK (on_menu_rearrange_team_activate), + NULL); g_signal_connect ((gpointer) menu_browse_teams, "activate", G_CALLBACK (on_menu_browse_teams_activate), NULL); @@ -1191,6 +1204,8 @@ create_main_window (void) GLADE_HOOKUP_OBJECT (main_window, menu_file_menu, "menu_file_menu"); GLADE_HOOKUP_OBJECT (main_window, menu_new, "menu_new"); GLADE_HOOKUP_OBJECT (main_window, menu_open, "menu_open"); + GLADE_HOOKUP_OBJECT (main_window, menu_load_last_save, "menu_load_last_save"); + GLADE_HOOKUP_OBJECT (main_window, image277, "image277"); GLADE_HOOKUP_OBJECT (main_window, menu_save, "menu_save"); GLADE_HOOKUP_OBJECT (main_window, menu_save_as, "menu_save_as"); GLADE_HOOKUP_OBJECT (main_window, trennlinie1, "trennlinie1"); @@ -1198,7 +1213,7 @@ create_main_window (void) GLADE_HOOKUP_OBJECT (main_window, menu_options, "menu_options"); GLADE_HOOKUP_OBJECT (main_window, menu_options_menu, "menu_options_menu"); GLADE_HOOKUP_OBJECT (main_window, menu_preferences, "menu_preferences"); - GLADE_HOOKUP_OBJECT (main_window, image264, "image264"); + GLADE_HOOKUP_OBJECT (main_window, image278, "image278"); GLADE_HOOKUP_OBJECT (main_window, trennlinie7, "trennlinie7"); GLADE_HOOKUP_OBJECT (main_window, menu_job_offers, "menu_job_offers"); GLADE_HOOKUP_OBJECT (main_window, menu_live_game, "menu_live_game"); @@ -1236,7 +1251,9 @@ create_main_window (void) GLADE_HOOKUP_OBJECT (main_window, menu_boost_on, "menu_boost_on"); GLADE_HOOKUP_OBJECT (main_window, menu_boost_off, "menu_boost_off"); GLADE_HOOKUP_OBJECT (main_window, menu_boost_anti, "menu_boost_anti"); + GLADE_HOOKUP_OBJECT (main_window, trennlinie11, "trennlinie11"); GLADE_HOOKUP_OBJECT (main_window, menu_custom_structure, "menu_custom_structure"); + GLADE_HOOKUP_OBJECT (main_window, menu_rearrange_team, "menu_rearrange_team"); GLADE_HOOKUP_OBJECT (main_window, trennlinie8, "trennlinie8"); GLADE_HOOKUP_OBJECT (main_window, menu_browse_teams, "menu_browse_teams"); GLADE_HOOKUP_OBJECT (main_window, menu_player, "menu_player"); @@ -1255,11 +1272,11 @@ create_main_window (void) GLADE_HOOKUP_OBJECT (main_window, menu_user_show_last_stats, "menu_user_show_last_stats"); GLADE_HOOKUP_OBJECT (main_window, trennlinie9, "trennlinie9"); GLADE_HOOKUP_OBJECT (main_window, menu_next_user, "menu_next_user"); - GLADE_HOOKUP_OBJECT (main_window, image265, "image265"); + GLADE_HOOKUP_OBJECT (main_window, image279, "image279"); GLADE_HOOKUP_OBJECT (main_window, menu_previous_user, "menu_previous_user"); - GLADE_HOOKUP_OBJECT (main_window, image266, "image266"); + GLADE_HOOKUP_OBJECT (main_window, image280, "image280"); GLADE_HOOKUP_OBJECT (main_window, menu_manage_users, "menu_manage_users"); - GLADE_HOOKUP_OBJECT (main_window, image267, "image267"); + GLADE_HOOKUP_OBJECT (main_window, image281, "image281"); GLADE_HOOKUP_OBJECT (main_window, menu_finances_stadium, "menu_finances_stadium"); GLADE_HOOKUP_OBJECT (main_window, menu_finances_stadium_menu, "menu_finances_stadium_menu"); GLADE_HOOKUP_OBJECT (main_window, menu_show_finances, "menu_show_finances"); diff --git a/src/live_game.c b/src/live_game.c index 65fecd55..9d9b5ecf 100644 --- a/src/live_game.c +++ b/src/live_game.c @@ -1555,6 +1555,9 @@ live_game_reset(LiveGame *live_game, Fixture *fix, gboolean free_variable) live_game->stats.values[1][i] = 0; live_game->fix = fix; + live_game->fix_clid = (fix != NULL) ? fix->clid : -1; + live_game->fix_idx = (fix != NULL) ? fixture_get_index(fix) : -1; + live_game->subs_left[0] = live_game->subs_left[1] = 3; live_game->stadium_event = -1; diff --git a/src/live_game_struct.h b/src/live_game_struct.h index f068b4bd..3a44ee01 100644 --- a/src/live_game_struct.h +++ b/src/live_game_struct.h @@ -190,6 +190,9 @@ typedef struct { /** The fixture that belongs to the game. */ Fixture *fix; + /** Integers determining the fixture (needed because fixture pointers + can change when new fixtures are added to the fixtures array). */ + gint fix_clid, fix_idx; /** Substitutions left for the teams. */ gint subs_left[2]; /** The team that started the game, 0 or 1. */ diff --git a/src/load_save.c b/src/load_save.c index 79a8d2e0..019d8e83 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -1,3 +1,4 @@ +#include "callbacks.h" #include "file.h" #include "gui.h" #include "game_gui.h" @@ -12,7 +13,7 @@ #include "xml_loadsave_transfers.h" #include "xml.h" -#define PROGRESS_MAX 6 +#define PROGRESS_MAX 7 /** Save the game to the specified file. */ void @@ -40,6 +41,16 @@ load_save_save_game(const gchar *filename) xml_loadsave_misc_write(prefix); + gui_show_progress( + ((PROGRESS_MAX * gtk_progress_bar_get_fraction( + GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX, + "Saving options/constants..."); + + sprintf(buf, "%s___options", prefix); + file_save_opt_file(buf, &options); + sprintf(buf, "%s___constants", prefix); + file_save_opt_file(buf, &constants); + gui_show_progress( ((PROGRESS_MAX * gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX, @@ -98,6 +109,25 @@ load_save_load_game(const gchar* filename) *dirname = g_path_get_dirname(filename); gchar *prefix = g_strndup(basename, strlen(basename) - strlen(const_str("string_save_suffix"))); + if(strcmp(basename, "last_save") == 0) + { + g_free(basename); + g_free(dirname); + g_free(prefix); + + basename = load_save_last_save_get(); + + if(basename != NULL) + { + load_save_load_game(basename); + g_free(basename); + } + else + g_warning("load_save_load_game: last save file not found.\n"); + + return; + } + gui_show_progress(0, "Uncompressing savegame..."); file_decompress(filename); @@ -109,6 +139,16 @@ load_save_load_game(const gchar* filename) xml_loadsave_misc_read(dirname, prefix); + gui_show_progress( + ((PROGRESS_MAX * gtk_progress_bar_get_fraction( + GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX, + "Loading options/constants..."); + + sprintf(buf, "%s___options", prefix); + file_load_opt_file(buf, &options); + sprintf(buf, "%s___constants", prefix); + file_load_opt_file(buf, &constants); + gui_show_progress( ((PROGRESS_MAX * gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar")))) + 1) / PROGRESS_MAX, @@ -150,6 +190,9 @@ load_save_load_game(const gchar* filename) gui_show_progress(-1, ""); setsav1; + + cur_user = 0; + on_button_back_to_main_clicked(NULL, NULL); } /** Store the name of the last savegame in the users home dir. */ diff --git a/src/misc.c b/src/misc.c index 20732f29..f507bf05 100644 --- a/src/misc.c +++ b/src/misc.c @@ -230,7 +230,7 @@ misc_truncate_string(const gchar *src, gchar *dest, gint number_of_chars) /** Find out whether the first string contains the second string. */ gboolean -misc_string_contains(const gchar *string, const gchar *text) +query_misc_string_contains(const gchar *string, const gchar *text) { gint i, j; gint lens = strlen(string), @@ -254,3 +254,16 @@ misc_string_contains(const gchar *string, const gchar *text) return FALSE; } + +/** Check whether the string is in the GString array. */ +gboolean +query_misc_string_in_array(const gchar *string, GPtrArray *array) +{ + gint i; + + for(i=0;ilen;i++) + if(strcmp(string, ((GString*)g_ptr_array_index(array, i))->str) == 0) + return TRUE; + + return FALSE; +} diff --git a/src/misc.h b/src/misc.h index 506bfb33..7766a7bd 100644 --- a/src/misc.h +++ b/src/misc.h @@ -34,6 +34,9 @@ void misc_truncate_string(const gchar *src, gchar *dest, gint number_of_chars); gboolean -misc_string_contains(const gchar *string, const gchar *text); +query_misc_string_contains(const gchar *string, const gchar *text); + +gboolean +query_misc_string_in_array(const gchar *string, GPtrArray *array); #endif diff --git a/src/misc2_callback_func.c b/src/misc2_callback_func.c index 7ab13aca..743688c0 100644 --- a/src/misc2_callback_func.c +++ b/src/misc2_callback_func.c @@ -113,7 +113,7 @@ misc2_callback_contract_offer(void) pl->contract += (i + 1); pl->wage = value; sprintf(buf, _("%s accepts your offer."), pl->name->str); - game_gui_print_message(buf); + game_gui_show_warning(buf); window_destroy(&window.contract, FALSE); } else diff --git a/src/misc_callback_func.c b/src/misc_callback_func.c index 586ae72c..045bd618 100644 --- a/src/misc_callback_func.c +++ b/src/misc_callback_func.c @@ -221,6 +221,4 @@ misc_callback_startup_load(const gchar *filename) window_create(WINDOW_MAIN); xml_name_read(opt_str("string_opt_player_names_file"), 1000); load_save_load_game(filename); - cur_user = 0; - on_button_back_to_main_clicked(NULL, NULL); } diff --git a/src/misc_callbacks.c b/src/misc_callbacks.c index e254bb6d..23b59d4f 100644 --- a/src/misc_callbacks.c +++ b/src/misc_callbacks.c @@ -84,11 +84,7 @@ on_button_fsel_ok_clicked (GtkButton *button, if(stat1 == STATUS_SAVE_GAME) load_save_save_game(filename); else if(stat1 == STATUS_LOAD_GAME) - { load_save_load_game(filename); - cur_user = 0; - on_button_back_to_main_clicked(NULL, NULL); - } else if(stat1 == STATUS_LOAD_GAME_TEAM_SELECTION) misc_callback_startup_load(filename); @@ -269,6 +265,9 @@ on_button_stadium_ok_clicked (GtkButton *button, gpointer user_data) { misc_callback_improve_stadium(); + + if(stat0 == STATUS_SHOW_FINANCES) + on_menu_show_finances_activate(NULL, NULL); } @@ -298,12 +297,15 @@ void on_button_startup_resume_clicked (GtkButton *button, gpointer user_data) { - gchar *last_save = load_save_last_save_get(); - - if(last_save == NULL) - return; - - misc_callback_startup_load(last_save); - - g_free(last_save); + misc_callback_startup_load("last_save"); } + +gboolean +on_window_stadium_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + + return TRUE; +} + diff --git a/src/misc_callbacks.h b/src/misc_callbacks.h index a301a0a9..814dbff7 100644 --- a/src/misc_callbacks.h +++ b/src/misc_callbacks.h @@ -118,3 +118,8 @@ void on_button_startup_resume_clicked (GtkButton *button, gpointer user_data); #endif + +gboolean +on_window_stadium_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data); diff --git a/src/misc_interface.c b/src/misc_interface.c index e6d038bc..2166f363 100644 --- a/src/misc_interface.c +++ b/src/misc_interface.c @@ -336,7 +336,7 @@ create_window_startup (void) gtk_widget_show (image61); gtk_box_pack_start (GTK_BOX (hbox68), image61, FALSE, FALSE, 0); - label108 = gtk_label_new_with_mnemonic (_("Resume last game")); + label108 = gtk_label_new_with_mnemonic (_("_Resume last game")); gtk_widget_show (label108); gtk_box_pack_start (GTK_BOX (hbox68), label108, FALSE, FALSE, 0); gtk_label_set_justify (GTK_LABEL (label108), GTK_JUSTIFY_LEFT); @@ -1175,6 +1175,9 @@ create_window_stadium (void) GDK_Escape, 0, GTK_ACCEL_VISIBLE); + g_signal_connect ((gpointer) window_stadium, "delete_event", + G_CALLBACK (on_window_stadium_delete_event), + NULL); g_signal_connect ((gpointer) spinbutton_capacity, "value_changed", G_CALLBACK (on_spinbutton_capacity_value_changed), NULL); diff --git a/src/option_gui.c b/src/option_gui.c index eaab19be..1a9d69b0 100644 --- a/src/option_gui.c +++ b/src/option_gui.c @@ -1,3 +1,4 @@ +#include "callbacks.h" #include "file.h" #include "option.h" #include "option_gui.h" @@ -387,10 +388,13 @@ option_gui_write_options(void) for(i=0;iparticipation) + { + pl->participation = FALSE; return; + } for(i=0;i<7;i++) if(diff > age_limits[i]) @@ -946,6 +949,7 @@ player_update_weekly(Team *tm, gint idx) pl->age += 0.0192; pl->contract -= 0.0192; + /*todo: warning*/ if(pl->contract <= 0) player_remove_contract(tm, idx); @@ -981,9 +985,6 @@ player_remove_from_team(Team *tm, gint idx) void player_update_post_match(Player *pl, gint clid) { - if(pl->health == 0) - player_update_fitness(pl); - if(player_card_get(pl, clid, PLAYER_VALUE_CARD_RED) > 0) player_card_set(pl, clid, PLAYER_VALUE_CARD_RED, -1, TRUE); } @@ -1018,8 +1019,11 @@ player_update_week_roundly(Team *tm, gint idx) { Player *pl = player_of(tm, idx); + if(pl->health == 0) + player_update_fitness(pl); + pl->cskill = (pl->health > 0 || player_is_banned(pl) > 0) ? - 0 : player_get_cskill(pl, pl->cpos); + 0 : player_get_cskill(pl, pl->cpos); } /** Return injury descriptions. */ diff --git a/src/start_end.c b/src/start_end.c index f115aeff..d923c015 100644 --- a/src/start_end.c +++ b/src/start_end.c @@ -162,7 +162,7 @@ end_week_round_results(void) gchar buf[SMALL], buf2[SMALL]; gfloat num_matches = (gfloat)fixture_get_number_of_matches(week, week_round); - + if(week_round == 1) { for(i=0;ilen;i++) @@ -172,6 +172,7 @@ end_week_round_results(void) g_array_index(lig(i).fixtures, Fixture, j).attendance == -1) { live_game_calculate_fixture(&g_array_index(lig(i).fixtures, Fixture, j)); + done++; fixture_result_to_buf(&g_array_index(lig(i).fixtures, Fixture, j), buf); sprintf(buf2, "%s %s %s", @@ -190,6 +191,7 @@ end_week_round_results(void) g_array_index(cp(i).fixtures, Fixture, j).attendance == -1) { live_game_calculate_fixture(&g_array_index(cp(i).fixtures, Fixture, j)); + done++; fixture_result_to_buf(&g_array_index(cp(i).fixtures, Fixture, j), buf); sprintf(buf2, "%s %s %s", diff --git a/src/team.c b/src/team.c index 342dd4d7..483b52e4 100644 --- a/src/team.c +++ b/src/team.c @@ -664,10 +664,17 @@ team_update_cpu_corrections(Team *tm, gboolean reset_fitness) for(i=0;iplayers->len;i++) { pl = player_of(tm, i); + + for(j=0;jcards->len;j++) + g_array_index(pl->cards, PlayerCard, j).red = 0; + if(pl->cskill == 0) { pl->health = pl->recovery = 0; pl->cskill = player_get_cskill(pl, pl->cpos); + + pl->fitness = math_rnd(const_float("float_player_fitness_lower"), + const_float("float_player_fitness_upper")); } if(pl->pos != pl->cpos) @@ -676,18 +683,16 @@ team_update_cpu_corrections(Team *tm, gboolean reset_fitness) pl->cskill = player_get_cskill(pl, pl->cpos); } - for(j=0;jcards->len;j++) - g_array_index(pl->cards, PlayerCard, j).red = 0; - if(reset_fitness) pl->fitness = math_rnd(const_float("float_player_fitness_lower"), const_float("float_player_fitness_upper")); } + team_rearrange(tm); + tm->structure = team_find_appropriate_structure(tm); - if(!player_substitution_good_structure(tm->structure, - player_of(tm, 1)->pos, player_of(tm, 1)->pos)) + if(!player_substitution_good_structure(tm->structure, PLAYER_POS_DEFENDER, PLAYER_POS_DEFENDER)) { tm->structure = team_assign_playing_structure(); for(i=0;iplayers->len;i++) @@ -755,7 +760,7 @@ team_update_cpu_new_players(Team *tm) /** Heal players, re-set fitnesses, make some random subs and replace some players with new ones. @param tm The team we examine. - @param reset_fitness Whether to reset the fitness values of playes. */ + @param reset_fitness Whether to reset the fitness values of players. */ void team_update_cpu_team(Team *tm, gboolean reset_fitness) { diff --git a/src/treeview.c b/src/treeview.c index 03997b13..bbb9c1dd 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -241,7 +241,7 @@ treeview_pixbuf_from_filename(gchar *filename) if(filename != NULL && strlen(filename) != 0) { - symbol_file = file_find_support_file(filename); + symbol_file = file_find_support_file(filename, FALSE); if(symbol_file != NULL) { symbol = gdk_pixbuf_new_from_file(symbol_file, &error); @@ -1010,7 +1010,7 @@ treeview_create_game_stats(LiveGame *live_game) gchar buf[2][SMALL]; gchar buf3[SMALL]; gchar *categories[LIVE_GAME_STAT_VALUE_END] = - {_("Goals (w/o pen.)"), + {_("Goals (regular)"), _("Shots"), _("Shot %"), _("Possession"), @@ -1616,6 +1616,37 @@ treeview_show_table(GtkTreeView *treeview, gint clid) g_object_unref(model); } +/** Print some quick info about the stadium in the finances view. */ +void +treeview_create_stadium_summary(GtkListStore *liststore) +{ + gchar buf[SMALL]; + GtkTreeIter iter; + + gtk_list_store_append(liststore, &iter); + misc_print_grouped_int(current_user.tm->stadium.capacity, buf, FALSE); + gtk_list_store_set(liststore, &iter, 0, _("Stadium capacity"), 1, buf, 2, "", -1); + + gtk_list_store_append(liststore, &iter); + sprintf(buf, "%.0f", current_user.tm->stadium.safety * 100); + gtk_list_store_set(liststore, &iter, 0, _("Stadium safety"), 1, buf, 2, "", -1); + + if(current_user.counters[COUNT_USER_STADIUM_CAPACITY] + + current_user.counters[COUNT_USER_STADIUM_SAFETY] != 0) + { + gtk_list_store_append(liststore, &iter); + sprintf(buf, _("Improvement in progress.\n%d seats and %d%% safety still to be done.\nExpected finish: %d weeks."), + current_user.counters[COUNT_USER_STADIUM_CAPACITY], + current_user.counters[COUNT_USER_STADIUM_SAFETY], + MAX(finance_get_stadium_improvement_duration( + (gfloat)current_user.counters[COUNT_USER_STADIUM_CAPACITY], TRUE), + finance_get_stadium_improvement_duration( + (gfloat)current_user.counters[COUNT_USER_STADIUM_SAFETY] / 100, FALSE))); + + gtk_list_store_set(liststore, &iter, 0, _("Stadium status"), 1, buf, 2, "", -1); + } +} + GtkTreeModel* treeview_create_finances(const User* user) { @@ -1711,6 +1742,11 @@ treeview_create_finances(const User* user) gtk_list_store_set(liststore, &iter, 0, buf, 1, "", 2, buf2, -1); } + gtk_list_store_append(liststore, &iter); + gtk_list_store_set(liststore, &iter, 0, "", 1, "", 2, "", -1); + + treeview_create_stadium_summary(liststore); + return GTK_TREE_MODEL(liststore); } diff --git a/src/treeview.h b/src/treeview.h index dc59be3e..7ad08bd9 100644 --- a/src/treeview.h +++ b/src/treeview.h @@ -210,4 +210,7 @@ treeview_create_player_info(const Player *pl); gint treeview_iter_get_row(GtkTreeModel *model, GtkTreeIter *iter); +void +treeview_create_stadium_summary(GtkListStore *liststore); + #endif diff --git a/src/treeview_cell.c b/src/treeview_cell.c index e27d0cd2..c9a47eab 100644 --- a/src/treeview_cell.c +++ b/src/treeview_cell.c @@ -161,7 +161,7 @@ treeview_cell_player_info_banned_to_cell(GtkCellRenderer *renderer, const GArray for(i=0;ilen;i++) if(g_array_index(cards, PlayerCard, i).red > 0) { - sprintf(buf2, "%s: %d weeks ", + sprintf(buf2, "%s: %d weeks\n", league_cup_get_name_string(g_array_index(cards, PlayerCard, i).clid), g_array_index(cards, PlayerCard, i).red); strcat(buf, buf2); @@ -191,12 +191,12 @@ treeview_cell_player_info_yellow_to_cell(GtkCellRenderer *renderer, const GArray { if(yellow_red < 1000) { - sprintf(buf2, "%s: %d (%d) ", + sprintf(buf2, "%s: %d (%d)\n", league_cup_get_name_string(g_array_index(cards, PlayerCard, i).clid), g_array_index(cards, PlayerCard, i).yellow, yellow_red); } else - sprintf(buf2, "%s: %d (no limit) ", + sprintf(buf2, "%s: %d (no limit)\n", league_cup_get_name_string(g_array_index(cards, PlayerCard, i).clid), g_array_index(cards, PlayerCard, i).yellow); @@ -217,7 +217,7 @@ treeview_cell_player_info_games_goals_to_cell(GtkCellRenderer *renderer, const G for(i=0;ilen;i++) { - sprintf(buf2, "%s: %d/%d ", + sprintf(buf2, "%s: %d/%d\n", league_cup_get_name_string(g_array_index(games_goals, PlayerGamesGoals, i).clid), g_array_index(games_goals, PlayerGamesGoals, i).games, g_array_index(games_goals, PlayerGamesGoals, i).goals); diff --git a/src/window.c b/src/window.c index b94141d0..e1651f0b 100644 --- a/src/window.c +++ b/src/window.c @@ -4,6 +4,7 @@ #include "game_gui.h" #include "gui.h" #include "interface.h" +#include "main.h" #include "misc_interface.h" #include "misc2_interface.h" #include "option.h" @@ -24,22 +25,22 @@ window_show_startup(void) window_create(WINDOW_STARTUP); GtkWidget *combo_country = lookup_widget(window_startup, "combo_country"); - const gchar *country_dir; - GPtrArray *dir_contents = NULL; + GPtrArray *country_files = NULL; GList *combo_strings = NULL; gint i; - country_dir = file_get_definitions_dir(); + country_files = file_get_country_files(); - dir_contents = file_dir_get_contents(country_dir, "country_", ""); + if(country_files->len == 0) + main_exit_program(EXIT_NO_COUNTRY_FILES, "Didn't find any country definition files in the support directories."); - for(i=0;ilen;i++) + for(i=0;ilen;i++) combo_strings = g_list_append(combo_strings, - ((GString*)g_ptr_array_index(dir_contents, i))->str); + ((GString*)g_ptr_array_index(country_files, i))->str); gtk_combo_set_popdown_strings(GTK_COMBO(combo_country), combo_strings); - free_g_string_array(&dir_contents); + free_g_string_array(&country_files); } /** Show the file selection window. */ diff --git a/src/xml.c b/src/xml.c index fdb42370..ed9d57c9 100644 --- a/src/xml.c +++ b/src/xml.c @@ -65,7 +65,7 @@ xml_load_leagues(const gchar *dirname, const gchar *basename) if(!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table.xml") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml") && - !misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_promcup")) + !query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_promcup")) xml_load_league(dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str, dir_contents); @@ -107,7 +107,7 @@ xml_load_league(const gchar *dirname, const gchar *basename, const GPtrArray *di for(i=0;ilen;i++) if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, i))->str, buf) && - !misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table") && + !query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml")) { @@ -134,7 +134,7 @@ xml_load_cups(const gchar *dirname, const gchar *basename) for(i=0;ilen;i++) { - if(!misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table") && + if(!query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml")) xml_load_cup(dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str, @@ -177,7 +177,7 @@ xml_load_cup(const gchar *dirname, const gchar *basename, const GPtrArray *dir_c { if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, i))->str, prefix) && - misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, + query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table")) { new_table = table_new(); diff --git a/src/xml_country.c b/src/xml_country.c index 0816e4bb..af55e72c 100644 --- a/src/xml_country.c +++ b/src/xml_country.c @@ -149,7 +149,7 @@ xml_country_read_text (GMarkupParseContext *context, void xml_country_read(const gchar *country_name) { - gchar *file_name = file_find_support_file(country_name); + gchar *file_name = file_find_support_file(country_name, FALSE); GMarkupParser parser = {xml_country_read_start_element, xml_country_read_end_element, xml_country_read_text, NULL, NULL}; @@ -165,7 +165,7 @@ xml_country_read(const gchar *country_name) if(file_name == NULL) { sprintf(buf, "country_%s.xml", country_name); - file_name = file_find_support_file(buf); + file_name = file_find_support_file(buf, TRUE); } if(!g_file_get_contents(file_name, &file_contents, &length, &error)) diff --git a/src/xml_cup.c b/src/xml_cup.c index 030f0ca0..3cb3d663 100644 --- a/src/xml_cup.c +++ b/src/xml_cup.c @@ -312,7 +312,7 @@ xml_cup_read_text (GMarkupParseContext *context, void xml_cup_read(const gchar *cup_name, GArray *cups) { - gchar *file_name = file_find_support_file(cup_name); + gchar *file_name = file_find_support_file(cup_name, FALSE); GMarkupParser parser = {xml_cup_read_start_element, xml_cup_read_end_element, xml_cup_read_text, NULL, NULL}; @@ -328,7 +328,7 @@ xml_cup_read(const gchar *cup_name, GArray *cups) if(file_name == NULL) { sprintf(buf, "cup_%s.xml", cup_name); - file_name = file_find_support_file(buf); + file_name = file_find_support_file(buf, TRUE); } if(!g_file_get_contents(file_name, &file_contents, &length, &error)) diff --git a/src/xml_league.c b/src/xml_league.c index 222c5977..3916b2b4 100644 --- a/src/xml_league.c +++ b/src/xml_league.c @@ -295,7 +295,7 @@ xml_league_read(const gchar *league_name, GArray *leagues) { gint i; TableElement new_table_element; - gchar *file_name = file_find_support_file(league_name); + gchar *file_name = file_find_support_file(league_name, FALSE); GMarkupParser parser = {xml_league_read_start_element, xml_league_read_end_element, xml_league_read_text, NULL, NULL}; @@ -311,7 +311,7 @@ xml_league_read(const gchar *league_name, GArray *leagues) if(file_name == NULL) { sprintf(buf, "league_%s.xml", league_name); - file_name = file_find_support_file(buf); + file_name = file_find_support_file(buf, TRUE); } if(!g_file_get_contents(file_name, &file_contents, &length, &error)) diff --git a/src/xml_loadsave_live_game.c b/src/xml_loadsave_live_game.c index 1cb48357..8e9f6596 100644 --- a/src/xml_loadsave_live_game.c +++ b/src/xml_loadsave_live_game.c @@ -154,10 +154,13 @@ xml_loadsave_live_game_text (GMarkupParseContext *context, int_value = (gint)g_ascii_strtod(buf, NULL); if(state == TAG_LIVE_GAME_FIX_CLID) - fix_clid = int_value; + lgame->fix_clid = int_value; else if(state == TAG_LIVE_GAME_FIX_IDX) - lgame->fix = &g_array_index(league_cup_get_fixtures(fix_clid), + { + lgame->fix_idx = int_value; + lgame->fix = &g_array_index(league_cup_get_fixtures(lgame->fix_clid), Fixture, int_value); + } else if(state == TAG_LIVE_GAME_UNIT_POSSESSION) new_unit.possession = int_value; else if(state == TAG_LIVE_GAME_UNIT_AREA) diff --git a/src/xml_name.c b/src/xml_name.c index 12e9d98a..8957eceb 100644 --- a/src/xml_name.c +++ b/src/xml_name.c @@ -91,7 +91,7 @@ void xml_name_read(const gchar *names_file, gint number_of_names) { gint i; - gchar *file_name = file_find_support_file(names_file); + gchar *file_name = file_find_support_file(names_file, FALSE); GMarkupParser parser = {xml_name_read_start_element, xml_name_read_end_element, xml_name_read_text, NULL, NULL}; diff --git a/support_files/bygfoot_constants b/support_files/bygfoot_constants index aa8d5ee3..dc7a3d56 100644 --- a/support_files/bygfoot_constants +++ b/support_files/bygfoot_constants @@ -484,7 +484,7 @@ int_team_subs_upper 3 float_team_new_style 1000 # prob that the team structure gets changed -float_team_new_structure 500 +float_team_new_structure 2000 # the influence of the fitness on the current skill. # this determines the player's contribution to the team @@ -746,7 +746,7 @@ string_treeview_opponent_skill_positive_fg darkred string_treeview_opponent_skill_negative_fg darkgreen # background of the home column in the league results -string_treeview_league_results_away_bg lightgrey +string_treeview_league_results_away_bg white string_treeview_league_results_away_fg black # foreground of own team bar in the opponent preview