Skip to content

Commit

Permalink
Added clear current floor to gridmap
Browse files Browse the repository at this point in the history
  • Loading branch information
GuybrushThreepwood-GitHub committed Aug 10, 2023
1 parent f95aed7 commit e2d33be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/gridmap/editor/grid_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions modules/gridmap/editor/grid_map_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit e2d33be

Please sign in to comment.