From 7ab7a9d09834726404f2fa51cfc12c3154c9dd37 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 17 May 2024 21:48:34 +0200 Subject: [PATCH] BlackboardPlan: Improve inspector update while manually typing in mappings Fixes property glitches observed while a map variable is typed in. --- blackboard/blackboard_plan.cpp | 13 +++++++++++-- editor/editor_property_variable_name.cpp | 20 ++++++++++++++++---- editor/editor_property_variable_name.h | 7 ++++++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index b49b4e0..6d9c7ff 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -31,12 +31,21 @@ bool BlackboardPlan::_set(const StringName &p_name, const Variant &p_value) { if (name_str.begins_with("mapping/")) { StringName mapped_var_name = name_str.get_slicec('/', 1); StringName value = p_value; + bool properties_changed = false; if (value == StringName()) { - parent_scope_mapping.erase(mapped_var_name); + if (parent_scope_mapping.has(mapped_var_name)) { + properties_changed = true; + parent_scope_mapping.erase(mapped_var_name); + } } else { + if (!parent_scope_mapping.has(mapped_var_name)) { + properties_changed = true; + } parent_scope_mapping[mapped_var_name] = value; } - notify_property_list_changed(); + if (properties_changed) { + notify_property_list_changed(); + } return true; } diff --git a/editor/editor_property_variable_name.cpp b/editor/editor_property_variable_name.cpp index 9975930..0c40293 100644 --- a/editor/editor_property_variable_name.cpp +++ b/editor/editor_property_variable_name.cpp @@ -31,6 +31,8 @@ #include #endif // LIMBOAI_GDEXTENSION +int EditorPropertyVariableName::last_caret_column = 0; + //***** EditorPropertyVariableName void EditorPropertyVariableName::_show_variables_popup() { @@ -54,13 +56,18 @@ void EditorPropertyVariableName::_show_variables_popup() { variables_popup->popup(rect); } -void EditorPropertyVariableName::_name_changed(const String &p_new_name, bool p_changing) { - emit_changed(get_edited_property(), p_new_name, StringName(), p_changing); +void EditorPropertyVariableName::_name_changed(const String &p_new_name) { + if (updating) { + return; + } + + emit_changed(get_edited_property(), p_new_name); + last_caret_column = name_edit->get_caret_column(); _update_status(); } void EditorPropertyVariableName::_name_submitted() { - _name_changed(name_edit->get_text(), false); + _name_changed(name_edit->get_text()); if (name_edit->has_focus()) { name_edit->release_focus(); } @@ -131,13 +138,18 @@ void EditorPropertyVariableName::update_property() { void EditorPropertyVariableName::_update_property() { #endif // LIMBOAI_GDEXTENSION String s = get_edited_object()->get(get_edited_property()); + updating = true; if (name_edit->get_text() != s) { int caret = name_edit->get_caret_column(); + if (caret == 0) { + caret = last_caret_column; + } name_edit->set_text(s); name_edit->set_caret_column(caret); } name_edit->set_editable(!is_read_only()); _update_status(); + updating = false; } void EditorPropertyVariableName::setup(const Ref &p_plan, bool p_allow_empty, Variant::Type p_type, PropertyHint p_hint, String p_hint_string, Variant p_default_value) { @@ -153,7 +165,7 @@ void EditorPropertyVariableName::setup(const Ref &p_plan, bool p void EditorPropertyVariableName::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - name_edit->connect(LW_NAME(text_changed), callable_mp(this, &EditorPropertyVariableName::_name_changed).bind(true)); + name_edit->connect(LW_NAME(text_changed), callable_mp(this, &EditorPropertyVariableName::_name_changed)); name_edit->connect(LW_NAME(text_submitted), callable_mp(this, &EditorPropertyVariableName::_name_submitted).unbind(1)); name_edit->connect(LW_NAME(focus_exited), callable_mp(this, &EditorPropertyVariableName::_name_submitted)); variables_popup->connect(LW_NAME(id_pressed), callable_mp(this, &EditorPropertyVariableName::_variable_selected)); diff --git a/editor/editor_property_variable_name.h b/editor/editor_property_variable_name.h index 0ea1a55..bff47a9 100644 --- a/editor/editor_property_variable_name.h +++ b/editor/editor_property_variable_name.h @@ -31,6 +31,9 @@ using namespace godot; class EditorPropertyVariableName : public EditorProperty { GDCLASS(EditorPropertyVariableName, EditorProperty); +private: + static int last_caret_column; + private: struct ThemeCache { Ref var_add_icon; @@ -50,13 +53,15 @@ private: String default_hint_string; Variant default_value; + bool updating = false; + LineEdit *name_edit; Button *drop_btn; Button *status_btn; PopupMenu *variables_popup; void _show_variables_popup(); - void _name_changed(const String &p_new_name, bool p_changing); + void _name_changed(const String &p_new_name); void _name_submitted(); void _variable_selected(int p_id); void _update_status();