diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 3f8d3d5094..175bfdf74d 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -79,6 +79,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index 819aa8884e..ffddfa3167 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -206,6 +206,9 @@ Windows + + Windows + diff --git a/src/game.c b/src/game.c index 53bc5f8ae3..c6091df352 100644 --- a/src/game.c +++ b/src/game.c @@ -25,6 +25,8 @@ #include "peep.h" #include "window.h" +void game_handle_input(); + /** * * rct2: 0x0066B5C0 (part of 0x0066B3E8) @@ -97,7 +99,7 @@ void game_update() // Input RCT2_GLOBAL(0x0141F568, uint8) = RCT2_GLOBAL(0x0013CA740, uint8); - RCT2_CALLPROC_EBPSAFE(0x006EA627); // window_manager_handle_input(); + game_handle_input(); RCT2_CALLPROC_EBPSAFE(0x006838BD); RCT2_CALLPROC_EBPSAFE(0x00684218); @@ -155,4 +157,100 @@ void game_logic_update() RCT2_CALLPROC_X(0x0066792F, 0, _bx, 0, _dx, 0, 0, 0); } +} + +static void game_handle_input_mouse(); + +/** + * + * rct2: 0x006EA627 + */ +void game_handle_input() +{ + rct_window *w; + + if (RCT2_GLOBAL(0x009DEA64, uint16) & 2) { + RCT2_GLOBAL(0x009DEA64, uint16) &= ~2; + RCT2_CALLPROC_X(0x006677F2, 0, 1, 0, 0, 5, 2, 0); + } + + if (RCT2_GLOBAL(0x009ABDF2, uint8) != 0) { + for (w = RCT2_ADDRESS(RCT2_ADDRESS_WINDOW_LIST, rct_window); w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) + RCT2_CALLPROC_X(w->event_handlers[WE_UNKNOWN_07], 0, 0, 0, 0, w, 0, 0); + + RCT2_CALLPROC_EBPSAFE(0x006EA73F); + RCT2_CALLPROC_EBPSAFE(0x006E8346); // update_cursor_position + + { + int eax, ebx, ecx, edx, esi, edi, ebp; + + for (;;) { + RCT2_CALLFUNC_X(0x006E83C7, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + if (ecx == 0) + break; + + RCT2_CALLPROC_X(0x006E8655, eax, ebx, ecx, 0, 0, 0, 0); // window_process_mouse_input + } + + if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 5)) { + RCT2_CALLPROC_X(0x006E8655, eax, ebx, 0, 0, 0, 0, 0); // window_process_mouse_input + } else if (eax != 0x80000000) { + eax = clamp(0, eax, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) - 1); + ebx = clamp(0, ebx, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, sint16) - 1); + + RCT2_CALLPROC_X(0x006E8655, eax, ebx, 0, 0, 0, 0, 0); // window_process_mouse_input + RCT2_CALLPROC_X(0x006ED833, eax, ebx, 0, 0, 0, 0, 0); + RCT2_CALLPROC_EBPSAFE(0x006ED801); + } + } + } + + for (w = RCT2_ADDRESS(RCT2_ADDRESS_WINDOW_LIST, rct_window); w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) + RCT2_CALLPROC_X(w->event_handlers[WE_UNKNOWN_08], 0, 0, 0, 0, w, 0, 0); +} + +/** + * + * rct2: 0x006E8655 + */ +static void game_handle_input_mouse(int x, int y, int state) +{ + rct_window *w; + + w = window_find_from_point(x, y); + if (w != NULL) + window_find_widget_from_point(w, x, y); + + switch (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8)) { + case INPUT_STATE_RESET: + RCT2_CALLPROC_X(0x006E9203, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_NORMAL: + RCT2_CALLPROC_X(0x006E9203, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_WIDGET_PRESSED: + RCT2_CALLPROC_X(0x006E8DA7, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_DRAGGING: + RCT2_CALLPROC_X(0x006E8C5C, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_VIEWPORT_LEFT: + RCT2_CALLPROC_X(0x006E89C6, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_DROPDOWN_ACTIVE: + RCT2_CALLPROC_X(0x006E8DA7, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_VIEWPORT_RIGHT: + RCT2_CALLPROC_X(0x006E87B4, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_SCROLL_LEFT: + RCT2_CALLPROC_X(0x006E8676, x, y, state, -1, w, 0, 0); + break; + case INPUT_STATE_RESIZING: + RCT2_CALLPROC_X(0x006E8B46, x, y, state, -1, w, 0, 0); + break; + case 9: + RCT2_CALLPROC_X(0x006E8ACB, x, y, state, -1, w, 0, 0); + break; + } } \ No newline at end of file diff --git a/src/title.c b/src/title.c index d63b3db46c..f23be3b851 100644 --- a/src/title.c +++ b/src/title.c @@ -221,7 +221,7 @@ static void title_update_showcase() _scriptWaitCounter--; } - +void game_handle_input(); void title_update() { int tmp; @@ -251,8 +251,9 @@ void title_update() RCT2_GLOBAL(0x01388698, uint16)++; // Input - RCT2_CALLPROC_X(0x00667919, 1, 0, 0, 0, 0, 0, 0); // read_input(1) - RCT2_CALLPROC_EBPSAFE(0x006EA627); // window_manager_handle_input(); + // RCT2_CALLPROC_X(0x00667919, 1, 0, 0, 0, 0, 0, 0); // read_input(1) + // RCT2_CALLPROC_EBPSAFE(0x006EA627); // window_manager_handle_input(); + game_handle_input(); RCT2_CALLPROC_EBPSAFE(0x006838BD); RCT2_CALLPROC_EBPSAFE(0x00684218); diff --git a/src/window.c b/src/window.c index b613e01ce6..f7fdaf0055 100644 --- a/src/window.c +++ b/src/window.c @@ -261,6 +261,79 @@ rct_window *window_find_by_id(rct_windowclass cls, rct_windownumber number) return NULL; } +/** + * + * rct2: 0x006EA845 + */ +rct_window *window_find_from_point(int x, int y) +{ + rct_window *w, *w2; + rct_widget *widget; + int widget_index; + + for (w = RCT2_LAST_WINDOW; w >= RCT2_FIRST_WINDOW; w--) { + if (x < w->x || x >= w->x + w->width || y < w->y || y >= w->y + w->height) + continue; + + if (w->flags & 0x20) { + widget_index = window_find_widget_from_point(w, x, y); + if (widget_index == -1) + continue; + + widget = &w->widgets[widget_index]; + } + + return w; + } + + return NULL; +} + +/** + * + * rct2: 0x006EA594 + * x (ax) + * y (bx) + * returns widget_index (edx) + * EDI NEEDS TO BE SET TO w->widgets[widget_index] AFTER + */ +int window_find_widget_from_point(rct_window *w, int x, int y) +{ + rct_widget *widget; + int i, widget_index; + + // Invalidate the window + RCT2_CALLPROC_X(w->event_handlers[WE_INVALIDATE], 0, 0, 0, 0, w, 0, 0); + + // Find the widget at point x, y + widget_index = -1; + RCT2_GLOBAL(0x01420074, uint8) = -1; + for (i = 0;; i++) { + widget = &w->widgets[i]; + if (widget->type == WWT_LAST) { + break; + } else if (widget->type != WWT_EMPTY) { + if (widget->type == WWT_SCROLL) + RCT2_GLOBAL(0x01420074, uint8)++; + + if (x >= w->x + widget->left && x <= w->x + widget->right && + y >= w->y + widget->top && y <= w->y + widget->bottom + ) { + widget_index = i; + RCT2_GLOBAL(0x01420075, uint8) = RCT2_GLOBAL(0x01420074, uint8); + } + } + } + + // Return next widget if a dropdown + if (widget_index != -1) + if (w->widgets[widget_index].type == WWT_DROPDOWN) + widget_index++; + + // Return the widget index + return widget_index; +} + /** * Invalidates the specified window. * rct2: 0x006EB31A diff --git a/src/window.h b/src/window.h index 9bf736cd61..d15c121c32 100644 --- a/src/window.h +++ b/src/window.h @@ -273,6 +273,8 @@ rct_window *window_create(int x, int y, int width, int height, uint32 *event_han void window_close(rct_window *window); void window_close_by_id(rct_windowclass cls, rct_windownumber number); rct_window *window_find_by_id(rct_windowclass cls, rct_windownumber number); +rct_window *window_find_from_point(int x, int y); +int window_find_widget_from_point(rct_window *w, int x, int y); void window_invalidate(rct_window *window); void window_invalidate_by_id(uint16 cls, rct_windownumber number); void window_init_scroll_widgets(rct_window *w); @@ -300,5 +302,6 @@ void window_title_exit_open(); void window_title_logo_open(); void window_scenarioselect_open(); void window_land_open(); +void window_water_open(); #endif \ No newline at end of file diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index 7a6bda2b37..628d876595 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -196,7 +196,7 @@ static void window_game_top_toolbar_mouseup() RCT2_CALLPROC_X(0x006EE212, 19, 0, 0, WIDX_WATER, w, 0, 0); RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) = 1; - RCT2_CALLPROC_EBPSAFE(0x006E6A40); + window_water_open(); } break; case WIDX_SCENERY: diff --git a/src/window_water.c b/src/window_water.c new file mode 100644 index 0000000000..424c15bdfc --- /dev/null +++ b/src/window_water.c @@ -0,0 +1,236 @@ +/***************************************************************************** + * 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. + + * 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. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *****************************************************************************/ + +#include "addresses.h" +#include "map.h" +#include "strings.h" +#include "sprites.h" +#include "widget.h" +#include "window.h" + +static enum WINDOW_WATER_WIDGET_IDX { + 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(); + +static void window_water_emptysub() { } +static void window_water_close(); +static void window_water_mouseup(); +static void window_water_update(); +static void window_water_invalidate(); +static void window_water_paint(); + +static uint32 window_water_events[] = { + window_water_close, + window_water_mouseup, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_update, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_emptysub, + window_water_invalidate, + window_water_paint, + window_water_emptysub +}; + +/** + * + * rct2: 0x006E6A40 + */ +void window_water_open() +{ + rct_window* window; + + // Check if window is already open + if (window_find_by_id(WC_WATER, 0) != NULL) + return; + + window = window_create(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) - 76, 29, 76, 77, window_water_events, WC_WATER, 0); + window->widgets = window_water_widgets; + window->enabled_widgets = 0x04 | 0x10 | 0x20; + window_init_scroll_widgets(window); + window_push_others_below(window); + + RCT2_GLOBAL(0x0141F738, uint32) = 0x80000000; + RCT2_GLOBAL(0x0141F73C, uint32) = 0x80000000; + window->colours[0] = 24; + window->colours[1] = 24; + window->colours[2] = 24; +} + +/** + * + * rct2: 0x006E6B65 + */ +static void window_water_close() +{ + // If the tool wasn't changed, turn tool off + if (!window_water_should_close()) + RCT2_CALLPROC_EBPSAFE(0x006EE281); +} + +/** + * + * rct2: 0x006E6B4E + */ +static void window_water_mouseup() +{ + rct_window *w; + int limit; + short widgetIndex; + + __asm mov widgetIndex, dx + __asm mov w, esi + + switch (widgetIndex) { + case WIDX_CLOSE: + window_close(w); + break; + case WIDX_DECREMENT: + // Decrement land tool size + RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint8)--; + limit = 1; + + if (RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint8) < limit) + RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint8) = limit; + + // Invalidate the window + window_invalidate(w); + break; + case WIDX_INCREMENT: + // Increment land tool size + RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint8)++; + + // FEATURE: maximum size is always 7 + limit = 7; + // limit = (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2 ? 7 : 5); + + if (RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint8) > limit) + RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint8) = limit; + + // Invalidate the window + window_invalidate(w); + break; + } +} + +static void window_water_update() +{ + rct_window *w; + + __asm mov w, esi + + // Close window if another tool is open + if (window_water_should_close()) + window_close(w); +} + +/** + * + * rct2: 0x006E6AB8 + */ +static void window_water_invalidate() +{ + rct_window *w; + + __asm mov w, esi + + // Set the preview image button to be pressed down + w->pressed_widgets |= (1 << WIDX_PREVIEW); + + // Update the preview image + window_water_widgets[WIDX_PREVIEW].image = SPR_LAND_TOOL_SIZE_0 + RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint8); +} + +/** + * + * rct2: 0x006E6ACF + */ +static void window_water_paint() +{ + rct_window *w; + rct_drawpixelinfo *dpi; + int x, y; + + __asm mov w, esi + __asm mov dpi, edi + + window_draw_widgets(w, dpi); + + // Draw raise cost amount + x = (window_water_widgets[3].left + window_water_widgets[3].right) / 2 + w->x; + y = window_water_widgets[3].bottom + w->y + 5; + if (RCT2_GLOBAL(0x0141F738, uint32) != 0x80000000 && RCT2_GLOBAL(0x0141F738, uint32) != 0) + gfx_draw_string_centred(dpi, 984, x, y, 0, (void*)0x0141F738); + y += 10; + + // Draw lower cost amount + if (RCT2_GLOBAL(0x0141F73C, uint32) != 0x80000000 && RCT2_GLOBAL(0x0141F73C, uint32) != 0) + gfx_draw_string_centred(dpi, 985, x, y, 0, (void*)0x0141F73C); +} + +/** + * + * rct2: 0x0066D125 + */ +static int window_water_should_close() +{ + if (!(RCT2_GLOBAL(0x009DE518, uint32) & 8)) + return 1; + if (RCT2_GLOBAL(0x009DE544, uint8) != 1) + return 1; + if (RCT2_GLOBAL(0x009DE546, sint16) != 8) + return 1; + return 0; +} \ No newline at end of file