Skip to content

Commit

Permalink
Merge pull request #81061 from KoBeWi/remembering_things_is_so_meta
Browse files Browse the repository at this point in the history
Properly remember custom text color in scene tree
  • Loading branch information
akien-mga committed Aug 28, 2023
2 parents cd5c007 + b88007b commit b3811a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
Expand Down
1 change: 1 addition & 0 deletions editor/gui/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b3811a3

Please sign in to comment.