Automatic loan repayment.

This commit is contained in:
gyboth 2008-11-08 12:46:12 +00:00
parent 0c61e64b26
commit e8c1260cf6
14 changed files with 240 additions and 75 deletions

View File

@ -20,7 +20,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_job_offer_delete_event" last_modification_time="Sun, 15 May 2005 14:52:33 GMT"/> <signal name="delete_event" handler="on_window_job_offer_delete_event" last_modification_time="Sun, 15 May 2005 14:52:33 GMT"/>
<child> <child>
@ -718,7 +717,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_SPLASHSCREEN</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_SPLASHSCREEN</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<child> <child>
<widget class="GtkVBox" id="vbox28"> <widget class="GtkVBox" id="vbox28">
@ -776,7 +774,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_button_warning_clicked" last_modification_time="Sat, 05 Mar 2005 19:16:17 GMT"/> <signal name="delete_event" handler="on_button_warning_clicked" last_modification_time="Sat, 05 Mar 2005 19:16:17 GMT"/>
<signal name="destroy_event" handler="on_button_warning_clicked" last_modification_time="Sat, 05 Mar 2005 19:16:28 GMT"/> <signal name="destroy_event" handler="on_button_warning_clicked" last_modification_time="Sat, 05 Mar 2005 19:16:28 GMT"/>
@ -863,7 +860,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_digits_delete_event" last_modification_time="Sun, 15 May 2005 14:52:21 GMT"/> <signal name="delete_event" handler="on_window_digits_delete_event" last_modification_time="Sun, 15 May 2005 14:52:21 GMT"/>
<child> <child>
@ -1027,7 +1023,19 @@
</child> </child>
<child> <child>
<widget class="GtkHBox" id="hbox16"> <widget class="GtkHSeparator" id="hseparator10">
<property name="height_request">10</property>
<property name="visible">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox29">
<property name="visible">True</property> <property name="visible">True</property>
<property name="homogeneous">False</property> <property name="homogeneous">False</property>
<property name="spacing">3</property> <property name="spacing">3</property>
@ -1044,8 +1052,86 @@
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>
<property name="expand">True</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_digits_alr">
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_digits_alr_clicked" last_modification_time="Sat, 08 Nov 2008 12:17:54 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment16">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox38">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image23">
<property name="visible">True</property>
<property name="stock">gtk-jump-to</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">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="label63">
<property name="visible">True</property>
<property name="label" translatable="yes">Confirm &amp; schedule repayment</property>
<property name="use_underline">True</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>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing> </packing>
</child> </child>
@ -1063,15 +1149,15 @@
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>
<property name="expand">True</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">False</property>
</packing> </packing>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">False</property>
</packing> </packing>
</child> </child>
</widget> </widget>
@ -1093,7 +1179,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_yesno_delete_event" last_modification_time="Sun, 20 Mar 2005 19:14:01 GMT"/> <signal name="delete_event" handler="on_window_yesno_delete_event" last_modification_time="Sun, 20 Mar 2005 19:14:01 GMT"/>
<child> <child>
@ -1211,7 +1296,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_contract_delete_event" last_modification_time="Fri, 25 Mar 2005 19:18:36 GMT"/> <signal name="delete_event" handler="on_window_contract_delete_event" last_modification_time="Fri, 25 Mar 2005 19:18:36 GMT"/>
<child> <child>
@ -1595,7 +1679,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_user_management_delete_event" last_modification_time="Sun, 15 May 2005 14:52:50 GMT"/> <signal name="delete_event" handler="on_window_user_management_delete_event" last_modification_time="Sun, 15 May 2005 14:52:50 GMT"/>
<child> <child>
@ -1934,7 +2017,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_debug_delete_event" last_modification_time="Fri, 13 May 2005 16:56:52 GMT"/> <signal name="delete_event" handler="on_window_debug_delete_event" last_modification_time="Fri, 13 May 2005 16:56:52 GMT"/>
<child> <child>
@ -2056,7 +2138,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_help_delete_event" last_modification_time="Sat, 21 May 2005 19:25:09 GMT"/> <signal name="delete_event" handler="on_window_help_delete_event" last_modification_time="Sat, 21 May 2005 19:25:09 GMT"/>
<child> <child>
@ -2351,7 +2432,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_transfer_dialog_delete_event" last_modification_time="Mon, 30 May 2005 14:25:43 GMT"/> <signal name="delete_event" handler="on_window_transfer_dialog_delete_event" last_modification_time="Mon, 30 May 2005 14:25:43 GMT"/>
<child> <child>
@ -2552,7 +2632,6 @@
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property> <property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_mmatches_delete_event" last_modification_time="Fri, 19 Aug 2005 10:35:08 GMT"/> <signal name="delete_event" handler="on_window_mmatches_delete_event" last_modification_time="Fri, 19 Aug 2005 10:35:08 GMT"/>
<child> <child>

