Fix connected signal error when loading BT for the second time

This commit is contained in:
Serhii Snitsaruk 2024-07-05 20:32:53 +02:00
parent 2973590533
commit 2813728785
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
1 changed files with 12 additions and 9 deletions

View File

@ -221,6 +221,8 @@ void LimboAIEditor::_load_bt(String p_path) {
void LimboAIEditor::_disable_editing() { void LimboAIEditor::_disable_editing() {
task_tree->unload(); task_tree->unload();
task_palette->hide(); task_palette->hide();
task_tree->hide();
usage_hint->show();
} }
void LimboAIEditor::edit_bt(Ref<BehaviorTree> p_behavior_tree, bool p_force_refresh) { void LimboAIEditor::edit_bt(Ref<BehaviorTree> p_behavior_tree, bool p_force_refresh) {
@ -235,14 +237,9 @@ void LimboAIEditor::edit_bt(Ref<BehaviorTree> p_behavior_tree, bool p_force_refr
p_behavior_tree->notify_property_list_changed(); p_behavior_tree->notify_property_list_changed();
#endif // LIMBOAI_MODULE #endif // LIMBOAI_MODULE
if (task_tree->get_bt().is_valid() &&
task_tree->get_bt()->is_connected(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty).bind(true))) {
task_tree->get_bt()->disconnect(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty).bind(true));
}
task_tree->load_bt(p_behavior_tree); task_tree->load_bt(p_behavior_tree);
if (task_tree->get_bt().is_valid()) { if (task_tree->get_bt().is_valid() && !task_tree->get_bt()->is_connected(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty))) {
task_tree->get_bt()->connect(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty).bind(true)); task_tree->get_bt()->connect(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty).bind(true));
} }
@ -959,6 +956,10 @@ void LimboAIEditor::_tab_clicked(int p_tab) {
void LimboAIEditor::_tab_closed(int p_tab) { void LimboAIEditor::_tab_closed(int p_tab) {
ERR_FAIL_INDEX(p_tab, history.size()); ERR_FAIL_INDEX(p_tab, history.size());
Ref<BehaviorTree> history_bt = history[p_tab];
if (history_bt.is_valid() && history_bt->is_connected(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty))) {
history_bt->disconnect(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty));
}
history.remove_at(p_tab); history.remove_at(p_tab);
idx_history = MIN(idx_history, history.size() - 1); idx_history = MIN(idx_history, history.size() - 1);
if (idx_history < 0) { if (idx_history < 0) {
@ -1302,9 +1303,11 @@ void LimboAIEditor::_notification(int p_what) {
cf->set_value("bt_editor", "bteditor_hsplit", split_offset); cf->set_value("bt_editor", "bteditor_hsplit", split_offset);
cf->save(conf_path); cf->save(conf_path);
if (task_tree->get_bt().is_valid() && task_tree->unload();
task_tree->get_bt()->is_connected(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty).bind(true))) { for (int i = 0; i < history.size(); i++) {
task_tree->get_bt()->disconnect(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty).bind(true)); if (history[i]->is_connected(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty))) {
history[i]->disconnect(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty));
}
} }
} break; } break;
case NOTIFICATION_READY: { case NOTIFICATION_READY: {