2016-06-24 17:57:41 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2016-06-24 17:57:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-06-24 17:57:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-06-24 17:57:41 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Dropdown.h>
|
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2017-08-06 21:20:05 +02:00
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/config/Config.h>
|
|
|
|
#include <openrct2/drawing/Drawing.h>
|
|
|
|
#include <openrct2/interface/Colour.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2017-12-13 13:02:24 +01:00
|
|
|
#include <openrct2/util/Util.h>
|
2016-06-24 17:57:41 +02:00
|
|
|
|
2020-05-05 22:26:14 +02:00
|
|
|
static constexpr const rct_string_id WINDOW_TITLE = STR_CUSTOM_CURRENCY_WINDOW_TITLE;
|
|
|
|
static constexpr const int32_t WH = 100;
|
|
|
|
static constexpr const int32_t WW = 400;
|
2019-10-19 04:02:31 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2016-06-24 17:57:41 +02:00
|
|
|
enum WINDOW_CUSTOM_CURRENCY_WIDGET_IDX {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_RATE,
|
|
|
|
WIDX_RATE_UP,
|
|
|
|
WIDX_RATE_DOWN,
|
|
|
|
WIDX_SYMBOL_TEXT,
|
|
|
|
WIDX_AFFIX_DROPDOWN,
|
|
|
|
WIDX_AFFIX_DROPDOWN_BUTTON,
|
2016-06-24 17:57:41 +02:00
|
|
|
};
|
|
|
|
|
2017-10-09 17:13:14 +02:00
|
|
|
static rct_widget window_custom_currency_widgets[] = {
|
2020-05-09 16:44:21 +02:00
|
|
|
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
|
2020-08-29 04:31:31 +02:00
|
|
|
MakeSpinnerWidgets({100, 30}, {101, 11}, WWT_SPINNER, WindowColour::Secondary, STR_CHEAT_CURRENCY_FORMAT), // NB: 3 widgets
|
|
|
|
MakeWidget ({120, 50}, { 81, 11}, WWT_BUTTON, WindowColour::Secondary, STR_EMPTY ),
|
|
|
|
MakeWidget ({220, 50}, {131, 11}, WWT_DROPDOWN, WindowColour::Secondary ),
|
|
|
|
MakeWidget ({339, 51}, { 11, 9}, WWT_BUTTON, WindowColour::Secondary, STR_DROPDOWN_GLYPH ),
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END },
|
2016-06-24 17:57:41 +02:00
|
|
|
};
|
|
|
|
|
2016-06-27 23:15:30 +02:00
|
|
|
|
2017-07-03 23:09:46 +02:00
|
|
|
static void custom_currency_window_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget *widget);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void custom_currency_window_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2018-06-20 17:28:51 +02:00
|
|
|
static void custom_currency_window_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void custom_currency_window_text_input(struct rct_window *w, rct_widgetindex widgetIndex, char *text);
|
2016-06-27 23:15:30 +02:00
|
|
|
static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
|
|
|
|
|
|
|
|
2016-06-27 23:03:41 +02:00
|
|
|
static rct_window_event_list _windowCustomCurrencyEvents = {
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
custom_currency_window_mouseup,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
custom_currency_window_mousedown,
|
|
|
|
custom_currency_window_dropdown,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
custom_currency_window_text_input,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
custom_currency_window_paint,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr
|
2016-06-24 17:57:41 +02:00
|
|
|
};
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2016-06-24 17:57:41 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* custom_currency_window_open()
|
2016-06-24 17:57:41 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window* window;
|
|
|
|
|
|
|
|
// Check if window is already open
|
|
|
|
window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (window != nullptr)
|
2017-08-06 05:22:00 +02:00
|
|
|
return window;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
window = window_create_centred(400, 100, &_windowCustomCurrencyEvents, WC_CUSTOM_CURRENCY_CONFIG, 0);
|
2017-06-06 23:24:18 +02:00
|
|
|
window->widgets = window_custom_currency_widgets;
|
2018-06-22 23:21:44 +02:00
|
|
|
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);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window->hold_down_widgets = (1 << WIDX_RATE_UP) | (1 << WIDX_RATE_DOWN);
|
|
|
|
window_init_scroll_widgets(window);
|
|
|
|
window->colours[0] = COLOUR_LIGHT_BROWN;
|
|
|
|
window->colours[1] = COLOUR_LIGHT_BROWN;
|
|
|
|
window->colours[2] = COLOUR_LIGHT_BROWN;
|
2017-08-06 05:22:00 +02:00
|
|
|
|
|
|
|
return window;
|
2016-06-24 17:57:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void custom_currency_window_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget)
|
2016-06-24 20:15:45 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
widget = &w->widgets[widgetIndex - 1];
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
case WIDX_RATE_UP:
|
|
|
|
CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1;
|
2017-06-06 23:24:18 +02:00
|
|
|
gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate;
|
|
|
|
config_save_default();
|
|
|
|
window_invalidate_all();
|
2018-06-22 23:21:44 +02:00
|
|
|
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();
|
|
|
|
window_invalidate_all();
|
|
|
|
}
|
|
|
|
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(
|
2020-06-25 03:44:00 +02:00
|
|
|
{ w->windowPos.x + widget->left, w->windowPos.y + widget->top }, widget->height() + 1, w->colours[1], 0,
|
|
|
|
DROPDOWN_FLAG_STAY_OPEN, 2, widget->width() - 3);
|
2018-06-22 23:21:44 +02:00
|
|
|
|
2020-08-04 22:33:06 +02:00
|
|
|
if (CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CurrencyAffix::Prefix)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
|
|
|
dropdown_set_checked(0, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dropdown_set_checked(1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WIDX_SYMBOL_TEXT:
|
|
|
|
window_text_input_raw_open(
|
2018-07-21 13:51:54 +02:00
|
|
|
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);
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-06-24 17:57:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void custom_currency_window_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2016-07-09 09:39:45 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_RATE:
|
|
|
|
window_text_input_open(
|
2018-07-21 13:51:54 +02:00
|
|
|
w, WIDX_RATE, STR_RATE_INPUT_TITLE, STR_RATE_INPUT_DESC, STR_FORMAT_INTEGER,
|
2020-04-18 13:32:48 +02:00
|
|
|
static_cast<uint32_t>(CurrencyDescriptors[CURRENCY_CUSTOM].rate), CURRENCY_RATE_MAX_NUM_DIGITS);
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-07-09 09:39:45 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void custom_currency_window_dropdown([[maybe_unused]] rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex)
|
2016-06-24 20:15:45 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
if (dropdownIndex == -1)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2016-06-24 17:57:41 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
if (widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON)
|
|
|
|
{
|
|
|
|
if (dropdownIndex == 0)
|
|
|
|
{
|
2020-08-04 22:33:06 +02:00
|
|
|
CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CurrencyAffix::Prefix;
|
|
|
|
CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CurrencyAffix::Prefix;
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else if (dropdownIndex == 1)
|
|
|
|
{
|
2020-08-04 22:33:06 +02:00
|
|
|
CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CurrencyAffix::Suffix;
|
|
|
|
CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CurrencyAffix::Suffix;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-06-24 17:57:41 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode;
|
|
|
|
config_save_default();
|
2016-06-24 19:57:17 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
window_invalidate_all();
|
|
|
|
}
|
2016-06-24 17:57:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void custom_currency_window_text_input([[maybe_unused]] struct rct_window* w, rct_widgetindex widgetIndex, char* text)
|
2016-06-24 20:15:45 +02:00
|
|
|
{
|
2017-08-15 10:07:44 +02:00
|
|
|
if (text == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t rate;
|
2017-06-06 23:24:18 +02:00
|
|
|
char* end;
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_SYMBOL_TEXT:
|
|
|
|
safe_strcpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, text, CURRENCY_SYMBOL_MAX_SIZE);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
safe_strcpy(
|
2018-07-21 13:51:54 +02:00
|
|
|
gConfigGeneral.custom_currency_symbol, CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode,
|
2018-06-22 23:21:44 +02:00
|
|
|
CURRENCY_SYMBOL_MAX_SIZE);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
config_save_default();
|
|
|
|
window_invalidate_all();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WIDX_RATE:
|
|
|
|
rate = strtol(text, &end, 10);
|
|
|
|
if (*end == '\0')
|
|
|
|
{
|
|
|
|
CurrencyDescriptors[CURRENCY_CUSTOM].rate = rate;
|
|
|
|
gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate;
|
|
|
|
config_save_default();
|
|
|
|
window_invalidate_all();
|
|
|
|
}
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-06-24 17:57:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void custom_currency_window_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2016-06-27 23:03:41 +02:00
|
|
|
{
|
2020-05-14 02:29:39 +02:00
|
|
|
auto ft = Formatter::Common();
|
|
|
|
ft.Add<int32_t>(100);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window_draw_widgets(w, dpi);
|
|
|
|
|
2020-06-20 05:22:01 +02:00
|
|
|
auto screenCoords = w->windowPos + ScreenCoordsXY{ 10, 30 };
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-06-20 05:22:01 +02:00
|
|
|
gfx_draw_string_left(dpi, STR_RATE, nullptr, w->colours[1], screenCoords);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t baseExchange = CurrencyDescriptors[CURRENCY_POUNDS].rate;
|
2020-05-14 02:29:39 +02:00
|
|
|
ft = Formatter::Common();
|
|
|
|
ft.Add<int32_t>(baseExchange);
|
2020-05-10 14:49:15 +02:00
|
|
|
gfx_draw_string_left(
|
2020-06-20 05:22:01 +02:00
|
|
|
dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], screenCoords + ScreenCoordsXY{ 200, 0 });
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-05-10 14:49:15 +02:00
|
|
|
screenCoords.y += 20;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-06-20 05:22:01 +02:00
|
|
|
gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, nullptr, w->colours[1], screenCoords);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-06-20 05:22:01 +02:00
|
|
|
screenCoords = w->windowPos
|
|
|
|
+ ScreenCoordsXY{ window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1,
|
|
|
|
window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top };
|
2020-05-10 14:49:15 +02:00
|
|
|
|
|
|
|
gfx_draw_string(dpi, CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, w->colours[1], screenCoords);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-08-04 22:33:06 +02:00
|
|
|
if (CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CurrencyAffix::Prefix)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_draw_string_left(
|
2020-06-20 05:22:01 +02:00
|
|
|
dpi, STR_PREFIX, w, w->colours[1],
|
|
|
|
w->windowPos
|
|
|
|
+ ScreenCoordsXY{ window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1,
|
|
|
|
window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top });
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_draw_string_left(
|
2020-06-20 05:22:01 +02:00
|
|
|
dpi, STR_SUFFIX, w, w->colours[1],
|
|
|
|
w->windowPos
|
|
|
|
+ ScreenCoordsXY{ window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1,
|
|
|
|
window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top });
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-06-24 17:57:41 +02:00
|
|
|
}
|