diff --git a/src/game.c b/src/game.c index 9d7611bbc3..14b0627211 100644 --- a/src/game.c +++ b/src/game.c @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Ted John + * Copyright (c) 2014 Ted John, Peter Hill * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. @@ -870,15 +870,264 @@ int get_next_key() * * rct2: 0x006E3E68 */ -void handle_shortcut(int key) -{ - int i; - for (i = 0; i < 32; i++) { - if (key == gShortcutKeys[i]) { - RCT2_CALLPROC_EBPSAFE(RCT2_ADDRESS(0x006E3FB4, uint32)[i]); - break; +void handle_shortcut(int key) { + + rct_window* window; + + if (key == gShortcutKeys[0]) { + // Close top most window + window_close_top(); + + } else if (key == gShortcutKeys[1]) { + // Close all windows + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2)) { + window_close_all(); + return; } + if (RCT2_ADDRESS(0x0141F570, uint8) == 1) { + window_close_top(); + } + } else if (key == gShortcutKeys[2]) { + // Cancel construction mode + window = window_find_by_id(WC_ERROR, 0); + if (window != NULL) { + window_close(window); + return; + } + if (RCT2_GLOBAL(0x009DE518, uint32) & (1 << 3)) { + tool_cancel(); + } + } else if (key == gShortcutKeys[3]) { + // Pause + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 10)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 0, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[4]) { + // Zoom out + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 8)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 2, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[5]) { + // Zoom in + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 8)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 3, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[6]) { + // Rotate view + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 8)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 4, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[7]) { + // Rotate object + RCT2_CALLPROC_EBPSAFE(0x006E4182); + } else if (key == gShortcutKeys[8]) { + // Underground view toggle + RCT2_CALLPROC_X(0x0066CF8A, 0, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[9]) { + // Remove base land toggle + RCT2_CALLPROC_X(0x0066CF8A, 1, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[10]) { + // Remove vertical land toggle + RCT2_CALLPROC_X(0x0066CF8A, 2, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[11]) { + // See through rides toggle + RCT2_CALLPROC_X(0x0066CF8A, 4, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[12]) { + // See through scenery toggle + RCT2_CALLPROC_X(0x0066CF8A, 5, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[13]) { + // Invisible supports toggle + RCT2_CALLPROC_X(0x0066CF8A, 6, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[14]) { + // Invisible people toggle + RCT2_CALLPROC_X(0x0066CF8A, 7, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[15]) { + // Height marks on land toggle + RCT2_CALLPROC_X(0x0066CF8A, 9, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[16]) { + // Height marks on ride tracks toggle + RCT2_CALLPROC_X(0x0066CF8A, 10, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[17]) { + // Height marks on paths toggle + RCT2_CALLPROC_X(0x0066CF8A, 11, 0, 0, 0, 0, 0, 0); + } else if (key == gShortcutKeys[18]) { + // Adjust land + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 7, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[19]) { + // Adjust water + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 8, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[20]) { + // Build scenery + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 9, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[21]) { + // Build paths + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 10, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[22]) { + // Build new ride + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 11, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[23]) { + // Show financial information + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800)) { + RCT2_CALLPROC_EBPSAFE(0x0069DDF1); + } + } + } else if (key == gShortcutKeys[24]) { + // Show research information + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0E)) { + // Open new ride window + RCT2_CALLPROC_EBPSAFE(0x006B3CFF); + window = window_find_by_id(WC_CONSTRUCT_RIDE, 0); + if (window != NULL) { + window_event_helper(window, 10, WE_MOUSE_DOWN); + } + } + } else if (key == gShortcutKeys[25]) { + // Show rides list + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0E)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 12, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[26]) { + // Show park information + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0E)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 13, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[27]) { + // Show guest list + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0E)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 15, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[28]) { + // Show staff information + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0E)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 14, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[29]) { + // Show recent messages + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0E)) { + window_news_open(); + } + } else if (key == gShortcutKeys[30]) { + // Show map + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) { + window = window_find_by_id(WC_TOP_TOOLBAR, 0); + if (window != NULL) { + window_invalidate(window); + window_event_helper(window, 6, WE_MOUSE_UP); + } + } + } else if (key == gShortcutKeys[31]) { + // Screenshot + RCT2_CALLPROC_EBPSAFE(0x006E4034); } + } /** diff --git a/src/window.c b/src/window.c index 0a7f726040..f41a874ff6 100644 --- a/src/window.c +++ b/src/window.c @@ -1,5 +1,5 @@ /***************************************************************************** -* Copyright (c) 2014 Ted John +* Copyright (c) 2014 Ted John, Peter Hill * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. @@ -493,6 +493,47 @@ rct_window *window_find_by_id(rct_windowclass cls, rct_windownumber number) return NULL; } +/** + * Closes the top-most window + * + * rct2: 0x006E403C + */ +void window_close_top() { + rct_window* w; + + window_close_by_id(WC_DROPDOWN, 0); + + if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2) { + if (RCT2_ADDRESS(0x0141F570, uint8) != 1) { + return; + } + } + for (w = RCT2_FIRST_WINDOW; w < RCT2_LAST_WINDOW; w++){ + if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) { + window_close(w); + return; + } + } +} + +/** + * Closes all open windows + * + * rct2: 0x006EE927 + */ +void window_close_all() { + rct_window* w; + + window_close_by_id(WC_DROPDOWN, 0); + + for (w = RCT2_FIRST_WINDOW; w < RCT2_LAST_WINDOW; w++){ + if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) { + window_close(w); + w = RCT2_FIRST_WINDOW; + } + } +} + /** * * rct2: 0x006EA845 @@ -1203,4 +1244,13 @@ void window_guest_list_init_vars_b() { RCT2_GLOBAL(0x00F1EE02, uint32) = 0xFFFFFFFF; RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_GUEST_LIST_SELECTED_FILTER, uint8) = 0xFF; RCT2_GLOBAL(0x00F1AF20, uint16) = 0; -} \ No newline at end of file +} + +/** + * Wrapper for window events so C functions can call them + */ +void window_event_helper(rct_window* w, short widgetIndex, WINDOW_EVENTS event) { + + RCT2_CALLPROC_X(w->event_handlers[event], 0, 0, 0, widgetIndex, w, 0, 0); + +} diff --git a/src/window.h b/src/window.h index 01ce98f35c..eb4abfa776 100644 --- a/src/window.h +++ b/src/window.h @@ -292,6 +292,8 @@ rct_window *window_create(int x, int y, int width, int height, uint32 *event_han rct_window *window_create_auto_pos(int width, int height, uint32 *event_handlers, rct_windowclass cls, uint16 flags); void window_close(rct_window *window); void window_close_by_id(rct_windowclass cls, rct_windownumber number); +void window_close_top(); +void window_close_all(); 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); @@ -360,4 +362,6 @@ void window_ride_construction_init_vars(); void window_staff_init_vars(); +void window_event_helper(rct_window* w, short widgetIndex, WINDOW_EVENTS event); + #endif diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index fa59d02950..afacce3cf1 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -208,9 +208,10 @@ static void window_game_top_toolbar_mouseup() } break; case WIDX_SCENERY: - tool_set(w, WIDX_SCENERY, 0); - RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); - RCT2_CALLPROC_EBPSAFE(0x006E0FEF); + if (!tool_set(w, WIDX_SCENERY, 0)) { + RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 6); + RCT2_CALLPROC_EBPSAFE(0x006E0FEF); + } break; case WIDX_PATH: if (window_find_by_id(WC_FOOTPATH, 0) == NULL) { diff --git a/src/window_guest_list.c b/src/window_guest_list.c index 4af11e4dd4..a3f2de1480 100644 --- a/src/window_guest_list.c +++ b/src/window_guest_list.c @@ -142,7 +142,7 @@ void window_guest_list_open() rct_window* window; // Check if window is already open - window = window_bring_to_front_by_id(WC_RIDE_LIST, 0); + window = window_bring_to_front_by_id(WC_GUEST_LIST, 0); if (window != NULL) return; @@ -994,4 +994,4 @@ static int get_guest_face_sprite_large(rct_peep* peep){ } return sprite; -} \ No newline at end of file +}