From 1692d228c4effc44cc9c63b34227ae7127e02bfe Mon Sep 17 00:00:00 2001 From: gyboth Date: Wed, 11 Mar 2009 20:25:26 +0000 Subject: [PATCH] Constants editing done. --- ChangeLog | 2 ++ bygfoot_options.glade | 4 ++-- src/options_callbacks.c | 15 ++++++++------- src/options_interface.c | 28 ++++++++++++++-------------- src/treeview2.c | 2 ++ src/treeview_helper.c | 17 +++++++++++++++++ src/treeview_helper.h | 6 ++++++ 7 files changed, 51 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 068fc385..c95f02f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ - corrected some supercup definition errors which resulted in crashes - foul probabilities in the live game are more sophisticated now + - added a simple GUI for editing Bygfoot constants in the + preferences (enabling users to fine-tune the game) 29/01/2009: v2.3.1 - added possibility for multiple tables in leagues (think diff --git a/bygfoot_options.glade b/bygfoot_options.glade index 72e2315f..bfbcf49f 100644 --- a/bygfoot_options.glade +++ b/bygfoot_options.glade @@ -3682,7 +3682,7 @@ GTK_WINDOW_TOPLEVEL GTK_WIN_POS_CENTER False - 550 + 650 700 True False @@ -3702,7 +3702,7 @@ 5 - + True True True diff --git a/src/options_callbacks.c b/src/options_callbacks.c index f18ab886..2d72ff7b 100644 --- a/src/options_callbacks.c +++ b/src/options_callbacks.c @@ -30,6 +30,7 @@ #include "option_gui.h" #include "support.h" #include "training.h" +#include "treeview2.h" #include "user.h" #include "variables.h" #include "window.h" @@ -221,15 +222,15 @@ void on_button_constants_reload_clicked (GtkButton *button, gpointer user_data) { - if(window.options != NULL) - { - printf("hu\n"); - file_load_opt_file(gtk_entry_get_text(GTK_ENTRY(lookup_widget(window.options, "entry_constants_file"))), - &constants, TRUE); - } - else + if(gtk_notebook_get_current_page( + GTK_NOTEBOOK(lookup_widget(GTK_WIDGET(button), "notebook_constants"))) == 3) + file_load_opt_file(opt_str("string_opt_appearance_file"), + &constants_app, TRUE); + else file_load_opt_file(opt_str("string_opt_constants_file"), &constants, TRUE); + + treeview2_show_constants(); } diff --git a/src/options_interface.c b/src/options_interface.c index b15efbad..86cf2448 100644 --- a/src/options_interface.c +++ b/src/options_interface.c @@ -1452,7 +1452,7 @@ create_window_constants (void) { GtkWidget *window_constants; GtkWidget *vbox12; - GtkWidget *notebook2; + GtkWidget *notebook_constants; GtkWidget *scrolledwindow1; GtkWidget *treeview_constants_integer; GtkWidget *label50; @@ -1487,19 +1487,19 @@ create_window_constants (void) gtk_container_set_border_width (GTK_CONTAINER (window_constants), 5); gtk_window_set_title (GTK_WINDOW (window_constants), _("window1")); gtk_window_set_position (GTK_WINDOW (window_constants), GTK_WIN_POS_CENTER); - gtk_window_set_default_size (GTK_WINDOW (window_constants), 550, 700); + gtk_window_set_default_size (GTK_WINDOW (window_constants), 650, 700); vbox12 = gtk_vbox_new (FALSE, 5); gtk_widget_show (vbox12); gtk_container_add (GTK_CONTAINER (window_constants), vbox12); - notebook2 = gtk_notebook_new (); - gtk_widget_show (notebook2); - gtk_box_pack_start (GTK_BOX (vbox12), notebook2, TRUE, TRUE, 0); + notebook_constants = gtk_notebook_new (); + gtk_widget_show (notebook_constants); + gtk_box_pack_start (GTK_BOX (vbox12), notebook_constants, TRUE, TRUE, 0); scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow1); - gtk_container_add (GTK_CONTAINER (notebook2), scrolledwindow1); + gtk_container_add (GTK_CONTAINER (notebook_constants), scrolledwindow1); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN); @@ -1509,11 +1509,11 @@ create_window_constants (void) label50 = gtk_label_new (_("Integer")); gtk_widget_show (label50); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 0), label50); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook_constants), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_constants), 0), label50); scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow2); - gtk_container_add (GTK_CONTAINER (notebook2), scrolledwindow2); + gtk_container_add (GTK_CONTAINER (notebook_constants), scrolledwindow2); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_SHADOW_IN); @@ -1523,11 +1523,11 @@ create_window_constants (void) label51 = gtk_label_new (_("Float")); gtk_widget_show (label51); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 1), label51); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook_constants), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_constants), 1), label51); scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow3); - gtk_container_add (GTK_CONTAINER (notebook2), scrolledwindow3); + gtk_container_add (GTK_CONTAINER (notebook_constants), scrolledwindow3); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_SHADOW_IN); @@ -1537,11 +1537,11 @@ create_window_constants (void) label52 = gtk_label_new (_("String")); gtk_widget_show (label52); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 2), label52); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook_constants), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_constants), 2), label52); scrolledwindow4 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow4); - gtk_container_add (GTK_CONTAINER (notebook2), scrolledwindow4); + gtk_container_add (GTK_CONTAINER (notebook_constants), scrolledwindow4); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow4), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow4), GTK_SHADOW_IN); @@ -1551,7 +1551,7 @@ create_window_constants (void) label53 = gtk_label_new (_("Appearance")); gtk_widget_show (label53); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 3), label53); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook_constants), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_constants), 3), label53); hseparator9 = gtk_hseparator_new (); gtk_widget_show (hseparator9); @@ -1619,7 +1619,7 @@ create_window_constants (void) /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (window_constants, window_constants, "window_constants"); GLADE_HOOKUP_OBJECT (window_constants, vbox12, "vbox12"); - GLADE_HOOKUP_OBJECT (window_constants, notebook2, "notebook2"); + GLADE_HOOKUP_OBJECT (window_constants, notebook_constants, "notebook_constants"); GLADE_HOOKUP_OBJECT (window_constants, scrolledwindow1, "scrolledwindow1"); GLADE_HOOKUP_OBJECT (window_constants, treeview_constants_integer, "treeview_constants_integer"); GLADE_HOOKUP_OBJECT (window_constants, label50, "label50"); diff --git a/src/treeview2.c b/src/treeview2.c index 3fa54b74..3286ca7f 100644 --- a/src/treeview2.c +++ b/src/treeview2.c @@ -816,6 +816,8 @@ treeview2_set_up_constants(GtkTreeView *treeview, gint type) g_object_set(renderer, "editable", TRUE, NULL); g_signal_connect (renderer, "edited", + (type == CONSTANTS_TYPE_APP) ? + G_CALLBACK (treeview_helper_constants_app_editing_done) : G_CALLBACK (treeview_helper_constants_editing_done), treeview); } diff --git a/src/treeview_helper.c b/src/treeview_helper.c index 11d71459..c4f7409e 100644 --- a/src/treeview_helper.c +++ b/src/treeview_helper.c @@ -2064,3 +2064,20 @@ treeview_helper_constants_editing_done(GtkCellRendererText *renderer, gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, new_text, -1); } } + +void +treeview_helper_constants_app_editing_done(GtkCellRendererText *renderer, + gchar *path, + gchar *new_text, + gpointer user_data) +{ + GtkTreeModel *model = gtk_tree_view_get_model((GtkTreeView*)user_data); + GtkTreeIter iter; + const gchar *name; + + gtk_tree_model_get_iter_from_string(model, &iter, path); + gtk_tree_model_get(model, &iter, 0, &name, -1); + + option_set_string(name, &constants_app, new_text); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, new_text, -1); +} diff --git a/src/treeview_helper.h b/src/treeview_helper.h index c3d32c71..eea68685 100644 --- a/src/treeview_helper.h +++ b/src/treeview_helper.h @@ -271,4 +271,10 @@ treeview_helper_constants_editing_done(GtkCellRendererText *renderer, gchar *new_text, gpointer user_data); +void +treeview_helper_constants_app_editing_done(GtkCellRendererText *renderer, + gchar *path, + gchar *new_text, + gpointer user_data); + #endif