Skip to content

Commit

Permalink
Disallow polygon2D editing if internal vertices exists, as suggested in
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Feb 13, 2019
1 parent 7f69da4 commit 419fb45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions editor/plugins/abstract_polygon_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)

if (mb.is_valid()) {

String cant_edit = _why_cant_edit_polygon();
if (cant_edit != String()) {
EditorNode::get_singleton()->show_warning(cant_edit);
return true;
}

Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform();

Vector2 gpoint = mb->get_position();
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/abstract_polygon_2d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class AbstractPolygon2DEditor : public HBoxContainer {
virtual bool _has_resource() const;
virtual void _create_resource();

virtual String _why_cant_edit_polygon() const { return String(); }

public:
bool forward_gui_input(const Ref<InputEvent> &p_event);
void forward_canvas_draw_over_viewport(Control *p_overlay);
Expand Down
10 changes: 10 additions & 0 deletions editor/plugins/polygon_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ Vector2 Polygon2DEditor::_get_offset(int p_idx) const {
return node->get_offset();
}

String Polygon2DEditor::_why_cant_edit_polygon() const {

if (node->get_internal_vertex_count() > 0) {

return TTR("Polygon 2D has internal vertices, so it can no longer be edited in the viewport.");
}

return String();
}

int Polygon2DEditor::_get_polygon_count() const {
if (node->get_internal_vertex_count() > 0) {
return 0; //do not edit if internal vertices exist
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/polygon_2d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor {
virtual void _set_node(Node *p_polygon);

virtual Vector2 _get_offset(int p_idx) const;
virtual String _why_cant_edit_polygon() const;

virtual bool _has_uv() const { return true; };
virtual void _commit_action();
Expand Down

0 comments on commit 419fb45

Please sign in to comment.