From 653039151a91291eda757f72674b6b968770cf51 Mon Sep 17 00:00:00 2001 From: rzllmr <30299783+rzllmr@users.noreply.github.com> Date: Sat, 3 Aug 2019 21:32:13 +0200 Subject: [PATCH] Fix row-column-swap in TileMap palette Due to the TileSet coordinates using x for columns and y for rows, the columns are assigned to the rows in the TileMap palette and distort the order. Thus the default sorting algorithm prioritizing x is replaced with a custom one prioritizing y. Fixes #24751 --- editor/plugins/tile_map_editor_plugin.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 766890242fe..b2f06ca41f1 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -521,7 +521,13 @@ void TileMapEditor::_update_palette() { for (const Map::Element *E = tiles2.front(); E; E = E->next()) { entries2.push_back(E->key()); } - entries2.sort(); + // Sort tiles in row-major order + struct SwapComparator { + _FORCE_INLINE_ bool operator()(const Vector2 &v_l, const Vector2 &v_r) const { + return v_l.y != v_r.y ? v_l.y < v_r.y : v_l.x < v_r.x; + } + }; + entries2.sort_custom(); Ref tex = tileset->tile_get_texture(sel_tile);