Constants editing.

This commit is contained in:
gyboth 2009-03-10 20:58:34 +00:00
parent a707c3805e
commit e4e16947c7
16 changed files with 175 additions and 53 deletions

View File

@ -610,7 +610,7 @@ file_save_opt_file(const gchar *filename, OptionList *optionlist)
/** Load a file containing name - value pairs into
the specified array. */
void
file_load_opt_file(const gchar *filename, OptionList *optionlist)
file_load_opt_file(const gchar *filename, OptionList *optionlist, gboolean sort)
{
#ifdef DEBUG
printf("file_load_opt_file\n");
@ -651,6 +651,9 @@ file_load_opt_file(const gchar *filename, OptionList *optionlist)
}
}
if(sort)
g_array_sort(optionlist->list, (GCompareFunc)option_compare_func);
for(i=0;i<optionlist->list->len;i++)
g_datalist_set_data(&optionlist->datalist, g_array_index(optionlist->list, Option, i).name,
&g_array_index(optionlist->list, Option, i));
@ -679,7 +682,7 @@ file_load_hints_file(void)
else
strcpy(hints_file, "bygfoot_hints_en");
file_load_opt_file(hints_file, &hints);
file_load_opt_file(hints_file, &hints, FALSE);
}
/** Load the options at the beginning of a new game from
@ -694,12 +697,12 @@ file_load_conf_files(void)
gint i;
gchar *conf_file = file_find_support_file("bygfoot.conf", TRUE);
file_load_opt_file(conf_file, &options);
file_load_opt_file(conf_file, &options, FALSE);
g_free(conf_file);
file_load_opt_file(opt_str("string_opt_constants_file"), &constants);
file_load_opt_file(opt_str("string_opt_appearance_file"), &constants_app);
file_load_opt_file("bygfoot_tokens", &tokens);
file_load_opt_file(opt_str("string_opt_constants_file"), &constants, TRUE);
file_load_opt_file(opt_str("string_opt_appearance_file"), &constants_app, TRUE);
file_load_opt_file("bygfoot_tokens", &tokens, FALSE);
file_load_hints_file();
for(i=0;i<tokens.list->len;i++)
@ -729,7 +732,7 @@ file_load_user_conf_file(User *user)
file_find_support_file(opt_str("string_opt_default_user_conf_file"), TRUE);
}
file_load_opt_file(conf_file, &user->options);
file_load_opt_file(conf_file, &user->options, FALSE);
g_free(conf_file);
}

View File

@ -46,7 +46,7 @@ gboolean
file_get_next_opt_line(FILE *fil, gchar *opt_name, gchar *opt_value);
void
file_load_opt_file(const gchar *filename, OptionList *optionlist);
file_load_opt_file(const gchar *filename, OptionList *optionlist, gboolean sort);
void
file_save_opt_file(const gchar *filename, OptionList *optionlist);

View File

@ -237,9 +237,9 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
PIC_TYPE_LOAD);
g_string_sprintf(buf, "%s%s%s___options", dirname, G_DIR_SEPARATOR_S, prefix);
file_load_opt_file(buf->str, &options);
file_load_opt_file(buf->str, &options, FALSE);
g_string_sprintf(buf, "%s%s%s___settings", dirname, G_DIR_SEPARATOR_S, prefix);
file_load_opt_file(buf->str, &settings);
file_load_opt_file(buf->str, &settings, FALSE);
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
if(debug > 60)

View File

@ -792,3 +792,43 @@ misc_string_replace_all_tokens(GPtrArray **token_rep,
return (g_strrstr(dest, "_") == NULL);
}
/* Alphabetic compare function. */
gint
misc_alphabetic_compare(gconstpointer a, gconstpointer b)
{
const gchar *string[2] = {(const gchar*)a,
(const gchar*)b};
gchar alphabet[26] = {'a','b','c','d','e','f','g',
'h','i','j','k','l','m','n',
'o','p','q','r','s','t','u',
'v','w','x','y','z'};
gint len[2] = {strlen(string[0]), strlen(string[1])};
gint maxlen = MIN(len[0], len[1]);
gint letter[2];
gint i, j, k;
for(i = 0; i < maxlen; i++)
{
for(k = 0; k < 2; k++)
{
letter[k] = 0;
for(j = 0; j < 26; j++)
if(string[k][i] == alphabet[j])
{
letter[k] = j;
break;
}
}
if(letter[0] < letter[1])
return -1;
else if(letter[0] > letter[1])
return 1;
}
if(len[0] != len[1])
return 1 - 2 * (len[0] < len[1]);
return 0;
}

