From b88007b6c55bd383a9a0f052cf4a7f6d8dd56e4e Mon Sep 17 00:00:00 2001 From: kobewi Date: Mon, 28 Aug 2023 02:37:47 +0200 Subject: [PATCH] Properly remember custom text color in scene tree --- editor/gui/scene_tree_editor.cpp | 26 ++++++++++++++++++-------- editor/gui/scene_tree_editor.h | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 1a02e45f846..0862af37b68 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -234,7 +234,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { item->add_button(0, get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), BUTTON_SCRIPT); } else { //has no script (or script is a custom type) - item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); + _set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); item->set_selectable(0, false); if (!scr.is_null()) { // make sure to mark the script if a custom type @@ -251,11 +251,11 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { node_name += " " + TTR("(Connecting From)"); } item->set_text(0, node_name); - item->set_custom_color(0, accent); + _set_item_custom_color(item, accent); } } else if (part_of_subscene) { if (valid_types.size() == 0) { - item->set_custom_color(0, get_theme_color(SNAME("warning_color"), SNAME("Editor"))); + _set_item_custom_color(item, get_theme_color(SNAME("warning_color"), SNAME("Editor"))); } } else if (marked.has(p_node)) { String node_name = p_node->get_name(); @@ -264,15 +264,15 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { } item->set_text(0, node_name); item->set_selectable(0, marked_selectable); - item->set_custom_color(0, get_theme_color(SNAME("accent_color"), SNAME("Editor"))); + _set_item_custom_color(item, get_theme_color(SNAME("accent_color"), SNAME("Editor"))); } else if (!p_node->can_process()) { - item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); + _set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); } else if (!marked_selectable && !marked_children_selectable) { Node *node = p_node; while (node) { if (marked.has(node)) { item->set_selectable(0, false); - item->set_custom_color(0, get_theme_color(SNAME("error_color"), SNAME("Editor"))); + _set_item_custom_color(item, get_theme_color(SNAME("error_color"), SNAME("Editor"))); break; } node = node->get_parent(); @@ -500,7 +500,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { } if (!valid) { - item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); + _set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); item->set_selectable(0, false); } } @@ -550,6 +550,11 @@ void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) { } } +void SceneTreeEditor::_set_item_custom_color(TreeItem *p_item, Color p_color) { + p_item->set_custom_color(0, p_color); + p_item->set_meta(SNAME("custom_color"), p_color); +} + void SceneTreeEditor::_node_script_changed(Node *p_node) { if (tree_dirty) { return; @@ -661,7 +666,12 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select } if (selectable) { - p_parent->clear_custom_color(0); + Color custom_color = p_parent->get_meta(SNAME("custom_color"), Color(0, 0, 0, 0)); + if (custom_color == Color(0, 0, 0, 0)) { + p_parent->clear_custom_color(0); + } else { + p_parent->set_custom_color(0, custom_color); + } p_parent->set_selectable(0, true); } else if (keep_for_children) { p_parent->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); diff --git a/editor/gui/scene_tree_editor.h b/editor/gui/scene_tree_editor.h index 9e38b49bd59..f38c76a21aa 100644 --- a/editor/gui/scene_tree_editor.h +++ b/editor/gui/scene_tree_editor.h @@ -117,6 +117,7 @@ class SceneTreeEditor : public Control { void _node_script_changed(Node *p_node); void _node_visibility_changed(Node *p_node); void _update_visibility_color(Node *p_node, TreeItem *p_item); + void _set_item_custom_color(TreeItem *p_item, Color p_color); void _selection_changed(); Node *get_scene_node();