summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp31
-rw-r--r--tools/editor/plugins/shader_graph_editor_plugin.cpp105
-rw-r--r--tools/editor/plugins/shader_graph_editor_plugin.h6
-rw-r--r--tools/editor/scenes_dock.cpp17
-rw-r--r--tools/editor/scenes_dock.h3
5 files changed, 153 insertions, 9 deletions
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp
index d8d5fddfe9..9ad827e0d8 100644
--- a/tools/editor/plugins/script_editor_plugin.cpp
+++ b/tools/editor/plugins/script_editor_plugin.cpp
@@ -1252,16 +1252,35 @@ void ScriptEditor::_menu_option(int p_option) {
Ref<Script> scr = current->get_edited_script();
if (scr.is_null())
return;
- int line = tx->cursor_get_line();
- int next_line = line + 1;
+
+ int from_line = tx->cursor_get_line();
+ int to_line = tx->cursor_get_line();
int column = tx->cursor_get_column();
- if (line >= tx->get_line_count() - 1)
- tx->set_line(line, tx->get_line(line) + "\n");
+ if (tx->is_selection_active()) {
+ from_line = tx->get_selection_from_line();
+ to_line = tx->get_selection_to_line();
+ column = tx->cursor_get_column();
+ }
+ int next_line = to_line + 1;
+
+ tx->begin_complex_operation();
+ for (int i = from_line; i <= to_line; i++) {
+
+ if (i >= tx->get_line_count() - 1) {
+ tx->set_line(i, tx->get_line(i) + "\n");
+ }
+ String line_clone = tx->get_line(i);
+ tx->insert_at(line_clone, next_line);
+ next_line++;
+ }
- String line_clone = tx->get_line(line);
- tx->insert_at(line_clone, next_line);
tx->cursor_set_column(column);
+ if (tx->is_selection_active()) {
+ tx->select(to_line + 1, tx->get_selection_from_column(), next_line - 1, tx->get_selection_to_column());
+ }
+
+ tx->end_complex_operation();
tx->update();
} break;
diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp
index f618f41cf8..a70dad48c1 100644
--- a/tools/editor/plugins/shader_graph_editor_plugin.cpp
+++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp
@@ -2311,7 +2311,9 @@ void ShaderGraphView::_create_node(int p_id) {
TextureFrame *tex = memnew( TextureFrame );
tex->set_expand(true);
tex->set_custom_minimum_size(Size2(80,80));
+ tex->set_drag_forwarding(this);
gn->add_child(tex);
+ tex->set_ignore_mouse(false);
tex->set_texture(graph->texture_input_node_get_value(type,p_id));
ToolButton *edit = memnew( ToolButton );
edit->set_text("edit..");
@@ -2517,6 +2519,105 @@ void ShaderGraphView::_sg_updated() {
}
}
+Variant ShaderGraphView::get_drag_data_fw(const Point2 &p_point, Control *p_from)
+{
+ TextureFrame* frame = p_from->cast_to<TextureFrame>();
+ if (!frame)
+ return Variant();
+
+ if (!frame->get_texture().is_valid())
+ return Variant();
+
+ RES res = frame->get_texture();
+ return EditorNode::get_singleton()->drag_resource(res,p_from);
+
+ return Variant();
+}
+
+bool ShaderGraphView::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const
+{
+ if (p_data.get_type() != Variant::DICTIONARY)
+ return false;
+
+ Dictionary d = p_data;
+
+ if (d.has("type")){
+ if (d["type"] == "resource" && d.has("resource")) {
+ Variant val = d["resource"];
+
+ if (val.get_type()==Variant::OBJECT) {
+ RES res = val;
+ if (res.is_valid() && res->cast_to<Texture>())
+ return true;
+ }
+ }
+ else if (d["type"] == "files" && d.has("files")) {
+ Vector<String> files = d["files"];
+ if (files.size() != 1)
+ return false;
+ return (ResourceLoader::get_resource_type(files[0]) == "ImageTexture");
+ }
+ }
+
+ return false;
+}
+
+void ShaderGraphView::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from)
+{
+ if (!can_drop_data_fw(p_point, p_data, p_from))
+ return;
+
+ TextureFrame *frame = p_from->cast_to<TextureFrame>();
+ if (!frame)
+ return;
+
+ Dictionary d = p_data;
+ Ref<Texture> tex;
+
+ if (d.has("type")) {
+ if (d["type"] == "resource" && d.has("resource")){
+ Variant val = d["resource"];
+
+ if (val.get_type()==Variant::OBJECT) {
+ RES res = val;
+ if (res.is_valid())
+ tex = Ref<Texture>(res->cast_to<Texture>());
+ }
+ }
+ else if (d["type"] == "files" && d.has("files")) {
+ Vector<String> files = d["files"];
+ RES res = ResourceLoader::load(files[0]);
+ if (res.is_valid())
+ tex = Ref<Texture>(res->cast_to<Texture>());
+ }
+ }
+
+ if (!tex.is_valid()) return;
+
+ GraphNode *gn = frame->get_parent()->cast_to<GraphNode>();
+ if (!gn) return;
+
+ int id = -1;
+ for(Map<int,GraphNode*>::Element *E = node_map.front();E;E=E->next())
+ if (E->get() == gn) {
+ id = E->key();
+ break;
+ }
+ print_line(String::num(double(id)));
+ if (id < 0) return;
+
+ if (graph->node_get_type(type,id)==ShaderGraph::NODE_TEXTURE_INPUT) {
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action(TTR("Change Texture Uniform"));
+ ur->add_do_method(graph.ptr(),"texture_input_node_set_value",type,id,tex);
+ ur->add_undo_method(graph.ptr(),"texture_input_node_set_value",type,id,graph->texture_input_node_get_value(type,id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
+ }
+}
+
void ShaderGraphView::set_graph(Ref<ShaderGraph> p_graph){
@@ -2623,6 +2724,10 @@ void ShaderGraphView::_bind_methods() {
ObjectTypeDB::bind_method("_color_ramp_changed",&ShaderGraphView::_color_ramp_changed);
ObjectTypeDB::bind_method("_curve_changed",&ShaderGraphView::_curve_changed);
+ ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &ShaderGraphView::get_drag_data_fw);
+ ObjectTypeDB::bind_method(_MD("can_drop_data_fw"), &ShaderGraphView::can_drop_data_fw);
+ ObjectTypeDB::bind_method(_MD("drop_data_fw"), &ShaderGraphView::drop_data_fw);
+
ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated);
}
diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h
index 0336696911..b33432807b 100644
--- a/tools/editor/plugins/shader_graph_editor_plugin.h
+++ b/tools/editor/plugins/shader_graph_editor_plugin.h
@@ -116,7 +116,7 @@ public:
GraphCurveMapEdit();
};
-class ShaderGraphView : public Node {
+class ShaderGraphView : public Control {
OBJ_TYPE(ShaderGraphView,Node);
@@ -181,6 +181,10 @@ class ShaderGraphView : public Node {
void _curve_changed(int p_id,Node* p_curve);
void _sg_updated();
Map<int,GraphNode*> node_map;
+
+ Variant get_drag_data_fw(const Point2& p_point,Control* p_from);
+ bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const;
+ void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from);
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/tools/editor/scenes_dock.cpp b/tools/editor/scenes_dock.cpp
index e00f470bc4..a068bdf58b 100644
--- a/tools/editor/scenes_dock.cpp
+++ b/tools/editor/scenes_dock.cpp
@@ -944,6 +944,7 @@ void ScenesDock::_file_option(int p_option) {
switch(p_option) {
+ case FILE_SHOW_IN_EXPLORER:
case FILE_OPEN: {
int idx=-1;
for(int i=0;i<files->get_item_count();i++) {
@@ -959,6 +960,17 @@ void ScenesDock::_file_option(int p_option) {
String path = files->get_item_metadata(idx);
+ if (p_option == FILE_SHOW_IN_EXPLORER) {
+ String dir = DirAccess::get_full_path("res://", DirAccess::ACCESS_FILESYSTEM);
+ const int res_begin = String("res://").length();
+ const int last_sep = path.find_last("/");
+ if (last_sep > res_begin) {
+ dir += "/";
+ dir += path.substr(res_begin, last_sep - res_begin);
+ }
+ OS::get_singleton()->shell_open(String("file://")+dir);
+ return;
+ }
if (path.ends_with("/")) {
if (path!="res://") {
@@ -1416,6 +1428,10 @@ void ScenesDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) {
file_options->add_item(TTR("Delete"),FILE_REMOVE);
//file_options->add_item(TTR("Info"),FILE_INFO);
+
+ file_options->add_separator();
+ file_options->add_item(TTR("Show In System"),FILE_SHOW_IN_EXPLORER);
+
file_options->set_pos(files->get_global_pos() + p_pos);
file_options->popup();
@@ -1635,4 +1651,3 @@ ScenesDock::ScenesDock(EditorNode *p_editor) {
ScenesDock::~ScenesDock() {
}
-
diff --git a/tools/editor/scenes_dock.h b/tools/editor/scenes_dock.h
index 327e5a25f0..42c1374be1 100644
--- a/tools/editor/scenes_dock.h
+++ b/tools/editor/scenes_dock.h
@@ -62,7 +62,8 @@ class ScenesDock : public VBoxContainer {
FILE_MOVE,
FILE_REMOVE,
FILE_REIMPORT,
- FILE_INFO
+ FILE_INFO,
+ FILE_SHOW_IN_EXPLORER
};