diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c857e01..4d971918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ add_definitions("-DPACKAGE=\"${PROJECT_NAME}\"") add_executable(bygfoot WIN32 src/bet.c src/bet.h src/bet_struct.h - src/bygfoot.h + src/bygfoot.c src/bygfoot.h src/callback_func.c src/callback_func.h src/callbacks.c src/callbacks.h src/cup.c src/cup.h src/cup_struct.h diff --git a/src/bygfoot.c b/src/bygfoot.c new file mode 100644 index 00000000..f3f4c5b8 --- /dev/null +++ b/src/bygfoot.c @@ -0,0 +1,19 @@ + +#include "bygfoot.h" +#include "misc.h" +#include "user.h" +#include "xml_country.h" + +User *bygfoot_add_user(Bygfoot *bygfoot, const gchar *username, Team *tm) +{ + User new_user = user_new(); + new_user.tm = tm; + new_user.team_id = tm->id; + + /* FIXME: Use strnlen */ + if(strlen(username) > 0) + misc_string_assign(&new_user.name, username); + + g_array_append_val(users, new_user); + return &g_array_index(users, User, users->len - 1); +} diff --git a/src/bygfoot.h b/src/bygfoot.h index d7475b4a..9ca4f2dd 100644 --- a/src/bygfoot.h +++ b/src/bygfoot.h @@ -44,6 +44,8 @@ #include #include "gettext_macros.h" #include "debug.h" +#include "user_struct.h" +#include "bygfoot_struct.h" /** * Program version number and year (copyright). @@ -202,4 +204,6 @@ typedef struct /** The position of the horizontal divider is stored here. */ gint paned_pos; } Windows; + +User *bygfoot_add_user(Bygfoot *bygfoot, const gchar *username, Team *tm); #endif diff --git a/src/bygfoot_struct.h b/src/bygfoot_struct.h new file mode 100644 index 00000000..67198c40 --- /dev/null +++ b/src/bygfoot_struct.h @@ -0,0 +1,12 @@ +#ifndef BYGFOOT_STRUCT_H +#define BYGFOOT_STRUCT_H + +/** This struct holds all of the global state for a bygfoot game. The goal + * is for ths struct to eventually replace all the global variables. +*/ +typedef struct +{ + gint unused; +} Bygfoot; + +#endif diff --git a/src/callbacks.c b/src/callbacks.c index 331d844a..69966cea 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -585,7 +585,7 @@ on_menu_new_activate (GtkMenuItem *menuitem, free_memory(); main_init(NULL, NULL); - window_show_startup(); + window_show_startup(user_data); stat0 = STATUS_TEAM_SELECTION; statp = NULL; } diff --git a/src/main.c b/src/main.c index fc2d248f..cd10e255 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,7 @@ #endif #include "bet_struct.h" +#include "bygfoot_struct.h" #include "debug.h" #include "file.h" #include "free.h" @@ -407,6 +408,7 @@ main_init(gint *argc, gchar ***argv) gint main (gint argc, gchar *argv[]) { + Bygfoot bygfoot; #ifdef DEBUG printf("main\n"); #endif @@ -440,7 +442,7 @@ main (gint argc, gchar *argv[]) } else { - window_show_startup(); + window_show_startup(&bygfoot); stat0 = STATUS_TEAM_SELECTION; } } diff --git a/src/misc3_callbacks.c b/src/misc3_callbacks.c index 4374b09d..acfac10f 100644 --- a/src/misc3_callbacks.c +++ b/src/misc3_callbacks.c @@ -213,7 +213,7 @@ on_button_splash_new_game_clicked (GtkButton *button, window_destroy(&window.splash); - window_show_startup(); + window_show_startup(user_data); stat0 = STATUS_TEAM_SELECTION; } diff --git a/src/misc_callback_func.c b/src/misc_callback_func.c index d628f829..67c11a15 100644 --- a/src/misc_callback_func.c +++ b/src/misc_callback_func.c @@ -130,7 +130,7 @@ misc_callback_start_game(void) /** Add a user to the users array. */ void -misc_callback_add_player(void) +misc_callback_add_player(Bygfoot *bygfoot) { #ifdef DEBUG printf("misc_callback_add_player\n"); @@ -145,22 +145,15 @@ misc_callback_add_player(void) GtkComboBox *combo_leagues = GTK_COMBO_BOX(lookup_widget(window.startup, "combobox_start_league")); const gchar *player_name = gtk_entry_get_text(entry_player_name); - User new_user = user_new(); Team *tm = (Team*)treeview_helper_get_pointer(treeview_startup, 2); + User *new_user = bygfoot_add_user(bygfoot, player_name, tm); gint start_league = gtk_combo_box_get_active(combo_leagues); - if(strlen(player_name) > 0) - misc_string_assign(&new_user.name, player_name); - gtk_entry_set_text(entry_player_name, ""); - new_user.tm = tm; - new_user.team_id = tm->id; - - new_user.scout = (start_league == 0 || tm->clid == lig(start_league - 1).id) ? -1 : start_league - 1; + new_user->scout = (start_league == 0 || tm->clid == lig(start_league - 1).id) ? -1 : start_league - 1; - g_array_append_val(users, new_user); treeview_show_users(treeview_users); diff --git a/src/misc_callback_func.h b/src/misc_callback_func.h index e04650b8..49182c2f 100644 --- a/src/misc_callback_func.h +++ b/src/misc_callback_func.h @@ -35,7 +35,7 @@ void misc_callback_show_team_list(GtkWidget *widget, const gchar *country_file); void -misc_callback_add_player(void); +misc_callback_add_player(Bygfoot *bygfoot); void misc_callback_remove_user(GdkEventButton *event); diff --git a/src/misc_callbacks.c b/src/misc_callbacks.c index f11b15b0..8cef97bb 100644 --- a/src/misc_callbacks.c +++ b/src/misc_callbacks.c @@ -44,11 +44,12 @@ G_MODULE_EXPORT void on_button_add_player_clicked (GtkButton *button, gpointer user_data) { + Bygfoot *bygfoot = (Bygfoot*)user_data; #ifdef DEBUG printf("on_button_add_player_clicked\n"); #endif - misc_callback_add_player(); + misc_callback_add_player(bygfoot); } @@ -56,11 +57,12 @@ G_MODULE_EXPORT void on_entry_player_name_activate (GtkEntry *entry, gpointer user_data) { + Bygfoot *bygfoot = (Bygfoot*)user_data; #ifdef DEBUG printf("on_entry_player_name_activate\n"); #endif - on_button_add_player_clicked(NULL, NULL); + on_button_add_player_clicked(NULL, bygfoot); } diff --git a/src/misc_interface.c b/src/misc_interface.c index a7e6c451..51dc1b67 100644 --- a/src/misc_interface.c +++ b/src/misc_interface.c @@ -36,17 +36,18 @@ #include #include +#include "bygfoot_struct.h" #include "misc_callbacks.h" #include "misc_interface.h" #include "support.h" #include "file.h" GtkWidget* -create_window_startup (void) +create_window_startup (Bygfoot *bygfoot) { GtkWidget *window_startup; GtkBuilder *builder; - builder = load_ui(file_find_support_file("bygfoot_misc.glade", TRUE)); + builder = load_ui_with_userdata(file_find_support_file("bygfoot_misc.glade", TRUE), bygfoot); window_startup = GTK_WIDGET (gtk_builder_get_object (builder, "window_startup")); /* Store pointers to all widgets, for use by lookup_widget(). */ diff --git a/src/misc_interface.h b/src/misc_interface.h index 129ea065..dba0e854 100644 --- a/src/misc_interface.h +++ b/src/misc_interface.h @@ -2,7 +2,9 @@ * DO NOT EDIT THIS FILE - it is generated by Glade. */ -GtkWidget* create_window_startup (void); +#include "bygfoot_struct.h" + +GtkWidget* create_window_startup (Bygfoot *bygfoot); GtkWidget* create_window_font_sel (void); GtkWidget* create_window_live (void); GtkWidget* create_window_stadium (void); diff --git a/src/support.c b/src/support.c index 7077d17e..d3f6a6f1 100644 --- a/src/support.c +++ b/src/support.c @@ -68,6 +68,12 @@ lookup_widget (GtkWidget *widget, */ GtkBuilder* load_ui (const gchar *filename) +{ + return load_ui_with_userdata(filename, NULL); +} + +GtkBuilder* +load_ui_with_userdata (const gchar *filename, Bygfoot *bygfoot) { GtkBuilder *builder; GError *error = NULL; @@ -80,7 +86,7 @@ load_ui (const gchar *filename) ": Problems found in the glade file: %s\n", error->message); } - gtk_builder_connect_signals (builder, NULL); + gtk_builder_connect_signals (builder, bygfoot); return builder; } diff --git a/src/support.h b/src/support.h index 8938dcd7..4b0d74e6 100644 --- a/src/support.h +++ b/src/support.h @@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "bygfoot_struct.h" + #ifdef HAVE_CONFIG_H # include #endif @@ -76,5 +78,8 @@ GtkWidget* lookup_widget (GtkWidget *widget, GtkBuilder* load_ui (const gchar *filename); +GtkBuilder* +load_ui_with_userdata (const gchar *filename, Bygfoot *bygfoot); + /* Use this function to set the directory containing installed pixmaps. */ void add_pixmap_directory (const gchar *directory); diff --git a/src/window.c b/src/window.c index 3baaccab..856f7133 100644 --- a/src/window.c +++ b/src/window.c @@ -289,14 +289,14 @@ is_capital_sensitive (GtkCellLayout *cell_layout, 'country_' from $HOME/.bygfoot/definitions are appended to a combo box. */ void -window_show_startup(void) +window_show_startup(Bygfoot *bygfoot) { #ifdef DEBUG printf("window_show_startup\n"); #endif GtkWidget *window_startup = - window_create(WINDOW_STARTUP); + window_create_with_userdata(WINDOW_STARTUP, bygfoot); GtkWidget *combo_country = lookup_widget(window_startup, "combo_country"); GPtrArray *country_files = NULL; @@ -794,6 +794,12 @@ window_main_load_geometry(void) @see #Windows */ GtkWidget* window_create(gint window_type) +{ + return window_create_with_userdata(window_type, NULL); +} + +GtkWidget* +window_create_with_userdata(gint window_type, Bygfoot *bygfoot) { gchar buf[SMALL]; GtkWidget *wind = NULL; @@ -827,7 +833,7 @@ window_create(gint window_type) if(window.startup != NULL) debug_print_message("window_create: called on already existing window\n"); else - window.startup = create_window_startup(); + window.startup = create_window_startup(bygfoot); wind = window.startup; break; case WINDOW_LIVE: diff --git a/src/window.h b/src/window.h index f5d2c7d5..62b1d7eb 100644 --- a/src/window.h +++ b/src/window.h @@ -27,6 +27,7 @@ #define WINDOW_H #include "bygfoot.h" +#include "bygfoot_struct.h" /** These are used to keep track of open windows. @see window_create() */ @@ -64,11 +65,14 @@ void window_show_help(gint page); void -window_show_startup(void); +window_show_startup(Bygfoot *bygfoot); GtkWidget* window_create(gint window_type); +GtkWidget* +window_create_with_userdata(gint window_type, Bygfoot *bygfoot); + void window_destroy(GtkWidget **wind);