From b2d1f0dfd6a9b9a00d85f36e9e3231e506cc630d Mon Sep 17 00:00:00 2001 From: ZedThree Date: Fri, 9 May 2014 12:54:11 +0200 Subject: [PATCH] Add functions for closing top/all window(s) --- src/window.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- src/window.h | 2 ++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/window.c b/src/window.c index 0a7f726040..9ce9708cdf 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,4 @@ 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 +} diff --git a/src/window.h b/src/window.h index 956507fa1e..a9dad108d6 100644 --- a/src/window.h +++ b/src/window.h @@ -291,6 +291,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);