diff --git a/debugger/behavior_tree_view.cpp b/debugger/behavior_tree_view.cpp index 9a81bf0..48c9fa8 100644 --- a/debugger/behavior_tree_view.cpp +++ b/debugger/behavior_tree_view.cpp @@ -65,18 +65,22 @@ void BehaviorTreeView::update_tree(const BehaviorTreeData &p_data) { TreeItem *item = tree->create_item(parent); // Do this first because it resets properties of the cell... item->set_cell_mode(0, TreeItem::CELL_MODE_CUSTOM); + item->set_cell_mode(1, TreeItem::CELL_MODE_ICON); item->set_metadata(0, task_data.id); item->set_text(0, task_data.name); item->set_icon(0, LimboUtility::get_singleton()->get_task_icon(task_data.type_name)); - item->set_text(1, rtos(Math::snapped(task_data.elapsed_time, 0.01))); + item->set_text(2, rtos(Math::snapped(task_data.elapsed_time, 0.01))); if (task_data.status == BTTask::SUCCESS) { item->set_custom_draw(0, this, SNAME("_draw_success_status")); + item->set_icon(1, 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); } else if (task_data.status == BTTask::RUNNING) { item->set_custom_draw(0, this, SNAME("_draw_running_status")); + item->set_icon(1, icon_running); } if (task_data.id == selected_id) { @@ -99,6 +103,14 @@ void BehaviorTreeView::clear() { collapsed_ids.clear(); } +void BehaviorTreeView::_notification(int p_notification) { + if (p_notification == NOTIFICATION_THEME_CHANGED) { + icon_running = get_theme_icon(SNAME("BTClock"), SNAME("EditorIcons")); + icon_success = get_theme_icon(SNAME("BTAlwaysSucceed"), SNAME("EditorIcons")); + icon_failure = get_theme_icon(SNAME("BTAlwaysFail"), SNAME("EditorIcons")); + } +} + void BehaviorTreeView::_bind_methods() { ClassDB::bind_method(D_METHOD("_draw_running_status"), &BehaviorTreeView::_draw_running_status); ClassDB::bind_method(D_METHOD("_draw_success_status"), &BehaviorTreeView::_draw_success_status); @@ -109,10 +121,12 @@ void BehaviorTreeView::_bind_methods() { BehaviorTreeView::BehaviorTreeView() { tree = memnew(Tree); add_child(tree); - tree->set_columns(2); + tree->set_columns(3); tree->set_column_expand(0, true); tree->set_column_expand(1, false); - tree->set_column_custom_minimum_width(1, 40.0 * EDSCALE); + tree->set_column_expand(2, false); + tree->set_column_custom_minimum_width(1, 18.0 * EDSCALE); + tree->set_column_custom_minimum_width(2, 40.0 * EDSCALE); tree->set_anchor(SIDE_RIGHT, ANCHOR_END); tree->set_anchor(SIDE_BOTTOM, ANCHOR_END); diff --git a/debugger/behavior_tree_view.h b/debugger/behavior_tree_view.h index 9a9a024..563e2ae 100644 --- a/debugger/behavior_tree_view.h +++ b/debugger/behavior_tree_view.h @@ -9,6 +9,7 @@ #include "scene/gui/control.h" #include "scene/gui/tree.h" #include "scene/resources/style_box.h" +#include "scene/resources/texture.h" class BehaviorTreeView : public Control { GDCLASS(BehaviorTreeView, Control); @@ -20,6 +21,10 @@ private: StyleBoxFlat sbf_failure; Vector collapsed_ids; + Ref icon_running; + Ref icon_success; + Ref icon_failure; + void _draw_success_status(Object *p_obj, Rect2 p_rect); void _draw_running_status(Object *p_obj, Rect2 p_rect); void _draw_failure_status(Object *p_obj, Rect2 p_rect); @@ -28,6 +33,8 @@ private: protected: static void _bind_methods(); + void _notification(int p_notification); + public: void update_tree(const BehaviorTreeData &p_data); void clear(); diff --git a/debugger/limbo_debugger_plugin.cpp b/debugger/limbo_debugger_plugin.cpp index 7aa7c61..1c00bba 100644 --- a/debugger/limbo_debugger_plugin.cpp +++ b/debugger/limbo_debugger_plugin.cpp @@ -36,7 +36,7 @@ void LimboDebuggerTab::stop_session() { session->send_message("limboai:stop_session", Array()); } -void LimboDebuggerTab::update_bt_list(const Array &p_items) { +void LimboDebuggerTab::update_bt_list(const Array &p_node_paths) { // Remember selected item. String selected_bt = ""; if (bt_list->is_anything_selected()) { @@ -45,9 +45,11 @@ void LimboDebuggerTab::update_bt_list(const Array &p_items) { bt_list->clear(); int select_idx = -1; - for (int i = 0; i < p_items.size(); i++) { - bt_list->add_item(p_items[i]); - if (p_items[i] == selected_bt) { + for (int i = 0; i < p_node_paths.size(); i++) { + bt_list->add_item(p_node_paths[i]); + // Make item text shortened from the left, e.g ".../Agent/BTPlayer". + bt_list->set_item_text_direction(i, TEXT_DIRECTION_RTL); + if (p_node_paths[i] == selected_bt) { select_idx = i; } } @@ -83,7 +85,7 @@ LimboDebuggerTab::LimboDebuggerTab(Ref p_session) { bt_list = memnew(ItemList); hsc->add_child(bt_list); - bt_list->set_custom_minimum_size(Size2(280.0 * EDSCALE, 0.0)); + bt_list->set_custom_minimum_size(Size2(240.0 * EDSCALE, 0.0)); bt_list->connect(SNAME("item_selected"), callable_mp(this, &LimboDebuggerTab::_bt_selected)); view_box = memnew(VBoxContainer); diff --git a/debugger/limbo_debugger_plugin.h b/debugger/limbo_debugger_plugin.h index 7766a55..cd2f10a 100644 --- a/debugger/limbo_debugger_plugin.h +++ b/debugger/limbo_debugger_plugin.h @@ -34,7 +34,7 @@ private: public: void start_session(); void stop_session(); - void update_bt_list(const Array &p_items); + void update_bt_list(const Array &p_node_paths); BehaviorTreeView *get_behavior_tree_view() const { return bt_view; } LimboDebuggerTab(Ref p_session); diff --git a/icons/BTClock.svg b/icons/BTClock.svg new file mode 100644 index 0000000..dfedd92 --- /dev/null +++ b/icons/BTClock.svg @@ -0,0 +1 @@ + \ No newline at end of file