Move format_readable_size and format_readable_speed into Localisation

This commit is contained in:
Matt 2019-02-04 14:16:33 +01:00
parent f310fd2e07
commit 57eccef347
4 changed files with 51 additions and 53 deletions

View File

@ -3727,39 +3727,26 @@ STR_6276 :{RED}{STRINGID} has guests getting stuck, possibly due to invalid r
STR_6277 :{WINDOW_COLOUR_2}Station index: {BLACK}{COMMA16}
STR_6278 :Autosave amount
STR_6279 :{SMALLFONT}{BLACK}Number of autosaves that should be kept
<<<<<<< HEAD
STR_6280 :{SMALLFONT}{BLACK}Chat
STR_6281 :{SMALLFONT}{BLACK}Show a separate button for the Chat window in the toolbar
STR_6282 :Chat
STR_6283 :Chat not available at this time. Are you connected to a server?
STR_6284 :Network
STR_6285 :Network Information
STR_6286 :Bytes in
STR_6287 :Bytes out
STR_6288 :Total in
STR_6289 :Total out
STR_6286 :Receive
STR_6287 :Send
STR_6288 :Total received
STR_6289 :Total sent
STR_6290 :Base protocol
STR_6291 :Commands
STR_6292 :Map
=======
STR_6280 :Network
STR_6281 :Network Information
STR_6282 :Receive
STR_6283 :Send
STR_6284 :Total received
STR_6285 :Total sent
STR_6286 :Base protocol
STR_6287 :Commands
STR_6288 :Map
STR_6289 :B
STR_6290 :KB
STR_6291 :MB
STR_6292 :GB
STR_6293 :TB
STR_6294 :{STRING}/sec
STR_6293 :B
STR_6294 :KB
STR_6295 :MB
STR_6296 :GB
STR_6297 :TB
STR_6298 :{STRING}/sec
>>>>>>> Use localisation for speed and size information.
#############
# Scenarios #
################

View File

@ -292,36 +292,6 @@ static void window_network_information_update(rct_window* w)
_networkHistory.push_back(_networkLastDeltaStats);
}
static void format_readable_size(char* buf, size_t bufSize, uint64_t bytes)
{
constexpr uint32_t SizeTable[] = { STR_SIZE_BYTE, STR_SIZE_KILOBYTE, STR_SIZE_MEGABYTE, STR_SIZE_GIGABYTE,
STR_SIZE_TERABYTE };
double size = bytes;
size_t idx = 0;
while (size >= 1024.0)
{
size /= 1024.0;
idx++;
}
char sizeType[128] = {};
format_string(sizeType, sizeof(sizeType), SizeTable[idx], nullptr);
sprintf(buf, "%.03f %s", size, sizeType);
}
static void format_readable_speed(char* buf, size_t bufSize, uint64_t bytes)
{
char sizeText[128] = {};
format_readable_size(sizeText, sizeof(sizeText), bytes);
const char* args[1] = {
sizeText,
};
format_string(buf, bufSize, STR_NETWORK_SPEED_SEC, args);
}
static void window_network_information_invalidate(rct_window* w)
{
window_network_set_pressed_tab(w);

View File

@ -1403,6 +1403,36 @@ void format_string_to_upper(utf8* dest, size_t size, rct_string_id format, const
dest[upperString.size()] = '\0';
}
void format_readable_size(char* buf, size_t bufSize, uint64_t sizeBytes)
{
constexpr uint32_t SizeTable[] = { STR_SIZE_BYTE, STR_SIZE_KILOBYTE, STR_SIZE_MEGABYTE, STR_SIZE_GIGABYTE,
STR_SIZE_TERABYTE };
double size = sizeBytes;
size_t idx = 0;
while (size >= 1024.0)
{
size /= 1024.0;
idx++;
}
char sizeType[128] = {};
format_string(sizeType, sizeof(sizeType), SizeTable[idx], nullptr);
sprintf(buf, "%.03f %s", size, sizeType);
}
void format_readable_speed(char* buf, size_t bufSize, uint64_t sizeBytes)
{
char sizeText[128] = {};
format_readable_size(sizeText, sizeof(sizeText), sizeBytes);
const char* args[1] = {
sizeText,
};
format_string(buf, bufSize, STR_NETWORK_SPEED_SEC, args);
}
money32 string_to_money(const char* string_to_monetise)
{
const char* decimal_char = language_get_string(STR_LOCALE_DECIMAL_POINT);

View File

@ -29,6 +29,17 @@ void format_string(char* dest, size_t size, rct_string_id format, const void* ar
void format_string_raw(char* dest, size_t size, const char* src, const void* args);
void format_string_to_upper(char* dest, size_t size, rct_string_id format, const void* args);
void generate_string_file();
/**
* Formats sizeBytes into buf as a human readable text, e.x.: "1024 MB"
*/
void format_readable_size(char* buf, size_t bufSize, uint64_t sizeBytes);
/**
* Formats sizeBytesPerSec into buf as a human readable text, e.x.: "1024 MB/sec"
*/
void format_readable_speed(char* buf, size_t bufSize, uint64_t sizeBytesPerSec);
utf8* get_string_end(const utf8* text);
size_t get_string_size(const utf8* text);
int32_t get_string_length(const utf8* text);