Automatic loan repayment.

This commit is contained in:
gyboth 2008-11-07 08:38:55 +00:00
parent da0eee7603
commit ef5a5ff1c2
12 changed files with 185 additions and 58 deletions

View File

@ -20,7 +20,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_bets_delete_event" last_modification_time="Thu, 27 Oct 2005 17:10:03 GMT"/>
<child>
@ -224,7 +223,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_splash_delete_event" last_modification_time="Fri, 10 Feb 2006 14:27:35 GMT"/>
<child>
@ -1005,7 +1003,7 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_alr_delete_event" last_modification_time="Fri, 10 Feb 2006 14:27:35 GMT"/>
<child>
<widget class="GtkVBox" id="vbox5">
@ -1279,7 +1277,7 @@
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
<property name="snap_to_ticks">False</property>
<property name="wrap">False</property>
<property name="adjustment">1 0 0 1 10 10</property>
<property name="adjustment">0 0 0 1 10 0</property>
<signal name="changed" handler="on_spinbutton_start_week_changed" last_modification_time="Thu, 06 Nov 2008 16:38:31 GMT"/>
</widget>
<packing>
@ -1292,7 +1290,7 @@
</child>
<child>
<widget class="GtkSpinButton" id="spinbutton_installment">
<widget class="GtkSpinButton" id="spinbutton_weekly_installment">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="climb_rate">1</property>
@ -1301,7 +1299,7 @@
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
<property name="snap_to_ticks">False</property>
<property name="wrap">False</property>
<property name="adjustment">1 0 0 1 10 10</property>
<property name="adjustment">1 0 0 1 10 0</property>
</widget>
<packing>
<property name="left_attach">1</property>
@ -1477,30 +1475,67 @@
</child>
<child>
<widget class="GtkLabel" id="label_start_week">
<widget class="GtkHBox" id="hbox17">
<property name="visible">True</property>
<property name="label" translatable="yes">(Week 10)</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">3</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label26">
<property name="visible">True</property>
<property name="label" translatable="yes">Week</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_start_week">
<property name="visible">True</property>
<property name="label" translatable="yes">label14</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">3</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
<property name="y_options">fill</property>
</packing>
</child>
</widget>
@ -1555,6 +1590,7 @@
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_alr_cancel_clicked" last_modification_time="Thu, 06 Nov 2008 16:38:11 GMT"/>
<accelerator key="Escape" modifiers="0" signal="clicked"/>
</widget>
<packing>
<property name="padding">0</property>

View File

@ -168,7 +168,8 @@ typedef struct
*bets,
*splash,
*training_camp,
*league_table;
*league_table,
*alr;
/** The position of the horizontal divider is stored here. */
gint paned_pos;

View File

@ -1305,6 +1305,12 @@ void
on_automatic_loan_repayment_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
if(current_user.debt == 0)
{
game_gui_print_message(_("You are not in debt."));
return;
}
window_show_alr();
}

View File

@ -238,12 +238,17 @@ finance_pay_loan(gint value)
gint add = (gint)rint((gfloat)value / (gfloat)(-current_user.debt) *
(gfloat)const_int("int_finance_payback_weeks"));
if(value > -current_user.debt)
value = -current_user.debt;
current_user.money -= value;
current_user.debt += value;
if(current_user.debt == 0)
{
current_user.counters[COUNT_USER_LOAN] = -1;
current_user.alr_start_week = 0;
current_user.alr_weekly_installment = 0;
game_gui_print_message(_("You are free from debt."));
}
else

View File

@ -233,7 +233,8 @@ void
on_spinbutton_start_week_changed (GtkEditable *editable,
gpointer user_data)
{
gui_label_set_text_from_int(GTK_LABEL(lookup_widget(window.alr, "label_start_week")),
week + 1, FALSE);
}
@ -266,6 +267,15 @@ void
on_button_alr_cancel_clicked (GtkButton *button,
gpointer user_data)
{
window_destroy(&window.alr);
}
gboolean
on_window_alr_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
on_button_alr_cancel_clicked(NULL, NULL);
return TRUE;
}

