bygfoot/src/misc_callbacks.c

588 lines
15 KiB
C
Raw Permalink Normal View History

2005-10-20 17:45:00 +02:00
/*
2005-11-26 17:52:51 +01:00
misc_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-04-04 12:36:04 +02:00
#include "callbacks.h"
#include "callback_func.h"
2005-03-21 11:16:37 +01:00
#include "game.h"
#include "game_gui.h"
2005-04-04 12:36:04 +02:00
#include "gui.h"
#include "live_game.h"
2005-04-04 12:36:04 +02:00
#include "load_save.h"
2005-03-16 21:48:25 +01:00
#include "main.h"
2005-06-20 14:46:57 +02:00
#include "maths.h"
#include "misc_callback_func.h"
2004-12-23 13:58:39 +01:00
#include "misc_callbacks.h"
#include "option.h"
#include "user.h"
2005-01-09 21:21:22 +01:00
#include "variables.h"
#include "window.h"
2005-04-07 18:44:33 +02:00
#include "xml_country.h"
2004-12-23 13:58:39 +01:00
G_MODULE_EXPORT void
on_button_add_player_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_add_player_clicked\n");
#endif
misc_callback_add_player();
}
G_MODULE_EXPORT void
on_entry_player_name_activate (GtkEntry *entry,
gpointer user_data)
{
#ifdef DEBUG
printf("on_entry_player_name_activate\n");
#endif
on_button_add_player_clicked(NULL, NULL);
}
G_MODULE_EXPORT void
on_team_selection_ok_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_team_selection_ok_clicked\n");
#endif
misc_callback_start_game();
}
G_MODULE_EXPORT void
2004-12-23 13:58:39 +01:00
on_team_selection_cancel_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_team_selection_cancel_clicked\n");
#endif
2005-03-16 21:48:25 +01:00
main_exit_program(EXIT_OK, NULL);
2004-12-23 13:58:39 +01:00
}
G_MODULE_EXPORT gboolean
2004-12-23 13:58:39 +01:00
on_button_font_sel_cancel_clicked (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_font_sel_cancel_clicked\n");
#endif
window_destroy(&window.font_sel);
2004-12-23 13:58:39 +01:00
2005-03-24 14:00:01 +01:00
return FALSE;
2004-12-23 13:58:39 +01:00
}
G_MODULE_EXPORT void
2004-12-23 13:58:39 +01:00
on_button_font_sel_ok_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_font_sel_ok_clicked\n");
#endif
2005-03-24 14:00:01 +01:00
gchar *font =
gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(window.font_sel));
2004-12-23 13:58:39 +01:00
2005-03-24 14:00:01 +01:00
if(font != NULL)
{
gtk_entry_set_text(GTK_ENTRY(lookup_widget(window.options, "entry_font_name")), font);
g_free(font);
}
window_destroy(&window.font_sel);
2004-12-23 13:58:39 +01:00
}
G_MODULE_EXPORT void
2004-12-23 13:58:39 +01:00
on_button_font_sel_apply_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_font_sel_apply_clicked\n");
#endif
2005-03-24 14:00:01 +01:00
gchar *font =
gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(window.font_sel));
if(font != NULL)
{
opt_set_str("string_opt_font_name", font);
gtk_entry_set_text(GTK_ENTRY(lookup_widget(window.options, "entry_font_name")), font);
g_free(font);
2004-12-23 13:58:39 +01:00
2005-03-24 14:00:01 +01:00
stat0 = STATUS_MAIN;
game_gui_show_main();
2005-04-07 18:44:33 +02:00
setsav0;
2005-03-24 14:00:01 +01:00
}
2004-12-23 13:58:39 +01:00
}
G_MODULE_EXPORT gboolean
2004-12-23 13:58:39 +01:00
on_live_window_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_live_window_delete_event\n");
#endif
2005-03-09 14:10:28 +01:00
if(GTK_WIDGET_IS_SENSITIVE(lookup_widget(widget, "button_live_close")))
{
on_button_live_close_clicked(NULL, NULL);
return FALSE;
}
2004-12-23 13:58:39 +01:00
2005-03-09 14:10:28 +01:00
return TRUE;
2004-12-23 13:58:39 +01:00
}
G_MODULE_EXPORT void
2004-12-23 13:58:39 +01:00
on_button_live_close_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_live_close_clicked\n");
#endif
2005-05-08 08:15:35 +02:00
if(stat1 == STATUS_SHOW_LAST_MATCH && stat3 != -1 &&
stat4 != STATUS_SHOW_LAST_MATCH_PAUSE)
stat4 = STATUS_SHOW_LAST_MATCH_ABORT;
else if(stat1 != STATUS_SHOW_LAST_MATCH)
2005-03-11 18:18:51 +01:00
callback_show_next_live_game();
else
2005-05-08 08:15:35 +02:00
{
window_destroy(&window.live);
2005-05-08 08:15:35 +02:00
stat1 = stat2 = stat3 = stat4 = -1;
}
2004-12-23 13:58:39 +01:00
}
G_MODULE_EXPORT void
2005-01-09 21:21:22 +01:00
on_button_pause_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_pause_clicked\n");
#endif
misc_callback_pause_live_game();
2005-01-09 21:21:22 +01:00
}
G_MODULE_EXPORT void
2005-01-09 21:21:22 +01:00
on_button_resume_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_resume_clicked\n");
#endif
2005-05-28 10:19:56 +02:00
GtkWidget *button_pause =
lookup_widget(window.live, "button_pause");
2005-05-08 08:15:35 +02:00
if(stat1 == STATUS_SHOW_LAST_MATCH)
{
2005-08-20 21:39:36 +02:00
callback_show_last_match(FALSE, &current_user.live_game);
2005-05-08 08:15:35 +02:00
return;
}
else if(game_check_live_game_resume_state())
2005-03-08 09:25:46 +01:00
{
2005-03-24 19:04:31 +01:00
gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
2005-03-08 09:25:46 +01:00
if(g_array_index(usr(stat2).live_game.units, LiveGameUnit,
usr(stat2).live_game.units->len - 1).event.type !=
LIVE_GAME_EVENT_PENALTIES)
2005-05-28 10:19:56 +02:00
{
gtk_widget_set_sensitive(button_pause, TRUE);
gtk_widget_grab_focus(button_pause);
}
2005-03-08 09:25:46 +01:00
game_gui_set_main_window_sensitivity(FALSE);
live_game_resume();
}
else
2005-06-18 16:45:29 +02:00
game_gui_show_warning(_("There were too many substitutions. Only 3 per game are allowed. Player list reset."));
2005-01-09 21:21:22 +01:00
}
2005-01-10 16:24:15 +01:00
G_MODULE_EXPORT void
2005-01-10 16:24:15 +01:00
on_spinbutton_speed_value_changed (GtkSpinButton *spinbutton,
gpointer user_data)
{
#ifdef DEBUG
printf("on_spinbutton_speed_value_changed\n");
#endif
option_set_int("int_opt_user_live_game_speed",
2005-03-23 20:03:26 +01:00
&usr(stat2).options, gtk_spin_button_get_value_as_int(spinbutton));
2005-01-10 16:24:15 +01:00
}
G_MODULE_EXPORT void
2005-05-19 10:31:47 +02:00
on_spinbutton_verbosity_value_changed (GtkSpinButton *spinbutton,
gpointer user_data)
{
#ifdef DEBUG
printf("on_spinbutton_verbosity_value_changed\n");
#endif
2005-05-19 10:31:47 +02:00
option_set_int("int_opt_user_live_game_verbosity",
&usr(stat2).options, gtk_spin_button_get_value_as_int(spinbutton));
}
G_MODULE_EXPORT gboolean
on_treeview_users_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_treeview_users_button_press_event\n");
#endif
misc_callback_remove_user(event);
return FALSE;
}
2005-03-17 21:26:01 +01:00
G_MODULE_EXPORT void
2005-03-17 21:26:01 +01:00
on_spinbutton_capacity_value_changed (GtkSpinButton *spinbutton,
gpointer user_data)
{
#ifdef DEBUG
printf("on_spinbutton_capacity_value_changed\n");
#endif
2005-03-17 21:26:01 +01:00
misc_callback_update_stadium_window(TRUE);
}
G_MODULE_EXPORT void
2005-03-17 21:26:01 +01:00
on_spinbutton_safety_value_changed (GtkSpinButton *spinbutton,
gpointer user_data)
{
#ifdef DEBUG
printf("on_spinbutton_safety_value_changed\n");
#endif
2005-03-17 21:26:01 +01:00
misc_callback_update_stadium_window(FALSE);
}
G_MODULE_EXPORT void
2005-03-17 21:26:01 +01:00
on_button_stadium_ok_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_stadium_ok_clicked\n");
#endif
2005-03-17 21:26:01 +01:00
misc_callback_improve_stadium();
2005-04-09 21:18:28 +02:00
if(stat0 == STATUS_SHOW_FINANCES)
on_menu_show_finances_activate(NULL, NULL);
2005-03-17 21:26:01 +01:00
}
G_MODULE_EXPORT void
2005-03-17 21:26:01 +01:00
on_button_stadium_cancel_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_stadium_cancel_clicked\n");
#endif
window_destroy(&window.stadium);
2005-03-17 21:26:01 +01:00
}
G_MODULE_EXPORT gboolean
2005-03-17 21:26:01 +01:00
on_spinbutton_capacity_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_spinbutton_capacity_button_press_event\n");
#endif
2005-03-17 21:43:57 +01:00
if(event->button == 3)
{
2005-03-17 21:26:01 +01:00
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), 0);
2005-03-17 21:43:57 +01:00
return TRUE;
}
2005-03-17 21:26:01 +01:00
return FALSE;
}
2005-04-06 13:14:34 +02:00
G_MODULE_EXPORT gboolean
2005-04-09 21:18:28 +02:00
on_window_stadium_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_window_stadium_delete_event\n");
#endif
2005-05-02 17:14:41 +02:00
on_button_stadium_cancel_clicked(NULL, NULL);
2005-04-06 13:14:34 +02:00
2005-04-09 21:18:28 +02:00
return TRUE;
2005-04-06 13:14:34 +02:00
}
2005-04-09 21:18:28 +02:00
G_MODULE_EXPORT void
2005-05-07 16:19:52 +02:00
on_combo_country_changed (GtkComboBox *combobox,
gpointer user_data)
{
#ifdef DEBUG
printf("on_combo_country_changed\n");
#endif
2005-05-07 16:19:52 +02:00
GtkTreeIter iter;
gchar *buf = NULL;
gtk_combo_box_get_active_iter(combobox, &iter);
if (!gtk_tree_model_iter_has_child (gtk_combo_box_get_model(combobox),
&iter))
{
gtk_tree_model_get(gtk_combo_box_get_model(combobox), &iter, 1, &buf, -1);
misc_callback_show_team_list(GTK_WIDGET(combobox), buf);
} else {
gtk_widget_set_sensitive(lookup_widget(window.startup, "button_add_player"), FALSE);
}
2008-12-17 16:31:07 +01:00
2005-05-07 16:19:52 +02:00
g_free(buf);
}
2005-05-19 20:13:14 +02:00
G_MODULE_EXPORT gboolean
2005-05-19 20:13:14 +02:00
on_spinbutton_speed_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_spinbutton_speed_button_press_event\n");
#endif
2005-05-19 20:13:14 +02:00
if(event->button == 3)
{
2005-08-29 10:31:00 +02:00
if(option_int("int_opt_user_live_game_speed", &usr(stat2).options) ==
-rint((gfloat)(const_int("int_game_gui_live_game_speed_max") - 10) /
(gfloat)(const_int("int_game_gui_live_game_speed_grad"))))
2005-08-27 18:17:50 +02:00
option_set_int("int_opt_user_live_game_speed", &usr(stat2).options, 0);
2005-08-29 10:31:00 +02:00
else if(option_int("int_opt_user_live_game_speed", &usr(stat2).options) == 0)
option_set_int("int_opt_user_live_game_speed", &usr(stat2).options,
-rint((gfloat)(const_int("int_game_gui_live_game_speed_max") - 10) /
(gfloat)(const_int("int_game_gui_live_game_speed_grad") * 2)));
else
option_set_int("int_opt_user_live_game_speed", &usr(stat2).options,
-rint((gfloat)(const_int("int_game_gui_live_game_speed_max") - 10) /
(gfloat)(const_int("int_game_gui_live_game_speed_grad"))));
2005-05-19 20:13:14 +02:00
gtk_spin_button_set_value(
GTK_SPIN_BUTTON(lookup_widget(window.live, "spinbutton_speed")),
(gdouble)option_int("int_opt_user_live_game_speed", &usr(stat2).options));
return TRUE;
}
return FALSE;
}
2005-06-20 14:46:57 +02:00
G_MODULE_EXPORT void
2005-06-20 14:46:57 +02:00
on_button_sponsors_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_sponsors_clicked\n");
#endif
2005-06-20 14:46:57 +02:00
misc_callback_new_sponsor();
window_destroy(&window.sponsors);
2005-06-20 14:46:57 +02:00
}
G_MODULE_EXPORT void
2005-06-20 14:46:57 +02:00
on_treeview_sponsors_row_activated (GtkTreeView *treeview,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer user_data)
{
#ifdef DEBUG
printf("on_treeview_sponsors_row_activated\n");
#endif
2005-06-20 14:46:57 +02:00
on_button_sponsors_clicked(NULL, NULL);
}
G_MODULE_EXPORT gboolean
2005-06-20 14:46:57 +02:00
on_window_sponsors_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
#ifdef DEBUG
printf("on_window_sponsors_delete_event\n");
#endif
2005-06-20 14:46:57 +02:00
return TRUE;
}
G_MODULE_EXPORT void
2005-06-20 14:46:57 +02:00
on_button_sponsors_wait_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_sponsors_wait_clicked\n");
#endif
2005-06-20 14:46:57 +02:00
if(stat1 != STATUS_SPONSOR_CONTINUE)
{
g_string_printf(current_user.sponsor.name, _("None"));
current_user.sponsor.contract = 0;
current_user.sponsor.benefit = 0;
current_user.counters[COUNT_USER_NEW_SPONSOR] =
math_rndi(const_int("int_sponsor_without_weeks_lower"),
const_int("int_sponsor_without_weeks_upper"));
}
else
current_user.counters[COUNT_USER_NEW_SPONSOR] = 0;
window_destroy(&window.sponsors);
2005-06-20 14:46:57 +02:00
}
2005-09-28 12:21:43 +02:00
G_MODULE_EXPORT gboolean
2005-09-28 18:41:32 +02:00
on_eventbox_lg_style_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
2005-09-28 12:21:43 +02:00
{
#ifdef DEBUG
printf("on_eventbox_lg_style_button_press_event\n");
#endif
2005-09-28 18:41:32 +02:00
gint new_style = -1;
if(stat0 == STATUS_LIVE_GAME_PAUSE)
{
on_eventbox_style_button_press_event(NULL, event, NULL);
return FALSE;
}
2006-04-19 19:00:53 +02:00
if(event->type != GDK_BUTTON_PRESS ||
g_array_index(usr(stat2).live_game.units, LiveGameUnit,
usr(stat2).live_game.units->len -1).event.type ==
LIVE_GAME_EVENT_END_MATCH)
2005-09-28 18:41:32 +02:00
return FALSE;
if(event->button == 3)
new_style = (usr(stat2).tm->style != 2) ?
usr(stat2).tm->style + 1 : -2;
else if(event->button == 1)
new_style = (usr(stat2).tm->style != -2) ?
usr(stat2).tm->style - 1 : 2;
else
return FALSE;
game_save_team_states();
usr(stat2).tm->style = new_style;
game_gui_write_meters(usr(stat2).tm);
2005-09-28 18:41:32 +02:00
if(&current_user == &usr(stat2))
game_gui_write_meters(current_user.tm);
2005-09-28 18:41:32 +02:00
stat0 = STATUS_LIVE_GAME_CHANGE;
2005-09-28 12:21:43 +02:00
return FALSE;
}
G_MODULE_EXPORT gboolean
2005-09-28 18:41:32 +02:00
on_eventbox_lg_boost_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
2005-09-28 12:21:43 +02:00
{
#ifdef DEBUG
printf("on_eventbox_lg_boost_button_press_event\n");
#endif
2005-09-28 18:41:32 +02:00
gint new_boost = -1;
if(stat0 == STATUS_LIVE_GAME_PAUSE)
{
on_eventbox_boost_button_press_event(NULL, event, NULL);
return FALSE;
}
2006-04-19 18:57:01 +02:00
if(event->type != GDK_BUTTON_PRESS ||
g_array_index(usr(stat2).live_game.units, LiveGameUnit,
usr(stat2).live_game.units->len -1).event.type ==
LIVE_GAME_EVENT_END_MATCH)
2005-09-28 18:41:32 +02:00
return FALSE;
if(event->button == 3)
new_boost = (usr(stat2).tm->boost != 1) ?
usr(stat2).tm->boost + 1 : -1;
else if(event->button == 1)
new_boost = (usr(stat2).tm->boost != -1) ?
usr(stat2).tm->boost - 1 : 1;
else
return FALSE;
if(new_boost == 1 && sett_int("int_opt_disable_boost_on"))
{
game_gui_show_warning(_("Boost ON is disabled in this country definition."));
return FALSE;
}
game_save_team_states();
usr(stat2).tm->boost = new_boost;
game_gui_write_meters(usr(stat2).tm);
2005-09-28 18:41:32 +02:00
if(&current_user == &usr(stat2))
game_gui_write_meters(current_user.tm);
2005-09-28 12:21:43 +02:00
2005-09-28 18:41:32 +02:00
stat0 = STATUS_LIVE_GAME_CHANGE;
2005-09-28 12:21:43 +02:00
return FALSE;
}
2006-02-15 13:03:48 +01:00
G_MODULE_EXPORT void
2006-02-15 13:03:48 +01:00
on_button_team_selection_back_clicked (GtkButton *button,
gpointer user_data)
{
#ifdef DEBUG
printf("on_button_team_selection_back_clicked\n");
#endif
window_destroy(&window.startup);
2006-02-15 13:03:48 +01:00
stat0 = STATUS_SPLASH;
window_show_splash();
}