View File

@ -1208,8 +1208,8 @@
<property name="n_rows">2</property> <property name="n_rows">2</property>
<property name="n_columns">3</property> <property name="n_columns">3</property>
<property name="homogeneous">False</property> <property name="homogeneous">False</property>
<property name="row_spacing">2</property> <property name="row_spacing">5</property>
<property name="column_spacing">2</property> <property name="column_spacing">10</property>
<child> <child>
<widget class="GtkLabel" id="label17"> <widget class="GtkLabel" id="label17">

View File

@ -332,7 +332,7 @@ callback_get_loan(void)
misc_print_grouped_int(max_loan, buf2); misc_print_grouped_int(max_loan, buf2);
sprintf(buf, _("You can take out at most %s."), buf2); sprintf(buf, _("You can take out at most %s."), buf2);
window_show_digits(buf, _("Loan"), max_loan, NULL, 0); window_show_digits(buf, _("Loan"), max_loan, NULL, 0, TRUE);
} }
/** Open the digits window to pay back a loan. */ /** Open the digits window to pay back a loan. */
@ -358,7 +358,7 @@ callback_pay_loan(void)
misc_print_grouped_int(max_payback, buf2); misc_print_grouped_int(max_payback, buf2);
sprintf(buf, _("You can pay back at most %s"), buf2); sprintf(buf, _("You can pay back at most %s"), buf2);
window_show_digits(buf, _("Payback"), max_payback, NULL, 0); window_show_digits(buf, _("Payback"), max_payback, NULL, 0, FALSE);
} }
/** Manage a click on a player of the current team on the /** Manage a click on a player of the current team on the
@ -494,14 +494,14 @@ callback_transfer_list_clicked(gint button, gint idx)
player_of_id_team(tr->tm, tr->id)->name); player_of_id_team(tr->tm, tr->id)->name);
window_show_digits(buf, _("Fee"), tr->fee[current_user.scout % 10], window_show_digits(buf, _("Fee"), tr->fee[current_user.scout % 10],
_("Wage"), tr->wage[current_user.scout % 10]); _("Wage"), tr->wage[current_user.scout % 10], FALSE);
} }
else else
{ {
sprintf(buf, _("You are making an offer for %s again. Your previous values for fee and wage are preset."), sprintf(buf, _("You are making an offer for %s again. Your previous values for fee and wage are preset."),
player_of_id_team(tr->tm, tr->id)->name); player_of_id_team(tr->tm, tr->id)->name);
window_show_digits(buf, _("Fee"), old_fee, _("Wage"), old_wage); window_show_digits(buf, _("Fee"), old_fee, _("Wage"), old_wage, FALSE);
} }
} }

View File

@ -749,7 +749,7 @@ on_menu_custom_structure_activate (GtkMenuItem *menuitem,
{ {
stat1 = STATUS_CUSTOM_STRUCTURE; stat1 = STATUS_CUSTOM_STRUCTURE;
window_show_digits(_("Enter a structure. The digits must sum up to 10."), window_show_digits(_("Enter a structure. The digits must sum up to 10."),
NULL, -1, _("Structure"), current_user.tm->structure); NULL, -1, _("Structure"), current_user.tm->structure, FALSE);
} }
@ -1152,7 +1152,7 @@ on_menu_set_investment_activate (GtkMenuItem *menuitem,
stat1 = STATUS_SET_YA_PERCENTAGE; stat1 = STATUS_SET_YA_PERCENTAGE;
window_show_digits( window_show_digits(
_("Set the percentage of your income you want to devote to your youth academy."), _("Set the percentage of your income you want to devote to your youth academy."),
NULL, -1, "%", current_user.youth_academy.percentage); NULL, -1, "%", current_user.youth_academy.percentage, FALSE);
} }
void void

View File

@ -124,6 +124,16 @@ finance_update_user_weekly(User *user)
user->debt = (gint)rint((gfloat)user->debt * (1 + user->debt_interest)); user->debt = (gint)rint((gfloat)user->debt * (1 + user->debt_interest));
if(user->alr_start_week != 0 && week >= user->alr_start_week)
{
finance_pay_loan(user, user->alr_weekly_installment);
if(user->debt == 0)
{
user->alr_start_week =
user->alr_weekly_installment = 0;
}
}
if(user->money < -finance_team_drawing_credit_loan(user->tm, FALSE) && if(user->money < -finance_team_drawing_credit_loan(user->tm, FALSE) &&
user->counters[COUNT_USER_POSITIVE] == -1 && debug < 50) user->counters[COUNT_USER_POSITIVE] == -1 && debug < 50)
{ {
@ -143,7 +153,7 @@ finance_update_user_weekly(User *user)
if(user->counters[COUNT_USER_LOAN] > -1) if(user->counters[COUNT_USER_LOAN] > -1)
user->counters[COUNT_USER_LOAN]--; user->counters[COUNT_USER_LOAN]--;
if(user->counters[COUNT_USER_LOAN] == 0 && debug < 50) if(user->counters[COUNT_USER_LOAN] == 0 && debug < 50 && user->alr_start_week == 0)
user_event_add(user, EVENT_TYPE_WARNING, -1, -1, NULL, user_event_add(user, EVENT_TYPE_WARNING, -1, -1, NULL,
_("You have to pay back your loan this week.")); _("You have to pay back your loan this week."));
@ -226,42 +236,38 @@ finance_get_loan(gint value)
game_gui_print_message(_("You have %d weeks to pay back your loan."), game_gui_print_message(_("You have %d weeks to pay back your loan."),
current_user.counters[COUNT_USER_LOAN]); current_user.counters[COUNT_USER_LOAN]);
on_menu_show_finances_activate(NULL, NULL);
} }
/** Pay back some loan for the current user. /** Pay back some loan for the specified user.
@param value The amount of money paid back. */ @param value The amount of money paid back. */
void void
finance_pay_loan(gint value) finance_pay_loan(User *user, gint value)
{ {
gint add = (gint)rint((gfloat)value / (gfloat)(-current_user.debt) * gint add = (gint)rint((gfloat)value / (gfloat)(-user->debt) *
(gfloat)const_int("int_finance_payback_weeks")); (gfloat)const_int("int_finance_payback_weeks"));
if(value > -current_user.debt) if(value > -user->debt)
value = -current_user.debt; value = -user->debt;
current_user.money -= value; user->money -= value;
current_user.debt += value; user->debt += value;
if(current_user.debt == 0) if(user->debt == 0)
{ {
current_user.counters[COUNT_USER_LOAN] = -1; user->counters[COUNT_USER_LOAN] = -1;
current_user.alr_start_week = 0; user->alr_start_week = 0;
current_user.alr_weekly_installment = 0; user->alr_weekly_installment = 0;
game_gui_print_message(_("You are free from debt.")); game_gui_print_message(_("You are free from debt."));
} }
else else
{ {
current_user.counters[COUNT_USER_LOAN] = user->counters[COUNT_USER_LOAN] =
MIN(current_user.counters[COUNT_USER_LOAN] + add, MIN(user->counters[COUNT_USER_LOAN] + add,
const_int("int_finance_payback_weeks")); const_int("int_finance_payback_weeks"));
game_gui_print_message(_("You have %d weeks to pay back the rest of your loan."), game_gui_print_message(_("You have %d weeks to pay back the rest of your loan."),
current_user.counters[COUNT_USER_LOAN]); user->counters[COUNT_USER_LOAN]);
} }
on_menu_show_finances_activate(NULL, NULL);
} }
/** Return the cost of a stadium improvement. /** Return the cost of a stadium improvement.
@ -396,21 +402,21 @@ finance_update_current_interest(void)
gint gint
finance_calculate_alr_weekly_installment(gint start_week) finance_calculate_alr_weekly_installment(gint start_week)
{ {
gfloat debt_start; gfloat debt_end;
gfloat interest_factor; gfloat interest_factor;
gfloat max_start_week;
gfloat installment; gfloat installment;
gint weekly_installment; gint weekly_installment;
debt_start = current_user.debt * powf(1 + current_user.debt_interest, (gfloat)(start_week - week)); max_start_week = MIN(week + current_user.counters[COUNT_USER_LOAN], fixture_get_last_scheduled_week());
interest_factor = 1 / debt_end = current_user.debt * powf(1 + current_user.debt_interest, max_start_week - 1);
powf(1 + current_user.debt_interest, (gfloat)(const_int("int_finance_payback_weeks") - start_week + week + 1)) / interest_factor =
(powf(1 + current_user.debt_interest, (gfloat)(max_start_week - start_week + 1)) - 1) /
current_user.debt_interest; current_user.debt_interest;
installment = -debt_start / (1 / current_user.debt_interest - interest_factor + 1); installment = -debt_end / interest_factor;
weekly_installment = (gint)rint(installment); weekly_installment = (gint)rint(installment);
printf("start %.2f intfac %.2f inst %.2f winst %d\n", debt_start, interest_factor, installment, weekly_installment);
return (weekly_installment > installment) ? weekly_installment : weekly_installment + 1; return (weekly_installment > installment) ? weekly_installment : weekly_installment + 1;
} }
@ -423,14 +429,16 @@ finance_calculate_alr_start_week(gint weekly_installment)
gint start_week; gint start_week;
gint installment; gint installment;
upper = MIN(week + current_user.counters[COUNT_USER_LOAN] - 1, fixture_get_last_scheduled_week()); upper = MIN(week + current_user.counters[COUNT_USER_LOAN], fixture_get_last_scheduled_week());
for(start_week = week + 1; start_week <= upper; start_week++) for(start_week = week + 1; start_week <= upper; start_week++)
{ {
installment = finance_calculate_alr_weekly_installment(start_week); installment = finance_calculate_alr_weekly_installment(start_week);
if(installment > weekly_installment) if(installment > weekly_installment)
return start_week - 1; return start_week - 1;
else if(installment == weekly_installment)
return start_week;
} }
return start_week - 1; return start_week;
} }

View File

@ -42,7 +42,7 @@ gint
finance_team_drawing_credit_loan(const Team *tm, gboolean loan); finance_team_drawing_credit_loan(const Team *tm, gboolean loan);
void void
finance_pay_loan(gint value); finance_pay_loan(User *user, gint value);
void void
finance_get_loan(gint value); finance_get_loan(gint value);

View File

@ -137,9 +137,11 @@ on_button_digits_ok_clicked (GtkButton *button,
{ {
case STATUS_GET_LOAN: case STATUS_GET_LOAN:
finance_get_loan(values[0]); finance_get_loan(values[0]);
on_menu_show_finances_activate(NULL, NULL);
break; break;
case STATUS_PAY_LOAN: case STATUS_PAY_LOAN:
finance_pay_loan(values[0]); finance_pay_loan(&current_user, values[0]);
on_menu_show_finances_activate(NULL, NULL);
break; break;
case STATUS_SHOW_TRANSFER_LIST: case STATUS_SHOW_TRANSFER_LIST:
if(transfer_add_offer(stat2, current_user.tm, values[0], values[1])) if(transfer_add_offer(stat2, current_user.tm, values[0], values[1]))
@ -170,6 +172,14 @@ on_button_digits_ok_clicked (GtkButton *button,
} }
void
on_button_digits_alr_clicked (GtkButton *button,
gpointer user_data)
{
on_button_digits_ok_clicked(NULL, NULL);
on_automatic_loan_repayment_activate(NULL, NULL);
}
void void
on_button_digits_cancel_clicked (GtkButton *button, on_button_digits_cancel_clicked (GtkButton *button,
gpointer user_data) gpointer user_data)
@ -618,3 +628,4 @@ on_button_mm_import_clicked (GtkButton *button,
window_show_file_sel(); window_show_file_sel();
} }

View File

@ -204,4 +204,8 @@ on_button_mm_reload_close_clicked (GtkButton *button,
void void
on_button_mm_import_clicked (GtkButton *button, on_button_mm_import_clicked (GtkButton *button,
gpointer user_data); gpointer user_data);
void
on_button_digits_alr_clicked (GtkButton *button,
gpointer user_data);
#endif #endif

View File

@ -381,8 +381,14 @@ create_window_digits (void)
GtkWidget *label_2; GtkWidget *label_2;
GtkObject *spinbutton2_adj; GtkObject *spinbutton2_adj;
GtkWidget *spinbutton2; GtkWidget *spinbutton2;
GtkWidget *hbox16; GtkWidget *hseparator10;
GtkWidget *vbox29;
GtkWidget *button_digits_ok; GtkWidget *button_digits_ok;
GtkWidget *button_digits_alr;
GtkWidget *alignment16;
GtkWidget *hbox38;
GtkWidget *image23;
GtkWidget *label63;
GtkWidget *button_digits_cancel; GtkWidget *button_digits_cancel;
GtkAccelGroup *accel_group; GtkAccelGroup *accel_group;
GtkTooltips *tooltips; GtkTooltips *tooltips;
@ -437,17 +443,41 @@ create_window_digits (void)
gtk_box_pack_start (GTK_BOX (vbox16), spinbutton2, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox16), spinbutton2, FALSE, FALSE, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton2), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton2), TRUE);
hbox16 = gtk_hbox_new (FALSE, 3); hseparator10 = gtk_hseparator_new ();
gtk_widget_show (hbox16); gtk_widget_show (hseparator10);
gtk_box_pack_start (GTK_BOX (vbox14), hbox16, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox14), hseparator10, FALSE, FALSE, 0);
gtk_widget_set_size_request (hseparator10, -1, 10);
vbox29 = gtk_vbox_new (FALSE, 3);
gtk_widget_show (vbox29);
gtk_box_pack_start (GTK_BOX (vbox14), vbox29, TRUE, FALSE, 0);
button_digits_ok = gtk_button_new_from_stock ("gtk-ok"); button_digits_ok = gtk_button_new_from_stock ("gtk-ok");
gtk_widget_show (button_digits_ok); gtk_widget_show (button_digits_ok);
gtk_box_pack_start (GTK_BOX (hbox16), button_digits_ok, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox29), button_digits_ok, FALSE, FALSE, 0);
button_digits_alr = gtk_button_new ();
gtk_box_pack_start (GTK_BOX (vbox29), button_digits_alr, FALSE, FALSE, 0);
alignment16 = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_widget_show (alignment16);
gtk_container_add (GTK_CONTAINER (button_digits_alr), alignment16);
hbox38 = gtk_hbox_new (FALSE, 2);
gtk_widget_show (hbox38);
gtk_container_add (GTK_CONTAINER (alignment16), hbox38);
image23 = gtk_image_new_from_stock ("gtk-jump-to", GTK_ICON_SIZE_BUTTON);
gtk_widget_show (image23);
gtk_box_pack_start (GTK_BOX (hbox38), image23, FALSE, FALSE, 0);
label63 = gtk_label_new_with_mnemonic (_("Confirm & schedule repayment"));
gtk_widget_show (label63);
gtk_box_pack_start (GTK_BOX (hbox38), label63, FALSE, FALSE, 0);
button_digits_cancel = gtk_button_new_from_stock ("gtk-cancel"); button_digits_cancel = gtk_button_new_from_stock ("gtk-cancel");
gtk_widget_show (button_digits_cancel); gtk_widget_show (button_digits_cancel);
gtk_box_pack_start (GTK_BOX (hbox16), button_digits_cancel, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox29), button_digits_cancel, FALSE, FALSE, 0);
gtk_tooltips_set_tip (tooltips, button_digits_cancel, _("Esc"), NULL); gtk_tooltips_set_tip (tooltips, button_digits_cancel, _("Esc"), NULL);
gtk_widget_add_accelerator (button_digits_cancel, "clicked", accel_group, gtk_widget_add_accelerator (button_digits_cancel, "clicked", accel_group,
GDK_Escape, (GdkModifierType) 0, GDK_Escape, (GdkModifierType) 0,
@ -465,6 +495,9 @@ create_window_digits (void)
g_signal_connect ((gpointer) button_digits_ok, "clicked", g_signal_connect ((gpointer) button_digits_ok, "clicked",
G_CALLBACK (on_button_digits_ok_clicked), G_CALLBACK (on_button_digits_ok_clicked),
NULL); NULL);
g_signal_connect ((gpointer) button_digits_alr, "clicked",
G_CALLBACK (on_button_digits_alr_clicked),
NULL);
g_signal_connect ((gpointer) button_digits_cancel, "clicked", g_signal_connect ((gpointer) button_digits_cancel, "clicked",
G_CALLBACK (on_button_digits_cancel_clicked), G_CALLBACK (on_button_digits_cancel_clicked),
NULL); NULL);
@ -480,8 +513,14 @@ create_window_digits (void)
GLADE_HOOKUP_OBJECT (window_digits, vbox16, "vbox16"); GLADE_HOOKUP_OBJECT (window_digits, vbox16, "vbox16");
GLADE_HOOKUP_OBJECT (window_digits, label_2, "label_2"); GLADE_HOOKUP_OBJECT (window_digits, label_2, "label_2");
GLADE_HOOKUP_OBJECT (window_digits, spinbutton2, "spinbutton2"); GLADE_HOOKUP_OBJECT (window_digits, spinbutton2, "spinbutton2");
GLADE_HOOKUP_OBJECT (window_digits, hbox16, "hbox16"); GLADE_HOOKUP_OBJECT (window_digits, hseparator10, "hseparator10");
GLADE_HOOKUP_OBJECT (window_digits, vbox29, "vbox29");
GLADE_HOOKUP_OBJECT (window_digits, button_digits_ok, "button_digits_ok"); GLADE_HOOKUP_OBJECT (window_digits, button_digits_ok, "button_digits_ok");
GLADE_HOOKUP_OBJECT (window_digits, button_digits_alr, "button_digits_alr");
GLADE_HOOKUP_OBJECT (window_digits, alignment16, "alignment16");
GLADE_HOOKUP_OBJECT (window_digits, hbox38, "hbox38");
GLADE_HOOKUP_OBJECT (window_digits, image23, "image23");
GLADE_HOOKUP_OBJECT (window_digits, label63, "label63");
GLADE_HOOKUP_OBJECT (window_digits, button_digits_cancel, "button_digits_cancel"); GLADE_HOOKUP_OBJECT (window_digits, button_digits_cancel, "button_digits_cancel");
GLADE_HOOKUP_OBJECT_NO_REF (window_digits, tooltips, "tooltips"); GLADE_HOOKUP_OBJECT_NO_REF (window_digits, tooltips, "tooltips");

View File

@ -24,8 +24,10 @@
*/ */
#include "bet.h" #include "bet.h"
#include "callbacks.h"
#include "finance.h" #include "finance.h"
#include "fixture.h" #include "fixture.h"
#include "game_gui.h"
#include "gui.h" #include "gui.h"
#include "main.h" #include "main.h"
#include "misc_callback_func.h" #include "misc_callback_func.h"
@ -137,7 +139,7 @@ on_treeview_bets_button_press_event (GtkWidget *widget,
stat3 = col_num - 1; stat3 = col_num - 1;
/* 'Wager' is the amount of money the user placed on a bet. */ /* 'Wager' is the amount of money the user placed on a bet. */
window_show_digits(buf, _("Wager"), 0, NULL, -1); window_show_digits(buf, _("Wager"), 0, NULL, -1, FALSE);
spin_wager = GTK_SPIN_BUTTON(lookup_widget(window.digits, "spinbutton1")); spin_wager = GTK_SPIN_BUTTON(lookup_widget(window.digits, "spinbutton1"));
gtk_spin_button_set_range(spin_wager, 0, gtk_spin_button_set_range(spin_wager, 0,
(gdouble)const_int("int_bet_wager_max")); (gdouble)const_int("int_bet_wager_max"));
@ -240,8 +242,6 @@ on_button_calculate_start_week_clicked (GtkButton *button,
start_week = finance_calculate_alr_start_week( start_week = finance_calculate_alr_start_week(
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment")))); gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment"))));
printf("startweek %d\n", start_week);
gtk_spin_button_set_value( gtk_spin_button_set_value(
GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week")), (gfloat)start_week); GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week")), (gfloat)start_week);
} }
@ -257,8 +257,6 @@ on_button_calculate_installment_clicked
weekly_installment = finance_calculate_alr_weekly_installment( weekly_installment = finance_calculate_alr_weekly_installment(
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week")))); gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week"))));
printf("inst %d\n", weekly_installment);
gtk_spin_button_set_value( gtk_spin_button_set_value(
GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment")), (gfloat)weekly_installment); GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment")), (gfloat)weekly_installment);
} }
@ -268,7 +266,17 @@ void
on_button_alr_confirm_clicked (GtkButton *button, on_button_alr_confirm_clicked (GtkButton *button,
gpointer user_data) gpointer user_data)
{ {
current_user.alr_start_week =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week")));
current_user.alr_weekly_installment =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment")));
window_destroy(&window.alr);
setsav0;
on_menu_show_finances_activate(NULL, NULL);
} }

