1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 14:24:33 +01:00

Add localised currency string formatting - fixes #222

This commit is contained in:
ZedThree
2014-07-26 22:05:46 +02:00
parent 6e61f73e7b
commit ebe6c95a88
6 changed files with 137 additions and 37 deletions

View File

@@ -20,6 +20,7 @@
<ClInclude Include="..\src\award.h" />
<ClInclude Include="..\src\climate.h" />
<ClInclude Include="..\src\config.h" />
<ClInclude Include="..\src\currency.h" />
<ClInclude Include="..\src\date.h" />
<ClInclude Include="..\src\editor.h" />
<ClInclude Include="..\src\finance.h" />
@@ -62,6 +63,7 @@
<ClCompile Include="..\src\award.c" />
<ClCompile Include="..\src\climate.c" />
<ClCompile Include="..\src\config.c" />
<ClCompile Include="..\src\currency.c" />
<ClCompile Include="..\src\date.c" />
<ClCompile Include="..\src\editor.c" />
<ClCompile Include="..\src\finance.c" />

View File

@@ -138,6 +138,9 @@
<ClInclude Include="..\src\award.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\currency.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\game.c">
@@ -335,6 +338,9 @@
<ClCompile Include="..\src\window_peep.c">
<Filter>Windows</Filter>
</ClCompile>
<ClCompile Include="..\src\currency.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\openrct2.exe">

View File

@@ -21,6 +21,7 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include "currency.h"
#include "rct2.h"
#include <windows.h> // for MAX_PATH
@@ -87,20 +88,6 @@ enum {
MEASUREMENT_FORMAT_METRIC
};
enum{
CURRENCY_POUNDS,
CURRENCY_DOLLARS,
CURRENCY_FRANC,
CURRENCY_DEUTSCHMARK,
CURRENCY_YEN,
CURRENCY_PESETA,
CURRENCY_LIRA,
CURRENCY_GUILDERS,
CURRENCY_KRONA,
CURRENCY_EUROS
};
enum{
SOUND_QUALITY_LOW,
SOUND_QUALITY_MEDIUM,
@@ -156,9 +143,10 @@ static const struct { char *key; int value; } _currencyLookupTable[] = {
{ "DEK", CURRENCY_KRONA },
{ "EUR", CURRENCY_EUROS },
{ "£", CURRENCY_POUNDS },
{ "$", CURRENCY_DOLLARS },
{ "", CURRENCY_EUROS }
{ "\xA3", CURRENCY_POUNDS },
{ "\x24", CURRENCY_DOLLARS },
{ "\xA5", CURRENCY_YEN },
{ "\xB5", CURRENCY_EUROS }
};
//typedef struct hotkey_configuration{

34
src/currency.c Normal file
View File

@@ -0,0 +1,34 @@
/*****************************************************************************
* Copyright (c) 2014 Ted John, Peter Hill
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* This file is part of OpenRCT2.
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "currency.h"
const rct_currency_spec g_currency_specs[CURRENCY_END] = {
{10 , "\xA3" , 1}, //British Pound
{10 , "\x24" , 1}, //US Dollar
{10 , "FRF" , 1}, //French Franc
{10 , "DM" , 1}, //Deutsche Mark
{1000 , "\xA5" , 1}, //Japanese Yen
{10 , "Pts" , 0}, //Spanish Peseta
{1000 , "L" , 1}, //Italian Lira
{10 , "Dfl." , 1}, //Dutch Guilder
{10 , "kr." , 0}, //Swedish Krona
{10 , "\xb5" , 1}, //Euro
};

52
src/currency.h Normal file
View File

@@ -0,0 +1,52 @@
/*****************************************************************************
* Copyright (c) 2014 Ted John, Peter Hill
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* This file is part of OpenRCT2.
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef CURRENCY_H
#define CURRENCY_H
// List of currencies
typedef enum {
CURRENCY_POUNDS, //British Pound
CURRENCY_DOLLARS, //US Dollar
CURRENCY_FRANC, //French Franc
CURRENCY_DEUTSCHMARK, //Deutsche Mark
CURRENCY_YEN, //Japanese Yen
CURRENCY_PESETA, //Spanish Peseta
CURRENCY_LIRA, //Italian Lira
CURRENCY_GUILDERS, //Dutch Gilder
CURRENCY_KRONA, //Swedish Krona
CURRENCY_EUROS, //Euro
CURRENCY_END //Last item
} CURRENCY_TYPE;
// Currency format specification - inspired by OpenTTD
typedef struct {
// Rate is relative to 0.1 GBP
int rate;
char symbol[8];
// 0: symbol is a suffix, 1: symbol is a prefix
int prefix;
} rct_currency_spec;
// List of currency formats
extern const rct_currency_spec g_currency_specs[CURRENCY_END];
#endif

View File

@@ -21,6 +21,8 @@
#include <stdio.h>
#include <string.h>
#include "addresses.h"
#include "config.h"
#include "currency.h"
#include "game.h"
#include "date.h"
#include "rct2.h"
@@ -1218,48 +1220,64 @@ void format_comma_separated_fixed_2dp(char **dest, int value)
void format_currency(char **dest, int value)
{
int digit, groupIndex;
char *dst = *dest;
char *finish;
char tmp;
int rate = g_currency_specs[gGeneral_config.currency_format].rate;
value *= rate;
// Negative sign
if (value < 0) {
*dst++ = '-';
*(*dest)++ = '-';
value = -value;
}
// Currency symbol
*dst++ = '£';
char *symbol = &(g_currency_specs[gGeneral_config.currency_format].symbol);
// Prefix
if (g_currency_specs[gGeneral_config.currency_format].prefix) {
strcpy(*dest, symbol);
*dest += strlen(*dest);
}
*dest = dst;
// Divide by 100 to get rid of the pennies
format_comma_separated_integer(dest, value/100);
// value is in tens of pennies, so to get rid of
// the pence, just divide by ten
format_comma_separated_integer(dest, value/10);
// Currency symbol suffix
if (!g_currency_specs[gGeneral_config.currency_format].prefix) {
strcpy(*dest, symbol);
*dest += strlen(*dest);
}
}
void format_currency_2dp(char **dest, int value)
{
int digit, groupIndex;
char *dst = *dest;
char *finish;
char tmp;
int rate = g_currency_specs[gGeneral_config.currency_format].rate;
value *= rate;
// Negative sign
if (value < 0) {
*dst++ = '-';
*(*dest)++ = '-';
value = -value;
}
// Currency symbol
*dst++ = '£';
char *symbol = &(g_currency_specs[gGeneral_config.currency_format].symbol);
// Prefix
if (g_currency_specs[gGeneral_config.currency_format].prefix) {
strcpy(*dest, symbol);
*dest += strlen(*dest);
}
*dest = dst;
// Drop the pennies for "large" currencies
if (rate > 10) {
format_comma_separated_integer(dest, value/100);
} else {
format_comma_separated_fixed_2dp(dest, value);
}
// value is in tens of pennies, so multiply by 10
// to get in pounds and pence
format_comma_separated_fixed_2dp(dest, value*10);
// Currency symbol suffix
if (!g_currency_specs[gGeneral_config.currency_format].prefix) {
strcpy(*dest, symbol);
*dest += strlen(*dest);
}
}
void format_string_code(unsigned char format_code, char **dest, char **args)