Usability improvements
This commit is contained in:
parent
a22860b244
commit
f912f0acc4
|
@ -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<String, BBVariable> a = var_list[p_idx_a];
|
||||
Pair<String, BBVariable> 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<Pair<String, BBVariable>>::Element *E = var_list.front();
|
||||
for (int i = 0; i < p_index; i++) {
|
||||
E = E->next();
|
||||
}
|
||||
List<Pair<String, BBVariable>>::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();
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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<InputEvent> &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<Control>(rows_vbox->get_child(drag_index));
|
||||
Control *other_row = Object::cast_to<Control>(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));
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ private:
|
|||
|
||||
int last_index = 0;
|
||||
int drag_mouse_y_delta = 0;
|
||||
int drag_start = -1;
|
||||
int drag_index = -1;
|
||||
|
||||
Ref<BlackboardPlan> plan;
|
||||
|
|
|
@ -184,8 +184,9 @@ void LimboAIEditor::_update_history_buttons() {
|
|||
}
|
||||
|
||||
void LimboAIEditor::_new_bt() {
|
||||
BehaviorTree *bt = memnew(BehaviorTree);
|
||||
Ref<BehaviorTree> 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<BehaviorTree> 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -78,6 +78,8 @@ public:
|
|||
StringName doc_italic;
|
||||
StringName draw;
|
||||
StringName Duplicate;
|
||||
StringName Edit;
|
||||
StringName EditAddRemove;
|
||||
StringName Editor;
|
||||
StringName EditorFonts;
|
||||
StringName EditorIcons;
|
||||
|
|
Loading…
Reference in New Issue