diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 0bbcbb0080e..a13043f24c6 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -4308,13 +4308,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"]); @@ -4421,6 +4423,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; @@ -5901,25 +5917,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", callable_mp(this, &SpatialEditor::_snap_changed)); + snap_dialog->get_cancel()->connect("pressed", callable_mp(this, &SpatialEditor::_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 a4d6b133895..b79f2f5b797 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -545,6 +545,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; @@ -624,6 +627,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);