View File

@ -110,3 +110,7 @@ on_button_alr_confirm_clicked (GtkButton *button,
void
on_button_alr_cancel_clicked (GtkButton *button,
gpointer user_data);
gboolean
on_window_alr_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data);

View File

@ -8,9 +8,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <stdio.h>
@ -517,8 +515,8 @@ create_window_alr (void)
GtkWidget *label18;
GtkObject *spinbutton_start_week_adj;
GtkWidget *spinbutton_start_week;
GtkObject *spinbutton_installment_adj;
GtkWidget *spinbutton_installment;
GtkObject *spinbutton_weekly_installment_adj;
GtkWidget *spinbutton_weekly_installment;
GtkWidget *button_calculate_start_week;
GtkWidget *alignment7;
GtkWidget *hbox16;
@ -529,11 +527,16 @@ create_window_alr (void)
GtkWidget *hbox15;
GtkWidget *image8;
GtkWidget *label20;
GtkWidget *hbox17;
GtkWidget *label26;
GtkWidget *label_start_week;
GtkWidget *hseparator6;
GtkWidget *hbox11;
GtkWidget *button_alr_confirm;
GtkWidget *button_alr_cancel;
GtkAccelGroup *accel_group;
accel_group = gtk_accel_group_new ();
window_alr = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window_alr), _("Automatic loan repayment"));
@ -615,17 +618,17 @@ create_window_alr (void)
gtk_misc_set_alignment (GTK_MISC (label18), 1, 0.5);
gtk_misc_set_padding (GTK_MISC (label18), 3, 0);
spinbutton_start_week_adj = gtk_adjustment_new (1, 0, 0, 1, 10, 10);
spinbutton_start_week_adj = gtk_adjustment_new (0, 0, 0, 1, 10, 0);
spinbutton_start_week = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_start_week_adj), 1, 0);
gtk_widget_show (spinbutton_start_week);
gtk_table_attach (GTK_TABLE (table1), spinbutton_start_week, 1, 2, 0, 1,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
spinbutton_installment_adj = gtk_adjustment_new (1, 0, 0, 1, 10, 10);
spinbutton_installment = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_installment_adj), 1, 0);
gtk_widget_show (spinbutton_installment);
gtk_table_attach (GTK_TABLE (table1), spinbutton_installment, 1, 2, 1, 2,
spinbutton_weekly_installment_adj = gtk_adjustment_new (1, 0, 0, 1, 10, 0);
spinbutton_weekly_installment = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_weekly_installment_adj), 1, 0);
gtk_widget_show (spinbutton_weekly_installment);
gtk_table_attach (GTK_TABLE (table1), spinbutton_weekly_installment, 1, 2, 1, 2,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
@ -673,11 +676,19 @@ create_window_alr (void)
gtk_widget_show (label20);
gtk_box_pack_start (GTK_BOX (hbox15), label20, FALSE, FALSE, 0);
label_start_week = gtk_label_new (_("(Week 10)"));
hbox17 = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox17);
gtk_table_attach (GTK_TABLE (table1), hbox17, 2, 3, 0, 1,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (GTK_FILL), 0, 0);
label26 = gtk_label_new (_("Week"));
gtk_widget_show (label26);
gtk_box_pack_start (GTK_BOX (hbox17), label26, FALSE, FALSE, 0);
label_start_week = gtk_label_new (_("label14"));
gtk_widget_show (label_start_week);
gtk_table_attach (GTK_TABLE (table1), label_start_week, 2, 3, 0, 1,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_box_pack_start (GTK_BOX (hbox17), label_start_week, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (label_start_week), 0, 0.5);
gtk_misc_set_padding (GTK_MISC (label_start_week), 3, 0);
@ -697,7 +708,13 @@ create_window_alr (void)
button_alr_cancel = gtk_button_new_from_stock ("gtk-cancel");
gtk_widget_show (button_alr_cancel);
gtk_box_pack_start (GTK_BOX (hbox11), button_alr_cancel, TRUE, TRUE, 0);
gtk_widget_add_accelerator (button_alr_cancel, "clicked", accel_group,
GDK_Escape, (GdkModifierType) 0,
GTK_ACCEL_VISIBLE);
g_signal_connect ((gpointer) window_alr, "delete_event",
G_CALLBACK (on_window_alr_delete_event),
NULL);
g_signal_connect ((gpointer) spinbutton_start_week, "changed",
G_CALLBACK (on_spinbutton_start_week_changed),
NULL);
@ -729,7 +746,7 @@ create_window_alr (void)
GLADE_HOOKUP_OBJECT (window_alr, label17, "label17");
GLADE_HOOKUP_OBJECT (window_alr, label18, "label18");
GLADE_HOOKUP_OBJECT (window_alr, spinbutton_start_week, "spinbutton_start_week");
GLADE_HOOKUP_OBJECT (window_alr, spinbutton_installment, "spinbutton_installment");
GLADE_HOOKUP_OBJECT (window_alr, spinbutton_weekly_installment, "spinbutton_weekly_installment");
GLADE_HOOKUP_OBJECT (window_alr, button_calculate_start_week, "button_calculate_start_week");
GLADE_HOOKUP_OBJECT (window_alr, alignment7, "alignment7");
GLADE_HOOKUP_OBJECT (window_alr, hbox16, "hbox16");
@ -740,12 +757,16 @@ create_window_alr (void)
GLADE_HOOKUP_OBJECT (window_alr, hbox15, "hbox15");
GLADE_HOOKUP_OBJECT (window_alr, image8, "image8");
GLADE_HOOKUP_OBJECT (window_alr, label20, "label20");
GLADE_HOOKUP_OBJECT (window_alr, hbox17, "hbox17");
GLADE_HOOKUP_OBJECT (window_alr, label26, "label26");
GLADE_HOOKUP_OBJECT (window_alr, label_start_week, "label_start_week");
GLADE_HOOKUP_OBJECT (window_alr, hseparator6, "hseparator6");
GLADE_HOOKUP_OBJECT (window_alr, hbox11, "hbox11");
GLADE_HOOKUP_OBJECT (window_alr, button_alr_confirm, "button_alr_confirm");
GLADE_HOOKUP_OBJECT (window_alr, button_alr_cancel, "button_alr_cancel");
gtk_window_add_accel_group (GTK_WINDOW (window_alr), accel_group);
return window_alr;
}

