From 872f7a453201e209b587edd6e04ce72c45ba673d Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 2 Jul 2024 11:55:22 +0200 Subject: [PATCH 01/12] Editor: Add setting for task palette placement --- editor/limbo_ai_editor_plugin.cpp | 11 ++++++++++- editor/limbo_ai_editor_plugin.h | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 980bd21..11efd50 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1544,9 +1544,15 @@ LimboAIEditor::LimboAIEditor() { usage_hint->add_child(usage_label); task_palette = memnew(TaskPalette()); - hsc->set_split_offset(-300); task_palette->hide(); hsc->add_child(task_palette); + TaskPalettePlacement palette_placement = (TaskPalettePlacement)(int)EDITOR_GET("limbo_ai/editor/task_palette_placement"); + if (palette_placement == TaskPalettePlacement::LEFT_SIDE) { + hsc->move_child(task_palette, 0); + hsc->set_split_offset(300); + } else { + hsc->set_split_offset(-300); + } change_type_popup = memnew(PopupPanel); add_child(change_type_popup); @@ -1654,6 +1660,9 @@ LimboAIEditor::LimboAIEditor() { GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_2", PROPERTY_HINT_DIR), ""); GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_3", PROPERTY_HINT_DIR), ""); + EDITOR_DEF("limbo_ai/editor/task_palette_placement", 0); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "limbo_ai/editor/task_palette_placement", PROPERTY_HINT_ENUM, "Right Side:0,Left Side:1")); + String bt_default_dir = GLOBAL_GET("limbo_ai/behavior_tree/behavior_tree_default_dir"); save_dialog->set_current_dir(bt_default_dir); load_dialog->set_current_dir(bt_default_dir); diff --git a/editor/limbo_ai_editor_plugin.h b/editor/limbo_ai_editor_plugin.h index 8d5f8f1..3475200 100644 --- a/editor/limbo_ai_editor_plugin.h +++ b/editor/limbo_ai_editor_plugin.h @@ -26,8 +26,8 @@ #include "core/object/object.h" #include "core/templates/hash_set.h" #include "editor/editor_node.h" -#include "editor/plugins/editor_plugin.h" #include "editor/gui/editor_spin_slider.h" +#include "editor/plugins/editor_plugin.h" #include "scene/gui/box_container.h" #include "scene/gui/control.h" #include "scene/gui/dialogs.h" @@ -111,6 +111,11 @@ private: TAB_CLOSE_ALL, }; + enum TaskPalettePlacement { + RIGHT_SIDE, + LEFT_SIDE, + }; + struct ThemeCache { Ref duplicate_task_icon; Ref edit_script_icon; From 7d6cc1a828468fec950008f254bdb102ea4ea94f Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 4 Jul 2024 21:16:35 +0200 Subject: [PATCH 02/12] Editor: Adjust layout to work better with task palette on the left --- editor/limbo_ai_editor_plugin.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 11efd50..9e93b61 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1548,7 +1548,12 @@ LimboAIEditor::LimboAIEditor() { hsc->add_child(task_palette); TaskPalettePlacement palette_placement = (TaskPalettePlacement)(int)EDITOR_GET("limbo_ai/editor/task_palette_placement"); if (palette_placement == TaskPalettePlacement::LEFT_SIDE) { - hsc->move_child(task_palette, 0); + VBoxContainer *editor_vbox = memnew(VBoxContainer); + hsc->add_child(editor_vbox); + toolbar->reparent(editor_vbox); + tab_bar_panel->reparent(editor_vbox); + task_tree->reparent(editor_vbox); + usage_hint->reparent(editor_vbox); hsc->set_split_offset(300); } else { hsc->set_split_offset(-300); From b305041f2888cb0827a9ea8bfaca09f2ae7f427e Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 4 Jul 2024 21:25:00 +0200 Subject: [PATCH 03/12] Bump demo version --- demo/project.godot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/project.godot b/demo/project.godot index 32ef28a..91d00b8 100644 --- a/demo/project.godot +++ b/demo/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="LimboAI Demo" run/main_scene="res://demo/scenes/showcase.tscn" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://demo/assets/icon.svg" [display] From 7baa395d3f295ed016d51ba912c3d033aea14f8d Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 5 Jul 2024 17:02:29 +0200 Subject: [PATCH 04/12] Rename to editor_layout --- editor/limbo_ai_editor_plugin.cpp | 10 +++++----- editor/limbo_ai_editor_plugin.h | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 9e93b61..d59ecd0 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1377,6 +1377,9 @@ LimboAIEditor::LimboAIEditor() { plugin = nullptr; idx_history = 0; + EDITOR_DEF("limbo_ai/editor/layout", 0); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "limbo_ai/editor/layout", PROPERTY_HINT_ENUM, "Classic:0,Widescreen Optimized:1")); + LW_SHORTCUT("limbo_ai/rename_task", TTR("Rename"), LW_KEY(F2)); // Todo: Add override support for shortcuts. // LW_SHORTCUT_OVERRIDE("limbo_ai/rename_task", "macos", Key::ENTER); @@ -1546,8 +1549,8 @@ LimboAIEditor::LimboAIEditor() { task_palette = memnew(TaskPalette()); task_palette->hide(); hsc->add_child(task_palette); - TaskPalettePlacement palette_placement = (TaskPalettePlacement)(int)EDITOR_GET("limbo_ai/editor/task_palette_placement"); - if (palette_placement == TaskPalettePlacement::LEFT_SIDE) { + editor_layout = (EditorLayout)(int)EDITOR_GET("limbo_ai/editor/layout"); + if (editor_layout == EditorLayout::WIDESCREEN_OPTIMIZED) { VBoxContainer *editor_vbox = memnew(VBoxContainer); hsc->add_child(editor_vbox); toolbar->reparent(editor_vbox); @@ -1665,9 +1668,6 @@ LimboAIEditor::LimboAIEditor() { GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_2", PROPERTY_HINT_DIR), ""); GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_3", PROPERTY_HINT_DIR), ""); - EDITOR_DEF("limbo_ai/editor/task_palette_placement", 0); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "limbo_ai/editor/task_palette_placement", PROPERTY_HINT_ENUM, "Right Side:0,Left Side:1")); - String bt_default_dir = GLOBAL_GET("limbo_ai/behavior_tree/behavior_tree_default_dir"); save_dialog->set_current_dir(bt_default_dir); load_dialog->set_current_dir(bt_default_dir); diff --git a/editor/limbo_ai_editor_plugin.h b/editor/limbo_ai_editor_plugin.h index 3475200..bda549c 100644 --- a/editor/limbo_ai_editor_plugin.h +++ b/editor/limbo_ai_editor_plugin.h @@ -111,9 +111,9 @@ private: TAB_CLOSE_ALL, }; - enum TaskPalettePlacement { - RIGHT_SIDE, - LEFT_SIDE, + enum EditorLayout { + CLASSIC, + WIDESCREEN_OPTIMIZED, }; struct ThemeCache { @@ -137,6 +137,7 @@ private: } theme_cache; EditorPlugin *plugin; + EditorLayout editor_layout; Vector> history; int idx_history; bool updating_tabs = false; From b74f664da613cb90723996113d45bc9ad30aea23 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 5 Jul 2024 17:24:32 +0200 Subject: [PATCH 05/12] Fix compilation issue with GDExtension --- editor/limbo_ai_editor_plugin.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index d59ecd0..5439377 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1377,8 +1377,18 @@ LimboAIEditor::LimboAIEditor() { plugin = nullptr; idx_history = 0; +#ifdef LIMBOAI_MODULE EDITOR_DEF("limbo_ai/editor/layout", 0); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "limbo_ai/editor/layout", PROPERTY_HINT_ENUM, "Classic:0,Widescreen Optimized:1")); + EDITOR_SETTINGS()->add_property_hint(PropertyInfo(Variant::INT, "limbo_ai/editor/layout", PROPERTY_HINT_ENUM, "Classic:0,Widescreen Optimized:1")); +#elif LIMBOAI_GDEXTENSION + EDITOR_SETTINGS()->set_initial_value("limbo_ai/editor/layout", 0, false); + Dictionary pinfo; + pinfo["name"] = "limbo_ai/editor/layout"; + pinfo["type"] = Variant::INT; + pinfo["hint"] = PROPERTY_HINT_ENUM; + pinfo["hint_string"] = "Classic:0,Widescreen Optimized:1"; + EDITOR_SETTINGS()->add_property_info(pinfo); +#endif LW_SHORTCUT("limbo_ai/rename_task", TTR("Rename"), LW_KEY(F2)); // Todo: Add override support for shortcuts. From 29735905332df9e5e18969869e4cddd98d906f51 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 5 Jul 2024 17:53:35 +0200 Subject: [PATCH 06/12] Flip split offset setting if editor layout changed --- editor/limbo_ai_editor_plugin.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 5439377..157902d 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1294,7 +1294,12 @@ void LimboAIEditor::_notification(int p_what) { cf.instantiate(); String conf_path = PROJECT_CONFIG_FILE(); cf->load(conf_path); - cf->set_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset()); + int split_offset = hsc->get_split_offset(); + if (editor_layout != (int)EDITOR_GET("limbo_ai/editor/layout")) { + // Editor layout settings changed - flip split offset. + split_offset *= -1; + } + cf->set_value("bt_editor", "bteditor_hsplit", split_offset); cf->save(conf_path); if (task_tree->get_bt().is_valid() && @@ -1380,6 +1385,7 @@ LimboAIEditor::LimboAIEditor() { #ifdef LIMBOAI_MODULE EDITOR_DEF("limbo_ai/editor/layout", 0); EDITOR_SETTINGS()->add_property_hint(PropertyInfo(Variant::INT, "limbo_ai/editor/layout", PROPERTY_HINT_ENUM, "Classic:0,Widescreen Optimized:1")); + EDITOR_SETTINGS()->set_restart_if_changed("limbo_ai/editor/layout", true); #elif LIMBOAI_GDEXTENSION EDITOR_SETTINGS()->set_initial_value("limbo_ai/editor/layout", 0, false); Dictionary pinfo; From 2813728785196fe6eef398e47581b8fb1f3beb66 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 5 Jul 2024 20:32:53 +0200 Subject: [PATCH 07/12] Fix connected signal error when loading BT for the second time --- editor/limbo_ai_editor_plugin.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 157902d..d6215db 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -221,6 +221,8 @@ void LimboAIEditor::_load_bt(String p_path) { void LimboAIEditor::_disable_editing() { task_tree->unload(); task_palette->hide(); + task_tree->hide(); + usage_hint->show(); } void LimboAIEditor::edit_bt(Ref p_behavior_tree, bool p_force_refresh) { @@ -235,14 +237,9 @@ void LimboAIEditor::edit_bt(Ref p_behavior_tree, bool p_force_refr p_behavior_tree->notify_property_list_changed(); #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); - 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)); } @@ -959,6 +956,10 @@ void LimboAIEditor::_tab_clicked(int p_tab) { void LimboAIEditor::_tab_closed(int p_tab) { ERR_FAIL_INDEX(p_tab, history.size()); + Ref 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); idx_history = MIN(idx_history, history.size() - 1); if (idx_history < 0) { @@ -1302,9 +1303,11 @@ void LimboAIEditor::_notification(int p_what) { cf->set_value("bt_editor", "bteditor_hsplit", split_offset); cf->save(conf_path); - 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->unload(); + for (int i = 0; i < history.size(); i++) { + 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; case NOTIFICATION_READY: { From 4787413cb610b5cd9eff67c412e52b1cf9ff690c Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 5 Jul 2024 20:49:16 +0200 Subject: [PATCH 08/12] Add header to the sidebar --- editor/limbo_ai_editor_plugin.cpp | 39 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index d6215db..a18ea65 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1498,14 +1498,14 @@ LimboAIEditor::LimboAIEditor() { misc_btn->set_flat(true); toolbar->add_child(misc_btn); - HBoxContainer *toolbar_end_hbox = memnew(HBoxContainer); - toolbar_end_hbox->set_h_size_flags(SIZE_EXPAND | SIZE_SHRINK_END); - toolbar->add_child(toolbar_end_hbox); + HBoxContainer *version_hbox = memnew(HBoxContainer); + version_hbox->set_h_size_flags(SIZE_EXPAND | SIZE_SHRINK_END); + toolbar->add_child(version_hbox); TextureRect *logo = memnew(TextureRect); logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); logo->set_texture(LimboUtility::get_singleton()->get_task_icon("LimboAI")); - toolbar_end_hbox->add_child(logo); + version_hbox->add_child(logo); version_btn = memnew(LinkButton); version_btn->set_text(TTR("v") + String(GET_LIMBOAI_FULL_VERSION())); @@ -1513,11 +1513,11 @@ LimboAIEditor::LimboAIEditor() { version_btn->set_self_modulate(Color(1, 1, 1, 0.65)); version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); version_btn->set_v_size_flags(SIZE_SHRINK_CENTER); - toolbar_end_hbox->add_child(version_btn); + version_hbox->add_child(version_btn); Control *version_spacer = memnew(Control); version_spacer->set_custom_minimum_size(Size2(2, 0) * EDSCALE); - toolbar_end_hbox->add_child(version_spacer); + version_hbox->add_child(version_spacer); tab_bar_panel = memnew(PanelContainer); vbox->add_child(tab_bar_panel); @@ -1568,19 +1568,40 @@ LimboAIEditor::LimboAIEditor() { task_palette = memnew(TaskPalette()); task_palette->hide(); hsc->add_child(task_palette); + editor_layout = (EditorLayout)(int)EDITOR_GET("limbo_ai/editor/layout"); if (editor_layout == EditorLayout::WIDESCREEN_OPTIMIZED) { + // * Alternative layout optimized for wide screen. + VBoxContainer *sidebar_vbox = memnew(VBoxContainer); + hsc->add_child(sidebar_vbox); + sidebar_vbox->set_v_size_flags(SIZE_EXPAND_FILL); + + HBoxContainer *header_bar = memnew(HBoxContainer); + sidebar_vbox->add_child(header_bar); + Control *header_spacer = memnew(Control); + header_bar->add_child(header_spacer); + header_spacer->set_custom_minimum_size(Size2(6, 0) * EDSCALE); + TextureRect *header_logo = Object::cast_to(logo->duplicate()); + header_bar->add_child(header_logo); + Label *header_title = memnew(Label); + header_bar->add_child(header_title); + header_title->set_text(TTR("Behavior Tree Editor")); + header_title->set_v_size_flags(SIZE_SHRINK_CENTER); + header_title->set_theme_type_variation("HeaderMedium"); + + task_palette->reparent(sidebar_vbox); + task_palette->set_v_size_flags(SIZE_EXPAND_FILL); + VBoxContainer *editor_vbox = memnew(VBoxContainer); hsc->add_child(editor_vbox); toolbar->reparent(editor_vbox); tab_bar_panel->reparent(editor_vbox); task_tree->reparent(editor_vbox); usage_hint->reparent(editor_vbox); - hsc->set_split_offset(300); - } else { - hsc->set_split_offset(-300); } + hsc->set_split_offset((editor_layout == EditorLayout::CLASSIC ? -320 : 320) * EDSCALE); + change_type_popup = memnew(PopupPanel); add_child(change_type_popup); { From da9d80d11011bb9e8bf495142a85fc35ab3ea0f1 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 6 Jul 2024 09:18:50 +0200 Subject: [PATCH 09/12] Add Misc->Layout options --- editor/limbo_ai_editor_plugin.cpp | 43 +++++++++++++++++++++++++++++-- editor/limbo_ai_editor_plugin.h | 7 +++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index a18ea65..1815a62 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -316,6 +316,12 @@ void LimboAIEditor::_remove_task_from_favorite(const String &p_task) { ProjectSettings::get_singleton()->save(); } +void LimboAIEditor::_save_and_restart() { + ProjectSettings::get_singleton()->save(); + EditorNode::get_singleton()->save_all_scenes(); + EditorNode::get_singleton()->restart_editor(); +} + void LimboAIEditor::_extract_subtree(const String &p_path) { Ref selected = task_tree->get_selected(); ERR_FAIL_COND(selected.is_null()); @@ -699,6 +705,16 @@ void LimboAIEditor::_misc_option_selected(int p_id) { case MISC_PROJECT_SETTINGS: { _edit_project_settings(); } break; + case MISC_LAYOUT_CLASSIC: { + EDITOR_SETTINGS()->set_setting("limbo_ai/editor/layout", LAYOUT_CLASSIC); + EDITOR_SETTINGS()->save(); + _update_banners(); + } break; + case MISC_LAYOUT_WIDESCREEN_OPTIMIZED: { + EDITOR_SETTINGS()->set_setting("limbo_ai/editor/layout", LAYOUT_WIDESCREEN_OPTIMIZED); + EDITOR_SETTINGS()->save(); + _update_banners(); + } break; case MISC_CREATE_SCRIPT_TEMPLATE: { String template_path = _get_script_template_path(); String template_dir = template_path.get_base_dir(); @@ -1217,6 +1233,20 @@ void LimboAIEditor::_update_misc_menu() { #endif // LIMBOAI_MODULE misc_menu->add_item(TTR("Project Settings..."), MISC_PROJECT_SETTINGS); + PopupMenu *layout_menu = Object::cast_to(misc_menu->get_node_or_null(NodePath("LayoutMenu"))); + if (layout_menu == nullptr) { + layout_menu = memnew(PopupMenu); + layout_menu->set_name("LayoutMenu"); + layout_menu->connect(LW_NAME(id_pressed), callable_mp(this, &LimboAIEditor::_misc_option_selected)); + misc_menu->add_child(layout_menu); + } + layout_menu->add_radio_check_item(TTR("Classic"), MISC_LAYOUT_CLASSIC); + layout_menu->add_radio_check_item(TTR("Widescreen Optimized"), MISC_LAYOUT_WIDESCREEN_OPTIMIZED); + misc_menu->add_submenu_item(TTR("Layout"), "LayoutMenu"); + EditorLayout saved_layout = (EditorLayout)(int)EDITOR_GET("limbo_ai/editor/layout"); + layout_menu->set_item_checked(0, saved_layout == LAYOUT_CLASSIC); + layout_menu->set_item_checked(1, saved_layout == LAYOUT_WIDESCREEN_OPTIMIZED); + misc_menu->add_separator(); misc_menu->add_item( FILE_EXISTS(_get_script_template_path()) ? TTR("Edit Script Template") : TTR("Create Script Template"), @@ -1257,6 +1287,15 @@ void LimboAIEditor::_update_banners() { banners->call_deferred(LW_NAME(add_child), banner); } } + + EditorLayout saved_layout = (EditorLayout)(int)EDITOR_GET("limbo_ai/editor/layout"); + if (saved_layout != editor_layout) { + ActionBanner *banner = memnew(ActionBanner); + banner->set_text(TTR("Restart required to apply changes to editor layout.")); + banner->add_action(TTR("Save & Restart"), callable_mp(this, &LimboAIEditor::_save_and_restart), true); + banner->set_meta(LW_NAME(managed), Variant(true)); + banners->call_deferred(LW_NAME(add_child), banner); + } } void LimboAIEditor::_do_update_theme_item_cache() { @@ -1570,7 +1609,7 @@ LimboAIEditor::LimboAIEditor() { hsc->add_child(task_palette); editor_layout = (EditorLayout)(int)EDITOR_GET("limbo_ai/editor/layout"); - if (editor_layout == EditorLayout::WIDESCREEN_OPTIMIZED) { + if (editor_layout == LAYOUT_WIDESCREEN_OPTIMIZED) { // * Alternative layout optimized for wide screen. VBoxContainer *sidebar_vbox = memnew(VBoxContainer); hsc->add_child(sidebar_vbox); @@ -1600,7 +1639,7 @@ LimboAIEditor::LimboAIEditor() { usage_hint->reparent(editor_vbox); } - hsc->set_split_offset((editor_layout == EditorLayout::CLASSIC ? -320 : 320) * EDSCALE); + hsc->set_split_offset((editor_layout == LAYOUT_CLASSIC ? -320 : 320) * EDSCALE); change_type_popup = memnew(PopupPanel); add_child(change_type_popup); diff --git a/editor/limbo_ai_editor_plugin.h b/editor/limbo_ai_editor_plugin.h index bda549c..57ba68c 100644 --- a/editor/limbo_ai_editor_plugin.h +++ b/editor/limbo_ai_editor_plugin.h @@ -98,6 +98,8 @@ private: MISC_DOC_INTRODUCTION, MISC_DOC_CUSTOM_TASKS, MISC_OPEN_DEBUGGER, + MISC_LAYOUT_CLASSIC, + MISC_LAYOUT_WIDESCREEN_OPTIMIZED, MISC_PROJECT_SETTINGS, MISC_CREATE_SCRIPT_TEMPLATE, }; @@ -112,8 +114,8 @@ private: }; enum EditorLayout { - CLASSIC, - WIDESCREEN_OPTIMIZED, + LAYOUT_CLASSIC, + LAYOUT_WIDESCREEN_OPTIMIZED, }; struct ThemeCache { @@ -201,6 +203,7 @@ private: void _mark_as_dirty(bool p_dirty); void _create_user_task_dir(); void _remove_task_from_favorite(const String &p_task); + void _save_and_restart(); void _extract_subtree(const String &p_path); void _replace_task(const Ref &p_task, const Ref &p_by_task); From 7c0d49bafae54d63e418db5d6a16d1c0e96d09a3 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 6 Jul 2024 09:29:09 +0200 Subject: [PATCH 10/12] Reparent banners if using new layout --- editor/limbo_ai_editor_plugin.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 1815a62..9d24c1a 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1291,7 +1291,7 @@ void LimboAIEditor::_update_banners() { EditorLayout saved_layout = (EditorLayout)(int)EDITOR_GET("limbo_ai/editor/layout"); if (saved_layout != editor_layout) { ActionBanner *banner = memnew(ActionBanner); - banner->set_text(TTR("Restart required to apply changes to editor layout.")); + banner->set_text(TTR("Restart required to apply changes to editor layout")); banner->add_action(TTR("Save & Restart"), callable_mp(this, &LimboAIEditor::_save_and_restart), true); banner->set_meta(LW_NAME(managed), Variant(true)); banners->call_deferred(LW_NAME(add_child), banner); @@ -1608,6 +1608,9 @@ LimboAIEditor::LimboAIEditor() { task_palette->hide(); hsc->add_child(task_palette); + banners = memnew(VBoxContainer); + vbox->add_child(banners); + editor_layout = (EditorLayout)(int)EDITOR_GET("limbo_ai/editor/layout"); if (editor_layout == LAYOUT_WIDESCREEN_OPTIMIZED) { // * Alternative layout optimized for wide screen. @@ -1637,6 +1640,7 @@ LimboAIEditor::LimboAIEditor() { tab_bar_panel->reparent(editor_vbox); task_tree->reparent(editor_vbox); usage_hint->reparent(editor_vbox); + banners->reparent(editor_vbox); } hsc->set_split_offset((editor_layout == LAYOUT_CLASSIC ? -320 : 320) * EDSCALE); @@ -1659,9 +1663,6 @@ LimboAIEditor::LimboAIEditor() { change_type_palette->set_v_size_flags(SIZE_EXPAND_FILL); } - banners = memnew(VBoxContainer); - vbox->add_child(banners); - menu = memnew(PopupMenu); add_child(menu); From cfa1f70d79d40dc534552e2b0909827b105e7ec8 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 6 Jul 2024 09:38:33 +0200 Subject: [PATCH 11/12] Update banners upon editor settings changed --- editor/limbo_ai_editor_plugin.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 9d24c1a..7fc500e 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1401,7 +1401,12 @@ void LimboAIEditor::_notification(int p_what) { BUTTON_SET_ICON(misc_btn, get_theme_icon(LW_NAME(Tools), LW_NAME(EditorIcons))); _update_favorite_tasks(); - } + } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + if (is_visible_in_tree()) { + _update_banners(); + } + } break; } } From bc999652051f09f9e38c531ef75d7ac84fe47629 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 6 Jul 2024 09:46:22 +0200 Subject: [PATCH 12/12] Fix compilation with GDExtension --- editor/limbo_ai_editor_plugin.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 7fc500e..0083f04 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -34,6 +34,7 @@ #include "editor/debugger/script_editor_debugger.h" #include "editor/editor_file_system.h" #include "editor/editor_help.h" +#include "editor/editor_interface.h" #include "editor/editor_paths.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" @@ -318,8 +319,8 @@ void LimboAIEditor::_remove_task_from_favorite(const String &p_task) { void LimboAIEditor::_save_and_restart() { ProjectSettings::get_singleton()->save(); - EditorNode::get_singleton()->save_all_scenes(); - EditorNode::get_singleton()->restart_editor(); + EditorInterface::get_singleton()->save_all_scenes(); + EditorInterface::get_singleton()->restart_editor(true); } void LimboAIEditor::_extract_subtree(const String &p_path) { @@ -707,12 +708,12 @@ void LimboAIEditor::_misc_option_selected(int p_id) { } break; case MISC_LAYOUT_CLASSIC: { EDITOR_SETTINGS()->set_setting("limbo_ai/editor/layout", LAYOUT_CLASSIC); - EDITOR_SETTINGS()->save(); + EDITOR_SETTINGS()->mark_setting_changed("limbo_ai/editor/layout"); _update_banners(); } break; case MISC_LAYOUT_WIDESCREEN_OPTIMIZED: { EDITOR_SETTINGS()->set_setting("limbo_ai/editor/layout", LAYOUT_WIDESCREEN_OPTIMIZED); - EDITOR_SETTINGS()->save(); + EDITOR_SETTINGS()->mark_setting_changed("limbo_ai/editor/layout"); _update_banners(); } break; case MISC_CREATE_SCRIPT_TEMPLATE: {