From 7d53b065dd93923460f287cd642675a532a71996 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Wed, 22 Jun 2016 10:28:28 +0200 Subject: [PATCH 01/26] Add custom currency Add the corresponding entry inside CurrencyDescriptors array, and made it non-const to let the rate and other properties to change. Also, a language string (STR_5880, en-GB & es-ES) has been added. --- data/language/en-GB.txt | 1 + data/language/es-ES.txt | 1 + src/localisation/currency.c | 3 ++- src/localisation/currency.h | 4 +++- src/localisation/string_ids.h | 3 +++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index f84a62c850..2f0a25571c 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -4190,6 +4190,7 @@ STR_5878 :Software (hardware display) STR_5879 :OpenGL STR_5880 :Selected only STR_5881 :Non-selected only +STR_5882 :Custom currency ############# # Scenarios # diff --git a/data/language/es-ES.txt b/data/language/es-ES.txt index 5f1a0d7151..76f218d467 100644 --- a/data/language/es-ES.txt +++ b/data/language/es-ES.txt @@ -4148,6 +4148,7 @@ STR_5876 :{SMALLFONT}{BLACK}El software a utilizar para dibujar el juego. STR_5877 :Software STR_5878 :Software (vía hardware) STR_5879 :OpenGL +STR_5880 :Moneda personalizada ############## # Escenarios # diff --git a/src/localisation/currency.c b/src/localisation/currency.c index cc74aa051d..d09dce6575 100644 --- a/src/localisation/currency.c +++ b/src/localisation/currency.c @@ -17,7 +17,7 @@ #include "currency.h" #include "string_ids.h" -const currency_descriptor CurrencyDescriptors[CURRENCY_END] = { +currency_descriptor CurrencyDescriptors[CURRENCY_END] = { { "GBP", 10, CURRENCY_PREFIX, "\xC2\xA3", CURRENCY_SUFFIX, "GBP", STR_POUNDS }, // British Pound { "USD", 10, CURRENCY_PREFIX, "$", CURRENCY_PREFIX, "$", STR_DOLLARS }, // US Dollar { "FRF", 10, CURRENCY_SUFFIX, "F", CURRENCY_SUFFIX, "F", STR_FRANC }, // French Franc @@ -34,4 +34,5 @@ const currency_descriptor CurrencyDescriptors[CURRENCY_END] = { { "HKD", 100, CURRENCY_PREFIX, "$", CURRENCY_PREFIX, "HKD", STR_HONG_KONG_DOLLAR}, // Hong Kong Dollar { "TWD", 1000, CURRENCY_PREFIX, "NT$", CURRENCY_PREFIX, "NT$", STR_NEW_TAIWAN_DOLLAR}, // New Taiwan Dollar { "CNY", 100, CURRENCY_PREFIX, "CN\xC2\xA5", CURRENCY_PREFIX, "CNY", STR_CHINESE_YUAN }, // Chinese Yuan + { "CTM", 1, CURRENCY_PREFIX, "Ctm", CURRENCY_PREFIX, "Ctm", STR_CUSTOM_CURRENCY }, // Customizable currency }; diff --git a/src/localisation/currency.h b/src/localisation/currency.h index 7c96eb8ab1..b23b1ffe60 100644 --- a/src/localisation/currency.h +++ b/src/localisation/currency.h @@ -38,6 +38,8 @@ typedef enum { CURRENCY_TWD, // New Taiwan Dollar CURRENCY_YUAN, // Chinese Yuan + CURRENCY_CUSTOM, // Custom currency + CURRENCY_END // Last item } CURRENCY_TYPE; @@ -61,6 +63,6 @@ typedef struct currency_descriptor { } currency_descriptor; // List of currency formats -extern const currency_descriptor CurrencyDescriptors[CURRENCY_END]; +extern currency_descriptor CurrencyDescriptors[CURRENCY_END]; #endif diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 625cd286ce..fdd5d2efcf 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -2658,6 +2658,9 @@ enum { STR_SELECTED_ONLY = 5880, STR_NON_SELECTED_ONLY = 5881, + + STR_CUSTOM_CURRENCY = 5882, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 }; From 9355eef5d41f6aa173bb407963284dcd2d64be74 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Wed, 22 Jun 2016 13:17:30 +0200 Subject: [PATCH 02/26] Add custom currency option Add custom currency entry to the dropdown menu of the options window --- src/windows/options.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/windows/options.c b/src/windows/options.c index 21dda00826..49344593da 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -914,13 +914,20 @@ static void window_options_mousedown(int widgetIndex, rct_window*w, rct_widget* dropdown_set_checked(gConfigGeneral.show_height_as_units ? 0 : 1, true); break; case WIDX_CURRENCY_DROPDOWN: - num_items = CURRENCY_END; + num_items = CURRENCY_END + 1; // All the currencies plus the separator + int num_ordinary_currencies = CURRENCY_END - 1; // All the currencies except custom currency - for (i = 0; i < num_items; i++) { + for (i = 0; i < num_ordinary_currencies; i++) { gDropdownItemsFormat[i] = STR_DROPDOWN_MENU_LABEL; gDropdownItemsArgs[i] = CurrencyDescriptors[i].stringId; } + gDropdownItemsFormat[num_ordinary_currencies] = DROPDOWN_SEPARATOR; + + gDropdownItemsFormat[num_ordinary_currencies+1] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[num_ordinary_currencies+1] = CurrencyDescriptors[CURRENCY_CUSTOM].stringId; + + window_options_show_dropdown(w, widget, num_items); dropdown_set_checked(gConfigGeneral.currency_format, true); @@ -1181,7 +1188,11 @@ static void window_options_dropdown(rct_window *w, int widgetIndex, int dropdown window_options_update_height_markers(); break; case WIDX_CURRENCY_DROPDOWN: - gConfigGeneral.currency_format = (sint8)dropdownIndex; + if(dropdownIndex == CURRENCY_CUSTOM+1) { // Add 1 because the separator occupies a position + gConfigGeneral.currency_format = (sint8)dropdownIndex-1; + } else { + gConfigGeneral.currency_format = (sint8)dropdownIndex; + } config_save_default(); gfx_invalidate_screen(); break; From 187499fd7233cf0abcefac3825c6da5c66eba60c Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Thu, 23 Jun 2016 22:52:10 +0200 Subject: [PATCH 03/26] Fix currency dropdown not showing checked custom currency. Due to the dropdown separator before custom currency entry, the selected item index was incorrectly assigned to the separator. --- src/windows/options.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/windows/options.c b/src/windows/options.c index 49344593da..b5945d6dcb 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -930,7 +930,11 @@ static void window_options_mousedown(int widgetIndex, rct_window*w, rct_widget* window_options_show_dropdown(w, widget, num_items); - dropdown_set_checked(gConfigGeneral.currency_format, true); + if(gConfigGeneral.currency_format == CURRENCY_CUSTOM){ + dropdown_set_checked(gConfigGeneral.currency_format+1, true); + } else { + dropdown_set_checked(gConfigGeneral.currency_format, true); + } break; case WIDX_DISTANCE_DROPDOWN: gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; @@ -1190,9 +1194,10 @@ static void window_options_dropdown(rct_window *w, int widgetIndex, int dropdown case WIDX_CURRENCY_DROPDOWN: if(dropdownIndex == CURRENCY_CUSTOM+1) { // Add 1 because the separator occupies a position gConfigGeneral.currency_format = (sint8)dropdownIndex-1; + window_custom_currency_open(); } else { gConfigGeneral.currency_format = (sint8)dropdownIndex; - } + } // TODO: Save current custom currency rate config_save_default(); gfx_invalidate_screen(); break; From 140b4f73aa4fedc61b15cbbf3ab7eb9b8ebb90e1 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 08:44:54 +0200 Subject: [PATCH 04/26] Add other-than-selected currency support to format_currency_2dp This commit adds support for formatting currency strings using other than the selected currency. --- src/localisation/localisation.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c index 7d95ea4822..18113cf7bb 100644 --- a/src/localisation/localisation.c +++ b/src/localisation/localisation.c @@ -476,9 +476,9 @@ void format_currency(char **dest, long long value) } } -void format_currency_2dp(char **dest, long long value) +void format_any_currency_2dp(char **dest, long long value, int currencyIndex) { - const currency_descriptor *currencyDesc = &CurrencyDescriptors[gConfigGeneral.currency_format]; + const currency_descriptor *currencyDesc = &CurrencyDescriptors[currencyIndex]; int rate = currencyDesc->rate; value *= rate; @@ -517,6 +517,11 @@ void format_currency_2dp(char **dest, long long value) } } +void format_currency_2dp(char **dest, long long value) +{ + format_any_currency_2dp(dest, value, gConfigGeneral.currency_format); +} + void format_date(char **dest, uint16 value) { uint16 args[] = { date_get_month(value), date_get_year(value) + 1 }; From 5302ebd951f8f6f8cd86ee7d4ca09e2c4facba47 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 08:54:13 +0200 Subject: [PATCH 05/26] Revert "Add other-than-selected currency support to format_currency_2dp" This reverts commit 98d5b332bd9958296218a66e2eb7ef61600c8086. --- src/localisation/localisation.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c index 18113cf7bb..7d95ea4822 100644 --- a/src/localisation/localisation.c +++ b/src/localisation/localisation.c @@ -476,9 +476,9 @@ void format_currency(char **dest, long long value) } } -void format_any_currency_2dp(char **dest, long long value, int currencyIndex) +void format_currency_2dp(char **dest, long long value) { - const currency_descriptor *currencyDesc = &CurrencyDescriptors[currencyIndex]; + const currency_descriptor *currencyDesc = &CurrencyDescriptors[gConfigGeneral.currency_format]; int rate = currencyDesc->rate; value *= rate; @@ -517,11 +517,6 @@ void format_any_currency_2dp(char **dest, long long value, int currencyIndex) } } -void format_currency_2dp(char **dest, long long value) -{ - format_any_currency_2dp(dest, value, gConfigGeneral.currency_format); -} - void format_date(char **dest, uint16 value) { uint16 args[] = { date_get_month(value), date_get_year(value) + 1 }; From 71a32a8750e2cd6109d52baac1a633f763779e4b Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 17:57:41 +0200 Subject: [PATCH 06/26] Create custom currency configuration window --- data/language/en-GB.txt | 8 ++ data/language/es-ES.txt | 9 ++ src/interface/window.h | 3 + src/localisation/string_ids.h | 8 ++ src/windows/custom_currency.c | 249 ++++++++++++++++++++++++++++++++++ 5 files changed, 277 insertions(+) create mode 100644 src/windows/custom_currency.c diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 2f0a25571c..821ca8a377 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -4191,6 +4191,14 @@ STR_5879 :OpenGL STR_5880 :Selected only STR_5881 :Non-selected only STR_5882 :Custom currency +STR_5883 :Custom currency configuration +STR_5884 :{WINDOW_COLOUR_2}Exchange rate: +STR_5885 :{WINDOW_COLOUR_2}is equivalent to {COMMA2DP32} GBP +STR_5886 :{WINDOW_COLOUR_2}Currency symbol: +STR_5887 :Prefix +STR_5888 :Suffix +STR_5889 :Custom currency symbol +STR_5890 :Enter the currency symbol to display ############# # Scenarios # diff --git a/data/language/es-ES.txt b/data/language/es-ES.txt index 76f218d467..a89e6f305e 100644 --- a/data/language/es-ES.txt +++ b/data/language/es-ES.txt @@ -4148,7 +4148,16 @@ STR_5876 :{SMALLFONT}{BLACK}El software a utilizar para dibujar el juego. STR_5877 :Software STR_5878 :Software (vía hardware) STR_5879 :OpenGL + STR_5880 :Moneda personalizada +STR_5881 :Configuración de la moneda personalizada +STR_5882 :{WINDOW_COLOUR_2}Tasa de cambio: +STR_5883 :{WINDOW_COLOUR_2}es equivalente a {COMMA2DP32} libras +STR_5884 :{WINDOW_COLOUR_2}Símbolo monetario: +STR_5885 :Prefijo +STR_5886 :Sufijo +STR_5887 :Símbolo de moneda personalizada +STR_5888 :Introduzca el símbolo de la moneda a mostrar ############## # Escenarios # diff --git a/src/interface/window.h b/src/interface/window.h index acdbe46d06..649da6219b 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -453,6 +453,7 @@ enum { WC_NETWORK_STATUS = 126, WC_SERVER_LIST = 127, WC_SERVER_START = 128, + WC_CUSTOM_CURRENCY_CONFIG = 129, // Only used for colour schemes WC_STAFF = 220, @@ -629,6 +630,8 @@ void ride_construction_toolupdate_entrance_exit(int screenX, int screenY); void ride_construction_toolupdate_construct(int screenX, int screenY); void ride_construction_tooldown_construct(int screenX, int screenY); +void window_custom_currency_open(); + void window_maze_construction_update_pressed_widgets(); void window_track_place_open(const track_design_file_ref *tdFileRef); rct_window *window_new_ride_open(); diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index fdd5d2efcf..3b7ef36d08 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -2660,6 +2660,14 @@ enum { STR_NON_SELECTED_ONLY = 5881, STR_CUSTOM_CURRENCY = 5882, + STR_CUSTOM_CURRENCY_WINDOW_TITLE = 5883, + STR_RATE = 5884, + STR_CUSTOM_CURRENCY_EQUIVALENCY = 5885, + STR_CURRENCY_SYMBOL_TEXT = 5886, + STR_PREFIX = 5887, + STR_SUFFIX = 5888, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE = 5889, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC = 5890, // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c new file mode 100644 index 0000000000..840c3a3d03 --- /dev/null +++ b/src/windows/custom_currency.c @@ -0,0 +1,249 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/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. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#include "../localisation/localisation.h" +#include "../interface/widget.h" +#include "dropdown.h" + +enum WINDOW_CUSTOM_CURRENCY_WIDGET_IDX { + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_RATE, + WIDX_RATE_UP, + WIDX_RATE_DOWN, + WIDX_SYMBOL_TEXT, + WIDX_AFFIX_DROPDOWN, + WIDX_AFFIX_DROPDOWN_BUTTON, +}; + +rct_widget window_custom_currency_widgets[] = { +// TYPE COLOUR LEFT RIGHT TOP BOTTOM IMAGE TOOLTIP + { WWT_FRAME, 0, 0, 399, 0, 99, 0x0FFFFFFFF, STR_NONE }, // panel / background + { WWT_CAPTION, 0, 1, 398, 1, 14, STR_CUSTOM_CURRENCY_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, // title bar + { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button + { WWT_SPINNER, 1, 100, 200, 30, 40, 5462, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 31, 35, STR_NUMERIC_UP, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 36, 40, STR_NUMERIC_DOWN, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 120, 200, 50, 60, 0, STR_NONE }, + { WWT_DROPDOWN, 1, 220, 350, 50, 60, 865, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 339, 349, 51, 59, STR_DROPDOWN_GLYPH, STR_NONE }, + { WIDGETS_END }, +}; + +static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); +static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex); +static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text); +static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi); + +static void invalidate_money_widgets(); + +static rct_window_event_list window_custom_currency_events = { + NULL, + NULL, + NULL, + window_custom_currency_mousedown, + window_custom_currency_dropdown, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + window_custom_currency_text_input, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + window_custom_currency_paint, + NULL +}; + +/** + * + * rct2: 0x0066D2AC + */ +void window_custom_currency_open() +{ + rct_window* window; + + // Check if window is already open + window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG); + if (window != NULL) + return; + + window = window_create_centred( + 400, + 100, + &window_custom_currency_events, + WC_CUSTOM_CURRENCY_CONFIG, + 0 + ); + window->widgets = window_custom_currency_widgets; + window->enabled_widgets = (1 << WIDX_CLOSE) | + (1 << WIDX_RATE) | + (1 << WIDX_RATE_UP) | + (1 << WIDX_RATE_DOWN) | + (1 << WIDX_SYMBOL_TEXT) | + (1 << WIDX_AFFIX_DROPDOWN) | + (1 << WIDX_AFFIX_DROPDOWN_BUTTON); + + window_init_scroll_widgets(window); + window->colours[0] = 22; + window->colours[1] = 22; + window->colours[2] = 22; +} + + + +/** +* +* rct2: 0x006BB01B +*/ +static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget) { + widget = &w->widgets[widgetIndex - 1]; + + switch (widgetIndex) { + + case WIDX_CLOSE: + window_close(w); + break; + + case WIDX_RATE_UP: + CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; + invalidate_money_widgets(); + break; + + case WIDX_RATE_DOWN: + if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; + } + invalidate_money_widgets(); + break; + + case WIDX_AFFIX_DROPDOWN_BUTTON: + gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[0] = STR_PREFIX; + + gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[1] = STR_SUFFIX; + + window_dropdown_show_text_custom_width( + w->x + widget->left, + w->y + widget->top, + widget->bottom - widget->top + 1, + w->colours[1], + DROPDOWN_FLAG_STAY_OPEN, + 2, + widget->right - widget->left - 3 + ); + + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii == CURRENCY_PREFIX) { + dropdown_set_checked(0, true); + } else { + dropdown_set_checked(1, true); + } + + break; + + case WIDX_SYMBOL_TEXT: + window_text_input_raw_open( w, + WIDX_SYMBOL_TEXT, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + CURRENCY_SYMBOL_MAX_SIZE); + break; + + } +} + +/** +* +* rct2: 0x006BB076 +*/ +static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) { + if (dropdownIndex == -1) + return; + + if(widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON) { + + if(dropdownIndex == 0) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_PREFIX; + } else if(dropdownIndex == 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; + } + + invalidate_money_widgets(); + + } +} + +static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text) { + if(text != NULL) { + strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, text, CURRENCY_SYMBOL_MAX_SIZE); + invalidate_money_widgets(); + } +} + +static void invalidate_money_widgets() { + widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); + widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); +} + +/** + * + * rct2: 0x0066D321 + */ +static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi) { + int x, y; + + set_format_arg(0, sint32, 100); + + window_draw_widgets(w, dpi); + + x = w->x + 10; + y = w->y + 30; + + gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); + + sint32 baseExchange = 100/CurrencyDescriptors[CURRENCY_POUNDS].rate; + set_format_arg(0, sint32, baseExchange); + gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x+200, y); + + y += 20; + + gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, NULL, w->colours[1], x, y); + + gfx_draw_string(dpi, CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, w->colours[1], w->x + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1, w->y + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top); + + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX){ + gfx_draw_string_left(dpi, STR_PREFIX, w, w->colours[1], w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); + } else { + gfx_draw_string_left(dpi, STR_SUFFIX, w, w->colours[1], w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); + } + +} From b12e5443e9f66ba466206b2d196c8ce8b026d88d Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 19:57:17 +0200 Subject: [PATCH 07/26] Add configuration support for the custom currency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit do several things: · Add proper entries to config.c file · Load custom currency definition at start time · Save every change made from the custom currency configuration window --- src/config.c | 9 +++++++++ src/config.h | 3 +++ src/openrct2.c | 5 +++++ src/windows/custom_currency.c | 15 +++++++++++++-- src/windows/options.c | 2 +- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 4ec41c744c..8f12fc04ea 100644 --- a/src/config.c +++ b/src/config.c @@ -130,6 +130,12 @@ config_enum_definition _currencyEnum[] = { END_OF_ENUM }; +config_enum_definition _currencySymbolAffixEnum[] = { + { "PREFIX", CURRENCY_PREFIX }, + { "SUFFIX", CURRENCY_SUFFIX }, + END_OF_ENUM +}; + config_enum_definition _languageEnum[] = { { "en-GB", LANGUAGE_ENGLISH_UK }, { "en-US", LANGUAGE_ENGLISH_US }, @@ -171,6 +177,9 @@ config_property_definition _generalDefinitions[] = { { offsetof(general_configuration, confirmation_prompt), "confirmation_prompt", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, { offsetof(general_configuration, construction_marker_colour), "construction_marker_colour", CONFIG_VALUE_TYPE_UINT8, false, NULL }, { offsetof(general_configuration, currency_format), "currency_format", CONFIG_VALUE_TYPE_UINT8, CURRENCY_POUNDS, _currencyEnum }, + { offsetof(general_configuration, custom_currency_rate), "custom_currency_rate", CONFIG_VALUE_TYPE_SINT32, 1, NULL }, + { offsetof(general_configuration, custom_currency_affix), "custom_currency_affix", CONFIG_VALUE_TYPE_SINT8, CURRENCY_SUFFIX, _currencySymbolAffixEnum}, + { offsetof(general_configuration, custom_currency_symbol), "custom_currency_symbol", CONFIG_VALUE_TYPE_STRING, { .value_string = "Ctm" }, NULL }, { offsetof(general_configuration, edge_scrolling), "edge_scrolling", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, { offsetof(general_configuration, fullscreen_mode), "fullscreen_mode", CONFIG_VALUE_TYPE_UINT8, 0, NULL }, { offsetof(general_configuration, fullscreen_height), "fullscreen_height", CONFIG_VALUE_TYPE_SINT32, -1, NULL }, diff --git a/src/config.h b/src/config.h index ba5a033006..45b9fd75cf 100644 --- a/src/config.h +++ b/src/config.h @@ -146,6 +146,9 @@ typedef struct general_configuration { sint8 measurement_format; sint8 temperature_format; sint8 currency_format; + sint32 custom_currency_rate; + sint8 custom_currency_affix; + utf8string custom_currency_symbol; sint8 construction_marker_colour; sint8 edge_scrolling; sint8 always_show_gridlines; diff --git a/src/openrct2.c b/src/openrct2.c index fcfe3fee32..970616efe4 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -323,6 +323,11 @@ void openrct2_launch() } #endif // DISABLE_NETWORK + // Set custom currency properties + CurrencyDescriptors[CURRENCY_CUSTOM].rate = gConfigGeneral.custom_currency_rate; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = gConfigGeneral.custom_currency_affix; + strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, gConfigGeneral.custom_currency_symbol, CURRENCY_SYMBOL_MAX_SIZE); + openrct2_loop(); } openrct2_dispose(); diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index 840c3a3d03..40c5f7ea48 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -16,6 +16,7 @@ #include "../localisation/localisation.h" #include "../interface/widget.h" +#include "../config.h" #include "dropdown.h" enum WINDOW_CUSTOM_CURRENCY_WIDGET_IDX { @@ -134,14 +135,18 @@ static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_ case WIDX_RATE_UP: CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); invalidate_money_widgets(); break; case WIDX_RATE_DOWN: if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); + invalidate_money_widgets(); } - invalidate_money_widgets(); break; case WIDX_AFFIX_DROPDOWN_BUTTON: @@ -161,7 +166,7 @@ static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_ widget->right - widget->left - 3 ); - if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii == CURRENCY_PREFIX) { + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { dropdown_set_checked(0, true); } else { dropdown_set_checked(1, true); @@ -197,6 +202,10 @@ static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; } + + gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; + config_save_default(); + invalidate_money_widgets(); } @@ -205,6 +214,8 @@ static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text) { if(text != NULL) { strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, text, CURRENCY_SYMBOL_MAX_SIZE); + strncpy(gConfigGeneral.custom_currency_symbol, CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, CURRENCY_SYMBOL_MAX_SIZE); + config_save_default(); invalidate_money_widgets(); } } diff --git a/src/windows/options.c b/src/windows/options.c index b5945d6dcb..7754c5e87a 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -1197,7 +1197,7 @@ static void window_options_dropdown(rct_window *w, int widgetIndex, int dropdown window_custom_currency_open(); } else { gConfigGeneral.currency_format = (sint8)dropdownIndex; - } // TODO: Save current custom currency rate + } config_save_default(); gfx_invalidate_screen(); break; From 4a28f7f6aa00885f7e8f21250925036f30fac7ae Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 20:15:45 +0200 Subject: [PATCH 08/26] Clean code in custom_currency.c To make it more OpenRCT coding style compliant --- src/windows/custom_currency.c | 350 ++++++++++++++++++---------------- 1 file changed, 188 insertions(+), 162 deletions(-) diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index 40c5f7ea48..ad6aea07b7 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -20,29 +20,28 @@ #include "dropdown.h" enum WINDOW_CUSTOM_CURRENCY_WIDGET_IDX { - WIDX_BACKGROUND, - WIDX_TITLE, - WIDX_CLOSE, - WIDX_RATE, - WIDX_RATE_UP, - WIDX_RATE_DOWN, - WIDX_SYMBOL_TEXT, - WIDX_AFFIX_DROPDOWN, - WIDX_AFFIX_DROPDOWN_BUTTON, + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_RATE, + WIDX_RATE_UP, + WIDX_RATE_DOWN, + WIDX_SYMBOL_TEXT, + WIDX_AFFIX_DROPDOWN, + WIDX_AFFIX_DROPDOWN_BUTTON, }; rct_widget window_custom_currency_widgets[] = { -// TYPE COLOUR LEFT RIGHT TOP BOTTOM IMAGE TOOLTIP - { WWT_FRAME, 0, 0, 399, 0, 99, 0x0FFFFFFFF, STR_NONE }, // panel / background - { WWT_CAPTION, 0, 1, 398, 1, 14, STR_CUSTOM_CURRENCY_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, // title bar - { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button - { WWT_SPINNER, 1, 100, 200, 30, 40, 5462, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 189, 199, 31, 35, STR_NUMERIC_UP, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 189, 199, 36, 40, STR_NUMERIC_DOWN, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 120, 200, 50, 60, 0, STR_NONE }, - { WWT_DROPDOWN, 1, 220, 350, 50, 60, 865, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 339, 349, 51, 59, STR_DROPDOWN_GLYPH, STR_NONE }, - { WIDGETS_END }, + { WWT_FRAME, 0, 0, 399, 0, 99, 0x0FFFFFFFF, STR_NONE }, + { WWT_CAPTION, 0, 1, 398, 1, 14, STR_CUSTOM_CURRENCY_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, + { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, + { WWT_SPINNER, 1, 100, 200, 30, 40, 5462, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 31, 35, STR_NUMERIC_UP, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 36, 40, STR_NUMERIC_DOWN, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 120, 200, 50, 60, 0, STR_NONE }, + { WWT_DROPDOWN, 1, 220, 350, 50, 60, 865, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 339, 349, 51, 59, STR_DROPDOWN_GLYPH, STR_NONE }, + { WIDGETS_END }, }; static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); @@ -53,34 +52,34 @@ static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi); static void invalidate_money_widgets(); static rct_window_event_list window_custom_currency_events = { - NULL, - NULL, - NULL, - window_custom_currency_mousedown, - window_custom_currency_dropdown, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - window_custom_currency_text_input, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - window_custom_currency_paint, - NULL + NULL, + NULL, + NULL, + window_custom_currency_mousedown, + window_custom_currency_dropdown, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + window_custom_currency_text_input, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + window_custom_currency_paint, + NULL }; /** @@ -89,33 +88,33 @@ static rct_window_event_list window_custom_currency_events = { */ void window_custom_currency_open() { - rct_window* window; + rct_window* window; - // Check if window is already open - window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG); - if (window != NULL) - return; + // Check if window is already open + window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG); + if (window != NULL) + return; - window = window_create_centred( - 400, - 100, - &window_custom_currency_events, - WC_CUSTOM_CURRENCY_CONFIG, - 0 - ); - window->widgets = window_custom_currency_widgets; - window->enabled_widgets = (1 << WIDX_CLOSE) | - (1 << WIDX_RATE) | - (1 << WIDX_RATE_UP) | - (1 << WIDX_RATE_DOWN) | - (1 << WIDX_SYMBOL_TEXT) | - (1 << WIDX_AFFIX_DROPDOWN) | - (1 << WIDX_AFFIX_DROPDOWN_BUTTON); + window = window_create_centred( + 400, + 100, + &window_custom_currency_events, + WC_CUSTOM_CURRENCY_CONFIG, + 0 + ); + window->widgets = window_custom_currency_widgets; + window->enabled_widgets = (1 << WIDX_CLOSE) | + (1 << WIDX_RATE) | + (1 << WIDX_RATE_UP) | + (1 << WIDX_RATE_DOWN) | + (1 << WIDX_SYMBOL_TEXT) | + (1 << WIDX_AFFIX_DROPDOWN) | + (1 << WIDX_AFFIX_DROPDOWN_BUTTON); - window_init_scroll_widgets(window); - window->colours[0] = 22; - window->colours[1] = 22; - window->colours[2] = 22; + window_init_scroll_widgets(window); + window->colours[0] = 22; + window->colours[1] = 22; + window->colours[2] = 22; } @@ -124,137 +123,164 @@ void window_custom_currency_open() * * rct2: 0x006BB01B */ -static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget) { - widget = &w->widgets[widgetIndex - 1]; +static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget) +{ + widget = &w->widgets[widgetIndex - 1]; - switch (widgetIndex) { + switch (widgetIndex) { - case WIDX_CLOSE: - window_close(w); - break; + case WIDX_CLOSE: + window_close(w); + break; - case WIDX_RATE_UP: - CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; - gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; - config_save_default(); - invalidate_money_widgets(); - break; + case WIDX_RATE_UP: + CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); + invalidate_money_widgets(); + break; - case WIDX_RATE_DOWN: - if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { - CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; - gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; - config_save_default(); - invalidate_money_widgets(); - } - break; + case WIDX_RATE_DOWN: + if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); + invalidate_money_widgets(); + } + break; - case WIDX_AFFIX_DROPDOWN_BUTTON: - gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; - gDropdownItemsArgs[0] = STR_PREFIX; + case WIDX_AFFIX_DROPDOWN_BUTTON: + gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[0] = STR_PREFIX; - gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL; - gDropdownItemsArgs[1] = STR_SUFFIX; + gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[1] = STR_SUFFIX; - window_dropdown_show_text_custom_width( - w->x + widget->left, - w->y + widget->top, - widget->bottom - widget->top + 1, - w->colours[1], - DROPDOWN_FLAG_STAY_OPEN, - 2, - widget->right - widget->left - 3 - ); + window_dropdown_show_text_custom_width( + w->x + widget->left, + w->y + widget->top, + widget->bottom - widget->top + 1, + w->colours[1], + DROPDOWN_FLAG_STAY_OPEN, + 2, + widget->right - widget->left - 3 + ); - if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { - dropdown_set_checked(0, true); - } else { - dropdown_set_checked(1, true); - } + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { + dropdown_set_checked(0, true); + } else { + dropdown_set_checked(1, true); + } - break; + break; - case WIDX_SYMBOL_TEXT: - window_text_input_raw_open( w, - WIDX_SYMBOL_TEXT, - STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, - STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, - CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - CURRENCY_SYMBOL_MAX_SIZE); - break; + case WIDX_SYMBOL_TEXT: + window_text_input_raw_open( w, + WIDX_SYMBOL_TEXT, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + CURRENCY_SYMBOL_MAX_SIZE); + break; - } + } } /** * * rct2: 0x006BB076 */ -static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) { - if (dropdownIndex == -1) - return; +static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) +{ + if (dropdownIndex == -1) + return; - if(widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON) { + if(widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON) { - if(dropdownIndex == 0) { - CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_PREFIX; - } else if(dropdownIndex == 1) { - CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; - } + if(dropdownIndex == 0) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_PREFIX; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_PREFIX; + } else if(dropdownIndex == 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_SUFFIX; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; + } - gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; - config_save_default(); + gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; + config_save_default(); - invalidate_money_widgets(); + invalidate_money_widgets(); - } + } } -static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text) { - if(text != NULL) { - strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, text, CURRENCY_SYMBOL_MAX_SIZE); - strncpy(gConfigGeneral.custom_currency_symbol, CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, CURRENCY_SYMBOL_MAX_SIZE); - config_save_default(); - invalidate_money_widgets(); - } +static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text) +{ + if(text != NULL) { + strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + text, + CURRENCY_SYMBOL_MAX_SIZE); + + strncpy(gConfigGeneral.custom_currency_symbol, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + CURRENCY_SYMBOL_MAX_SIZE); + + config_save_default(); + invalidate_money_widgets(); + } } -static void invalidate_money_widgets() { - widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); - widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); +static void invalidate_money_widgets() +{ + widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); + widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); } /** * * rct2: 0x0066D321 */ -static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi) { - int x, y; +static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi) +{ + int x, y; - set_format_arg(0, sint32, 100); + set_format_arg(0, sint32, 100); - window_draw_widgets(w, dpi); + window_draw_widgets(w, dpi); - x = w->x + 10; - y = w->y + 30; + x = w->x + 10; + y = w->y + 30; - gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); + gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); - sint32 baseExchange = 100/CurrencyDescriptors[CURRENCY_POUNDS].rate; - set_format_arg(0, sint32, baseExchange); - gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x+200, y); + sint32 baseExchange = 100/CurrencyDescriptors[CURRENCY_POUNDS].rate; + set_format_arg(0, sint32, baseExchange); + gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x+200, y); - y += 20; + y += 20; - gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, NULL, w->colours[1], x, y); + gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, NULL, w->colours[1], x, y); - gfx_draw_string(dpi, CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, w->colours[1], w->x + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1, w->y + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top); + gfx_draw_string(dpi, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1, + w->y + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top); - if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX){ - gfx_draw_string_left(dpi, STR_PREFIX, w, w->colours[1], w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); - } else { - gfx_draw_string_left(dpi, STR_SUFFIX, w, w->colours[1], w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); - } + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX){ + gfx_draw_string_left(dpi, + STR_PREFIX, + w, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, + w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); + } else { + gfx_draw_string_left(dpi, + STR_SUFFIX, + w, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, + w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); + } } From 8412433683106e93c8a24d92b0263c1d807fbb57 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 20:21:01 +0200 Subject: [PATCH 09/26] Vanity card --- contributors.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contributors.md b/contributors.md index 416fe3197a..5de34b95cb 100644 --- a/contributors.md +++ b/contributors.md @@ -50,6 +50,7 @@ Includes all git commit authors. Aliases are GitHub user names. * Kelson Blakewood (spacek531) - title sequence for 0.0.4 * Hugo Wallenburg (Goddesen) - Misc. * (Nubbie) - Misc, UX +* Daniel Trujillo Viedma (gDanix) - Custom currency. ## Bug fixes * (halfbro) @@ -101,7 +102,7 @@ Includes all git commit authors. Aliases are GitHub user names. * Portuguese (BR) - (kaudy), (renansimoes) * Russian - (Soosisya) * Simplified Chinese - Naiji Ma (naijim), (izhangfei), Eric Zhao (sczyh30) -* Spanish - (mdtrooper), Josué Acevedo (Wirlie), Daniel Trujillo Viedma (gdabi); small fixes: (teapartycthulu) +* Spanish - (mdtrooper), Josué Acevedo (Wirlie), Daniel Trujillo Viedma (gDanix); small fixes: (teapartycthulu) * Swedish - (Jinxit), (mharrys), (Slimeyo), (Nubbie) * Traditional Chinese - Harry Lam (daihakken) * Norwegian - (Goddesen) From d69ab15557d89e42a63a7595b129535c3671c7ff Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 23:39:56 +0200 Subject: [PATCH 10/26] Revert changes in es-ES.txt --- data/language/es-ES.txt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/data/language/es-ES.txt b/data/language/es-ES.txt index a89e6f305e..5f1a0d7151 100644 --- a/data/language/es-ES.txt +++ b/data/language/es-ES.txt @@ -4149,16 +4149,6 @@ STR_5877 :Software STR_5878 :Software (vía hardware) STR_5879 :OpenGL -STR_5880 :Moneda personalizada -STR_5881 :Configuración de la moneda personalizada -STR_5882 :{WINDOW_COLOUR_2}Tasa de cambio: -STR_5883 :{WINDOW_COLOUR_2}es equivalente a {COMMA2DP32} libras -STR_5884 :{WINDOW_COLOUR_2}Símbolo monetario: -STR_5885 :Prefijo -STR_5886 :Sufijo -STR_5887 :Símbolo de moneda personalizada -STR_5888 :Introduzca el símbolo de la moneda a mostrar - ############## # Escenarios # ############## From 8ef1e1669d025c0648fceda8103c1832e1228ada Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 24 Jun 2016 23:44:03 +0200 Subject: [PATCH 11/26] Add a missing include. That was preventing from building on OSX and Win --- src/windows/custom_currency.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index ad6aea07b7..ed74959dd3 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -16,6 +16,7 @@ #include "../localisation/localisation.h" #include "../interface/widget.h" +#include "../interface/window.h" #include "../config.h" #include "dropdown.h" From cef8eef1773e918fb5f0541620263e8b7c6852f5 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Sat, 25 Jun 2016 00:28:51 +0200 Subject: [PATCH 12/26] Add Pound symbol to the "equivalent" string --- data/language/en-GB.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 821ca8a377..27490ed87b 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -4193,7 +4193,7 @@ STR_5881 :Non-selected only STR_5882 :Custom currency STR_5883 :Custom currency configuration STR_5884 :{WINDOW_COLOUR_2}Exchange rate: -STR_5885 :{WINDOW_COLOUR_2}is equivalent to {COMMA2DP32} GBP +STR_5885 :{WINDOW_COLOUR_2}is equivalent to {COMMA2DP32} GBP (£) STR_5886 :{WINDOW_COLOUR_2}Currency symbol: STR_5887 :Prefix STR_5888 :Suffix From f4d5cc0e28283b9cba0408b42ead25147bfe3550 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Sat, 25 Jun 2016 12:07:45 +0200 Subject: [PATCH 13/26] Add new created sorce file to the VS project file --- openrct2.vcxproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openrct2.vcxproj b/openrct2.vcxproj index ef0aabeab6..1561101908 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -257,6 +257,7 @@ + @@ -568,4 +569,4 @@ - \ No newline at end of file + From bc01d91930a6f3f19394a4863ad92b69b870adb5 Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Sat, 25 Jun 2016 05:22:58 -0500 Subject: [PATCH 14/26] Updated Xcode Project for #3952 --- OpenRCT2.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index dfb4818b33..9d130b35e3 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -319,6 +319,7 @@ D45A395D1CF300AF00659A24 /* libSDL2_ttf.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38B71CF3006400659A24 /* libSDL2_ttf.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; D45A395E1CF300AF00659A24 /* libSDL2.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38B81CF3006400659A24 /* libSDL2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; D45A395F1CF300AF00659A24 /* libspeexdsp.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38B91CF3006400659A24 /* libspeexdsp.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; + D45B202D1D1E92DB00B67CC7 /* custom_currency.c in Sources */ = {isa = PBXBuildFile; fileRef = D45B202C1D1E92DB00B67CC7 /* custom_currency.c */; }; D47304D51C4FF8250015C0EA /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D47304D41C4FF8250015C0EA /* libz.tbd */; }; D48A8D831D00272F00649DA7 /* TcpSocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D48A8D811D00272F00649DA7 /* TcpSocket.cpp */; }; D49766831D03B9FE002222CD /* SoftwareDrawingEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D49766811D03B9FE002222CD /* SoftwareDrawingEngine.cpp */; }; @@ -933,6 +934,7 @@ D45A39561CF3007A00659A24 /* speex_resampler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = speex_resampler.h; sourceTree = ""; }; D45A39571CF3007A00659A24 /* speexdsp_config_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = speexdsp_config_types.h; sourceTree = ""; }; D45A39581CF3007A00659A24 /* speexdsp_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = speexdsp_types.h; sourceTree = ""; }; + D45B202C1D1E92DB00B67CC7 /* custom_currency.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = custom_currency.c; sourceTree = ""; }; D47304D41C4FF8250015C0EA /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; D4895D321C23EFDD000CD788 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = distribution/osx/Info.plist; sourceTree = SOURCE_ROOT; }; D48A8D811D00272F00649DA7 /* TcpSocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TcpSocket.cpp; sourceTree = ""; usesTabs = 0; }; @@ -1524,6 +1526,7 @@ D44271911CC81B3200D84D28 /* changelog.c */, D44271921CC81B3200D84D28 /* cheats.c */, D44271931CC81B3200D84D28 /* clear_scenery.c */, + D45B202C1D1E92DB00B67CC7 /* custom_currency.c */, D44271941CC81B3200D84D28 /* demolish_ride_prompt.c */, D44271951CC81B3200D84D28 /* dropdown.c */, D44271961CC81B3200D84D28 /* dropdown.h */, @@ -2094,6 +2097,7 @@ 007A05CF1CFB2C8B00F419C3 /* NetworkConnection.cpp in Sources */, C686F9341CDBC3B7009F9BFC /* merry_go_round.c in Sources */, C686F8B81CDBC37E009F9BFC /* sprite.c in Sources */, + D45B202D1D1E92DB00B67CC7 /* custom_currency.c in Sources */, C686F9221CDBC3B7009F9BFC /* stand_up_roller_coaster.c in Sources */, C686F94F1CDBC3B7009F9BFC /* dingy_slide.c in Sources */, D44272341CC81B3200D84D28 /* network.cpp in Sources */, From 6ce45848422351601126b6838d3bad06b8eb255d Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Sat, 25 Jun 2016 14:27:48 +0200 Subject: [PATCH 15/26] Fix the currency equivalence bug The custom currency configuration window was showing an incorrectly equivalence ratio between GBP and the custom currency. --- src/windows/custom_currency.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index ed74959dd3..9fb5345994 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -254,7 +254,7 @@ static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi) gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); - sint32 baseExchange = 100/CurrencyDescriptors[CURRENCY_POUNDS].rate; + sint32 baseExchange = 100*CurrencyDescriptors[CURRENCY_POUNDS].rate; set_format_arg(0, sint32, baseExchange); gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x+200, y); From a17061cfb6cf08c2d3eb44dffa36740280ecb3c7 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Sat, 25 Jun 2016 16:04:21 +0200 Subject: [PATCH 16/26] Set default custom currency rate to 10, as GBP --- src/config.c | 2 +- src/localisation/currency.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 8f12fc04ea..4c076d04b3 100644 --- a/src/config.c +++ b/src/config.c @@ -177,7 +177,7 @@ config_property_definition _generalDefinitions[] = { { offsetof(general_configuration, confirmation_prompt), "confirmation_prompt", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, { offsetof(general_configuration, construction_marker_colour), "construction_marker_colour", CONFIG_VALUE_TYPE_UINT8, false, NULL }, { offsetof(general_configuration, currency_format), "currency_format", CONFIG_VALUE_TYPE_UINT8, CURRENCY_POUNDS, _currencyEnum }, - { offsetof(general_configuration, custom_currency_rate), "custom_currency_rate", CONFIG_VALUE_TYPE_SINT32, 1, NULL }, + { offsetof(general_configuration, custom_currency_rate), "custom_currency_rate", CONFIG_VALUE_TYPE_SINT32, 10, NULL }, { offsetof(general_configuration, custom_currency_affix), "custom_currency_affix", CONFIG_VALUE_TYPE_SINT8, CURRENCY_SUFFIX, _currencySymbolAffixEnum}, { offsetof(general_configuration, custom_currency_symbol), "custom_currency_symbol", CONFIG_VALUE_TYPE_STRING, { .value_string = "Ctm" }, NULL }, { offsetof(general_configuration, edge_scrolling), "edge_scrolling", CONFIG_VALUE_TYPE_BOOLEAN, true, NULL }, diff --git a/src/localisation/currency.c b/src/localisation/currency.c index d09dce6575..50ad672573 100644 --- a/src/localisation/currency.c +++ b/src/localisation/currency.c @@ -34,5 +34,5 @@ currency_descriptor CurrencyDescriptors[CURRENCY_END] = { { "HKD", 100, CURRENCY_PREFIX, "$", CURRENCY_PREFIX, "HKD", STR_HONG_KONG_DOLLAR}, // Hong Kong Dollar { "TWD", 1000, CURRENCY_PREFIX, "NT$", CURRENCY_PREFIX, "NT$", STR_NEW_TAIWAN_DOLLAR}, // New Taiwan Dollar { "CNY", 100, CURRENCY_PREFIX, "CN\xC2\xA5", CURRENCY_PREFIX, "CNY", STR_CHINESE_YUAN }, // Chinese Yuan - { "CTM", 1, CURRENCY_PREFIX, "Ctm", CURRENCY_PREFIX, "Ctm", STR_CUSTOM_CURRENCY }, // Customizable currency + { "CTM", 10, CURRENCY_PREFIX, "Ctm", CURRENCY_PREFIX, "Ctm", STR_CUSTOM_CURRENCY }, // Customizable currency }; From cb1f9269a6fddb057f36279c60dce677c5195f84 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Sat, 25 Jun 2016 16:07:26 +0200 Subject: [PATCH 17/26] Hide useless decimals in custom currency configuration window --- data/language/en-GB.txt | 2 +- src/windows/custom_currency.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 27490ed87b..505ff2ad58 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -4193,7 +4193,7 @@ STR_5881 :Non-selected only STR_5882 :Custom currency STR_5883 :Custom currency configuration STR_5884 :{WINDOW_COLOUR_2}Exchange rate: -STR_5885 :{WINDOW_COLOUR_2}is equivalent to {COMMA2DP32} GBP (£) +STR_5885 :{WINDOW_COLOUR_2}is equivalent to {COMMA32} GBP (£) STR_5886 :{WINDOW_COLOUR_2}Currency symbol: STR_5887 :Prefix STR_5888 :Suffix diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index 9fb5345994..0fc8bc9666 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -254,7 +254,7 @@ static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi) gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); - sint32 baseExchange = 100*CurrencyDescriptors[CURRENCY_POUNDS].rate; + sint32 baseExchange = CurrencyDescriptors[CURRENCY_POUNDS].rate; set_format_arg(0, sint32, baseExchange); gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x+200, y); From dfd78ec359318439bf927932eb42bfd8bf42dd21 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Mon, 27 Jun 2016 23:03:41 +0200 Subject: [PATCH 18/26] Perform a refactor for compliance with conding style. --- src/interface/window.h | 2 +- src/windows/custom_currency.c | 409 ++++++++++++++++++---------------- src/windows/options.c | 2 +- 3 files changed, 213 insertions(+), 200 deletions(-) diff --git a/src/interface/window.h b/src/interface/window.h index 649da6219b..caf981dc91 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -630,7 +630,7 @@ void ride_construction_toolupdate_entrance_exit(int screenX, int screenY); void ride_construction_toolupdate_construct(int screenX, int screenY); void ride_construction_tooldown_construct(int screenX, int screenY); -void window_custom_currency_open(); +void custom_currency_window_open(); void window_maze_construction_update_pressed_widgets(); void window_track_place_open(const track_design_file_ref *tdFileRef); diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index 0fc8bc9666..dfd3409a0f 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -14,108 +14,113 @@ *****************************************************************************/ #pragma endregion +/** + * 'Custom currency configuration' window definition and logic. + */ + +#include "../config.h" +#include "dropdown.h" #include "../localisation/localisation.h" #include "../interface/widget.h" #include "../interface/window.h" -#include "../config.h" -#include "dropdown.h" enum WINDOW_CUSTOM_CURRENCY_WIDGET_IDX { - WIDX_BACKGROUND, - WIDX_TITLE, - WIDX_CLOSE, - WIDX_RATE, - WIDX_RATE_UP, - WIDX_RATE_DOWN, - WIDX_SYMBOL_TEXT, - WIDX_AFFIX_DROPDOWN, - WIDX_AFFIX_DROPDOWN_BUTTON, + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_RATE, + WIDX_RATE_UP, + WIDX_RATE_DOWN, + WIDX_SYMBOL_TEXT, + WIDX_AFFIX_DROPDOWN, + WIDX_AFFIX_DROPDOWN_BUTTON, }; rct_widget window_custom_currency_widgets[] = { - { WWT_FRAME, 0, 0, 399, 0, 99, 0x0FFFFFFFF, STR_NONE }, - { WWT_CAPTION, 0, 1, 398, 1, 14, STR_CUSTOM_CURRENCY_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, - { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, - { WWT_SPINNER, 1, 100, 200, 30, 40, 5462, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 189, 199, 31, 35, STR_NUMERIC_UP, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 189, 199, 36, 40, STR_NUMERIC_DOWN, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 120, 200, 50, 60, 0, STR_NONE }, - { WWT_DROPDOWN, 1, 220, 350, 50, 60, 865, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 339, 349, 51, 59, STR_DROPDOWN_GLYPH, STR_NONE }, - { WIDGETS_END }, + { WWT_FRAME, 0, 0, 399, 0, 99, 0x0FFFFFFFF, STR_NONE }, + { WWT_CAPTION, 0, 1, 398, 1, 14, STR_CUSTOM_CURRENCY_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, + { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, + { WWT_SPINNER, 1, 100, 200, 30, 40, 5462, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 31, 35, STR_NUMERIC_UP, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 36, 40, STR_NUMERIC_DOWN, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 120, 200, 50, 60, 0, STR_NONE }, + { WWT_DROPDOWN, 1, 220, 350, 50, 60, 865, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 339, 349, 51, 59, STR_DROPDOWN_GLYPH, STR_NONE }, + { WIDGETS_END }, }; -static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); -static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex); -static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text); -static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi); - -static void invalidate_money_widgets(); - -static rct_window_event_list window_custom_currency_events = { - NULL, - NULL, - NULL, - window_custom_currency_mousedown, - window_custom_currency_dropdown, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - window_custom_currency_text_input, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - window_custom_currency_paint, - NULL +static rct_window_event_list _windowCustomCurrencyEvents = { + NULL, + NULL, + NULL, + custom_currency_window_mousedown, + custom_currency_window_dropdown, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + custom_currency_window_text_input, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + custom_currency_window_paint, + NULL }; +static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct_widget *widget); +static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int dropdownIndex); +static void custom_currency_window_text_input(struct rct_window *w, int windgetIndex, char *text); +static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi); + +static void custom_currency_invalidate_money_widgets(); + /** * - * rct2: 0x0066D2AC + * rct2: 0x0066D2AC */ -void window_custom_currency_open() +void custom_currency_window_open() { - rct_window* window; + rct_window* window; - // Check if window is already open - window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG); - if (window != NULL) - return; + // Check if window is already open + window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG); + if(window != NULL) + return; - window = window_create_centred( - 400, - 100, - &window_custom_currency_events, - WC_CUSTOM_CURRENCY_CONFIG, - 0 - ); - window->widgets = window_custom_currency_widgets; - window->enabled_widgets = (1 << WIDX_CLOSE) | - (1 << WIDX_RATE) | - (1 << WIDX_RATE_UP) | - (1 << WIDX_RATE_DOWN) | - (1 << WIDX_SYMBOL_TEXT) | - (1 << WIDX_AFFIX_DROPDOWN) | - (1 << WIDX_AFFIX_DROPDOWN_BUTTON); + window = window_create_centred( + 400, + 100, + &_windowCustomCurrencyEvents, + WC_CUSTOM_CURRENCY_CONFIG, + 0 + ); + window->widgets = window_custom_currency_widgets; + window->enabled_widgets = + (1 << WIDX_CLOSE) | + (1 << WIDX_RATE) | + (1 << WIDX_RATE_UP) | + (1 << WIDX_RATE_DOWN) | + (1 << WIDX_SYMBOL_TEXT) | + (1 << WIDX_AFFIX_DROPDOWN) | + (1 << WIDX_AFFIX_DROPDOWN_BUTTON); - window_init_scroll_widgets(window); - window->colours[0] = 22; - window->colours[1] = 22; - window->colours[2] = 22; + window_init_scroll_widgets(window); + window->colours[0] = 22; + window->colours[1] = 22; + window->colours[2] = 22; } @@ -124,164 +129,172 @@ void window_custom_currency_open() * * rct2: 0x006BB01B */ -static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget) +static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct_widget *widget) { - widget = &w->widgets[widgetIndex - 1]; + widget = &w->widgets[widgetIndex - 1]; - switch (widgetIndex) { + switch(widgetIndex) { - case WIDX_CLOSE: - window_close(w); - break; + case WIDX_CLOSE: + window_close(w); + break; - case WIDX_RATE_UP: - CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; - gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; - config_save_default(); - invalidate_money_widgets(); - break; + case WIDX_RATE_UP: + CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); + custom_currency_invalidate_money_widgets(); + break; - case WIDX_RATE_DOWN: - if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { - CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; - gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; - config_save_default(); - invalidate_money_widgets(); - } - break; + case WIDX_RATE_DOWN: + if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); + custom_currency_invalidate_money_widgets(); + } + break; - case WIDX_AFFIX_DROPDOWN_BUTTON: - gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; - gDropdownItemsArgs[0] = STR_PREFIX; + case WIDX_AFFIX_DROPDOWN_BUTTON: + gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[0] = STR_PREFIX; - gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL; - gDropdownItemsArgs[1] = STR_SUFFIX; + gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[1] = STR_SUFFIX; - window_dropdown_show_text_custom_width( - w->x + widget->left, - w->y + widget->top, - widget->bottom - widget->top + 1, - w->colours[1], - DROPDOWN_FLAG_STAY_OPEN, - 2, - widget->right - widget->left - 3 - ); + window_dropdown_show_text_custom_width( + w->x + widget->left, + w->y + widget->top, + widget->bottom - widget->top + 1, + w->colours[1], + DROPDOWN_FLAG_STAY_OPEN, + 2, + widget->right - widget->left - 3 + ); - if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { - dropdown_set_checked(0, true); - } else { - dropdown_set_checked(1, true); - } + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { + dropdown_set_checked(0, true); + } else { + dropdown_set_checked(1, true); + } - break; + break; - case WIDX_SYMBOL_TEXT: - window_text_input_raw_open( w, - WIDX_SYMBOL_TEXT, - STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, - STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, - CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - CURRENCY_SYMBOL_MAX_SIZE); - break; + case WIDX_SYMBOL_TEXT: + window_text_input_raw_open( + w, + WIDX_SYMBOL_TEXT, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + CURRENCY_SYMBOL_MAX_SIZE + ); + break; - } + } } /** * * rct2: 0x006BB076 */ -static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) +static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) { - if (dropdownIndex == -1) - return; + if(dropdownIndex == -1) + return; - if(widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON) { + if(widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON) { - if(dropdownIndex == 0) { - CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_PREFIX; - CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_PREFIX; - } else if(dropdownIndex == 1) { - CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_SUFFIX; - CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; - } + if(dropdownIndex == 0) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_PREFIX; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_PREFIX; + } else if(dropdownIndex == 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_SUFFIX; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; + } - gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; - config_save_default(); + gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; + config_save_default(); - invalidate_money_widgets(); + custom_currency_invalidate_money_widgets(); - } + } } -static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text) +static void custom_currency_window_text_input(struct rct_window *w, int windgetIndex, char *text) { - if(text != NULL) { - strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - text, - CURRENCY_SYMBOL_MAX_SIZE); + if(text != NULL) { + strncpy( + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + text, + CURRENCY_SYMBOL_MAX_SIZE + ); - strncpy(gConfigGeneral.custom_currency_symbol, - CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - CURRENCY_SYMBOL_MAX_SIZE); + strncpy( + gConfigGeneral.custom_currency_symbol, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + CURRENCY_SYMBOL_MAX_SIZE + ); - config_save_default(); - invalidate_money_widgets(); - } + config_save_default(); + custom_currency_invalidate_money_widgets(); + } } -static void invalidate_money_widgets() +static void custom_currency_invalidate_money_widgets() { - widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); - widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); +// widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); + widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); + } -/** - * - * rct2: 0x0066D321 - */ -static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi) + +static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi) { - int x, y; + int x, y; - set_format_arg(0, sint32, 100); + set_format_arg(0, sint32, 100); - window_draw_widgets(w, dpi); + window_draw_widgets(w, dpi); - x = w->x + 10; - y = w->y + 30; + x = w->x + 10; + y = w->y + 30; - gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); + gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); - sint32 baseExchange = CurrencyDescriptors[CURRENCY_POUNDS].rate; - set_format_arg(0, sint32, baseExchange); - gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x+200, y); + sint32 baseExchange = CurrencyDescriptors[CURRENCY_POUNDS].rate; + set_format_arg(0, sint32, baseExchange); + gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x + 200, y); - y += 20; + y += 20; - gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, NULL, w->colours[1], x, y); + gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, NULL, w->colours[1], x, y); - gfx_draw_string(dpi, - CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - w->colours[1], - w->x + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1, - w->y + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top); - - if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX){ - gfx_draw_string_left(dpi, - STR_PREFIX, - w, - w->colours[1], - w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, - w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); - } else { - gfx_draw_string_left(dpi, - STR_SUFFIX, - w, - w->colours[1], - w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, - w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); - } + gfx_draw_string( + dpi, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1, + w->y + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top); + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { + gfx_draw_string_left( + dpi, + STR_PREFIX, + w, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, + w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top + ); + } else { + gfx_draw_string_left( + dpi, + STR_SUFFIX, + w, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, + w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top + ); + } } diff --git a/src/windows/options.c b/src/windows/options.c index 7754c5e87a..7fbf42a769 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -1194,7 +1194,7 @@ static void window_options_dropdown(rct_window *w, int widgetIndex, int dropdown case WIDX_CURRENCY_DROPDOWN: if(dropdownIndex == CURRENCY_CUSTOM+1) { // Add 1 because the separator occupies a position gConfigGeneral.currency_format = (sint8)dropdownIndex-1; - window_custom_currency_open(); + custom_currency_window_open(); } else { gConfigGeneral.currency_format = (sint8)dropdownIndex; } From 6a3210b7b72c5c2e84156dfc1cfcf2914955688f Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Mon, 27 Jun 2016 23:06:10 +0200 Subject: [PATCH 19/26] Remove useless comments. --- src/windows/custom_currency.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index dfd3409a0f..b379376fdf 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -125,10 +125,6 @@ void custom_currency_window_open() -/** -* -* rct2: 0x006BB01B -*/ static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct_widget *widget) { widget = &w->widgets[widgetIndex - 1]; @@ -194,10 +190,6 @@ static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct } } -/** -* -* rct2: 0x006BB076 -*/ static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) { if(dropdownIndex == -1) From 036b09d91623d768a8c4d20d86c2bd1fdb1084c3 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Mon, 27 Jun 2016 23:15:30 +0200 Subject: [PATCH 20/26] Several fixes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit · Delete 1 remaining useless comment · Move static function definitions above window events definition · Replaced 'invalidate' function with window_invalidate_all() --- src/windows/custom_currency.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index b379376fdf..d4e5104538 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -19,10 +19,10 @@ */ #include "../config.h" -#include "dropdown.h" #include "../localisation/localisation.h" #include "../interface/widget.h" #include "../interface/window.h" +#include "dropdown.h" enum WINDOW_CUSTOM_CURRENCY_WIDGET_IDX { WIDX_BACKGROUND, @@ -49,6 +49,15 @@ rct_widget window_custom_currency_widgets[] = { { WIDGETS_END }, }; + +static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct_widget *widget); +static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int dropdownIndex); +static void custom_currency_window_text_input(struct rct_window *w, int windgetIndex, char *text); +static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi); + +static void custom_currency_invalidate_money_widgets(); + + static rct_window_event_list _windowCustomCurrencyEvents = { NULL, NULL, @@ -80,17 +89,7 @@ static rct_window_event_list _windowCustomCurrencyEvents = { NULL }; -static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct_widget *widget); -static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int dropdownIndex); -static void custom_currency_window_text_input(struct rct_window *w, int windgetIndex, char *text); -static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi); -static void custom_currency_invalidate_money_widgets(); - -/** - * - * rct2: 0x0066D2AC - */ void custom_currency_window_open() { rct_window* window; @@ -139,7 +138,7 @@ static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; config_save_default(); - custom_currency_invalidate_money_widgets(); + window_invalidate_all(); break; case WIDX_RATE_DOWN: @@ -147,7 +146,7 @@ static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; config_save_default(); - custom_currency_invalidate_money_widgets(); + window_invalidate_all(); } break; @@ -209,7 +208,7 @@ static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; config_save_default(); - custom_currency_invalidate_money_widgets(); + window_invalidate_all(); } } @@ -230,15 +229,13 @@ static void custom_currency_window_text_input(struct rct_window *w, int windgetI ); config_save_default(); - custom_currency_invalidate_money_widgets(); + window_invalidate_all(); } } static void custom_currency_invalidate_money_widgets() { -// widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); - widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); - + window_invalidate_all(); } From f61da894103d2d5169bd327db17b0a515d757312 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Mon, 27 Jun 2016 23:18:17 +0200 Subject: [PATCH 21/26] Delete useless 'invalidate' function. --- src/windows/custom_currency.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index d4e5104538..aeec7f9547 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -55,8 +55,6 @@ static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int static void custom_currency_window_text_input(struct rct_window *w, int windgetIndex, char *text); static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi); -static void custom_currency_invalidate_money_widgets(); - static rct_window_event_list _windowCustomCurrencyEvents = { NULL, @@ -233,11 +231,6 @@ static void custom_currency_window_text_input(struct rct_window *w, int windgetI } } -static void custom_currency_invalidate_money_widgets() -{ - window_invalidate_all(); -} - static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi) { From fc6f4929b7e6b87f8249bdf279a2303801bd62be Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 1 Jul 2016 21:37:54 +0200 Subject: [PATCH 22/26] Refactor for compliance with coding standards. --- src/windows/options.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/windows/options.c b/src/windows/options.c index 7fbf42a769..12b4e2e718 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -924,14 +924,14 @@ static void window_options_mousedown(int widgetIndex, rct_window*w, rct_widget* gDropdownItemsFormat[num_ordinary_currencies] = DROPDOWN_SEPARATOR; - gDropdownItemsFormat[num_ordinary_currencies+1] = STR_DROPDOWN_MENU_LABEL; - gDropdownItemsArgs[num_ordinary_currencies+1] = CurrencyDescriptors[CURRENCY_CUSTOM].stringId; + gDropdownItemsFormat[num_ordinary_currencies + 1] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[num_ordinary_currencies + 1] = CurrencyDescriptors[CURRENCY_CUSTOM].stringId; window_options_show_dropdown(w, widget, num_items); if(gConfigGeneral.currency_format == CURRENCY_CUSTOM){ - dropdown_set_checked(gConfigGeneral.currency_format+1, true); + dropdown_set_checked(gConfigGeneral.currency_format + 1, true); } else { dropdown_set_checked(gConfigGeneral.currency_format, true); } @@ -1192,8 +1192,8 @@ static void window_options_dropdown(rct_window *w, int widgetIndex, int dropdown window_options_update_height_markers(); break; case WIDX_CURRENCY_DROPDOWN: - if(dropdownIndex == CURRENCY_CUSTOM+1) { // Add 1 because the separator occupies a position - gConfigGeneral.currency_format = (sint8)dropdownIndex-1; + if(dropdownIndex == CURRENCY_CUSTOM + 1) { // Add 1 because the separator occupies a position + gConfigGeneral.currency_format = (sint8)dropdownIndex - 1; custom_currency_window_open(); } else { gConfigGeneral.currency_format = (sint8)dropdownIndex; From 4ebcf80a1aa922fadb019afe98b70b41e18a32b4 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 1 Jul 2016 21:59:56 +0200 Subject: [PATCH 23/26] Redefine what is a "large" currency. Decimals currencies does make sense when 10 < rate < 100, so it's neccesary to raise the limit before hiding decimals --- src/localisation/localisation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c index 7d95ea4822..0a18840a93 100644 --- a/src/localisation/localisation.c +++ b/src/localisation/localisation.c @@ -504,7 +504,7 @@ void format_currency_2dp(char **dest, long long value) } // Drop the pennies for "large" currencies - if (rate > 10) { + if (rate >= 100) { format_comma_separated_integer(dest, value / 100); } else { format_comma_separated_fixed_2dp(dest, value); From a29db378eb2e644c87e32e3f84c28e9cfda894bf Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Fri, 1 Jul 2016 23:52:33 +0200 Subject: [PATCH 24/26] Move loading custom currency-related preferences code into currency.c --- src/localisation/currency.c | 8 ++++++++ src/localisation/currency.h | 6 ++++++ src/openrct2.c | 8 +++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/localisation/currency.c b/src/localisation/currency.c index 50ad672573..20476a35bc 100644 --- a/src/localisation/currency.c +++ b/src/localisation/currency.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../config.h" #include "currency.h" #include "string_ids.h" @@ -36,3 +37,10 @@ currency_descriptor CurrencyDescriptors[CURRENCY_END] = { { "CNY", 100, CURRENCY_PREFIX, "CN\xC2\xA5", CURRENCY_PREFIX, "CNY", STR_CHINESE_YUAN }, // Chinese Yuan { "CTM", 10, CURRENCY_PREFIX, "Ctm", CURRENCY_PREFIX, "Ctm", STR_CUSTOM_CURRENCY }, // Customizable currency }; + +void currency_load_custom_currency_config() +{ + CurrencyDescriptors[CURRENCY_CUSTOM].rate = gConfigGeneral.custom_currency_rate; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = gConfigGeneral.custom_currency_affix; + strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, gConfigGeneral.custom_currency_symbol, CURRENCY_SYMBOL_MAX_SIZE); +} diff --git a/src/localisation/currency.h b/src/localisation/currency.h index b23b1ffe60..6f6318ded6 100644 --- a/src/localisation/currency.h +++ b/src/localisation/currency.h @@ -65,4 +65,10 @@ typedef struct currency_descriptor { // List of currency formats extern currency_descriptor CurrencyDescriptors[CURRENCY_END]; +/** + * Loads custom currency saved parameters into {@link CurrencyDescriptors}' + * custom currency entry + */ +void currency_load_custom_currency_config(); + #endif diff --git a/src/openrct2.c b/src/openrct2.c index 970616efe4..b68355332b 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -26,6 +26,7 @@ #include "interface/window.h" #include "interface/viewport.h" #include "intro.h" +#include "localisation/currency.h" #include "localisation/localisation.h" #include "network/http.h" #include "network/network.h" @@ -260,6 +261,8 @@ bool openrct2_initialise() } } + currency_load_custom_currency_config(); + return true; } @@ -323,11 +326,6 @@ void openrct2_launch() } #endif // DISABLE_NETWORK - // Set custom currency properties - CurrencyDescriptors[CURRENCY_CUSTOM].rate = gConfigGeneral.custom_currency_rate; - CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = gConfigGeneral.custom_currency_affix; - strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, gConfigGeneral.custom_currency_symbol, CURRENCY_SYMBOL_MAX_SIZE); - openrct2_loop(); } openrct2_dispose(); From 1fc75131a473a744e4b903f14994fc6f640eecc7 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Sat, 2 Jul 2016 12:12:44 +0200 Subject: [PATCH 25/26] Move call to load custom currency preferences to config_open_default() --- src/config.c | 2 ++ src/openrct2.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 4c076d04b3..d17577c8d7 100644 --- a/src/config.c +++ b/src/config.c @@ -479,6 +479,8 @@ bool config_open_default() return true; } + currency_load_custom_currency_config(); + return false; } diff --git a/src/openrct2.c b/src/openrct2.c index b68355332b..e3d478f8cd 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -261,8 +261,6 @@ bool openrct2_initialise() } } - currency_load_custom_currency_config(); - return true; } From 3745d3fa953bc50006a4ef7b8f67551e0ff4dd08 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Sat, 2 Jul 2016 12:14:01 +0200 Subject: [PATCH 26/26] Remove unused include --- src/openrct2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/openrct2.c b/src/openrct2.c index e3d478f8cd..fcfe3fee32 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -26,7 +26,6 @@ #include "interface/window.h" #include "interface/viewport.h" #include "intro.h" -#include "localisation/currency.h" #include "localisation/localisation.h" #include "network/http.h" #include "network/network.h"