From 46178bb44f810a482a5b0627da8f577b884e1640 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 2 Jul 2015 17:00:39 +0100 Subject: [PATCH] implement finish-map-window part 6 --- src/input.c | 2 +- src/interface/window.c | 4 +- src/interface/window.h | 6 ++- src/windows/land.c | 22 +-------- src/windows/map.c | 101 ++++++++++++++++++++++++++++++++++++-- src/windows/top_toolbar.c | 15 ++++++ 6 files changed, 121 insertions(+), 29 deletions(-) diff --git a/src/input.c b/src/input.c index 2d4ea19218..56c1218d94 100644 --- a/src/input.c +++ b/src/input.c @@ -577,7 +577,7 @@ static void input_scroll_continue(rct_window *w, int widgetIndex, int state, int switch (scroll_part){ case SCROLL_PART_VIEW: - window_event_tool_drag_call(w, widgetIndex, w->number / 18, y); + window_event_scroll_mousedrag_call(w, scroll_id, x, y); break; case SCROLL_PART_HSCROLLBAR_LEFT: input_scroll_part_update_hleft(w, widgetIndex, scroll_id); diff --git a/src/interface/window.c b/src/interface/window.c index bdd5084f98..264d89beac 100644 --- a/src/interface/window.c +++ b/src/interface/window.c @@ -1952,9 +1952,9 @@ void window_event_scroll_mousedown_call(rct_window* w, int scrollIndex, int x, i RCT2_CALLPROC_X(w->event_handlers[WE_SCROLL_MOUSEDOWN], scrollIndex, 0, x, y, (int)w, (int)window_get_scroll_widget(w, scrollIndex), 0); } -void window_event_unknown_11_call(rct_window* w) +void window_event_scroll_mousedrag_call(rct_window* w, int scrollIndex, int x, int y) { - window_event_call_address(w->event_handlers[WE_UNKNOWN_11], w); + RCT2_CALLPROC_X(w->event_handlers[WE_SCROLL_MOUSEDRAG], scrollIndex, 0, x, y, (int)w, (int)window_get_scroll_widget(w, scrollIndex), 0); } void window_event_scroll_mouseover_call(rct_window* w, int scrollIndex, int x, int y) diff --git a/src/interface/window.h b/src/interface/window.h index 5e02e69147..9423d7c31c 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -273,7 +273,7 @@ typedef enum { WE_UNKNOWN_0E = 14, WE_SCROLL_GETSIZE = 15, WE_SCROLL_MOUSEDOWN = 16, - WE_UNKNOWN_11 = 17, + WE_SCROLL_MOUSEDRAG = 17, WE_SCROLL_MOUSEOVER = 18, WE_TEXT_INPUT = 19, WE_UNKNOWN_14 = 20, @@ -632,7 +632,7 @@ void window_event_tool_abort_call(rct_window* w, int widgetIndex); void window_event_unknown_0E_call(rct_window* w); int window_get_scroll_size(rct_window *w, int scrollIndex, int *width, int *height); void window_event_scroll_mousedown_call(rct_window* w, int scrollIndex, int x, int y); -void window_event_unknown_11_call(rct_window* w); +void window_event_scroll_mousedrag_call(rct_window* w, int scrollIndex, int x, int y); void window_event_scroll_mouseover_call(rct_window* w, int scrollIndex, int x, int y); void window_event_textinput_call(rct_window *w, int widgetIndex, char *text); void window_event_unknown_14_call(rct_window* w); @@ -655,6 +655,8 @@ void window_cancel_textbox(); void window_update_textbox_caret(); void window_update_textbox(); +bool land_tool_is_active(); + //Cheat: in-game land ownership editor void toggle_ingame_land_ownership_editor(); diff --git a/src/windows/land.c b/src/windows/land.c index 5c5c308f81..8d456e9ba9 100644 --- a/src/windows/land.c +++ b/src/windows/land.c @@ -96,8 +96,6 @@ static void* window_land_events[] = { window_land_emptysub }; -static int window_land_should_close(); - static char window_land_floor_texture_order[] = { TERRAIN_SAND_DARK, TERRAIN_SAND_LIGHT, TERRAIN_DIRT, TERRAIN_GRASS_CLUMPS, TERRAIN_GRASS, TERRAIN_ROCK, TERRAIN_SAND, TERRAIN_MARTIAN, TERRAIN_CHECKERBOARD, TERRAIN_ICE, @@ -158,7 +156,7 @@ void window_land_open() static void window_land_close() { // If the tool wasn't changed, turn tool off - if (!window_land_should_close()) + if (land_tool_is_active()) tool_cancel(); } @@ -349,8 +347,7 @@ static void window_land_inputsize(rct_window *w) */ static void window_land_update(rct_window *w) { - // Close window if another tool is open - if (window_land_should_close()) + if (!land_tool_is_active()) window_close(w); } @@ -433,18 +430,3 @@ static void window_land_paint() gfx_draw_string_centred(dpi, 986, x, y, 0, (void*)0x013CE952); } } - -/** - * - * rct2: 0x0066D104 - */ -static int window_land_should_close() -{ - if (!(RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_TOOL_ACTIVE)) - return 1; - if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) != WC_TOP_TOOLBAR) - return 1; - if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, sint16) != 7) - return 1; - return 0; -} diff --git a/src/windows/map.c b/src/windows/map.c index 45a4a7c491..22ed38688c 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -166,6 +166,8 @@ static void map_window_increase_map_size(); static void map_window_decrease_map_size(); static void map_window_set_pixels(rct_window *w); +static void map_window_screen_to_map(int screenX, int screenY, int *mapX, int *mapY); + /** * * rct2: 0x0068C88A @@ -439,7 +441,6 @@ static void window_map_update(rct_window *w) } } - /** * * rct2: 0x0068D093 @@ -465,7 +466,6 @@ static void window_map_toolupdate() } } - /** * * rct2: 0x0068D074 @@ -574,12 +574,77 @@ static void window_map_scrollgetsize() */ static void window_map_scrollmousedown() { + int mapX, mapY, mapZ; short x, y, scrollIndex; - rct_window *w; + rct_window *w, *mainWindow; window_scrollmouse_get_registers(w, scrollIndex, x, y); - RCT2_CALLPROC_X(0x0068D726, scrollIndex, 0, x, y, (int)w, 0, 0); + map_window_screen_to_map(x, y, &mapX, &mapY); + mapX = clamp(0, mapX, 8191); + mapY = clamp(0, mapY, 8191); + mapZ = map_element_height(x, y); + + mainWindow = window_get_main(); + if (mainWindow != NULL) { + window_scroll_to_location(mainWindow, mapX, mapY, mapZ); + } + + if (land_tool_is_active()) { + // Set land terrain + int landToolSize = max(1, RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint16)); + int size = (landToolSize * 32) - 32; + int radius = (landToolSize * 16) - 16; + mapX = (mapX - radius) & 0xFFE0; + mapY = (mapY - radius) & 0xFFE0; + + map_invalidate_selection_rect(); + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) |= (1 << 0); + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_TYPE, uint16) = 4; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16) = mapX; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16) = mapY; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16) = mapX + size; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16) = mapY + size; + map_invalidate_selection_rect(); + + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID, rct_string_id) = 1387; + game_do_command( + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, sint16), + GAME_COMMAND_FLAG_APPLY, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, sint16), + RCT2_GLOBAL(RCT2_ADDRESS_SELECTED_TERRAIN_SURFACE, uint8) | (RCT2_GLOBAL(RCT2_ADDRESS_SELECTED_TERRAIN_EDGE, uint8) << 8), + GAME_COMMAND_CHANGE_SURFACE_STYLE, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, sint16), + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, sint16) + ); + } else if (widget_is_active_tool(w, WIDX_SET_LAND_RIGHTS)) { + // Set land rights + int landToolSize = max(1, RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, uint16)); + int size = (landToolSize * 32) - 32; + int radius = (landToolSize * 16) - 16; + mapX = (mapX - radius) & 0xFFE0; + mapY = (mapY - radius) & 0xFFE0; + + map_invalidate_selection_rect(); + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) |= (1 << 0); + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_TYPE, uint16) = 4; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16) = mapX; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16) = mapY; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16) = mapX + size; + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16) = mapY + size; + map_invalidate_selection_rect(); + + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, rct_string_id) = 0; + game_do_command( + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_X, uint16), + GAME_COMMAND_FLAG_APPLY, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_A_Y, uint16), + RCT2_GLOBAL(0x00F1AD61, uint8), + GAME_COMMAND_SET_LAND_OWNERSHIP, + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_X, uint16), + RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_B_Y, uint16) + ); + } } static void window_map_textinput() @@ -1659,3 +1724,31 @@ static void map_window_set_pixels(rct_window *w) if (RCT2_GLOBAL(0x00F1AD6C, uint32) >= 256) RCT2_GLOBAL(0x00F1AD6C, uint32) = 0; } + +static void map_window_screen_to_map(int screenX, int screenY, int *mapX, int *mapY) +{ + int x, y; + + screenX = ((screenX + 8) - 256) / 2; + screenY = ((screenY + 8) ) / 2; + x = (screenY - screenX) * 32; + y = (screenX + screenY) * 32; + switch (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) & 3) { + case 0: + *mapX = x; + *mapY = y; + break; + case 1: + *mapX = 8191 - y; + *mapY = x; + break; + case 2: + *mapX = 8191 - x; + *mapY = 8191 - y; + break; + case 3: + *mapX = y; + *mapY = 8191 - x; + break; + } +} diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index d86e831383..25e21e990f 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -3038,3 +3038,18 @@ void toggle_water_window(rct_window *topToolbar, int widgetIndex) window_water_open(); } } + +/** + * + * rct2: 0x0066D104 + */ +bool land_tool_is_active() +{ + if (!(RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_TOOL_ACTIVE)) + return false; + if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass) != WC_TOP_TOOLBAR) + return false; + if (RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, sint16) != WIDX_LAND) + return false; + return true; +}