View File

@ -135,4 +135,7 @@ void
misc_token_add_bool(GPtrArray **token_rep, gint token_idx,
gboolean value);
gint
misc_alphabetic_compare(gconstpointer a, gconstpointer b);
#endif

View File

@ -194,8 +194,6 @@ option_add(OptionList *optionlist, const gchar *name,
((Option*)element)->string_value = (string_value == NULL) ? NULL : g_strdup(string_value);
return;
}
/* main_exit_program(EXIT_OPTION_NOT_FOUND, */
/* "Option named '%s' already contained in optionlist.", name); */
new.name = g_strdup(name);
new.value = int_value;
@ -214,3 +212,9 @@ option_add(OptionList *optionlist, const gchar *name,
g_array_index(optionlist->list, Option, i).name,
&g_array_index(optionlist->list, Option, i));
}
gint
option_compare_func(gconstpointer a, gconstpointer b)
{
return misc_alphabetic_compare(((const Option*)a)->name, ((const Option*)b)->name);
}

View File

@ -90,4 +90,7 @@ option_set_int(const gchar *name, OptionList *optionlist, gint new_value);
void
option_add(OptionList *optionlist, const gchar *name, gint int_value, const gchar *string_value);
gint
option_compare_func(gconstpointer a, gconstpointer b);
#endif

View File

@ -560,7 +560,7 @@ option_gui_write_options(void)
if(i == ENTRY_OPT_CONSTANTS &&
strcmp(gtk_entry_get_text(entry_widgets[i]), opt_str("string_opt_constants_file")) != 0)
file_load_opt_file(gtk_entry_get_text(entry_widgets[i]), &constants);
file_load_opt_file(gtk_entry_get_text(entry_widgets[i]), &constants, TRUE);
else if(i == ENTRY_OPT_FONT_NAME &&
strcmp(gtk_entry_get_text(entry_widgets[i]), opt_str("string_opt_font_name")) != 0)
on_button_back_to_main_clicked(NULL, NULL);

View File

@ -108,7 +108,7 @@ on_button_reload_constants_clicked (GtkButton *button,
const gchar *constants_file =
gtk_entry_get_text(GTK_ENTRY(lookup_widget(window.options, "entry_constants_file")));
file_load_opt_file(constants_file, &constants);
file_load_opt_file(constants_file, &constants, TRUE);
}
@ -126,7 +126,7 @@ on_checkbutton_save_global_button_press_event
{
gchar *conf_file = file_find_support_file("bygfoot.conf", TRUE);
file_load_opt_file(conf_file, &options);
file_load_opt_file(conf_file, &options, FALSE);
g_free(conf_file);
option_gui_set_up_window();
@ -225,11 +225,11 @@ on_button_constants_reload_clicked (GtkButton *button,
{
printf("hu\n");
file_load_opt_file(gtk_entry_get_text(GTK_ENTRY(lookup_widget(window.options, "entry_constants_file"))),
&constants);
&constants, TRUE);
}
else
file_load_opt_file(opt_str("string_opt_constants_file"),
&constants);
&constants, TRUE);
}

View File