View File

@ -596,8 +596,8 @@ create_window_alr (void)
table1 = gtk_table_new (2, 3, FALSE); table1 = gtk_table_new (2, 3, FALSE);
gtk_widget_show (table1); gtk_widget_show (table1);
gtk_box_pack_start (GTK_BOX (vbox5), table1, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox5), table1, FALSE, FALSE, 0);
gtk_table_set_row_spacings (GTK_TABLE (table1), 2); gtk_table_set_row_spacings (GTK_TABLE (table1), 5);
gtk_table_set_col_spacings (GTK_TABLE (table1), 2); gtk_table_set_col_spacings (GTK_TABLE (table1), 10);
label17 = gtk_label_new (_("Start in week")); label17 = gtk_label_new (_("Start in week"));
gtk_widget_show (label17); gtk_widget_show (label17);

View File

@ -1489,6 +1489,19 @@ treeview_create_finances(const User* user)
gtk_list_store_set(ls, &iter, 0, buf, 1, "", 2, buf2, -1); gtk_list_store_set(ls, &iter, 0, buf, 1, "", 2, buf2, -1);
} }
if(user->alr_start_week != 0)
{
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, _("Automatic repayment"), 1, "", 2, "", -1);
misc_print_grouped_int(user->alr_weekly_installment, buf);
sprintf(buf2, "<span foreground='%s'>%s</span>",
const_app("string_treeview_finances_expenses_fg"), buf);
sprintf(buf, _("(from week %d)"), user->alr_start_week);
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, buf, 1, "", 2, buf2, -1);
}
gtk_list_store_append(ls, &iter); gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, "", 1, "", 2, "", -1); gtk_list_store_set(ls, &iter, 0, "", 1, "", 2, "", -1);

