diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 0e3b408996b1..b7380c9fc2d9 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2630,16 +2630,22 @@ void EditorPropertyColor::_set_read_only(bool p_read_only) { } void EditorPropertyColor::_color_changed(const Color &p_color) { + if (!live_changes_enabled) { + return; + } + // Cancel the color change if the current color is identical to the new one. - if (get_edited_property_value() == p_color) { + if (((Color)get_edited_property_value()).is_equal_approx(p_color)) { return; } - emit_changed(get_edited_property(), p_color, "", true); + // Preview color change, bypassing undo/redo. + get_edited_object()->set(get_edited_property(), p_color); } void EditorPropertyColor::_popup_closed() { - if (picker->get_pick_color() != last_color) { + get_edited_object()->set(get_edited_property(), last_color); + if (!picker->get_pick_color().is_equal_approx(last_color)) { emit_changed(get_edited_property(), picker->get_pick_color(), "", false); } } @@ -2682,6 +2688,10 @@ void EditorPropertyColor::setup(bool p_show_alpha) { picker->set_edit_alpha(p_show_alpha); } +void EditorPropertyColor::set_live_changes_enabled(bool p_enabled) { + live_changes_enabled = p_enabled; +} + EditorPropertyColor::EditorPropertyColor() { picker = memnew(ColorPickerButton); add_child(picker); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index fa759d5d19d9..ce164733fee9 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -621,10 +621,10 @@ class EditorPropertyColor : public EditorProperty { ColorPickerButton *picker = nullptr; void _color_changed(const Color &p_color); void _popup_closed(); - void _picker_created(); void _picker_opening(); Color last_color; + bool live_changes_enabled = true; protected: virtual void _set_read_only(bool p_read_only) override; @@ -633,6 +633,7 @@ class EditorPropertyColor : public EditorProperty { public: virtual void update_property() override; void setup(bool p_show_alpha); + void set_live_changes_enabled(bool p_enabled); EditorPropertyColor(); }; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 964558ee78d0..c83c47577d30 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -6922,6 +6922,8 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref &p_par } else if (Object::cast_to(prop)) { prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); Object::cast_to(prop)->set_option_button_clip(false); + } else if (Object::cast_to(prop)) { + Object::cast_to(prop)->set_live_changes_enabled(false); } editors.push_back(prop); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index ee2122f2696a..3b62f6c23d3e 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -714,6 +714,10 @@ Color ColorPicker::get_pick_color() const { return color; } +Color ColorPicker::get_old_color() const { + return old_color; +} + void ColorPicker::set_picker_shape(PickerShapeType p_shape) { ERR_FAIL_INDEX(p_shape, SHAPE_MAX); if (p_shape == current_shape) { @@ -1514,7 +1518,7 @@ void ColorPicker::_pick_finished() { return; } - if (Input::get_singleton()->is_key_pressed(Key::ESCAPE)) { + if (Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"))) { set_pick_color(old_color); } else { emit_signal(SNAME("color_changed"), color); @@ -1627,7 +1631,12 @@ void ColorPicker::_html_focus_exit() { if (c_text->is_menu_visible()) { return; } - _html_submitted(c_text->get_text()); + + if (is_visible_in_tree()) { + _html_submitted(c_text->get_text()); + } else { + _update_text_value(); + } } void ColorPicker::set_can_add_swatches(bool p_enabled) { @@ -2026,6 +2035,15 @@ ColorPicker::~ColorPicker() { ///////////////// +void ColorPickerPopupPanel::_input_from_window(const Ref &p_event) { + if (p_event->is_action_pressed(SNAME("ui_accept"), false, true)) { + _close_pressed(); + } + PopupPanel::_input_from_window(p_event); +} + +///////////////// + void ColorPickerButton::_about_to_popup() { set_pressed(true); if (picker) { @@ -2040,6 +2058,10 @@ void ColorPickerButton::_color_changed(const Color &p_color) { } void ColorPickerButton::_modal_closed() { + if (Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"))) { + set_pick_color(picker->get_old_color()); + emit_signal(SNAME("color_changed"), color); + } emit_signal(SNAME("popup_closed")); set_pressed(false); } @@ -2137,7 +2159,7 @@ PopupPanel *ColorPickerButton::get_popup() { void ColorPickerButton::_update_picker() { if (!picker) { - popup = memnew(PopupPanel); + popup = memnew(ColorPickerPopupPanel); popup->set_wrap_controls(true); picker = memnew(ColorPicker); picker->set_anchors_and_offsets_preset(PRESET_FULL_RECT); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 282926d1ff8d..ad028584b11b 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -317,12 +317,11 @@ class ColorPicker : public VBoxContainer { void set_edit_alpha(bool p_show); bool is_editing_alpha() const; - int get_preset_size(); - void _set_pick_color(const Color &p_color, bool p_update_sliders); void set_pick_color(const Color &p_color); Color get_pick_color() const; void set_old_color(const Color &p_color); + Color get_old_color() const; void set_display_old_color(bool p_enabled); bool is_displaying_old_color() const; @@ -375,6 +374,10 @@ class ColorPicker : public VBoxContainer { ~ColorPicker(); }; +class ColorPickerPopupPanel : public PopupPanel { + virtual void _input_from_window(const Ref &p_event) override; +}; + class ColorPickerButton : public Button { GDCLASS(ColorPickerButton, Button);