View File

@ -189,7 +189,9 @@ user_set_up_finances(User *user)
for(i=0; i<MON_IN_END;i++)
user->money_in[0][i] = user->money_in[1][i] = 0;
user->debt = 0;
user->debt =
user->alr_start_week =
user->alr_weekly_installment = 0;
user->money =
math_round_integer(user->tm->stadium.capacity *
math_rndi(const_int("int_initial_money_lower"),

View File

@ -168,6 +168,8 @@ typedef struct
money_out[2][MON_OUT_END];
/** Interest the debt was taken at. */
gfloat debt_interest;
/** Information about the automatic loan repayment. */
gint alr_start_week, alr_weekly_installment;
/** The user's scout and physio qualities.
@see #Quality */
gint scout, physio;

View File

@ -878,22 +878,30 @@ window_create(gint window_type)
window.splash = create_window_splash();
wind = window.splash;
break;
case WINDOW_TRAINING_CAMP:
if(window.training_camp != NULL)
g_warning("window_create: called on already existing window\n");
else
window.training_camp = create_window_training_camp();
wind = window.training_camp;
strcpy(buf, _("Training camp"));
break;
case WINDOW_LEAGUE_TABLE:
if(window.league_table != NULL)
g_warning("window_create: called on already existing window\n");
else
window.league_table = create_window_training_camp();
wind = window.league_table;
strcpy(buf, _("League table"));
break;
case WINDOW_TRAINING_CAMP:
if(window.training_camp != NULL)
g_warning("window_create: called on already existing window\n");
else
window.training_camp = create_window_training_camp();
wind = window.training_camp;
strcpy(buf, _("Training camp"));
break;
case WINDOW_LEAGUE_TABLE:
if(window.league_table != NULL)
g_warning("window_create: called on already existing window\n");
else
window.league_table = create_window_training_camp();
wind = window.league_table;
strcpy(buf, _("League table"));
break;
case WINDOW_ALR:
if(window.alr != NULL)
g_warning("window_create: called on already existing window\n");
else
window.alr = create_window_alr();
wind = window.alr;
strcpy(buf, _("Automatic loan repayment"));
break;
}
if(window_type != WINDOW_FILE_CHOOSER)
@ -1085,3 +1093,21 @@ window_show_league_table(void)
*/
}
/** Create and set up the debt repayment window. */
void
window_show_alr(void)
{
window_create(WINDOW_ALR);
gui_label_set_text_from_int(GTK_LABEL(lookup_widget(window.alr, "label_current_start_week")),
current_user.alr_start_week, FALSE);
gui_label_set_text_from_int(GTK_LABEL(lookup_widget(window.alr, "label_current_weekly_installment")),
current_user.alr_weekly_installment, FALSE);
gtk_spin_button_set_range(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week")),
1, current_user.counters[COUNT_USER_LOAN]);
gtk_spin_button_set_range(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment")),
0, -current_user.debt);
gui_label_set_text_from_int(GTK_LABEL(lookup_widget(window.alr, "label_start_week")),
week + 1, FALSE);
}

