From 6f1cd77f3c3efd95b84ed259839f5fc9bc79f9ce Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 28 May 2015 01:15:58 +0100 Subject: [PATCH] implement textinput_cancel and refactor textinput event calls --- src/addresses.h | 4 ++++ src/interface/viewport.c | 2 +- src/interface/window.c | 31 +++++++++++++++++++++++++++++++ src/interface/window.h | 2 ++ src/windows/banner.c | 2 +- src/windows/text_input.c | 6 +++--- 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 4e70688479..962770bc24 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -230,6 +230,10 @@ #define RCT2_ADDRESS_WINDOW_DPI 0x009DEA74 +#define RCT2_ADDRESS_TEXTINPUT_WIDGETINDEX 0x009DEB88 +#define RCT2_ADDRESS_TEXTINPUT_WINDOWNUMBER 0x009DEB8A +#define RCT2_ADDRESS_TEXTINPUT_WINDOWCLASS 0x009DEB8C + #define RCT2_ADDRESS_DSOUND_BUFFERS 0x009E1AB0 #define RCT2_ADDRESS_NUM_DSOUND_DEVICES 0x009E2B88 #define RCT2_ADDRESS_DSOUND_DEVICES 0x009E2B8C diff --git a/src/interface/viewport.c b/src/interface/viewport.c index cd5043b6ea..74a03069e8 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -112,7 +112,7 @@ void viewport_init_all() RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_NOT_SHOWN_TICKS, sint16) = -1; RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, sint16) = 0; RCT2_GLOBAL(0x009DEA50, sint16) = -1; - RCT2_CALLPROC_EBPSAFE(0x006EE3C3); + textinput_cancel(); format_string((char*)0x0141FA44, STR_CANCEL, NULL); format_string((char*)0x0141F944, STR_OK, NULL); } diff --git a/src/interface/window.c b/src/interface/window.c index 335d425add..03fac892cb 100644 --- a/src/interface/window.c +++ b/src/interface/window.c @@ -2141,3 +2141,34 @@ int window_can_resize(rct_window *w) { return (w->flags & WF_RESIZABLE) && (w->min_width != w->max_width || w->min_height != w->max_height); } + +void window_event_textinput_call(rct_window *w, int widgetIndex, char *text) +{ + RCT2_CALLPROC_X(w->event_handlers[WE_TEXT_INPUT], 0, 0, text != NULL, widgetIndex, (int)w, (int)text, 0); +} + +/** + * + * rct2: 0x006EE3C3 + */ +void textinput_cancel() +{ + rct_window *w; + + // Close the new text input window + window_close_by_class(WC_TEXTINPUT); + + // The following code is only necessary for the old Windows text input dialog. In theory this isn't used anymore, but can + // still be triggered via original code paths. + RCT2_CALLPROC_EBPSAFE(0x0040701D); + if (RCT2_GLOBAL(0x009DEB8C, uint8) != 255) { + RCT2_CALLPROC_EBPSAFE(0x006EE4E2); + w = window_find_by_number( + RCT2_GLOBAL(RCT2_ADDRESS_TEXTINPUT_WINDOWCLASS, rct_windowclass), + RCT2_GLOBAL(RCT2_ADDRESS_TEXTINPUT_WINDOWNUMBER, rct_windownumber) + ); + if (w != NULL) { + window_event_textinput_call(w, RCT2_GLOBAL(RCT2_ADDRESS_TEXTINPUT_WIDGETINDEX, uint16), NULL); + } + } +} \ No newline at end of file diff --git a/src/interface/window.h b/src/interface/window.h index acae56af2c..2a6969a9c0 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -590,8 +590,10 @@ void window_event_resize_call(rct_window* w); void window_event_mouse_down_call(rct_window* w, int widgetIndex); void window_event_invalidate_call(rct_window* w); void window_event_update_call(rct_window *w); +void window_event_textinput_call(rct_window *w, int widgetIndex, char *text); void sub_6EA73F(); +void textinput_cancel(); void window_move_and_snap(rct_window *w, int newWindowX, int newWindowY, int snapProximity); int window_can_resize(rct_window *w); diff --git a/src/windows/banner.c b/src/windows/banner.c index 76626d71cf..febc389481 100644 --- a/src/windows/banner.c +++ b/src/windows/banner.c @@ -207,7 +207,7 @@ static void window_banner_mouseup() window_text_input_open(w, WIDX_BANNER_TEXT, 2982, 2983, gBanners[w->number].string_idx, 0, 32); break; case WIDX_BANNER_NO_ENTRY: - RCT2_CALLPROC_EBPSAFE(0x006EE3C3); + textinput_cancel(); banner->flags ^= BANNER_FLAG_NO_ENTRY; window_invalidate(w); diff --git a/src/windows/text_input.c b/src/windows/text_input.c index d12a5bfe0a..d0b81642a8 100644 --- a/src/windows/text_input.c +++ b/src/windows/text_input.c @@ -240,7 +240,7 @@ static void window_text_input_mouseup(){ // Pass back the text that has been entered. // ecx when zero means text input failed if (calling_w != NULL) - RCT2_CALLPROC_X(calling_w->event_handlers[WE_TEXT_INPUT], 0, 0, 0, calling_widget, (int)calling_w, (int)text_input, 0); + window_event_textinput_call(calling_w, calling_widget, NULL); window_close(w); break; case WIDX_OKAY: @@ -248,7 +248,7 @@ static void window_text_input_mouseup(){ // Pass back the text that has been entered. // ecx when none zero means text input success if (calling_w != NULL) - RCT2_CALLPROC_X(calling_w->event_handlers[WE_TEXT_INPUT], 0, 0, 1, calling_widget, (int)calling_w, (int)text_input, 0); + window_event_textinput_call(calling_w, calling_widget, text_input); window_close(w); } } @@ -340,7 +340,7 @@ static void window_text_input_text(int key, rct_window* w){ // Pass back the text that has been entered. // ecx when none zero means text input success if (calling_w) - RCT2_CALLPROC_X(calling_w->event_handlers[WE_TEXT_INPUT], 0, 0, 1, calling_widget, (int)calling_w, (int)text_input, 0); + window_event_textinput_call(calling_w, calling_widget, text_input); } window_invalidate(w);