From f4f07ae5bbb72a7053003dbfdb555f11f8a52502 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Tue, 5 Jan 2016 22:33:47 +0000 Subject: [PATCH] integrate variable: gInputPlaceObjectModifier --- src/input.c | 39 +++++++++++++++++++-------------- src/input.h | 7 ++++++ src/rct2.c | 3 ++- src/windows/map_tooltip.c | 2 +- src/windows/ride_construction.c | 8 +++---- src/windows/top_toolbar.c | 27 ++++++++++------------- 6 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/input.c b/src/input.c index 22cb0e7948..bf90a98d49 100644 --- a/src/input.c +++ b/src/input.c @@ -71,6 +71,7 @@ static sint32 _originalWindowHeight; uint8 gInputState; uint8 gInputFlags; +uint8 gInputPlaceObjectModifier; widget_ref gHoverWidget; widget_ref gPressedWidget; @@ -1388,14 +1389,14 @@ void title_handle_keyboard_input() if (!gConsoleOpen) { // Handle modifier keys and key scrolling - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0; + gInputPlaceObjectModifier = PLACE_OBJECT_MODIFIER_NONE; if (RCT2_GLOBAL(0x009E2B64, uint32) != 1) { if (gKeysState[SDL_SCANCODE_LSHIFT] || gKeysState[SDL_SCANCODE_RSHIFT]) - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) |= 1; + gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_SHIFT_Z; if (gKeysState[SDL_SCANCODE_LCTRL] || gKeysState[SDL_SCANCODE_RCTRL]) - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) |= 2; + gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_COPY_Z; if (gKeysState[SDL_SCANCODE_LALT] || gKeysState[SDL_SCANCODE_RALT]) - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) |= 4; + gInputPlaceObjectModifier |= 4; } } @@ -1415,7 +1416,7 @@ void title_handle_keyboard_input() continue; } - key |= RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) << 8; + key |= gInputPlaceObjectModifier << 8; w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); if (w != NULL) { @@ -1438,20 +1439,26 @@ void game_handle_keyboard_input() if (!gConsoleOpen) { // Handle mouse scrolling - if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, uint8) != 0) - if (gInputState == INPUT_STATE_NORMAL) - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & 3)) + if (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_EDGE_SCROLLING, uint8) != 0) { + if (gInputState == INPUT_STATE_NORMAL) { + if (!(gInputPlaceObjectModifier & (PLACE_OBJECT_MODIFIER_SHIFT_Z | PLACE_OBJECT_MODIFIER_COPY_Z))) { game_handle_edge_scroll(); + } + } + } // Handle modifier keys and key scrolling - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0; + gInputPlaceObjectModifier = PLACE_OBJECT_MODIFIER_NONE; if (RCT2_GLOBAL(0x009E2B64, uint32) != 1) { - if (gKeysState[SDL_SCANCODE_LSHIFT] || gKeysState[SDL_SCANCODE_RSHIFT]) - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) |= 1; - if (gKeysState[SDL_SCANCODE_LCTRL] || gKeysState[SDL_SCANCODE_RCTRL]) - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) |= 2; - if (gKeysState[SDL_SCANCODE_LALT] || gKeysState[SDL_SCANCODE_RALT]) - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) |= 4; + if (gKeysState[SDL_SCANCODE_LSHIFT] || gKeysState[SDL_SCANCODE_RSHIFT]) { + gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_SHIFT_Z; + } + if (gKeysState[SDL_SCANCODE_LCTRL] || gKeysState[SDL_SCANCODE_RCTRL]) { + gInputPlaceObjectModifier |= PLACE_OBJECT_MODIFIER_COPY_Z; + } + if (gKeysState[SDL_SCANCODE_LALT] || gKeysState[SDL_SCANCODE_RALT]) { + gInputPlaceObjectModifier |= 4; + } game_handle_key_scroll(); } } @@ -1477,7 +1484,7 @@ void game_handle_keyboard_input() continue; } - key |= RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) << 8; + key |= gInputPlaceObjectModifier << 8; w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); if (w != NULL) { diff --git a/src/input.h b/src/input.h index 2584ff4071..2953eb2f92 100644 --- a/src/input.h +++ b/src/input.h @@ -60,6 +60,12 @@ enum { INPUT_FLAG_VIEWPORT_SCROLLING = (1 << 7) }; +enum { + PLACE_OBJECT_MODIFIER_NONE = 0, + PLACE_OBJECT_MODIFIER_SHIFT_Z = (1 << 0), + PLACE_OBJECT_MODIFIER_COPY_Z = (1 << 1), +}; + typedef struct { rct_windowclass window_classification; rct_windownumber window_number; @@ -68,6 +74,7 @@ typedef struct { extern uint8 gInputState; extern uint8 gInputFlags; +extern uint8 gInputPlaceObjectModifier; extern widget_ref gHoverWidget; extern widget_ref gPressedWidget; diff --git a/src/rct2.c b/src/rct2.c index aa36ae4a30..e15e6b9859 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -29,6 +29,7 @@ #include "drawing/drawing.h" #include "editor.h" #include "game.h" +#include "input.h" #include "interface/chat.h" #include "interface/console.h" #include "interface/viewport.h" @@ -92,7 +93,7 @@ int rct2_init() config_reset_shortcut_keys(); config_shortcut_keys_load(); - RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0; + gInputPlaceObjectModifier = PLACE_OBJECT_MODIFIER_NONE; // config_load(); object_list_load(); diff --git a/src/windows/map_tooltip.c b/src/windows/map_tooltip.c index eb5b2179f1..87c65aa5bc 100644 --- a/src/windows/map_tooltip.c +++ b/src/windows/map_tooltip.c @@ -95,7 +95,7 @@ void window_map_tooltip_update_visibility() if ( _cursorHoldDuration < 25 || RCT2_GLOBAL(RCT2_ADDRESS_MAP_TOOLTIP_ARGS, sint16) == -1 || - (RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & 3) || + (gInputPlaceObjectModifier & 3) || window_find_by_class(WC_ERROR) != NULL ) { window_close_by_class(WC_MAP_TOOLTIP); diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index b1d9005935..7665d997e0 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -1961,7 +1961,7 @@ static bool ride_get_place_position_from_screen_position(int screenX, int screen rct_viewport *viewport; if (!_trackPlaceCtrlState) { - if (RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & 2) { + if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) { get_map_coordinates_from_pos(screenX, screenY, 0xFCCA, &mapX, &mapY, &interactionType, &mapElement, &viewport); if (interactionType != 0) { _trackPlaceCtrlZ = mapElement->base_height * 8; @@ -1969,20 +1969,20 @@ static bool ride_get_place_position_from_screen_position(int screenX, int screen } } } else { - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & 2)) { + if (!(gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z)) { _trackPlaceCtrlState = false; } } if (!_trackPlaceShiftState) { - if (RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & 1) { + if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) { _trackPlaceShiftState = true; _trackPlaceShiftStartScreenX = screenX; _trackPlaceShiftStartScreenY = screenY; _trackPlaceShiftZ = 0; } } else { - if (RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & 1) { + if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) { _trackPlaceShiftZ = floor2(_trackPlaceShiftStartScreenY - screenY + 4, 8); screenX = _trackPlaceShiftStartScreenX; screenY = _trackPlaceShiftStartScreenY; diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index 7c2e2b5e1c..a7a20d23c1 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -1008,11 +1008,10 @@ void sub_6E1F34(sint16 x, sint16 y, uint16 selected_scenery, sint16* grid_x, sin if (type == 0 && !gCheatsDisableSupportLimits) { RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_CTRL_PRESSED, uint8) = 0; RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_SHIFT_PRESSED, uint8) = 0; - } - else{ - if (RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_CTRL_PRESSED, uint8) == 0){ - // CTRL pressed - if (RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & (1 << 1)){ + } else { + if (RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_CTRL_PRESSED, uint8) == 0) { + if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_COPY_Z) { + // CTRL pressed rct_map_element* map_element; uint16 flags = VIEWPORT_INTERACTION_MASK_TERRAIN & @@ -1029,17 +1028,16 @@ void sub_6E1F34(sint16 x, sint16 y, uint16 selected_scenery, sint16* grid_x, sin RCT2_GLOBAL(RCT2_ADDRESS_CTRL_PRESS_Z_COORDINATE, uint16) = map_element->base_height * 8; } } - } - else{ - // CTRL not pressed - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & (1 << 1))){ + } else { + if (!(gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_COPY_Z)) { + // CTRL not pressed RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_CTRL_PRESSED, uint8) = 0; } } if (RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_SHIFT_PRESSED, uint8) == 0){ - // SHIFT pressed - if (RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & (1 << 0)){ + if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) { + // SHIFT pressed RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_SHIFT_PRESSED, uint8) = 1; RCT2_GLOBAL(RCT2_ADDRESS_SHIFT_PRESS_X_COORDINATE, uint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_SHIFT_PRESS_Y_COORDINATE, uint16) = y; @@ -1047,15 +1045,14 @@ void sub_6E1F34(sint16 x, sint16 y, uint16 selected_scenery, sint16* grid_x, sin } } else{ - // SHIFT pressed - if (RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) & (1 << 0)){ + if (gInputPlaceObjectModifier & PLACE_OBJECT_MODIFIER_SHIFT_Z) { + // SHIFT pressed RCT2_GLOBAL(RCT2_ADDRESS_SHIFT_PRESS_Z_VECTOR, sint16) = (RCT2_GLOBAL(RCT2_ADDRESS_SHIFT_PRESS_Y_COORDINATE, sint16) - y + 4) & 0xFFF8; x = RCT2_GLOBAL(RCT2_ADDRESS_SHIFT_PRESS_X_COORDINATE, sint16); y = RCT2_GLOBAL(RCT2_ADDRESS_SHIFT_PRESS_Y_COORDINATE, sint16); - } - else{ + } else { // SHIFT not pressed RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_TOOL_SHIFT_PRESSED, uint8) = 0; }