diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/import/editor_scene_importer_gltf.cpp | 6 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 530 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 15 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 6 | ||||
-rw-r--r-- | editor/scene_tree_dock.cpp | 12 | ||||
-rw-r--r-- | editor/script_create_dialog.cpp | 15 | ||||
-rw-r--r-- | editor/script_editor_debugger.cpp | 222 | ||||
-rw-r--r-- | editor/script_editor_debugger.h | 9 |
8 files changed, 496 insertions, 319 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 80713a157b..85383fd69d 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1876,9 +1876,9 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector<float> &p_times, cons float c = (p_time - p_times[idx]) / (p_times[idx + 1] - p_times[idx]); T from = p_values[idx * 3 + 1]; - T c1 = from + p_values[idx * 3 + 0]; - T to = p_values[idx * 3 + 3]; - T c2 = to + p_values[idx * 3 + 2]; + T c1 = from + p_values[idx * 3 + 2]; + T to = p_values[idx * 3 + 4]; + T c2 = to + p_values[idx * 3 + 3]; return interp.bezier(from, c1, c2, to, c); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index d2a9a18a43..7fe9f429b0 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -55,6 +55,7 @@ #define MAX_ZOOM 100 #define RULER_WIDTH 15 * EDSCALE +#define SCALE_HANDLE_DISTANCE 25 class SnapDialog : public ConfirmationDialog { @@ -335,10 +336,11 @@ void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack()) return; - if (k->get_control()) - return; + if (k->get_scancode() == KEY_CONTROL || k->get_scancode() == KEY_ALT || k->get_scancode() == KEY_SHIFT) { + viewport->update(); + } - if (k->is_pressed() && !k->is_echo()) { + if (k->is_pressed() && !k->get_control() && !k->is_echo()) { if ((snap_grid || show_grid) && multiply_grid_step_shortcut.is_valid() && multiply_grid_step_shortcut->is_shortcut(p_ev)) { // Multiply the grid size grid_step_multiplier = MIN(grid_step_multiplier + 1, 12); @@ -1267,7 +1269,7 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) { if (drag_type == DRAG_NONE) { if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) { drag_selection = _get_edited_canvas_items(); - if (drag_selection.size() > 0 && ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE)) { + if (drag_selection.size() > 0 && ((b->get_control() && !b->get_alt() && tool == TOOL_SELECT) || tool == TOOL_ROTATE)) { drag_type = DRAG_ROTATE; drag_from = transform.affine_inverse().xform(b->get_position()); CanvasItem *canvas_item = drag_selection[0]; @@ -1615,6 +1617,89 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) { return false; } +bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) { + + Ref<InputEventMouseButton> b = p_event; + Ref<InputEventMouseMotion> m = p_event; + + // Drag resize handles + if (drag_type == DRAG_NONE) { + if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed() && ((b->get_alt() && b->get_control()) || tool == TOOL_SCALE)) { + List<CanvasItem *> selection = _get_edited_canvas_items(); + if (selection.size() == 1) { + CanvasItem *canvas_item = selection[0]; + + Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); + Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + + Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); + Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_SCALE_X; + } + Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) { + drag_type = DRAG_SCALE_Y; + } + if (drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) { + drag_from = transform.affine_inverse().xform(b->get_position()); + drag_selection = List<CanvasItem *>(); + drag_selection.push_back(canvas_item); + _save_canvas_item_state(drag_selection); + return true; + } + } + } + } + + if (drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) { + // Resize the node + if (m.is_valid()) { + _restore_canvas_item_state(drag_selection, true); + CanvasItem *canvas_item = drag_selection[0]; + + drag_to = transform.affine_inverse().xform(m->get_position()); + + bool uniform = m->get_shift(); + Point2 offset = drag_to - drag_from; + Size2 scale = canvas_item->call("get_scale"); + float ratio = scale.y / scale.x; + if (drag_type == DRAG_SCALE_X) { + scale.x += offset.x / SCALE_HANDLE_DISTANCE; + if (uniform) { + scale.y = scale.x * ratio; + } + canvas_item->call("set_scale", scale); + + } else if (drag_type == DRAG_SCALE_Y) { + scale.y -= offset.y / SCALE_HANDLE_DISTANCE; + if (uniform) { + scale.x = scale.y / ratio; + } + canvas_item->call("set_scale", scale); + } + } + + // Confirm resize + if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) { + _commit_canvas_item_state(drag_selection, TTR("Scale CanvasItem")); + drag_type = DRAG_NONE; + viewport->update(); + return true; + } + + // Cancel a drag + if (b.is_valid() && b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) { + _restore_canvas_item_state(drag_selection); + drag_type = DRAG_NONE; + viewport->update(); + return true; + } + } + return false; +} + bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> b = p_event; Ref<InputEventMouseMotion> m = p_event; @@ -1624,7 +1709,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { //Start moving the nodes if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) { List<CanvasItem *> selection = _get_edited_canvas_items(); - if ((b->get_alt() || tool == TOOL_MOVE) && selection.size() > 0) { + if (((b->get_alt() && !b->get_control()) || tool == TOOL_MOVE) && selection.size() > 0) { drag_type = DRAG_MOVE; drag_from = transform.affine_inverse().xform(b->get_position()); drag_selection = selection; @@ -2006,6 +2091,8 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { //printf("Open scene on double click\n"); } else if ((accepted = _gui_input_anchors(p_event))) { //printf("Anchors\n"); + } else if ((accepted = _gui_input_scale(p_event))) { + //printf("Set scale\n"); } else if ((accepted = _gui_input_pivot(p_event))) { //printf("Set pivot\n"); } else if ((accepted = _gui_input_resize(p_event))) { @@ -2288,6 +2375,188 @@ void CanvasItemEditor::_draw_grid() { } } +void CanvasItemEditor::_draw_control_helpers(Control *control) { + Transform2D xform = transform * control->get_global_transform_with_canvas(); + RID ci = viewport->get_canvas_item(); + if (tool == TOOL_SELECT && show_helpers && !Object::cast_to<Container>(control->get_parent())) { + // Draw the helpers + Color color_base = Color(0.8, 0.8, 0.8, 0.5); + + float anchors_values[4]; + anchors_values[0] = control->get_anchor(MARGIN_LEFT); + anchors_values[1] = control->get_anchor(MARGIN_TOP); + anchors_values[2] = control->get_anchor(MARGIN_RIGHT); + anchors_values[3] = control->get_anchor(MARGIN_BOTTOM); + + // Draw the anchors + Vector2 anchors[4]; + Vector2 anchors_pos[4]; + for (int i = 0; i < 4; i++) { + anchors[i] = Vector2((i % 2 == 0) ? anchors_values[i] : anchors_values[(i + 1) % 4], (i % 2 == 1) ? anchors_values[i] : anchors_values[(i + 1) % 4]); + anchors_pos[i] = xform.xform(_anchor_to_position(control, anchors[i])); + } + + // Get which anchor is dragged + int dragged_anchor = -1; + switch (drag_type) { + case DRAG_ANCHOR_ALL: + case DRAG_ANCHOR_TOP_LEFT: + dragged_anchor = 0; + break; + case DRAG_ANCHOR_TOP_RIGHT: + dragged_anchor = 1; + break; + case DRAG_ANCHOR_BOTTOM_RIGHT: + dragged_anchor = 2; + break; + case DRAG_ANCHOR_BOTTOM_LEFT: + dragged_anchor = 3; + break; + default: + break; + } + + if (dragged_anchor >= 0) { + // Draw the 4 lines when dragged + bool snapped; + Color color_snapped = Color(0.64, 0.93, 0.67, 0.5); + + Vector2 corners_pos[4]; + for (int i = 0; i < 4; i++) { + corners_pos[i] = xform.xform(_anchor_to_position(control, Vector2((i == 0 || i == 3) ? ANCHOR_BEGIN : ANCHOR_END, (i <= 1) ? ANCHOR_BEGIN : ANCHOR_END))); + } + + Vector2 line_starts[4]; + Vector2 line_ends[4]; + for (int i = 0; i < 4; i++) { + float anchor_val = (i >= 2) ? ANCHOR_END - anchors_values[i] : anchors_values[i]; + line_starts[i] = Vector2::linear_interpolate(corners_pos[i], corners_pos[(i + 1) % 4], anchor_val); + line_ends[i] = Vector2::linear_interpolate(corners_pos[(i + 3) % 4], corners_pos[(i + 2) % 4], anchor_val); + snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; + viewport->draw_line(line_starts[i], line_ends[i], snapped ? color_snapped : color_base, (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) ? 2 : 1); + } + + // Display the percentages next to the lines + float percent_val; + percent_val = anchors_values[(dragged_anchor + 2) % 4] - anchors_values[dragged_anchor]; + percent_val = (dragged_anchor >= 2) ? -percent_val : percent_val; + _draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 1) % 4]) / 2, (Margin)((dragged_anchor + 1) % 4)); + + percent_val = anchors_values[(dragged_anchor + 3) % 4] - anchors_values[(dragged_anchor + 1) % 4]; + percent_val = ((dragged_anchor + 1) % 4 >= 2) ? -percent_val : percent_val; + _draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 3) % 4]) / 2, (Margin)(dragged_anchor)); + + percent_val = anchors_values[(dragged_anchor + 1) % 4]; + percent_val = ((dragged_anchor + 1) % 4 >= 2) ? ANCHOR_END - percent_val : percent_val; + _draw_percentage_at_position(percent_val, (line_starts[dragged_anchor] + anchors_pos[dragged_anchor]) / 2, (Margin)(dragged_anchor)); + + percent_val = anchors_values[dragged_anchor]; + percent_val = (dragged_anchor >= 2) ? ANCHOR_END - percent_val : percent_val; + _draw_percentage_at_position(percent_val, (line_ends[(dragged_anchor + 1) % 4] + anchors_pos[dragged_anchor]) / 2, (Margin)((dragged_anchor + 1) % 4)); + } + + Rect2 anchor_rects[4]; + anchor_rects[0] = Rect2(anchors_pos[0] - anchor_handle->get_size(), anchor_handle->get_size()); + anchor_rects[1] = Rect2(anchors_pos[1] - Vector2(0.0, anchor_handle->get_size().y), Point2(-anchor_handle->get_size().x, anchor_handle->get_size().y)); + anchor_rects[2] = Rect2(anchors_pos[2], -anchor_handle->get_size()); + anchor_rects[3] = Rect2(anchors_pos[3] - Vector2(anchor_handle->get_size().x, 0.0), Point2(anchor_handle->get_size().x, -anchor_handle->get_size().y)); + + for (int i = 0; i < 4; i++) { + anchor_handle->draw_rect(ci, anchor_rects[i]); + } + + // Draw the margin values and the node width/height when dragging control side + float ratio = 0.33; + Transform2D parent_transform = xform * control->get_transform().affine_inverse(); + float node_pos_in_parent[4]; + + Rect2 parent_rect = control->get_parent_anchorable_rect(); + + node_pos_in_parent[0] = control->get_anchor(MARGIN_LEFT) * parent_rect.size.width + control->get_margin(MARGIN_LEFT) + parent_rect.position.x; + node_pos_in_parent[1] = control->get_anchor(MARGIN_TOP) * parent_rect.size.height + control->get_margin(MARGIN_TOP) + parent_rect.position.y; + node_pos_in_parent[2] = control->get_anchor(MARGIN_RIGHT) * parent_rect.size.width + control->get_margin(MARGIN_RIGHT) + parent_rect.position.x; + node_pos_in_parent[3] = control->get_anchor(MARGIN_BOTTOM) * parent_rect.size.height + control->get_margin(MARGIN_BOTTOM) + parent_rect.position.y; + + Point2 start, end; + switch (drag_type) { + case DRAG_LEFT: + case DRAG_TOP_LEFT: + case DRAG_BOTTOM_LEFT: + _draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM); + case DRAG_MOVE: + start = Vector2(node_pos_in_parent[0], Math::lerp(node_pos_in_parent[1], node_pos_in_parent[3], ratio)); + end = start - Vector2(control->get_margin(MARGIN_LEFT), 0); + _draw_margin_at_position(control->get_margin(MARGIN_LEFT), parent_transform.xform((start + end) / 2), MARGIN_TOP); + viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); + break; + default: + break; + } + switch (drag_type) { + case DRAG_RIGHT: + case DRAG_TOP_RIGHT: + case DRAG_BOTTOM_RIGHT: + _draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM); + case DRAG_MOVE: + start = Vector2(node_pos_in_parent[2], Math::lerp(node_pos_in_parent[3], node_pos_in_parent[1], ratio)); + end = start - Vector2(control->get_margin(MARGIN_RIGHT), 0); + _draw_margin_at_position(control->get_margin(MARGIN_RIGHT), parent_transform.xform((start + end) / 2), MARGIN_BOTTOM); + viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); + break; + default: + break; + } + switch (drag_type) { + case DRAG_TOP: + case DRAG_TOP_LEFT: + case DRAG_TOP_RIGHT: + _draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2)) + Vector2(5, 0), MARGIN_RIGHT); + case DRAG_MOVE: + start = Vector2(Math::lerp(node_pos_in_parent[0], node_pos_in_parent[2], ratio), node_pos_in_parent[1]); + end = start - Vector2(0, control->get_margin(MARGIN_TOP)); + _draw_margin_at_position(control->get_margin(MARGIN_TOP), parent_transform.xform((start + end) / 2), MARGIN_LEFT); + viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); + break; + default: + break; + } + switch (drag_type) { + case DRAG_BOTTOM: + case DRAG_BOTTOM_LEFT: + case DRAG_BOTTOM_RIGHT: + _draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2) + Vector2(5, 0)), MARGIN_RIGHT); + case DRAG_MOVE: + start = Vector2(Math::lerp(node_pos_in_parent[2], node_pos_in_parent[0], ratio), node_pos_in_parent[3]); + end = start - Vector2(0, control->get_margin(MARGIN_BOTTOM)); + _draw_margin_at_position(control->get_margin(MARGIN_BOTTOM), parent_transform.xform((start + end) / 2), MARGIN_RIGHT); + viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); + break; + default: + break; + } + + switch (drag_type) { + //Draw the ghost rect if the node if rotated/scaled + case DRAG_LEFT: + case DRAG_TOP_LEFT: + case DRAG_TOP: + case DRAG_TOP_RIGHT: + case DRAG_RIGHT: + case DRAG_BOTTOM_RIGHT: + case DRAG_BOTTOM: + case DRAG_BOTTOM_LEFT: + case DRAG_MOVE: + if (control->get_rotation() != 0.0 || control->get_scale() != Vector2(1, 1)) { + Rect2 rect = Rect2(Vector2(node_pos_in_parent[0], node_pos_in_parent[1]), control->get_size()); + viewport->draw_rect(parent_transform.xform(rect), color_base, false); + } + break; + default: + break; + } + } +} + void CanvasItemEditor::_draw_selection() { Ref<Texture> pivot_icon = get_icon("EditorPivot", "EditorIcons"); Ref<Texture> position_icon = get_icon("EditorPosition", "EditorIcons"); @@ -2346,199 +2615,26 @@ void CanvasItemEditor::_draw_selection() { } } else { - Transform2D transform = Transform2D(xform.get_rotation(), xform.get_origin()); - viewport->draw_set_transform_matrix(transform); + Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + viewport->draw_set_transform_matrix(simple_xform); viewport->draw_texture(position_icon, -(position_icon->get_size() / 2)); - viewport->draw_set_transform_matrix(Transform2D()); + viewport->draw_set_transform_matrix(viewport->get_transform()); } - if (single && (tool == TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_ROTATE || tool == TOOL_EDIT_PIVOT)) { //kind of sucks + if (single && (tool == TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_SCALE || tool == TOOL_ROTATE || tool == TOOL_EDIT_PIVOT)) { //kind of sucks // Draw the pivot if (canvas_item->_edit_get_pivot() != Vector2() || drag_type == DRAG_PIVOT || tool == TOOL_EDIT_PIVOT) { // This is not really clean :/ viewport->draw_texture(pivot_icon, (xform.xform(canvas_item->_edit_get_pivot()) - (pivot_icon->get_size() / 2)).floor()); } + // Draw control-related helpers Control *control = Object::cast_to<Control>(canvas_item); if (control) { - if (tool == TOOL_SELECT && show_helpers && !Object::cast_to<Container>(control->get_parent())) { - // Draw the helpers - Color color_base = Color(0.8, 0.8, 0.8, 0.5); - - float anchors_values[4]; - anchors_values[0] = control->get_anchor(MARGIN_LEFT); - anchors_values[1] = control->get_anchor(MARGIN_TOP); - anchors_values[2] = control->get_anchor(MARGIN_RIGHT); - anchors_values[3] = control->get_anchor(MARGIN_BOTTOM); - - // Draw the anchors - Vector2 anchors[4]; - Vector2 anchors_pos[4]; - for (int i = 0; i < 4; i++) { - anchors[i] = Vector2((i % 2 == 0) ? anchors_values[i] : anchors_values[(i + 1) % 4], (i % 2 == 1) ? anchors_values[i] : anchors_values[(i + 1) % 4]); - anchors_pos[i] = xform.xform(_anchor_to_position(control, anchors[i])); - } - - // Get which anchor is dragged - int dragged_anchor = -1; - switch (drag_type) { - case DRAG_ANCHOR_ALL: - case DRAG_ANCHOR_TOP_LEFT: - dragged_anchor = 0; - break; - case DRAG_ANCHOR_TOP_RIGHT: - dragged_anchor = 1; - break; - case DRAG_ANCHOR_BOTTOM_RIGHT: - dragged_anchor = 2; - break; - case DRAG_ANCHOR_BOTTOM_LEFT: - dragged_anchor = 3; - break; - default: - break; - } - - if (dragged_anchor >= 0) { - // Draw the 4 lines when dragged - bool snapped; - Color color_snapped = Color(0.64, 0.93, 0.67, 0.5); - - Vector2 corners_pos[4]; - for (int i = 0; i < 4; i++) { - corners_pos[i] = xform.xform(_anchor_to_position(control, Vector2((i == 0 || i == 3) ? ANCHOR_BEGIN : ANCHOR_END, (i <= 1) ? ANCHOR_BEGIN : ANCHOR_END))); - } - - Vector2 line_starts[4]; - Vector2 line_ends[4]; - for (int i = 0; i < 4; i++) { - float anchor_val = (i >= 2) ? ANCHOR_END - anchors_values[i] : anchors_values[i]; - line_starts[i] = Vector2::linear_interpolate(corners_pos[i], corners_pos[(i + 1) % 4], anchor_val); - line_ends[i] = Vector2::linear_interpolate(corners_pos[(i + 3) % 4], corners_pos[(i + 2) % 4], anchor_val); - snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; - viewport->draw_line(line_starts[i], line_ends[i], snapped ? color_snapped : color_base, (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) ? 2 : 1); - } - - // Display the percentages next to the lines - float percent_val; - percent_val = anchors_values[(dragged_anchor + 2) % 4] - anchors_values[dragged_anchor]; - percent_val = (dragged_anchor >= 2) ? -percent_val : percent_val; - _draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 1) % 4]) / 2, (Margin)((dragged_anchor + 1) % 4)); - - percent_val = anchors_values[(dragged_anchor + 3) % 4] - anchors_values[(dragged_anchor + 1) % 4]; - percent_val = ((dragged_anchor + 1) % 4 >= 2) ? -percent_val : percent_val; - _draw_percentage_at_position(percent_val, (anchors_pos[dragged_anchor] + anchors_pos[(dragged_anchor + 3) % 4]) / 2, (Margin)(dragged_anchor)); - - percent_val = anchors_values[(dragged_anchor + 1) % 4]; - percent_val = ((dragged_anchor + 1) % 4 >= 2) ? ANCHOR_END - percent_val : percent_val; - _draw_percentage_at_position(percent_val, (line_starts[dragged_anchor] + anchors_pos[dragged_anchor]) / 2, (Margin)(dragged_anchor)); - - percent_val = anchors_values[dragged_anchor]; - percent_val = (dragged_anchor >= 2) ? ANCHOR_END - percent_val : percent_val; - _draw_percentage_at_position(percent_val, (line_ends[(dragged_anchor + 1) % 4] + anchors_pos[dragged_anchor]) / 2, (Margin)((dragged_anchor + 1) % 4)); - } - - Rect2 anchor_rects[4]; - anchor_rects[0] = Rect2(anchors_pos[0] - anchor_handle->get_size(), anchor_handle->get_size()); - anchor_rects[1] = Rect2(anchors_pos[1] - Vector2(0.0, anchor_handle->get_size().y), Point2(-anchor_handle->get_size().x, anchor_handle->get_size().y)); - anchor_rects[2] = Rect2(anchors_pos[2], -anchor_handle->get_size()); - anchor_rects[3] = Rect2(anchors_pos[3] - Vector2(anchor_handle->get_size().x, 0.0), Point2(anchor_handle->get_size().x, -anchor_handle->get_size().y)); - - for (int i = 0; i < 4; i++) { - anchor_handle->draw_rect(ci, anchor_rects[i]); - } - - // Draw the margin values and the node width/height when dragging control side - float ratio = 0.33; - Transform2D parent_transform = xform * control->get_transform().affine_inverse(); - float node_pos_in_parent[4]; - - Rect2 parent_rect = control->get_parent_anchorable_rect(); - - node_pos_in_parent[0] = control->get_anchor(MARGIN_LEFT) * parent_rect.size.width + control->get_margin(MARGIN_LEFT) + parent_rect.position.x; - node_pos_in_parent[1] = control->get_anchor(MARGIN_TOP) * parent_rect.size.height + control->get_margin(MARGIN_TOP) + parent_rect.position.y; - node_pos_in_parent[2] = control->get_anchor(MARGIN_RIGHT) * parent_rect.size.width + control->get_margin(MARGIN_RIGHT) + parent_rect.position.x; - node_pos_in_parent[3] = control->get_anchor(MARGIN_BOTTOM) * parent_rect.size.height + control->get_margin(MARGIN_BOTTOM) + parent_rect.position.y; - - Point2 start, end; - switch (drag_type) { - case DRAG_LEFT: - case DRAG_TOP_LEFT: - case DRAG_BOTTOM_LEFT: - _draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM); - case DRAG_MOVE: - start = Vector2(node_pos_in_parent[0], Math::lerp(node_pos_in_parent[1], node_pos_in_parent[3], ratio)); - end = start - Vector2(control->get_margin(MARGIN_LEFT), 0); - _draw_margin_at_position(control->get_margin(MARGIN_LEFT), parent_transform.xform((start + end) / 2), MARGIN_TOP); - viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); - break; - default: - break; - } - switch (drag_type) { - case DRAG_RIGHT: - case DRAG_TOP_RIGHT: - case DRAG_BOTTOM_RIGHT: - _draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM); - case DRAG_MOVE: - start = Vector2(node_pos_in_parent[2], Math::lerp(node_pos_in_parent[3], node_pos_in_parent[1], ratio)); - end = start - Vector2(control->get_margin(MARGIN_RIGHT), 0); - _draw_margin_at_position(control->get_margin(MARGIN_RIGHT), parent_transform.xform((start + end) / 2), MARGIN_BOTTOM); - viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); - break; - default: - break; - } - switch (drag_type) { - case DRAG_TOP: - case DRAG_TOP_LEFT: - case DRAG_TOP_RIGHT: - _draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2)) + Vector2(5, 0), MARGIN_RIGHT); - case DRAG_MOVE: - start = Vector2(Math::lerp(node_pos_in_parent[0], node_pos_in_parent[2], ratio), node_pos_in_parent[1]); - end = start - Vector2(0, control->get_margin(MARGIN_TOP)); - _draw_margin_at_position(control->get_margin(MARGIN_TOP), parent_transform.xform((start + end) / 2), MARGIN_LEFT); - viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); - break; - default: - break; - } - switch (drag_type) { - case DRAG_BOTTOM: - case DRAG_BOTTOM_LEFT: - case DRAG_BOTTOM_RIGHT: - _draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2) + Vector2(5, 0)), MARGIN_RIGHT); - case DRAG_MOVE: - start = Vector2(Math::lerp(node_pos_in_parent[2], node_pos_in_parent[0], ratio), node_pos_in_parent[3]); - end = start - Vector2(0, control->get_margin(MARGIN_BOTTOM)); - _draw_margin_at_position(control->get_margin(MARGIN_BOTTOM), parent_transform.xform((start + end) / 2), MARGIN_RIGHT); - viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1); - break; - default: - break; - } - - switch (drag_type) { - //Draw the ghost rect if the node if rotated/scaled - case DRAG_LEFT: - case DRAG_TOP_LEFT: - case DRAG_TOP: - case DRAG_TOP_RIGHT: - case DRAG_RIGHT: - case DRAG_BOTTOM_RIGHT: - case DRAG_BOTTOM: - case DRAG_BOTTOM_LEFT: - case DRAG_MOVE: - if (control->get_rotation() != 0.0 || control->get_scale() != Vector2(1, 1)) { - Rect2 rect = Rect2(Vector2(node_pos_in_parent[0], node_pos_in_parent[1]), control->get_size()); - viewport->draw_rect(parent_transform.xform(rect), color_base, false); - } - break; - default: - break; - } - } + _draw_control_helpers(control); } + // Draw the resize handles if (tool == TOOL_SELECT && canvas_item->_edit_use_rect()) { Rect2 rect = canvas_item->_edit_get_rect(); Vector2 endpoints[4] = { @@ -2548,7 +2644,6 @@ void CanvasItemEditor::_draw_selection() { xform.xform(rect.position + Vector2(0, rect.size.y)) }; for (int i = 0; i < 4; i++) { - // Draw the resize handles int prev = (i + 3) % 4; int next = (i + 1) % 4; @@ -2563,6 +2658,46 @@ void CanvasItemEditor::_draw_selection() { select_handle->draw(ci, (ofs - (select_handle->get_size() / 2)).floor()); } } + + // Draw the rescale handles + bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CONTROL); + bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT); + if ((is_alt && is_ctrl) || tool == TOOL_SCALE || drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) { + + Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + + Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); + bool uniform = Input::get_singleton()->is_key_pressed(KEY_SHIFT); + Point2 offset = (simple_xform.affine_inverse().xform(drag_to) - simple_xform.affine_inverse().xform(drag_from)) * zoom; + + if (drag_type == DRAG_SCALE_X) { + scale_factor.x += offset.x; + if (uniform) { + scale_factor.y += offset.x; + } + } else if (drag_type == DRAG_SCALE_Y) { + scale_factor.y -= offset.y; + if (uniform) { + scale_factor.x -= offset.y; + } + } + + //scale_factor *= zoom; + + viewport->draw_set_transform_matrix(simple_xform); + Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + Color x_axis_color(1.0, 0.4, 0.4, 0.6); + viewport->draw_rect(x_handle_rect, x_axis_color); + viewport->draw_line(Point2(), Point2(scale_factor.x * EDSCALE, 0), x_axis_color); + + Rect2 y_handle_rect = Rect2(-5 * EDSCALE, -(scale_factor.y + 10) * EDSCALE, 10 * EDSCALE, 10 * EDSCALE); + Color y_axis_color(0.4, 1.0, 0.4, 0.6); + viewport->draw_rect(y_handle_rect, y_axis_color); + viewport->draw_line(Point2(), Point2(0, -scale_factor.y * EDSCALE), y_axis_color); + + viewport->draw_set_transform_matrix(viewport->get_transform()); + } } } @@ -2737,15 +2872,16 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans _draw_invisible_nodes_positions(p_node->get_child(i), parent_xform, canvas_xform); } - if (canvas_item && !canvas_item->_edit_use_rect() && (!editor_selection->is_selected(canvas_item) || canvas_item->get_meta("_edit_lock_"))) { + if (canvas_item && !canvas_item->_edit_use_rect() && (!editor_selection->is_selected(canvas_item) || (canvas_item->has_meta("_edit_lock_") && canvas_item->get_meta("_edit_lock_")))) { Transform2D xform = transform * canvas_xform * parent_xform; // Draw the node's position Ref<Texture> position_icon = get_icon("EditorPositionUnselected", "EditorIcons"); - Transform2D transform = Transform2D(xform.get_rotation(), xform.get_origin()); - viewport->draw_set_transform_matrix(transform); + Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized(); + Transform2D simple_xform = viewport->get_transform() * unscaled_transform; + viewport->draw_set_transform_matrix(simple_xform); viewport->draw_texture(position_icon, -position_icon->get_size() / 2, Color(1.0, 1.0, 1.0, 0.5)); - viewport->draw_set_transform_matrix(Transform2D()); + viewport->draw_set_transform_matrix(viewport->get_transform()); } } @@ -3073,6 +3209,7 @@ void CanvasItemEditor::_notification(int p_what) { select_button->set_icon(get_icon("ToolSelect", "EditorIcons")); list_select_button->set_icon(get_icon("ListSelect", "EditorIcons")); move_button->set_icon(get_icon("ToolMove", "EditorIcons")); + scale_button->set_icon(get_icon("ToolScale", "EditorIcons")); rotate_button->set_icon(get_icon("ToolRotate", "EditorIcons")); snap_button->set_icon(get_icon("Snap", "EditorIcons")); snap_config_menu->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons")); @@ -3381,7 +3518,7 @@ void CanvasItemEditor::_button_toggle_snap(bool p_status) { void CanvasItemEditor::_button_tool_select(int p_index) { - ToolButton *tb[TOOL_MAX] = { select_button, list_select_button, move_button, rotate_button, pivot_button, pan_button }; + ToolButton *tb[TOOL_MAX] = { select_button, list_select_button, move_button, scale_button, rotate_button, pivot_button, pan_button }; for (int i = 0; i < TOOL_MAX; i++) { tb[i]->set_pressed(i == p_index); } @@ -4273,6 +4410,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { select_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/select_mode", TTR("Select Mode"), KEY_Q)); select_button->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate") + "\n" + TTR("Alt+Drag: Move") + "\n" + TTR("Press 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).") + "\n" + TTR("Alt+RMB: Depth list selection")); + hb->add_child(memnew(VSeparator)); + move_button = memnew(ToolButton); hb->add_child(move_button); move_button->set_toggle_mode(true); @@ -4280,6 +4419,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { move_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/move_mode", TTR("Move Mode"), KEY_W)); move_button->set_tooltip(TTR("Move Mode")); + scale_button = memnew(ToolButton); + hb->add_child(scale_button); + scale_button->set_toggle_mode(true); + scale_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_SCALE)); + scale_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/scale_mode", TTR("Scale Mode"), KEY_S)); + scale_button->set_tooltip(TTR("Scale Mode")); + rotate_button = memnew(ToolButton); hb->add_child(rotate_button); rotate_button->set_toggle_mode(true); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index dd6c94eb60..61d77581d3 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -77,6 +77,7 @@ class CanvasItemEditor : public VBoxContainer { TOOL_SELECT, TOOL_LIST_SELECT, TOOL_MOVE, + TOOL_SCALE, TOOL_ROTATE, TOOL_EDIT_PIVOT, TOOL_PAN, @@ -189,6 +190,8 @@ class CanvasItemEditor : public VBoxContainer { DRAG_ANCHOR_BOTTOM_LEFT, DRAG_ANCHOR_ALL, DRAG_MOVE, + DRAG_SCALE_X, + DRAG_SCALE_Y, DRAG_ROTATE, DRAG_PIVOT, DRAG_V_GUIDE, @@ -298,17 +301,19 @@ class CanvasItemEditor : public VBoxContainer { List<PoseClipboard> pose_clipboard; ToolButton *select_button; - ToolButton *list_select_button; + ToolButton *move_button; + ToolButton *scale_button; ToolButton *rotate_button; + ToolButton *list_select_button; + ToolButton *pivot_button; + ToolButton *pan_button; + ToolButton *snap_button; MenuButton *snap_config_menu; PopupMenu *smartsnap_config_popup; - ToolButton *pivot_button; - ToolButton *pan_button; - ToolButton *lock_button; ToolButton *unlock_button; @@ -408,6 +413,7 @@ class CanvasItemEditor : public VBoxContainer { void _draw_guides(); void _draw_focus(); void _draw_grid(); + void _draw_control_helpers(Control *control); void _draw_selection(); void _draw_axis(); void _draw_bones(); @@ -420,6 +426,7 @@ class CanvasItemEditor : public VBoxContainer { bool _gui_input_anchors(const Ref<InputEvent> &p_event); bool _gui_input_move(const Ref<InputEvent> &p_event); bool _gui_input_open_scene_on_double_click(const Ref<InputEvent> &p_event); + bool _gui_input_scale(const Ref<InputEvent> &p_event); bool _gui_input_pivot(const Ref<InputEvent> &p_event); bool _gui_input_resize(const Ref<InputEvent> &p_event); bool _gui_input_rotate(const Ref<InputEvent> &p_event); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 706bda4089..f25ca4786e 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -946,7 +946,7 @@ void ScriptEditor::_menu_option(int p_option) { switch (p_option) { case FILE_NEW: { - script_create_dialog->config("Node", ".gd"); + script_create_dialog->config("Node", "new_script"); script_create_dialog->popup_centered(Size2(300, 300) * EDSCALE); } break; case FILE_NEW_TEXTFILE: { @@ -1749,7 +1749,7 @@ void ScriptEditor::_update_script_names() { } break; case DISPLAY_DIR_AND_NAME: { if (!path.get_base_dir().get_file().empty()) { - sd.name = path.get_base_dir().get_file() + "/" + name; + sd.name = path.get_base_dir().get_file().plus_file(name); } else { sd.name = name; } @@ -2114,8 +2114,6 @@ void ScriptEditor::_editor_play() { debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), true); debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), false); debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true); - - //debugger_gui->start_listening(Globals::get_singleton()->get("debug/debug_port")); } void ScriptEditor::_editor_pause() { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 5f2841d2c0..9461f39aeb 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -224,7 +224,7 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node String new_name = parent->validate_child_name(instanced_scene); ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); editor_data->get_undo_redo().add_do_method(sed, "live_debug_instance_node", edited_scene->get_path_to(parent), p_files[i], new_name); - editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)) + "/" + new_name)); + editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).plus_file(new_name))); } editor_data->get_undo_redo().commit_action(); @@ -354,9 +354,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (path == "") { String root_path = editor_data->get_edited_scene_root()->get_filename(); if (root_path == "") { - path = "res://" + selected->get_name(); + path = String("res://").plus_file(selected->get_name()); } else { - path = root_path.get_base_dir() + "/" + selected->get_name(); + path = root_path.get_base_dir().plus_file(selected->get_name()); } } @@ -535,7 +535,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); editor_data->get_undo_redo().add_do_method(sed, "live_debug_duplicate_node", edited_scene->get_path_to(node), dup->get_name()); - editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)) + "/" + dup->get_name())); + editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).plus_file(dup->get_name()))); } editor_data->get_undo_redo().commit_action(); @@ -1429,7 +1429,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V } editor_data->get_undo_redo().add_do_method(sed, "live_debug_reparent_node", edited_scene->get_path_to(node), edited_scene->get_path_to(new_parent), new_name, p_position_in_parent + inc); - editor_data->get_undo_redo().add_undo_method(sed, "live_debug_reparent_node", NodePath(String(edited_scene->get_path_to(new_parent)) + "/" + new_name), edited_scene->get_path_to(node->get_parent()), node->get_name(), node->get_index()); + editor_data->get_undo_redo().add_undo_method(sed, "live_debug_reparent_node", NodePath(String(edited_scene->get_path_to(new_parent)).plus_file(new_name)), edited_scene->get_path_to(node->get_parent()), node->get_name(), node->get_index()); if (p_keep_global_xform) { if (Object::cast_to<Node2D>(node)) @@ -1661,7 +1661,7 @@ void SceneTreeDock::_create() { String new_name = parent->validate_child_name(child); ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); editor_data->get_undo_redo().add_do_method(sed, "live_debug_create_node", edited_scene->get_path_to(parent), child->get_class(), new_name); - editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)) + "/" + new_name)); + editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).plus_file(new_name))); } else { diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 8c36a71d71..be255ba4aa 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -56,6 +56,7 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_ class_name->deselect(); parent_name->set_text(p_base_name); parent_name->deselect(); + if (p_base_path != "") { initial_bp = p_base_path.get_basename(); file_path->set_text(initial_bp + "." + ScriptServer::get_language(language_menu->get_selected())->get_extension()); @@ -359,7 +360,7 @@ void ScriptCreateDialog::_path_changed(const String &p_path) { is_path_valid = false; is_new_script_created = true; - String p = p_path; + String p = p_path.strip_edges(); if (p == "") { _msg_path_valid(false, TTR("Path is empty")); @@ -367,6 +368,12 @@ void ScriptCreateDialog::_path_changed(const String &p_path) { return; } + if (p.get_file().get_basename() == "") { + _msg_path_valid(false, TTR("Filename is empty")); + _update_dialog(); + return; + } + p = ProjectSettings::get_singleton()->localize_path(p); if (!p.begins_with("res://")) { _msg_path_valid(false, TTR("Path is not local")); @@ -443,12 +450,6 @@ void ScriptCreateDialog::_path_changed(const String &p_path) { return; } - if (p.get_file().get_basename() == "") { - _msg_path_valid(false, TTR("Filename is empty")); - _update_dialog(); - return; - } - /* All checks passed */ is_path_valid = true; diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index b43402e834..c07220d42c 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -711,27 +711,65 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da bool warning = err[9]; bool e; String time = String("%d:%02d:%02d:%04d").sprintf(vals, &e); - String txt = time + " - " + (err[8].is_zero() ? String(err[7]) : String(err[8])); + String txt = err[8].is_zero() ? String(err[7]) : String(err[8]); - String tooltip = TTR("Type:") + String(warning ? TTR("Warning") : TTR("Error")); - tooltip += "\n" + TTR("Description:") + " " + String(err[8]); - tooltip += "\n" + TTR("Time:") + " " + time; - tooltip += "\nC " + TTR("Error:") + " " + String(err[7]); - tooltip += "\nC " + TTR("Source:") + " " + String(err[5]) + ":" + String(err[6]); - tooltip += "\nC " + TTR("Function:") + " " + String(err[4]); + TreeItem *r = error_tree->get_root(); + if (!r) { + r = error_tree->create_item(); + } - error_list->add_item(txt, EditorNode::get_singleton()->get_gui_base()->get_icon(warning ? "Warning" : "Error", "EditorIcons")); - error_list->set_item_tooltip(error_list->get_item_count() - 1, tooltip); + TreeItem *error = error_tree->create_item(r); + error->set_collapsed(true); - int scc = p_data[1]; + error->set_icon(0, get_icon(warning ? "Warning" : "Error", "EditorIcons")); + error->set_text(0, time); + error->set_text_align(0, TreeItem::ALIGN_LEFT); + + error->set_text(1, txt); + + String source(err[5]); + bool source_is_project_file = source.begins_with("res://"); + if (source_is_project_file) + source = source.get_file(); + + txt = source + ":" + String(err[6]); + String method = err[4]; + if (method.length() > 0) + txt += " @ " + method + "()"; - Array stack; - stack.resize(scc); - for (int i = 0; i < scc; i++) { - stack[i] = p_data[2 + i]; + TreeItem *c_info = error_tree->create_item(error); + c_info->set_text(0, "<" + TTR(source_is_project_file ? "Source" : "C Source") + ">"); + c_info->set_text(1, txt); + c_info->set_text_align(0, TreeItem::ALIGN_LEFT); + + if (source_is_project_file) { + Array meta; + meta.push_back(source); + meta.push_back(err[6]); + error->set_metadata(0, meta); + c_info->set_metadata(0, meta); } - error_list->set_item_metadata(error_list->get_item_count() - 1, stack); + int scc = p_data[1]; + + for (int i = 0; i < scc; i += 3) { + String script = p_data[2 + i]; + String method = p_data[3 + i]; + int line = p_data[4 + i]; + TreeItem *stack_trace = error_tree->create_item(error); + + Array meta; + meta.push_back(script); + meta.push_back(line); + stack_trace->set_metadata(0, meta); + + if (i == 0) { + stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">"); + stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT); + error->set_metadata(0, meta); + } + stack_trace->set_text(1, script.get_file() + ":" + itos(line) + " @ " + method + "()"); + } if (warning) warning_count++; @@ -969,8 +1007,8 @@ void ScriptEditorDebugger::_notification(int p_what) { //scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons")); le_set->connect("pressed", this, "_live_edit_set"); le_clear->connect("pressed", this, "_live_edit_clear"); - error_list->connect("item_selected", this, "_error_selected"); - error_stack->connect("item_selected", this, "_error_stack_selected"); + error_tree->connect("item_selected", this, "_error_selected"); + error_tree->connect("item_activated", this, "_error_activated"); vmem_refresh->set_icon(get_icon("Reload", "EditorIcons")); reason->add_color_override("font_color", get_color("error_color", "Editor")); @@ -1016,19 +1054,19 @@ void ScriptEditorDebugger::_notification(int p_what) { if (error_count != last_error_count || warning_count != last_warning_count) { if (error_count == 0 && warning_count == 0) { - error_split->set_name(TTR("Errors")); + error_tree->set_name(TTR("Errors")); debugger_button->set_text(TTR("Debugger")); debugger_button->set_icon(Ref<Texture>()); - tabs->set_tab_icon(error_split->get_index(), Ref<Texture>()); + tabs->set_tab_icon(error_tree->get_index(), Ref<Texture>()); } else { - error_split->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")"); + error_tree->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")"); debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")"); if (error_count == 0) { debugger_button->set_icon(get_icon("Warning", "EditorIcons")); - tabs->set_tab_icon(error_split->get_index(), get_icon("Warning", "EditorIcons")); + tabs->set_tab_icon(error_tree->get_index(), get_icon("Warning", "EditorIcons")); } else { debugger_button->set_icon(get_icon("Error", "EditorIcons")); - tabs->set_tab_icon(error_split->get_index(), get_icon("Error", "EditorIcons")); + tabs->set_tab_icon(error_tree->get_index(), get_icon("Error", "EditorIcons")); } } last_error_count = error_count; @@ -1059,8 +1097,7 @@ void ScriptEditorDebugger::_notification(int p_what) { inspect_scene_tree->clear(); le_set->set_disabled(true); le_clear->set_disabled(false); - error_list->clear(); - error_stack->clear(); + error_tree->clear(); error_count = 0; warning_count = 0; profiler_signature.clear(); @@ -1658,45 +1695,26 @@ void ScriptEditorDebugger::reload_scripts() { } } -void ScriptEditorDebugger::_error_selected(int p_idx) { - - error_stack->clear(); - Array st = error_list->get_item_metadata(p_idx); - for (int i = 0; i < st.size(); i += 3) { - - String script = st[i]; - String func = st[i + 1]; - int line = st[i + 2]; - Array md; - md.push_back(st[i]); - md.push_back(st[i + 1]); - md.push_back(st[i + 2]); - - String str = func; - String tooltip_str = TTR("Function:") + " " + func; - if (script.length() > 0) { - str += " in " + script.get_file(); - tooltip_str = TTR("File:") + " " + script + "\n" + tooltip_str; - if (line > 0) { - str += ":line " + itos(line); - tooltip_str += "\n" + TTR("Line:") + " " + itos(line); - } - } +void ScriptEditorDebugger::_error_activated() { + TreeItem *selected = error_tree->get_selected(); - error_stack->add_item(str); - error_stack->set_item_metadata(error_stack->get_item_count() - 1, md); - error_stack->set_item_tooltip(error_stack->get_item_count() - 1, tooltip_str); + TreeItem *ci = selected->get_children(); + if (ci) { + selected->set_collapsed(!selected->is_collapsed()); } } -void ScriptEditorDebugger::_error_stack_selected(int p_idx) { +void ScriptEditorDebugger::_error_selected() { + TreeItem *selected = error_tree->get_selected(); - Array arr = error_stack->get_item_metadata(p_idx); - if (arr.size() != 3) + Array meta = selected->get_metadata(0); + + if (meta.size() == 0) { return; + } - Ref<Script> s = ResourceLoader::load(arr[0]); - emit_signal("goto_script_line", s, int(arr[2]) - 1); + Ref<Script> s = ResourceLoader::load(meta[0]); + emit_signal("goto_script_line", s, int(meta[1]) - 1); } void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) { @@ -1753,27 +1771,24 @@ void ScriptEditorDebugger::_clear_remote_objects() { void ScriptEditorDebugger::_clear_errors_list() { - error_list->clear(); + error_tree->clear(); error_count = 0; warning_count = 0; _notification(NOTIFICATION_PROCESS); } // Right click on specific file(s) or folder(s). -void ScriptEditorDebugger::_error_list_item_rmb_selected(int p_item, const Vector2 &p_pos) { +void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) { item_menu->clear(); item_menu->set_size(Size2(1, 1)); - // Allow specific actions only on one item. - bool single_item_selected = error_list->get_selected_items().size() == 1; - - if (single_item_selected) { + if (error_tree->is_anything_selected()) { item_menu->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), ITEM_MENU_COPY_ERROR); } if (item_menu->get_item_count() > 0) { - item_menu->set_position(error_list->get_global_position() + p_pos); + item_menu->set_position(error_tree->get_global_position() + p_pos); item_menu->popup(); } } @@ -1783,10 +1798,30 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { switch (p_option) { case ITEM_MENU_COPY_ERROR: { - String title = error_list->get_item_text(error_list->get_current()); - String desc = error_list->get_item_tooltip(error_list->get_current()); + TreeItem *ti = error_tree->get_selected(); + while (ti->get_parent() != error_tree->get_root()) + ti = ti->get_parent(); + + String type; + + if (ti->get_icon(0) == get_icon("Warning", "EditorIcons")) { + type = "W "; + } else if (ti->get_icon(0) == get_icon("Error", "EditorIcons")) { + type = "E "; + } + + String text = ti->get_text(0) + " "; + int rpad_len = text.length(); + + text = type + text + ti->get_text(1) + "\n"; + TreeItem *ci = ti->get_children(); + while (ci) { + text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n"; + ci = ci->get_next(); + } + + OS::get_singleton()->set_clipboard(text); - OS::get_singleton()->set_clipboard(title + "\n----------\n" + desc); } break; case ITEM_MENU_SAVE_REMOTE_NODE: { @@ -1825,12 +1860,12 @@ void ScriptEditorDebugger::_bind_methods() { ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear); ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected); - ClassDB::bind_method(D_METHOD("_error_stack_selected"), &ScriptEditorDebugger::_error_stack_selected); + ClassDB::bind_method(D_METHOD("_error_activated"), &ScriptEditorDebugger::_error_activated); ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate); ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked); ClassDB::bind_method(D_METHOD("_clear_errors_list"), &ScriptEditorDebugger::_clear_errors_list); - ClassDB::bind_method(D_METHOD("_error_list_item_rmb_selected"), &ScriptEditorDebugger::_error_list_item_rmb_selected); + ClassDB::bind_method(D_METHOD("_error_tree_item_rmb_selected"), &ScriptEditorDebugger::_error_tree_item_rmb_selected); ClassDB::bind_method(D_METHOD("_item_menu_id_pressed"), &ScriptEditorDebugger::_item_menu_id_pressed); ClassDB::bind_method(D_METHOD("_paused"), &ScriptEditorDebugger::_paused); @@ -1964,44 +1999,35 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { } { //errors - - error_split = memnew(HSplitContainer); - VBoxContainer *errvb = memnew(VBoxContainer); HBoxContainer *errhb = memnew(HBoxContainer); - errvb->set_h_size_flags(SIZE_EXPAND_FILL); - Label *velb = memnew(Label(TTR("Errors:"))); - velb->set_h_size_flags(SIZE_EXPAND_FILL); - errhb->add_child(velb); + errhb->set_name(TTR("Errors")); - clearbutton = memnew(Button); - clearbutton->set_text(TTR("Clear")); - clearbutton->connect("pressed", this, "_clear_errors_list"); - errhb->add_child(clearbutton); - errvb->add_child(errhb); + error_tree = memnew(Tree); + error_tree->set_columns(2); - error_list = memnew(ItemList); - error_list->set_v_size_flags(SIZE_EXPAND_FILL); - error_list->set_h_size_flags(SIZE_EXPAND_FILL); - error_list->connect("item_rmb_selected", this, "_error_list_item_rmb_selected"); - error_list->set_allow_rmb_select(true); - error_list->set_autoscroll_to_bottom(true); + error_tree->set_column_expand(0, false); + error_tree->set_column_min_width(0, 140); - item_menu = memnew(PopupMenu); - item_menu->connect("id_pressed", this, "_item_menu_id_pressed"); - error_list->add_child(item_menu); + error_tree->set_column_expand(1, true); - errvb->add_child(error_list); + error_tree->set_select_mode(Tree::SELECT_ROW); + error_tree->set_hide_root(true); + error_tree->set_h_size_flags(SIZE_EXPAND_FILL); + error_tree->set_allow_rmb_select(true); + error_tree->connect("item_rmb_selected", this, "_error_tree_item_rmb_selected"); + errhb->add_child(error_tree); - error_split->add_child(errvb); + item_menu = memnew(PopupMenu); + item_menu->connect("id_pressed", this, "_item_menu_id_pressed"); + error_tree->add_child(item_menu); - errvb = memnew(VBoxContainer); - errvb->set_h_size_flags(SIZE_EXPAND_FILL); - error_stack = memnew(ItemList); - errvb->add_margin_child(TTR("Stack Trace (if applicable):"), error_stack, true); - error_split->add_child(errvb); + clearbutton = memnew(Button); + clearbutton->set_text(TTR("Clear")); + clearbutton->set_v_size_flags(0); + clearbutton->connect("pressed", this, "_clear_errors_list"); + errhb->add_child(clearbutton); - error_split->set_name(TTR("Errors")); - tabs->add_child(error_split); + tabs->add_child(errhb); } { // remote scene tree diff --git a/editor/script_editor_debugger.h b/editor/script_editor_debugger.h index 9a5680e4b6..017619e56f 100644 --- a/editor/script_editor_debugger.h +++ b/editor/script_editor_debugger.h @@ -88,8 +88,7 @@ class ScriptEditorDebugger : public Control { Set<ObjectID> unfold_cache; HSplitContainer *error_split; - ItemList *error_list; - ItemList *error_stack; + Tree *error_tree; Tree *inspect_scene_tree; Button *clearbutton; PopupMenu *item_menu; @@ -179,8 +178,8 @@ class ScriptEditorDebugger : public Control { void _method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE); void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value); - void _error_selected(int p_idx); - void _error_stack_selected(int p_idx); + void _error_activated(); + void _error_selected(); void _profiler_activate(bool p_enable); void _profiler_seeked(); @@ -191,7 +190,7 @@ class ScriptEditorDebugger : public Control { void _clear_remote_objects(); void _clear_errors_list(); - void _error_list_item_rmb_selected(int p_item, const Vector2 &p_pos); + void _error_tree_item_rmb_selected(const Vector2 &p_pos); void _item_menu_id_pressed(int p_option); protected: |