Skip to content

Commit 134bb32

Browse files
authored
Merge pull request #225 from ydeltastar/remember-last-session
Remember loaded `BehaviorTree`s of last session
2 parents 08884e6 + db7c990 commit 134bb32

File tree

5 files changed

+67
-37
lines changed

5 files changed

+67
-37
lines changed

editor/debugger/limbo_debugger_plugin.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,18 @@ void LimboDebuggerTab::_notification(int p_what) {
193193

194194
Ref<ConfigFile> cf;
195195
cf.instantiate();
196-
String conf_path = PROJECT_CONFIG_FILE();
196+
String conf_path = LAYOUT_CONFIG_FILE();
197197
if (cf->load(conf_path) == OK) {
198-
Variant value = cf->get_value("debugger", "update_interval_msec", 0);
198+
Variant value = cf->get_value("LimboAI", "debugger_update_interval_msec", 0);
199199
update_interval->set_value(value);
200200
}
201201
} break;
202202
case NOTIFICATION_EXIT_TREE: {
203203
Ref<ConfigFile> cf;
204204
cf.instantiate();
205-
String conf_path = PROJECT_CONFIG_FILE();
205+
String conf_path = LAYOUT_CONFIG_FILE();
206206
cf->load(conf_path);
207-
cf->set_value("debugger", "update_interval_msec", update_interval->get_value());
207+
cf->set_value("LimboAI", "debugger_update_interval_msec", update_interval->get_value());
208208
cf->save(conf_path);
209209
} break;
210210
case NOTIFICATION_THEME_CHANGED: {

editor/limbo_ai_editor_plugin.cpp

+44-21
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,34 @@ Ref<BlackboardPlan> LimboAIEditor::get_edited_blackboard_plan() {
293293
return task_tree->get_bt()->get_blackboard_plan();
294294
}
295295

296+
void LimboAIEditor::set_window_layout(const Ref<ConfigFile> &p_configuration) {
297+
Array open_bts;
298+
open_bts = p_configuration->get_value("LimboAI", "bteditor_open_bts", open_bts);
299+
for (int i = 0; i < open_bts.size(); i++) {
300+
String path = open_bts[i];
301+
if (FILE_EXISTS(path)) {
302+
_load_bt(path);
303+
}
304+
}
305+
306+
hsc->set_split_offset(p_configuration->get_value("LimboAI", "bteditor_hsplit", hsc->get_split_offset()));
307+
}
308+
309+
void LimboAIEditor::get_window_layout(const Ref<ConfigFile> &p_configuration) {
310+
Array open_bts;
311+
for (const Ref<BehaviorTree> &bt : history) {
312+
open_bts.push_back(bt->get_path());
313+
}
314+
p_configuration->set_value("LimboAI", "bteditor_open_bts", open_bts);
315+
316+
int split_offset = hsc->get_split_offset();
317+
if (editor_layout != (int)EDITOR_GET("limbo_ai/editor/layout")) {
318+
// Editor layout settings changed - flip split offset.
319+
split_offset *= -1;
320+
}
321+
p_configuration->set_value("LimboAI", "bteditor_hsplit", split_offset);
322+
}
323+
296324
void LimboAIEditor::_mark_as_dirty(bool p_dirty) {
297325
Ref<BehaviorTree> bt = task_tree->get_bt();
298326
if (p_dirty && !dirty.has(bt)) {
@@ -1361,27 +1389,7 @@ void LimboAIEditor::_do_update_theme_item_cache() {
13611389

13621390
void LimboAIEditor::_notification(int p_what) {
13631391
switch (p_what) {
1364-
case NOTIFICATION_ENTER_TREE: {
1365-
Ref<ConfigFile> cf;
1366-
cf.instantiate();
1367-
String conf_path = PROJECT_CONFIG_FILE();
1368-
if (cf->load(conf_path) == OK) {
1369-
hsc->set_split_offset(cf->get_value("bt_editor", "bteditor_hsplit", hsc->get_split_offset()));
1370-
}
1371-
} break;
13721392
case NOTIFICATION_EXIT_TREE: {
1373-
Ref<ConfigFile> cf;
1374-
cf.instantiate();
1375-
String conf_path = PROJECT_CONFIG_FILE();
1376-
cf->load(conf_path);
1377-
int split_offset = hsc->get_split_offset();
1378-
if (editor_layout != (int)EDITOR_GET("limbo_ai/editor/layout")) {
1379-
// Editor layout settings changed - flip split offset.
1380-
split_offset *= -1;
1381-
}
1382-
cf->set_value("bt_editor", "bteditor_hsplit", split_offset);
1383-
cf->save(conf_path);
1384-
13851393
task_tree->unload();
13861394
for (int i = 0; i < history.size(); i++) {
13871395
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) {
14281436

14291437
EDITOR_FILE_SYSTEM()->connect("resources_reload", callable_mp(this, &LimboAIEditor::_on_resources_reload));
14301438
EDITOR_FILE_SYSTEM()->connect("filesystem_changed", callable_mp(this, &LimboAIEditor::_on_filesystem_changed));
1431-
14321439
} break;
14331440
case NOTIFICATION_THEME_CHANGED: {
14341441
_do_update_theme_item_cache();
@@ -1856,6 +1863,22 @@ void LimboAIEditorPlugin::_make_visible(bool p_visible) {
18561863
limbo_ai_editor->set_visible(p_visible);
18571864
}
18581865

1866+
#ifdef LIMBOAI_MODULE
1867+
void LimboAIEditorPlugin::get_window_layout(Ref<ConfigFile> p_configuration) {
1868+
#elif LIMBOAI_GDEXTENSION
1869+
void LimboAIEditorPlugin::_get_window_layout(const Ref<ConfigFile> &p_configuration) {
1870+
#endif
1871+
limbo_ai_editor->get_window_layout(p_configuration);
1872+
}
1873+
1874+
#ifdef LIMBOAI_MODULE
1875+
void LimboAIEditorPlugin::set_window_layout(Ref<ConfigFile> p_configuration) {
1876+
#elif LIMBOAI_GDEXTENSION
1877+
void LimboAIEditorPlugin::_set_window_layout(const Ref<ConfigFile> &p_configuration) {
1878+
#endif
1879+
limbo_ai_editor->set_window_layout(p_configuration);
1880+
}
1881+
18591882
#ifdef LIMBOAI_MODULE
18601883
void LimboAIEditorPlugin::edit(Object *p_object) {
18611884
#elif LIMBOAI_GDEXTENSION

editor/limbo_ai_editor_plugin.h

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include <godot_cpp/classes/texture2d.hpp>
6464
#include <godot_cpp/variant/packed_string_array.hpp>
6565
#include <godot_cpp/variant/variant.hpp>
66+
#include <godot_cpp/classes/config_file.hpp>
6667

6768
using namespace godot;
6869

@@ -263,6 +264,8 @@ class LimboAIEditor : public Control {
263264
void set_plugin(EditorPlugin *p_plugin) { plugin = p_plugin; };
264265
void edit_bt(const Ref<BehaviorTree> &p_behavior_tree, bool p_force_refresh = false);
265266
Ref<BlackboardPlan> get_edited_blackboard_plan();
267+
void set_window_layout(const Ref<ConfigFile> &p_configuration);
268+
void get_window_layout(const Ref<ConfigFile> &p_configuration);
266269

267270
void apply_changes();
268271

@@ -293,6 +296,8 @@ class LimboAIEditorPlugin : public EditorPlugin {
293296
virtual void apply_changes() override;
294297
virtual void edit(Object *p_object) override;
295298
virtual bool handles(Object *p_object) const override;
299+
virtual void set_window_layout(Ref<ConfigFile> p_configuration) override;
300+
virtual void get_window_layout(Ref<ConfigFile> p_configuration) override;
296301

297302
#elif LIMBOAI_GDEXTENSION
298303
bool _has_main_screen() const override { return true; }
@@ -303,6 +308,8 @@ class LimboAIEditorPlugin : public EditorPlugin {
303308
virtual void _edit(Object *p_object) override;
304309
virtual bool _handles(Object *p_object) const override;
305310
virtual Ref<Texture2D> _get_plugin_icon() const override;
311+
virtual void _set_window_layout(const Ref<ConfigFile> &p_configuration) override;
312+
virtual void _get_window_layout(const Ref<ConfigFile> &p_configuration) override;
306313
#endif // LIMBOAI_MODULE & LIMBOAI_GDEXTENSION
307314

308315
LimboAIEditorPlugin();

editor/task_palette.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ void TaskPalette::refresh() {
440440
// Restore collapsed state from config.
441441
Ref<ConfigFile> cf;
442442
cf.instantiate();
443-
String conf_path = PROJECT_CONFIG_FILE();
443+
String conf_path = LAYOUT_CONFIG_FILE();
444444
if (cf->load(conf_path) == OK) {
445-
Variant value = cf->get_value("task_palette", "collapsed_sections", Array());
445+
Variant value = cf->get_value("LimboAI", "task_palette_collapsed_sections", Array());
446446
if (VARIANT_IS_ARRAY(value)) {
447447
Array arr = value;
448448
for (int i = 0; i < arr.size(); i++) {
@@ -547,19 +547,19 @@ void TaskPalette::_notification(int p_what) {
547547
case NOTIFICATION_ENTER_TREE: {
548548
Ref<ConfigFile> cf;
549549
cf.instantiate();
550-
String conf_path = PROJECT_CONFIG_FILE();
550+
String conf_path = LAYOUT_CONFIG_FILE();
551551
if (cf->load(conf_path) == OK) {
552-
Variant value = cf->get_value("task_palette", "type_filter", FilterSettings::TypeFilter(0));
552+
Variant value = cf->get_value("LimboAI", "task_palette_type_filter", FilterSettings::TypeFilter(0));
553553
if (VARIANT_IS_NUM(value)) {
554554
filter_settings.type_filter = (FilterSettings::TypeFilter)(int)value;
555555
}
556556

557-
value = cf->get_value("task_palette", "category_filter", FilterSettings::CategoryFilter(0));
557+
value = cf->get_value("LimboAI", "task_palette_category_filter", FilterSettings::CategoryFilter(0));
558558
if (VARIANT_IS_NUM(value)) {
559559
filter_settings.category_filter = (FilterSettings::CategoryFilter)(int)value;
560560
}
561561

562-
value = cf->get_value("task_palette", "excluded_categories", Array());
562+
value = cf->get_value("LimboAI", "task_palette_excluded_categories", Array());
563563
if (VARIANT_IS_ARRAY(value)) {
564564
Array arr = value;
565565
for (int i = 0; i < arr.size(); i++) {
@@ -574,7 +574,7 @@ void TaskPalette::_notification(int p_what) {
574574
case NOTIFICATION_EXIT_TREE: {
575575
Ref<ConfigFile> cf;
576576
cf.instantiate();
577-
String conf_path = PROJECT_CONFIG_FILE();
577+
String conf_path = LAYOUT_CONFIG_FILE();
578578
cf->load(conf_path);
579579

580580
Array collapsed_sections;
@@ -584,16 +584,16 @@ void TaskPalette::_notification(int p_what) {
584584
collapsed_sections.push_back(sec->get_category_name());
585585
}
586586
}
587-
cf->set_value("task_palette", "collapsed_sections", collapsed_sections);
587+
cf->set_value("LimboAI", "task_palette_collapsed_sections", collapsed_sections);
588588

589-
cf->set_value("task_palette", "type_filter", filter_settings.type_filter);
590-
cf->set_value("task_palette", "category_filter", filter_settings.category_filter);
589+
cf->set_value("LimboAI", "task_palette_type_filter", filter_settings.type_filter);
590+
cf->set_value("LimboAI", "task_palette_category_filter", filter_settings.category_filter);
591591

592592
Array excluded_categories;
593593
for (const String &cat : filter_settings.excluded_categories) {
594594
excluded_categories.append(cat);
595595
}
596-
cf->set_value("task_palette", "excluded_categories", excluded_categories);
596+
cf->set_value("LimboAI", "task_palette_excluded_categories", excluded_categories);
597597

598598
cf->save(conf_path);
599599
} break;

util/limbo_compat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ inline void VARIANT_DELETE_IF_OBJECT(Variant m_variant) {
170170

171171
Variant VARIANT_DEFAULT(Variant::Type p_type);
172172

173-
#define PROJECT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("limbo_ai.cfg")
173+
#define LAYOUT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("editor_layout.cfg")
174174
#define IS_RESOURCE_FILE(m_path) (m_path.begins_with("res://") && m_path.find("::") == -1)
175175
#define RESOURCE_TYPE_HINT(m_type) vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, m_type)
176176
#define RESOURCE_IS_BUILT_IN(m_res) (m_res->get_path().is_empty() || m_res->get_path().contains("::"))

0 commit comments

Comments
 (0)