Editor: Remember collapsed items in task tree
This commit is contained in:
parent
b0e4c15982
commit
3e32051791
|
@ -88,6 +88,14 @@ void BTTask::_set_children(Array p_children) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BTTask::set_display_collapsed(bool p_display_collapsed) {
|
||||||
|
data.display_collapsed = p_display_collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BTTask::is_displayed_collapsed() const {
|
||||||
|
return data.display_collapsed;
|
||||||
|
}
|
||||||
|
|
||||||
String BTTask::get_task_name() {
|
String BTTask::get_task_name() {
|
||||||
if (data.custom_name.is_empty()) {
|
if (data.custom_name.is_empty()) {
|
||||||
#ifdef LIMBOAI_MODULE
|
#ifdef LIMBOAI_MODULE
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
Vector<Ref<BTTask>> children;
|
Vector<Ref<BTTask>> children;
|
||||||
Status status = FRESH;
|
Status status = FRESH;
|
||||||
double elapsed = 0.0;
|
double elapsed = 0.0;
|
||||||
|
bool display_collapsed = false;
|
||||||
} data;
|
} data;
|
||||||
|
|
||||||
Array _get_children() const;
|
Array _get_children() const;
|
||||||
|
@ -115,6 +116,9 @@ public:
|
||||||
_FORCE_INLINE_ Node *get_agent() const { return data.agent; }
|
_FORCE_INLINE_ Node *get_agent() const { return data.agent; }
|
||||||
void set_agent(Node *p_agent) { data.agent = p_agent; }
|
void set_agent(Node *p_agent) { data.agent = p_agent; }
|
||||||
|
|
||||||
|
void set_display_collapsed(bool p_display_collapsed);
|
||||||
|
bool is_displayed_collapsed() const;
|
||||||
|
|
||||||
String get_custom_name() const { return data.custom_name; }
|
String get_custom_name() const { return data.custom_name; }
|
||||||
void set_custom_name(const String &p_name);
|
void set_custom_name(const String &p_name);
|
||||||
String get_task_name();
|
String get_task_name();
|
||||||
|
|
|
@ -81,6 +81,7 @@ void TaskTree::_update_item(TreeItem *p_item) {
|
||||||
p_item->set_icon(0, LimboUtility::get_singleton()->get_task_icon(type_arg));
|
p_item->set_icon(0, LimboUtility::get_singleton()->get_task_icon(type_arg));
|
||||||
p_item->set_icon_max_width(0, 16 * EDSCALE);
|
p_item->set_icon_max_width(0, 16 * EDSCALE);
|
||||||
p_item->set_editable(0, false);
|
p_item->set_editable(0, false);
|
||||||
|
p_item->set_collapsed(task->is_displayed_collapsed());
|
||||||
|
|
||||||
for (int i = 0; i < p_item->get_button_count(0); i++) {
|
for (int i = 0; i < p_item->get_button_count(0); i++) {
|
||||||
p_item->erase_button(0, i);
|
p_item->erase_button(0, i);
|
||||||
|
@ -111,7 +112,9 @@ void TaskTree::_update_tree() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bt->get_root_task().is_valid()) {
|
if (bt->get_root_task().is_valid()) {
|
||||||
|
updating_tree = true;
|
||||||
_create_tree(bt->get_root_task(), nullptr);
|
_create_tree(bt->get_root_task(), nullptr);
|
||||||
|
updating_tree = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem *item = _find_item(sel);
|
TreeItem *item = _find_item(sel);
|
||||||
|
@ -167,6 +170,21 @@ void TaskTree::_on_item_activated() {
|
||||||
emit_signal(LW_NAME(task_activated));
|
emit_signal(LW_NAME(task_activated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TaskTree::_on_item_collapsed(Object *p_obj) {
|
||||||
|
if (updating_tree) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeItem *item = Object::cast_to<TreeItem>(p_obj);
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<BTTask> task = item->get_metadata(0);
|
||||||
|
ERR_FAIL_NULL(task);
|
||||||
|
task->set_display_collapsed(item->is_collapsed());
|
||||||
|
}
|
||||||
|
|
||||||
void TaskTree::_on_task_changed() {
|
void TaskTree::_on_task_changed() {
|
||||||
_update_item(tree->get_selected());
|
_update_item(tree->get_selected());
|
||||||
}
|
}
|
||||||
|
@ -183,7 +201,9 @@ void TaskTree::load_bt(const Ref<BehaviorTree> &p_behavior_tree) {
|
||||||
tree->clear();
|
tree->clear();
|
||||||
probability_rect_cache.clear();
|
probability_rect_cache.clear();
|
||||||
if (bt->get_root_task().is_valid()) {
|
if (bt->get_root_task().is_valid()) {
|
||||||
|
updating_tree = true;
|
||||||
_create_tree(bt->get_root_task(), nullptr);
|
_create_tree(bt->get_root_task(), nullptr);
|
||||||
|
updating_tree = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,6 +386,7 @@ void TaskTree::_notification(int p_what) {
|
||||||
tree->connect("item_mouse_selected", callable_mp(this, &TaskTree::_on_item_mouse_selected));
|
tree->connect("item_mouse_selected", callable_mp(this, &TaskTree::_on_item_mouse_selected));
|
||||||
tree->connect("item_selected", callable_mp(this, &TaskTree::_on_item_selected));
|
tree->connect("item_selected", callable_mp(this, &TaskTree::_on_item_selected));
|
||||||
tree->connect("item_activated", callable_mp(this, &TaskTree::_on_item_activated));
|
tree->connect("item_activated", callable_mp(this, &TaskTree::_on_item_activated));
|
||||||
|
tree->connect("item_collapsed", callable_mp(this, &TaskTree::_on_item_collapsed));
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_THEME_CHANGED: {
|
case NOTIFICATION_THEME_CHANGED: {
|
||||||
_do_update_theme_item_cache();
|
_do_update_theme_item_cache();
|
||||||
|
@ -399,6 +420,7 @@ void TaskTree::_bind_methods() {
|
||||||
|
|
||||||
TaskTree::TaskTree() {
|
TaskTree::TaskTree() {
|
||||||
editable = true;
|
editable = true;
|
||||||
|
updating_tree = false;
|
||||||
|
|
||||||
tree = memnew(Tree);
|
tree = memnew(Tree);
|
||||||
add_child(tree);
|
add_child(tree);
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
Ref<BehaviorTree> bt;
|
Ref<BehaviorTree> bt;
|
||||||
Ref<BTTask> last_selected;
|
Ref<BTTask> last_selected;
|
||||||
bool editable;
|
bool editable;
|
||||||
|
bool updating_tree;
|
||||||
HashMap<RECT_CACHE_KEY, Rect2> probability_rect_cache;
|
HashMap<RECT_CACHE_KEY, Rect2> probability_rect_cache;
|
||||||
|
|
||||||
struct ThemeCache {
|
struct ThemeCache {
|
||||||
|
@ -67,6 +68,7 @@ private:
|
||||||
|
|
||||||
void _on_item_selected();
|
void _on_item_selected();
|
||||||
void _on_item_activated();
|
void _on_item_activated();
|
||||||
|
void _on_item_collapsed(Object *p_obj);
|
||||||
void _on_item_mouse_selected(const Vector2 &p_pos, MouseButton p_button_index);
|
void _on_item_mouse_selected(const Vector2 &p_pos, MouseButton p_button_index);
|
||||||
void _on_task_changed();
|
void _on_task_changed();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue