Skip to content

Commit

Permalink
Fix creating polygons in GenericTilePolygonEditor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Relintai committed Mar 9, 2024
1 parent 5359053 commit de33138
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions modules/layered_tile_map/editor/layered_tile_data_editors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,20 +545,20 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
if (!multiple_polygon_mode) {
clear_polygons();
}
int added = add_polygon(in_creation_polygon);

in_creation_polygon.clear();

button_edit->set_pressed(true);
undo_redo->create_action(TTR("Edit Polygons"));
if (!multiple_polygon_mode) {
undo_redo->add_do_method(this, "clear_polygons");
}
undo_redo->add_do_method(this, "add_polygon", in_creation_polygon);
undo_redo->add_do_method(base_control, "update");
undo_redo->add_undo_method(this, "remove_polygon", added);
undo_redo->add_undo_method(this, "remove_last_polygon");
undo_redo->add_undo_method(base_control, "update");
undo_redo->commit_action();
emit_signal("polygons_changed");

in_creation_polygon.clear();
} else {
// Create a new point.
drag_type = DRAG_TYPE_CREATE_POINT;
Expand Down Expand Up @@ -795,6 +795,10 @@ void GenericTilePolygonEditor::remove_polygon(int p_index) {
base_control->update();
}

void GenericTilePolygonEditor::remove_last_polygon() {
remove_polygon(polygons.size() - 1);
}

void GenericTilePolygonEditor::clear_polygons() {
polygons.clear();
base_control->update();
Expand Down Expand Up @@ -854,6 +858,7 @@ void GenericTilePolygonEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_polygon_count"), &GenericTilePolygonEditor::get_polygon_count);
ClassDB::bind_method(D_METHOD("add_polygon", "polygon", "index"), &GenericTilePolygonEditor::add_polygon, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("remove_polygon", "index"), &GenericTilePolygonEditor::remove_polygon);
ClassDB::bind_method(D_METHOD("remove_last_polygon"), &GenericTilePolygonEditor::remove_last_polygon);
ClassDB::bind_method(D_METHOD("clear_polygons"), &GenericTilePolygonEditor::clear_polygons);
ClassDB::bind_method(D_METHOD("set_polygon", "index", "polygon"), &GenericTilePolygonEditor::set_polygon);
ClassDB::bind_method(D_METHOD("get_polygon", "index"), &GenericTilePolygonEditor::get_polygon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class GenericTilePolygonEditor : public VBoxContainer {
int get_polygon_count();
int add_polygon(const Vector<Point2> &p_polygon, int p_index = -1);
void remove_polygon(int p_index);
void remove_last_polygon();
void clear_polygons();
void set_polygon(int p_polygon_index, const Vector<Point2> &p_polygon);
Vector<Point2> get_polygon(int p_polygon_index);
Expand Down

0 comments on commit de33138

Please sign in to comment.