summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
authorZi Ye <major.mcdoom@gmail.com>2024-02-22 18:01:28 -0600
committerZi Ye <major.mcdoom@gmail.com>2024-03-24 15:12:11 -0500
commitd827b34ea822382155258e79123f3fff8222fde3 (patch)
treee6a7e971019d2da16922f9bf2265e3bedabaee7b /editor
parent99ff024f78f65ba0bc54fb409cfeca43ba2008fe (diff)
downloadredot-engine-d827b34ea822382155258e79123f3fff8222fde3.tar.gz
Fixed undo/redo behaviour of color picker and added ability to cancel/confirm color selection.
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_properties.cpp16
-rw-r--r--editor/editor_properties.h3
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp2
3 files changed, 17 insertions, 4 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 0e3b408996..b7380c9fc2 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 fa759d5d19..ce164733fe 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 @@ protected:
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 964558ee78..c83c47577d 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<Resource> &p_par
} else if (Object::cast_to<EditorPropertyEnum>(prop)) {
prop->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
Object::cast_to<EditorPropertyEnum>(prop)->set_option_button_clip(false);
+ } else if (Object::cast_to<EditorPropertyColor>(prop)) {
+ Object::cast_to<EditorPropertyColor>(prop)->set_live_changes_enabled(false);
}
editors.push_back(prop);