Skip to content

Commit

Permalink
FIX: depot display of large money values
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@6294 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
TurfIt committed Jan 20, 2013
1 parent b775e2e commit dae2f9a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 26 deletions.
13 changes: 7 additions & 6 deletions gui/convoi_detail_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ void convoi_detail_t::zeichnen(koord pos, koord gr)
display_proportional_clip( pos.x+10, offset_y, buf, ALIGN_LEFT, COL_BLACK, true );
offset_y += LINESPACE;

money_to_string( number, cnv->calc_restwert()/100.0 );
money_to_string( number, cnv->calc_restwert() / 100.0 );
buf.clear();
buf.printf("%s %s", translator::translate("Restwert:"), number );
display_proportional_clip( pos.x+10, offset_y, buf, ALIGN_LEFT, MONEY_PLUS, true );
offset_y += LINESPACE;

money_to_string( number, cnv->calc_restwert()/100.0 );
money_to_string( number, cnv->calc_restwert() / 100.0 );
buf.clear();
buf.printf(translator::translate("Bonusspeed: %i km/h"), cnv->get_speedbonus_kmh() );
display_proportional_clip( pos.x+10, offset_y, buf, ALIGN_LEFT, COL_BLACK, true );
Expand Down Expand Up @@ -272,15 +272,16 @@ void gui_vehicleinfo_t::zeichnen(koord offset)
extra_y += LINESPACE;

// age
sint32 month = v->get_insta_zeit();
buf.clear();
buf.printf( "%s %s %i", translator::translate("Manufactured:"), translator::get_month_name(month%12), month/12 );
{
const sint32 month = v->get_insta_zeit();
buf.printf( "%s %s %i", translator::translate("Manufactured:"), translator::get_month_name(month%12), month/12 );
}
display_proportional_clip( pos.x+w+offset.x, pos.y+offset.y+total_height+extra_y, buf, ALIGN_LEFT, COL_BLACK, true );
extra_y += LINESPACE;

// value
sint32 current = v->calc_restwert();
money_to_string( number, current/100.0 );
money_to_string( number, v->calc_restwert() / 100.0 );
buf.clear();
buf.printf( "%s %s", translator::translate("Restwert:"), number );
display_proportional_clip( pos.x+w+offset.x, pos.y+offset.y+total_height+extra_y, buf, ALIGN_LEFT, MONEY_PLUS, true );
Expand Down
35 changes: 23 additions & 12 deletions gui/depot_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ void depot_frame_t::update_data()
}


sint32 depot_frame_t::calc_restwert(const vehikel_besch_t *veh_type)
sint64 depot_frame_t::calc_restwert(const vehikel_besch_t *veh_type)
{
sint32 wert = 0;
sint64 wert = 0;
FOR(slist_tpl<vehikel_t*>, const v, depot->get_vehicle_list()) {
if( v->get_besch() == veh_type ) {
wert += v->calc_restwert();
Expand Down Expand Up @@ -1317,11 +1317,16 @@ void depot_frame_t::zeichnen(koord pos, koord groesse)
convoi_length_too_slow_sb = 0;
}

txt_convoi_value.clear();
txt_convoi_value.printf("%s %6ld$", translator::translate("Restwert:"), (long)(cnv->calc_restwert() / 100) );
{
char buf[128];
txt_convoi_value.clear();
money_to_string( buf, cnv->calc_restwert() / 100.0, false );
txt_convoi_value.printf("%s %8s", translator::translate("Restwert:"), buf );

txt_convoi_cost.clear();
txt_convoi_cost.printf( translator::translate("Cost: %6d$ (%.2f$/km)\n"), cnv->get_purchase_cost() / 100, (double)cnv->get_running_cost() / 100.0 );
txt_convoi_cost.clear();
money_to_string( buf, cnv->get_purchase_cost() / 100.0, false );
txt_convoi_cost.printf( translator::translate("Cost: %8s (%.2f$/km)\n"), buf, (double)cnv->get_running_cost() / 100.0 );
}

txt_convoi_power.clear();
txt_convoi_power.printf( translator::translate("Power: %4d kW\n"), cnv->get_sum_leistung() );
Expand Down Expand Up @@ -1443,7 +1448,7 @@ void depot_frame_t::draw_vehicle_info_text(koord pos)
&waggons;
int x = get_maus_x();
int y = get_maus_y();
long resale_value = -1;
double resale_value = -1.0;
const vehikel_besch_t *veh_type = NULL;
bool new_vehicle_length_sb_force_zero = false;
koord relpos = koord( 0, ((gui_scrollpane_t *)tabs.get_aktives_tab())->get_scroll_y() );
Expand All @@ -1458,7 +1463,7 @@ void depot_frame_t::draw_vehicle_info_text(koord pos)
new_vehicle_length_sb_force_zero = true;
}
if( vec[sel_index].count > 0 ) {
resale_value = calc_restwert( veh_type ) / 100;
resale_value = calc_restwert( veh_type );
}
}
else {
Expand All @@ -1467,7 +1472,7 @@ void depot_frame_t::draw_vehicle_info_text(koord pos)
if( sel_index != -1 ) {
convoihandle_t cnv = depot->get_convoi( icnv );
veh_type = cnv->get_vehikel( sel_index )->get_besch();
resale_value = cnv->get_vehikel( sel_index )->calc_restwert() / 100;
resale_value = cnv->get_vehikel( sel_index )->calc_restwert();
new_vehicle_length_sb_force_zero = true;
}
}
Expand Down Expand Up @@ -1503,7 +1508,11 @@ void depot_frame_t::draw_vehicle_info_text(koord pos)
n += sprintf( buf + n, "\n");
}