@ -137,7 +137,7 @@ treeview_set_up_team_selection_treeview(GtkTreeView *treeview)
gtk_tree_view_set_search_column(treeview, 2);
gtk_tree_view_set_search_equal_func(treeview,
treeview_helper_search_equal,
treeview_helper_search_equal_teams,
NULL, NULL);
/* Numbering the teams */
@ -443,10 +443,8 @@ treeview_show_player_list(GtkTreeView *treeview, GPtrArray *players,
treeview_helper_clear(treeview);
for(i=0;i<PLAYER_LIST_ATTRIBUTE_END;i++)
{
if(attribute.on_off[i])
attributes[cnt++] = i;
}
treeview_set_up_player_list(treeview, attributes, columns, show_separator, transfer_list, sortable);
@ -2773,7 +2771,7 @@ treeview_show_contributors(GtkTreeView *treeview)
help_list.list = NULL;
help_list.datalist = NULL;
file_load_opt_file(help_file, &help_list);
file_load_opt_file(help_file, &help_list, FALSE);
gtk_tree_selection_set_mode(gtk_tree_view_get_selection(treeview),
GTK_SELECTION_NONE);

View File

@ -743,14 +743,14 @@ treeview2_create_constants(const GPtrArray *list, gint type)
g_warning("treeview2_create_constants: unknown constants type\n");
return NULL;
case CONSTANTS_TYPE_INT:
ls = gtk_list_store_new(3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT);
ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
break;
case CONSTANTS_TYPE_FLOAT:
ls = gtk_list_store_new(3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_FLOAT);
ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_FLOAT);
break;
case CONSTANTS_TYPE_STRING:
case CONSTANTS_TYPE_APP:
ls = gtk_list_store_new(3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
ls = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
break;
}
@ -760,21 +760,18 @@ treeview2_create_constants(const GPtrArray *list, gint type)
if(type == CONSTANTS_TYPE_INT)
gtk_list_store_set(ls, &iter,
0, i,
1, ((Option*)g_ptr_array_index(list, i))->name,
2, ((Option*)g_ptr_array_index(list, i))->value,
0, ((Option*)g_ptr_array_index(list, i))->name,
1, ((Option*)g_ptr_array_index(list, i))->value,
-1);
else if(type == CONSTANTS_TYPE_FLOAT)
gtk_list_store_set(ls, &iter,
0, i,
1, ((Option*)g_ptr_array_index(list, i))->name,
2, (gfloat)((Option*)g_ptr_array_index(list, i))->value / OPTION_FLOAT_DIVISOR,
0, ((Option*)g_ptr_array_index(list, i))->name,
1, (gfloat)((Option*)g_ptr_array_index(list, i))->value / OPTION_FLOAT_DIVISOR,
-1);
else
gtk_list_store_set(ls, &iter,
0, i,
1, ((Option*)g_ptr_array_index(list, i))->name,
2, ((Option*)g_ptr_array_index(list, i))->string_value,
0, ((Option*)g_ptr_array_index(list, i))->name,
1, ((Option*)g_ptr_array_index(list, i))->string_value,
-1);
}
@ -782,7 +779,7 @@ treeview2_create_constants(const GPtrArray *list, gint type)
}
void
treeview2_set_up_constants(GtkTreeView *treeview)
treeview2_set_up_constants(GtkTreeView *treeview, gint type)
{
#ifdef DEBUG
printf("treeview2_set_up_constants\n");
@ -790,9 +787,8 @@ treeview2_set_up_constants(GtkTreeView *treeview)
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
gchar *titles[3] =
{"",
_("Name"),
gchar *titles[2] =
{_("Name"),
_("Value")};
gint i;
@ -800,8 +796,12 @@ treeview2_set_up_constants(GtkTreeView *treeview)
GTK_SELECTION_SINGLE);
gtk_tree_view_set_headers_visible(treeview, TRUE);
gtk_tree_view_set_rules_hint(treeview, TRUE);
gtk_tree_view_set_search_column(treeview, 0);
gtk_tree_view_set_search_equal_func(treeview,
treeview_helper_search_equal_strings,
NULL, NULL);
for(i = 0; i < 3; i++)
for(i = 0; i < 2; i++)
{
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, titles[i]);
@ -810,6 +810,15 @@ treeview2_set_up_constants(GtkTreeView *treeview)
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer,
"text", i);
if(i == 1)
{
g_object_set(renderer, "editable", TRUE, NULL);
g_signal_connect (renderer,
"edited",
G_CALLBACK (treeview_helper_constants_editing_done),
treeview);
}
}
}
@ -848,7 +857,7 @@ treeview2_show_constants(void)
for(i = 0; i < 4; i++)
{
treeview_helper_clear(treeview[i]);
treeview2_set_up_constants(treeview[i]);
treeview2_set_up_constants(treeview[i], i);
model = treeview2_create_constants(list[i], i);
gtk_tree_view_set_model(treeview[i], model);
g_object_unref(model);

View File

@ -86,7 +86,7 @@ GtkTreeModel*
treeview2_create_constants(const GPtrArray *list, gint type);
void
treeview2_set_up_constants(GtkTreeView *treeview);
treeview2_set_up_constants(GtkTreeView *treeview, gint type);
void
treeview2_show_constants(void);

View File

@ -1814,14 +1814,14 @@ treeview_helper_bet_odds(GtkTreeViewColumn *col,
}
gboolean
treeview_helper_search_equal(GtkTreeModel *model,
gint column,
const gchar *key,
GtkTreeIter *iter,
gpointer search_data)
treeview_helper_search_equal_teams(GtkTreeModel *model,
gint column,
const gchar *key,
GtkTreeIter *iter,
gpointer search_data)
{
#ifdef DEBUG
printf("treeview_helper_search_equal\n");
printf("treeview_helper_search_equal_teams\n");
#endif
const Team *tm = NULL;
@ -1837,6 +1837,24 @@ treeview_helper_search_equal(GtkTreeModel *model,
return return_value;
}
gboolean
treeview_helper_search_equal_strings(GtkTreeModel *model,
gint column,
const gchar *key,
GtkTreeIter *iter,
gpointer search_data)
{
#ifdef DEBUG
printf("treeview_helper_search_equal_strings\n");
#endif
const gchar *string = NULL;
gtk_tree_model_get(model, iter, column, &string, -1);
return (g_strrstr(string, key) == NULL);
}
void
treeview_helper_news_additional(GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
@ -2015,3 +2033,34 @@ treeview_helper_player_name_editing_started(GtkCellRenderer *renderer,
gtk_widget_set_sensitive(lookup_widget(window.main, "menubar1"), FALSE);
gtk_widget_set_sensitive(lookup_widget(window.main, "hbox1"), FALSE);
}
void
treeview_helper_constants_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;
gfloat float_value = g_ascii_strtod(new_text, NULL);
gtk_tree_model_get_iter_from_string(model, &iter, path);
gtk_tree_model_get(model, &iter, 0, &name, -1);
if(g_str_has_prefix(name, "int_"))
{
option_set_int(name, &constants, (gint)float_value);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, (gint)float_value, -1);
}
else if(g_str_has_prefix(name, "float_"))
{
option_set_int(name, &constants, (gint)rint(g_ascii_strtod(new_text, NULL) * OPTION_FLOAT_DIVISOR));
gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, float_value, -1);
}
else
{
option_set_string(name, &constants, new_text);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, new_text, -1);
}
}