View File

@ -461,7 +461,7 @@ window_show_menu_youth(GdkEvent *event)
according to the arguments. */ according to the arguments. */
void void
window_show_digits(const gchar *text_main, const gchar* text1, gint value1, window_show_digits(const gchar *text_main, const gchar* text1, gint value1,
const gchar* text2, gint value2) const gchar* text2, gint value2, gboolean show_alr)
{ {
GtkLabel *label_main, *label_1, *label_2; GtkLabel *label_main, *label_1, *label_2;
GtkSpinButton *spinbutton1, *spinbutton2; GtkSpinButton *spinbutton1, *spinbutton2;
@ -496,6 +496,9 @@ window_show_digits(const gchar *text_main, const gchar* text1, gint value1,
gtk_label_set_text(label_2, text2); gtk_label_set_text(label_2, text2);
else else
gtk_widget_hide(GTK_WIDGET(label_2)->parent); gtk_widget_hide(GTK_WIDGET(label_2)->parent);
if(show_alr)
gtk_widget_show(lookup_widget(window.digits, "button_digits_alr"));
} }
/** Show the stadium window for the current user. */ /** Show the stadium window for the current user. */
@ -1022,7 +1025,7 @@ window_show_alr(void)
gui_label_set_text_from_int(GTK_LABEL(lookup_widget(window.alr, "label_current_weekly_installment")), gui_label_set_text_from_int(GTK_LABEL(lookup_widget(window.alr, "label_current_weekly_installment")),
current_user.alr_weekly_installment, FALSE); current_user.alr_weekly_installment, FALSE);
gtk_spin_button_set_range(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week")), gtk_spin_button_set_range(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_start_week")),
week + 1, MIN(week + current_user.counters[COUNT_USER_LOAN] - 1, fixture_get_last_scheduled_week())); week + 1, MIN(week + current_user.counters[COUNT_USER_LOAN], fixture_get_last_scheduled_week()));
gtk_spin_button_set_range(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment")), gtk_spin_button_set_range(GTK_SPIN_BUTTON(lookup_widget(window.alr, "spinbutton_weekly_installment")),
0, -current_user.debt * powf(1 + current_user.debt_interest, const_int("int_finance_payback_weeks"))); 0, -current_user.debt * powf(1 + current_user.debt_interest, const_int("int_finance_payback_weeks")) + 1);
} }

View File

@ -72,7 +72,7 @@ window_destroy(GtkWidget **wind);
void void
window_show_digits(const gchar *text_main, const gchar* text1, window_show_digits(const gchar *text_main, const gchar* text1,
gint value1, const gchar* text2, gint value2); gint value1, const gchar* text2, gint value2, gboolean show_alr);
void void
window_show_file_sel(void); window_show_file_sel(void);