Compare commits

..

2 Commits

Author SHA1 Message Date
Serhii Snitsaruk 134bb3214a
Merge pull request #225 from ydeltastar/remember-last-session
Remember loaded `BehaviorTree`s of last session
2024-09-22 13:32:56 +02:00
yds db7c990f51 Remember loaded BehaviorTrees of last session 2024-09-21 16:23:13 -03:00
5 changed files with 67 additions and 37 deletions

View File

@ -193,18 +193,18 @@ void LimboDebuggerTab::_notification(int p_what) {
Ref<ConfigFile> cf; Ref<ConfigFile> cf;
cf.instantiate(); cf.instantiate();
String conf_path = PROJECT_CONFIG_FILE(); String conf_path = LAYOUT_CONFIG_FILE();
if (cf->load(conf_path) == OK) { if (cf->load(conf_path) == OK) {
Variant value = cf->get_value("debugger", "update_interval_msec", 0); Variant value = cf->get_value("LimboAI", "debugger_update_interval_msec", 0);
update_interval->set_value(value); update_interval->set_value(value);
} }
} break; } break;
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
Ref<ConfigFile> cf; Ref<ConfigFile> cf;
cf.instantiate(); cf.instantiate();
String conf_path = PROJECT_CONFIG_FILE(); String conf_path = LAYOUT_CONFIG_FILE();
cf->load(conf_path); cf->load(conf_path);
cf->set_value("debugger", "update_interval_msec", update_interval->get_value()); cf->set_value("LimboAI", "debugger_update_interval_msec", update_interval->get_value());
cf->save(conf_path); cf->save(conf_path);
} break; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {

View File

@ -293,6 +293,34 @@ Ref<BlackboardPlan> LimboAIEditor::get_edited_blackboard_plan() {
return task_tree->get_bt()->get_blackboard_plan(); return task_tree->get_bt()->get_blackboard_plan();
} }
void LimboAIEditor::set_window_layout(const Ref<ConfigFile> &p_configuration) {
Array open_bts;
open_bts = p_configuration->get_value("LimboAI", "bteditor_open_bts", open_bts);
for (int i = 0; i < open_bts.size(); i++) {
String path = open_bts[i];
if (FILE_EXISTS(path)) {
_load_bt(path);
}
}
hsc->set_split_offset(p_configuration->get_value("LimboAI", "bteditor_hsplit", hsc->get_split_offset()));
}
void LimboAIEditor::get_window_layout(const Ref<ConfigFile> &p_configuration) {
Array open_bts;
for (const Ref<BehaviorTree> &bt : history) {
open_bts.push_back(bt->get_path());
}
p_configuration->set_value("LimboAI", "bteditor_open_bts", open_bts);
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;
}
p_configuration->set_value("LimboAI", "bteditor_hsplit", split_offset);
}
void LimboAIEditor::_mark_as_dirty(bool p_dirty) { void LimboAIEditor::_mark_as_dirty(bool p_dirty) {
Ref<BehaviorTree> bt = task_tree->get_bt(); Ref<BehaviorTree> bt = task_tree->get_bt();
if (p_dirty && !dirty.has(bt)) { if (p_dirty && !dirty.has(bt)) {
@ -1361,27 +1389,7 @@ void LimboAIEditor::_do_update_theme_item_cache() {
void LimboAIEditor::_notification(int p_what) { void LimboAIEditor::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
Ref<ConfigFile> cf;
cf.instantiate();
String conf_path = PROJECT_CONFIG_FILE();
if (cf->load(conf_path) == OK) {
hsc->set_split_offset(cf->get_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset()));
}
} break;
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
Ref<ConfigFile> cf;
cf.instantiate();
String conf_path = PROJECT_CONFIG_FILE();
cf->load(conf_path);
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);
task_tree->unload(); task_tree->unload();
for (int i = 0; i < history.size(); i++) { for (int i = 0; i < history.size(); i++) {
if (history[i]->is_connected(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty))) { if (history[i]->is_connected(LW_NAME(changed), callable_mp(this, &LimboAIEditor::_mark_as_dirty))) {
@ -1428,7 +1436,6 @@ void LimboAIEditor::_notification(int p_what) {
EDITOR_FILE_SYSTEM()->connect("resources_reload", callable_mp(this, &LimboAIEditor::_on_resources_reload)); EDITOR_FILE_SYSTEM()->connect("resources_reload", callable_mp(this, &LimboAIEditor::_on_resources_reload));
EDITOR_FILE_SYSTEM()->connect("filesystem_changed", callable_mp(this, &LimboAIEditor::_on_filesystem_changed)); EDITOR_FILE_SYSTEM()->connect("filesystem_changed", callable_mp(this, &LimboAIEditor::_on_filesystem_changed));
} break; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
_do_update_theme_item_cache(); _do_update_theme_item_cache();
@ -1856,6 +1863,22 @@ void LimboAIEditorPlugin::_make_visible(bool p_visible) {
limbo_ai_editor->set_visible(p_visible); limbo_ai_editor->set_visible(p_visible);
} }
#ifdef LIMBOAI_MODULE
void LimboAIEditorPlugin::get_window_layout(Ref<ConfigFile> p_configuration) {
#elif LIMBOAI_GDEXTENSION
void LimboAIEditorPlugin::_get_window_layout(const Ref<ConfigFile> &p_configuration) {
#endif
limbo_ai_editor->get_window_layout(p_configuration);
}
#ifdef LIMBOAI_MODULE
void LimboAIEditorPlugin::set_window_layout(Ref<ConfigFile> p_configuration) {
#elif LIMBOAI_GDEXTENSION
void LimboAIEditorPlugin::_set_window_layout(const Ref<ConfigFile> &p_configuration) {
#endif
limbo_ai_editor->set_window_layout(p_configuration);
}
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
void LimboAIEditorPlugin::edit(Object *p_object) { void LimboAIEditorPlugin::edit(Object *p_object) {
#elif LIMBOAI_GDEXTENSION #elif LIMBOAI_GDEXTENSION

View File

@ -63,6 +63,7 @@
#include <godot_cpp/classes/texture2d.hpp> #include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/variant/packed_string_array.hpp> #include <godot_cpp/variant/packed_string_array.hpp>
#include <godot_cpp/variant/variant.hpp> #include <godot_cpp/variant/variant.hpp>
#include <godot_cpp/classes/config_file.hpp>
using namespace godot; using namespace godot;
@ -263,6 +264,8 @@ public:
void set_plugin(EditorPlugin *p_plugin) { plugin = p_plugin; }; void set_plugin(EditorPlugin *p_plugin) { plugin = p_plugin; };
void edit_bt(const Ref<BehaviorTree> &p_behavior_tree, bool p_force_refresh = false); void edit_bt(const Ref<BehaviorTree> &p_behavior_tree, bool p_force_refresh = false);
Ref<BlackboardPlan> get_edited_blackboard_plan(); Ref<BlackboardPlan> get_edited_blackboard_plan();
void set_window_layout(const Ref<ConfigFile> &p_configuration);
void get_window_layout(const Ref<ConfigFile> &p_configuration);
void apply_changes(); void apply_changes();
@ -293,6 +296,8 @@ public:
virtual void apply_changes() override; virtual void apply_changes() override;
virtual void edit(Object *p_object) override; virtual void edit(Object *p_object) override;
virtual bool handles(Object *p_object) const override; virtual bool handles(Object *p_object) const override;
virtual void set_window_layout(Ref<ConfigFile> p_configuration) override;
virtual void get_window_layout(Ref<ConfigFile> p_configuration) override;
#elif LIMBOAI_GDEXTENSION #elif LIMBOAI_GDEXTENSION
bool _has_main_screen() const override { return true; } bool _has_main_screen() const override { return true; }
@ -303,6 +308,8 @@ public:
virtual void _edit(Object *p_object) override; virtual void _edit(Object *p_object) override;
virtual bool _handles(Object *p_object) const override; virtual bool _handles(Object *p_object) const override;
virtual Ref<Texture2D> _get_plugin_icon() const override; virtual Ref<Texture2D> _get_plugin_icon() const override;
virtual void _set_window_layout(const Ref<ConfigFile> &p_configuration) override;
virtual void _get_window_layout(const Ref<ConfigFile> &p_configuration) override;
#endif // LIMBOAI_MODULE & LIMBOAI_GDEXTENSION #endif // LIMBOAI_MODULE & LIMBOAI_GDEXTENSION
LimboAIEditorPlugin(); LimboAIEditorPlugin();

View File

@ -440,9 +440,9 @@ void TaskPalette::refresh() {
// Restore collapsed state from config. // Restore collapsed state from config.
Ref<ConfigFile> cf; Ref<ConfigFile> cf;
cf.instantiate(); cf.instantiate();
String conf_path = PROJECT_CONFIG_FILE(); String conf_path = LAYOUT_CONFIG_FILE();
if (cf->load(conf_path) == OK) { if (cf->load(conf_path) == OK) {
Variant value = cf->get_value("task_palette", "collapsed_sections", Array()); Variant value = cf->get_value("LimboAI", "task_palette_collapsed_sections", Array());
if (VARIANT_IS_ARRAY(value)) { if (VARIANT_IS_ARRAY(value)) {
Array arr = value; Array arr = value;
for (int i = 0; i < arr.size(); i++) { for (int i = 0; i < arr.size(); i++) {
@ -547,19 +547,19 @@ void TaskPalette::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
Ref<ConfigFile> cf; Ref<ConfigFile> cf;
cf.instantiate(); cf.instantiate();
String conf_path = PROJECT_CONFIG_FILE(); String conf_path = LAYOUT_CONFIG_FILE();
if (cf->load(conf_path) == OK) { if (cf->load(conf_path) == OK) {
Variant value = cf->get_value("task_palette", "type_filter", FilterSettings::TypeFilter(0)); Variant value = cf->get_value("LimboAI", "task_palette_type_filter", FilterSettings::TypeFilter(0));
if (VARIANT_IS_NUM(value)) { if (VARIANT_IS_NUM(value)) {
filter_settings.type_filter = (FilterSettings::TypeFilter)(int)value; filter_settings.type_filter = (FilterSettings::TypeFilter)(int)value;
} }
value = cf->get_value("task_palette", "category_filter", FilterSettings::CategoryFilter(0)); value = cf->get_value("LimboAI", "task_palette_category_filter", FilterSettings::CategoryFilter(0));
if (VARIANT_IS_NUM(value)) { if (VARIANT_IS_NUM(value)) {
filter_settings.category_filter = (FilterSettings::CategoryFilter)(int)value; filter_settings.category_filter = (FilterSettings::CategoryFilter)(int)value;
} }
value = cf->get_value("task_palette", "excluded_categories", Array()); value = cf->get_value("LimboAI", "task_palette_excluded_categories", Array());
if (VARIANT_IS_ARRAY(value)) { if (VARIANT_IS_ARRAY(value)) {
Array arr = value; Array arr = value;
for (int i = 0; i < arr.size(); i++) { for (int i = 0; i < arr.size(); i++) {
@ -574,7 +574,7 @@ void TaskPalette::_notification(int p_what) {
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
Ref<ConfigFile> cf; Ref<ConfigFile> cf;
cf.instantiate(); cf.instantiate();
String conf_path = PROJECT_CONFIG_FILE(); String conf_path = LAYOUT_CONFIG_FILE();
cf->load(conf_path); cf->load(conf_path);
Array collapsed_sections; Array collapsed_sections;
@ -584,16 +584,16 @@ void TaskPalette::_notification(int p_what) {
collapsed_sections.push_back(sec->get_category_name()); collapsed_sections.push_back(sec->get_category_name());
} }
} }
cf->set_value("task_palette", "collapsed_sections", collapsed_sections); cf->set_value("LimboAI", "task_palette_collapsed_sections", collapsed_sections);
cf->set_value("task_palette", "type_filter", filter_settings.type_filter); cf->set_value("LimboAI", "task_palette_type_filter", filter_settings.type_filter);
cf->set_value("task_palette", "category_filter", filter_settings.category_filter); cf->set_value("LimboAI", "task_palette_category_filter", filter_settings.category_filter);
Array excluded_categories; Array excluded_categories;
for (const String &cat : filter_settings.excluded_categories) { for (const String &cat : filter_settings.excluded_categories) {
excluded_categories.append(cat); excluded_categories.append(cat);
} }
cf->set_value("task_palette", "excluded_categories", excluded_categories); cf->set_value("LimboAI", "task_palette_excluded_categories", excluded_categories);
cf->save(conf_path); cf->save(conf_path);
} break; } break;

View File

@ -170,7 +170,7 @@ inline void VARIANT_DELETE_IF_OBJECT(Variant m_variant) {
Variant VARIANT_DEFAULT(Variant::Type p_type); Variant VARIANT_DEFAULT(Variant::Type p_type);
#define PROJECT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("limbo_ai.cfg") #define LAYOUT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("editor_layout.cfg")
#define IS_RESOURCE_FILE(m_path) (m_path.begins_with("res://") && m_path.find("::") == -1) #define IS_RESOURCE_FILE(m_path) (m_path.begins_with("res://") && m_path.find("::") == -1)
#define RESOURCE_TYPE_HINT(m_type) vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, m_type) #define RESOURCE_TYPE_HINT(m_type) vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, m_type)
#define RESOURCE_IS_BUILT_IN(m_res) (m_res->get_path().is_empty() || m_res->get_path().contains("::")) #define RESOURCE_IS_BUILT_IN(m_res) (m_res->get_path().is_empty() || m_res->get_path().contains("::"))