Compare commits

..

4 Commits

Author SHA1 Message Date
Serhii Snitsaruk b4e77f08f8
Merge 2b299c0007 into 5f5ecc2db1 2024-05-29 11:59:04 +02:00
Serhii Snitsaruk 2b299c0007
Accept Ctrl-J when LimboAI editor is visible and fix shortcuts not working sometimes 2024-05-29 11:58:59 +02:00
Serhii Snitsaruk 88e468c526
Editor: Add Ctrl+J shortcut for "Jump to Owner" tab action 2024-05-29 11:18:11 +02:00
Serhii Snitsaruk a0cd983927
Editor: Fix "jump to owner" from subtree and refactor 2024-05-29 10:53:54 +02:00
5 changed files with 58 additions and 48 deletions

View File

@ -352,41 +352,49 @@ void LimboAIEditor::_process_shortcut_input(const Ref<InputEvent> &p_event) {
get_viewport()->set_input_as_handled(); get_viewport()->set_input_as_handled();
} }
// * Local shortcuts. // * When editor is on screen.
if (!(has_focus() || get_viewport()->gui_get_focus_owner() == nullptr || is_ancestor_of(get_viewport()->gui_get_focus_owner()))) { if (is_visible_in_tree()) {
return; if (LW_IS_SHORTCUT("limbo_ai/jump_to_owner", p_event)) {
_tab_menu_option_selected(TAB_JUMP_TO_OWNER);
get_viewport()->set_input_as_handled();
return;
}
} }
if (LW_IS_SHORTCUT("limbo_ai/rename_task", p_event)) { // * When editor is focused.
_action_selected(ACTION_RENAME);
} else if (LW_IS_SHORTCUT("limbo_ai/cut_task", p_event)) {
_action_selected(ACTION_CUT);
} else if (LW_IS_SHORTCUT("limbo_ai/copy_task", p_event)) {
_action_selected(ACTION_COPY);
} else if (LW_IS_SHORTCUT("limbo_ai/paste_task", p_event)) {
_action_selected(ACTION_PASTE);
} else if (LW_IS_SHORTCUT("limbo_ai/paste_task_after", p_event)) {
_action_selected(ACTION_PASTE_AFTER);
} else if (LW_IS_SHORTCUT("limbo_ai/move_task_up", p_event)) {
_action_selected(ACTION_MOVE_UP);
} else if (LW_IS_SHORTCUT("limbo_ai/move_task_down", p_event)) {
_action_selected(ACTION_MOVE_DOWN);
} else if (LW_IS_SHORTCUT("limbo_ai/duplicate_task", p_event)) {
_action_selected(ACTION_DUPLICATE);
} else if (LW_IS_SHORTCUT("limbo_ai/remove_task", p_event)) {
_action_selected(ACTION_REMOVE);
} else if (LW_IS_SHORTCUT("limbo_ai/new_behavior_tree", p_event)) {
_new_bt();
} else if (LW_IS_SHORTCUT("limbo_ai/save_behavior_tree", p_event)) {
_on_save_pressed();
} else if (LW_IS_SHORTCUT("limbo_ai/load_behavior_tree", p_event)) {
_popup_file_dialog(load_dialog);
} else {
return;
}
get_viewport()->set_input_as_handled(); if (has_focus() || (get_viewport()->gui_get_focus_owner() && is_ancestor_of(get_viewport()->gui_get_focus_owner()))) {
if (LW_IS_SHORTCUT("limbo_ai/rename_task", p_event)) {
_action_selected(ACTION_RENAME);
} else if (LW_IS_SHORTCUT("limbo_ai/cut_task", p_event)) {
_action_selected(ACTION_CUT);
} else if (LW_IS_SHORTCUT("limbo_ai/copy_task", p_event)) {
_action_selected(ACTION_COPY);
} else if (LW_IS_SHORTCUT("limbo_ai/paste_task", p_event)) {
_action_selected(ACTION_PASTE);
} else if (LW_IS_SHORTCUT("limbo_ai/paste_task_after", p_event)) {
_action_selected(ACTION_PASTE_AFTER);
} else if (LW_IS_SHORTCUT("limbo_ai/move_task_up", p_event)) {
_action_selected(ACTION_MOVE_UP);
} else if (LW_IS_SHORTCUT("limbo_ai/move_task_down", p_event)) {
_action_selected(ACTION_MOVE_DOWN);
} else if (LW_IS_SHORTCUT("limbo_ai/duplicate_task", p_event)) {
_action_selected(ACTION_DUPLICATE);
} else if (LW_IS_SHORTCUT("limbo_ai/remove_task", p_event)) {
_action_selected(ACTION_REMOVE);
} else if (LW_IS_SHORTCUT("limbo_ai/new_behavior_tree", p_event)) {
_new_bt();
} else if (LW_IS_SHORTCUT("limbo_ai/save_behavior_tree", p_event)) {
_on_save_pressed();
} else if (LW_IS_SHORTCUT("limbo_ai/load_behavior_tree", p_event)) {
_popup_file_dialog(load_dialog);
} else {
return;
}
get_viewport()->set_input_as_handled();
}
} }
void LimboAIEditor::_on_tree_rmb(const Vector2 &p_menu_pos) { void LimboAIEditor::_on_tree_rmb(const Vector2 &p_menu_pos) {
@ -1014,7 +1022,7 @@ void LimboAIEditor::_tab_input(const Ref<InputEvent> &p_input) {
void LimboAIEditor::_show_tab_context_menu() { void LimboAIEditor::_show_tab_context_menu() {
tab_menu->clear(); tab_menu->clear();
tab_menu->add_item(TTR("Show in FileSystem"), TabMenu::TAB_SHOW_IN_FILESYSTEM); tab_menu->add_item(TTR("Show in FileSystem"), TabMenu::TAB_SHOW_IN_FILESYSTEM);
tab_menu->add_item(TTR("Open Owner Scene"), TabMenu::TAB_OPEN_OWNER); tab_menu->add_shortcut(LW_GET_SHORTCUT("limbo_ai/jump_to_owner"), TabMenu::TAB_JUMP_TO_OWNER);
tab_menu->add_separator(); tab_menu->add_separator();
tab_menu->add_item(TTR("Close Tab"), TabMenu::TAB_CLOSE); tab_menu->add_item(TTR("Close Tab"), TabMenu::TAB_CLOSE);
tab_menu->add_item(TTR("Close Other Tabs"), TabMenu::TAB_CLOSE_OTHER); tab_menu->add_item(TTR("Close Other Tabs"), TabMenu::TAB_CLOSE_OTHER);
@ -1035,12 +1043,12 @@ void LimboAIEditor::_tab_menu_option_selected(int p_id) {
FS_DOCK_SELECT_FILE(path.get_slice("::", 0)); FS_DOCK_SELECT_FILE(path.get_slice("::", 0));
} }
} break; } break;
case TAB_OPEN_OWNER: { case TAB_JUMP_TO_OWNER: {
Ref<BehaviorTree> bt = history[idx_history]; Ref<BehaviorTree> bt = history[idx_history];
ERR_FAIL_NULL(bt); ERR_FAIL_NULL(bt);
String bt_path = bt->get_path(); String bt_path = bt->get_path();
if (!bt_path.is_empty()) { if (!bt_path.is_empty()) {
owner_picker->show(bt_path); owner_picker->pick_and_open_owner_of_resource(bt_path);
} }
} break; } break;
case TAB_CLOSE: { case TAB_CLOSE: {
@ -1356,6 +1364,7 @@ LimboAIEditor::LimboAIEditor() {
LW_SHORTCUT("limbo_ai/save_behavior_tree", TTR("Save Behavior Tree"), (Key)(LW_KEY_MASK(CMD_OR_CTRL) | LW_KEY_MASK(ALT) | LW_KEY(S))); LW_SHORTCUT("limbo_ai/save_behavior_tree", TTR("Save Behavior Tree"), (Key)(LW_KEY_MASK(CMD_OR_CTRL) | LW_KEY_MASK(ALT) | LW_KEY(S)));
LW_SHORTCUT("limbo_ai/load_behavior_tree", TTR("Load Behavior Tree"), (Key)(LW_KEY_MASK(CMD_OR_CTRL) | LW_KEY_MASK(ALT) | LW_KEY(L))); LW_SHORTCUT("limbo_ai/load_behavior_tree", TTR("Load Behavior Tree"), (Key)(LW_KEY_MASK(CMD_OR_CTRL) | LW_KEY_MASK(ALT) | LW_KEY(L)));
LW_SHORTCUT("limbo_ai/open_debugger", TTR("Open Debugger"), (Key)(LW_KEY_MASK(CMD_OR_CTRL) | LW_KEY_MASK(ALT) | LW_KEY(D))); LW_SHORTCUT("limbo_ai/open_debugger", TTR("Open Debugger"), (Key)(LW_KEY_MASK(CMD_OR_CTRL) | LW_KEY_MASK(ALT) | LW_KEY(D)));
LW_SHORTCUT("limbo_ai/jump_to_owner", TTR("Jump to Owner"), (Key)(LW_KEY_MASK(CMD_OR_CTRL) | LW_KEY(J)));
set_process_shortcut_input(true); set_process_shortcut_input(true);

View File

@ -102,7 +102,7 @@ private:
enum TabMenu { enum TabMenu {
TAB_SHOW_IN_FILESYSTEM, TAB_SHOW_IN_FILESYSTEM,
TAB_OPEN_OWNER, TAB_JUMP_TO_OWNER,
TAB_CLOSE, TAB_CLOSE,
TAB_CLOSE_OTHER, TAB_CLOSE_OTHER,
TAB_CLOSE_RIGHT, TAB_CLOSE_RIGHT,

View File

@ -25,7 +25,7 @@
#include <godot_cpp/classes/resource_loader.hpp> #include <godot_cpp/classes/resource_loader.hpp>
#endif #endif
Vector<String> OwnerPicker::find_owners(const String &p_path) const { Vector<String> OwnerPicker::_find_owners(const String &p_path) const {
Vector<String> owners; Vector<String> owners;
List<EditorFileSystemDirectory *> dirs; List<EditorFileSystemDirectory *> dirs;
@ -67,14 +67,14 @@ Vector<String> OwnerPicker::find_owners(const String &p_path) const {
return owners; return owners;
} }
void OwnerPicker::show(const String &p_path) { void OwnerPicker::pick_and_open_owner_of_resource(const String &p_path) {
if (p_path.is_empty()) { if (p_path.is_empty()) {
return; return;
} }
owners_item_list->clear(); owners_item_list->clear();
Vector<String> owners = find_owners(p_path); Vector<String> owners = _find_owners(p_path);
for (int i = 0; i < owners.size(); i++) { for (int i = 0; i < owners.size(); i++) {
owners_item_list->add_item(owners[i]); owners_item_list->add_item(owners[i]);
} }
@ -85,12 +85,12 @@ void OwnerPicker::show(const String &p_path) {
} }
if (owners_item_list->get_item_count() == 1) { if (owners_item_list->get_item_count() == 1) {
// Open scene immediately if there is only one owner scene. // Open owner immediately if there is only one owner.
_selection_confirmed(); _selection_confirmed();
} else if (owners_item_list->get_item_count() == 0) { } else if (owners_item_list->get_item_count() == 0) {
owners_item_list->hide(); owners_item_list->hide();
set_title(TTR("Alert!")); set_title(TTR("Alert!"));
set_text(TTR("This behavior tree is not used by any scene.")); set_text(TTR("Couldn't find owner. Looks like it's not used by any other resource."));
reset_size(); reset_size();
popup_centered(); popup_centered();
} else { } else {
@ -111,10 +111,10 @@ void OwnerPicker::_item_activated(int p_item) {
void OwnerPicker::_selection_confirmed() { void OwnerPicker::_selection_confirmed() {
for (int idx : owners_item_list->get_selected_items()) { for (int idx : owners_item_list->get_selected_items()) {
String owner_path = owners_item_list->get_item_text(idx); String owner_path = owners_item_list->get_item_text(idx);
if (RESOURCE_EXISTS(owner_path, "PackedScene")) { if (RESOURCE_IS_SCENE_FILE(owner_path)) {
EditorInterface::get_singleton()->open_scene_from_path(owner_path); EditorInterface::get_singleton()->open_scene_from_path(owner_path);
} else { } else {
RESOURCE_LOAD(owner_path, ""); EditorInterface::get_singleton()->edit_resource(RESOURCE_LOAD(owner_path, ""));
} }
} }
} }
@ -133,9 +133,9 @@ void OwnerPicker::_bind_methods() {
OwnerPicker::OwnerPicker() { OwnerPicker::OwnerPicker() {
owners_item_list = memnew(ItemList); owners_item_list = memnew(ItemList);
// Note: In my tests, editor couldn't process open request for multiple scenes at once. // Note: In my tests, editor couldn't process open request for multiple packed scenes at once.
owners_item_list->set_select_mode(ItemList::SELECT_SINGLE); owners_item_list->set_select_mode(ItemList::SELECT_SINGLE);
add_child(owners_item_list); add_child(owners_item_list);
} }
#endif // TOOLS_ENABLED #endif // TOOLS_ENABLED

View File

@ -36,9 +36,10 @@ protected:
void _notification(int p_what); void _notification(int p_what);
Vector<String> _find_owners(const String &p_path) const;
public: public:
Vector<String> find_owners(const String &p_path) const; void pick_and_open_owner_of_resource(const String &p_path);
void show(const String &p_path);
OwnerPicker(); OwnerPicker();
}; };

View File

@ -42,8 +42,8 @@
#define RESOURCE_LOAD_NO_CACHE(m_path, m_hint) ResourceLoader::load(m_path, m_hint, ResourceFormatLoader::CACHE_MODE_IGNORE) #define RESOURCE_LOAD_NO_CACHE(m_path, m_hint) ResourceLoader::load(m_path, m_hint, ResourceFormatLoader::CACHE_MODE_IGNORE)
#define RESOURCE_SAVE(m_res, m_path, m_flags) ResourceSaver::save(m_res, m_path, m_flags) #define RESOURCE_SAVE(m_res, m_path, m_flags) ResourceSaver::save(m_res, m_path, m_flags)
#define RESOURCE_IS_CACHED(m_path) (ResourceCache::has(m_path)) #define RESOURCE_IS_CACHED(m_path) (ResourceCache::has(m_path))
#define RESOURCE_GET_TYPE(m_path) (ResourceLoader::get_resource_type(m_path))
#define RESOURCE_EXISTS(m_path, m_type_hint) (ResourceLoader::exists(m_path, m_type_hint)) #define RESOURCE_EXISTS(m_path, m_type_hint) (ResourceLoader::exists(m_path, m_type_hint))
#define RESOURCE_IS_SCENE_FILE(m_path) (ResourceLoader::get_resource_type(m_path) == "PackedScene")
#define GET_PROJECT_SETTINGS_DIR() EditorPaths::get_singleton()->get_project_settings_dir() #define GET_PROJECT_SETTINGS_DIR() EditorPaths::get_singleton()->get_project_settings_dir()
#define EDIT_RESOURCE(m_res) EditorNode::get_singleton()->edit_resource(m_res) #define EDIT_RESOURCE(m_res) EditorNode::get_singleton()->edit_resource(m_res)
#define INSPECTOR_GET_EDITED_OBJECT() (InspectorDock::get_inspector_singleton()->get_edited_object()) #define INSPECTOR_GET_EDITED_OBJECT() (InspectorDock::get_inspector_singleton()->get_edited_object())
@ -127,7 +127,7 @@ using namespace godot;
#define RESOURCE_LOAD_NO_CACHE(m_path, m_hint) ResourceLoader::get_singleton()->load(m_path, m_hint, ResourceLoader::CACHE_MODE_IGNORE) #define RESOURCE_LOAD_NO_CACHE(m_path, m_hint) ResourceLoader::get_singleton()->load(m_path, m_hint, ResourceLoader::CACHE_MODE_IGNORE)
#define RESOURCE_SAVE(m_res, m_path, m_flags) ResourceSaver::get_singleton()->save(m_res, m_path, m_flags) #define RESOURCE_SAVE(m_res, m_path, m_flags) ResourceSaver::get_singleton()->save(m_res, m_path, m_flags)
#define RESOURCE_IS_CACHED(m_path) (ResourceLoader::get_singleton()->has_cached(res_path)) #define RESOURCE_IS_CACHED(m_path) (ResourceLoader::get_singleton()->has_cached(res_path))
#define RESOURCE_GET_TYPE(m_path) (ResourceLoader::get_resource_type(m_path)) #define RESOURCE_IS_SCENE_FILE(m_path) (ResourceLoader::get_singleton()->get_recognized_extensions_for_type("PackedScene").has(m_path.get_extension()))
#define RESOURCE_EXISTS(m_path, m_type_hint) (ResourceLoader::get_singleton()->exists(m_path, m_type_hint)) #define RESOURCE_EXISTS(m_path, m_type_hint) (ResourceLoader::get_singleton()->exists(m_path, m_type_hint))
#define GET_PROJECT_SETTINGS_DIR() EditorInterface::get_singleton()->get_editor_paths()->get_project_settings_dir() #define GET_PROJECT_SETTINGS_DIR() EditorInterface::get_singleton()->get_editor_paths()->get_project_settings_dir()
#define EDIT_RESOURCE(m_res) EditorInterface::get_singleton()->edit_resource(m_res) #define EDIT_RESOURCE(m_res) EditorInterface::get_singleton()->edit_resource(m_res)