summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/graph_edit.cpp10
-rw-r--r--scene/gui/graph_node.cpp18
-rw-r--r--scene/resources/shader_graph.cpp41
-rw-r--r--scene/resources/shader_graph.h4
4 files changed, 64 insertions, 9 deletions
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 003486dcf1..a81542ea17 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -534,7 +534,7 @@ void GraphEdit::_input_event(const InputEvent& p_ev) {
top_layer->update();
}
- if (p_ev.type== InputEvent::MOUSE_BUTTON) {
+ if (p_ev.type==InputEvent::MOUSE_BUTTON) {
const InputEventMouseButton &b=p_ev.mouse_button;
@@ -667,6 +667,11 @@ void GraphEdit::_input_event(const InputEvent& p_ev) {
top_layer->update();
}
}
+
+ if (p_ev.type==InputEvent::KEY && p_ev.key.scancode==KEY_D && p_ev.key.pressed && p_ev.key.mod.command) {
+ emit_signal("duplicate_nodes_request");
+ accept_event();
+ }
}
void GraphEdit::clear_connections() {
@@ -723,6 +728,7 @@ void GraphEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2,"p_position")));
+ ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
ADD_SIGNAL(MethodInfo("_begin_node_move"));
ADD_SIGNAL(MethodInfo("_end_node_move"));
}
@@ -730,6 +736,8 @@ void GraphEdit::_bind_methods() {
GraphEdit::GraphEdit() {
+ set_focus_mode(FOCUS_ALL);
+
top_layer=NULL;
top_layer=memnew(GraphEditFilter(this));
add_child(top_layer);
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index f0917aa4d1..5efc9757b7 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -525,15 +525,17 @@ Color GraphNode::get_connection_output_color(int p_idx) {
void GraphNode::_input_event(const InputEvent& p_ev) {
- if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
-
- Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
- if (close_rect.size!=Size2() && close_rect.has_point(mpos)) {
- emit_signal("close_request");
- return;
+ if (p_ev.type==InputEvent::MOUSE_BUTTON) {
+ get_parent_control()->grab_focus();
+ if(p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
+
+ Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
+ if (close_rect.size!=Size2() && close_rect.has_point(mpos)) {
+ emit_signal("close_request");
+ return;
+ }
+ emit_signal("raise_request");
}
- emit_signal("raise_request");
-
}
}
diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp
index a0766ff317..108aad3c56 100644
--- a/scene/resources/shader_graph.cpp
+++ b/scene/resources/shader_graph.cpp
@@ -824,6 +824,47 @@ float ShaderGraph::texture_node_get_filter_strength(ShaderType p_type,float p_id
return arr[1];
}
+void ShaderGraph::duplicate_nodes(ShaderType p_which, List<int> &p_nodes)
+{
+ //Create new node IDs
+ Map<int,int> duplicates = Map<int,int>();
+ int i=1;
+ for(List<int>::Element *E=p_nodes.front();E; E=E->next()) {
+ while (shader[p_which].node_map.has(i))
+ i++;
+ duplicates.insert(E->get(), i);
+ i++;
+ }
+
+ for(List<int>::Element *E = p_nodes.front();E; E=E->next()) {
+
+ const Node &n=shader[p_which].node_map[E->get()];
+ Node nn=n;
+ nn.id=duplicates.find(n.id)->get();
+ nn.pos += Vector2(0,100);
+ for (Map<int,SourceSlot>::Element *C=nn.connections.front();C;C=C->next()) {
+ SourceSlot &c=C->get();
+ if (p_nodes.find(c.id))
+ c.id=duplicates.find(c.id)->get();
+ }
+ shader[p_which].node_map[nn.id]=nn;
+ }
+ _request_update();
+}
+
+List<int> ShaderGraph::generate_ids(ShaderType p_type, int count)
+{
+ List<int> ids = List<int>();
+ int i=1;
+ while (ids.size() < count) {
+ while (shader[p_type].node_map.has(i))
+ i++;
+ ids.push_back(i);
+ i++;
+ }
+ return ids;
+}
+
void ShaderGraph::scalar_op_node_set_op(ShaderType p_type,float p_id,ScalarOp p_op){
diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h
index fd6540a747..d3a297cd6c 100644
--- a/scene/resources/shader_graph.h
+++ b/scene/resources/shader_graph.h
@@ -216,6 +216,10 @@ public:
void texture_node_set_filter_strength(ShaderType p_which,float p_id,float p_strength);
float texture_node_get_filter_strength(ShaderType p_which,float p_id) const;
+ void duplicate_nodes(ShaderType p_which, List<int> &p_nodes);
+
+ List<int> generate_ids(ShaderType p_type, int count);
+
enum ScalarOp {
SCALAR_OP_ADD,
SCALAR_OP_SUB,