| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "editor/plugins/editor_plugin.h" |
| 34 |
#include "scene/2d/physics/collision_shape_2d.h" |
| 35 |
|
| 36 |
class CanvasItemEditor; |
| 37 |
|
| 38 |
class CollisionShape2DEditor : public Control { |
| 39 |
GDCLASS(CollisionShape2DEditor, Control); |
| 40 |
|
| 41 |
enum ShapeType { |
| 42 |
CAPSULE_SHAPE, |
| 43 |
CIRCLE_SHAPE, |
| 44 |
CONCAVE_POLYGON_SHAPE, |
| 45 |
CONVEX_POLYGON_SHAPE, |
| 46 |
WORLD_BOUNDARY_SHAPE, |
| 47 |
SEPARATION_RAY_SHAPE, |
| 48 |
RECTANGLE_SHAPE, |
| 49 |
SEGMENT_SHAPE |
| 50 |
}; |
| 51 |
|
| 52 |
const Point2 RECT_HANDLES[8] = { |
| 53 |
Point2(1, 0), |
| 54 |
Point2(1, 1), |
| 55 |
Point2(0, 1), |
| 56 |
Point2(-1, 1), |
| 57 |
Point2(-1, 0), |
| 58 |
Point2(-1, -1), |
| 59 |
Point2(0, -1), |
| 60 |
Point2(1, -1), |
| 61 |
}; |
| 62 |
|
| 63 |
CanvasItemEditor *canvas_item_editor = nullptr; |
| 64 |
CollisionShape2D *node = nullptr; |
| 65 |
|
| 66 |
Vector<Point2> handles; |
| 67 |
|
| 68 |
int shape_type = -1; |
| 69 |
int edit_handle = -1; |
| 70 |
bool pressed = false; |
| 71 |
real_t grab_threshold = 8; |
| 72 |
Variant original; |
| 73 |
Transform2D original_transform; |
| 74 |
Vector2 original_point; |
| 75 |
Point2 last_point; |
| 76 |
Vector2 original_mouse_pos; |
| 77 |
|
| 78 |
Ref<Shape2D> current_shape; |
| 79 |
|
| 80 |
Variant get_handle_value(int idx) const; |
| 81 |
void set_handle(int idx, Point2 &p_point); |
| 82 |
void commit_handle(int idx, Variant &p_org); |
| 83 |
|
| 84 |
void _shape_changed(); |
| 85 |
|
| 86 |
protected: |
| 87 |
void _notification(int p_what); |
| 88 |
void _node_removed(Node *p_node); |
| 89 |
|
| 90 |
public: |
| 91 |
bool forward_canvas_gui_input(const Ref<InputEvent> &p_event); |
| 92 |
void forward_canvas_draw_over_viewport(Control *p_overlay); |
| 93 |
void edit(Node *p_node); |
| 94 |
|
| 95 |
CollisionShape2DEditor(); |
| 96 |
}; |
| 97 |
|
| 98 |
class CollisionShape2DEditorPlugin : public EditorPlugin { |
| 99 |
GDCLASS(CollisionShape2DEditorPlugin, EditorPlugin); |
| 100 |
|
| 101 |
CollisionShape2DEditor *collision_shape_2d_editor = nullptr; |
| 102 |
|
| 103 |
public: |
| 104 |
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override { return collision_shape_2d_editor->forward_canvas_gui_input(p_event); } |
| 105 |
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override { collision_shape_2d_editor->forward_canvas_draw_over_viewport(p_overlay); } |
| 106 |
|
| 107 |
virtual String get_plugin_name() const override { return "CollisionShape2D"; } |
| 108 |
bool has_main_screen() const override { return false; } |
| 109 |
virtual void edit(Object *p_obj) override; |
| 110 |
virtual bool handles(Object *p_obj) const override; |
| 111 |
virtual void make_visible(bool visible) override; |
| 112 |
|
| 113 |
CollisionShape2DEditorPlugin(); |
| 114 |
}; |