From e2d33be85ec8f2eb64c85c96f1e456689b4b57ad Mon Sep 17 00:00:00 2001 From: John Murray Date: Thu, 10 Aug 2023 14:58:00 +0200 Subject: [PATCH] Added clear current floor to gridmap --- .../gridmap/editor/grid_map_editor_plugin.cpp | 22 +++++++++++++++++++ .../gridmap/editor/grid_map_editor_plugin.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/modules/gridmap/editor/grid_map_editor_plugin.cpp b/modules/gridmap/editor/grid_map_editor_plugin.cpp index fa13811cc315..280cd57754fc 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.cpp +++ b/modules/gridmap/editor/grid_map_editor_plugin.cpp @@ -1158,6 +1158,23 @@ void GridMapEditor::_item_selected_cbk(int idx) { _update_cursor_instance(); } +void GridMapEditor::_clear_floor_pressed() { + int currentAxis = edit_floor[edit_axis]; + + Array all_cells_used = node->get_used_cells(); + Array cell_used_axis; + for (int32_t idx = 0; idx < all_cells_used.size(); idx++) { + Vector3i c = all_cells_used[idx]; + + if (c.y == currentAxis) + cell_used_axis.push_back(c); + } + + for (int32_t idx = 0; idx < cell_used_axis.size(); idx++) { + node->set_cell_item(cell_used_axis[idx], -1, 0); + } +} + void GridMapEditor::_floor_changed(float p_value) { if (updating) { return; @@ -1204,6 +1221,11 @@ GridMapEditor::GridMapEditor() { floor->connect("mouse_exited", callable_mp(this, &GridMapEditor::_floor_mouse_exited)); floor->get_line_edit()->connect("mouse_exited", callable_mp(this, &GridMapEditor::_floor_mouse_exited)); + clear_floor_button = memnew(MenuButton); + clear_floor_button->set_text(TTR("Clear Current Floor")); + clear_floor_button->connect("pressed", callable_mp(this, &GridMapEditor::_clear_floor_pressed)); + spatial_editor_hb->add_child(clear_floor_button); + spatial_editor_hb->add_child(memnew(VSeparator)); options = memnew(MenuButton); diff --git a/modules/gridmap/editor/grid_map_editor_plugin.h b/modules/gridmap/editor/grid_map_editor_plugin.h index 2c6bf39f81d4..5722c1325d49 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.h +++ b/modules/gridmap/editor/grid_map_editor_plugin.h @@ -68,6 +68,7 @@ class GridMapEditor : public VBoxContainer { InputAction input_action = INPUT_NONE; Panel *panel = nullptr; + MenuButton *clear_floor_button = nullptr; MenuButton *options = nullptr; SpinBox *floor = nullptr; double accumulated_floor_delta = 0.0; @@ -212,6 +213,7 @@ class GridMapEditor : public VBoxContainer { void _validate_selection(); void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3()); + void _clear_floor_pressed(); void _floor_changed(float p_value); void _floor_mouse_exited();