diff options
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/animation_player_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 2 | ||||
-rw-r--r-- | editor/plugins/collision_shape_2d_editor_plugin.cpp | 47 | ||||
-rw-r--r-- | editor/plugins/collision_shape_2d_editor_plugin.h | 1 | ||||
-rw-r--r-- | editor/plugins/node_3d_editor_gizmos.cpp | 62 | ||||
-rw-r--r-- | editor/plugins/node_3d_editor_plugin.cpp | 103 | ||||
-rw-r--r-- | editor/plugins/node_3d_editor_plugin.h | 6 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 4 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 136 | ||||
-rw-r--r-- | editor/plugins/shader_editor_plugin.cpp | 35 | ||||
-rw-r--r-- | editor/plugins/skeleton_3d_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/text_editor.cpp | 43 | ||||
-rw-r--r-- | editor/plugins/texture_region_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/theme_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/version_control_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 131 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.h | 8 |
18 files changed, 282 insertions, 308 deletions
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 681c3e7195..b4e9f468de 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1246,6 +1246,8 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { } accept_event(); } break; + default: + break; } } } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index da0359d729..76c056ed33 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -6159,7 +6159,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte editor = p_node; editor_data = editor->get_scene_tree_dock()->get_editor_data(); canvas_item_editor = p_canvas_item_editor; - preview_node = memnew(Node2D); + preview_node = memnew(Control); accept = memnew(AcceptDialog); editor->get_gui_base()->add_child(accept); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index f14e1e9657..bff580315e 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -651,7 +651,7 @@ class CanvasItemEditorViewport : public Control { EditorNode *editor; EditorData *editor_data; CanvasItemEditor *canvas_item_editor; - Node2D *preview_node; + Control *preview_node; AcceptDialog *accept; AcceptDialog *selector; Label *selector_label; diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index 2c2adc2672..4266e0f676 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -37,7 +37,6 @@ #include "scene/resources/concave_polygon_shape_2d.h" #include "scene/resources/convex_polygon_shape_2d.h" #include "scene/resources/line_shape_2d.h" -#include "scene/resources/ray_shape_2d.h" #include "scene/resources/rectangle_shape_2d.h" #include "scene/resources/segment_shape_2d.h" @@ -86,15 +85,6 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { } break; - case RAY_SHAPE: { - Ref<RayShape2D> ray = node->get_shape(); - - if (idx == 0) { - return ray->get_length(); - } - - } break; - case RECTANGLE_SHAPE: { Ref<RectangleShape2D> rect = node->get_shape(); @@ -130,7 +120,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { if (idx == 0) { capsule->set_radius(parameter); } else if (idx == 1) { - capsule->set_height(parameter * 2 - capsule->get_radius() * 2); + capsule->set_height(parameter * 2); } canvas_item_editor->update_viewport(); @@ -167,15 +157,6 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { } break; - case RAY_SHAPE: { - Ref<RayShape2D> ray = node->get_shape(); - - ray->set_length(Math::abs(p_point.y)); - - canvas_item_editor->update_viewport(); - - } break; - case RECTANGLE_SHAPE: { if (idx < 8) { Ref<RectangleShape2D> rect = node->get_shape(); @@ -277,16 +258,6 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { } break; - case RAY_SHAPE: { - Ref<RayShape2D> ray = node->get_shape(); - - undo_redo->add_do_method(ray.ptr(), "set_length", ray->get_length()); - undo_redo->add_do_method(canvas_item_editor, "update_viewport"); - undo_redo->add_undo_method(ray.ptr(), "set_length", p_org); - undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); - - } break; - case RECTANGLE_SHAPE: { Ref<RectangleShape2D> rect = node->get_shape(); @@ -428,8 +399,6 @@ void CollisionShape2DEditor::_get_current_shape_type() { shape_type = CONVEX_POLYGON_SHAPE; } else if (Object::cast_to<LineShape2D>(*s)) { shape_type = LINE_SHAPE; - } else if (Object::cast_to<RayShape2D>(*s)) { - shape_type = RAY_SHAPE; } else if (Object::cast_to<RectangleShape2D>(*s)) { shape_type = RECTANGLE_SHAPE; } else if (Object::cast_to<SegmentShape2D>(*s)) { @@ -471,8 +440,8 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla float radius = shape->get_radius(); float height = shape->get_height() / 2; - handles.write[0] = Point2(radius, height); - handles.write[1] = Point2(0, height + radius); + handles.write[0] = Point2(radius, 0); + handles.write[1] = Point2(0, height); p_overlay->draw_texture(h, gt.xform(handles[0]) - size); p_overlay->draw_texture(h, gt.xform(handles[1]) - size); @@ -507,16 +476,6 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla } break; - case RAY_SHAPE: { - Ref<RayShape2D> shape = node->get_shape(); - - handles.resize(1); - handles.write[0] = Point2(0, shape->get_length()); - - p_overlay->draw_texture(h, gt.xform(handles[0]) - size); - - } break; - case RECTANGLE_SHAPE: { Ref<RectangleShape2D> shape = node->get_shape(); diff --git a/editor/plugins/collision_shape_2d_editor_plugin.h b/editor/plugins/collision_shape_2d_editor_plugin.h index 7db6bd22aa..130ec708cf 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.h +++ b/editor/plugins/collision_shape_2d_editor_plugin.h @@ -47,7 +47,6 @@ class CollisionShape2DEditor : public Control { CONCAVE_POLYGON_SHAPE, CONVEX_POLYGON_SHAPE, LINE_SHAPE, - RAY_SHAPE, RECTANGLE_SHAPE, SEGMENT_SHAPE }; diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index b8cbaaf7c1..dcea7b26f3 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -66,7 +66,6 @@ #include "scene/resources/cylinder_shape_3d.h" #include "scene/resources/height_map_shape_3d.h" #include "scene/resources/primitive_meshes.h" -#include "scene/resources/ray_shape_3d.h" #include "scene/resources/sphere_shape_3d.h" #include "scene/resources/surface_tool.h" #include "scene/resources/world_margin_shape_3d.h" @@ -4081,10 +4080,6 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g return p_id == 0 ? "Radius" : "Height"; } - if (Object::cast_to<RayShape3D>(*s)) { - return "Length"; - } - return ""; } @@ -4116,11 +4111,6 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p return p_id == 0 ? cs2->get_radius() : cs2->get_height(); } - if (Object::cast_to<RayShape3D>(*s)) { - Ref<RayShape3D> cs2 = s; - return cs2->get_length(); - } - return Variant(); } @@ -4156,22 +4146,6 @@ void CollisionShape3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, i ss->set_radius(d); } - if (Object::cast_to<RayShape3D>(*s)) { - Ref<RayShape3D> rs = s; - Vector3 ra, rb; - Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(0, 0, 4096), sg[0], sg[1], ra, rb); - float d = ra.z; - if (Node3DEditor::get_singleton()->is_snap_enabled()) { - d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); - } - - if (d < 0.001) { - d = 0.001; - } - - rs->set_length(d); - } - if (Object::cast_to<BoxShape3D>(*s)) { Vector3 axis; axis[p_id] = 1.0; @@ -4194,14 +4168,11 @@ void CollisionShape3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, i if (Object::cast_to<CapsuleShape3D>(*s)) { Vector3 axis; - axis[p_id == 0 ? 0 : 2] = 1.0; + axis[p_id == 0 ? 0 : 1] = 1.0; Ref<CapsuleShape3D> cs2 = s; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb); float d = axis.dot(ra); - if (p_id == 1) { - d -= cs2->get_radius(); - } if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); @@ -4330,20 +4301,6 @@ void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo ur->commit_action(); } - - if (Object::cast_to<RayShape3D>(*s)) { - Ref<RayShape3D> ss = s; - if (p_cancel) { - ss->set_length(p_restore); - return; - } - - UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); - ur->create_action(TTR("Change Ray Shape Length")); - ur->add_do_method(ss.ptr(), "set_length", ss->get_length()); - ur->add_undo_method(ss.ptr(), "set_length", p_restore); - ur->commit_action(); - } } void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { @@ -4437,7 +4394,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Vector<Vector3> points; - Vector3 d(0, height * 0.5, 0); + Vector3 d(0, height * 0.5 - radius, 0); for (int i = 0; i < 360; i++) { float ra = Math::deg2rad((float)i); float rb = Math::deg2rad((float)i + 1); @@ -4496,7 +4453,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Vector<Vector3> handles; handles.push_back(Vector3(cs2->get_radius(), 0, 0)); - handles.push_back(Vector3(0, cs2->get_height() * 0.5 + cs2->get_radius(), 0)); + handles.push_back(Vector3(0, cs2->get_height() * 0.5, 0)); p_gizmo->add_handles(handles, handles_material); } @@ -4614,19 +4571,6 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_collision_segments(cs2->get_debug_mesh_lines()); } - if (Object::cast_to<RayShape3D>(*s)) { - Ref<RayShape3D> rs = s; - - Vector<Vector3> points; - points.push_back(Vector3()); - points.push_back(Vector3(0, 0, rs->get_length())); - p_gizmo->add_lines(points, material); - p_gizmo->add_collision_segments(points); - Vector<Vector3> handles; - handles.push_back(Vector3(0, 0, rs->get_length())); - p_gizmo->add_handles(handles, handles_material); - } - if (Object::cast_to<HeightMapShape3D>(*s)) { Ref<HeightMapShape3D> hms = s; diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 07962a5b4c..e9a67491aa 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -2457,7 +2457,7 @@ static bool is_shortcut_pressed(const String &p_path) { return false; } const Input &input = *Input::get_singleton(); - int keycode = k->get_keycode(); + Key keycode = k->get_keycode(); return input.is_key_pressed(keycode); } @@ -5508,6 +5508,12 @@ void Node3DEditor::_init_indicators() { Vector<Color> origin_colors; Vector<Vector3> origin_points; + const int count_of_elements = 3 * 6; + origin_colors.resize(count_of_elements); + origin_points.resize(count_of_elements); + + int x = 0; + for (int i = 0; i < 3; i++) { Vector3 axis; axis[i] = 1; @@ -5530,21 +5536,22 @@ void Node3DEditor::_init_indicators() { grid_enable[i] = false; grid_visible[i] = false; - origin_colors.push_back(origin_color); - origin_colors.push_back(origin_color); - origin_colors.push_back(origin_color); - origin_colors.push_back(origin_color); - origin_colors.push_back(origin_color); - origin_colors.push_back(origin_color); + origin_colors.set(x, origin_color); + origin_colors.set(x + 1, origin_color); + origin_colors.set(x + 2, origin_color); + origin_colors.set(x + 3, origin_color); + origin_colors.set(x + 4, origin_color); + origin_colors.set(x + 5, origin_color); // To both allow having a large origin size and avoid jitter // at small scales, we should segment the line into pieces. // 3 pieces seems to do the trick, and let's use powers of 2. - origin_points.push_back(axis * 1048576); - origin_points.push_back(axis * 1024); - origin_points.push_back(axis * 1024); - origin_points.push_back(axis * -1024); - origin_points.push_back(axis * -1024); - origin_points.push_back(axis * -1048576); + origin_points.set(x, axis * 1048576); + origin_points.set(x + 1, axis * 1024); + origin_points.set(x + 2, axis * 1024); + origin_points.set(x + 3, axis * -1024); + origin_points.set(x + 4, axis * -1024); + origin_points.set(x + 5, axis * -1048576); + x += 6; } Ref<Shader> grid_shader = memnew(Shader); @@ -6121,6 +6128,32 @@ void Node3DEditor::_init_grid() { grid_mat[c]->set_shader_param("grid_size", grid_fade_size); grid_mat[c]->set_shader_param("orthogonal", orthogonal); + // Cache these so we don't have to re-access memory. + Vector<Vector3> &ref_grid = grid_points[c]; + Vector<Vector3> &ref_grid_normals = grid_normals[c]; + Vector<Color> &ref_grid_colors = grid_colors[c]; + + // Count our elements same as code below it. + int expected_size = 0; + for (int i = -grid_size; i <= grid_size; i++) { + const real_t position_a = center_a + i * small_step_size; + const real_t position_b = center_b + i * small_step_size; + + // Don't draw lines over the origin if it's enabled. + if (!(origin_enabled && Math::is_zero_approx(position_a))) { + expected_size += 2; + } + + if (!(origin_enabled && Math::is_zero_approx(position_b))) { + expected_size += 2; + } + } + + int idx = 0; + ref_grid.resize(expected_size); + ref_grid_normals.resize(expected_size); + ref_grid_colors.resize(expected_size); + // In each iteration of this loop, draw one line in each direction (so two lines per loop, in each if statement). for (int i = -grid_size; i <= grid_size; i++) { Color line_color; @@ -6143,12 +6176,13 @@ void Node3DEditor::_init_grid() { line_end[a] = position_a; line_bgn[b] = bgn_b; line_end[b] = end_b; - grid_points[c].push_back(line_bgn); - grid_points[c].push_back(line_end); - grid_colors[c].push_back(line_color); - grid_colors[c].push_back(line_color); - grid_normals[c].push_back(normal); - grid_normals[c].push_back(normal); + ref_grid.set(idx, line_bgn); + ref_grid.set(idx + 1, line_end); + ref_grid_colors.set(idx, line_color); + ref_grid_colors.set(idx + 1, line_color); + ref_grid_normals.set(idx, normal); + ref_grid_normals.set(idx + 1, normal); + idx += 2; } if (!(origin_enabled && Math::is_zero_approx(position_b))) { @@ -6158,12 +6192,13 @@ void Node3DEditor::_init_grid() { line_end[b] = position_b; line_bgn[a] = bgn_a; line_end[a] = end_a; - grid_points[c].push_back(line_bgn); - grid_points[c].push_back(line_end); - grid_colors[c].push_back(line_color); - grid_colors[c].push_back(line_color); - grid_normals[c].push_back(normal); - grid_normals[c].push_back(normal); + ref_grid.set(idx, line_bgn); + ref_grid.set(idx + 1, line_end); + ref_grid_colors.set(idx, line_color); + ref_grid_colors.set(idx + 1, line_color); + ref_grid_normals.set(idx, normal); + ref_grid_normals.set(idx + 1, normal); + idx += 2; } } @@ -6201,8 +6236,22 @@ void Node3DEditor::_finish_grid() { } void Node3DEditor::update_grid() { - _finish_grid(); - _init_grid(); + const Camera3D::Projection current_projection = viewports[0]->camera->get_projection(); + + if (current_projection != grid_camera_last_update_perspective) { + grid_init_draw = false; // redraw + grid_camera_last_update_perspective = current_projection; + } + + // Gets a orthogonal or perspective position correctly (for the grid comparison) + const Vector3 camera_position = get_editor_viewport(0)->camera->get_position(); + + if (!grid_init_draw || (camera_position - grid_camera_last_update_position).length() >= 10.0f) { + _finish_grid(); + _init_grid(); + grid_init_draw = true; + grid_camera_last_update_position = camera_position; + } } void Node3DEditor::_selection_changed() { diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index 0c1456aaf8..094aa5662f 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -35,6 +35,7 @@ #include "editor/editor_plugin.h" #include "editor/editor_scale.h" #include "editor/plugins/node_3d_editor_gizmos.h" +#include "scene/3d/camera_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/visual_instance_3d.h" #include "scene/3d/world_environment.h" @@ -42,7 +43,6 @@ #include "scene/resources/environment.h" #include "scene/resources/sky_material.h" -class Camera3D; class Node3DEditor; class Node3DEditorViewport; class SubViewportContainer; @@ -521,6 +521,9 @@ private: bool grid_visible[3]; //currently visible bool grid_enable[3]; //should be always visible if true bool grid_enabled; + bool grid_init_draw = false; + Camera3D::Projection grid_camera_last_update_perspective; + Vector3 grid_camera_last_update_position = Vector3(); Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[4], scale_gizmo[3], scale_plane_gizmo[3]; Ref<StandardMaterial3D> gizmo_color[3]; @@ -622,7 +625,6 @@ private: void _menu_gizmo_toggled(int p_option); void _update_camera_override_button(bool p_game_running); void _update_camera_override_viewport(Object *p_viewport); - HBoxContainer *hbc_menu; // Used for secondary menu items which are displayed depending on the currently selected node // (such as MeshInstance's "Mesh" menu). diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 668a15da37..e6762826dd 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -3409,8 +3409,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { ED_SHORTCUT("script_editor/window_sort", TTR("Sort")); ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP); ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN); - ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work - ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA); + ED_SHORTCUT("script_editor/next_script", TTR("Next Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work + ED_SHORTCUT("script_editor/prev_script", TTR("Previous Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA); set_process_unhandled_key_input(true); file_menu = memnew(MenuButton); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index bb8b87ed83..8cd746304c 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -241,14 +241,14 @@ void ScriptTextEditor::_warning_clicked(Variant p_line) { goto_line_centered(p_line.operator int64_t()); } else if (p_line.get_type() == Variant::DICTIONARY) { Dictionary meta = p_line.operator Dictionary(); - code_editor->get_text_editor()->insert_at("# warning-ignore:" + meta["code"].operator String(), meta["line"].operator int64_t() - 1); + code_editor->get_text_editor()->insert_line_at(meta["line"].operator int64_t() - 1, "# warning-ignore:" + meta["code"].operator String()); _validate_script(); } } void ScriptTextEditor::_error_clicked(Variant p_line) { if (p_line.get_type() == Variant::INT) { - code_editor->get_text_editor()->cursor_set_line(p_line.operator int64_t()); + code_editor->get_text_editor()->set_caret_line(p_line.operator int64_t()); } } @@ -256,14 +256,14 @@ void ScriptTextEditor::reload_text() { ERR_FAIL_COND(script.is_null()); CodeEdit *te = code_editor->get_text_editor(); - int column = te->cursor_get_column(); - int row = te->cursor_get_line(); + int column = te->get_caret_column(); + int row = te->get_caret_line(); int h = te->get_h_scroll(); int v = te->get_v_scroll(); te->set_text(script->get_source_code()); - te->cursor_set_line(row); - te->cursor_set_column(column); + te->set_caret_line(row); + te->set_caret_column(column); te->set_h_scroll(h); te->set_v_scroll(v); @@ -281,12 +281,12 @@ void ScriptTextEditor::add_callback(const String &p_function, PackedStringArray pos = code_editor->get_text_editor()->get_line_count() + 2; String func = script->get_language()->make_function("", p_function, p_args); //code=code+func; - code_editor->get_text_editor()->cursor_set_line(pos + 1); - code_editor->get_text_editor()->cursor_set_column(1000000); //none shall be that big - code_editor->get_text_editor()->insert_text_at_cursor("\n\n" + func); + code_editor->get_text_editor()->set_caret_line(pos + 1); + code_editor->get_text_editor()->set_caret_column(1000000); //none shall be that big + code_editor->get_text_editor()->insert_text_at_caret("\n\n" + func); } - code_editor->get_text_editor()->cursor_set_line(pos); - code_editor->get_text_editor()->cursor_set_column(1); + code_editor->get_text_editor()->set_caret_line(pos); + code_editor->get_text_editor()->set_caret_column(1); } bool ScriptTextEditor::show_members_overview() { @@ -726,7 +726,7 @@ void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) { _edit_option(breakpoints_menu->get_item_id(p_idx)); } else { code_editor->goto_line(breakpoints_menu->get_item_metadata(p_idx)); - code_editor->get_text_editor()->call_deferred(SNAME("center_viewport_to_cursor")); //Need to be deferred, because goto uses call_deferred(). + code_editor->get_text_editor()->call_deferred(SNAME("center_viewport_to_caret")); //Need to be deferred, because goto uses call_deferred(). } } @@ -884,7 +884,7 @@ void ScriptTextEditor::update_toggle_scripts_button() { void ScriptTextEditor::_update_connected_methods() { CodeEdit *text_edit = code_editor->get_text_editor(); - text_edit->set_gutter_width(connection_gutter, text_edit->get_row_height()); + text_edit->set_gutter_width(connection_gutter, text_edit->get_line_height()); for (int i = 0; i < text_edit->get_line_count(); i++) { if (text_edit->get_line_gutter_metadata(i, connection_gutter) == "") { continue; @@ -1054,7 +1054,7 @@ void ScriptTextEditor::_edit_option(int p_op) { code_editor->duplicate_selection(); } break; case EDIT_TOGGLE_FOLD_LINE: { - tx->toggle_foldable_line(tx->cursor_get_line()); + tx->toggle_foldable_line(tx->get_caret_line()); tx->update(); } break; case EDIT_FOLD_ALL_LINES: { @@ -1062,7 +1062,7 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->update(); } break; case EDIT_UNFOLD_ALL_LINES: { - tx->unhide_all_lines(); + tx->unfold_all_lines(); tx->update(); } break; case EDIT_TOGGLE_COMMENT: { @@ -1080,7 +1080,7 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->begin_complex_operation(); int begin, end; - if (tx->is_selection_active()) { + if (tx->has_selection()) { begin = tx->get_selection_from_line(); end = tx->get_selection_to_line(); // ignore if the cursor is not past the first column @@ -1122,7 +1122,7 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case EDIT_EVALUATE: { Expression expression; - Vector<String> lines = code_editor->get_text_editor()->get_selection_text().split("\n"); + Vector<String> lines = code_editor->get_text_editor()->get_selected_text().split("\n"); PackedStringArray results; for (int i = 0; i < lines.size(); i++) { @@ -1142,7 +1142,7 @@ void ScriptTextEditor::_edit_option(int p_op) { } code_editor->get_text_editor()->begin_complex_operation(); //prevents creating a two-step undo - code_editor->get_text_editor()->insert_text_at_cursor(String("\n").join(results)); + code_editor->get_text_editor()->insert_text_at_caret(String("\n").join(results)); code_editor->get_text_editor()->end_complex_operation(); } break; case SEARCH_FIND: { @@ -1158,14 +1158,14 @@ void ScriptTextEditor::_edit_option(int p_op) { code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selection_text(); + String selected_text = code_editor->get_text_editor()->get_selected_text(); // Yep, because it doesn't make sense to instance this dialog for every single script open... // So this will be delegated to the ScriptEditor. emit_signal(SNAME("search_in_files_requested"), selected_text); } break; case REPLACE_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selection_text(); + String selected_text = code_editor->get_text_editor()->get_selected_text(); emit_signal(SNAME("replace_in_files_requested"), selected_text); } break; @@ -1189,7 +1189,7 @@ void ScriptTextEditor::_edit_option(int p_op) { code_editor->remove_all_bookmarks(); } break; case DEBUG_TOGGLE_BREAKPOINT: { - int line = tx->cursor_get_line(); + int line = tx->get_caret_line(); bool dobreak = !tx->is_line_breakpointed(line); tx->set_line_as_breakpoint(line, dobreak); EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak); @@ -1210,20 +1210,20 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - int line = tx->cursor_get_line(); + int line = tx->get_caret_line(); // wrap around if (line >= (int)bpoints[bpoints.size() - 1]) { tx->unfold_line(bpoints[0]); - tx->cursor_set_line(bpoints[0]); - tx->center_viewport_to_cursor(); + tx->set_caret_line(bpoints[0]); + tx->center_viewport_to_caret(); } else { for (int i = 0; i < bpoints.size(); i++) { int bline = bpoints[i]; if (bline > line) { tx->unfold_line(bline); - tx->cursor_set_line(bline); - tx->center_viewport_to_cursor(); + tx->set_caret_line(bline); + tx->center_viewport_to_caret(); return; } } @@ -1236,19 +1236,19 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - int line = tx->cursor_get_line(); + int line = tx->get_caret_line(); // wrap around if (line <= (int)bpoints[0]) { tx->unfold_line(bpoints[bpoints.size() - 1]); - tx->cursor_set_line(bpoints[bpoints.size() - 1]); - tx->center_viewport_to_cursor(); + tx->set_caret_line(bpoints[bpoints.size() - 1]); + tx->center_viewport_to_caret(); } else { for (int i = bpoints.size(); i >= 0; i--) { int bline = bpoints[i]; if (bline < line) { tx->unfold_line(bline); - tx->cursor_set_line(bline); - tx->center_viewport_to_cursor(); + tx->set_caret_line(bline); + tx->center_viewport_to_caret(); return; } } @@ -1256,21 +1256,21 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case HELP_CONTEXTUAL: { - String text = tx->get_selection_text(); + String text = tx->get_selected_text(); if (text == "") { - text = tx->get_word_under_cursor(); + text = tx->get_word_under_caret(); } if (text != "") { emit_signal(SNAME("request_help"), text); } } break; case LOOKUP_SYMBOL: { - String text = tx->get_word_under_cursor(); + String text = tx->get_word_under_caret(); if (text == "") { - text = tx->get_selection_text(); + text = tx->get_selected_text(); } if (text != "") { - _lookup_symbol(text, tx->cursor_get_line(), tx->cursor_get_column()); + _lookup_symbol(text, tx->get_caret_line(), tx->get_caret_column()); } } break; } @@ -1325,7 +1325,7 @@ void ScriptTextEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { - code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_row_height()); + code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_line_height()); } break; default: break; @@ -1422,8 +1422,10 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data Dictionary d = p_data; CodeEdit *te = code_editor->get_text_editor(); - int row, col; - te->_get_mouse_pos(p_point, row, col); + + Point2i pos = te->get_line_column_at_pos(p_point); + int row = pos.y; + int col = pos.x; if (d.has("type") && String(d["type"]) == "resource") { Ref<Resource> res = d["resource"]; @@ -1436,9 +1438,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data return; } - te->cursor_set_line(row); - te->cursor_set_column(col); - te->insert_text_at_cursor(res->get_path()); + te->set_caret_line(row); + te->set_caret_column(col); + te->insert_text_at_caret(res->get_path()); } if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) { @@ -1459,9 +1461,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } } - te->cursor_set_line(row); - te->cursor_set_column(col); - te->insert_text_at_cursor(text_to_drop); + te->set_caret_line(row); + te->set_caret_column(col); + te->insert_text_at_caret(text_to_drop); } if (d.has("type") && String(d["type"]) == "nodes") { @@ -1489,9 +1491,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data text_to_drop += "\"" + path.c_escape() + "\""; } - te->cursor_set_line(row); - te->cursor_set_column(col); - te->insert_text_at_cursor(text_to_drop); + te->set_caret_line(row); + te->set_caret_column(col); + te->insert_text_at_caret(text_to_drop); } } @@ -1505,18 +1507,20 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_RIGHT && mb->is_pressed()) { local_pos = mb->get_global_position() - tx->get_global_position(); create_menu = true; - } else if (k.is_valid() && k->get_keycode() == KEY_MENU) { - local_pos = tx->_get_cursor_pixel_pos(); + } else if (k.is_valid() && k->is_action("ui_menu", true)) { + tx->adjust_viewport_to_caret(); + local_pos = tx->get_caret_draw_pos(); create_menu = true; } if (create_menu) { - int col, row; - tx->_get_mouse_pos(local_pos, row, col); + Point2i pos = tx->get_line_column_at_pos(local_pos); + int row = pos.y; + int col = pos.x; - tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); - if (tx->is_right_click_moving_caret()) { - if (tx->is_selection_active()) { + tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + if (tx->is_move_caret_on_right_click_enabled()) { + if (tx->has_selection()) { int from_line = tx->get_selection_from_line(); int to_line = tx->get_selection_to_line(); int from_column = tx->get_selection_from_column(); @@ -1527,18 +1531,18 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { tx->deselect(); } } - if (!tx->is_selection_active()) { - tx->cursor_set_line(row, true, false); - tx->cursor_set_column(col); + if (!tx->has_selection()) { + tx->set_caret_line(row, false, false); + tx->set_caret_column(col); } } String word_at_pos = tx->get_word_at_pos(local_pos); if (word_at_pos == "") { - word_at_pos = tx->get_word_under_cursor(); + word_at_pos = tx->get_word_under_caret(); } if (word_at_pos == "") { - word_at_pos = tx->get_selection_text(); + word_at_pos = tx->get_selected_text(); } bool has_color = (word_at_pos == "Color"); @@ -1590,7 +1594,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { has_color = false; } } - _make_context_menu(tx->is_selection_active(), has_color, foldable, open_docs, goto_definition, local_pos); + _make_context_menu(tx->has_selection(), has_color, foldable, open_docs, goto_definition, local_pos); } } @@ -1925,12 +1929,12 @@ void ScriptTextEditor::register_editor() { // Leave these at zero, same can be accomplished with tab/shift-tab, including selection. // The next/previous in history shortcut in this case makes a lot more sense. - ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), 0); - ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0); + ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), KEY_NONE); + ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), KEY_NONE); ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K); ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KEY_MASK_ALT | KEY_F); - ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0); - ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0); + ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), KEY_NONE); + ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), KEY_NONE); #ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_C); #else @@ -1965,7 +1969,7 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B); ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B); ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); - ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0); + ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), KEY_NONE); #ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 95973f9dfd..29436e32b2 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -74,14 +74,14 @@ void ShaderTextEditor::reload_text() { ERR_FAIL_COND(shader.is_null()); CodeEdit *te = get_text_editor(); - int column = te->cursor_get_column(); - int row = te->cursor_get_line(); + int column = te->get_caret_column(); + int row = te->get_caret_line(); int h = te->get_h_scroll(); int v = te->get_v_scroll(); te->set_text(shader->get_code()); - te->cursor_set_line(row); - te->cursor_set_column(column); + te->set_caret_line(row); + te->set_caret_column(column); te->set_h_scroll(h); te->set_v_scroll(v); @@ -408,7 +408,7 @@ void ShaderEditor::_show_warnings_panel(bool p_show) { void ShaderEditor::_warning_clicked(Variant p_line) { if (p_line.get_type() == Variant::INT) { - shader_editor->get_text_editor()->cursor_set_line(p_line.operator int64_t()); + shader_editor->get_text_editor()->set_caret_line(p_line.operator int64_t()); } } @@ -550,13 +550,15 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { if (mb.is_valid()) { if (mb->get_button_index() == MOUSE_BUTTON_RIGHT && mb->is_pressed()) { - int col, row; CodeEdit *tx = shader_editor->get_text_editor(); - tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); - tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); - if (tx->is_right_click_moving_caret()) { - if (tx->is_selection_active()) { + Point2i pos = tx->get_line_column_at_pos(mb->get_global_position() - tx->get_global_position()); + int row = pos.y; + int col = pos.x; + tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + + if (tx->is_move_caret_on_right_click_enabled()) { + if (tx->has_selection()) { int from_line = tx->get_selection_from_line(); int to_line = tx->get_selection_to_line(); int from_column = tx->get_selection_from_column(); @@ -567,19 +569,20 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { tx->deselect(); } } - if (!tx->is_selection_active()) { - tx->cursor_set_line(row, true, false); - tx->cursor_set_column(col); + if (!tx->has_selection()) { + tx->set_caret_line(row, true, false); + tx->set_caret_column(col); } } - _make_context_menu(tx->is_selection_active(), get_local_mouse_position()); + _make_context_menu(tx->has_selection(), get_local_mouse_position()); } } Ref<InputEventKey> k = ev; - if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_MENU) { + if (k.is_valid() && k->is_pressed() && k->is_action("ui_menu", true)) { CodeEdit *tx = shader_editor->get_text_editor(); - _make_context_menu(tx->is_selection_active(), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos())); + tx->adjust_viewport_to_caret(); + _make_context_menu(tx->has_selection(), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos())); context_menu->grab_focus(); } } diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index 3de2ffc137..0bb0bfde6f 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -386,7 +386,7 @@ PhysicalBone3D *Skeleton3DEditor::create_physical_bone(int bone_id, int bone_chi const real_t radius(half_height * 0.2); CapsuleShape3D *bone_shape_capsule = memnew(CapsuleShape3D); - bone_shape_capsule->set_height((half_height - radius) * 2); + bone_shape_capsule->set_height(half_height * 2); bone_shape_capsule->set_radius(radius); CollisionShape3D *bone_shape = memnew(CollisionShape3D); diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index faf287b9bd..cfccf90499 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -132,14 +132,14 @@ void TextEditor::reload_text() { ERR_FAIL_COND(text_file.is_null()); CodeEdit *te = code_editor->get_text_editor(); - int column = te->cursor_get_column(); - int row = te->cursor_get_line(); + int column = te->get_caret_column(); + int row = te->get_caret_line(); int h = te->get_h_scroll(); int v = te->get_v_scroll(); te->set_text(text_file->get_text()); - te->cursor_set_line(row); - te->cursor_set_column(column); + te->set_caret_line(row); + te->set_caret_column(column); te->set_h_scroll(h); te->set_v_scroll(v); @@ -332,7 +332,7 @@ void TextEditor::_edit_option(int p_op) { code_editor->duplicate_selection(); } break; case EDIT_TOGGLE_FOLD_LINE: { - tx->toggle_foldable_line(tx->cursor_get_line()); + tx->toggle_foldable_line(tx->get_caret_line()); tx->update(); } break; case EDIT_FOLD_ALL_LINES: { @@ -340,7 +340,7 @@ void TextEditor::_edit_option(int p_op) { tx->update(); } break; case EDIT_UNFOLD_ALL_LINES: { - tx->unhide_all_lines(); + tx->unfold_all_lines(); tx->update(); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { @@ -374,14 +374,14 @@ void TextEditor::_edit_option(int p_op) { code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selection_text(); + String selected_text = code_editor->get_text_editor()->get_selected_text(); // Yep, because it doesn't make sense to instance this dialog for every single script open... // So this will be delegated to the ScriptEditor. emit_signal(SNAME("search_in_files_requested"), selected_text); } break; case REPLACE_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selection_text(); + String selected_text = code_editor->get_text_editor()->get_selected_text(); emit_signal(SNAME("replace_in_files_requested"), selected_text); } break; @@ -427,16 +427,18 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { if (mb.is_valid()) { if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { - int col, row; CodeEdit *tx = code_editor->get_text_editor(); - tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); - tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + Point2i pos = tx->get_line_column_at_pos(mb->get_global_position() - tx->get_global_position()); + int row = pos.y; + int col = pos.x; + + tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); bool can_fold = tx->can_fold_line(row); bool is_folded = tx->is_line_folded(row); - if (tx->is_right_click_moving_caret()) { - if (tx->is_selection_active()) { + if (tx->is_move_caret_on_right_click_enabled()) { + if (tx->has_selection()) { int from_line = tx->get_selection_from_line(); int to_line = tx->get_selection_to_line(); int from_column = tx->get_selection_from_column(); @@ -447,23 +449,24 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { tx->deselect(); } } - if (!tx->is_selection_active()) { - tx->cursor_set_line(row, true, false); - tx->cursor_set_column(col); + if (!tx->has_selection()) { + tx->set_caret_line(row, true, false); + tx->set_caret_column(col); } } if (!mb->is_pressed()) { - _make_context_menu(tx->is_selection_active(), can_fold, is_folded, get_local_mouse_position()); + _make_context_menu(tx->has_selection(), can_fold, is_folded, get_local_mouse_position()); } } } Ref<InputEventKey> k = ev; - if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_MENU) { + if (k.is_valid() && k->is_pressed() && k->is_action("ui_menu", true)) { CodeEdit *tx = code_editor->get_text_editor(); - int line = tx->cursor_get_line(); - _make_context_menu(tx->is_selection_active(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos())); + int line = tx->get_caret_line(); + tx->adjust_viewport_to_caret(); + _make_context_menu(tx->has_selection(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos())); context_menu->grab_focus(); } } diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index b277f2ab42..1a6eb7b63b 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -330,7 +330,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { for (const Rect2 &E : autoslice_cache) { if (E.has_point(point)) { rect = E; - if (Input::get_singleton()->is_key_pressed(KEY_CTRL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) { + if (Input::get_singleton()->is_key_pressed(KEY_CTRL) && !(Input::get_singleton()->is_key_pressed(Key(KEY_SHIFT | KEY_ALT)))) { Rect2 r; if (node_sprite) { r = node_sprite->get_region_rect(); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 7ea3deedb9..165a381407 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -1721,6 +1721,8 @@ void ThemeItemEditorDialog::_edit_theme_item_gui_input(const Ref<InputEvent> &p_ edit_theme_item_dialog->hide(); edit_theme_item_dialog->set_input_as_handled(); } break; + default: + break; } } } diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index a9a36427db..aaa29bcb7a 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -484,7 +484,7 @@ VersionControlEditorPlugin::VersionControlEditorPlugin() { commit_message->set_h_grow_direction(Control::GrowDirection::GROW_DIRECTION_BEGIN); commit_message->set_v_grow_direction(Control::GrowDirection::GROW_DIRECTION_END); commit_message->set_custom_minimum_size(Size2(200, 100)); - commit_message->set_wrap_enabled(true); + commit_message->set_line_wrapping_mode(TextEdit::LineWrappingMode::LINE_WRAPPING_BOUNDARY); commit_message->connect("text_changed", callable_mp(this, &VersionControlEditorPlugin::_update_commit_button)); commit_message->connect("gui_input", callable_mp(this, &VersionControlEditorPlugin::_commit_message_gui_input)); commit_box_vbc->add_child(commit_message); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index f960da6732..1fbf5eb0e6 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -110,7 +110,6 @@ void VisualShaderGraphPlugin::_bind_methods() { ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression); ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve); ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz); - ClassDB::bind_method("update_constant", &VisualShaderGraphPlugin::update_constant); } void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) { @@ -237,18 +236,6 @@ int VisualShaderGraphPlugin::get_constant_index(float p_constant) const { return 0; } -void VisualShaderGraphPlugin::update_constant(VisualShader::Type p_type, int p_node_id) { - if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].const_op) { - return; - } - VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(links[p_node_id].visual_node); - if (!float_const) { - return; - } - links[p_node_id].const_op->select(get_constant_index(float_const->get_constant())); - links[p_node_id].graph_node->set_size(Size2(-1, -1)); -} - void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) { if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) { return; @@ -267,10 +254,6 @@ void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p links[p_node_id].input_ports.insert(p_port_id, { p_button }); } -void VisualShaderGraphPlugin::register_constant_option_btn(int p_node_id, OptionButton *p_button) { - links[p_node_id].const_op = p_button; -} - void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) { links[p_node_id].expression_edit = p_expression_edit; } @@ -322,7 +305,7 @@ void VisualShaderGraphPlugin::make_dirty(bool p_enabled) { } void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) { - links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); + links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); } void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) { @@ -498,23 +481,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { custom_editor = hbox; } - Ref<VisualShaderNodeFloatConstant> float_const = vsnode; - if (float_const.is_valid()) { - HBoxContainer *hbox = memnew(HBoxContainer); - - hbox->add_child(custom_editor); - OptionButton *btn = memnew(OptionButton); - hbox->add_child(btn); - register_constant_option_btn(p_id, btn); - btn->add_item(""); - for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) { - btn->add_item(float_constant_defs[i].name); - } - btn->select(get_constant_index(float_const->get_constant())); - btn->connect("item_selected", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_float_constant_selected), varray(p_id)); - custom_editor = hbox; - } - if (custom_editor && !vsnode->is_use_prop_slots() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) { //will be embedded in first port } else if (custom_editor) { @@ -592,6 +558,14 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { } if (vsnode->is_use_prop_slots()) { + String error = vsnode->get_warning(visual_shader->get_mode(), p_type); + if (error != String()) { + Label *error_label = memnew(Label); + error_label->add_theme_color_override("font_color", VisualShaderEditor::get_singleton()->get_theme_color(SNAME("error_color"), SNAME("Editor"))); + error_label->set_text(error); + node->add_child(error_label); + } + return; } custom_editor = nullptr; @@ -2029,6 +2003,8 @@ void VisualShaderEditor::_uniform_line_edit_changed(const String &p_text, int p_ undo_redo->add_undo_method(node.ptr(), "set_uniform_name", node->get_uniform_name()); undo_redo->add_do_method(graph_plugin.ptr(), "set_uniform_name", type, p_node_id, validated_name); undo_redo->add_undo_method(graph_plugin.ptr(), "set_uniform_name", type, p_node_id, node->get_uniform_name()); + undo_redo->add_do_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id); + undo_redo->add_undo_method(graph_plugin.ptr(), "update_node_deferred", type, p_node_id); undo_redo->add_do_method(this, "_update_uniforms", true); undo_redo->add_undo_method(this, "_update_uniforms", true); @@ -2172,6 +2148,16 @@ void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, int p_op_idx) { } } + // TRANSFORM_OP + { + VisualShaderNodeTransformOp *matOp = Object::cast_to<VisualShaderNodeTransformOp>(p_node); + + if (matOp) { + matOp->set_operator((VisualShaderNodeTransformOp::Operator)p_op_idx); + return; + } + } + // TRANSFORM_FUNC { VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(p_node); @@ -2361,6 +2347,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa position += graph->get_size() * 0.5; position /= EDSCALE; } + position /= graph->get_zoom(); saved_node_pos_dirty = false; int id_to_use = visual_shader->get_valid_node_id(type); @@ -2933,6 +2920,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { selected_constants.clear(); selected_uniforms.clear(); selected_comment = -1; + selected_float_constant = -1; List<int> to_change; for (int i = 0; i < graph->get_child_count(); i++) { @@ -2952,6 +2940,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { if (constant_node != nullptr) { selected_constants.insert(id); } + VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr()); + if (float_constant_node != nullptr) { + selected_float_constant = id; + } VisualShaderNodeUniform *uniform_node = Object::cast_to<VisualShaderNodeUniform>(node.ptr()); if (uniform_node != nullptr && uniform_node->is_convertible_to_constant()) { selected_uniforms.insert(id); @@ -2962,6 +2954,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { if (to_change.size() > 1) { selected_comment = -1; + selected_float_constant = -1; } if (to_change.is_empty() && copy_nodes_buffer.is_empty()) { @@ -2976,6 +2969,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { if (temp != -1) { popup_menu->remove_item(temp); } + temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS); + if (temp != -1) { + popup_menu->remove_item(temp); + } temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS); if (temp != -1) { popup_menu->remove_item(temp); @@ -2997,14 +2994,23 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { popup_menu->remove_item(temp); } - if (selected_comment != -1) { + if (selected_constants.size() > 0 || selected_uniforms.size() > 0) { popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2); - popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE); - popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION); - } - if (selected_constants.size() > 0 || selected_uniforms.size() > 0) { - popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3); + if (selected_float_constant != -1) { + popup_menu->add_submenu_item(TTR("Float Constants"), "FloatConstants", int(NodeMenuOptions::FLOAT_CONSTANTS)); + + if (!constants_submenu) { + constants_submenu = memnew(PopupMenu); + constants_submenu->set_name("FloatConstants"); + + for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) { + constants_submenu->add_item(float_constant_defs[i].name, i); + } + popup_menu->add_child(constants_submenu); + constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected)); + } + } if (selected_constants.size() > 0) { popup_menu->add_item(TTR("Convert Constant(s) to Uniform(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS); @@ -3015,6 +3021,12 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { } } + if (selected_comment != -1) { + popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3); + popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE); + popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION); + } + menu_point = graph->get_local_mouse_position(); Point2 gpos = Input::get_singleton()->get_mouse_position(); popup_menu->set_position(gpos); @@ -3484,27 +3496,20 @@ void VisualShaderEditor::_uniform_select_item(Ref<VisualShaderNodeUniformRef> p_ undo_redo->commit_action(); } -void VisualShaderEditor::_float_constant_selected(int p_index, int p_node) { - if (p_index == 0) { - graph_plugin->update_node_size(p_node); - return; - } - - --p_index; - - ERR_FAIL_INDEX(p_index, MAX_FLOAT_CONST_DEFS); +void VisualShaderEditor::_float_constant_selected(int p_which) { + ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS); VisualShader::Type type = get_current_shader_type(); - Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, p_node); - if (!node.is_valid()) { - return; + Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant); + ERR_FAIL_COND(!node.is_valid()); + + if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) { + return; // same } - undo_redo->create_action(TTR("Set constant")); - undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_index].value); + undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name)); + undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value); undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant()); - undo_redo->add_do_method(graph_plugin.ptr(), "update_constant", type, p_node); - undo_redo->add_undo_method(graph_plugin.ptr(), "update_constant", type, p_node); undo_redo->commit_action(); } @@ -3967,7 +3972,7 @@ VisualShaderEditor::VisualShaderEditor() { preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); preview_text->set_syntax_highlighter(syntax_highlighter); preview_text->set_draw_line_numbers(true); - preview_text->set_readonly(true); + preview_text->set_editable(false); error_panel = memnew(PanelContainer); preview_vbox->add_child(error_panel); @@ -4449,6 +4454,7 @@ VisualShaderEditor::VisualShaderEditor() { // TRANSFORM add_options.push_back(AddOption("TransformFunc", "Transform", "Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("TransformOp", "Transform", "Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("OuterProduct", "Transform", "Composition", "VisualShaderNodeOuterProduct", TTR("Calculate the outer product of a pair of vectors.\n\nOuterProduct treats the first parameter 'c' as a column vector (matrix with one column) and the second parameter 'r' as a row vector (matrix with one row) and does a linear algebraic matrix multiply 'c * r', yielding a matrix whose number of rows is the number of components in 'c' and whose number of columns is the number of components in 'r'."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("TransformCompose", "Transform", "Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); @@ -4459,7 +4465,11 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Inverse", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), VisualShaderNodeTransformFunc::FUNC_INVERSE, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("Transpose", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), VisualShaderNodeTransformFunc::FUNC_TRANSPOSE, VisualShaderNode::PORT_TYPE_TRANSFORM)); - add_options.push_back(AddOption("TransformMult", "Transform", "Operators", "VisualShaderNodeTransformMult", TTR("Multiplies transform by transform."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Add", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), VisualShaderNodeTransformOp::OP_ADD, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Divide", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), VisualShaderNodeTransformOp::OP_A_DIV_B, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Multiply", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), VisualShaderNodeTransformOp::OP_AxB, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("MultiplyComp", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Performs per-component multiplication of two transforms."), VisualShaderNodeTransformOp::OP_AxB_COMP, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Subtract", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), VisualShaderNodeTransformOp::OP_A_MINUS_B, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("TransformVectorMult", "Transform", "Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("TransformConstant", "Transform", "Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); @@ -4742,9 +4752,6 @@ public: if (p_property != "constant") { undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id); undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id); - } else { - undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id); - undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id); } undo_redo->commit_action(); diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index f53726edb9..87bab16a45 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -73,7 +73,6 @@ private: Map<int, Port> output_ports; VBoxContainer *preview_box = nullptr; LineEdit *uniform_name = nullptr; - OptionButton *const_op = nullptr; CodeEdit *expression_edit = nullptr; CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr }; }; @@ -95,7 +94,6 @@ public: void register_output_port(int p_id, int p_port, TextureButton *p_button); void register_uniform_name(int p_id, LineEdit *p_uniform_name); void register_default_input_button(int p_node_id, int p_port_id, Button *p_button); - void register_constant_option_btn(int p_node_id, OptionButton *p_button); void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit); void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor); void clear_links(); @@ -118,7 +116,6 @@ public: void set_uniform_name(VisualShader::Type p_type, int p_node_id, const String &p_name); void update_curve(int p_node_id); void update_curve_xyz(int p_node_id); - void update_constant(VisualShader::Type p_type, int p_node_id); void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression); int get_constant_index(float p_constant) const; void update_node_size(int p_node_id); @@ -164,6 +161,7 @@ class VisualShaderEditor : public VBoxContainer { ConfirmationDialog *members_dialog; PopupMenu *popup_menu; + PopupMenu *constants_submenu = nullptr; MenuButton *tools; PopupPanel *comment_title_change_popup = nullptr; @@ -214,6 +212,7 @@ class VisualShaderEditor : public VBoxContainer { DELETE, DUPLICATE, SEPARATOR2, // ignore + FLOAT_CONSTANTS, CONVERT_CONSTANTS_TO_UNIFORMS, CONVERT_UNIFORMS_TO_CONSTANTS, SEPARATOR3, // ignore @@ -347,6 +346,7 @@ class VisualShaderEditor : public VBoxContainer { Set<int> selected_constants; Set<int> selected_uniforms; int selected_comment = -1; + int selected_float_constant = -1; void _convert_constants_to_uniforms(bool p_vice_versa); void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to); @@ -396,7 +396,7 @@ class VisualShaderEditor : public VBoxContainer { void _input_select_item(Ref<VisualShaderNodeInput> input, String name); void _uniform_select_item(Ref<VisualShaderNodeUniformRef> p_uniform, String p_name); - void _float_constant_selected(int p_index, int p_node); + void _float_constant_selected(int p_which); VisualShader::Type get_current_shader_type() const; |