bygfoot/src/options_callbacks.c

243 lines
6.2 KiB
C
Raw Normal View History

2005-10-20 17:45:00 +02:00
/*
2005-11-26 17:52:51 +01:00
options_callbacks.c
2005-10-20 17:45:00 +02:00
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
http://bygfoot.sourceforge.net
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
2005-03-27 19:59:57 +02:00
#include "file.h"
2009-03-09 21:20:26 +01:00
#include "option.h"
2004-12-23 13:58:39 +01:00
#include "options_callbacks.h"
#include "options_interface.h"
2005-03-24 14:00:01 +01:00
#include "option_gui.h"
2004-12-23 13:58:39 +01:00
#include "support.h"
2008-05-03 17:03:30 +02:00
#include "training.h"
2005-04-04 12:36:04 +02:00
#include "user.h"
2005-03-23 20:03:26 +01:00
#include "variables.h"
#include "window.h"
2004-12-23 13:58:39 +01:00
void
2005-03-23 20:03:26 +01:00
on_button_options_ok_clicked (GtkButton *button,
2004-12-23 13:58:39 +01:00
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_options_ok_clicked\n");
#endif
2005-04-04 12:36:04 +02:00
gboolean save_global =
gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(lookup_widget(window.options, "checkbutton_save_global"))),
save_user =
gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(lookup_widget(window.options, "checkbutton_save_user")));
const gchar *conf_dir = file_get_first_support_dir();
gchar buf[SMALL];
2005-03-24 14:00:01 +01:00
option_gui_write_options();
2004-12-23 13:58:39 +01:00
2005-04-04 12:36:04 +02:00
if(save_global)
{
2005-10-24 22:50:48 +02:00
sprintf(buf, "%s%sbygfoot.conf", conf_dir, G_DIR_SEPARATOR_S);
2005-04-04 12:36:04 +02:00
file_save_opt_file(buf, &options);
}
if(save_user)
{
2005-10-09 11:35:44 +02:00
if(strcmp(current_user.name, "NONAME") == 0)
2005-10-24 22:50:48 +02:00
sprintf(buf, "%s%sbygfoot_user.conf", conf_dir, G_DIR_SEPARATOR_S);
2005-04-04 12:36:04 +02:00
else
2005-10-24 22:50:48 +02:00
sprintf(buf, "%s%sbygfoot_%s.conf", conf_dir, G_DIR_SEPARATOR_S, current_user.name);
2005-04-04 12:36:04 +02:00
file_save_opt_file(buf, &current_user.options);
}
window_destroy(&window.options);
2004-12-23 13:58:39 +01:00
}
void
2005-03-23 20:03:26 +01:00
on_button_options_cancel_clicked (GtkButton *button,
2004-12-23 13:58:39 +01:00
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_options_cancel_clicked\n");
#endif
window_destroy(&window.options);
2004-12-23 13:58:39 +01:00
}
2005-03-24 14:00:01 +01:00
void
on_button_font_name_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_font_name_clicked\n");
#endif
2005-03-24 14:00:01 +01:00
window_create(WINDOW_FONT_SEL);
}
2005-03-27 19:59:57 +02:00
void
on_button_reload_constants_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_reload_constants_clicked\n");
#endif
2005-03-27 19:59:57 +02:00
const gchar *constants_file =
gtk_entry_get_text(GTK_ENTRY(lookup_widget(window.options, "entry_constants_file")));
2009-03-10 21:58:34 +01:00
file_load_opt_file(constants_file, &constants, TRUE);
2005-03-27 19:59:57 +02:00
}
2005-04-13 15:01:59 +02:00
gboolean
on_checkbutton_save_global_button_press_event
(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_checkbutton_save_global_button_press_event\n");
#endif
2005-04-13 15:01:59 +02:00
if(event->button == 3)
{
gchar *conf_file = file_find_support_file("bygfoot.conf", TRUE);
2009-03-10 21:58:34 +01:00
file_load_opt_file(conf_file, &options, FALSE);
2005-04-13 15:01:59 +02:00
g_free(conf_file);
option_gui_set_up_window();
2005-06-23 23:53:57 +02:00
return TRUE;
2005-04-13 15:01:59 +02:00
}
2005-06-23 23:53:57 +02:00
return FALSE;
2005-04-13 15:01:59 +02:00
}
gboolean
on_checkbutton_save_user_button_press_event
(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_checkbutton_save_user_button_press_event\n");
#endif
2005-04-13 15:01:59 +02:00
if(event->button == 3)
{
file_load_user_conf_file(&current_user);
option_gui_set_up_window();
2005-06-23 23:53:57 +02:00
return TRUE;
2005-04-13 15:01:59 +02:00
}
2005-06-23 23:53:57 +02:00
return FALSE;
2005-04-13 15:01:59 +02:00
}
2005-07-14 18:05:10 +02:00
gboolean
on_window_options_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_window_options_delete_event\n");
#endif
2005-07-14 18:05:10 +02:00
on_button_options_cancel_clicked(NULL, NULL);
return TRUE;
}
2008-05-03 17:03:30 +02:00
void
on_spinbutton_recreation_value_changed (GtkSpinButton *spinbutton,
gpointer user_data)
{
#ifdef DEBUG
printf("on_spinbutton_recreation_value_changed\n");
#endif
2008-05-03 17:03:30 +02:00
gchar buf[SMALL];
sprintf(buf, "%d", CAMP_SCALE_MAX - gtk_spin_button_get_value_as_int(spinbutton));
gtk_label_set_text(GTK_LABEL(lookup_widget(window.options, "label_training")), buf);
}
2009-03-09 21:20:26 +01:00
void
on_button_edit_constants_clicked (GtkButton *button,
gpointer user_data)
{
window_show_constants();
}
gboolean
on_window_constants_destroy_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
on_button_constants_close_clicked(NULL, NULL);
return FALSE;
}
gboolean
on_window_constants_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
on_button_constants_close_clicked(NULL, NULL);
return FALSE;
}
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"))),
2009-03-10 21:58:34 +01:00
&constants, TRUE);
2009-03-09 21:20:26 +01:00
}
else
file_load_opt_file(opt_str("string_opt_constants_file"),
2009-03-10 21:58:34 +01:00
&constants, TRUE);
2009-03-09 21:20:26 +01:00
}
void
on_button_constants_close_clicked (GtkButton *button,
gpointer user_data)
{
window_destroy(&window.constants);
}