bygfoot/src/training_callbacks.c

267 lines
8.3 KiB
C
Raw Normal View History

2007-01-18 18:36:09 +01:00
/*
2008-05-02 15:00:05 +02:00
bet_struct.h
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
http://bygfoot.sourceforge.net
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
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.
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
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.
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
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.
2007-01-18 18:36:09 +01:00
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include "bygfoot.h"
2008-05-02 15:00:05 +02:00
#include "finance.h"
2007-01-18 18:36:09 +01:00
#include "game_gui.h"
2008-05-02 15:00:05 +02:00
#include "option.h"
#include "maths.h"
#include "misc.h"
2007-01-18 18:36:09 +01:00
#include "support.h"
#include "training.h"
#include "training_callbacks.h"
#include "training_interface.h"
#include "training_struct.h"
#include "treeview.h"
#include "user.h"
#include "variables.h"
#include "window.h"
void
on_b_cancel_clicked (GtkButton *button,
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
window_destroy(&window.training_camp);
2007-01-18 18:36:09 +01:00
}
void
on_b_ok_clicked (GtkButton *button,
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
GtkWidget *rb_camp1;
2007-01-18 18:36:09 +01:00
GtkWidget *rb_camp2;
GtkHScale *hs_recreation;
GtkHScale *hs_training;
gdouble value_training;
2008-05-02 15:00:05 +02:00
gdouble value_recreation;
gint number_camp;
2008-05-03 17:03:30 +02:00
gboolean save;
2008-05-02 15:00:05 +02:00
Team *current_team = current_user.tm;
2008-05-03 17:03:30 +02:00
save = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(lookup_widget(window.training_camp, "checkbutton_save")));
2008-05-02 15:00:05 +02:00
//Get active radio
rb_camp1 = GTK_WIDGET(lookup_widget(window.training_camp, "rb_camp1"));
2007-01-18 18:36:09 +01:00
rb_camp2 = GTK_WIDGET(lookup_widget(window.training_camp, "rb_camp2"));
2008-05-02 15:00:05 +02:00
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_camp1)))
2008-05-03 17:03:30 +02:00
number_camp = TRAINING_CAMP_HOTEL_GOOD;
2008-05-02 15:00:05 +02:00
else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_camp2)))
2008-05-03 17:03:30 +02:00
number_camp = TRAINING_CAMP_HOTEL_FIRST;
2008-05-02 15:00:05 +02:00
else
2008-05-03 17:03:30 +02:00
number_camp = TRAINING_CAMP_HOTEL_PREMIUM;
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
//Get values for training and recreation
2007-01-18 18:36:09 +01:00
hs_recreation = GTK_HSCALE(lookup_widget(window.training_camp, "hs_recreation"));
hs_training = GTK_HSCALE(lookup_widget(window.training_camp, "hs_training"));
value_training = gtk_range_get_value(GTK_RANGE(hs_training));
value_recreation = gtk_range_get_value(GTK_RANGE(hs_recreation));
2008-05-02 15:00:05 +02:00
//Calculate training camp
calculateTrainingCamp(current_team, value_training, value_recreation, number_camp);
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
//Set new av-values -> GUI
game_gui_write_av_skills(current_team);
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
//Set new player values in GUI
treeview_show_user_player_list();
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
//Calculate costs of the training camp
calculateCostsTrainingCamp(number_camp);
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
//Set new av-values -> GUI
game_gui_write_money();
2008-05-03 17:03:30 +02:00
if(save)
{
opt_user_set_int("int_opt_user_training_camp_hotel", number_camp);
opt_user_set_int("int_opt_user_training_camp_recreation", value_recreation);
}
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
window_destroy(&window.training_camp);
2008-05-03 17:03:30 +02:00
current_user.counters[COUNT_USER_TRAININGS_WEEK]++;
current_user.counters[COUNT_USER_TRAININGS_LEFT_SEASON]--;
game_gui_print_message(_("%d training camps left this season."),
current_user.counters[COUNT_USER_TRAININGS_LEFT_SEASON]);
2007-01-18 18:36:09 +01:00
}
void
on_rb_camp3_clicked (GtkButton *button,
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
GtkEntry *tfCosts;
gchar buf[SMALL];
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
misc_print_grouped_int(
math_round_integer(finance_wage_unit(current_user.tm) * const_float("float_training_camp_factor3"), -2),
buf);
tfCosts = GTK_ENTRY(lookup_widget(window.training_camp, "tf_costs"));
2007-01-18 18:36:09 +01:00
gtk_entry_set_text (tfCosts, buf);
}
void
on_rb_camp2_clicked (GtkButton *button,
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
GtkEntry *tfCosts;
gchar buf[SMALL];
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
misc_print_grouped_int(
math_round_integer(finance_wage_unit(current_user.tm) * const_float("float_training_camp_factor2"), -2),
buf);
tfCosts = GTK_ENTRY(lookup_widget(window.training_camp, "tf_costs"));
2007-01-18 18:36:09 +01:00
gtk_entry_set_text (tfCosts, buf);
}
void
on_rb_camp1_clicked (GtkButton *button,
2008-05-02 15:00:05 +02:00
gpointer user_data)
2007-01-18 18:36:09 +01:00
{
2008-05-02 15:00:05 +02:00
GtkEntry *tfCosts;
gchar buf[SMALL];
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
misc_print_grouped_int(
math_round_integer(finance_wage_unit(current_user.tm) * const_float("float_training_camp_factor1"), -2),
buf);
tfCosts = GTK_ENTRY(lookup_widget(window.training_camp, "tf_costs"));
2007-01-18 18:36:09 +01:00
gtk_entry_set_text (tfCosts, buf);
}
2007-02-12 17:07:19 +01:00
void
on_b_dec_recreation_clicked (GtkButton *button,
2007-01-18 18:36:09 +01:00
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
GtkHScale *hs_camp_points;
GtkHScale *hs_recreation;
gdouble value_camp_points;
gdouble value_recreation;
2007-02-12 17:07:19 +01:00
2008-05-02 15:00:05 +02:00
hs_camp_points = GTK_HSCALE(lookup_widget(window.training_camp, "hs_camp_points"));
hs_recreation = GTK_HSCALE(lookup_widget(window.training_camp, "hs_recreation"));
value_camp_points = gtk_range_get_value(GTK_RANGE(hs_camp_points));
value_recreation = gtk_range_get_value(GTK_RANGE(hs_recreation));
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
if (value_recreation > CAMP_SCALE_MIN)
{
value_recreation --;
value_camp_points ++;
gtk_range_set_value(GTK_RANGE(hs_recreation), value_recreation);
gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points);
}
2007-02-12 17:07:19 +01:00
}
void
on_b_inc_recreation_clicked (GtkButton *button,
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
GtkHScale *hs_camp_points;
GtkHScale *hs_recreation;
gdouble value_camp_points;
gdouble value_recreation;
2007-02-12 17:07:19 +01:00
2008-05-02 15:00:05 +02:00
hs_camp_points = GTK_HSCALE(lookup_widget(window.training_camp, "hs_camp_points"));
hs_recreation = GTK_HSCALE(lookup_widget(window.training_camp, "hs_recreation"));
value_camp_points = gtk_range_get_value(GTK_RANGE(hs_camp_points));
value_recreation = gtk_range_get_value(GTK_RANGE(hs_recreation));
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
if (value_camp_points > CAMP_SCALE_MIN)
{
value_recreation ++;
value_camp_points --;
gtk_range_set_value(GTK_RANGE(hs_recreation), value_recreation);
gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points);
}
2007-01-18 18:36:09 +01:00
}
2007-02-12 17:07:19 +01:00
void
on_b_dec_training_clicked (GtkButton *button,
2007-01-18 18:36:09 +01:00
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
GtkHScale *hs_camp_points;
GtkHScale *hs_training;
gdouble value_camp_points;
gdouble value_training;
2007-02-12 17:07:19 +01:00
2008-05-02 15:00:05 +02:00
hs_camp_points = GTK_HSCALE(lookup_widget(window.training_camp, "hs_camp_points"));
hs_training = GTK_HSCALE(lookup_widget(window.training_camp, "hs_training"));
value_camp_points = gtk_range_get_value(GTK_RANGE(hs_camp_points));
value_training = gtk_range_get_value(GTK_RANGE(hs_training));
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
if (value_training > CAMP_SCALE_MIN)
{
value_training --;
value_camp_points ++;
gtk_range_set_value(GTK_RANGE(hs_training), value_training);
gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points);
}
2007-02-12 17:07:19 +01:00
}
void
on_b_inc_training_clicked (GtkButton *button,
gpointer user_data)
{
2008-05-02 15:00:05 +02:00
GtkHScale *hs_camp_points;
GtkHScale *hs_training;
gdouble value_camp_points;
gdouble value_training;
2007-02-12 17:07:19 +01:00
2008-05-02 15:00:05 +02:00
hs_camp_points = GTK_HSCALE(lookup_widget(window.training_camp, "hs_camp_points"));
hs_training = GTK_HSCALE(lookup_widget(window.training_camp, "hs_training"));
value_camp_points = gtk_range_get_value(GTK_RANGE(hs_camp_points));
value_training = gtk_range_get_value(GTK_RANGE(hs_training));
2007-01-18 18:36:09 +01:00
2008-05-02 15:00:05 +02:00
if (value_camp_points > CAMP_SCALE_MIN)
{
value_training ++;
value_camp_points --;
gtk_range_set_value(GTK_RANGE(hs_training), value_training);
gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points);
}
2007-01-18 18:36:09 +01:00
}
gboolean
on_window_training_camp_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
on_b_cancel_clicked(NULL, NULL);
return TRUE;
}