collision_shape_2d_editor_plugin.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /**************************************************************************/
  2. /* collision_shape_2d_editor_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "collision_shape_2d_editor_plugin.h"
  31. #include "canvas_item_editor_plugin.h"
  32. #include "core/os/keyboard.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/editor_undo_redo_manager.h"
  36. #include "scene/main/viewport.h"
  37. #include "scene/resources/2d/capsule_shape_2d.h"
  38. #include "scene/resources/2d/circle_shape_2d.h"
  39. #include "scene/resources/2d/concave_polygon_shape_2d.h"
  40. #include "scene/resources/2d/convex_polygon_shape_2d.h"
  41. #include "scene/resources/2d/rectangle_shape_2d.h"
  42. #include "scene/resources/2d/segment_shape_2d.h"
  43. #include "scene/resources/2d/separation_ray_shape_2d.h"
  44. #include "scene/resources/2d/world_boundary_shape_2d.h"
  45. CollisionShape2DEditor::CollisionShape2DEditor() {
  46. grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
  47. }
  48. void CollisionShape2DEditor::_node_removed(Node *p_node) {
  49. if (p_node == node) {
  50. node = nullptr;
  51. }
  52. }
  53. Variant CollisionShape2DEditor::get_handle_value(int idx) const {
  54. switch (shape_type) {
  55. case CAPSULE_SHAPE: {
  56. Ref<CapsuleShape2D> capsule = node->get_shape();
  57. return Vector2(capsule->get_radius(), capsule->get_height());
  58. } break;
  59. case CIRCLE_SHAPE: {
  60. Ref<CircleShape2D> circle = node->get_shape();
  61. if (idx == 0) {
  62. return circle->get_radius();
  63. }
  64. } break;
  65. case CONCAVE_POLYGON_SHAPE: {
  66. Ref<ConcavePolygonShape2D> shape = node->get_shape();
  67. const Vector<Vector2> &segments = shape->get_segments();
  68. return segments[idx];
  69. } break;
  70. case CONVEX_POLYGON_SHAPE: {
  71. Ref<ConvexPolygonShape2D> shape = node->get_shape();
  72. const Vector<Vector2> &points = shape->get_points();
  73. return points[idx];
  74. } break;
  75. case WORLD_BOUNDARY_SHAPE: {
  76. Ref<WorldBoundaryShape2D> world_boundary = node->get_shape();
  77. if (idx == 0) {
  78. return world_boundary->get_distance();
  79. } else {
  80. return world_boundary->get_normal();
  81. }
  82. } break;
  83. case SEPARATION_RAY_SHAPE: {
  84. Ref<SeparationRayShape2D> ray = node->get_shape();
  85. if (idx == 0) {
  86. return ray->get_length();
  87. }
  88. } break;
  89. case RECTANGLE_SHAPE: {
  90. Ref<RectangleShape2D> rect = node->get_shape();
  91. if (idx < 8) {
  92. return rect->get_size().abs();
  93. }
  94. } break;
  95. case SEGMENT_SHAPE: {
  96. Ref<SegmentShape2D> seg = node->get_shape();
  97. if (idx == 0) {
  98. return seg->get_a();
  99. } else if (idx == 1) {
  100. return seg->get_b();
  101. }
  102. } break;
  103. }
  104. return Variant();
  105. }
  106. void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) {
  107. switch (shape_type) {
  108. case CAPSULE_SHAPE: {
  109. if (idx < 2) {
  110. Ref<CapsuleShape2D> capsule = node->get_shape();
  111. real_t parameter = Math::abs(p_point[idx]);
  112. if (idx == 0) {
  113. capsule->set_radius(parameter);
  114. } else if (idx == 1) {
  115. capsule->set_height(parameter * 2);
  116. }
  117. }
  118. } break;
  119. case CIRCLE_SHAPE: {
  120. Ref<CircleShape2D> circle = node->get_shape();
  121. circle->set_radius(p_point.length());
  122. } break;
  123. case CONCAVE_POLYGON_SHAPE: {
  124. Ref<ConcavePolygonShape2D> concave_shape = node->get_shape();
  125. Vector<Vector2> segments = concave_shape->get_segments();
  126. ERR_FAIL_INDEX(idx, segments.size());
  127. segments.write[idx] = p_point;
  128. concave_shape->set_segments(segments);
  129. } break;
  130. case CONVEX_POLYGON_SHAPE: {
  131. Ref<ConvexPolygonShape2D> convex_shape = node->get_shape();
  132. Vector<Vector2> points = convex_shape->get_points();
  133. ERR_FAIL_INDEX(idx, points.size());
  134. points.write[idx] = p_point;
  135. convex_shape->set_points(points);
  136. } break;
  137. case WORLD_BOUNDARY_SHAPE: {
  138. if (idx < 2) {
  139. Ref<WorldBoundaryShape2D> world_boundary = node->get_shape();
  140. if (idx == 0) {
  141. Vector2 normal = world_boundary->get_normal();
  142. world_boundary->set_distance(p_point.dot(normal) / normal.length_squared());
  143. } else {
  144. real_t dir = world_boundary->get_distance() < 0 ? -1 : 1;
  145. world_boundary->set_normal(p_point.normalized() * dir);
  146. }
  147. }
  148. } break;
  149. case SEPARATION_RAY_SHAPE: {
  150. Ref<SeparationRayShape2D> ray = node->get_shape();
  151. ray->set_length(Math::abs(p_point.y));
  152. } break;
  153. case RECTANGLE_SHAPE: {
  154. if (idx < 8) {
  155. Ref<RectangleShape2D> rect = node->get_shape();
  156. Vector2 size = (Point2)original;
  157. if (RECT_HANDLES[idx].x != 0) {
  158. size.x = p_point.x * RECT_HANDLES[idx].x * 2;
  159. }
  160. if (RECT_HANDLES[idx].y != 0) {
  161. size.y = p_point.y * RECT_HANDLES[idx].y * 2;
  162. }
  163. if (Input::get_singleton()->is_key_pressed(Key::ALT)) {
  164. rect->set_size(size.abs());
  165. node->set_global_position(original_transform.get_origin());
  166. } else {
  167. rect->set_size(((Point2)original + (size - (Point2)original) * 0.5).abs());
  168. Point2 pos = original_transform.affine_inverse().xform(original_transform.get_origin());
  169. pos += (size - (Point2)original) * 0.5 * RECT_HANDLES[idx] * 0.5;
  170. node->set_global_position(original_transform.xform(pos));
  171. }
  172. }
  173. } break;
  174. case SEGMENT_SHAPE: {
  175. if (edit_handle < 2) {
  176. Ref<SegmentShape2D> seg = node->get_shape();
  177. if (idx == 0) {
  178. seg->set_a(p_point);
  179. } else if (idx == 1) {
  180. seg->set_b(p_point);
  181. }
  182. }
  183. } break;
  184. }
  185. }
  186. void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
  187. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  188. undo_redo->create_action(TTR("Set Handle"));
  189. switch (shape_type) {
  190. case CAPSULE_SHAPE: {
  191. Ref<CapsuleShape2D> capsule = node->get_shape();
  192. Vector2 values = p_org;
  193. if (idx == 0) {
  194. undo_redo->add_do_method(capsule.ptr(), "set_radius", capsule->get_radius());
  195. } else if (idx == 1) {
  196. undo_redo->add_do_method(capsule.ptr(), "set_height", capsule->get_height());
  197. }
  198. undo_redo->add_undo_method(capsule.ptr(), "set_radius", values[0]);
  199. undo_redo->add_undo_method(capsule.ptr(), "set_height", values[1]);
  200. } break;
  201. case CIRCLE_SHAPE: {
  202. Ref<CircleShape2D> circle = node->get_shape();
  203. undo_redo->add_do_method(circle.ptr(), "set_radius", circle->get_radius());
  204. undo_redo->add_undo_method(circle.ptr(), "set_radius", p_org);
  205. } break;
  206. case CONCAVE_POLYGON_SHAPE: {
  207. Ref<ConcavePolygonShape2D> concave_shape = node->get_shape();
  208. Vector2 values = p_org;
  209. Vector<Vector2> undo_segments = concave_shape->get_segments();
  210. ERR_FAIL_INDEX(idx, undo_segments.size());
  211. undo_segments.write[idx] = values;
  212. undo_redo->add_do_method(concave_shape.ptr(), "set_segments", concave_shape->get_segments());
  213. undo_redo->add_undo_method(concave_shape.ptr(), "set_segments", undo_segments);
  214. } break;
  215. case CONVEX_POLYGON_SHAPE: {
  216. Ref<ConvexPolygonShape2D> convex_shape = node->get_shape();
  217. Vector2 values = p_org;
  218. Vector<Vector2> undo_points = convex_shape->get_points();
  219. ERR_FAIL_INDEX(idx, undo_points.size());
  220. undo_points.write[idx] = values;
  221. undo_redo->add_do_method(convex_shape.ptr(), "set_points", convex_shape->get_points());
  222. undo_redo->add_undo_method(convex_shape.ptr(), "set_points", undo_points);
  223. } break;
  224. case WORLD_BOUNDARY_SHAPE: {
  225. Ref<WorldBoundaryShape2D> world_boundary = node->get_shape();
  226. if (idx == 0) {
  227. undo_redo->add_do_method(world_boundary.ptr(), "set_distance", world_boundary->get_distance());
  228. undo_redo->add_undo_method(world_boundary.ptr(), "set_distance", p_org);
  229. } else {
  230. undo_redo->add_do_method(world_boundary.ptr(), "set_normal", world_boundary->get_normal());
  231. undo_redo->add_undo_method(world_boundary.ptr(), "set_normal", p_org);
  232. }
  233. } break;
  234. case SEPARATION_RAY_SHAPE: {
  235. Ref<SeparationRayShape2D> ray = node->get_shape();
  236. undo_redo->add_do_method(ray.ptr(), "set_length", ray->get_length());
  237. undo_redo->add_undo_method(ray.ptr(), "set_length", p_org);
  238. } break;
  239. case RECTANGLE_SHAPE: {
  240. Ref<RectangleShape2D> rect = node->get_shape();
  241. undo_redo->add_do_method(rect.ptr(), "set_size", rect->get_size());
  242. undo_redo->add_do_method(node, "set_global_transform", node->get_global_transform());
  243. undo_redo->add_undo_method(rect.ptr(), "set_size", p_org);
  244. undo_redo->add_undo_method(node, "set_global_transform", original_transform);
  245. } break;
  246. case SEGMENT_SHAPE: {
  247. Ref<SegmentShape2D> seg = node->get_shape();
  248. if (idx == 0) {
  249. undo_redo->add_do_method(seg.ptr(), "set_a", seg->get_a());
  250. undo_redo->add_undo_method(seg.ptr(), "set_a", p_org);
  251. } else if (idx == 1) {
  252. undo_redo->add_do_method(seg.ptr(), "set_b", seg->get_b());
  253. undo_redo->add_undo_method(seg.ptr(), "set_b", p_org);
  254. }
  255. } break;
  256. }
  257. undo_redo->commit_action();
  258. }
  259. bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
  260. if (!node) {
  261. return false;
  262. }
  263. if (!node->is_visible_in_tree()) {
  264. return false;
  265. }
  266. Viewport *vp = node->get_viewport();
  267. if (vp && !vp->is_visible_subviewport()) {
  268. return false;
  269. }
  270. if (shape_type == -1) {
  271. return false;
  272. }
  273. Ref<InputEventMouseButton> mb = p_event;
  274. Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_screen_transform();
  275. if (mb.is_valid()) {
  276. Vector2 gpoint = mb->get_position();
  277. if (mb->get_button_index() == MouseButton::LEFT) {
  278. if (mb->is_pressed()) {
  279. for (int i = 0; i < handles.size(); i++) {
  280. if (xform.xform(handles[i]).distance_to(gpoint) < grab_threshold) {
  281. edit_handle = i;
  282. break;
  283. }
  284. }
  285. if (edit_handle == -1) {
  286. pressed = false;
  287. return false;
  288. }
  289. original_mouse_pos = gpoint;
  290. original_point = handles[edit_handle];
  291. original = get_handle_value(edit_handle);
  292. original_transform = node->get_global_transform();
  293. last_point = original;
  294. pressed = true;
  295. return true;
  296. } else {
  297. if (pressed) {
  298. if (original_mouse_pos != gpoint) {
  299. commit_handle(edit_handle, original);
  300. }
  301. edit_handle = -1;
  302. pressed = false;
  303. return true;
  304. }
  305. }
  306. }
  307. return false;
  308. }
  309. Ref<InputEventMouseMotion> mm = p_event;
  310. if (mm.is_valid()) {
  311. if (edit_handle == -1 || !pressed) {
  312. return false;
  313. }
  314. Vector2 cpoint = canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position()));
  315. cpoint = node->get_viewport()->get_popup_base_transform().affine_inverse().xform(cpoint);
  316. cpoint = original_transform.affine_inverse().xform(cpoint);
  317. last_point = cpoint;
  318. set_handle(edit_handle, cpoint);
  319. return true;
  320. }
  321. Ref<InputEventKey> k = p_event;
  322. if (k.is_valid()) {
  323. if (edit_handle == -1 || !pressed || k->is_echo()) {
  324. return false;
  325. }
  326. if (shape_type == RECTANGLE_SHAPE && k->get_keycode() == Key::ALT) {
  327. set_handle(edit_handle, last_point); // Update handle when Alt key is toggled.
  328. }
  329. }
  330. return false;
  331. }
  332. void CollisionShape2DEditor::_shape_changed() {
  333. canvas_item_editor->update_viewport();
  334. if (current_shape.is_valid()) {
  335. current_shape->disconnect_changed(callable_mp(canvas_item_editor, &CanvasItemEditor::update_viewport));
  336. current_shape = Ref<Shape2D>();
  337. shape_type = -1;
  338. }
  339. if (!node) {
  340. return;
  341. }
  342. current_shape = node->get_shape();
  343. if (current_shape.is_valid()) {
  344. current_shape->connect_changed(callable_mp(canvas_item_editor, &CanvasItemEditor::update_viewport));
  345. } else {
  346. return;
  347. }
  348. if (Object::cast_to<CapsuleShape2D>(*current_shape)) {
  349. shape_type = CAPSULE_SHAPE;
  350. } else if (Object::cast_to<CircleShape2D>(*current_shape)) {
  351. shape_type = CIRCLE_SHAPE;
  352. } else if (Object::cast_to<ConcavePolygonShape2D>(*current_shape)) {
  353. shape_type = CONCAVE_POLYGON_SHAPE;
  354. } else if (Object::cast_to<ConvexPolygonShape2D>(*current_shape)) {
  355. shape_type = CONVEX_POLYGON_SHAPE;
  356. } else if (Object::cast_to<WorldBoundaryShape2D>(*current_shape)) {
  357. shape_type = WORLD_BOUNDARY_SHAPE;
  358. } else if (Object::cast_to<SeparationRayShape2D>(*current_shape)) {
  359. shape_type = SEPARATION_RAY_SHAPE;
  360. } else if (Object::cast_to<RectangleShape2D>(*current_shape)) {
  361. shape_type = RECTANGLE_SHAPE;
  362. } else if (Object::cast_to<SegmentShape2D>(*current_shape)) {
  363. shape_type = SEGMENT_SHAPE;
  364. }
  365. }
  366. void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
  367. if (!node) {
  368. return;
  369. }
  370. if (!node->is_visible_in_tree()) {
  371. return;
  372. }
  373. Viewport *vp = node->get_viewport();
  374. if (vp && !vp->is_visible_subviewport()) {
  375. return;
  376. }
  377. if (shape_type == -1) {
  378. return;
  379. }
  380. Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_screen_transform();
  381. Ref<Texture2D> h = get_editor_theme_icon(SNAME("EditorHandle"));
  382. Vector2 size = h->get_size() * 0.5;
  383. handles.clear();
  384. switch (shape_type) {
  385. case CAPSULE_SHAPE: {
  386. Ref<CapsuleShape2D> shape = current_shape;
  387. handles.resize(2);
  388. float radius = shape->get_radius();
  389. float height = shape->get_height() / 2;
  390. handles.write[0] = Point2(radius, 0);
  391. handles.write[1] = Point2(0, height);
  392. p_overlay->draw_texture(h, gt.xform(handles[0]) - size);
  393. p_overlay->draw_texture(h, gt.xform(handles[1]) - size);
  394. } break;
  395. case CIRCLE_SHAPE: {
  396. Ref<CircleShape2D> shape = current_shape;
  397. handles.resize(1);
  398. handles.write[0] = Point2(shape->get_radius(), 0);
  399. p_overlay->draw_texture(h, gt.xform(handles[0]) - size);
  400. } break;
  401. case CONCAVE_POLYGON_SHAPE: {
  402. Ref<ConcavePolygonShape2D> shape = current_shape;
  403. const Vector<Vector2> &segments = shape->get_segments();
  404. handles.resize(segments.size());
  405. for (int i = 0; i < handles.size(); i++) {
  406. handles.write[i] = segments[i];
  407. p_overlay->draw_texture(h, gt.xform(handles[i]) - size);
  408. }
  409. } break;
  410. case CONVEX_POLYGON_SHAPE: {
  411. Ref<ConvexPolygonShape2D> shape = current_shape;
  412. const Vector<Vector2> &points = shape->get_points();
  413. handles.resize(points.size());
  414. for (int i = 0; i < handles.size(); i++) {
  415. handles.write[i] = points[i];
  416. p_overlay->draw_texture(h, gt.xform(handles[i]) - size);
  417. }
  418. } break;
  419. case WORLD_BOUNDARY_SHAPE: {
  420. Ref<WorldBoundaryShape2D> shape = current_shape;
  421. handles.resize(2);
  422. handles.write[0] = shape->get_normal() * shape->get_distance();
  423. handles.write[1] = shape->get_normal() * (shape->get_distance() + 30.0);
  424. p_overlay->draw_texture(h, gt.xform(handles[0]) - size);
  425. p_overlay->draw_texture(h, gt.xform(handles[1]) - size);
  426. } break;
  427. case SEPARATION_RAY_SHAPE: {
  428. Ref<SeparationRayShape2D> shape = current_shape;
  429. handles.resize(1);
  430. handles.write[0] = Point2(0, shape->get_length());
  431. p_overlay->draw_texture(h, gt.xform(handles[0]) - size);
  432. } break;
  433. case RECTANGLE_SHAPE: {
  434. Ref<RectangleShape2D> shape = current_shape;
  435. handles.resize(8);
  436. Vector2 ext = shape->get_size() / 2;
  437. for (int i = 0; i < handles.size(); i++) {
  438. handles.write[i] = RECT_HANDLES[i] * ext;
  439. p_overlay->draw_texture(h, gt.xform(handles[i]) - size);
  440. }
  441. } break;
  442. case SEGMENT_SHAPE: {
  443. Ref<SegmentShape2D> shape = current_shape;
  444. handles.resize(2);
  445. handles.write[0] = shape->get_a();
  446. handles.write[1] = shape->get_b();
  447. p_overlay->draw_texture(h, gt.xform(handles[0]) - size);
  448. p_overlay->draw_texture(h, gt.xform(handles[1]) - size);
  449. } break;
  450. }
  451. }
  452. void CollisionShape2DEditor::_notification(int p_what) {
  453. switch (p_what) {
  454. case NOTIFICATION_ENTER_TREE: {
  455. get_tree()->connect("node_removed", callable_mp(this, &CollisionShape2DEditor::_node_removed));
  456. } break;
  457. case NOTIFICATION_EXIT_TREE: {
  458. get_tree()->disconnect("node_removed", callable_mp(this, &CollisionShape2DEditor::_node_removed));
  459. } break;
  460. case NOTIFICATION_PROCESS: {
  461. if (node && node->get_shape() != current_shape) {
  462. _shape_changed();
  463. }
  464. } break;
  465. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  466. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/polygon_editor")) {
  467. grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
  468. }
  469. } break;
  470. }
  471. }
  472. void CollisionShape2DEditor::edit(Node *p_node) {
  473. if (!canvas_item_editor) {
  474. canvas_item_editor = CanvasItemEditor::get_singleton();
  475. }
  476. if (p_node) {
  477. node = Object::cast_to<CollisionShape2D>(p_node);
  478. set_process(true);
  479. } else {
  480. if (pressed) {
  481. set_handle(edit_handle, original_point);
  482. pressed = false;
  483. }
  484. edit_handle = -1;
  485. node = nullptr;
  486. set_process(false);
  487. }
  488. _shape_changed();
  489. }
  490. void CollisionShape2DEditorPlugin::edit(Object *p_obj) {
  491. collision_shape_2d_editor->edit(Object::cast_to<Node>(p_obj));
  492. }
  493. bool CollisionShape2DEditorPlugin::handles(Object *p_obj) const {
  494. return p_obj->is_class("CollisionShape2D");
  495. }
  496. void CollisionShape2DEditorPlugin::make_visible(bool visible) {
  497. if (!visible) {
  498. edit(nullptr);
  499. }
  500. }
  501. CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin() {
  502. collision_shape_2d_editor = memnew(CollisionShape2DEditor);
  503. EditorNode::get_singleton()->get_gui_base()->add_child(collision_shape_2d_editor);
  504. }