View File

@ -55,7 +55,8 @@ enum Windows
WINDOW_SPLASH,
WINDOW_END,
WINDOW_TRAINING_CAMP,
WINDOW_LEAGUE_TABLE
WINDOW_LEAGUE_TABLE,
WINDOW_ALR
};
void
@ -131,4 +132,7 @@ window_show_training_camp(void);
void
window_show_league_table(void);
void
window_show_alr(void);
#endif

View File

@ -43,6 +43,8 @@ enum
TAG_USER_MONEY,
TAG_USER_DEBT,
TAG_USER_DEBT_INTEREST,
TAG_USER_ALR_START_WEEK,
TAG_USER_ALR_WEEKLY_INSTALLMENT,
TAG_USER_MONEY_INS,
TAG_USER_MONEY_IN,
TAG_USER_MONEY_OUTS,
@ -165,6 +167,8 @@ xml_loadsave_users_end_element (GMarkupParseContext *context,
tag == TAG_USER_MONEY ||
tag == TAG_USER_DEBT ||
tag == TAG_USER_DEBT_INTEREST ||
tag == TAG_USER_ALR_START_WEEK ||
tag == TAG_USER_ALR_WEEKLY_INSTALLMENT ||
tag == TAG_USER_MONEY_INS ||
tag == TAG_USER_MONEY_OUTS ||
tag == TAG_USER_SCOUT ||
@ -272,6 +276,10 @@ xml_loadsave_users_text (GMarkupParseContext *context,
new_user.debt = int_value;
else if(state == TAG_USER_DEBT_INTEREST)
new_user.debt_interest = float_value;
else if(state == TAG_USER_ALR_START_WEEK)
new_user.alr_start_week = int_value;
else if(state == TAG_USER_ALR_WEEKLY_INSTALLMENT)
new_user.alr_weekly_installment = int_value;
else if(state == TAG_USER_SCOUT)
new_user.scout = int_value;
else if(state == TAG_USER_PHYSIO)
@ -397,6 +405,8 @@ xml_loadsave_users_write(const gchar *prefix)
xml_write_int(fil, usr(i).money, TAG_USER_MONEY, I1);
xml_write_int(fil, usr(i).debt, TAG_USER_DEBT, I1);
xml_write_float(fil, usr(i).debt_interest, TAG_USER_DEBT_INTEREST, I1);
xml_write_int(fil, usr(i).alr_start_week, TAG_USER_ALR_START_WEEK, I1);
xml_write_int(fil, usr(i).alr_weekly_installment, TAG_USER_ALR_WEEKLY_INSTALLMENT, I1);
xml_write_int(fil, usr(i).scout, TAG_USER_SCOUT, I1);
xml_write_int(fil, usr(i).physio, TAG_USER_PHYSIO, I1);