From 3cfdd900d81fe1b4b5d774fc0029d19821628800 Mon Sep 17 00:00:00 2001 From: mrsmola Date: Mon, 12 Feb 2007 16:07:19 +0000 Subject: [PATCH] fixed the count-bug in training-camp --- src/training_callbacks.c | 109 +++++++++++++------- src/training_callbacks.h | 20 ++-- src/training_interface.c | 214 +++++++++++++++++++++++++-------------- src/training_struct.h | 6 +- 4 files changed, 224 insertions(+), 125 deletions(-) diff --git a/src/training_callbacks.c b/src/training_callbacks.c index 85437861..4d713f97 100755 --- a/src/training_callbacks.c +++ b/src/training_callbacks.c @@ -134,65 +134,98 @@ on_rb_camp1_clicked (GtkButton *button, gtk_entry_set_text (tfCosts, buf); } - -gboolean -on_hs_recreation_change_value (GtkRange *range, - GtkScrollType scroll, - gdouble value, +void +on_b_dec_recreation_clicked (GtkButton *button, gpointer user_data) { GtkHScale *hs_camp_points; + GtkHScale *hs_recreation; gdouble value_camp_points; gdouble value_recreation; - - value_recreation = gtk_range_get_value(GTK_RANGE(range)); - + 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)); - if ((value > (value_recreation + 0.5)) && (value_camp_points > CAMP_SCALE_MIN)) - { - gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points - 1.0); - return FALSE; - } - - if ((value < (value_recreation - 0.5)) && (value_camp_points < CAMP_SCALE_MAX)) + if (value_recreation > CAMP_SCALE_MIN) { - gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points + 1.0); - return FALSE; + 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); } - - return TRUE; } -gboolean -on_hs_training_change_value (GtkRange *range, - GtkScrollType scroll, - gdouble value, +void +on_b_inc_recreation_clicked (GtkButton *button, gpointer user_data) { GtkHScale *hs_camp_points; + GtkHScale *hs_recreation; gdouble value_camp_points; - gdouble value_training; - - value_training = gtk_range_get_value(GTK_RANGE(range)); - + gdouble value_recreation; + 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)); - if ((value > (value_training + 0.5)) && (value_camp_points > CAMP_SCALE_MIN)) - { - gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points - 1.0); - return FALSE; - } - - if ((value < (value_training - 0.5)) && (value_camp_points < CAMP_SCALE_MAX)) + if (value_camp_points > CAMP_SCALE_MIN) { - gtk_range_set_value(GTK_RANGE(hs_camp_points), value_camp_points + 1.0); - return FALSE; + 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); + } +} + + +void +on_b_dec_training_clicked (GtkButton *button, + gpointer user_data) +{ + GtkHScale *hs_camp_points; + GtkHScale *hs_training; + gdouble value_camp_points; + gdouble value_training; + + 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)); + + 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); + } +} + + +void +on_b_inc_training_clicked (GtkButton *button, + gpointer user_data) +{ + GtkHScale *hs_camp_points; + GtkHScale *hs_training; + gdouble value_camp_points; + gdouble value_training; + + 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)); + + 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); } - - return TRUE; } diff --git a/src/training_callbacks.h b/src/training_callbacks.h index 61e75a97..483b39e9 100755 --- a/src/training_callbacks.h +++ b/src/training_callbacks.h @@ -46,14 +46,18 @@ void on_rb_camp1_clicked (GtkButton *button, gpointer user_data); -gboolean -on_hs_recreation_change_value (GtkRange *range, - GtkScrollType scroll, - gdouble value, +void +on_b_dec_recreation_clicked (GtkButton *button, gpointer user_data); -gboolean -on_hs_training_change_value (GtkRange *range, - GtkScrollType scroll, - gdouble value, +void +on_b_inc_recreation_clicked (GtkButton *button, + gpointer user_data); + +void +on_b_dec_training_clicked (GtkButton *button, + gpointer user_data); + +void +on_b_inc_training_clicked (GtkButton *button, gpointer user_data); diff --git a/src/training_interface.c b/src/training_interface.c index 971dba45..e4b6198f 100755 --- a/src/training_interface.c +++ b/src/training_interface.c @@ -35,18 +35,26 @@ create_window_training_camp (void) GtkWidget *hs_camp1; GtkWidget *b_cancel; GtkWidget *b_ok; - GtkWidget *hs_recreation; - GtkWidget *hs_training; - GtkWidget *hs_camp_points; - GtkWidget *l_recreation; - GtkWidget *l_training; - GtkWidget *l_camp_points; - GtkWidget *rb_camp3; - GSList *rb_camp3_group = NULL; - GtkWidget *rb_camp2; - GtkWidget *rb_camp1; GtkWidget *hs_camp2; + GtkWidget *l_camp_points; + GtkWidget *b_dec_recreation; + GtkWidget *image1; + GtkWidget *b_inc_recreation; + GtkWidget *image2; + GtkWidget *l_recreation; GtkWidget *l_costs; + GtkWidget *rb_camp1; + GSList *rb_camp1_group = NULL; + GtkWidget *rb_camp2; + GtkWidget *rb_camp3; + GtkWidget *b_dec_training; + GtkWidget *image3; + GtkWidget *l_training; + GtkWidget *b_inc_training; + GtkWidget *image4; + GtkWidget *hs_camp_points; + GtkWidget *hs_training; + GtkWidget *hs_recreation; window_training_camp = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window_training_camp), _("Training camp")); @@ -83,90 +91,135 @@ create_window_training_camp (void) gtk_fixed_put (GTK_FIXED (panel_camp), b_ok, 256, 254); gtk_widget_set_size_request (b_ok, 110, 25); - hs_recreation = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 1, 10, 1, 0, 0))); - gtk_widget_show (hs_recreation); - gtk_fixed_put (GTK_FIXED (panel_camp), hs_recreation, 175, 120); - gtk_widget_set_size_request (hs_recreation, 200, 36); - gtk_scale_set_value_pos (GTK_SCALE (hs_recreation), GTK_POS_RIGHT); - - hs_training = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 1, 10, 1, 0, 0))); - gtk_widget_show (hs_training); - gtk_fixed_put (GTK_FIXED (panel_camp), hs_training, 175, 152); - gtk_widget_set_size_request (hs_training, 200, 36); - gtk_scale_set_value_pos (GTK_SCALE (hs_training), GTK_POS_RIGHT); - - hs_camp_points = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 1, 10, 1, 0, 0))); - gtk_widget_show (hs_camp_points); - gtk_fixed_put (GTK_FIXED (panel_camp), hs_camp_points, 175, 184); - gtk_widget_set_size_request (hs_camp_points, 200, 36); - gtk_scale_set_value_pos (GTK_SCALE (hs_camp_points), GTK_POS_RIGHT); - - l_recreation = gtk_label_new (_("Recreation")); - gtk_widget_show (l_recreation); - gtk_fixed_put (GTK_FIXED (panel_camp), l_recreation, 24, 128); - gtk_widget_set_size_request (l_recreation, 140, 20); - - l_training = gtk_label_new (_("Training")); - gtk_widget_show (l_training); - gtk_fixed_put (GTK_FIXED (panel_camp), l_training, 24, 160); - gtk_widget_set_size_request (l_training, 140, 20); + hs_camp2 = gtk_hseparator_new (); + gtk_widget_show (hs_camp2); + gtk_fixed_put (GTK_FIXED (panel_camp), hs_camp2, 25, 90); + gtk_widget_set_size_request (hs_camp2, 450, 16); l_camp_points = gtk_label_new (_("Camp points")); gtk_widget_show (l_camp_points); gtk_fixed_put (GTK_FIXED (panel_camp), l_camp_points, 24, 192); gtk_widget_set_size_request (l_camp_points, 140, 20); - rb_camp3 = gtk_radio_button_new_with_mnemonic (NULL, _("Premium Hotel")); - gtk_widget_show (rb_camp3); - gtk_fixed_put (GTK_FIXED (panel_camp), rb_camp3, 24, 64); - gtk_widget_set_size_request (rb_camp3, 200, 21); - gtk_radio_button_set_group (GTK_RADIO_BUTTON (rb_camp3), rb_camp3_group); - rb_camp3_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb_camp3)); + b_dec_recreation = gtk_button_new (); + gtk_widget_show (b_dec_recreation); + gtk_fixed_put (GTK_FIXED (panel_camp), b_dec_recreation, 176, 126); + gtk_widget_set_size_request (b_dec_recreation, 30, 24); - rb_camp2 = gtk_radio_button_new_with_mnemonic (NULL, _("First-Class Hotel")); - gtk_widget_show (rb_camp2); - gtk_fixed_put (GTK_FIXED (panel_camp), rb_camp2, 24, 40); - gtk_widget_set_size_request (rb_camp2, 200, 21); - gtk_radio_button_set_group (GTK_RADIO_BUTTON (rb_camp2), rb_camp3_group); - rb_camp3_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb_camp2)); + image1 = gtk_image_new_from_stock ("gtk-remove", GTK_ICON_SIZE_BUTTON); + gtk_widget_show (image1); + gtk_container_add (GTK_CONTAINER (b_dec_recreation), image1); - rb_camp1 = gtk_radio_button_new_with_mnemonic (NULL, _("Good Hotel")); - gtk_widget_show (rb_camp1); - gtk_fixed_put (GTK_FIXED (panel_camp), rb_camp1, 24, 16); - gtk_widget_set_size_request (rb_camp1, 200, 21); - gtk_radio_button_set_group (GTK_RADIO_BUTTON (rb_camp1), rb_camp3_group); - rb_camp3_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb_camp1)); + b_inc_recreation = gtk_button_new (); + gtk_widget_show (b_inc_recreation); + gtk_fixed_put (GTK_FIXED (panel_camp), b_inc_recreation, 425, 126); + gtk_widget_set_size_request (b_inc_recreation, 30, 24); - hs_camp2 = gtk_hseparator_new (); - gtk_widget_show (hs_camp2); - gtk_fixed_put (GTK_FIXED (panel_camp), hs_camp2, 25, 90); - gtk_widget_set_size_request (hs_camp2, 450, 16); + image2 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_BUTTON); + gtk_widget_show (image2); + gtk_container_add (GTK_CONTAINER (b_inc_recreation), image2); + + l_recreation = gtk_label_new (_("Recreation")); + gtk_widget_show (l_recreation); + gtk_fixed_put (GTK_FIXED (panel_camp), l_recreation, 24, 128); + gtk_widget_set_size_request (l_recreation, 140, 20); l_costs = gtk_label_new (_("Costs")); gtk_widget_show (l_costs); gtk_fixed_put (GTK_FIXED (panel_camp), l_costs, 255, 41); gtk_widget_set_size_request (l_costs, 90, 20); + rb_camp1 = gtk_radio_button_new_with_mnemonic (NULL, _("Good Hotel")); + gtk_widget_show (rb_camp1); + gtk_fixed_put (GTK_FIXED (panel_camp), rb_camp1, 24, 16); + gtk_widget_set_size_request (rb_camp1, 200, 21); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (rb_camp1), rb_camp1_group); + rb_camp1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb_camp1)); + + rb_camp2 = gtk_radio_button_new_with_mnemonic (NULL, _("First-Class Hotel")); + gtk_widget_show (rb_camp2); + gtk_fixed_put (GTK_FIXED (panel_camp), rb_camp2, 24, 40); + gtk_widget_set_size_request (rb_camp2, 200, 21); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (rb_camp2), rb_camp1_group); + rb_camp1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb_camp2)); + + rb_camp3 = gtk_radio_button_new_with_mnemonic (NULL, _("Premium Hotel")); + gtk_widget_show (rb_camp3); + gtk_fixed_put (GTK_FIXED (panel_camp), rb_camp3, 24, 64); + gtk_widget_set_size_request (rb_camp3, 200, 21); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (rb_camp3), rb_camp1_group); + rb_camp1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb_camp3)); + + b_dec_training = gtk_button_new (); + gtk_widget_show (b_dec_training); + gtk_fixed_put (GTK_FIXED (panel_camp), b_dec_training, 176, 158); + gtk_widget_set_size_request (b_dec_training, 30, 24); + + image3 = gtk_image_new_from_stock ("gtk-remove", GTK_ICON_SIZE_BUTTON); + gtk_widget_show (image3); + gtk_container_add (GTK_CONTAINER (b_dec_training), image3); + + l_training = gtk_label_new (_("Training")); + gtk_widget_show (l_training); + gtk_fixed_put (GTK_FIXED (panel_camp), l_training, 24, 160); + gtk_widget_set_size_request (l_training, 140, 20); + + b_inc_training = gtk_button_new (); + gtk_widget_show (b_inc_training); + gtk_fixed_put (GTK_FIXED (panel_camp), b_inc_training, 425, 158); + gtk_widget_set_size_request (b_inc_training, 30, 24); + + image4 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_BUTTON); + gtk_widget_show (image4); + gtk_container_add (GTK_CONTAINER (b_inc_training), image4); + + hs_camp_points = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 1, 10, 1, 0, 0))); + gtk_widget_show (hs_camp_points); + gtk_fixed_put (GTK_FIXED (panel_camp), hs_camp_points, 220, 184); + gtk_widget_set_size_request (hs_camp_points, 200, 36); + GTK_WIDGET_UNSET_FLAGS (hs_camp_points, GTK_CAN_FOCUS); + gtk_scale_set_value_pos (GTK_SCALE (hs_camp_points), GTK_POS_RIGHT); + + hs_training = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 1, 10, 1, 0, 0))); + gtk_widget_show (hs_training); + gtk_fixed_put (GTK_FIXED (panel_camp), hs_training, 220, 152); + gtk_widget_set_size_request (hs_training, 200, 36); + GTK_WIDGET_UNSET_FLAGS (hs_training, GTK_CAN_FOCUS); + gtk_scale_set_value_pos (GTK_SCALE (hs_training), GTK_POS_RIGHT); + + hs_recreation = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 1, 10, 1, 0, 0))); + gtk_widget_show (hs_recreation); + gtk_fixed_put (GTK_FIXED (panel_camp), hs_recreation, 220, 120); + gtk_widget_set_size_request (hs_recreation, 200, 36); + GTK_WIDGET_UNSET_FLAGS (hs_recreation, GTK_CAN_FOCUS); + gtk_scale_set_value_pos (GTK_SCALE (hs_recreation), GTK_POS_RIGHT); + g_signal_connect ((gpointer) b_cancel, "clicked", G_CALLBACK (on_b_cancel_clicked), NULL); g_signal_connect ((gpointer) b_ok, "clicked", G_CALLBACK (on_b_ok_clicked), NULL); - g_signal_connect ((gpointer) hs_recreation, "change_value", - G_CALLBACK (on_hs_recreation_change_value), + g_signal_connect ((gpointer) b_dec_recreation, "clicked", + G_CALLBACK (on_b_dec_recreation_clicked), NULL); - g_signal_connect ((gpointer) hs_training, "change_value", - G_CALLBACK (on_hs_training_change_value), + g_signal_connect ((gpointer) b_inc_recreation, "clicked", + G_CALLBACK (on_b_inc_recreation_clicked), NULL); - g_signal_connect ((gpointer) rb_camp3, "clicked", - G_CALLBACK (on_rb_camp3_clicked), + g_signal_connect ((gpointer) rb_camp1, "clicked", + G_CALLBACK (on_rb_camp1_clicked), NULL); g_signal_connect ((gpointer) rb_camp2, "clicked", G_CALLBACK (on_rb_camp2_clicked), NULL); - g_signal_connect ((gpointer) rb_camp1, "clicked", - G_CALLBACK (on_rb_camp1_clicked), + g_signal_connect ((gpointer) rb_camp3, "clicked", + G_CALLBACK (on_rb_camp3_clicked), + NULL); + g_signal_connect ((gpointer) b_dec_training, "clicked", + G_CALLBACK (on_b_dec_training_clicked), + NULL); + g_signal_connect ((gpointer) b_inc_training, "clicked", + G_CALLBACK (on_b_inc_training_clicked), NULL); /* Store pointers to all widgets, for use by lookup_widget(). */ @@ -176,18 +229,27 @@ create_window_training_camp (void) GLADE_HOOKUP_OBJECT (window_training_camp, hs_camp1, "hs_camp1"); GLADE_HOOKUP_OBJECT (window_training_camp, b_cancel, "b_cancel"); GLADE_HOOKUP_OBJECT (window_training_camp, b_ok, "b_ok"); - GLADE_HOOKUP_OBJECT (window_training_camp, hs_recreation, "hs_recreation"); - GLADE_HOOKUP_OBJECT (window_training_camp, hs_training, "hs_training"); - GLADE_HOOKUP_OBJECT (window_training_camp, hs_camp_points, "hs_camp_points"); - GLADE_HOOKUP_OBJECT (window_training_camp, l_recreation, "l_recreation"); - GLADE_HOOKUP_OBJECT (window_training_camp, l_training, "l_training"); - GLADE_HOOKUP_OBJECT (window_training_camp, l_camp_points, "l_camp_points"); - GLADE_HOOKUP_OBJECT (window_training_camp, rb_camp3, "rb_camp3"); - GLADE_HOOKUP_OBJECT (window_training_camp, rb_camp2, "rb_camp2"); - GLADE_HOOKUP_OBJECT (window_training_camp, rb_camp1, "rb_camp1"); GLADE_HOOKUP_OBJECT (window_training_camp, hs_camp2, "hs_camp2"); + GLADE_HOOKUP_OBJECT (window_training_camp, l_camp_points, "l_camp_points"); + GLADE_HOOKUP_OBJECT (window_training_camp, b_dec_recreation, "b_dec_recreation"); + GLADE_HOOKUP_OBJECT (window_training_camp, image1, "image1"); + GLADE_HOOKUP_OBJECT (window_training_camp, b_inc_recreation, "b_inc_recreation"); + GLADE_HOOKUP_OBJECT (window_training_camp, image2, "image2"); + GLADE_HOOKUP_OBJECT (window_training_camp, l_recreation, "l_recreation"); GLADE_HOOKUP_OBJECT (window_training_camp, l_costs, "l_costs"); + GLADE_HOOKUP_OBJECT (window_training_camp, rb_camp1, "rb_camp1"); + GLADE_HOOKUP_OBJECT (window_training_camp, rb_camp2, "rb_camp2"); + GLADE_HOOKUP_OBJECT (window_training_camp, rb_camp3, "rb_camp3"); + GLADE_HOOKUP_OBJECT (window_training_camp, b_dec_training, "b_dec_training"); + GLADE_HOOKUP_OBJECT (window_training_camp, image3, "image3"); + GLADE_HOOKUP_OBJECT (window_training_camp, l_training, "l_training"); + GLADE_HOOKUP_OBJECT (window_training_camp, b_inc_training, "b_inc_training"); + GLADE_HOOKUP_OBJECT (window_training_camp, image4, "image4"); + GLADE_HOOKUP_OBJECT (window_training_camp, hs_camp_points, "hs_camp_points"); + GLADE_HOOKUP_OBJECT (window_training_camp, hs_training, "hs_training"); + GLADE_HOOKUP_OBJECT (window_training_camp, hs_recreation, "hs_recreation"); + gtk_widget_grab_focus (rb_camp1); return window_training_camp; } diff --git a/src/training_struct.h b/src/training_struct.h index fa0fd58e..28d4ea22 100755 --- a/src/training_struct.h +++ b/src/training_struct.h @@ -28,9 +28,9 @@ #include "bygfoot.h" -#define COSTS_CAMP_1 250000 -#define COSTS_CAMP_2 500000 -#define COSTS_CAMP_3 750000 +#define COSTS_CAMP_1 200000 +#define COSTS_CAMP_2 400000 +#define COSTS_CAMP_3 600000 #define CAMP_SCALE_MIN 0 #define CAMP_SCALE_MAX 10