n += sprintf( buf + n, translator::translate("Cost: %6d$ (%.2f$/km)\n"), veh_type->get_preis() / 100, veh_type->get_betriebskosten() / 100.0 );
{
char tmp[128];
money_to_string( tmp, veh_type->get_preis() / 100.0, false );
n += sprintf( buf + n, translator::translate("Cost: %8s (%.2f$/km)\n"), tmp, veh_type->get_betriebskosten() / 100.0 );
}

if( veh_type->get_zuladung() > 0 ) { // must translate as "Capacity: %3d%s %s\n"
n += sprintf( buf + n, translator::translate("Capacity: %d%s %s\n"),
Expand Down Expand Up @@ -1558,8 +1567,10 @@ void depot_frame_t::draw_vehicle_info_text(koord pos)
}
n += sprintf( buf + n, "\n");

if( resale_value != -1 ) {
sprintf( buf + n, "%s %6ld$", translator::translate("Restwert:"), resale_value );
if( resale_value != -1.0 ) {
char tmp[128];
money_to_string( tmp, resale_value / 100.0, false );
sprintf( buf + n, "%s %8s", translator::translate("Restwert:"), tmp );
}

display_multiline_text( pos.x + second_column_x, pos.y + tabs.get_pos().y + tabs.get_groesse().y + 31 + LINESPACE * 2 + 4, buf, COL_BLACK);
Expand Down
2 changes: 1 addition & 1 deletion gui/depot_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class depot_frame_t : public gui_frame_t,
* @author Volker Meyer
* @date 09.06.2003
*/
sint32 calc_restwert(const vehikel_besch_t *veh_type);
sint64 calc_restwert(const vehikel_besch_t *veh_type);

/**
* Does this window need a min size button in the title bar?
Expand Down
2 changes: 1 addition & 1 deletion player/ai_goods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ DBG_MESSAGE("ai_goods_t::step()","remove already constructed rail between %i,%i

// apparently we got the toatlly wrong vehicle here ...
// (but we will delete it only, if we need, because it may be needed for a chain)
bool delete_this = (konto_ueberzogen>0) && (gewinn < -(sint32)cnv->calc_restwert());
bool delete_this = (konto_ueberzogen>0) && (gewinn < -cnv->calc_restwert());

// check for empty vehicles (likely stucked) that are making no plus and remove them ...
// take care, that the vehicle is old enough ...
Expand Down
4 changes: 2 additions & 2 deletions simconvoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2903,9 +2903,9 @@ sint32 convoi_t::get_running_cost() const
}


sint32 convoi_t::get_purchase_cost() const
sint64 convoi_t::get_purchase_cost() const
{
sint32 purchase_cost = 0;
sint64 purchase_cost = 0;
for( unsigned i = 0; i < get_vehikel_anzahl(); i++ ) {
purchase_cost += fahr[i]->get_besch()->get_preis();
}
Expand Down
2 changes: 1 addition & 1 deletion simconvoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class convoi_t : public sync_steppable, public overtaker_t
/**
* returns the total new purchase cost for all vehicles in convoy
*/
sint32 get_purchase_cost() const;
sint64 get_purchase_cost() const;

/**
* Constructor for loading from file,
Expand Down
4 changes: 2 additions & 2 deletions utils/simstring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void set_large_amout(const char *s, const double v)
* are made!
* @author Hj. Malthaner
*/
void money_to_string(char * p, double f)
void money_to_string(char * p, double f, const bool show_decimal)
{
char tmp[128];
char *tp = tmp;
Expand Down Expand Up @@ -138,7 +138,7 @@ void money_to_string(char * p, double f)
*p++ = large_number_string[i];
}
}
else {
else if( show_decimal ) {
i = l+1;
// only decimals for smaller numbers
*p++ = fraction_sep;
Expand Down
2 changes: 1 addition & 1 deletion utils/simstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ char *make_single_line_string(const char *in,int number_of_lines);
* are made!
* @author Hj. Malthaner
*/
void money_to_string(char * buf, double f);
void money_to_string(char * buf, double f, const bool show_decimal = true);


/**
Expand Down

0 comments on commit dae2f9a

Please sign in to comment.