Skip to content

Commit

Permalink
ADD: no decimal point for very large amounts
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@3150 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Apr 6, 2010
1 parent 91eb33d commit fb4579d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
18 changes: 12 additions & 6 deletions gui/components/gui_label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ void gui_label_t::zeichnen(koord offset)
offset.y += (9-large_font_height)/2;
if(align == money) {
if(text) {
const char *separator = strrchr(text, get_fraction_sep());
if(separator) {
display_proportional_clip(pos.x+offset.x, pos.y+offset.y, translator::translate(separator), ALIGN_LEFT, color, true);
*const_cast<char *>(separator) = '\0';
display_proportional_clip(pos.x+offset.x, pos.y+offset.y, translator::translate(text), ALIGN_RIGHT, color, true);
*const_cast<char *>(separator) = ',';
const char *seperator = NULL;
if( strrchr(text, '$')!=NULL ) {
seperator = strrchr(text, get_fraction_sep());
if(seperator==NULL && get_large_money_string()!=NULL) {
seperator = strrchr(text, *(get_large_money_string()) );
}
}
if(seperator) {
display_proportional_clip(pos.x+offset.x, pos.y+offset.y, seperator, DT_DIRTY|ALIGN_LEFT, color, true);
if( seperator!=text ) {
display_text_proportional_len_clip(pos.x+offset.x, pos.y+offset.y, text, DT_DIRTY|ALIGN_RIGHT, color, seperator-text );
}
}
else {
display_proportional_clip(pos.x+offset.x, pos.y+offset.y, text, ALIGN_RIGHT, color, true);
Expand Down
3 changes: 2 additions & 1 deletion simutrans/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
FIX: build foundations only directly under elevated monorail depots
FIX: ist_natur() return als false on halt tiles (like harbour)
ADD: (gerw) broad tunnel patch (see pak64 sources: adding images [Nl] [Nm] [Nr] and so on)
FIX: no long no trees after 150 years
FIX: no longer no trees after 150 years
ADD: no decimal point for very large amounts


Release of 102.2.2 (r3131 on 8-Mar-2010):
Expand Down
27 changes: 21 additions & 6 deletions utils/simstring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ char get_fraction_sep(void)
return fraction_sep;
}

const char *get_large_money_string(void)
{
return large_number_string;
}


void set_large_amout(const char *s, const double v)
{
large_number_string = s;
Expand All @@ -80,7 +86,7 @@ void money_to_string(char * p, double f)
int i,l;

if( f>1000.0*large_number_factor ) {
sprintf( tp, "%.1f%s", f/large_number_factor, large_number_string );
sprintf( tp, "%.1f", f/large_number_factor );
}
else {
sprintf( tp, "%.2f", f );
Expand Down Expand Up @@ -109,12 +115,21 @@ void money_to_string(char * p, double f)
*p++ = thousand_sep;
}
--p;
i = l+1;

*p++ = fraction_sep;
// since it might be longer due to unicode characters
while( tp[i]!=0 ) {
*p++ = tp[i++];
if( f>1000.0*large_number_factor ) {
// only decimals for smaller numbers; add large number string instead
for( i=0; large_number_string[i]!=0; i++ ) {
*p++ = large_number_string[i];
}
}
else {
i = l+1;
// only decimals for smaller numbers
*p++ = fraction_sep;
// since it might be longer due to unicode characters
while( tp[i]!=0 ) {
*p++ = tp[i++];
}
}
*p++ = '$';
*p = 0;
Expand Down
3 changes: 1 addition & 2 deletions utils/simstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ void set_thousand_sep(char c);
*/
void set_fraction_sep(char c);


char get_fraction_sep(void);

const char *get_large_money_string(void);

/**
* Set abbrevitation and the amout by which large money amouts will be shortened
Expand Down

0 comments on commit fb4579d

Please sign in to comment.