summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp34
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h4
2 files changed, 32 insertions, 6 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 30ce2ef6e6..7fd6e517b5 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -1213,9 +1213,14 @@ void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node,
editing_port = p_port;
}
-void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
+void VisualShaderEditor::_add_texture_node(const String &p_path) {
+ VisualShaderNodeTexture *texture = (VisualShaderNodeTexture *)_add_node(texture_node_option_idx, -1);
+ texture->set_texture(ResourceLoader::load(p_path));
+}
+
+VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
- ERR_FAIL_INDEX(p_idx, add_options.size());
+ ERR_FAIL_INDEX_V(p_idx, add_options.size(), NULL);
Ref<VisualShaderNode> vsnode;
@@ -1223,7 +1228,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
if (!is_custom && add_options[p_idx].type != String()) {
VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type));
- ERR_FAIL_COND(!vsn);
+ ERR_FAIL_COND_V(!vsn, NULL);
VisualShaderNodeScalarConstant *constant = Object::cast_to<VisualShaderNodeScalarConstant>(vsn);
@@ -1309,10 +1314,10 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
vsnode = Ref<VisualShaderNode>(vsn);
} else {
- ERR_FAIL_COND(add_options[p_idx].script.is_null());
+ ERR_FAIL_COND_V(add_options[p_idx].script.is_null(), NULL);
String base_type = add_options[p_idx].script->get_instance_base_type();
VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(base_type));
- ERR_FAIL_COND(!vsn);
+ ERR_FAIL_COND_V(!vsn, NULL);
vsnode = Ref<VisualShaderNode>(vsn);
vsnode->set_script(add_options[p_idx].script.get_ref_ptr());
}
@@ -1367,6 +1372,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
undo_redo->add_do_method(this, "_update_graph");
undo_redo->add_undo_method(this, "_update_graph");
undo_redo->commit_action();
+ return vsnode.ptr();
}
void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
@@ -2038,6 +2044,9 @@ bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
if (d.has("id")) {
return true;
}
+ if (d.has("files")) {
+ return true;
+ }
}
return false;
@@ -2054,6 +2063,20 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
saved_node_pos = p_point;
saved_node_pos_dirty = true;
_add_node(idx, add_options[idx].sub_func);
+ } else if (d.has("files")) {
+ if (d["files"].get_type() == Variant::POOL_STRING_ARRAY) {
+
+ PoolStringArray arr = d["files"];
+ for (int i = 0; i < arr.size(); i++) {
+
+ String type = ResourceLoader::get_resource_type(arr[i]);
+ if (ClassDB::get_parent_class(type) == "Texture") {
+ saved_node_pos = p_point + Vector2(0, i * 210 * EDSCALE);
+ saved_node_pos_dirty = true;
+ _add_texture_node(arr[i]);
+ }
+ }
+ }
}
}
}
@@ -2558,6 +2581,7 @@ VisualShaderEditor::VisualShaderEditor() {
// TEXTURES
add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
+ texture_node_option_idx = add_options.size();
add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index cd5efc366b..d56e223057 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -148,11 +148,13 @@ class VisualShaderEditor : public VBoxContainer {
};
Vector<AddOption> add_options;
+ int texture_node_option_idx;
List<String> keyword_list;
void _draw_color_over_button(Object *obj, Color p_color);
- void _add_node(int p_idx, int p_op_idx = -1);
+ void _add_texture_node(const String &p_path);
+ VisualShaderNode *_add_node(int p_idx, int p_op_idx = -1);
void _update_custom_nodes();
void _update_options_menu();