From 9fdad31be27746d6873fa498f09538884dbd9e1f Mon Sep 17 00:00:00 2001 From: Broxzier Date: Sun, 9 Oct 2016 00:00:36 +0200 Subject: [PATCH] Tile inspector raises surface when all corners are raised. Removes printf. --- src/windows/tile_inspector.c | 50 +++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/windows/tile_inspector.c b/src/windows/tile_inspector.c index 7f236c2a15..0ba158b5b6 100644 --- a/src/windows/tile_inspector.c +++ b/src/windows/tile_inspector.c @@ -459,6 +459,7 @@ static void window_tile_inspector_swap_elements(sint16 first, sint16 second); static void window_tile_inspector_remove_element(int index); static void window_tile_inspector_rotate_element(int index); static void window_tile_inspector_sort_elements(rct_window *w); +static void window_tile_inspector_surface_toggle_corner(rct_map_element *mapElement, int cornerIndex); static void window_tile_inspector_track_block_height_offset(rct_map_element *mapElement, uint8 offset); static void window_tile_inspector_track_block_set_lift(rct_map_element *mapElement, bool chain); static void window_tile_inspector_quarter_tile_set(rct_map_element *const mapElement, const int index); @@ -707,6 +708,37 @@ static void window_tile_inspector_sort_elements(rct_window *w) { } } +static void window_tile_inspector_surface_toggle_corner(rct_map_element *mapElement, int cornerIndex) { + const uint8 originalSlope = mapElement->properties.surface.slope; + const bool diagonal = (originalSlope & 0x10) >> 4; + + mapElement->properties.surface.slope ^= 1 << cornerIndex; + if (mapElement->properties.surface.slope & 0x0F) { + mapElement->clearance_height = mapElement->base_height + 2; + } + else { + mapElement->clearance_height = mapElement->base_height; + } + + // All corners are raised + if ((mapElement->properties.surface.slope & 0x0F) == 0x0F) { + mapElement->properties.surface.slope &= ~0x1F; + + if (diagonal) { + switch (originalSlope & 0x0F) { + case 0b1011: mapElement->properties.surface.slope |= (1 << 0); break; + case 0b0111: mapElement->properties.surface.slope |= (1 << 1); break; + case 0b1110: mapElement->properties.surface.slope |= (1 << 2); break; + case 0b1101: mapElement->properties.surface.slope |= (1 << 3); break; + } + } + + // Update base and clearance heights + mapElement->base_height += 2; + mapElement->clearance_height = mapElement->base_height + (diagonal ? 2 : 0); + } +} + // Copied from track.c (track_remove), and modified for raising/lowering // Not sure if this should be in this file, track.c, or maybe another one static void window_tile_inspector_track_block_height_offset(rct_map_element *mapElement, uint8 offset) { @@ -1027,21 +1059,22 @@ static void window_tile_inspector_mouseup(rct_window *w, int widgetIndex) { case WIDX_SURFACE_CHECK_CORNER_E: case WIDX_SURFACE_CHECK_CORNER_S: case WIDX_SURFACE_CHECK_CORNER_W: - mapElement->properties.surface.slope ^= 1 << (((widgetIndex - WIDX_SURFACE_CHECK_CORNER_N) + 2 - get_current_rotation()) & 3); - if (mapElement->properties.surface.slope & 0x0F) { - mapElement->clearance_height = mapElement->base_height + 2; - } - else { - mapElement->clearance_height = mapElement->base_height; - } + window_tile_inspector_surface_toggle_corner(mapElement, ((widgetIndex - WIDX_SURFACE_CHECK_CORNER_N) + 2 - get_current_rotation()) & 3); map_invalidate_tile_full(windowTileInspectorTileX << 5, windowTileInspectorTileY << 5); - widget_invalidate(w, widgetIndex); + window_invalidate(w); break; case WIDX_SURFACE_CHECK_DIAGONAL: mapElement->properties.surface.slope ^= 0x10; if (mapElement->properties.surface.slope & 0x10) { mapElement->clearance_height = mapElement->base_height + 4; } + else if (mapElement->properties.surface.slope & 0x0F) { + mapElement->clearance_height = mapElement->base_height + 2; + } + else { + mapElement->clearance_height = mapElement->base_height; + } + map_invalidate_tile_full(windowTileInspectorTileX << 5, windowTileInspectorTileY << 5); widget_invalidate(w, widgetIndex); break; @@ -1332,7 +1365,6 @@ static void window_tile_inspector_dropdown(rct_window *w, int widgetIndex, int d switch (widgetIndex) { case WIDX_FENCE_DROPDOWN_SLOPE_BUTTON: - printf("Dropdown index: %d\n", dropdownIndex); mapElement->type &= ~0xC0; mapElement->type |= dropdownIndex << 6; break;