From e794436c69c6cb5ddec6708182945dab39675727 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 29 Aug 2023 11:07:18 +0200 Subject: [PATCH] Cache theme items in TaskTree --- editor/task_tree.cpp | 22 +++++++++++++++++----- editor/task_tree.h | 13 ++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/editor/task_tree.cpp b/editor/task_tree.cpp index c5750cd..76fcb67 100644 --- a/editor/task_tree.cpp +++ b/editor/task_tree.cpp @@ -38,13 +38,13 @@ void TaskTree::_update_item(TreeItem *p_item) { ERR_FAIL_COND_MSG(!task.is_valid(), "Invalid task reference in metadata."); p_item->set_text(0, task->get_task_name()); if (task->is_class_ptr(BTComment::get_class_ptr_static())) { - p_item->set_custom_font(0, (get_theme_font(SNAME("doc_italic"), SNAME("EditorFonts")))); - p_item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); + p_item->set_custom_font(0, theme_cache.comment_font); + p_item->set_custom_color(0, theme_cache.comment_color); } else if (task->get_custom_name().is_empty()) { - p_item->set_custom_font(0, nullptr); + p_item->set_custom_font(0, theme_cache.normal_name_font); p_item->clear_custom_color(0); } else { - p_item->set_custom_font(0, (get_theme_font(SNAME("bold"), SNAME("EditorFonts")))); + p_item->set_custom_font(0, theme_cache.custom_name_font); // p_item->set_custom_color(0, get_theme_color(SNAME("warning_color"), SNAME("Editor"))); } String type_arg; @@ -70,7 +70,7 @@ void TaskTree::_update_item(TreeItem *p_item) { warning_text += warnings[j]; } if (!warning_text.is_empty()) { - p_item->add_button(0, get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")), 0, false, warning_text); + p_item->add_button(0, theme_cache.task_warning_icon, 0, false, warning_text); } // TODO: Update probabilities. @@ -241,6 +241,18 @@ void TaskTree::_drop_data_fw(const Point2 &p_point, const Variant &p_data) { } } +void TaskTree::_update_theme_item_cache() { + Control::_update_theme_item_cache(); + + theme_cache.comment_font = get_theme_font(SNAME("doc_italic"), SNAME("EditorFonts")); + theme_cache.custom_name_font = get_theme_font(SNAME("bold"), SNAME("EditorFonts")); + // theme_cache.normal_name_font = Ref(nullptr); + + theme_cache.task_warning_icon = get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")); + + theme_cache.comment_color = get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")); +} + void TaskTree::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { diff --git a/editor/task_tree.h b/editor/task_tree.h index dd68895..6ee93e4 100644 --- a/editor/task_tree.h +++ b/editor/task_tree.h @@ -23,6 +23,16 @@ private: Ref last_selected; bool editable; + struct ThemeCache { + Ref comment_font; + Ref custom_name_font; + Ref normal_name_font; + + Ref task_warning_icon; + + Color comment_color; + } theme_cache; + TreeItem *_create_tree(const Ref &p_task, TreeItem *p_parent, int p_idx = -1); void _update_item(TreeItem *p_item); void _update_tree(); @@ -38,9 +48,10 @@ private: void _drop_data_fw(const Point2 &p_point, const Variant &p_data); protected: - static void _bind_methods(); + virtual void _update_theme_item_cache() override; void _notification(int p_what); + static void _bind_methods(); public: void load_bt(const Ref &p_behavior_tree);