From ae8aa2d46616a882d5b8de9ccf7e72e6e349a441 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 30 Apr 2017 22:33:19 +0100 Subject: [PATCH] Fix top toolbar tool switching Moved tool active checks to top toolbar so that it can use constants. --- src/openrct2/interface/window.h | 4 ++ src/openrct2/windows/clear_scenery.c | 21 +--------- src/openrct2/windows/land_rights.c | 17 +------- src/openrct2/windows/scenery.c | 20 +-------- src/openrct2/windows/top_toolbar.c | 62 ++++++++++++++++++++++++++-- src/openrct2/windows/water.c | 21 +--------- 6 files changed, 71 insertions(+), 74 deletions(-) diff --git a/src/openrct2/interface/window.h b/src/openrct2/interface/window.h index 2e0873640c..c46a38abad 100644 --- a/src/openrct2/interface/window.h +++ b/src/openrct2/interface/window.h @@ -792,6 +792,10 @@ void window_update_textbox(); bool window_is_visible(rct_window* w); bool land_tool_is_active(); +bool water_tool_is_active(); +bool clear_scenery_tool_is_active(); +bool land_rights_tool_is_active(); +bool scenery_tool_is_active(); //Cheat: in-game land ownership editor void toggle_ingame_land_ownership_editor(); diff --git a/src/openrct2/windows/clear_scenery.c b/src/openrct2/windows/clear_scenery.c index 3c8a02f971..cf7c218e51 100644 --- a/src/openrct2/windows/clear_scenery.c +++ b/src/openrct2/windows/clear_scenery.c @@ -52,8 +52,6 @@ rct_widget window_clear_scenery_widgets[] = { { WIDGETS_END }, }; -static sint32 window_clear_scenery_should_close(); - static void window_clear_scenery_close(rct_window *w); static void window_clear_scenery_mouseup(rct_window *w, sint32 widgetIndex); static void window_clear_scenery_update(rct_window *w); @@ -126,7 +124,7 @@ void window_clear_scenery_open() static void window_clear_scenery_close(rct_window *w) { // If the tool wasn't changed, turn tool off - if (!window_clear_scenery_should_close()) + if (clear_scenery_tool_is_active()) tool_cancel(); } @@ -203,7 +201,7 @@ static void window_clear_scenery_inputsize(rct_window *w) static void window_clear_scenery_update(rct_window *w) { // Close window if another tool is open - if (window_clear_scenery_should_close()) + if (!clear_scenery_tool_is_active()) window_close(w); } @@ -252,18 +250,3 @@ static void window_clear_scenery_paint(rct_window *w, rct_drawpixelinfo *dpi) gfx_draw_string_centred(dpi, STR_COST_AMOUNT, x, y, COLOUR_BLACK, &gClearSceneryCost); } } - -/** - * - * rct2: 0x0066D125 - */ -static sint32 window_clear_scenery_should_close() -{ - if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) - return 1; - if (gCurrentToolWidget.window_classification != WC_TOP_TOOLBAR) - return 1; - if (gCurrentToolWidget.widget_index != 16) - return 1; - return 0; -} diff --git a/src/openrct2/windows/land_rights.c b/src/openrct2/windows/land_rights.c index 5170cc27d1..7b71582e61 100644 --- a/src/openrct2/windows/land_rights.c +++ b/src/openrct2/windows/land_rights.c @@ -51,8 +51,6 @@ static rct_widget window_land_rights_widgets[] = { { WIDGETS_END }, }; -static sint32 window_land_rights_should_close(); - static void window_land_rights_close(rct_window *w); static void window_land_rights_mouseup(rct_window *w, sint32 widgetIndex); static void window_land_rights_update(rct_window *w); @@ -119,7 +117,7 @@ void window_land_rights_open() static void window_land_rights_close(rct_window *w) { // If the tool wasn't changed, turn tool off - if (!window_land_rights_should_close()) + if (land_rights_tool_is_active()) tool_cancel(); } @@ -192,7 +190,7 @@ static void window_land_rights_inputsize(rct_window *w) static void window_land_rights_update(rct_window *w) { // Close window if another tool is open - if (window_land_rights_should_close()) + if (!land_rights_tool_is_active()) window_close(w); } @@ -250,14 +248,3 @@ static void window_land_rights_paint(rct_window *w, rct_drawpixelinfo *dpi) gfx_draw_string_centred(dpi, STR_COST_AMOUNT, x, y, COLOUR_BLACK, &gLandRightsCost); } } - -static sint32 window_land_rights_should_close() -{ - if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) - return 1; - if (gCurrentToolWidget.window_classification != WC_PARK_INFORMATION) - return 1; - if (gCurrentToolWidget.widget_index != 14) - return 1; - return 0; -} diff --git a/src/openrct2/windows/scenery.c b/src/openrct2/windows/scenery.c index 84551ca471..9519434552 100644 --- a/src/openrct2/windows/scenery.c +++ b/src/openrct2/windows/scenery.c @@ -483,22 +483,6 @@ void window_scenery_open() window->max_height = WINDOW_SCENERY_HEIGHT; } -/** - * - * rct2: 0x0066DB3D - */ -static bool window_scenery_is_scenery_tool_active() { - sint32 toolWindowClassification = gCurrentToolWidget.window_classification; - sint32 toolWidgetIndex = gCurrentToolWidget.widget_index; - - if (input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) - if (toolWindowClassification == WC_TOP_TOOLBAR && toolWidgetIndex == 9) // 9 is WIDX_SCENERY - return true; - - return false; -} - - /** * * rct2: 0x006E1A73 @@ -509,7 +493,7 @@ void window_scenery_close(rct_window *w) hide_gridlines(); viewport_set_visibility(0); - if (window_scenery_is_scenery_tool_active()) + if (scenery_tool_is_active()) tool_cancel(); } @@ -783,7 +767,7 @@ static void window_scenery_update(rct_window *w) window_invalidate(w); - if (!window_scenery_is_scenery_tool_active()){ + if (!scenery_tool_is_active()){ window_close(w); return; } diff --git a/src/openrct2/windows/top_toolbar.c b/src/openrct2/windows/top_toolbar.c index 60b1e2659e..4c2e787427 100644 --- a/src/openrct2/windows/top_toolbar.c +++ b/src/openrct2/windows/top_toolbar.c @@ -3291,7 +3291,7 @@ void toggle_footpath_window() */ void toggle_land_window(rct_window *topToolbar, sint32 widgetIndex) { - if ((input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) && gCurrentToolWidget.window_classification == WC_TOP_TOOLBAR && gCurrentToolWidget.widget_index == 7) { + if ((input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) && gCurrentToolWidget.window_classification == WC_TOP_TOOLBAR && gCurrentToolWidget.widget_index == WIDX_LAND) { tool_cancel(); } else { show_gridlines(); @@ -3308,7 +3308,7 @@ void toggle_land_window(rct_window *topToolbar, sint32 widgetIndex) */ void toggle_clear_scenery_window(rct_window *topToolbar, sint32 widgetIndex) { - if ((input_test_flag(INPUT_FLAG_TOOL_ACTIVE) && gCurrentToolWidget.window_classification == WC_TOP_TOOLBAR && gCurrentToolWidget.widget_index == 16)) { + if ((input_test_flag(INPUT_FLAG_TOOL_ACTIVE) && gCurrentToolWidget.window_classification == WC_TOP_TOOLBAR && gCurrentToolWidget.widget_index == WIDX_CLEAR_SCENERY)) { tool_cancel(); } else { show_gridlines(); @@ -3325,7 +3325,7 @@ void toggle_clear_scenery_window(rct_window *topToolbar, sint32 widgetIndex) */ void toggle_water_window(rct_window *topToolbar, sint32 widgetIndex) { - if ((input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) && gCurrentToolWidget.window_classification == WC_TOP_TOOLBAR && gCurrentToolWidget.widget_index == 8) { + if ((input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) && gCurrentToolWidget.window_classification == WC_TOP_TOOLBAR && gCurrentToolWidget.widget_index == WIDX_WATER) { tool_cancel(); } else { show_gridlines(); @@ -3350,3 +3350,59 @@ bool land_tool_is_active() return false; return true; } + +/** + * + * rct2: 0x0066D125 + */ +bool clear_scenery_tool_is_active() +{ + if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) + return false; + if (gCurrentToolWidget.window_classification != WC_TOP_TOOLBAR) + return false; + if (gCurrentToolWidget.widget_index != WIDX_CLEAR_SCENERY) + return false; + return true; +} + +bool land_rights_tool_is_active() +{ + if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) + return false; + if (gCurrentToolWidget.window_classification != WC_PARK_INFORMATION) + return false; + if (gCurrentToolWidget.widget_index != WIDX_PARK) + return false; + return true; +} + +/** + * + * rct2: 0x0066DB3D + */ +bool scenery_tool_is_active() +{ + sint32 toolWindowClassification = gCurrentToolWidget.window_classification; + sint32 toolWidgetIndex = gCurrentToolWidget.widget_index; + if (input_test_flag(INPUT_FLAG_TOOL_ACTIVE)) + if (toolWindowClassification == WC_TOP_TOOLBAR && toolWidgetIndex == WIDX_SCENERY) + return true; + + return false; +} + +/** + * + * rct2: 0x0066D125 + */ +bool water_tool_is_active() +{ + if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) + return false; + if (gCurrentToolWidget.window_classification != WC_TOP_TOOLBAR) + return false; + if (gCurrentToolWidget.widget_index != WIDX_WATER) + return false; + return true; +} diff --git a/src/openrct2/windows/water.c b/src/openrct2/windows/water.c index ad60114dd0..80a0608d20 100644 --- a/src/openrct2/windows/water.c +++ b/src/openrct2/windows/water.c @@ -45,8 +45,6 @@ static rct_widget window_water_widgets[] = { { WIDGETS_END }, }; -static sint32 window_water_should_close(); - static void window_water_close(rct_window *w); static void window_water_mouseup(rct_window *w, sint32 widgetIndex); static void window_water_update(rct_window *w); @@ -123,7 +121,7 @@ void window_water_open() static void window_water_close(rct_window *w) { // If the tool wasn't changed, turn tool off - if (!window_water_should_close()) + if (water_tool_is_active()) tool_cancel(); } @@ -189,7 +187,7 @@ static void window_water_inputsize(rct_window *w) static void window_water_update(rct_window *w) { // Close window if another tool is open - if (window_water_should_close()) + if (!water_tool_is_active()) window_close(w); } @@ -243,18 +241,3 @@ static void window_water_paint(rct_window *w, rct_drawpixelinfo *dpi) } - -/** - * - * rct2: 0x0066D125 - */ -static sint32 window_water_should_close() -{ - if (!(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) - return 1; - if (gCurrentToolWidget.window_classification != WC_TOP_TOOLBAR) - return 1; - if (gCurrentToolWidget.widget_index != 8) - return 1; - return 0; -}