2014-04-14 04:09:51 +02:00
|
|
|
/*****************************************************************************
|
2019-03-17 08:16:15 +01:00
|
|
|
* Copyright (c) 2014-2019 OpenRCT2 developers
|
2014-04-14 04:09:51 +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
|
2014-04-14 04:09:51 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-04-14 04:09:51 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-08-12 13:50:40 +02:00
|
|
|
#include <algorithm>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/LandTool.h>
|
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2017-08-12 23:06:12 +02:00
|
|
|
#include <openrct2/Context.h>
|
2018-03-19 23:28:40 +01:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2019-04-20 18:10:15 +02:00
|
|
|
#include <openrct2/world/Park.h>
|
2014-04-14 04:09:51 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-05-19 21:10:32 +02:00
|
|
|
enum WINDOW_WATER_WIDGET_IDX {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_PREVIEW,
|
|
|
|
WIDX_DECREMENT,
|
|
|
|
WIDX_INCREMENT
|
2014-04-14 04:09:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_water_widgets[] = {
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WWT_FRAME, 0, 0, 75, 0, 76, 0xFFFFFFFF, STR_NONE }, // panel / background
|
|
|
|
{ WWT_CAPTION, 0, 1, 74, 1, 14, STR_WATER, STR_WINDOW_TITLE_TIP }, // title bar
|
|
|
|
{ WWT_CLOSEBOX, 0, 63, 73, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button
|
|
|
|
{ WWT_IMGBTN, 0, 16, 59, 17, 48, SPR_LAND_TOOL_SIZE_0, STR_NONE }, // preview box
|
2017-07-20 20:56:29 +02:00
|
|
|
{ WWT_TRNBTN, 2, 17, 32, 18, 33, IMAGE_TYPE_REMAP | SPR_LAND_TOOL_DECREASE, STR_ADJUST_SMALLER_WATER_TIP }, // decrement size
|
|
|
|
{ WWT_TRNBTN, 2, 43, 58, 32, 47, IMAGE_TYPE_REMAP | SPR_LAND_TOOL_INCREASE, STR_ADJUST_LARGER_WATER_TIP }, // increment size
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END },
|
2014-04-14 04:09:51 +02:00
|
|
|
};
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_close(rct_window *w);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_water_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2017-07-14 19:20:42 +02:00
|
|
|
static void window_water_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget *widget);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_update(rct_window *w);
|
|
|
|
static void window_water_invalidate(rct_window *w);
|
|
|
|
static void window_water_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_water_textinput(rct_window *w, rct_widgetindex widgetIndex, char *text);
|
2015-05-12 17:37:16 +02:00
|
|
|
static void window_water_inputsize(rct_window *w);
|
2014-04-14 04:09:51 +02:00
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static rct_window_event_list window_water_events = {
|
2017-06-06 23:24:18 +02:00
|
|
|
window_water_close,
|
|
|
|
window_water_mouseup,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
2017-07-04 01:49:37 +02:00
|
|
|
window_water_mousedown,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_water_update,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_water_textinput,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2017-06-06 23:24:18 +02:00
|
|
|
window_water_invalidate,
|
|
|
|
window_water_paint,
|
2017-08-15 10:07:44 +02:00
|
|
|
nullptr
|
2014-04-14 04:09:51 +02:00
|
|
|
};
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2014-04-14 04:09:51 +02:00
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-04-14 04:09:51 +02:00
|
|
|
* rct2: 0x006E6A40
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* window_water_open()
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
rct_window* window;
|
|
|
|
|
|
|
|
// Check if window is already open
|
2017-08-12 23:06:12 +02:00
|
|
|
window = window_find_by_class(WC_WATER);
|
|
|
|
if (window != nullptr)
|
|
|
|
return window;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2019-10-19 13:07:03 +02:00
|
|
|
window = window_create(ScreenCoordsXY(context_get_width() - 76, 29), 76, 77, &window_water_events, WC_WATER, 0);
|
2017-06-06 23:24:18 +02:00
|
|
|
window->widgets = window_water_widgets;
|
|
|
|
window->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_DECREMENT) | (1 << WIDX_INCREMENT) | (1 << WIDX_PREVIEW);
|
2017-07-04 01:49:37 +02:00
|
|
|
window->hold_down_widgets = (1 << WIDX_INCREMENT) | (1 << WIDX_DECREMENT);
|
2017-06-06 23:24:18 +02:00
|
|
|
window_init_scroll_widgets(window);
|
|
|
|
window_push_others_below(window);
|
|
|
|
|
2017-06-22 20:49:13 +02:00
|
|
|
gLandToolSize = 1;
|
2017-06-06 23:24:18 +02:00
|
|
|
gWaterToolRaiseCost = MONEY32_UNDEFINED;
|
|
|
|
gWaterToolLowerCost = MONEY32_UNDEFINED;
|
2017-08-12 23:06:12 +02:00
|
|
|
|
|
|
|
return window;
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6B65
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_close(rct_window* w)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// If the tool wasn't changed, turn tool off
|
|
|
|
if (water_tool_is_active())
|
|
|
|
tool_cancel();
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6B4E
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
case WIDX_PREVIEW:
|
|
|
|
window_water_inputsize(w);
|
|
|
|
break;
|
2017-07-04 01:49:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget)
|
2017-07-04 01:49:37 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_DECREMENT:
|
|
|
|
// Decrement land tool size
|
|
|
|
gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1);
|
|
|
|
|
|
|
|
// Invalidate the window
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case WIDX_INCREMENT:
|
|
|
|
// Increment land tool size
|
|
|
|
gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1);
|
|
|
|
|
|
|
|
// Invalidate the window
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-05-12 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_textinput(rct_window* w, rct_widgetindex widgetIndex, char* text)
|
2015-05-12 17:37:16 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t size;
|
2017-06-06 23:24:18 +02:00
|
|
|
char* end;
|
2015-05-12 17:37:16 +02:00
|
|
|
|
2017-08-15 10:07:44 +02:00
|
|
|
if (widgetIndex != WIDX_PREVIEW || text == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2015-05-12 17:37:16 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
size = strtol(text, &end, 10);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (*end == '\0')
|
|
|
|
{
|
|
|
|
size = std::max(MINIMUM_TOOL_SIZE, size);
|
|
|
|
size = std::min(MAXIMUM_TOOL_SIZE, size);
|
2017-06-06 23:24:18 +02:00
|
|
|
gLandToolSize = size;
|
2015-08-11 23:09:39 +02:00
|
|
|
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_inputsize(rct_window* w)
|
2015-05-12 17:37:16 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
TextInputDescriptionArgs[0] = MINIMUM_TOOL_SIZE;
|
|
|
|
TextInputDescriptionArgs[1] = MAXIMUM_TOOL_SIZE;
|
|
|
|
window_text_input_open(w, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, STR_NONE, STR_NONE, 3);
|
2015-05-12 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
2014-04-18 20:00:27 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6BCE
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_update(rct_window* w)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Close window if another tool is open
|
|
|
|
if (!water_tool_is_active())
|
|
|
|
window_close(w);
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6AB8
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_invalidate(rct_window* w)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Set the preview image button to be pressed down
|
|
|
|
w->pressed_widgets |= (1 << WIDX_PREVIEW);
|
2014-04-14 04:09:51 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Update the preview image
|
2017-06-22 20:49:13 +02:00
|
|
|
window_water_widgets[WIDX_PREVIEW].image = land_tool_size_to_sprite_index(gLandToolSize);
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6ACF
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_water_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t x, y;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-03-01 20:32:35 +01:00
|
|
|
x = w->windowPos.x + (window_water_widgets[WIDX_PREVIEW].left + window_water_widgets[WIDX_PREVIEW].right) / 2;
|
|
|
|
y = w->windowPos.y + (window_water_widgets[WIDX_PREVIEW].top + window_water_widgets[WIDX_PREVIEW].bottom) / 2;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window_draw_widgets(w, dpi);
|
|
|
|
// Draw number for tool sizes bigger than 7
|
2018-06-22 23:21:44 +02:00
|
|
|
if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gfx_draw_string_centred(dpi, STR_LAND_TOOL_SIZE_VALUE, x, y - 2, COLOUR_BLACK, &gLandToolSize);
|
|
|
|
}
|
|
|
|
|
2019-04-20 18:10:15 +02:00
|
|
|
if (!(gParkFlags & PARK_FLAGS_NO_MONEY))
|
|
|
|
{
|
|
|
|
// Draw raise cost amount
|
2020-03-01 20:32:35 +01:00
|
|
|
x = (window_water_widgets[WIDX_PREVIEW].left + window_water_widgets[WIDX_PREVIEW].right) / 2 + w->windowPos.x;
|
|
|
|
y = window_water_widgets[WIDX_PREVIEW].bottom + w->windowPos.y + 5;
|
2019-04-20 18:10:15 +02:00
|
|
|
if (gWaterToolRaiseCost != MONEY32_UNDEFINED && gWaterToolRaiseCost != 0)
|
|
|
|
gfx_draw_string_centred(dpi, STR_RAISE_COST_AMOUNT, x, y, COLOUR_BLACK, &gWaterToolRaiseCost);
|
|
|
|
y += 10;
|
|
|
|
|
|
|
|
// Draw lower cost amount
|
|
|
|
if (gWaterToolLowerCost != MONEY32_UNDEFINED && gWaterToolLowerCost != 0)
|
|
|
|
gfx_draw_string_centred(dpi, STR_LOWER_COST_AMOUNT, x, y, COLOUR_BLACK, &gWaterToolLowerCost);
|
|
|
|
}
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|