diff options
Diffstat (limited to 'editor/plugins/canvas_item_editor_plugin.cpp')
| -rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 0f9ce89f02..4814b9ae3b 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -697,6 +697,10 @@ void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_n CanvasItem *ci = Object::cast_to<CanvasItem>(p_node); Node *scene = EditorNode::get_singleton()->get_edited_scene(); + if (p_node != scene && !p_node->get_owner()) { + return; + } + bool editable = p_node == scene || p_node->get_owner() == scene || p_node == scene->get_deepest_editable_node(p_node); bool lock_children = p_node->get_meta("_edit_group_", false); bool locked = _is_node_locked(p_node); @@ -891,20 +895,29 @@ void CanvasItemEditor::_commit_canvas_item_state(List<CanvasItem *> p_canvas_ite void CanvasItemEditor::_snap_changed() { static_cast<SnapDialog *>(snap_dialog)->get_fields(grid_offset, grid_step, primary_grid_steps, snap_rotation_offset, snap_rotation_step, snap_scale_step); + + EditorSettings::get_singleton()->set_project_metadata("2d_editor", "grid_offset", grid_offset); + EditorSettings::get_singleton()->set_project_metadata("2d_editor", "grid_step", grid_step); + EditorSettings::get_singleton()->set_project_metadata("2d_editor", "primary_grid_steps", primary_grid_steps); + EditorSettings::get_singleton()->set_project_metadata("2d_editor", "snap_rotation_offset", snap_rotation_offset); + EditorSettings::get_singleton()->set_project_metadata("2d_editor", "snap_rotation_step", snap_rotation_step); + EditorSettings::get_singleton()->set_project_metadata("2d_editor", "snap_scale_step", snap_scale_step); + grid_step_multiplier = 0; viewport->queue_redraw(); } void CanvasItemEditor::_selection_result_pressed(int p_result) { - if (selection_results.size() <= p_result) { + if (selection_results_menu.size() <= p_result) { return; } - CanvasItem *item = selection_results[p_result].item; + CanvasItem *item = selection_results_menu[p_result].item; if (item) { _select_click_on_item(item, Point2(), selection_menu_additive_selection); } + selection_results_menu.clear(); } void CanvasItemEditor::_selection_menu_hide() { @@ -2247,6 +2260,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path); } + selection_results_menu = selection_results; selection_menu_additive_selection = b->is_shift_pressed(); selection_menu->set_position(viewport->get_screen_transform().xform(b->get_position())); selection_menu->reset_size(); @@ -2355,7 +2369,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { if (drag_type == DRAG_BOX_SELECTION) { if (b.is_valid() && !b->is_pressed() && b->get_button_index() == MouseButton::LEFT) { - // Confirms box selection + // Confirms box selection. Node *scene = EditorNode::get_singleton()->get_edited_scene(); if (scene) { List<CanvasItem *> selitems; @@ -2384,14 +2398,14 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { } if (b.is_valid() && b->is_pressed() && b->get_button_index() == MouseButton::RIGHT) { - // Cancel box selection + // Cancel box selection. _reset_drag(); viewport->queue_redraw(); return true; } if (m.is_valid()) { - // Update box selection + // Update box selection. box_selecting_to = transform.affine_inverse().xform(m->get_position()); viewport->queue_redraw(); return true; @@ -4554,6 +4568,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { undo_redo->add_do_method(root, "remove_meta", "_edit_vertical_guides_"); undo_redo->add_undo_method(root, "set_meta", "_edit_vertical_guides_", vguides); } + undo_redo->add_do_method(viewport, "queue_redraw"); undo_redo->add_undo_method(viewport, "queue_redraw"); undo_redo->commit_action(); } @@ -4676,7 +4691,6 @@ void CanvasItemEditor::_reset_drag() { void CanvasItemEditor::_bind_methods() { ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data); - ClassDB::bind_method(D_METHOD("set_state"), &CanvasItemEditor::set_state); ClassDB::bind_method(D_METHOD("update_viewport"), &CanvasItemEditor::update_viewport); ClassDB::bind_method(D_METHOD("center_at", "position"), &CanvasItemEditor::center_at); @@ -4889,6 +4903,22 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) { viewport->queue_redraw(); } +void CanvasItemEditor::clear() { + zoom = 1.0 / MAX(1, EDSCALE); + zoom_widget->set_zoom(zoom); + + view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); + previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen. + _update_scrollbars(); + + grid_offset = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_offset", Vector2()); + grid_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_step", Vector2(8, 8)); + primary_grid_steps = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "primary_grid_steps", 8); + snap_rotation_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_rotation_step", Math::deg_to_rad(15.0)); + snap_rotation_offset = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_rotation_offset", 0.0); + snap_scale_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_scale_step", 0.1); +} + void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) { ERR_FAIL_COND(!p_control); @@ -4932,10 +4962,6 @@ void CanvasItemEditor::center_at(const Point2 &p_pos) { } CanvasItemEditor::CanvasItemEditor() { - zoom = 1.0 / MAX(1, EDSCALE); - view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); - previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen - snap_target[0] = SNAP_TARGET_NONE; snap_target[1] = SNAP_TARGET_NONE; @@ -5381,9 +5407,10 @@ CanvasItemEditor::CanvasItemEditor() { singleton = this; set_process_shortcut_input(true); + clear(); // Make sure values are initialized. - // Update the menus' checkboxes - call_deferred(SNAME("set_state"), get_state()); + // Update the menus' checkboxes. + callable_mp(this, &CanvasItemEditor::set_state).bind(get_state()).call_deferred(); } CanvasItemEditor *CanvasItemEditor::singleton = nullptr; @@ -5419,6 +5446,10 @@ void CanvasItemEditorPlugin::set_state(const Dictionary &p_state) { canvas_item_editor->set_state(p_state); } +void CanvasItemEditorPlugin::clear() { + canvas_item_editor->clear(); +} + void CanvasItemEditorPlugin::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { |
