Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Add scene_painted signal to ScenePaint2DEditor

JekSun97de816ca29fd0
diff --git a/doc/classes/ScenePaint2DEditor.xml b/doc/classes/ScenePaint2DEditor.xml
index ad2b2e81e7b..2492770c36c 100644
--- a/doc/classes/ScenePaint2DEditor.xml
+++ b/doc/classes/ScenePaint2DEditor.xml
@@ -43,4 +43,26 @@
</description>
</method>
</methods>
+ <signals>
+ <signal name="scene_painted">
+ <param index="0" name="node" type="Node2D" />
+ <description>
+ Emitted for each new node created during drawing.
+ [b]Example:[/b]
+ [codeblocks]
+ [gdscript]
+ @tool
+ extends EditorPlugin
+
+ func _enter_tree():
+ EditorInterface.get_scene_paint_2d().scene_painted.connect(_on_scene_painted)
+
+ func _on_scene_painted(node: Node2D):
+ # Set random rotation when drawing nodes.
+ node.rotation = randf_range(0, 360)
+ [/gdscript]
+ [/codeblocks]
+ </description>
+ </signal>
+ </signals>
</class>
diff --git a/editor/scene/2d/scene_paint_2d_editor_plugin.cpp b/editor/scene/2d/scene_paint_2d_editor_plugin.cpp
index 82a9e044f85..772d25958f2 100644
--- a/editor/scene/2d/scene_paint_2d_editor_plugin.cpp
+++ b/editor/scene/2d/scene_paint_2d_editor_plugin.cpp
@@ -403,6 +403,7 @@ void ScenePaint2DEditor::_add_node_at_pos() {
undo_redo->add_do_method(node_2d, "set_global_position", pos);
undo_redo->add_undo_method(node, "remove_child", node_2d);
undo_redo->commit_action(false);
+ emit_signal(SNAME("scene_painted"), node_2d);
}
CanvasItemEditor::get_singleton()->update_viewport();
@@ -763,6 +764,7 @@ void ScenePaint2DEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("unregister_scene_provider", "control"), &ScenePaint2DEditor::unregister_scene_provider);
ClassDB::bind_method(D_METHOD("set_painted_scene", "scene"), &ScenePaint2DEditor::set_painted_scene);
ClassDB::bind_method(D_METHOD("get_painted_scene"), &ScenePaint2DEditor::get_painted_scene);
+ ADD_SIGNAL(MethodInfo("scene_painted", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, Node2D::get_class_static())));
}
void ScenePaint2DEditor::_notification(int p_what) {