diff options
author | damarindra <damarind@gmail.com> | 2018-01-05 17:53:30 +0700 |
---|---|---|
committer | damarindra <damarind@gmail.com> | 2018-01-05 17:53:30 +0700 |
commit | 97b8be7261dacd961bf4e391c3b8643ab39c1668 (patch) | |
tree | edc47b276f9345b0636dca58ac5aa07492f78adb | |
parent | 8ec06de6681a600bd5a74b4a1bdea85f656b5a88 (diff) |
Fixing weird behaviour on autotile editor
-rw-r--r-- | editor/plugins/tile_set_editor_plugin.cpp | 95 | ||||
-rw-r--r-- | editor/plugins/tile_set_editor_plugin.h | 1 |
2 files changed, 50 insertions, 46 deletions
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index b5ff94a056..f6a0763ba4 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -618,8 +618,10 @@ void AutotileEditor::_on_edit_mode_changed(int p_edit_mode) { tool_containers[TOOLBAR_BITMASK]->hide(); tool_containers[TOOLBAR_SHAPE]->show(); tools[TOOL_SELECT]->set_tooltip(TTR("Select current edited sub-tile.")); - current_shape = PoolVector2Array(); spin_priority->hide(); + + current_shape = PoolVector2Array(); + select_coord(edited_shape_coord); } break; default: { tool_containers[TOOLBAR_DUMMY]->show(); @@ -931,50 +933,18 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { edited_shape_coord = coord; edited_occlusion_shape = tile_set->autotile_get_light_occluder(get_current_tile(), edited_shape_coord); edited_navigation_shape = tile_set->autotile_get_navigation_polygon(get_current_tile(), edited_shape_coord); - shape_anchor = edited_shape_coord; - shape_anchor.x *= (size.x + spacing); - shape_anchor.y *= (size.y + spacing); - if (edit_mode == EDITMODE_OCCLUSION) { - current_shape.resize(0); - if (edited_occlusion_shape.is_valid()) { - for (int i = 0; i < edited_occlusion_shape->get_polygon().size(); i++) { - current_shape.push_back(edited_occlusion_shape->get_polygon()[i] + shape_anchor); - } - } - } else if (edit_mode == EDITMODE_NAVIGATION) { - current_shape.resize(0); - if (edited_navigation_shape.is_valid()) { - if (edited_navigation_shape->get_polygon_count() > 0) { - PoolVector<Vector2> vertices = edited_navigation_shape->get_vertices(); - for (int i = 0; i < edited_navigation_shape->get_polygon(0).size(); i++) { - current_shape.push_back(vertices[edited_navigation_shape->get_polygon(0)[i]] + shape_anchor); - } - } - } - } - } else { - if (edit_mode == EDITMODE_COLLISION) { - Vector<TileSet::ShapeData> sd = tile_set->tile_get_shapes(get_current_tile()); - for (int i = 0; i < sd.size(); i++) { - if (sd[i].autotile_coord == coord) { - Ref<ConvexPolygonShape2D> shape = sd[i].shape; - if (shape.is_valid()) { - - Rect2 bounding_rect; - PoolVector2Array polygon; - bounding_rect.position = shape->get_points()[0]; - for (int j = 0; j < shape->get_points().size(); j++) { - polygon.push_back(shape->get_points()[j] + shape_anchor); - bounding_rect.expand_to(shape->get_points()[j] + shape_anchor); - } - if (bounding_rect.has_point(mb->get_position())) { - current_shape = polygon; - edited_collision_shape = shape; - } - } - } + Vector<TileSet::ShapeData> sd = tile_set->tile_get_shapes(get_current_tile()); + bool found_collision_shape = false; + for (int i = 0; i < sd.size(); i++) { + if (sd[i].autotile_coord == coord) { + edited_collision_shape = sd[i].shape; + found_collision_shape = true; + break; } } + if (!found_collision_shape) + edited_collision_shape = Ref<ConvexPolygonShape2D>(NULL); + select_coord(edited_shape_coord); } workspace->update(); } else if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { @@ -1341,7 +1311,7 @@ void AutotileEditor::draw_polygon_shapes() { } Vector<Vector2> polygon; Vector<Color> colors; - if (shape == edited_collision_shape) { + if (shape == edited_collision_shape && current_shape.size() > 2) { for (int j = 0; j < current_shape.size(); j++) { polygon.push_back(current_shape[j]); colors.push_back(c_bg); @@ -1391,7 +1361,7 @@ void AutotileEditor::draw_polygon_shapes() { } Vector<Vector2> polygon; Vector<Color> colors; - if (shape == edited_occlusion_shape) { + if (shape == edited_occlusion_shape && current_shape.size() > 2) { for (int j = 0; j < current_shape.size(); j++) { polygon.push_back(current_shape[j]); colors.push_back(c_bg); @@ -1439,7 +1409,7 @@ void AutotileEditor::draw_polygon_shapes() { } Vector<Vector2> polygon; Vector<Color> colors; - if (shape == edited_navigation_shape) { + if (shape == edited_navigation_shape && current_shape.size() > 2) { for (int j = 0; j < current_shape.size(); j++) { polygon.push_back(current_shape[j]); colors.push_back(c_bg); @@ -1549,6 +1519,39 @@ void AutotileEditor::close_shape(const Vector2 &shape_anchor) { } } +void AutotileEditor::select_coord(const Vector2 &coord) { + int spacing = tile_set->autotile_get_spacing(get_current_tile()); + Vector2 size = tile_set->autotile_get_size(get_current_tile()); + Vector2 shape_anchor = coord; + shape_anchor.x *= (size.x + spacing); + shape_anchor.y *= (size.y + spacing); + if (edit_mode == EDITMODE_COLLISION) { + current_shape.resize(0); + if (edited_collision_shape.is_valid()) { + for (int j = 0; j < edited_collision_shape->get_points().size(); j++) { + current_shape.push_back(edited_collision_shape->get_points()[j] + shape_anchor); + } + } + } else if (edit_mode == EDITMODE_OCCLUSION) { + current_shape.resize(0); + if (edited_occlusion_shape.is_valid()) { + for (int i = 0; i < edited_occlusion_shape->get_polygon().size(); i++) { + current_shape.push_back(edited_occlusion_shape->get_polygon()[i] + shape_anchor); + } + } + } else if (edit_mode == EDITMODE_NAVIGATION) { + current_shape.resize(0); + if (edited_navigation_shape.is_valid()) { + if (edited_navigation_shape->get_polygon_count() > 0) { + PoolVector<Vector2> vertices = edited_navigation_shape->get_vertices(); + for (int i = 0; i < edited_navigation_shape->get_polygon(0).size(); i++) { + current_shape.push_back(vertices[edited_navigation_shape->get_polygon(0)[i]] + shape_anchor); + } + } + } + } +} + Vector2 AutotileEditor::snap_point(const Vector2 &point) { Vector2 p = point; Vector2 coord = edited_shape_coord; diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index de989a11e8..9bd3e23181 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -144,6 +144,7 @@ private: void draw_grid_snap(); void draw_polygon_shapes(); void close_shape(const Vector2 &shape_anchor); + void select_coord(const Vector2 &coord); Vector2 snap_point(const Vector2 &point); void edit(Object *p_node); |