diff --git a/editor/editor_properties_vector.cpp b/editor/editor_properties_vector.cpp index 9ff8bf674d8..d96cc581a93 100644 --- a/editor/editor_properties_vector.cpp +++ b/editor/editor_properties_vector.cpp @@ -64,7 +64,7 @@ void EditorPropertyVectorN::_value_changed(double val, const String &p_name) { continue; } - spin_sliders[slider_idx]->set_value_no_signal(spin_sliders[changed_component]->get_value() * ratio[ratio_idx]); + spin_sliders[slider_idx]->set_value_no_signal(spin_sliders[changed_component]->get_true_value() * ratio[ratio_idx]); } } @@ -74,9 +74,9 @@ void EditorPropertyVectorN::_value_changed(double val, const String &p_name) { for (int i = 0; i < component_count; i++) { if (radians_as_degrees) { - v.set(i, Math::deg_to_rad(spin_sliders[i]->get_value())); + v.set(i, Math::deg_to_rad(spin_sliders[i]->get_true_value())); } else { - v.set(i, spin_sliders[i]->get_value()); + v.set(i, spin_sliders[i]->get_true_value()); } } emit_changed(get_edited_property(), v, linked->is_pressed() ? "" : p_name); diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index a073a2338b0..e7d6b4e1b63 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -44,9 +44,9 @@ bool EditorSpinSlider::is_text_field() const { String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { if (!read_only && grabber->is_visible()) { Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; - return TS->format_number(rtos(get_value())) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key)); + return TS->format_number(rtos(get_true_value())) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key)); } - return TS->format_number(rtos(get_value())); + return TS->format_number(rtos(get_true_value())); } String EditorSpinSlider::get_text_value() const { diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index d7b1a4933d0..d7c3e94533d 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -44,8 +44,13 @@ void Range::_value_changed(double p_value) { GDVIRTUAL_CALL(_value_changed, p_value); } void Range::_value_changed_notify() { - _value_changed(shared->val); - emit_signal(SceneStringName(value_changed), shared->val); + if (Engine::get_singleton()->is_editor_hint()) { + _value_changed(shared->true_val); + emit_signal(SceneStringName(value_changed), shared->true_val); + } else { + _value_changed(shared->val); + emit_signal(SceneStringName(value_changed), shared->val); + } queue_redraw(); } @@ -85,10 +90,12 @@ void Range::Shared::redraw_owners() { } void Range::set_value(double p_val) { - double prev_val = shared->val; + double prev_val = Engine::get_singleton()->is_editor_hint() ? shared->true_val : shared->val; _set_value_no_signal(p_val); - if (shared->val != prev_val) { + if (Engine::get_singleton()->is_editor_hint() && shared->true_val != prev_val) { + shared->emit_value_changed(); + } else if (!Engine::get_singleton()->is_editor_hint() && shared->val != prev_val) { shared->emit_value_changed(); } } @@ -98,6 +105,8 @@ void Range::_set_value_no_signal(double p_val) { return; } + shared->true_val = p_val; + if (shared->step > 0) { p_val = Math::round((p_val - shared->min) / shared->step) * shared->step + shared->min; } @@ -138,7 +147,7 @@ void Range::set_min(double p_min) { shared->min = p_min; shared->max = MAX(shared->max, shared->min); shared->page = CLAMP(shared->page, 0, shared->max - shared->min); - set_value(shared->val); + set_value(shared->true_val); shared->emit_changed("min"); @@ -153,7 +162,7 @@ void Range::set_max(double p_max) { shared->max = max_validated; shared->page = CLAMP(shared->page, 0, shared->max - shared->min); - set_value(shared->val); + set_value(shared->true_val); shared->emit_changed("max"); } @@ -174,7 +183,7 @@ void Range::set_page(double p_page) { } shared->page = page_validated; - set_value(shared->val); + set_value(shared->true_val); shared->emit_changed("page"); } @@ -183,6 +192,10 @@ double Range::get_value() const { return shared->val; } +double Range::get_true_value() const { + return shared->true_val; +} + double Range::get_min() const { return shared->min; } @@ -257,6 +270,7 @@ void Range::unshare() { nshared->min = shared->min; nshared->max = shared->max; nshared->val = shared->val; + nshared->true_val = shared->true_val; nshared->step = shared->step; nshared->page = shared->page; nshared->exp_ratio = shared->exp_ratio; diff --git a/scene/gui/range.h b/scene/gui/range.h index b1c2446deda..6186b17738e 100644 --- a/scene/gui/range.h +++ b/scene/gui/range.h @@ -38,6 +38,7 @@ class Range : public Control { struct Shared { double val = 0.0; + double true_val = 0.0; double min = 0.0; double max = 100.0; double step = 1.0; @@ -82,6 +83,7 @@ public: void set_as_ratio(double p_value); double get_value() const; + double get_true_value() const; double get_min() const; double get_max() const; double get_step() const;