From 7ea9866efba2bce633c59c2bf64b88f3476b8886 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 17 Apr 2014 15:12:41 +0100 Subject: [PATCH] get park window buttons working --- src/addresses.h | 4 ++ src/rct2.c | 19 ----- src/rct2.h | 2 - src/strings.h | 3 + src/viewport.c | 129 ++++++++++++++++++++++++++++++++++ src/viewport.h | 11 ++- src/widget.c | 22 ++++-- src/widget.h | 1 + src/window.h | 10 +-- src/window_park.c | 173 +++++++++++++++++++++++++++++++++++++++++++--- 10 files changed, 335 insertions(+), 39 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index e0bac3aaf0..16868881d8 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -91,6 +91,10 @@ #define RCT2_ADDRESS_TOOLTIP_TIMEOUT 0x009DE53C #define RCT2_ADDRESS_TOOLTIP_NOT_SHOWN_TICKS 0x009DE53E +#define RCT2_ADDRESS_TOOL_WINDOWNUMBER 0x009DE542 +#define RCT2_ADDRESS_TOOL_WINDOWCLASS 0x009DE544 +#define RCT2_ADDRESS_TOOL_WIDGETINDEX 0x009DE546 + #define RCT2_ADDRESS_CURSOR_OVER_WINDOWCLASS 0x009DE55C #define RCT2_ADDRESS_CURSOR_OVER_WINDOWNUMBER 0x009DE55E #define RCT2_ADDRESS_CURSOR_OVER_WIDGETINDEX 0x009DE560 diff --git a/src/rct2.c b/src/rct2.c index 8e1e5d818a..5b93e66ec1 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -280,23 +280,4 @@ void *rct2_realloc(void *block, size_t numBytes) void rct2_free(void *block) { RCT2_CALLPROC_1(0x004068DE, void*, block); -} - -/** - * - * rct2: 0x00664689 - */ -void show_gridlines() -{ - rct_window *mainWindow; - - if (RCT2_GLOBAL(0x009E32B0, uint8) == 0) { - if ((mainWindow = window_get_main()) != NULL) { - if (!(mainWindow->viewport->flags & VIEWPORT_FLAG_GRIDLINES)) { - mainWindow->viewport->flags |= VIEWPORT_FLAG_GRIDLINES; - window_invalidate(mainWindow); - } - } - } - RCT2_GLOBAL(0x009E32B0, uint8)++; } \ No newline at end of file diff --git a/src/rct2.h b/src/rct2.h index 3157b8e270..00a748b5ab 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -132,6 +132,4 @@ void *rct2_malloc(size_t numBytes); void *rct2_realloc(void *block, size_t numBytes); void rct2_free(void *block); -void show_gridlines(); - #endif \ No newline at end of file diff --git a/src/strings.h b/src/strings.h index 4794844093..29d25f44c7 100644 --- a/src/strings.h +++ b/src/strings.h @@ -156,6 +156,9 @@ enum { STR_OPEN_OR_CLOSE_PARK_TIP = 1010, + STR_CLOSE_PARK = 1013, + STR_OPEN_PARK = 1014, + STR_LOCATE_SUBJECT_TIP = 1027, STR_RIDES_IN_PARK_TIP = 1053, diff --git a/src/viewport.c b/src/viewport.c index 77beffa45a..365a7d1d7b 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -19,6 +19,7 @@ *****************************************************************************/ #include "addresses.h" +#include "config.h" #include "gfx.h" #include "strings.h" #include "viewport.h" @@ -101,4 +102,132 @@ void viewport_update_position(rct_window *window) void viewport_render(rct_drawpixelinfo *dpi, rct_viewport *viewport, int left, int top, int right, int bottom) { RCT2_CALLPROC_X(0x00685C02, left , top, 0, right, viewport, dpi, bottom); +} + +/** + * + * rct2: 0x0068958D + */ +void screen_pos_to_map_pos(int *x, int *y) +{ + int eax, ebx, ecx, edx, esi, edi, ebp; + eax = *x; + ebx = *y; + RCT2_CALLFUNC_X(0x0068958D, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + *x = eax & 0xFFFF; + *y = ebx & 0xFFFF; +} + +/** + * + * rct2: 0x00664689 + */ +void show_gridlines() +{ + rct_window *mainWindow; + + if (RCT2_GLOBAL(0x009E32B0, uint8) == 0) { + if ((mainWindow = window_get_main()) != NULL) { + if (!(mainWindow->viewport->flags & VIEWPORT_FLAG_GRIDLINES)) { + mainWindow->viewport->flags |= VIEWPORT_FLAG_GRIDLINES; + window_invalidate(mainWindow); + } + } + } + RCT2_GLOBAL(0x009E32B0, uint8)++; +} + +/** + * + * rct2: 0x006646B4 + */ +void hide_gridlines() +{ + rct_window *mainWindow; + + RCT2_GLOBAL(0x009E32B0, uint8)--; + if (RCT2_GLOBAL(0x009E32B0, uint8) == 0) { + if ((mainWindow = window_get_main()) != NULL) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & CONFIG_FLAG_ALWAYS_SHOW_GRIDLINES)) { + mainWindow->viewport->flags &= ~VIEWPORT_FLAG_GRIDLINES; + window_invalidate(mainWindow); + } + } + } +} + +/** + * + * rct2: 0x00664E8E + */ +void show_land_rights() +{ + rct_window *mainWindow; + + if (RCT2_GLOBAL(0x009E32B2, uint8) != 0) { + if ((mainWindow = window_get_main()) != NULL) { + if (!(mainWindow->viewport->flags & VIEWPORT_FLAG_LAND_OWNERSHIP)) { + mainWindow->viewport->flags |= VIEWPORT_FLAG_LAND_OWNERSHIP; + window_invalidate(mainWindow); + } + } + } + RCT2_GLOBAL(0x009E32B2, uint8)++; +} + +/** + * + * rct2: 0x00664E8E + */ +void hide_land_rights() +{ + rct_window *mainWindow; + + RCT2_GLOBAL(0x009E32B2, uint8)--; + if (RCT2_GLOBAL(0x009E32B2, uint8) == 0) { + if ((mainWindow = window_get_main()) != NULL) { + if (mainWindow->viewport->flags & VIEWPORT_FLAG_LAND_OWNERSHIP) { + mainWindow->viewport->flags &= ~VIEWPORT_FLAG_LAND_OWNERSHIP; + window_invalidate(mainWindow); + } + } + } +} + +/** + * + * rct2: 0x00664EDD + */ +void show_construction_rights() +{ + rct_window *mainWindow; + + if (RCT2_GLOBAL(0x009E32B3, uint8) != 0) { + if ((mainWindow = window_get_main()) != NULL) { + if (!(mainWindow->viewport->flags & VIEWPORT_FLAG_CONSTRUCTION_RIGHTS)) { + mainWindow->viewport->flags |= VIEWPORT_FLAG_CONSTRUCTION_RIGHTS; + window_invalidate(mainWindow); + } + } + } + RCT2_GLOBAL(0x009E32B3, uint8)++; +} + +/** + * + * rct2: 0x00664F08 + */ +void hide_construction_rights() +{ + rct_window *mainWindow; + + RCT2_GLOBAL(0x009E32B3, uint8)--; + if (RCT2_GLOBAL(0x009E32B3, uint8) == 0) { + if ((mainWindow = window_get_main()) != NULL) { + if (mainWindow->viewport->flags & VIEWPORT_FLAG_CONSTRUCTION_RIGHTS) { + mainWindow->viewport->flags &= ~VIEWPORT_FLAG_CONSTRUCTION_RIGHTS; + window_invalidate(mainWindow); + } + } + } } \ No newline at end of file diff --git a/src/viewport.h b/src/viewport.h index c70fafe7d1..f511fadc02 100644 --- a/src/viewport.h +++ b/src/viewport.h @@ -33,7 +33,7 @@ enum { VIEWPORT_FLAG_PATH_HEIGHTS = (1 << 6), VIEWPORT_FLAG_GRIDLINES = (1 << 7), VIEWPORT_FLAG_LAND_OWNERSHIP = (1 << 8), - VIEWPORT_FLAG_9 = (1 << 9), + VIEWPORT_FLAG_CONSTRUCTION_RIGHTS = (1 << 9), VIEWPORT_FLAG_SOUND_ON = (1 << 10), VIEWPORT_FLAG_INVISIBLE_PEEPS = (1 << 11), VIEWPORT_FLAG_HIDE_BASE = (1 << 12), @@ -47,4 +47,13 @@ void viewport_update_pointers(); void viewport_update_position(rct_window *window); void viewport_render(rct_drawpixelinfo *dpi, rct_viewport *viewport, int left, int top, int right, int bottom); +void screen_pos_to_map_pos(int *x, int *y); + +void show_gridlines(); +void hide_gridlines(); +void show_land_rights(); +void hide_land_rights(); +void show_construction_rights(); +void hide_construction_rights(); + #endif \ No newline at end of file diff --git a/src/widget.c b/src/widget.c index 336e716392..8f0da8a27c 100644 --- a/src/widget.c +++ b/src/widget.c @@ -206,7 +206,7 @@ static void widget_button_draw(rct_drawpixelinfo *dpi, rct_window *w, int widget b = w->y + widget->bottom; // Check if the button is pressed down - press = widget_is_pressed(w, widgetIndex) ? 0x20 : 0; + press = widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex) ? 0x20 : 0; // Get the colour colour = w->colours[widget->colour]; @@ -298,7 +298,7 @@ static void widget_flat_button_draw(rct_drawpixelinfo *dpi, rct_window *w, int w colour = w->colours[widget->colour]; // Check if the button is pressed down - if (widget_is_pressed(w, widgetIndex)) { + if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex)) { if (widget->image == -2) { // Draw border with no fill gfx_fill_rect_inset(dpi, l, t, r, b, colour, 0x20 | 0x10); @@ -432,7 +432,7 @@ static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widg press = 0; if (w->flags & 0x400) press |= 0x80; - if (widget_is_pressed(w, widgetIndex)) + if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex)) press |= 0x20; // Get the colour @@ -600,7 +600,7 @@ static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, int widgetI colour = w->colours[widget->colour]; if (widget->type == WWT_4 || widget->type == WWT_6 || widget->type == WWT_TRNBTN || widget->type == WWT_TAB) - if (widget_is_pressed(w, widgetIndex)) + if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex)) image++; if (!widget_is_disabled(w, widgetIndex)) { @@ -652,4 +652,18 @@ int widget_is_highlighted(rct_window *w, int widgetIndex) if (RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_OVER_WIDGETINDEX, sint32) != widgetIndex) return 0; return 1; +} + +int widget_is_active_tool(rct_window *w, int widgetIndex) +{ + if (!(RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3))) + return 0; + if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) != w->classification) + return 0; + if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) != w->number) + return 0; + if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, sint32) != widgetIndex) + return 0; + + return 1; } \ No newline at end of file diff --git a/src/widget.h b/src/widget.h index 50f083e991..8a84d373d2 100644 --- a/src/widget.h +++ b/src/widget.h @@ -60,5 +60,6 @@ void widget_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); int widget_is_disabled(rct_window *w, int widgetIndex); int widget_is_pressed(rct_window *w, int widgetIndex); int widget_is_highlighted(rct_window *w, int widgetIndex); +int widget_is_active_tool(rct_window *w, int widgetIndex); #endif \ No newline at end of file diff --git a/src/window.h b/src/window.h index dda04a7035..8e7db511fe 100644 --- a/src/window.h +++ b/src/window.h @@ -145,11 +145,11 @@ typedef enum { WE_UPDATE = 6, WE_UNKNOWN_07 = 7, WE_UNKNOWN_08 = 8, - WE_UNKNOWN_09 = 9, // tool update? - WE_UNKNOWN_0A = 10, // tool mouse down? - WE_UNKNOWN_0B = 11, // tool mouse down? - WE_UNKNOWN_0C = 12, - WE_UNKNOWN_0D = 13, // abort tool? + WE_TOOL_UPDATE = 9, + WE_TOOL_DOWN = 10, + WE_TOOL_DRAG = 11, + WE_TOOL_UP = 12, + WE_TOOL_ABORT = 13, WE_UNKNOWN_0E = 14, WE_SCROLL_GETSIZE = 15, WE_SCROLL_MOUSEDOWN = 16, diff --git a/src/window_park.c b/src/window_park.c index 859276e903..7549369b7e 100644 --- a/src/window_park.c +++ b/src/window_park.c @@ -31,6 +31,7 @@ #include "viewport.h" #include "widget.h" #include "window.h" +#include "window_dropdown.h" enum WINDOW_PARK_PAGE { WINDOW_PARK_PAGE_ENTRANCE, @@ -212,7 +213,13 @@ static void window_park_emptysub() { } static void window_park_entrance_close(); static void window_park_entrance_mouseup(); +static void window_park_entrance_mousedown(); +static void window_park_entrance_dropdown(); static void window_park_entrance_update(); +static void window_park_entrance_toolupdate(); +static void window_park_entrance_tooldown(); +static void window_park_entrance_tooldrag(); +static void window_park_entrance_toolabort(); static void window_park_entrance_textinput(); static void window_park_entrance_invalidate(); static void window_park_entrance_paint(); @@ -251,17 +258,17 @@ static uint32 window_park_entrance_events[] = { window_park_entrance_close, window_park_entrance_mouseup, window_park_emptysub, - window_park_emptysub, - window_park_emptysub, + window_park_entrance_mousedown, + window_park_entrance_dropdown, window_park_emptysub, window_park_entrance_update, window_park_emptysub, window_park_emptysub, + window_park_entrance_toolupdate, + window_park_entrance_tooldown, + window_park_entrance_tooldrag, window_park_emptysub, - window_park_emptysub, - window_park_emptysub, - window_park_emptysub, - window_park_emptysub, + window_park_entrance_toolabort, window_park_emptysub, window_park_emptysub, window_park_emptysub, @@ -660,10 +667,10 @@ static void window_park_entrance_mouseup() window_park_set_page(w, widgetIndex - WIDX_TAB_1); break; case WIDX_BUY_LAND_RIGHTS: - RCT2_CALLPROC_X(0x006682F7, 0, 0, 0, 0, w, 0, 0); + RCT2_CALLPROC_X(0x006682F7, 0, 0, 0, widgetIndex, w, 0, 0); break; case WIDX_BUY_CONSTRUCTION_RIGHTS: - RCT2_CALLPROC_X(0x00668393, 0, 0, 0, 0, w, 0, 0); + RCT2_CALLPROC_X(0x00668393, 0, 0, 0, widgetIndex, w, 0, 0); break; case WIDX_LOCATE: if (w->viewport == NULL || *((sint32*)&w->var_482) == -1) @@ -692,6 +699,70 @@ static void window_park_entrance_mouseup() } } +/** + * + * rct2: 0x006681BF + */ +static void window_park_entrance_mousedown() +{ + short widgetIndex; + rct_window *w; + rct_widget *widget; + + __asm mov widgetIndex, dx + __asm mov w, esi + __asm mov widget, edi + + if (widgetIndex == WIDX_OPEN_OR_CLOSE) { + gDropdownItemsFormat[0] = 1142; + gDropdownItemsFormat[1] = 1142; + gDropdownItemsArgs[0] = STR_CLOSE_PARK; + gDropdownItemsArgs[1] = STR_OPEN_PARK; + window_dropdown_show_text( + w->x + widget->left, + w->y + widget->top, + widget->bottom - widget->top + 1, + w->colours[1], + 0, + 2 + ); + + if (park_is_open()) { + RCT2_GLOBAL(0x009DEBA2, sint16) = 0; + gDropdownItemsChecked |= (1 << 1); + } else { + RCT2_GLOBAL(0x009DEBA2, sint16) = 1; + gDropdownItemsChecked |= (1 << 0); + } + } +} + +/** + * + * rct2: 0x006682B8 + */ +static void window_park_entrance_dropdown() +{ + short widgetIndex, dropdownIndex; + + __asm mov dropdownIndex, ax + __asm mov widgetIndex, dx + + if (widgetIndex == WIDX_OPEN_OR_CLOSE) { + if (dropdownIndex == -1) + dropdownIndex = RCT2_GLOBAL(0x009DEBA2, sint16); + if (dropdownIndex != 0) { + dropdownIndex &= 0x00FF; + dropdownIndex |= 0x0100; + RCT2_GLOBAL(0x0141E9AE, uint16) = 1724; + } else { + dropdownIndex &= 0x00FF; + RCT2_GLOBAL(0x0141E9AE, uint16) = 1723; + } + RCT2_CALLPROC_X(0x006677F2, 0, 1, 0, dropdownIndex, 34, 0, 0); + } +} + /** * * rct2: 0x006686B5 @@ -706,6 +777,92 @@ static void window_park_entrance_update() window_invalidate_by_id(w->classification, 1179); } +/** + * + * rct2: 0x006681D1 + */ +static void window_park_entrance_toolupdate() +{ + int x, y; + short widgetIndex; + rct_window *w, *mainWindow; + + __asm mov x, eax + __asm mov y, ebx + __asm mov widgetIndex, dx + __asm mov w, esi + + if (widgetIndex == WIDX_BUY_LAND_RIGHTS) { + RCT2_CALLPROC_X(0x0068AAE1, x, y, 0, 0, w, 0, 0); + RCT2_GLOBAL(0x009DE58A, uint16) &= 0xFFFE; + screen_pos_to_map_pos(&x, &y); + if (x != 0x8000) { + RCT2_GLOBAL(0x009DE58A, uint16) |= 1; + RCT2_GLOBAL(0x009DE594, uint16) = 4; + RCT2_GLOBAL(0x009DE58C, uint16) = x; + RCT2_GLOBAL(0x009DE58E, uint16) = x; + RCT2_GLOBAL(0x009DE590, uint16) = y; + RCT2_GLOBAL(0x009DE592, uint16) = y; + RCT2_CALLPROC_X(0x0068AAE1, x, y, 0, 0, w, 0, 0); + } + } +} + +/** + * + * rct2: 0x006681E6 + */ +static void window_park_entrance_tooldown() +{ + short x, y, widgetIndex; + rct_window *w, *mainWindow; + + __asm mov x, ax + __asm mov y, bx + __asm mov widgetIndex, dx + __asm mov w, esi + + RCT2_CALLPROC_X(0x006681E6, x, y, 0, widgetIndex, w, 0, 0); +} + +/** + * + * rct2: 0x006681FB + */ +static void window_park_entrance_tooldrag() +{ + short x, y, widgetIndex; + rct_window *w, *mainWindow; + + __asm mov x, ax + __asm mov y, bx + __asm mov widgetIndex, dx + __asm mov w, esi + + RCT2_CALLPROC_X(0x006681FB, x, y, 0, widgetIndex, w, 0, 0); +} + +/** + * + * rct2: 0x0066822A + */ +static void window_park_entrance_toolabort() +{ + short widgetIndex; + rct_window *w, *mainWindow; + + __asm mov widgetIndex, dx + __asm mov w, esi + + if (widgetIndex == WIDX_BUY_LAND_RIGHTS) { + hide_gridlines(); + hide_land_rights(); + } else if (widgetIndex == WIDX_BUY_CONSTRUCTION_RIGHTS) { + hide_gridlines(); + hide_construction_rights(); + } +} + /** * * rct2: 0x0066848B