Skip to content

Commit

Permalink
Merge pull request #78504 from timothyqiu/gridmap-selection
Browse files Browse the repository at this point in the history
Fix GridMap tile picking when a search filter is applied
  • Loading branch information
akien-mga committed Jun 21, 2023
2 parents 5285927 + 42faab8 commit ada712e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions modules/gridmap/editor/grid_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,16 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
int item = node->get_cell_item(Vector3i(cell[0], cell[1], cell[2]));
if (item >= 0) {
selected_palette = item;
mesh_library_palette->set_current(item);

// Clear the filter if picked an item that's filtered out.
int index = mesh_library_palette->find_metadata(item);
if (index == -1) {
search_box->clear();
}

// This will select `selected_palette` in the ItemList when possible.
update_palette();

_update_cursor_instance();
}
return true;
Expand Down Expand Up @@ -830,8 +838,6 @@ void GridMapEditor::_icon_size_changed(float p_value) {
}

void GridMapEditor::update_palette() {
int selected = mesh_library_palette->get_current();

float min_size = EDITOR_GET("editors/grid_map/preview_size");
min_size *= EDSCALE;

Expand Down Expand Up @@ -899,13 +905,11 @@ void GridMapEditor::update_palette() {
mesh_library_palette->set_item_text(item, name);
mesh_library_palette->set_item_metadata(item, id);

item++;
}
if (selected_palette == id) {
mesh_library_palette->select(item);
}

if (selected != -1 && mesh_library_palette->get_item_count() > 0) {
// Make sure that this variable is set correctly.
selected_palette = MIN(selected, mesh_library_palette->get_item_count() - 1);
mesh_library_palette->select(selected_palette);
item++;
}

last_mesh_library = *mesh_library;
Expand Down Expand Up @@ -1232,6 +1236,7 @@ GridMapEditor::GridMapEditor() {
search_box = memnew(LineEdit);
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
search_box->set_placeholder(TTR("Filter Meshes"));
search_box->set_clear_button_enabled(true);
hb->add_child(search_box);
search_box->connect("text_changed", callable_mp(this, &GridMapEditor::_text_changed));
search_box->connect("gui_input", callable_mp(this, &GridMapEditor::_sbox_input));
Expand Down

0 comments on commit ada712e

Please sign in to comment.