mirror of
https://github.com/godotengine/godot.git
synced 2025-10-25 10:44:26 +00:00
Create API to add and remove VisualScript custom nodes
This makes a VisualScriptEditor singleton, which gives plugins the ability to register their own custom nodes. Those will be available for insertion in the Visual Script editor, under the "Custom Nodes" category.
This commit is contained in:
parent
9543801d51
commit
0284727e7b
7 changed files with 135 additions and 0 deletions
|
|
@ -29,6 +29,7 @@
|
|||
/*************************************************************************/
|
||||
#include "visual_script_editor.h"
|
||||
|
||||
#include "core/script_language.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_resource_preview.h"
|
||||
#include "os/input.h"
|
||||
|
|
@ -3258,6 +3259,8 @@ void VisualScriptEditor::_bind_methods() {
|
|||
ClassDB::bind_method("_member_rmb_selected", &VisualScriptEditor::_member_rmb_selected);
|
||||
|
||||
ClassDB::bind_method("_member_option", &VisualScriptEditor::_member_option);
|
||||
|
||||
ClassDB::bind_method("_update_available_nodes", &VisualScriptEditor::_update_available_nodes);
|
||||
}
|
||||
|
||||
VisualScriptEditor::VisualScriptEditor() {
|
||||
|
|
@ -3442,6 +3445,8 @@ VisualScriptEditor::VisualScriptEditor() {
|
|||
members->connect("item_rmb_selected", this, "_member_rmb_selected");
|
||||
members->set_allow_rmb_select(true);
|
||||
member_popup->connect("id_pressed", this, "_member_option");
|
||||
|
||||
_VisualScriptEditor::get_singleton()->connect("custom_nodes_updated", this, "_update_available_nodes");
|
||||
}
|
||||
|
||||
VisualScriptEditor::~VisualScriptEditor() {
|
||||
|
|
@ -3485,4 +3490,42 @@ void VisualScriptEditor::register_editor() {
|
|||
EditorNode::add_plugin_init_callback(register_editor_callback);
|
||||
}
|
||||
|
||||
Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_name) {
|
||||
|
||||
Ref<VisualScriptCustomNode> node;
|
||||
node.instance();
|
||||
node->set_script(singleton->custom_nodes[p_name]);
|
||||
return node;
|
||||
}
|
||||
|
||||
_VisualScriptEditor *_VisualScriptEditor::singleton = NULL;
|
||||
Map<String, RefPtr> _VisualScriptEditor::custom_nodes;
|
||||
|
||||
_VisualScriptEditor::_VisualScriptEditor() {
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
_VisualScriptEditor::~_VisualScriptEditor() {
|
||||
custom_nodes.clear();
|
||||
}
|
||||
|
||||
void _VisualScriptEditor::add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script) {
|
||||
String node_name = "custom/" + p_category + "/" + p_name;
|
||||
custom_nodes.insert(node_name, p_script.get_ref_ptr());
|
||||
VisualScriptLanguage::singleton->add_register_func(node_name, &_VisualScriptEditor::create_node_custom);
|
||||
emit_signal("custom_nodes_updated");
|
||||
}
|
||||
|
||||
void _VisualScriptEditor::remove_custom_node(const String &p_name, const String &p_category) {
|
||||
String node_name = "custom/" + p_category + "/" + p_name;
|
||||
custom_nodes.erase(node_name);
|
||||
VisualScriptLanguage::singleton->remove_register_func(node_name);
|
||||
emit_signal("custom_nodes_updated");
|
||||
}
|
||||
|
||||
void _VisualScriptEditor::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_custom_node", "name", "category", "script"), &_VisualScriptEditor::add_custom_node);
|
||||
ClassDB::bind_method(D_METHOD("remove_custom_node", "name", "category"), &_VisualScriptEditor::remove_custom_node);
|
||||
ADD_SIGNAL(MethodInfo("custom_nodes_updated"));
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue