2014-04-14 04:09:51 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (c) 2014 Ted John
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* This file is part of OpenRCT2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2014-04-14 04:09:51 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2014-04-14 04:09:51 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-10-06 18:36:58 +02:00
|
|
|
#include "../addresses.h"
|
2014-10-15 23:59:26 +02:00
|
|
|
#include "../input.h"
|
2014-10-06 18:36:58 +02:00
|
|
|
#include "../interface/widget.h"
|
|
|
|
#include "../interface/window.h"
|
2014-10-15 23:59:26 +02:00
|
|
|
#include "../localisation/localisation.h"
|
|
|
|
#include "../sprites.h"
|
|
|
|
#include "../world/map.h"
|
2015-06-01 17:02:09 +02:00
|
|
|
#include "../interface/themes.h"
|
2014-04-14 04:09:51 +02:00
|
|
|
|
2015-08-12 14:24:20 +02:00
|
|
|
#define MINIMUM_TOOL_SIZE 1
|
2015-08-12 14:07:16 +02:00
|
|
|
#define MAXIMUM_TOOL_SIZE 64
|
|
|
|
|
2014-05-19 21:10:32 +02:00
|
|
|
enum WINDOW_WATER_WIDGET_IDX {
|
2014-04-14 04:09:51 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_PREVIEW,
|
|
|
|
WIDX_DECREMENT,
|
|
|
|
WIDX_INCREMENT
|
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_water_widgets[] = {
|
|
|
|
{ WWT_FRAME, 0, 0, 75, 0, 76, -1, 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, 824, STR_CLOSE_WINDOW_TIP }, // close x button
|
|
|
|
{ WWT_IMGBTN, 0, 16, 59, 17, 48, SPR_LAND_TOOL_SIZE_0, STR_NONE }, // preview box
|
|
|
|
{ WWT_TRNBTN, 2, 17, 32, 18, 33, 0x20000000 | SPR_LAND_TOOL_DECREASE, STR_ADJUST_SMALLER_WATER_TIP }, // decrement size
|
|
|
|
{ WWT_TRNBTN, 2, 43, 58, 32, 47, 0x20000000 | SPR_LAND_TOOL_INCREASE, STR_ADJUST_LARGER_WATER_TIP }, // increment size
|
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int window_water_should_close();
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_close(rct_window *w);
|
|
|
|
static void window_water_mouseup(rct_window *w, int widgetIndex);
|
|
|
|
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);
|
|
|
|
static void window_water_textinput(rct_window *w, int 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 = {
|
2014-04-14 04:09:51 +02:00
|
|
|
window_water_close,
|
|
|
|
window_water_mouseup,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-04-14 04:09:51 +02:00
|
|
|
window_water_update,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-05-12 17:37:16 +02:00
|
|
|
window_water_textinput,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-04-14 04:09:51 +02:00
|
|
|
window_water_invalidate,
|
|
|
|
window_water_paint,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL
|
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
|
|
|
|
*/
|
|
|
|
void window_water_open()
|
|
|
|
{
|
|
|
|
rct_window* window;
|
|
|
|
|
|
|
|
// Check if window is already open
|
2014-10-16 03:02:43 +02:00
|
|
|
if (window_find_by_class(WC_WATER) != NULL)
|
2014-04-14 04:09:51 +02:00
|
|
|
return;
|
|
|
|
|
2015-06-13 23:16:14 +02:00
|
|
|
window = window_create(
|
2015-07-05 16:57:01 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16) - 76,
|
2015-06-13 23:16:14 +02:00
|
|
|
29,
|
|
|
|
76,
|
|
|
|
77,
|
2015-07-10 02:39:16 +02:00
|
|
|
&window_water_events,
|
2015-06-13 23:16:14 +02:00
|
|
|
WC_WATER,
|
|
|
|
0
|
|
|
|
);
|
2014-04-14 04:09:51 +02:00
|
|
|
window->widgets = window_water_widgets;
|
2015-05-12 17:37:16 +02:00
|
|
|
window->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_DECREMENT) | (1 << WIDX_INCREMENT) | (1 << WIDX_PREVIEW);
|
2014-04-14 04:09:51 +02:00
|
|
|
window_init_scroll_widgets(window);
|
|
|
|
window_push_others_below(window);
|
|
|
|
|
2014-05-23 13:15:08 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_WATER_RAISE_COST, uint32) = MONEY32_UNDEFINED;
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_WATER_LOWER_COST, uint32) = MONEY32_UNDEFINED;
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6B65
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_close(rct_window *w)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
|
|
|
// If the tool wasn't changed, turn tool off
|
|
|
|
if (!window_water_should_close())
|
2014-04-30 17:57:27 +02:00
|
|
|
tool_cancel();
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6B4E
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_mouseup(rct_window *w, int widgetIndex)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
|
|
|
switch (widgetIndex) {
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
case WIDX_DECREMENT:
|
|
|
|
// Decrement land tool size
|
2015-08-12 14:07:16 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) = max(MINIMUM_TOOL_SIZE, RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16)-1);
|
2014-04-14 04:09:51 +02:00
|
|
|
|
|
|
|
// Invalidate the window
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
|
|
|
case WIDX_INCREMENT:
|
|
|
|
// Increment land tool size
|
2015-08-12 14:07:16 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) = min(MAXIMUM_TOOL_SIZE, RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16)+1);
|
2014-04-14 04:09:51 +02:00
|
|
|
|
|
|
|
// Invalidate the window
|
|
|
|
window_invalidate(w);
|
|
|
|
break;
|
2015-05-12 17:37:16 +02:00
|
|
|
case WIDX_PREVIEW:
|
|
|
|
window_water_inputsize(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_textinput(rct_window *w, int widgetIndex, char *text)
|
2015-05-12 17:37:16 +02:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
char* end;
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
if (widgetIndex != WIDX_PREVIEW || text == NULL)
|
2015-05-12 17:37:16 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
size = strtol(text, &end, 10);
|
2015-05-12 20:34:34 +02:00
|
|
|
if (*end == '\0') {
|
2015-08-12 14:07:16 +02:00
|
|
|
size = max(MINIMUM_TOOL_SIZE,size);
|
|
|
|
size = min(MAXIMUM_TOOL_SIZE,size);
|
2015-05-12 17:37:16 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) = size;
|
2015-08-11 23:09:39 +02:00
|
|
|
|
2015-05-12 17:37:16 +02:00
|
|
|
window_invalidate(w);
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-12 17:37:16 +02:00
|
|
|
static void window_water_inputsize(rct_window *w)
|
|
|
|
{
|
2015-12-31 09:16:44 +01:00
|
|
|
TextInputDescriptionArgs[0] = MINIMUM_TOOL_SIZE;
|
|
|
|
TextInputDescriptionArgs[1] = MAXIMUM_TOOL_SIZE;
|
2015-05-13 17:38:44 +02:00
|
|
|
window_text_input_open(w, WIDX_PREVIEW, 5128, 5129, STR_NONE, STR_NONE, 3);
|
2015-05-12 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
2014-04-18 20:00:27 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6BCE
|
|
|
|
*/
|
2014-05-19 19:47:14 +02:00
|
|
|
static void window_water_update(rct_window *w)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
|
|
|
// Close window if another tool is open
|
|
|
|
if (window_water_should_close())
|
|
|
|
window_close(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6AB8
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_invalidate(rct_window *w)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
2015-05-29 18:04:53 +02:00
|
|
|
colour_scheme_update(w);
|
2014-04-14 04:09:51 +02:00
|
|
|
|
|
|
|
// Set the preview image button to be pressed down
|
|
|
|
w->pressed_widgets |= (1 << WIDX_PREVIEW);
|
|
|
|
|
|
|
|
// Update the preview image
|
2014-07-16 04:41:12 +02:00
|
|
|
//window_water_widgets[WIDX_PREVIEW].image = SPR_LAND_TOOL_SIZE_0 + RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16);
|
|
|
|
|
|
|
|
window_water_widgets[WIDX_PREVIEW].image = RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) <= 7 ?
|
|
|
|
SPR_LAND_TOOL_SIZE_0 + RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) :
|
|
|
|
0xFFFFFFFF;
|
|
|
|
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x006E6ACF
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_water_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2014-04-14 04:09:51 +02:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
2014-07-16 04:41:12 +02:00
|
|
|
x = w->x + (window_water_widgets[WIDX_PREVIEW].left + window_water_widgets[WIDX_PREVIEW].right) / 2;
|
|
|
|
y = w->y + (window_water_widgets[WIDX_PREVIEW].top + window_water_widgets[WIDX_PREVIEW].bottom) / 2;
|
2014-04-14 04:09:51 +02:00
|
|
|
|
|
|
|
window_draw_widgets(w, dpi);
|
2015-08-11 23:09:39 +02:00
|
|
|
// Draw number for tool sizes bigger than 7
|
2014-07-16 04:41:12 +02:00
|
|
|
if (RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) > 7) {
|
2015-08-01 17:40:15 +02:00
|
|
|
gfx_draw_string_centred(dpi, STR_LAND_TOOL_SIZE_VALUE, x, y - 2, 0, &RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16));
|
2014-07-16 04:41:12 +02:00
|
|
|
}
|
|
|
|
y = w->y + window_water_widgets[WIDX_PREVIEW].bottom + 5;
|
|
|
|
|
2014-04-14 04:09:51 +02:00
|
|
|
|
|
|
|
// Draw raise cost amount
|
2014-04-18 20:00:27 +02:00
|
|
|
x = (window_water_widgets[WIDX_PREVIEW].left + window_water_widgets[WIDX_PREVIEW].right) / 2 + w->x;
|
|
|
|
y = window_water_widgets[WIDX_PREVIEW].bottom + w->y + 5;
|
2014-05-23 13:15:08 +02:00
|
|
|
if (RCT2_GLOBAL(RCT2_ADDRESS_WATER_RAISE_COST, uint32) != MONEY32_UNDEFINED && RCT2_GLOBAL(RCT2_ADDRESS_WATER_RAISE_COST, uint32) != 0)
|
2014-05-13 23:37:45 +02:00
|
|
|
gfx_draw_string_centred(dpi, 984, x, y, 0, (void*)RCT2_ADDRESS_WATER_RAISE_COST);
|
2014-04-14 04:09:51 +02:00
|
|
|
y += 10;
|
|
|
|
|
|
|
|
// Draw lower cost amount
|
2014-05-23 13:15:08 +02:00
|
|
|
if (RCT2_GLOBAL(RCT2_ADDRESS_WATER_LOWER_COST, uint32) != MONEY32_UNDEFINED && RCT2_GLOBAL(RCT2_ADDRESS_WATER_LOWER_COST, uint32) != 0)
|
2014-05-13 23:37:45 +02:00
|
|
|
gfx_draw_string_centred(dpi, 985, x, y, 0, (void*)RCT2_ADDRESS_WATER_LOWER_COST);
|
2014-07-16 04:41:12 +02:00
|
|
|
|
|
|
|
|
2014-04-14 04:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* rct2: 0x0066D125
|
|
|
|
*/
|
|
|
|
static int window_water_should_close()
|
|
|
|
{
|
2016-01-04 23:53:03 +01:00
|
|
|
if (!(gInputFlags & INPUT_FLAG_TOOL_ACTIVE))
|
2014-04-14 04:09:51 +02:00
|
|
|
return 1;
|
2016-04-15 19:26:47 +02:00
|
|
|
if (gCurrentToolWidget.window_classification != WC_TOP_TOOLBAR)
|
2014-04-14 04:09:51 +02:00
|
|
|
return 1;
|
2016-04-15 19:26:47 +02:00
|
|
|
if (gCurrentToolWidget.widget_index != 8)
|
2014-04-14 04:09:51 +02:00
|
|
|
return 1;
|
|
|
|
return 0;
|
2014-04-21 11:27:48 +02:00
|
|
|
}
|