View File

@ -215,11 +215,18 @@ treeview_helper_bet_odds(GtkTreeViewColumn *col,
gpointer user_data);
gboolean
treeview_helper_search_equal(GtkTreeModel *model,
gint column,
const gchar *key,
GtkTreeIter *iter,
gpointer search_data);
treeview_helper_search_equal_teams(GtkTreeModel *model,
gint column,
const gchar *key,
GtkTreeIter *iter,
gpointer search_data);
gboolean
treeview_helper_search_equal_strings(GtkTreeModel *model,
gint column,
const gchar *key,
GtkTreeIter *iter,
gpointer search_data);
void
treeview_helper_job_exchange(GtkTreeViewColumn *col,
@ -258,4 +265,10 @@ void
treeview_helper_player_name_editing_canceled(GtkCellRendererText *renderer,
gpointer user_data);
void
treeview_helper_constants_editing_done(GtkCellRendererText *renderer,
gchar *path,
gchar *new_text,
gpointer user_data);
#endif

View File

@ -786,7 +786,7 @@ window_main_load_geometry(void)
{
optionlist.list = NULL;
optionlist.datalist = NULL;
file_load_opt_file(filename, &optionlist);
file_load_opt_file(filename, &optionlist, FALSE);
gtk_window_resize(GTK_WINDOW(window.main),
option_int("int_window_settings_width", &optionlist),

View File

@ -64,7 +64,7 @@ xml_load_users(const gchar *dirname, const gchar *basename)
{
sprintf(buf, "%s%s%s___user_%02d_options",
dirname, G_DIR_SEPARATOR_S, basename, i);
file_load_opt_file(buf, &usr(i).options);
file_load_opt_file(buf, &usr(i).options, FALSE);
sprintf(buf, "%s%s%s___user_%02d_live_game.xml",
dirname, G_DIR_SEPARATOR_S, basename, i);