mirror of https://github.com/OpenRCT2/OpenRCT2.git
Sorting tile
This commit is contained in:
parent
fc42dce87e
commit
83dbb52976
|
@ -666,22 +666,16 @@ static void window_tile_inspector_swap_elements(sint16 first, sint16 second)
|
||||||
|
|
||||||
static void window_tile_inspector_sort_elements(rct_window *w)
|
static void window_tile_inspector_sort_elements(rct_window *w)
|
||||||
{
|
{
|
||||||
const rct_map_element *const firstElement = map_get_first_element_at(windowTileInspectorTileX, windowTileInspectorTileY);
|
assert(windowTileInspectorTileSelected == true);
|
||||||
|
game_do_command(
|
||||||
// Bubble sort
|
TILE_INSPECTOR_ANY_SORT,
|
||||||
for (sint32 loopStart = 1; loopStart < windowTileInspectorElementCount; loopStart++) {
|
GAME_COMMAND_FLAG_APPLY,
|
||||||
sint32 currentId = loopStart;
|
windowTileInspectorTileX | (windowTileInspectorTileY << 8),
|
||||||
const rct_map_element *currentElement = firstElement + currentId;
|
0,
|
||||||
const rct_map_element *otherElement = currentElement - 1;
|
GAME_COMMAND_MODIFY_TILE,
|
||||||
|
0,
|
||||||
// While current element's base height is lower, or (when their baseheight is the same) the other map element's clearance height is lower...
|
0
|
||||||
while (currentId > 0 && (otherElement->base_height > currentElement->base_height || (otherElement->base_height == currentElement->base_height && otherElement->clearance_height > currentElement->clearance_height))) {
|
);
|
||||||
window_tile_inspector_swap_elements(currentId - 1, currentId);
|
|
||||||
currentId--;
|
|
||||||
currentElement--;
|
|
||||||
otherElement--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_tile_inspector_copy_element(rct_window *w)
|
static void window_tile_inspector_copy_element(rct_window *w)
|
||||||
|
@ -1001,14 +995,9 @@ static void window_tile_inspector_mouseup(rct_window *w, sint32 widgetIndex)
|
||||||
break;
|
break;
|
||||||
case WIDX_BUTTON_SORT:
|
case WIDX_BUTTON_SORT:
|
||||||
window_tile_inspector_sort_elements(w);
|
window_tile_inspector_sort_elements(w);
|
||||||
w->selected_list_item = -1;
|
|
||||||
window_tile_inspector_set_page(w, PAGE_DEFAULT);
|
|
||||||
window_tile_inspector_auto_set_buttons(w);
|
|
||||||
window_invalidate(w);
|
|
||||||
break;
|
break;
|
||||||
case WIDX_BUTTON_COPY:
|
case WIDX_BUTTON_COPY:
|
||||||
window_tile_inspector_copy_element(w);
|
window_tile_inspector_copy_element(w);
|
||||||
map_invalidate_tile_full(windowTileInspectorTileX << 5, windowTileInspectorTileY << 5);
|
|
||||||
window_tile_inspector_auto_set_buttons(w);
|
window_tile_inspector_auto_set_buttons(w);
|
||||||
window_invalidate(w);
|
window_invalidate(w);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5648,6 +5648,11 @@ void game_command_modify_tile(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx
|
||||||
*ebx = tile_inspector_paste_element_at(x, y, element_to_paste, flags);
|
*ebx = tile_inspector_paste_element_at(x, y, element_to_paste, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case TILE_INSPECTOR_ANY_SORT:
|
||||||
|
{
|
||||||
|
*ebx = tile_inspector_sort(x, y, flags);
|
||||||
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
log_error("invalid instruction");
|
log_error("invalid instruction");
|
||||||
*ebx = MONEY32_UNDEFINED;
|
*ebx = MONEY32_UNDEFINED;
|
||||||
|
|
|
@ -268,3 +268,50 @@ sint32 tile_inspector_paste_element_at(sint32 x, sint32 y, rct_map_element eleme
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sint32 tile_inspector_sort(sint32 x, sint32 y, sint32 flags)
|
||||||
|
{
|
||||||
|
if (flags & GAME_COMMAND_FLAG_APPLY)
|
||||||
|
{
|
||||||
|
const rct_map_element *const first_element = map_get_first_element_at(x, y);
|
||||||
|
|
||||||
|
// Count elements on tile
|
||||||
|
sint32 num_element = 0;
|
||||||
|
const rct_map_element *element_iterator = first_element;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
num_element++;
|
||||||
|
} while (!map_element_is_last_for_tile(element_iterator++));
|
||||||
|
|
||||||
|
// Bubble sort
|
||||||
|
for (sint32 loopStart = 1; loopStart < num_element; loopStart++)
|
||||||
|
{
|
||||||
|
sint32 currentId = loopStart;
|
||||||
|
const rct_map_element *currentElement = first_element + currentId;
|
||||||
|
const rct_map_element *otherElement = currentElement - 1;
|
||||||
|
|
||||||
|
// While current element's base height is lower, or (when their baseheight is the same) the other map element's clearance height is lower...
|
||||||
|
while (currentId > 0 && (otherElement->base_height > currentElement->base_height || (otherElement->base_height == currentElement->base_height && otherElement->clearance_height > currentElement->clearance_height)))
|
||||||
|
{
|
||||||
|
map_swap_elements_at(x, y, currentId - 1, currentId);
|
||||||
|
currentId--;
|
||||||
|
currentElement--;
|
||||||
|
otherElement--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
map_invalidate_tile_full(x << 5, y << 5);
|
||||||
|
|
||||||
|
// Deselect tile for clients who had it selected
|
||||||
|
rct_window *const tile_inspector_window = window_find_by_class(WC_TILE_INSPECTOR);
|
||||||
|
if (tile_inspector_window != NULL && (uint32)x == windowTileInspectorTileX && (uint32)y == windowTileInspectorTileY)
|
||||||
|
{
|
||||||
|
window_tile_inspector_set_page(tile_inspector_window, PAGE_DEFAULT);
|
||||||
|
tile_inspector_window->selected_list_item = -1;
|
||||||
|
window_tile_inspector_auto_set_buttons(tile_inspector_window);
|
||||||
|
window_invalidate(tile_inspector_window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ typedef enum {
|
||||||
TILE_INSPECTOR_ANY_INSERT_CORRUPT,
|
TILE_INSPECTOR_ANY_INSERT_CORRUPT,
|
||||||
TILE_INSPECTOR_ANY_ROTATE,
|
TILE_INSPECTOR_ANY_ROTATE,
|
||||||
TILE_INSPECTOR_ANY_PASTE,
|
TILE_INSPECTOR_ANY_PASTE,
|
||||||
|
TILE_INSPECTOR_ANY_SORT,
|
||||||
} tile_inspector_instruction;
|
} tile_inspector_instruction;
|
||||||
|
|
||||||
sint32 tile_inspector_insert_corrupt_at(sint32 x, sint32 y, sint16 element_index, sint32 flags);
|
sint32 tile_inspector_insert_corrupt_at(sint32 x, sint32 y, sint16 element_index, sint32 flags);
|
||||||
|
@ -44,3 +45,4 @@ sint32 tile_inspector_remove_element_at(sint32 x, sint32 y, sint16 element_index
|
||||||
sint32 tile_inspector_swap_elements(sint32 x, sint32 y, sint16 first, sint16 second, sint32 flags);
|
sint32 tile_inspector_swap_elements(sint32 x, sint32 y, sint16 first, sint16 second, sint32 flags);
|
||||||
sint32 tile_inspector_rotate_element_at(sint32 x, sint32 y, sint32 element_index, sint32 flags);
|
sint32 tile_inspector_rotate_element_at(sint32 x, sint32 y, sint32 element_index, sint32 flags);
|
||||||
sint32 tile_inspector_paste_element_at(sint32 x, sint32 y, rct_map_element element, sint32 flags);
|
sint32 tile_inspector_paste_element_at(sint32 x, sint32 y, rct_map_element element, sint32 flags);
|
||||||
|
sint32 tile_inspector_sort(sint32 x, sint32 y, sint32 flags);
|
||||||
|
|
Loading…
Reference in New Issue