diff --git a/editor/debugger/behavior_tree_data.cpp b/editor/debugger/behavior_tree_data.cpp index 571c971..04b79d7 100644 --- a/editor/debugger/behavior_tree_data.cpp +++ b/editor/debugger/behavior_tree_data.cpp @@ -40,6 +40,7 @@ BehaviorTreeData::BehaviorTreeData(const Ref &p_instance, const NodePath tasks.push_back(TaskData( id, task->get_task_name(), + !task->get_custom_name().is_empty(), num_children, task->get_status(), task->get_elapsed_time(), @@ -54,6 +55,7 @@ void BehaviorTreeData::serialize(Array &p_arr) { for (const TaskData &td : tasks) { p_arr.push_back(td.id); p_arr.push_back(td.name); + p_arr.push_back(td.is_custom_name); p_arr.push_back(td.num_children); p_arr.push_back(td.status); p_arr.push_back(td.elapsed_time); @@ -74,12 +76,13 @@ void BehaviorTreeData::deserialize(const Array &p_arr) { ERR_FAIL_COND(p_arr.size() < idx + 7); ERR_FAIL_COND(p_arr[idx].get_type() != Variant::INT); ERR_FAIL_COND(p_arr[idx + 1].get_type() != Variant::STRING); - ERR_FAIL_COND(p_arr[idx + 2].get_type() != Variant::INT); + ERR_FAIL_COND(p_arr[idx + 2].get_type() != Variant::BOOL); ERR_FAIL_COND(p_arr[idx + 3].get_type() != Variant::INT); - ERR_FAIL_COND(p_arr[idx + 4].get_type() != Variant::FLOAT); - ERR_FAIL_COND(p_arr[idx + 5].get_type() != Variant::STRING); + ERR_FAIL_COND(p_arr[idx + 4].get_type() != Variant::INT); + ERR_FAIL_COND(p_arr[idx + 5].get_type() != Variant::FLOAT); ERR_FAIL_COND(p_arr[idx + 6].get_type() != Variant::STRING); - tasks.push_back(TaskData(p_arr[idx], p_arr[idx + 1], p_arr[idx + 2], p_arr[idx + 3], p_arr[idx + 4], p_arr[idx + 5], p_arr[idx + 6])); - idx += 7; + ERR_FAIL_COND(p_arr[idx + 7].get_type() != Variant::STRING); + tasks.push_back(TaskData(p_arr[idx], p_arr[idx + 1], p_arr[idx + 2], p_arr[idx + 3], p_arr[idx + 4], p_arr[idx + 5], p_arr[idx + 6], p_arr[idx + 7])); + idx += 8; } } diff --git a/editor/debugger/behavior_tree_data.h b/editor/debugger/behavior_tree_data.h index e0ccb99..43c931f 100644 --- a/editor/debugger/behavior_tree_data.h +++ b/editor/debugger/behavior_tree_data.h @@ -19,15 +19,17 @@ public: struct TaskData { int id = 0; String name; + bool is_custom_name = false; int num_children = 0; int status = 0; double elapsed_time = 0.0; String type_name; String script_path; - TaskData(int p_id, const String &p_name, int p_num_children, int p_status, double p_elapsed_time, const String &p_type_name, const String &p_script_path) { + TaskData(int p_id, const String &p_name, bool p_is_custom_name, int p_num_children, int p_status, double p_elapsed_time, const String &p_type_name, const String &p_script_path) { id = p_id; name = p_name; + is_custom_name = p_is_custom_name; num_children = p_num_children; status = p_status; elapsed_time = p_elapsed_time; diff --git a/editor/debugger/behavior_tree_view.cpp b/editor/debugger/behavior_tree_view.cpp index df5beec..cc575a3 100644 --- a/editor/debugger/behavior_tree_view.cpp +++ b/editor/debugger/behavior_tree_view.cpp @@ -26,17 +26,17 @@ void BehaviorTreeView::_draw_running_status(Object *p_obj, Rect2 p_rect) { p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x); - sbf_running.draw(tree->get_canvas_item(), p_rect); + theme_cache.sbf_running->draw(tree->get_canvas_item(), p_rect); } void BehaviorTreeView::_draw_success_status(Object *p_obj, Rect2 p_rect) { p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x); - sbf_success.draw(tree->get_canvas_item(), p_rect); + theme_cache.sbf_success->draw(tree->get_canvas_item(), p_rect); } void BehaviorTreeView::_draw_failure_status(Object *p_obj, Rect2 p_rect) { p_rect = p_rect.grow_side(SIDE_LEFT, p_rect.get_position().x); - sbf_failure.draw(tree->get_canvas_item(), p_rect); + theme_cache.sbf_failure->draw(tree->get_canvas_item(), p_rect); } void BehaviorTreeView::_item_collapsed(Object *p_obj) { @@ -81,7 +81,12 @@ void BehaviorTreeView::update_tree(const BehaviorTreeData &p_data) { item->set_cell_mode(1, TreeItem::CELL_MODE_ICON); item->set_metadata(0, task_data.id); + item->set_text(0, task_data.name); + if (task_data.is_custom_name) { + item->set_custom_font(0, theme_cache.font_custom_name); + } + item->set_text(2, rtos(Math::snapped(task_data.elapsed_time, 0.01)).pad_decimals(2)); String cors = (task_data.script_path.is_empty()) ? task_data.type_name : task_data.script_path; @@ -90,13 +95,13 @@ void BehaviorTreeView::update_tree(const BehaviorTreeData &p_data) { if (task_data.status == BTTask::SUCCESS) { item->set_custom_draw(0, this, SNAME("_draw_success_status")); - item->set_icon(1, icon_success); + item->set_icon(1, theme_cache.icon_success); } else if (task_data.status == BTTask::FAILURE) { item->set_custom_draw(0, this, SNAME("_draw_failure_status")); - item->set_icon(1, icon_failure); + item->set_icon(1, theme_cache.icon_failure); } else if (task_data.status == BTTask::RUNNING) { item->set_custom_draw(0, this, SNAME("_draw_running_status")); - item->set_icon(1, icon_running); + item->set_icon(1, theme_cache.icon_running); } if (task_data.id == selected_id) { @@ -119,34 +124,39 @@ void BehaviorTreeView::clear() { collapsed_ids.clear(); } -void BehaviorTreeView::_notification(int p_notification) { - if (p_notification == NOTIFICATION_THEME_CHANGED) { - icon_running = get_theme_icon(SNAME("LimboExtraClock"), SNAME("EditorIcons")); - icon_success = get_theme_icon(SNAME("BTAlwaysSucceed"), SNAME("EditorIcons")); - icon_failure = get_theme_icon(SNAME("BTAlwaysFail"), SNAME("EditorIcons")); +void BehaviorTreeView::_update_theme_item_cache() { + Control::_update_theme_item_cache(); - Color running_border = Color::html("#fea900"); - Color running_fill = Color(running_border, 0.1); - Color success_border = Color::html("#2fa139"); - Color success_fill = Color(success_border, 0.1); - Color failure_border = Color::html("#cd3838"); - Color failure_fill = Color(failure_border, 0.1); + theme_cache.icon_running = get_theme_icon(SNAME("LimboExtraClock"), SNAME("EditorIcons")); + theme_cache.icon_success = get_theme_icon(SNAME("BTAlwaysSucceed"), SNAME("EditorIcons")); + theme_cache.icon_failure = get_theme_icon(SNAME("BTAlwaysFail"), SNAME("EditorIcons")); - sbf_running.set_border_color(running_border); - sbf_running.set_bg_color(running_fill); - sbf_running.set_border_width(SIDE_LEFT, 4.0); - sbf_running.set_border_width(SIDE_RIGHT, 4.0); + theme_cache.font_custom_name = get_theme_font(SNAME("bold"), SNAME("EditorFonts")); - sbf_success.set_border_color(success_border); - sbf_success.set_bg_color(success_fill); - sbf_success.set_border_width(SIDE_LEFT, 4.0); - sbf_success.set_border_width(SIDE_RIGHT, 4.0); + Color running_border = Color::html("#fea900"); + Color running_fill = Color(running_border, 0.1); + Color success_border = Color::html("#2fa139"); + Color success_fill = Color(success_border, 0.1); + Color failure_border = Color::html("#cd3838"); + Color failure_fill = Color(failure_border, 0.1); - sbf_failure.set_border_color(failure_border); - sbf_failure.set_bg_color(failure_fill); - sbf_failure.set_border_width(SIDE_LEFT, 4.0); - sbf_failure.set_border_width(SIDE_RIGHT, 4.0); - } + theme_cache.sbf_running.instantiate(); + theme_cache.sbf_running->set_border_color(running_border); + theme_cache.sbf_running->set_bg_color(running_fill); + theme_cache.sbf_running->set_border_width(SIDE_LEFT, 4.0); + theme_cache.sbf_running->set_border_width(SIDE_RIGHT, 4.0); + + theme_cache.sbf_success.instantiate(); + theme_cache.sbf_success->set_border_color(success_border); + theme_cache.sbf_success->set_bg_color(success_fill); + theme_cache.sbf_success->set_border_width(SIDE_LEFT, 4.0); + theme_cache.sbf_success->set_border_width(SIDE_RIGHT, 4.0); + + theme_cache.sbf_failure.instantiate(); + theme_cache.sbf_failure->set_border_color(failure_border); + theme_cache.sbf_failure->set_bg_color(failure_fill); + theme_cache.sbf_failure->set_border_width(SIDE_LEFT, 4.0); + theme_cache.sbf_failure->set_border_width(SIDE_RIGHT, 4.0); } void BehaviorTreeView::_bind_methods() { @@ -171,4 +181,4 @@ BehaviorTreeView::BehaviorTreeView() { tree->connect(SNAME("item_collapsed"), callable_mp(this, &BehaviorTreeView::_item_collapsed)); } -#endif // TOOLS_ENABLED \ No newline at end of file +#endif // TOOLS_ENABLED diff --git a/editor/debugger/behavior_tree_view.h b/editor/debugger/behavior_tree_view.h index 8a78b58..e825a5b 100644 --- a/editor/debugger/behavior_tree_view.h +++ b/editor/debugger/behavior_tree_view.h @@ -28,14 +28,20 @@ class BehaviorTreeView : public Control { private: Tree *tree; - StyleBoxFlat sbf_running; - StyleBoxFlat sbf_success; - StyleBoxFlat sbf_failure; - Vector collapsed_ids; - Ref icon_running; - Ref icon_success; - Ref icon_failure; + struct ThemeCache { + Ref sbf_running; + Ref sbf_success; + Ref sbf_failure; + + Ref icon_running; + Ref icon_success; + Ref icon_failure; + + Ref font_custom_name; + } theme_cache; + + Vector collapsed_ids; void _draw_success_status(Object *p_obj, Rect2 p_rect); void _draw_running_status(Object *p_obj, Rect2 p_rect); @@ -43,9 +49,9 @@ private: void _item_collapsed(Object *p_obj); protected: - static void _bind_methods(); + virtual void _update_theme_item_cache() override; - void _notification(int p_notification); + static void _bind_methods(); public: void update_tree(const BehaviorTreeData &p_data);