diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index f1a07a5..a52cb6c 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -175,14 +175,27 @@ void BlackboardPlan::rename_var(const String &p_name, const String &p_new_name) emit_changed(); } -void BlackboardPlan::swap_vars(int p_idx_a, int p_idx_b) { - ERR_FAIL_INDEX(p_idx_a, (int)var_map.size()); - ERR_FAIL_INDEX(p_idx_b, (int)var_map.size()); +void BlackboardPlan::move_var(int p_index, int p_new_index) { + ERR_FAIL_INDEX(p_index, (int)var_map.size()); + ERR_FAIL_INDEX(p_new_index, (int)var_map.size()); - Pair a = var_list[p_idx_a]; - Pair b = var_list[p_idx_b]; + if (p_index == p_new_index) { + return; + } - var_list.swap(var_list.find(a), var_list.find(b)); + List>::Element *E = var_list.front(); + for (int i = 0; i < p_index; i++) { + E = E->next(); + } + List>::Element *E2 = var_list.front(); + for (int i = 0; i < p_new_index; i++) { + E2 = E2->next(); + } + + var_list.move_before(E, E2); + if (p_new_index > p_index) { + var_list.move_before(E2, E); + } notify_property_list_changed(); emit_changed(); diff --git a/blackboard/blackboard_plan.h b/blackboard/blackboard_plan.h index c4de76a..e5a315a 100644 --- a/blackboard/blackboard_plan.h +++ b/blackboard/blackboard_plan.h @@ -60,7 +60,7 @@ public: PackedStringArray list_vars() const; String get_var_name(const BBVariable &p_var) const; void rename_var(const String &p_name, const String &p_new_name); - void swap_vars(int idx_a, int idx_b); + void move_var(int p_index, int p_new_index); void sync_with_base_plan(); bool is_derived() const { return base.is_valid(); } diff --git a/editor/blackboard_plan_editor.cpp b/editor/blackboard_plan_editor.cpp index 8201d99..bde3d01 100644 --- a/editor/blackboard_plan_editor.cpp +++ b/editor/blackboard_plan_editor.cpp @@ -113,13 +113,16 @@ void BlackboardPlanEditor::_hint_chosen(int id) { void BlackboardPlanEditor::_drag_button_down(Control *p_row) { drag_index = p_row->get_index(); + drag_start = drag_index; drag_mouse_y_delta = 0.0; Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); } void BlackboardPlanEditor::_drag_button_up() { - drag_index = -1; Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + plan->move_var(drag_start, drag_index); + drag_index = -1; + drag_start = -1; _refresh(); } @@ -140,13 +143,11 @@ void BlackboardPlanEditor::_drag_button_gui_input(const Ref &p_event return; } - float required_distance = 20.0f * EDSCALE; + float required_distance = 30.0f * EDSCALE; if (ABS(drag_mouse_y_delta) > required_distance) { int drag_dir = drag_mouse_y_delta > 0.0f ? 1 : -1; drag_mouse_y_delta -= required_distance * drag_dir; - plan->swap_vars(drag_index, drag_index + drag_dir); - Control *row = Object::cast_to(rows_vbox->get_child(drag_index)); Control *other_row = Object::cast_to(rows_vbox->get_child(drag_index + drag_dir)); ERR_FAIL_NULL(row); @@ -412,21 +413,23 @@ void EditorInspectorPluginBBPlan::_parse_begin(Object *p_object) { VBoxContainer *toolbar = memnew(VBoxContainer); margin_container->add_child(toolbar); - toolbar->set_h_size_flags(Control::SIZE_SHRINK_CENTER); + toolbar->set_h_size_flags(Control::SIZE_EXPAND_FILL); if (plan->is_derived()) { Button *goto_btn = memnew(Button); toolbar->add_child(goto_btn); goto_btn->set_text(TTR("Edit Base")); goto_btn->set_h_size_flags(Control::SIZE_SHRINK_CENTER); - goto_btn->set_custom_minimum_size(Size2(200.0, 0.0) * EDSCALE); + goto_btn->set_custom_minimum_size(Size2(150.0, 0.0) * EDSCALE); + BUTTON_SET_ICON(goto_btn, EditorInterface::get_singleton()->get_editor_theme()->get_icon(LW_NAME(Edit), LW_NAME(EditorIcons))); goto_btn->connect(LW_NAME(pressed), callable_mp(this, &EditorInspectorPluginBBPlan::_open_base_plan).bind(plan)); } else { Button *edit_btn = memnew(Button); toolbar->add_child(edit_btn); edit_btn->set_text(TTR("Manage...")); edit_btn->set_h_size_flags(Control::SIZE_SHRINK_CENTER); - edit_btn->set_custom_minimum_size(Size2(200.0, 0.0) * EDSCALE); + edit_btn->set_custom_minimum_size(Size2(150.0, 0.0) * EDSCALE); + BUTTON_SET_ICON(edit_btn, EditorInterface::get_singleton()->get_editor_theme()->get_icon(LW_NAME(EditAddRemove), LW_NAME(EditorIcons))); edit_btn->connect(LW_NAME(pressed), callable_mp(this, &EditorInspectorPluginBBPlan::_edit_plan).bind(plan)); } diff --git a/editor/blackboard_plan_editor.h b/editor/blackboard_plan_editor.h index ae81f2f..0cceb3a 100644 --- a/editor/blackboard_plan_editor.h +++ b/editor/blackboard_plan_editor.h @@ -46,6 +46,7 @@ private: int last_index = 0; int drag_mouse_y_delta = 0; + int drag_start = -1; int drag_index = -1; Ref plan; diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index fa36120..788f1fd 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -184,8 +184,9 @@ void LimboAIEditor::_update_history_buttons() { } void LimboAIEditor::_new_bt() { - BehaviorTree *bt = memnew(BehaviorTree); + Ref bt = memnew(BehaviorTree); bt->set_root_task(memnew(BTSelector)); + bt->set_blackboard_plan(memnew(BlackboardPlan)); EDIT_RESOURCE(bt); } @@ -222,6 +223,11 @@ void LimboAIEditor::edit_bt(Ref p_behavior_tree, bool p_force_refr return; } +#ifdef LIMBOAI_MODULE + p_behavior_tree->editor_set_section_unfold("blackboard_plan", true); + p_behavior_tree->notify_property_list_changed(); +#endif // LIMBOAI_MODULE + task_tree->load_bt(p_behavior_tree); int idx = history.find(p_behavior_tree); @@ -698,6 +704,9 @@ void LimboAIEditor::_on_visibility_changed() { void LimboAIEditor::_on_header_pressed() { _update_header(); task_tree->deselect(); +#ifdef LIMBOAI_MODULE + task_tree->get_bt()->editor_set_section_unfold("blackboard_plan", true); +#endif // LIMBOAI_MODULE EDIT_RESOURCE(task_tree->get_bt()); } diff --git a/util/limbo_string_names.cpp b/util/limbo_string_names.cpp index ab92007..25b55d1 100644 --- a/util/limbo_string_names.cpp +++ b/util/limbo_string_names.cpp @@ -64,6 +64,8 @@ LimboStringNames::LimboStringNames() { doc_italic = SN("doc_italic"); draw = SN("draw"); Duplicate = SN("Duplicate"); + Edit = SN("Edit"); + EditAddRemove = SN("EditAddRemove"); Editor = SN("Editor"); EditorFonts = SN("EditorFonts"); EditorIcons = SN("EditorIcons"); diff --git a/util/limbo_string_names.h b/util/limbo_string_names.h index 85d7cf1..bccbafd 100644 --- a/util/limbo_string_names.h +++ b/util/limbo_string_names.h @@ -78,6 +78,8 @@ public: StringName doc_italic; StringName draw; StringName Duplicate; + StringName Edit; + StringName EditAddRemove; StringName Editor; StringName EditorFonts; StringName EditorIcons;