feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -259,7 +259,9 @@ PackedStringArray GraphEdit::get_configuration_warnings() const {
|
|||
return warnings;
|
||||
}
|
||||
|
||||
Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
|
||||
Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, bool p_keep_alive) {
|
||||
ERR_FAIL_NULL_V_MSG(connections_layer, FAILED, "connections_layer is missing.");
|
||||
|
||||
if (is_node_connected(p_from, p_from_port, p_to, p_to_port)) {
|
||||
return OK;
|
||||
}
|
||||
|
|
@ -270,6 +272,7 @@ Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const S
|
|||
c->to_node = p_to;
|
||||
c->to_port = p_to_port;
|
||||
c->activity = 0;
|
||||
c->keep_alive = p_keep_alive;
|
||||
connections.push_back(c);
|
||||
connection_map[p_from].push_back(c);
|
||||
connection_map[p_to].push_back(c);
|
||||
|
|
@ -313,26 +316,43 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
|
|||
}
|
||||
|
||||
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
|
||||
for (const List<Ref<Connection>>::Element *E = connections.front(); E; E = E->next()) {
|
||||
if (E->get()->from_node == p_from && E->get()->from_port == p_from_port && E->get()->to_node == p_to && E->get()->to_port == p_to_port) {
|
||||
connection_map[p_from].erase(E->get());
|
||||
connection_map[p_to].erase(E->get());
|
||||
E->get()->_cache.line->queue_free();
|
||||
connections.erase(E);
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
minimap->queue_redraw();
|
||||
queue_redraw();
|
||||
connections_layer->queue_redraw();
|
||||
callable_mp(this, &GraphEdit::_update_top_connection_layer).call_deferred();
|
||||
return;
|
||||
Ref<Connection> conn_to_remove;
|
||||
for (const Ref<Connection> &conn : connections) {
|
||||
if (conn->from_node == p_from && conn->from_port == p_from_port && conn->to_node == p_to && conn->to_port == p_to_port) {
|
||||
conn_to_remove = conn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (conn_to_remove.is_valid()) {
|
||||
connection_map[p_from].erase(conn_to_remove);
|
||||
connection_map[p_to].erase(conn_to_remove);
|
||||
conn_to_remove->_cache.line->queue_free();
|
||||
connections.erase(conn_to_remove);
|
||||
|
||||
minimap->queue_redraw();
|
||||
queue_redraw();
|
||||
connections_layer->queue_redraw();
|
||||
callable_mp(this, &GraphEdit::_update_top_connection_layer).call_deferred();
|
||||
}
|
||||
}
|
||||
|
||||
const List<Ref<GraphEdit::Connection>> &GraphEdit::get_connection_list() const {
|
||||
const Vector<Ref<GraphEdit::Connection>> &GraphEdit::get_connections() const {
|
||||
return connections;
|
||||
}
|
||||
|
||||
int GraphEdit::get_connection_count(const StringName &p_node, int p_port) {
|
||||
int count = 0;
|
||||
for (const Ref<Connection> &conn : connections) {
|
||||
if ((conn->from_node == p_node && conn->from_port == p_port) || (conn->to_node == p_node && conn->to_port == p_port)) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void GraphEdit::set_scroll_offset(const Vector2 &p_offset) {
|
||||
setting_scroll_offset = true;
|
||||
h_scrollbar->set_value(p_offset.x);
|
||||
|
|
@ -356,6 +376,8 @@ void GraphEdit::_scroll_moved(double) {
|
|||
}
|
||||
|
||||
void GraphEdit::_update_scroll_offset() {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
set_block_minimum_size_adjust(true);
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
|
@ -524,6 +546,8 @@ void GraphEdit::_graph_element_resize_request(const Vector2 &p_new_minsize, Node
|
|||
}
|
||||
|
||||
void GraphEdit::_graph_frame_autoshrink_changed(const Vector2 &p_new_minsize, GraphFrame *p_frame) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
_update_graph_frame(p_frame);
|
||||
|
||||
minimap->queue_redraw();
|
||||
|
|
@ -535,6 +559,7 @@ void GraphEdit::_graph_frame_autoshrink_changed(const Vector2 &p_new_minsize, Gr
|
|||
void GraphEdit::_graph_element_moved(Node *p_node) {
|
||||
GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
|
||||
ERR_FAIL_NULL(graph_element);
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
minimap->queue_redraw();
|
||||
queue_redraw();
|
||||
|
|
@ -543,6 +568,7 @@ void GraphEdit::_graph_element_moved(Node *p_node) {
|
|||
}
|
||||
|
||||
void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_node) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
GraphNode *graph_node = Object::cast_to<GraphNode>(p_node);
|
||||
ERR_FAIL_NULL(graph_node);
|
||||
|
||||
|
|
@ -558,15 +584,16 @@ void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_node) {
|
|||
}
|
||||
|
||||
void GraphEdit::_graph_node_rect_changed(GraphNode *p_node) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
// Only invalidate the cache when zooming or the node is moved/resized in graph space.
|
||||
if (panner->is_panning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Ref<Connection> &c : connection_map[p_node->get_name()]) {
|
||||
c->_cache.dirty = true;
|
||||
for (Ref<Connection> &conn : connection_map[p_node->get_name()]) {
|
||||
conn->_cache.dirty = true;
|
||||
}
|
||||
|
||||
connections_layer->queue_redraw();
|
||||
callable_mp(this, &GraphEdit::_update_top_connection_layer).call_deferred();
|
||||
|
||||
|
|
@ -623,7 +650,9 @@ void GraphEdit::add_child_notify(Node *p_child) {
|
|||
}
|
||||
graph_element->connect("raise_request", callable_mp(this, &GraphEdit::_ensure_node_order_from).bind(graph_element));
|
||||
graph_element->connect("resize_request", callable_mp(this, &GraphEdit::_graph_element_resize_request).bind(graph_element));
|
||||
graph_element->connect(SceneStringName(item_rect_changed), callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
|
||||
if (connections_layer != nullptr && connections_layer->is_inside_tree()) {
|
||||
graph_element->connect(SceneStringName(item_rect_changed), callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
|
||||
}
|
||||
graph_element->connect(SceneStringName(item_rect_changed), callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
|
||||
|
||||
graph_element->set_scale(Vector2(zoom, zoom));
|
||||
|
|
@ -640,6 +669,9 @@ void GraphEdit::remove_child_notify(Node *p_child) {
|
|||
minimap = nullptr;
|
||||
} else if (p_child == connections_layer) {
|
||||
connections_layer = nullptr;
|
||||
if (is_inside_tree()) {
|
||||
WARN_PRINT("GraphEdit's connection_layer removed. This should not be done. If you like to remove all GraphElements from a GraphEdit node, do not simply remove all non-internal children but check their type since the connection layer has to be kept non-internal due to technical reasons.");
|
||||
}
|
||||
}
|
||||
|
||||
if (top_layer != nullptr && is_inside_tree()) {
|
||||
|
|
@ -662,7 +694,9 @@ void GraphEdit::remove_child_notify(Node *p_child) {
|
|||
for (const Ref<Connection> &conn : connection_map[graph_node->get_name()]) {
|
||||
conn->_cache.dirty = true;
|
||||
}
|
||||
connections_layer->queue_redraw();
|
||||
if (connections_layer != nullptr && connections_layer->is_inside_tree()) {
|
||||
connections_layer->queue_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
GraphFrame *frame = Object::cast_to<GraphFrame>(graph_element);
|
||||
|
|
@ -715,14 +749,14 @@ void GraphEdit::_update_theme_item_cache() {
|
|||
void GraphEdit::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
zoom_minus_button->set_icon(theme_cache.zoom_out);
|
||||
zoom_reset_button->set_icon(theme_cache.zoom_reset);
|
||||
zoom_plus_button->set_icon(theme_cache.zoom_in);
|
||||
zoom_minus_button->set_button_icon(theme_cache.zoom_out);
|
||||
zoom_reset_button->set_button_icon(theme_cache.zoom_reset);
|
||||
zoom_plus_button->set_button_icon(theme_cache.zoom_in);
|
||||
|
||||
toggle_snapping_button->set_icon(theme_cache.snapping_toggle);
|
||||
toggle_grid_button->set_icon(theme_cache.grid_toggle);
|
||||
minimap_button->set_icon(theme_cache.minimap_toggle);
|
||||
arrange_button->set_icon(theme_cache.layout);
|
||||
toggle_snapping_button->set_button_icon(theme_cache.snapping_toggle);
|
||||
toggle_grid_button->set_button_icon(theme_cache.grid_toggle);
|
||||
minimap_button->set_button_icon(theme_cache.minimap_toggle);
|
||||
arrange_button->set_button_icon(theme_cache.layout);
|
||||
|
||||
zoom_label->set_custom_minimum_size(Size2(48, 0) * theme_cache.base_scale);
|
||||
|
||||
|
|
@ -757,6 +791,10 @@ void GraphEdit::_notification(int p_what) {
|
|||
minimap->queue_redraw();
|
||||
callable_mp(this, &GraphEdit::_update_top_connection_layer).call_deferred();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
update_warped_panning();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1271,16 +1309,16 @@ Ref<GraphEdit::Connection> GraphEdit::get_closest_connection_at_point(const Vect
|
|||
|
||||
Ref<GraphEdit::Connection> closest_connection;
|
||||
float closest_distance = p_max_distance;
|
||||
for (const Ref<Connection> &c : connections) {
|
||||
if (c->_cache.aabb.distance_to(transformed_point) > p_max_distance) {
|
||||
for (const Ref<Connection> &conn : connections) {
|
||||
if (conn->_cache.aabb.distance_to(transformed_point) > p_max_distance) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector<Vector2> points = get_connection_line(c->_cache.from_pos * zoom, c->_cache.to_pos * zoom);
|
||||
Vector<Vector2> points = get_connection_line(conn->_cache.from_pos * zoom, conn->_cache.to_pos * zoom);
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
float distance = Geometry2D::get_distance_to_segment(transformed_point, &points[i]);
|
||||
if (distance <= lines_thickness * 0.5 + p_max_distance && distance < closest_distance) {
|
||||
closest_connection = c;
|
||||
closest_connection = conn;
|
||||
closest_distance = distance;
|
||||
}
|
||||
}
|
||||
|
|
@ -1294,15 +1332,15 @@ List<Ref<GraphEdit::Connection>> GraphEdit::get_connections_intersecting_with_re
|
|||
transformed_rect.position += get_scroll_offset();
|
||||
|
||||
List<Ref<Connection>> intersecting_connections;
|
||||
for (const Ref<Connection> &c : connections) {
|
||||
if (!c->_cache.aabb.intersects(transformed_rect)) {
|
||||
for (const Ref<Connection> &conn : connections) {
|
||||
if (!conn->_cache.aabb.intersects(transformed_rect)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector<Vector2> points = get_connection_line(c->_cache.from_pos * zoom, c->_cache.to_pos * zoom);
|
||||
Vector<Vector2> points = get_connection_line(conn->_cache.from_pos * zoom, conn->_cache.to_pos * zoom);
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
if (Geometry2D::segment_intersects_rect(points[i], points[i + 1], transformed_rect)) {
|
||||
intersecting_connections.push_back(c);
|
||||
intersecting_connections.push_back(conn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1334,47 +1372,49 @@ void GraphEdit::_draw_minimap_connection_line(const Vector2 &p_from_graph_positi
|
|||
|
||||
void GraphEdit::_update_connections() {
|
||||
// Collect all dead connections and remove them.
|
||||
List<List<Ref<Connection>>::Element *> dead_connections;
|
||||
LocalVector<Ref<Connection>> dead_connections;
|
||||
|
||||
for (List<Ref<Connection>>::Element *E = connections.front(); E; E = E->next()) {
|
||||
Ref<Connection> &c = E->get();
|
||||
|
||||
if (c->_cache.dirty) {
|
||||
Node *from = get_node_or_null(NodePath(c->from_node));
|
||||
for (const Ref<Connection> &conn : connections) {
|
||||
if (conn->_cache.dirty) {
|
||||
Node *from = get_node_or_null(NodePath(conn->from_node));
|
||||
GraphNode *gnode_from = Object::cast_to<GraphNode>(from);
|
||||
if (!gnode_from) {
|
||||
dead_connections.push_back(E);
|
||||
if (!gnode_from && !conn->keep_alive) {
|
||||
dead_connections.push_back(conn);
|
||||
continue;
|
||||
}
|
||||
Node *to = get_node_or_null(NodePath(c->to_node));
|
||||
Node *to = get_node_or_null(NodePath(conn->to_node));
|
||||
GraphNode *gnode_to = Object::cast_to<GraphNode>(to);
|
||||
|
||||
if (!gnode_to) {
|
||||
dead_connections.push_back(E);
|
||||
if (!gnode_to && !conn->keep_alive) {
|
||||
dead_connections.push_back(conn);
|
||||
continue;
|
||||
}
|
||||
|
||||
const Vector2 from_pos = gnode_from->get_output_port_position(c->from_port) + gnode_from->get_position_offset();
|
||||
const Vector2 to_pos = gnode_to->get_input_port_position(c->to_port) + gnode_to->get_position_offset();
|
||||
if (conn->keep_alive && (!gnode_from || !gnode_to)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Color from_color = gnode_from->get_output_port_color(c->from_port);
|
||||
const Color to_color = gnode_to->get_input_port_color(c->to_port);
|
||||
const Vector2 from_pos = gnode_from->get_output_port_position(conn->from_port) + gnode_from->get_position_offset();
|
||||
const Vector2 to_pos = gnode_to->get_input_port_position(conn->to_port) + gnode_to->get_position_offset();
|
||||
|
||||
const int from_type = gnode_from->get_output_port_type(c->from_port);
|
||||
const int to_type = gnode_to->get_input_port_type(c->to_port);
|
||||
const Color from_color = gnode_from->get_output_port_color(conn->from_port);
|
||||
const Color to_color = gnode_to->get_input_port_color(conn->to_port);
|
||||
|
||||
c->_cache.from_pos = from_pos;
|
||||
c->_cache.to_pos = to_pos;
|
||||
c->_cache.from_color = from_color;
|
||||
c->_cache.to_color = to_color;
|
||||
const int from_type = gnode_from->get_output_port_type(conn->from_port);
|
||||
const int to_type = gnode_to->get_input_port_type(conn->to_port);
|
||||
|
||||
conn->_cache.from_pos = from_pos;
|
||||
conn->_cache.to_pos = to_pos;
|
||||
conn->_cache.from_color = from_color;
|
||||
conn->_cache.to_color = to_color;
|
||||
|
||||
PackedVector2Array line_points = get_connection_line(from_pos * zoom, to_pos * zoom);
|
||||
c->_cache.line->set_points(line_points);
|
||||
conn->_cache.line->set_points(line_points);
|
||||
|
||||
Ref<ShaderMaterial> line_material = c->_cache.line->get_material();
|
||||
Ref<ShaderMaterial> line_material = conn->_cache.line->get_material();
|
||||
if (line_material.is_null()) {
|
||||
line_material.instantiate();
|
||||
c->_cache.line->set_material(line_material);
|
||||
conn->_cache.line->set_material(line_material);
|
||||
}
|
||||
|
||||
float line_width = _get_shader_line_width();
|
||||
|
|
@ -1384,31 +1424,31 @@ void GraphEdit::_update_connections() {
|
|||
line_material->set_shader_parameter("rim_color", theme_cache.connection_rim_color);
|
||||
|
||||
// Compute bounding box of the line, including the line width.
|
||||
c->_cache.aabb = Rect2(line_points[0], Vector2());
|
||||
conn->_cache.aabb = Rect2(line_points[0], Vector2());
|
||||
for (int i = 0; i < line_points.size(); i++) {
|
||||
c->_cache.aabb.expand_to(line_points[i]);
|
||||
conn->_cache.aabb.expand_to(line_points[i]);
|
||||
}
|
||||
c->_cache.aabb.grow_by(lines_thickness * 0.5);
|
||||
conn->_cache.aabb.grow_by(lines_thickness * 0.5);
|
||||
|
||||
c->_cache.dirty = false;
|
||||
conn->_cache.dirty = false;
|
||||
}
|
||||
|
||||
// Skip updating/drawing connections that are not visible.
|
||||
Rect2 viewport_rect = get_viewport_rect();
|
||||
viewport_rect.position += get_scroll_offset();
|
||||
if (!c->_cache.aabb.intersects(viewport_rect)) {
|
||||
if (!conn->_cache.aabb.intersects(viewport_rect)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Color from_color = c->_cache.from_color;
|
||||
Color to_color = c->_cache.to_color;
|
||||
Color from_color = conn->_cache.from_color;
|
||||
Color to_color = conn->_cache.to_color;
|
||||
|
||||
if (c->activity > 0) {
|
||||
from_color = from_color.lerp(theme_cache.activity_color, c->activity);
|
||||
to_color = to_color.lerp(theme_cache.activity_color, c->activity);
|
||||
if (conn->activity > 0) {
|
||||
from_color = from_color.lerp(theme_cache.activity_color, conn->activity);
|
||||
to_color = to_color.lerp(theme_cache.activity_color, conn->activity);
|
||||
}
|
||||
|
||||
if (c == hovered_connection) {
|
||||
if (conn == hovered_connection) {
|
||||
from_color = from_color.blend(theme_cache.connection_hover_tint_color);
|
||||
to_color = to_color.blend(theme_cache.connection_hover_tint_color);
|
||||
}
|
||||
|
|
@ -1417,21 +1457,25 @@ void GraphEdit::_update_connections() {
|
|||
Ref<Gradient> line_gradient = memnew(Gradient);
|
||||
|
||||
float line_width = _get_shader_line_width();
|
||||
c->_cache.line->set_width(line_width);
|
||||
if (conn == hovered_connection) {
|
||||
line_width *= 1.0f + (theme_cache.connection_hover_thickness / 100.0f);
|
||||
}
|
||||
|
||||
conn->_cache.line->set_width(line_width);
|
||||
line_gradient->set_color(0, from_color);
|
||||
line_gradient->set_color(1, to_color);
|
||||
|
||||
c->_cache.line->set_gradient(line_gradient);
|
||||
conn->_cache.line->set_gradient(line_gradient);
|
||||
}
|
||||
|
||||
for (const List<Ref<Connection>>::Element *E : dead_connections) {
|
||||
List<Ref<Connection>> &connections_from = connection_map[E->get()->from_node];
|
||||
List<Ref<Connection>> &connections_to = connection_map[E->get()->to_node];
|
||||
connections_from.erase(E->get());
|
||||
connections_to.erase(E->get());
|
||||
E->get()->_cache.line->queue_free();
|
||||
for (const Ref<Connection> &dead_conn : dead_connections) {
|
||||
List<Ref<Connection>> &connections_from = connection_map[dead_conn->from_node];
|
||||
List<Ref<Connection>> &connections_to = connection_map[dead_conn->to_node];
|
||||
connections_from.erase(dead_conn);
|
||||
connections_to.erase(dead_conn);
|
||||
dead_conn->_cache.line->queue_free();
|
||||
|
||||
connections.erase(E->get());
|
||||
connections.erase(dead_conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1583,15 +1627,15 @@ void GraphEdit::_minimap_draw() {
|
|||
}
|
||||
|
||||
// Draw node connections.
|
||||
for (const Ref<Connection> &c : connections) {
|
||||
Vector2 from_graph_position = c->_cache.from_pos * zoom - graph_offset;
|
||||
Vector2 to_graph_position = c->_cache.to_pos * zoom - graph_offset;
|
||||
Color from_color = c->_cache.from_color;
|
||||
Color to_color = c->_cache.to_color;
|
||||
for (const Ref<Connection> &conn : connections) {
|
||||
Vector2 from_graph_position = conn->_cache.from_pos * zoom - graph_offset;
|
||||
Vector2 to_graph_position = conn->_cache.to_pos * zoom - graph_offset;
|
||||
Color from_color = conn->_cache.from_color;
|
||||
Color to_color = conn->_cache.to_color;
|
||||
|
||||
if (c->activity > 0) {
|
||||
from_color = from_color.lerp(theme_cache.activity_color, c->activity);
|
||||
to_color = to_color.lerp(theme_cache.activity_color, c->activity);
|
||||
if (conn->activity > 0) {
|
||||
from_color = from_color.lerp(theme_cache.activity_color, conn->activity);
|
||||
to_color = to_color.lerp(theme_cache.activity_color, conn->activity);
|
||||
}
|
||||
|
||||
_draw_minimap_connection_line(from_graph_position, to_graph_position, from_color, to_color);
|
||||
|
|
@ -1646,24 +1690,34 @@ void GraphEdit::_draw_grid() {
|
|||
Color transparent_grid_minor = theme_cache.grid_minor;
|
||||
transparent_grid_minor.a *= CLAMP(1.0 * (zoom - 0.4), 0, 1);
|
||||
|
||||
for (int i = from_pos.x; i < from_pos.x + len.x; i++) {
|
||||
for (int j = from_pos.y; j < from_pos.y + len.y; j++) {
|
||||
Color color = transparent_grid_minor;
|
||||
// Minor dots.
|
||||
if (transparent_grid_minor.a != 0) {
|
||||
for (int i = from_pos.x; i < from_pos.x + len.x; i++) {
|
||||
for (int j = from_pos.y; j < from_pos.y + len.y; j++) {
|
||||
if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0 && ABS(j) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ABS(i) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0 && ABS(j) % GRID_MINOR_STEPS_PER_MAJOR_DOT == 0) {
|
||||
color = theme_cache.grid_major;
|
||||
float base_offset_x = i * snapping_distance * zoom - offset.x * zoom;
|
||||
float base_offset_y = j * snapping_distance * zoom - offset.y * zoom;
|
||||
|
||||
draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), transparent_grid_minor);
|
||||
}
|
||||
|
||||
if (color.a == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float base_offset_x = i * snapping_distance * zoom - offset.x * zoom;
|
||||
float base_offset_y = j * snapping_distance * zoom - offset.y * zoom;
|
||||
|
||||
draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), color);
|
||||
}
|
||||
}
|
||||
|
||||
// Major dots.
|
||||
if (theme_cache.grid_major.a != 0) {
|
||||
for (int i = from_pos.x - from_pos.x % GRID_MINOR_STEPS_PER_MAJOR_DOT; i < from_pos.x + len.x; i += GRID_MINOR_STEPS_PER_MAJOR_DOT) {
|
||||
for (int j = from_pos.y - from_pos.y % GRID_MINOR_STEPS_PER_MAJOR_DOT; j < from_pos.y + len.y; j += GRID_MINOR_STEPS_PER_MAJOR_DOT) {
|
||||
float base_offset_x = i * snapping_distance * zoom - offset.x * zoom;
|
||||
float base_offset_y = j * snapping_distance * zoom - offset.y * zoom;
|
||||
|
||||
draw_rect(Rect2(base_offset_x - 1, base_offset_y - 1, 3, 3), theme_cache.grid_major);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1680,8 +1734,10 @@ void GraphEdit::set_selected(Node *p_child) {
|
|||
}
|
||||
|
||||
void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
ERR_FAIL_COND(p_ev.is_null());
|
||||
if (panner->gui_input(p_ev, warped_panning ? get_global_rect() : Rect2())) {
|
||||
if (panner->gui_input(p_ev, get_global_rect())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1989,6 +2045,9 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
|||
} else if (p_ev->is_action("ui_copy", true)) {
|
||||
emit_signal(SNAME("copy_nodes_request"));
|
||||
accept_event();
|
||||
} else if (p_ev->is_action("ui_cut", true)) {
|
||||
emit_signal(SNAME("cut_nodes_request"));
|
||||
accept_event();
|
||||
} else if (p_ev->is_action("ui_paste", true)) {
|
||||
emit_signal(SNAME("paste_nodes_request"));
|
||||
accept_event();
|
||||
|
|
@ -2012,6 +2071,8 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
|
|||
}
|
||||
|
||||
void GraphEdit::_pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
h_scrollbar->set_value(h_scrollbar->get_value() - p_scroll_vec.x);
|
||||
v_scrollbar->set_value(v_scrollbar->get_value() - p_scroll_vec.y);
|
||||
|
||||
|
|
@ -2027,22 +2088,26 @@ void GraphEdit::_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputE
|
|||
}
|
||||
|
||||
void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
|
||||
for (Ref<Connection> &c : connection_map[p_from]) {
|
||||
if (c->from_node == p_from && c->from_port == p_from_port && c->to_node == p_to && c->to_port == p_to_port) {
|
||||
if (!Math::is_equal_approx(c->activity, p_activity)) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
for (Ref<Connection> &conn : connection_map[p_from]) {
|
||||
if (conn->from_node == p_from && conn->from_port == p_from_port && conn->to_node == p_to && conn->to_port == p_to_port) {
|
||||
if (!Math::is_equal_approx(conn->activity, p_activity)) {
|
||||
// Update only if changed.
|
||||
minimap->queue_redraw();
|
||||
c->_cache.dirty = true;
|
||||
conn->_cache.dirty = true;
|
||||
connections_layer->queue_redraw();
|
||||
callable_mp(this, &GraphEdit::_update_top_connection_layer).call_deferred();
|
||||
}
|
||||
c->activity = p_activity;
|
||||
conn->activity = p_activity;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphEdit::reset_all_connection_activity() {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
bool changed = false;
|
||||
for (Ref<Connection> &conn : connections) {
|
||||
if (conn->activity > 0) {
|
||||
|
|
@ -2057,8 +2122,10 @@ void GraphEdit::reset_all_connection_activity() {
|
|||
}
|
||||
|
||||
void GraphEdit::clear_connections() {
|
||||
for (Ref<Connection> &c : connections) {
|
||||
c->_cache.line->queue_free();
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
for (Ref<Connection> &conn : connections) {
|
||||
conn->_cache.line->queue_free();
|
||||
}
|
||||
|
||||
connections.clear();
|
||||
|
|
@ -2070,7 +2137,9 @@ void GraphEdit::clear_connections() {
|
|||
}
|
||||
|
||||
void GraphEdit::force_connection_drag_end() {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
ERR_FAIL_COND_MSG(!connecting, "Drag end requested without active drag!");
|
||||
|
||||
connecting = false;
|
||||
connecting_valid = false;
|
||||
minimap->queue_redraw();
|
||||
|
|
@ -2100,6 +2169,8 @@ void GraphEdit::set_zoom(float p_zoom) {
|
|||
}
|
||||
|
||||
void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
p_zoom = CLAMP(p_zoom, zoom_min, zoom_max);
|
||||
if (zoom == p_zoom) {
|
||||
return;
|
||||
|
|
@ -2201,8 +2272,20 @@ void GraphEdit::remove_valid_left_disconnect_type(int p_type) {
|
|||
valid_left_disconnect_types.erase(p_type);
|
||||
}
|
||||
|
||||
void GraphEdit::set_connections(const TypedArray<Dictionary> &p_connections) {
|
||||
clear_connections();
|
||||
|
||||
bool is_editor = Engine::get_singleton()->is_editor_hint();
|
||||
|
||||
for (const Dictionary d : p_connections) {
|
||||
// Always keep the connection alive in case it is created using the inspector.
|
||||
bool keep_alive = (is_editor && d.is_empty()) || d["keep_alive"];
|
||||
connect_node(d["from_node"], d["from_port"], d["to_node"], d["to_port"], keep_alive);
|
||||
}
|
||||
}
|
||||
|
||||
TypedArray<Dictionary> GraphEdit::_get_connection_list() const {
|
||||
List<Ref<Connection>> conns = get_connection_list();
|
||||
Vector<Ref<Connection>> conns = get_connections();
|
||||
|
||||
TypedArray<Dictionary> arr;
|
||||
for (const Ref<Connection> &conn : conns) {
|
||||
|
|
@ -2211,6 +2294,7 @@ TypedArray<Dictionary> GraphEdit::_get_connection_list() const {
|
|||
d["from_port"] = conn->from_port;
|
||||
d["to_node"] = conn->to_node;
|
||||
d["to_port"] = conn->to_port;
|
||||
d["keep_alive"] = conn->keep_alive;
|
||||
arr.push_back(d);
|
||||
}
|
||||
return arr;
|
||||
|
|
@ -2224,6 +2308,7 @@ Dictionary GraphEdit::_get_closest_connection_at_point(const Vector2 &p_point, f
|
|||
ret["from_port"] = c->from_port;
|
||||
ret["to_node"] = c->to_node;
|
||||
ret["to_port"] = c->to_port;
|
||||
ret["keep_alive"] = c->keep_alive;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -2238,6 +2323,7 @@ TypedArray<Dictionary> GraphEdit::_get_connections_intersecting_with_rect(const
|
|||
d["from_port"] = conn->from_port;
|
||||
d["to_node"] = conn->to_node;
|
||||
d["to_port"] = conn->to_port;
|
||||
d["keep_alive"] = conn->keep_alive;
|
||||
arr.push_back(d);
|
||||
}
|
||||
return arr;
|
||||
|
|
@ -2262,8 +2348,8 @@ void GraphEdit::_update_zoom_label() {
|
|||
}
|
||||
|
||||
void GraphEdit::_invalidate_connection_line_cache() {
|
||||
for (Ref<Connection> &c : connections) {
|
||||
c->_cache.dirty = true;
|
||||
for (Ref<Connection> &conn : connections) {
|
||||
conn->_cache.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2508,6 +2594,8 @@ bool GraphEdit::is_showing_arrange_button() const {
|
|||
}
|
||||
|
||||
void GraphEdit::override_connections_shader(const Ref<Shader> &p_shader) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
connections_shader = p_shader;
|
||||
|
||||
_invalidate_connection_line_cache();
|
||||
|
|
@ -2526,6 +2614,8 @@ void GraphEdit::_minimap_toggled() {
|
|||
}
|
||||
|
||||
void GraphEdit::set_connection_lines_curvature(float p_curvature) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
lines_curvature = p_curvature;
|
||||
_invalidate_connection_line_cache();
|
||||
connections_layer->queue_redraw();
|
||||
|
|
@ -2537,7 +2627,9 @@ float GraphEdit::get_connection_lines_curvature() const {
|
|||
}
|
||||
|
||||
void GraphEdit::set_connection_lines_thickness(float p_thickness) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
ERR_FAIL_COND_MSG(p_thickness < 0, "Connection lines thickness must be greater than or equal to 0.");
|
||||
|
||||
if (lines_thickness == p_thickness) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -2552,6 +2644,8 @@ float GraphEdit::get_connection_lines_thickness() const {
|
|||
}
|
||||
|
||||
void GraphEdit::set_connection_lines_antialiased(bool p_antialiased) {
|
||||
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");
|
||||
|
||||
if (lines_antialiased == p_antialiased) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -2575,6 +2669,11 @@ Ref<ViewPanner> GraphEdit::get_panner() {
|
|||
|
||||
void GraphEdit::set_warped_panning(bool p_warped) {
|
||||
warped_panning = p_warped;
|
||||
update_warped_panning();
|
||||
}
|
||||
|
||||
void GraphEdit::update_warped_panning() {
|
||||
panner->setup_warped_panning(get_viewport(), warped_panning);
|
||||
}
|
||||
|
||||
void GraphEdit::arrange_nodes() {
|
||||
|
|
@ -2582,11 +2681,13 @@ void GraphEdit::arrange_nodes() {
|
|||
}
|
||||
|
||||
void GraphEdit::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("connect_node", "from_node", "from_port", "to_node", "to_port"), &GraphEdit::connect_node);
|
||||
ClassDB::bind_method(D_METHOD("connect_node", "from_node", "from_port", "to_node", "to_port", "keep_alive"), &GraphEdit::connect_node, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("is_node_connected", "from_node", "from_port", "to_node", "to_port"), &GraphEdit::is_node_connected);
|
||||
ClassDB::bind_method(D_METHOD("disconnect_node", "from_node", "from_port", "to_node", "to_port"), &GraphEdit::disconnect_node);
|
||||
ClassDB::bind_method(D_METHOD("set_connection_activity", "from_node", "from_port", "to_node", "to_port", "amount"), &GraphEdit::set_connection_activity);
|
||||
ClassDB::bind_method(D_METHOD("set_connections", "connections"), &GraphEdit::set_connections);
|
||||
ClassDB::bind_method(D_METHOD("get_connection_list"), &GraphEdit::_get_connection_list);
|
||||
ClassDB::bind_method(D_METHOD("get_connection_count", "from_node", "from_port"), &GraphEdit::get_connection_count);
|
||||
ClassDB::bind_method(D_METHOD("get_closest_connection_at_point", "point", "max_distance"), &GraphEdit::_get_closest_connection_at_point, DEFVAL(4.0));
|
||||
ClassDB::bind_method(D_METHOD("get_connections_intersecting_with_rect", "rect"), &GraphEdit::_get_connections_intersecting_with_rect);
|
||||
ClassDB::bind_method(D_METHOD("clear_connections"), &GraphEdit::clear_connections);
|
||||
|
|
@ -2697,6 +2798,7 @@ void GraphEdit::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "connection_lines_curvature"), "set_connection_lines_curvature", "get_connection_lines_curvature");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "connection_lines_thickness", PROPERTY_HINT_RANGE, "0,100,0.1,suffix:px"), "set_connection_lines_thickness", "get_connection_lines_thickness");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "connection_lines_antialiased"), "set_connection_lines_antialiased", "is_connection_lines_antialiased");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "connections", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::DICTIONARY, PROPERTY_HINT_NONE, String())), "set_connections", "get_connection_list");
|
||||
|
||||
ADD_GROUP("Zoom", "");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "zoom"), "set_zoom", "get_zoom");
|
||||
|
|
@ -2725,13 +2827,14 @@ void GraphEdit::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo("connection_drag_ended"));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("copy_nodes_request"));
|
||||
ADD_SIGNAL(MethodInfo("cut_nodes_request"));
|
||||
ADD_SIGNAL(MethodInfo("paste_nodes_request"));
|
||||
ADD_SIGNAL(MethodInfo("duplicate_nodes_request"));
|
||||
ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
||||
ADD_SIGNAL(MethodInfo("node_deselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
||||
ADD_SIGNAL(MethodInfo("frame_rect_changed", PropertyInfo(Variant::OBJECT, "frame", PROPERTY_HINT_RESOURCE_TYPE, "GraphFrame"), PropertyInfo(Variant::VECTOR2, "new_rect")));
|
||||
ADD_SIGNAL(MethodInfo("frame_rect_changed", PropertyInfo(Variant::OBJECT, "frame", PROPERTY_HINT_RESOURCE_TYPE, "GraphFrame"), PropertyInfo(Variant::RECT2, "new_rect")));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2, "at_position")));
|
||||
|
||||
|
|
@ -2752,6 +2855,7 @@ void GraphEdit::_bind_methods() {
|
|||
|
||||
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, GraphEdit, activity_color, "activity");
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, connection_hover_tint_color);
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, GraphEdit, connection_hover_thickness);
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, connection_valid_target_tint_color);
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, connection_rim_color);
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, GraphEdit, selection_fill);
|
||||
|
|
@ -2851,7 +2955,7 @@ GraphEdit::GraphEdit() {
|
|||
_update_zoom_label();
|
||||
|
||||
zoom_minus_button = memnew(Button);
|
||||
zoom_minus_button->set_theme_type_variation("FlatButton");
|
||||
zoom_minus_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
zoom_minus_button->set_visible(show_zoom_buttons);
|
||||
zoom_minus_button->set_tooltip_text(ETR("Zoom Out"));
|
||||
zoom_minus_button->set_focus_mode(FOCUS_NONE);
|
||||
|
|
@ -2859,7 +2963,7 @@ GraphEdit::GraphEdit() {
|
|||
zoom_minus_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_zoom_minus));
|
||||
|
||||
zoom_reset_button = memnew(Button);
|
||||
zoom_reset_button->set_theme_type_variation("FlatButton");
|
||||
zoom_reset_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
zoom_reset_button->set_visible(show_zoom_buttons);
|
||||
zoom_reset_button->set_tooltip_text(ETR("Zoom Reset"));
|
||||
zoom_reset_button->set_focus_mode(FOCUS_NONE);
|
||||
|
|
@ -2867,7 +2971,7 @@ GraphEdit::GraphEdit() {
|
|||
zoom_reset_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_zoom_reset));
|
||||
|
||||
zoom_plus_button = memnew(Button);
|
||||
zoom_plus_button->set_theme_type_variation("FlatButton");
|
||||
zoom_plus_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
zoom_plus_button->set_visible(show_zoom_buttons);
|
||||
zoom_plus_button->set_tooltip_text(ETR("Zoom In"));
|
||||
zoom_plus_button->set_focus_mode(FOCUS_NONE);
|
||||
|
|
@ -2877,7 +2981,7 @@ GraphEdit::GraphEdit() {
|
|||
// Grid controls.
|
||||
|
||||
toggle_grid_button = memnew(Button);
|
||||
toggle_grid_button->set_theme_type_variation("FlatButton");
|
||||
toggle_grid_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
toggle_grid_button->set_visible(show_grid_buttons);
|
||||
toggle_grid_button->set_toggle_mode(true);
|
||||
toggle_grid_button->set_pressed(true);
|
||||
|
|
@ -2887,7 +2991,7 @@ GraphEdit::GraphEdit() {
|
|||
toggle_grid_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_show_grid_toggled));
|
||||
|
||||
toggle_snapping_button = memnew(Button);
|
||||
toggle_snapping_button->set_theme_type_variation("FlatButton");
|
||||
toggle_snapping_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
toggle_snapping_button->set_visible(show_grid_buttons);
|
||||
toggle_snapping_button->set_toggle_mode(true);
|
||||
toggle_snapping_button->set_tooltip_text(ETR("Toggle snapping to the grid."));
|
||||
|
|
@ -2909,7 +3013,7 @@ GraphEdit::GraphEdit() {
|
|||
// Extra controls.
|
||||
|
||||
minimap_button = memnew(Button);
|
||||
minimap_button->set_theme_type_variation("FlatButton");
|
||||
minimap_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
minimap_button->set_visible(show_minimap_button);
|
||||
minimap_button->set_toggle_mode(true);
|
||||
minimap_button->set_tooltip_text(ETR("Toggle the graph minimap."));
|
||||
|
|
@ -2919,7 +3023,7 @@ GraphEdit::GraphEdit() {
|
|||
minimap_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_minimap_toggled));
|
||||
|
||||
arrange_button = memnew(Button);
|
||||
arrange_button->set_theme_type_variation("FlatButton");
|
||||
arrange_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
arrange_button->set_visible(show_arrange_button);
|
||||
arrange_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::arrange_nodes));
|
||||
arrange_button->set_focus_mode(FOCUS_NONE);
|
||||
|
|
@ -2947,5 +3051,5 @@ GraphEdit::GraphEdit() {
|
|||
|
||||
set_clip_contents(true);
|
||||
|
||||
arranger = Ref<GraphEditArranger>(memnew(GraphEditArranger(this)));
|
||||
arranger.instantiate(this);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue