From 46308abfe3c5f1c2553afa2f1de9cf3a33d20333 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 30 Apr 2014 16:57:27 +0100 Subject: [PATCH] add cancel and set tool along with path refactor --- src/addresses.h | 1 + src/window.c | 67 +++++++++++++++++++++++++++++++++++ src/window.h | 3 ++ src/window_clear_scenery.c | 2 +- src/window_footpath.c | 48 ++++++++++++++++++++----- src/window_game_top_toolbar.c | 18 +++++----- src/window_land.c | 2 +- src/window_park.c | 6 ++-- src/window_water.c | 2 +- 9 files changed, 126 insertions(+), 23 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 4889529805..1772a58e77 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -98,6 +98,7 @@ #define RCT2_ADDRESS_TOOL_WINDOWNUMBER 0x009DE542 #define RCT2_ADDRESS_TOOL_WINDOWCLASS 0x009DE544 +#define RCT2_ADDRESS_CURRENT_TOOL 0x009DE545 #define RCT2_ADDRESS_TOOL_WIDGETINDEX 0x009DE546 #define RCT2_ADDRESS_CURSOR_OVER_WINDOWCLASS 0x009DE55C diff --git a/src/window.c b/src/window.c index 1c9b5e503b..da21178b58 100644 --- a/src/window.c +++ b/src/window.c @@ -1105,3 +1105,70 @@ void window_set_resize(rct_window *w, int minWidth, int minHeight, int maxWidth, window_invalidate(w); } } + +/** + * + * rct2: 0x006EE212 + * + * @param tool (al) + * @param widgetIndex (dx) + * @param w (esi) + */ +int tool_set(rct_window *w, int widgetIndex, int tool) +{ + if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) { + if ( + w->classification == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) && + w->number == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) && + widgetIndex == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) + ) { + tool_cancel(); + return 1; + } + } + + RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 3); + RCT2_GLOBAL(0x009DE518, uint32) &= ~(1 << 6); + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8) = tool; + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) = w->classification; + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) = w->number; + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) = widgetIndex; + return 0; +} + +/** + * + * rct2: 0x006EE281 + */ +void tool_cancel() +{ + rct_window *w; + + if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) { + RCT2_GLOBAL(0x009DE518, uint32) &= ~(1 << 3); + + // + RCT2_CALLPROC_EBPSAFE(0x0068AAE1); + RCT2_CALLPROC_EBPSAFE(0x0068AB1B); + + // Reset map selection + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) = 0; + + if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, sint16) >= 0) { + // Invalidate tool widget + widget_invalidate( + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass), + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber), + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) + ); + + // Abort tool event + w = window_find_by_id( + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass), + RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) + ); + if (w != NULL) + RCT2_CALLPROC_X(w->event_handlers[WE_TOOL_ABORT], 0, 0, 0, RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16), w, 0, 0); + } + } +} \ No newline at end of file diff --git a/src/window.h b/src/window.h index 62f2bcf74d..ff5257c90f 100644 --- a/src/window.h +++ b/src/window.h @@ -319,6 +319,9 @@ void window_move_position(rct_window *w, int dx, int dy); void window_resize(rct_window *w, int dw, int dh); void window_set_resize(rct_window *w, int minWidth, int minHeight, int maxWidth, int maxHeight); +int tool_set(rct_window *w, int widgetIndex, int tool); +void tool_cancel(); + // Open window functions void window_main_open(); void window_game_top_toolbar_open(); diff --git a/src/window_clear_scenery.c b/src/window_clear_scenery.c index 061de23294..f5a708f83d 100644 --- a/src/window_clear_scenery.c +++ b/src/window_clear_scenery.c @@ -116,7 +116,7 @@ static void window_clear_scenery_close() { // If the tool wasn't changed, turn tool off if (!window_clear_scenery_should_close()) - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); } /** diff --git a/src/window_footpath.c b/src/window_footpath.c index 0b90d247d2..1bed335299 100644 --- a/src/window_footpath.c +++ b/src/window_footpath.c @@ -29,6 +29,12 @@ #include "window.h" #include "window_dropdown.h" +enum { + PATH_CONSTRUCTION_MODE_LAND, + PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL, + PATH_CONSTRUCTION_MODE_2 +}; + typedef struct { uint16 pad_00; uint32 image; // 0x02 @@ -193,9 +199,9 @@ void window_footpath_open() window->colours[1] = 24; window->colours[2] = 24; - RCT2_CALLPROC_EBPSAFE(0x006EE281); - RCT2_GLOBAL(0x00F3EF99, uint8) = 0; - RCT2_CALLPROC_X(0x006EE212, 17, 0, 0, 18, window, 0, 0); + tool_cancel(); + RCT2_GLOBAL(0x00F3EF99, uint8) = PATH_CONSTRUCTION_MODE_LAND; + tool_set(window, WIDX_CONSTRUCT_ON_LAND, 17); RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); RCT2_GLOBAL(0x00F3EF9F, uint8) = 0; RCT2_CALLPROC_EBPSAFE(0x006A855C); @@ -242,10 +248,36 @@ static void window_footpath_mouseup() RCT2_CALLPROC_X(0x006A7863, 0, 0, 0, 0, w, 0, 0); break; case WIDX_CONSTRUCT_ON_LAND: - RCT2_CALLPROC_X(0x006A8072, 0, 0, 0, widgetIndex, w, 0, 0); + // RCT2_CALLPROC_X(0x006A8072, 0, 0, 0, widgetIndex, w, 0, 0); + + if (RCT2_GLOBAL(0x00F3EF99, uint8) == PATH_CONSTRUCTION_MODE_LAND) + break; + _window_footpath_cost = 0x80000000; + tool_cancel(); + RCT2_CALLPROC_EBPSAFE(0x006A7831); + RCT2_CALLPROC_EBPSAFE(0x0068AB1B); + RCT2_GLOBAL(0x009DE58A, uint16) &= ~2; + RCT2_GLOBAL(0x00F3EF99, uint8) = PATH_CONSTRUCTION_MODE_LAND; + tool_set(w, WIDX_CONSTRUCT_ON_LAND, 17); + RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); + RCT2_GLOBAL(0x00F3EF9F, uint8) = 0; + RCT2_CALLPROC_EBPSAFE(0x006A855C); break; case WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL: - RCT2_CALLPROC_X(0x006A80C5, 0, 0, 0, widgetIndex, w, 0, 0); + // RCT2_CALLPROC_X(0x006A80C5, 0, 0, 0, widgetIndex, w, 0, 0); + + if (RCT2_GLOBAL(0x00F3EF99, uint8) == PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL) + break; + _window_footpath_cost = 0x80000000; + RCT2_CALLPROC_EBPSAFE(0x006EE281); + RCT2_CALLPROC_EBPSAFE(0x006A7831); + RCT2_CALLPROC_EBPSAFE(0x0068AB1B); + RCT2_GLOBAL(0x009DE58A, uint16) &= ~2; + RCT2_GLOBAL(0x00F3EF99, uint8) = PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL; + tool_set(w, WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL, 12); + RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); + RCT2_GLOBAL(0x00F3EF9F, uint8) = 0; + RCT2_CALLPROC_EBPSAFE(0x006A855C); break; } } @@ -451,14 +483,14 @@ static void window_footpath_update() RCT2_CALLPROC_EBPSAFE(0x006A7760); // Check tool - if (RCT2_GLOBAL(0x00F3EF99, uint8) == 0) { + if (RCT2_GLOBAL(0x00F3EF99, uint8) == PATH_CONSTRUCTION_MODE_LAND) { if (!(RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3))) window_close(w); if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) != WC_FOOTPATH) window_close(w); if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) != WIDX_CONSTRUCT_ON_LAND) window_close(w); - } else if (RCT2_GLOBAL(0x00F3EF99, uint8) == 1) { + } else if (RCT2_GLOBAL(0x00F3EF99, uint8) == PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL) { if (!(RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3))) window_close(w); if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) != WC_FOOTPATH) @@ -488,7 +520,7 @@ static void window_footpath_invalidate() (1 << WIDX_QUEUELINE_TYPE); // Enable / disable construct button - window_footpath_widgets[WIDX_CONSTRUCT].type = RCT2_GLOBAL(0x00F3EF99, uint8) == 0 ? WWT_EMPTY : WWT_IMGBTN; + window_footpath_widgets[WIDX_CONSTRUCT].type = RCT2_GLOBAL(0x00F3EF99, uint8) == PATH_CONSTRUCTION_MODE_LAND ? WWT_EMPTY : WWT_IMGBTN; // Set footpath and queue type button images selectedPath = RCT2_GLOBAL(0x00F3EFA0, uint16); diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index 020afbb811..d329e5c954 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -175,10 +175,10 @@ static void window_game_top_toolbar_mouseup() case WIDX_CLEAR_SCENERY: if ((RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) && RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, uint8) == 1 && RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) == 16) { - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); } else { show_gridlines(); - RCT2_CALLPROC_X(0x006EE212, 12, 0, 0, WIDX_CLEAR_SCENERY, w, 0, 0); + tool_set(w, WIDX_CLEAR_SCENERY, 12); RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) = 2; window_clear_scenery_open(); @@ -186,10 +186,10 @@ static void window_game_top_toolbar_mouseup() break; case WIDX_LAND: if ((RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) && RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, uint8) == 1 && RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) == 7) { - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); } else { show_gridlines(); - RCT2_CALLPROC_X(0x006EE212, 18, 0, 0, WIDX_LAND, w, 0, 0); + tool_set(w, WIDX_LAND, 18); RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) = 1; window_land_open(); @@ -197,17 +197,17 @@ static void window_game_top_toolbar_mouseup() break; case WIDX_WATER: if ((RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) && RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, uint8) == 1 && RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) == 8) { - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); } else { show_gridlines(); - RCT2_CALLPROC_X(0x006EE212, 19, 0, 0, WIDX_WATER, w, 0, 0); + tool_set(w, WIDX_WATER, 19); RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) = 1; window_water_open(); } break; case WIDX_SCENERY: - RCT2_CALLPROC_X(0x006EE212, 0, 0, 0, WIDX_SCENERY, w, 0, 0); + tool_set(w, WIDX_SCENERY, 0); RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); RCT2_CALLPROC_EBPSAFE(0x006E0FEF); break; @@ -215,7 +215,7 @@ static void window_game_top_toolbar_mouseup() if (window_find_by_id(WC_FOOTPATH, 0) == NULL) { window_footpath_open(); } else { - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); window_close_by_id(0x80 | WC_FOOTPATH, 0); } break; @@ -345,7 +345,7 @@ static void window_game_top_toolbar_dropdown() RCT2_CALLPROC_X(0x006677F2, 0, 1, 0, 0, 5, 0, 0); break; case 1: // save game - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); { int eax, ebx, ecx, edx, esi, edi, ebp; RCT2_CALLFUNC_X(0x006750E9, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); diff --git a/src/window_land.c b/src/window_land.c index 0c196b46f1..3a47fa0937 100644 --- a/src/window_land.c +++ b/src/window_land.c @@ -152,7 +152,7 @@ static void window_land_close() { // If the tool wasn't changed, turn tool off if (!window_land_should_close()) - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); } /** diff --git a/src/window_park.c b/src/window_park.c index 29867a3540..39b17519ae 100644 --- a/src/window_park.c +++ b/src/window_park.c @@ -645,7 +645,7 @@ static void window_park_entrance_close() if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) if (w->classification == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) && w->number == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber)) - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); } /** @@ -1618,7 +1618,7 @@ void window_park_objective_open() if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) if (window->classification == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) && window->number == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber)) - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); window->viewport = NULL; window->page = WINDOW_PARK_PAGE_OBJECTIVE; @@ -1895,7 +1895,7 @@ static void window_park_set_page(rct_window *w, int page) if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) if (w->classification == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) && w->number == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber)) - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); // Set listen only to viewport listen = 0; diff --git a/src/window_water.c b/src/window_water.c index 6b7eab58a5..56be72a634 100644 --- a/src/window_water.c +++ b/src/window_water.c @@ -117,7 +117,7 @@ static void window_water_close() { // If the tool wasn't changed, turn tool off if (!window_water_should_close()) - RCT2_CALLPROC_EBPSAFE(0x006EE281); + tool_cancel(); } /**