From 5c3445236f9550d153e832f3273a31ec3fc24594 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 18 Aug 2023 12:12:55 +0200 Subject: [PATCH] Implement: Add/Remove task favorites Favorite tasks are tasks selected to be shown on the toolbar. Order can be edited in the project settings. --- editor/limbo_ai_editor_plugin.cpp | 156 ++++++++++++++++++------------ editor/limbo_ai_editor_plugin.h | 8 +- 2 files changed, 97 insertions(+), 67 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 1089e75..e7f5807 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -448,6 +448,17 @@ void TaskPanel::_menu_action_selected(int p_id) { ERR_FAIL_COND(!context_task.begins_with("res://")); ScriptEditor::get_singleton()->open_file(context_task); } break; + case MENU_FAVORITE: { + Array favorite_tasks = GLOBAL_GET("limbo_ai/behavior_tree/favorite_tasks"); + if (favorite_tasks.has(context_task)) { + favorite_tasks.erase(context_task); + } else { + favorite_tasks.append(context_task); + } + ProjectSettings::get_singleton()->set_setting("limbo_ai/behavior_tree/favorite_tasks", favorite_tasks); + ProjectSettings::get_singleton()->save(); + emit_signal(SNAME("favorite_tasks_changed")); + } break; } } @@ -465,6 +476,14 @@ void TaskPanel::_on_task_button_rmb(const String &p_task) { menu->set_item_disabled(MENU_EDIT_SCRIPT, !context_task.begins_with("res://")); menu->add_icon_item(get_theme_icon(SNAME("Help"), SNAME("EditorIcons")), TTR("Open Documentation"), MENU_OPEN_DOC); + menu->add_separator(); + Array favorite_tasks = GLOBAL_GET("limbo_ai/behavior_tree/favorite_tasks"); + if (favorite_tasks.has(context_task)) { + menu->add_icon_item(get_theme_icon(SNAME("NonFavorite"), SNAME("EditorIcons")), TTR("Remove from Favorites"), MENU_FAVORITE); + } else { + menu->add_icon_item(get_theme_icon(SNAME("Favorites"), SNAME("EditorIcons")), TTR("Add to Favorites"), MENU_FAVORITE); + } + menu->reset_size(); menu->set_position(get_screen_position() + get_local_mouse_position()); menu->popup(); @@ -659,6 +678,7 @@ void TaskPanel::_bind_methods() { ClassDB::bind_method(D_METHOD("refresh"), &TaskPanel::refresh); ADD_SIGNAL(MethodInfo("task_selected")); + ADD_SIGNAL(MethodInfo("favorite_tasks_changed")); } TaskPanel::TaskPanel() { @@ -715,6 +735,33 @@ void LimboAIEditor::_add_task(const Ref &p_task) { _mark_as_dirty(true); } +void LimboAIEditor::_add_task_by_class_or_path(String p_class_or_path) { + Ref task; + + if (p_class_or_path.begins_with("res:")) { + Ref