From b5069d3809438648b5de2d9e0bd012df0ed4dfd8 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 4 Jan 2016 22:45:51 +0000 Subject: [PATCH] integrate variable: gInputState --- src/game.c | 4 +-- src/input.c | 56 +++++++++++++++++++++------------------- src/input.h | 15 +++++++++++ src/interface/viewport.c | 3 ++- src/interface/widget.c | 2 +- src/interface/window.h | 13 ---------- src/windows/dropdown.c | 4 +-- src/windows/scenery.c | 4 +-- src/windows/tooltip.c | 3 ++- 9 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/game.c b/src/game.c index 7463dc8e5e..3c343e2428 100644 --- a/src/game.c +++ b/src/game.c @@ -291,8 +291,8 @@ void game_update() RCT2_GLOBAL(0x009E2D74, uint32) = 0; break; } else { - if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) == INPUT_STATE_RESET || - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) == INPUT_STATE_NORMAL + if (gInputState == INPUT_STATE_RESET || + gInputState == INPUT_STATE_NORMAL ) { if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_VIEWPORT_SCROLLING) { RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) &= ~INPUT_FLAG_VIEWPORT_SCROLLING; diff --git a/src/input.c b/src/input.c index 2f3ca89b54..0ea15b9fea 100644 --- a/src/input.c +++ b/src/input.c @@ -50,6 +50,8 @@ static rct_windownumber _dragWindowNumber; static int _dragWidgetIndex, _dragScrollIndex; static int _originalWindowWidth, _originalWindowHeight; +uint8 gInputState; + typedef struct { uint32 x, y; uint32 state; //1 = LeftDown 2 = LeftUp 3 = RightDown 4 = RightUp @@ -184,7 +186,7 @@ static rct_mouse_data* get_mouse_input() * rct2: 0x006E957F */ static void input_scroll_drag_begin(int x, int y, rct_window* w, rct_widget* widget, int widgetIndex) { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_SCROLL_RIGHT; + gInputState = INPUT_STATE_SCROLL_RIGHT; _dragX = x; _dragY = y; _dragWindowClass = w->classification; @@ -244,7 +246,7 @@ static void input_scroll_right(int x, int y, int state) { if (w == NULL) { platform_show_cursor(); - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; return; } @@ -258,7 +260,7 @@ static void input_scroll_right(int x, int y, int state) { input_scroll_drag_continue(x, y, w); break; case 4: - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; platform_show_cursor(); break; } @@ -279,7 +281,7 @@ static void game_handle_input_mouse(int x, int y, int state) widgetIndex = w == NULL ? -1 : window_find_widget_from_point(w, x, y); widget = widgetIndex == -1 ? 0 : &w->widgets[widgetIndex]; - switch (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8)) { + switch (gInputState) { case INPUT_STATE_RESET: window_tooltip_reset(x, y); // fall-through @@ -317,7 +319,7 @@ static void game_handle_input_mouse(int x, int y, int state) case INPUT_STATE_POSITIONING_WINDOW: w = window_find_by_number(_dragWindowClass, _dragWindowNumber); if (w == NULL) { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; } else { input_window_position_continue(w, _dragX, _dragY, x, y); @@ -346,13 +348,13 @@ static void game_handle_input_mouse(int x, int y, int state) RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWNUMBER, rct_windownumber) ); if (!w){ - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 0; + gInputState = INPUT_STATE_RESET; break; } if (state == 0){ if (!w->viewport){ - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 0; + gInputState = INPUT_STATE_RESET; break; } @@ -371,7 +373,7 @@ static void game_handle_input_mouse(int x, int y, int state) } else if (state == 2){ - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 0; + gInputState = INPUT_STATE_RESET; if (RCT2_GLOBAL(0x9DE52E, rct_windownumber) != w->number)break; if ((RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_TOOL_ACTIVE)){ w = window_find_by_number( @@ -399,7 +401,7 @@ static void game_handle_input_mouse(int x, int y, int state) case INPUT_STATE_RESIZING: w = window_find_by_number(_dragWindowClass, _dragWindowNumber); if (w == NULL) { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; } else { if (state == 2) @@ -419,7 +421,7 @@ static void game_handle_input_mouse(int x, int y, int state) void input_window_position_begin(rct_window *w, int widgetIndex, int x, int y) { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_POSITIONING_WINDOW; + gInputState = INPUT_STATE_POSITIONING_WINDOW; _dragX = x - w->x; _dragY = y - w->y; _dragWindowClass = w->classification; @@ -437,7 +439,7 @@ static void input_window_position_continue(rct_window *w, int wdx, int wdy, int static void input_window_position_end(rct_window *w, int x, int y) { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_NORMAL; + gInputState = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint8) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_CLASS, rct_windowclass) = _dragWindowClass; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_NUMBER, rct_windownumber) = _dragWindowNumber; @@ -447,7 +449,7 @@ static void input_window_position_end(rct_window *w, int x, int y) static void input_window_resize_begin(rct_window *w, int widgetIndex, int x, int y) { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESIZING; + gInputState = INPUT_STATE_RESIZING; _dragX = x; _dragY = y; _dragWindowClass = w->classification; @@ -477,7 +479,7 @@ static void input_window_resize_continue(rct_window *w, int x, int y) static void input_window_resize_end() { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_NORMAL; + gInputState = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint8) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_CLASS, rct_windowclass) = _dragWindowClass; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_NUMBER, rct_windownumber) = _dragWindowNumber; @@ -491,7 +493,7 @@ static void input_window_resize_end() static void input_viewport_drag_begin(rct_window *w, int x, int y) { w->flags &= ~WF_SCROLLING_TO_LOCATION; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_VIEWPORT_RIGHT; + gInputState = INPUT_STATE_VIEWPORT_RIGHT; _dragWindowClass = w->classification; _dragWindowNumber = w->number; RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_DRAG_START, sint16) = 0; @@ -518,7 +520,7 @@ static void input_viewport_drag_continue() RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_DRAG_START, sint16) += RCT2_GLOBAL(RCT2_ADDRESS_TICKS_SINCE_LAST_UPDATE, sint16); if (viewport == NULL) { platform_show_cursor(); - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; } else if (dx != 0 || dy != 0) { if (!(w->flags & WF_NO_SCROLLING)) { // User dragged a scrollable viewport @@ -544,7 +546,7 @@ static void input_viewport_drag_continue() static void input_viewport_drag_end() { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; platform_show_cursor(); } @@ -558,7 +560,7 @@ static void input_scroll_begin(rct_window *w, int widgetIndex, int x, int y) widget = &w->widgets[widgetIndex]; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_SCROLL_LEFT; + gInputState = INPUT_STATE_SCROLL_LEFT; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16) = widgetIndex; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, rct_windowclass) = w->classification; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, rct_windownumber) = w->number; @@ -702,7 +704,7 @@ static void input_scroll_continue(rct_window *w, int widgetIndex, int state, int static void input_scroll_end() { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; invalidate_scroll(); } @@ -1004,7 +1006,7 @@ static void input_widget_left(int x, int y, rct_window *w, int widgetIndex) input_window_resize_begin(w, widgetIndex, x, y); break; case WWT_VIEWPORT: - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_VIEWPORT_LEFT; + gInputState = INPUT_STATE_VIEWPORT_LEFT; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, uint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, uint16) = y; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWCLASS, rct_windowclass) = windowClass; @@ -1035,7 +1037,7 @@ static void input_widget_left(int x, int y, rct_window *w, int widgetIndex) RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, rct_windownumber) = windowNumber; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16) = widgetIndex; RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) |= INPUT_FLAG_WIDGET_PRESSED; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_WIDGET_PRESSED; + gInputState = INPUT_STATE_WIDGET_PRESSED; RCT2_GLOBAL(0x009DE528, uint16) = 1; widget_invalidate_by_number(windowClass, windowNumber, widgetIndex); @@ -1185,7 +1187,7 @@ void input_state_widget_pressed(int x, int y, int state, int widgetIndex, rct_wi rct_window *cursor_w = window_find_by_number(cursor_w_class, cursor_w_number); if (cursor_w == NULL) { - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 0; + gInputState = INPUT_STATE_RESET; return; } @@ -1214,7 +1216,7 @@ void input_state_widget_pressed(int x, int y, int state, int widgetIndex, rct_wi return; case 3: case 2: - if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) == 5) { + if (gInputState == INPUT_STATE_DROPDOWN_ACTIVE) { if (w) { int dropdown_index = 0; @@ -1251,7 +1253,7 @@ void input_state_widget_pressed(int x, int y, int state, int widgetIndex, rct_wi widget_invalidate_by_number(cursor_w_class, cursor_w_number, cursor_widgetIndex); } - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 1; + gInputState = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WIDGET_INDEX, uint16) = cursor_widgetIndex; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_CLASS, rct_windowclass) = cursor_w_class; @@ -1263,7 +1265,7 @@ void input_state_widget_pressed(int x, int y, int state, int widgetIndex, rct_wi } if (state == 3) return; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 1; + gInputState = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WIDGET_INDEX, uint16) = cursor_widgetIndex; @@ -1288,7 +1290,7 @@ void input_state_widget_pressed(int x, int y, int state, int widgetIndex, rct_wi } RCT2_GLOBAL(0x9DE528, uint16) = 0; - if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) != 5){ + if (gInputState != INPUT_STATE_DROPDOWN_ACTIVE){ // Hold down widget and drag outside of area?? if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_WIDGET_PRESSED){ RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) &= 0xFFFE; @@ -1434,7 +1436,7 @@ void game_handle_keyboard_input() // Handle mouse scrolling if (RCT2_GLOBAL(RCT2_ADDRESS_ON_TUTORIAL, uint8) == 0) if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, uint8) != 0) - if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) == 1) + if (gInputState == INPUT_STATE_NORMAL) if (!(RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & 3)) game_handle_edge_scroll(); @@ -1519,7 +1521,7 @@ int get_next_key() * rct2: 0x006ED990 */ void sub_6ED990(char cursor_id){ - if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) == INPUT_STATE_RESIZING) + if (gInputState == INPUT_STATE_RESIZING) { cursor_id = CURSOR_DIAGONAL_ARROWS; //resize icon } diff --git a/src/input.h b/src/input.h index e6322a68e8..32f4478717 100644 --- a/src/input.h +++ b/src/input.h @@ -23,6 +23,19 @@ #include "interface/window.h" +enum { + INPUT_STATE_RESET, + INPUT_STATE_NORMAL, + INPUT_STATE_WIDGET_PRESSED, + INPUT_STATE_POSITIONING_WINDOW, + INPUT_STATE_VIEWPORT_RIGHT, + INPUT_STATE_DROPDOWN_ACTIVE, + INPUT_STATE_VIEWPORT_LEFT, + INPUT_STATE_SCROLL_LEFT, + INPUT_STATE_RESIZING, + INPUT_STATE_SCROLL_RIGHT +}; + enum { INPUT_FLAG_WIDGET_PRESSED = (1 << 0), @@ -47,6 +60,8 @@ enum { INPUT_FLAG_VIEWPORT_SCROLLING = (1 << 7) }; +extern uint8 gInputState; + void title_handle_keyboard_input(); void game_handle_input(); void game_handle_keyboard_input(); diff --git a/src/interface/viewport.c b/src/interface/viewport.c index 1de8b79160..0de5641832 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -22,6 +22,7 @@ #include "../config.h" #include "../drawing/drawing.h" #include "../drawing/supports.h" +#include "../input.h" #include "../localisation/localisation.h" #include "../ride/ride_data.h" #include "../ride/track_data.h" @@ -102,7 +103,7 @@ void viewport_init_all() // ? RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) = INPUT_STATE_RESET; + gInputState = INPUT_STATE_RESET; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, rct_windowclass) = -1; RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_IMAGE, sint32) = -1; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_NOT_SHOWN_TICKS, sint16) = -1; diff --git a/src/interface/widget.c b/src/interface/widget.c index a07bba487e..97f0333641 100644 --- a/src/interface/widget.c +++ b/src/interface/widget.c @@ -978,7 +978,7 @@ int widget_is_disabled(rct_window *w, int widgetIndex) int widget_is_pressed(rct_window *w, int widgetIndex) { - int inputState = RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8); + int inputState = gInputState; if (w->pressed_widgets & (1LL << widgetIndex)) return 1; diff --git a/src/interface/window.h b/src/interface/window.h index c3fddca24b..b8a44147a1 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -386,19 +386,6 @@ enum { SCROLL_PART_VSCROLLBAR_THUMB = 10, }; -enum { - INPUT_STATE_RESET = 0, - INPUT_STATE_NORMAL = 1, - INPUT_STATE_WIDGET_PRESSED = 2, - INPUT_STATE_POSITIONING_WINDOW = 3, - INPUT_STATE_VIEWPORT_RIGHT = 4, - INPUT_STATE_DROPDOWN_ACTIVE = 5, - INPUT_STATE_VIEWPORT_LEFT = 6, - INPUT_STATE_SCROLL_LEFT = 7, - INPUT_STATE_RESIZING = 8, - INPUT_STATE_SCROLL_RIGHT = 9 -}; - enum { WC_MAIN_WINDOW = 0, WC_TOP_TOOLBAR = 1, diff --git a/src/windows/dropdown.c b/src/windows/dropdown.c index 655bbde163..4188ff2203 100644 --- a/src/windows/dropdown.c +++ b/src/windows/dropdown.c @@ -204,7 +204,7 @@ void window_dropdown_show_text_custom_width(int x, int y, int extray, uint8 colo gDropdownItemsDisabled = 0; gDropdownItemsChecked = 0; gDropdownIsColour = false; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) = INPUT_STATE_DROPDOWN_ACTIVE; + gInputState = INPUT_STATE_DROPDOWN_ACTIVE; } /** @@ -274,7 +274,7 @@ void window_dropdown_show_image(int x, int y, int extray, uint8 colour, uint8 fl gDropdownHighlightedIndex = -1; gDropdownItemsDisabled = 0; gDropdownItemsChecked = 0; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) = INPUT_STATE_DROPDOWN_ACTIVE; + gInputState = INPUT_STATE_DROPDOWN_ACTIVE; // Copy the following properties until all use of it is decompiled gDropdownHighlightedIndex = gDropdownHighlightedIndex; diff --git a/src/windows/scenery.c b/src/windows/scenery.c index 3c8e57278b..1c2517765a 100644 --- a/src/windows/scenery.c +++ b/src/windows/scenery.c @@ -693,7 +693,7 @@ static void window_scenery_update(rct_window *w) if (widgetIndex >= WIDX_SCENERY_TAB_CONTENT_PANEL) { w->scenery.hover_counter++; if (w->scenery.hover_counter < 8) { - if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) != INPUT_STATE_SCROLL_LEFT) { + if (gInputState != INPUT_STATE_SCROLL_LEFT) { w->min_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH; w->min_height = WINDOW_SCENERY_HEIGHT; @@ -713,7 +713,7 @@ static void window_scenery_update(rct_window *w) } } else { w->scenery.hover_counter = 0; - if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, sint8) != INPUT_STATE_SCROLL_LEFT) { + if (gInputState != INPUT_STATE_SCROLL_LEFT) { w->min_width = WINDOW_SCENERY_WIDTH; w->max_width = WINDOW_SCENERY_WIDTH; w->min_height = WINDOW_SCENERY_HEIGHT; diff --git a/src/windows/tooltip.c b/src/windows/tooltip.c index f2bf9b6e7b..fe74464f42 100644 --- a/src/windows/tooltip.c +++ b/src/windows/tooltip.c @@ -21,6 +21,7 @@ #include "../addresses.h" #include "../drawing/drawing.h" #include "../localisation/localisation.h" +#include "../input.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -74,7 +75,7 @@ void window_tooltip_reset(int x, int y) RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint16) = y; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_CLASS, uint8) = 255; - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 1; + gInputState = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) &= ~(1 << 4); }