diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 0e1e0f9b3b4..a716579e501 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -4504,13 +4504,15 @@ void SpatialEditor::set_state(const Dictionary &p_state) { } if (d.has("translate_snap")) - snap_translate->set_text(d["translate_snap"]); + snap_translate_value = d["translate_snap"]; if (d.has("rotate_snap")) - snap_rotate->set_text(d["rotate_snap"]); + snap_rotate_value = d["rotate_snap"]; if (d.has("scale_snap")) - snap_scale->set_text(d["scale_snap"]); + snap_scale_value = d["scale_snap"]; + + _snap_update(); if (d.has("local_coords")) { tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_pressed(d["local_coords"]); @@ -4617,6 +4619,20 @@ void SpatialEditor::edit(Spatial *p_spatial) { } } +void SpatialEditor::_snap_changed() { + + snap_translate_value = snap_translate->get_text().to_double(); + snap_rotate_value = snap_rotate->get_text().to_double(); + snap_scale_value = snap_scale->get_text().to_double(); +} + +void SpatialEditor::_snap_update() { + + snap_translate->set_text(String::num(snap_translate_value)); + snap_rotate->set_text(String::num(snap_rotate_value)); + snap_scale->set_text(String::num(snap_scale_value)); +} + void SpatialEditor::_xform_dialog_action() { Transform t; @@ -5848,6 +5864,8 @@ void SpatialEditor::_bind_methods() { ClassDB::bind_method("_refresh_menu_icons", &SpatialEditor::_refresh_menu_icons); ClassDB::bind_method("_update_camera_override_button", &SpatialEditor::_update_camera_override_button); ClassDB::bind_method("_update_camera_override_viewport", &SpatialEditor::_update_camera_override_viewport); + ClassDB::bind_method("_snap_changed", &SpatialEditor::_snap_changed); + ClassDB::bind_method("_snap_update", &SpatialEditor::_snap_update); ADD_SIGNAL(MethodInfo("transform_key_request")); ADD_SIGNAL(MethodInfo("item_lock_status_changed")); @@ -6106,25 +6124,30 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { /* SNAP DIALOG */ + snap_translate_value = 1; + snap_rotate_value = 15; + snap_scale_value = 10; + snap_dialog = memnew(ConfirmationDialog); snap_dialog->set_title(TTR("Snap Settings")); add_child(snap_dialog); + snap_dialog->connect("confirmed", this, "_snap_changed"); + snap_dialog->get_cancel()->connect("pressed", this, "_snap_update"); VBoxContainer *snap_dialog_vbc = memnew(VBoxContainer); snap_dialog->add_child(snap_dialog_vbc); snap_translate = memnew(LineEdit); - snap_translate->set_text("1"); snap_dialog_vbc->add_margin_child(TTR("Translate Snap:"), snap_translate); snap_rotate = memnew(LineEdit); - snap_rotate->set_text("15"); snap_dialog_vbc->add_margin_child(TTR("Rotate Snap (deg.):"), snap_rotate); snap_scale = memnew(LineEdit); - snap_scale->set_text("10"); snap_dialog_vbc->add_margin_child(TTR("Scale Snap (%):"), snap_scale); + _snap_update(); + /* SETTINGS DIALOG */ settings_dialog = memnew(ConfirmationDialog); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 2d034955046..25c676d6907 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -579,6 +579,9 @@ private: Ref plane_gizmo_color_hl[3]; int over_gizmo_handle; + float snap_translate_value; + float snap_rotate_value; + float snap_scale_value; Ref selection_box; RID indicators; @@ -658,6 +661,8 @@ private: SpinBox *settings_znear; SpinBox *settings_zfar; + void _snap_changed(); + void _snap_update(); void _xform_dialog_action(); void _menu_item_pressed(int p_option); void _menu_item_toggled(bool pressed, int p_option);