From 2718271bb1e7de7fe8c23e94f2d48abf47763ec7 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Wed, 15 May 2024 20:43:24 +0200 Subject: [PATCH] Clean up & renames --- blackboard/blackboard_plan.cpp | 5 ++--- editor/blackboard_plan_editor.cpp | 6 +++++- editor/blackboard_plan_editor.h | 3 ++- editor/editor_property_variable_name.cpp | 24 ++++++++++++++---------- editor/editor_property_variable_name.h | 11 ++++++----- editor/limbo_ai_editor_plugin.cpp | 2 +- 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index 1720e72..acc100b 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -425,11 +425,10 @@ void BlackboardPlan::_bind_methods() { ClassDB::bind_method(D_METHOD("set_base_plan", "blackboard_plan"), &BlackboardPlan::set_base_plan); ClassDB::bind_method(D_METHOD("get_base_plan"), &BlackboardPlan::get_base_plan); - ClassDB::bind_method(D_METHOD("set_parent_scope_plan_provider", "callable"), &BlackboardPlan::set_parent_scope_plan_provider); - ClassDB::bind_method(D_METHOD("get_parent_scope_plan_provider"), &BlackboardPlan::get_parent_scope_plan_provider); - ClassDB::bind_method(D_METHOD("is_mapping_enabled"), &BlackboardPlan::is_mapping_enabled); ClassDB::bind_method(D_METHOD("is_derived"), &BlackboardPlan::is_derived); ClassDB::bind_method(D_METHOD("sync_with_base_plan"), &BlackboardPlan::sync_with_base_plan); + ClassDB::bind_method(D_METHOD("set_parent_scope_plan_provider", "callable"), &BlackboardPlan::set_parent_scope_plan_provider); + ClassDB::bind_method(D_METHOD("get_parent_scope_plan_provider"), &BlackboardPlan::get_parent_scope_plan_provider); ClassDB::bind_method(D_METHOD("create_blackboard", "node"), &BlackboardPlan::create_blackboard); ClassDB::bind_method(D_METHOD("populate_blackboard", "blackboard", "overwrite", "node"), &BlackboardPlan::populate_blackboard); diff --git a/editor/blackboard_plan_editor.cpp b/editor/blackboard_plan_editor.cpp index c0424b8..a33220c 100644 --- a/editor/blackboard_plan_editor.cpp +++ b/editor/blackboard_plan_editor.cpp @@ -55,6 +55,9 @@ void BlackboardPlanEditor::_add_var() { } BBVariable var(default_type, default_hint, default_hint_string); + if (default_value.get_type() == default_type) { + var.set_value(default_value); + } plan->add_var(var_name, var); reset_defaults(); _refresh(); @@ -128,11 +131,12 @@ void BlackboardPlanEditor::edit_plan(const Ref &p_plan) { _refresh(); } -void BlackboardPlanEditor::set_defaults(const StringName &p_var_name, Variant::Type p_type, PropertyHint p_hint, String p_hint_string) { +void BlackboardPlanEditor::set_defaults(const StringName &p_var_name, Variant::Type p_type, PropertyHint p_hint, String p_hint_string, Variant p_value) { default_var_name = p_var_name; default_type = p_type; default_hint = p_hint; default_hint_string = p_hint_string; + default_value = p_value; } void BlackboardPlanEditor::reset_defaults() { diff --git a/editor/blackboard_plan_editor.h b/editor/blackboard_plan_editor.h index b1609a4..a711184 100644 --- a/editor/blackboard_plan_editor.h +++ b/editor/blackboard_plan_editor.h @@ -62,6 +62,7 @@ private: Variant::Type default_type = Variant::NIL; PropertyHint default_hint = PROPERTY_HINT_NONE; String default_hint_string; + Variant default_value; VBoxContainer *rows_vbox; Button *add_var_tool; @@ -102,7 +103,7 @@ public: _FORCE_INLINE_ static BlackboardPlanEditor *get_singleton() { return singleton; } void edit_plan(const Ref &p_plan); - void set_defaults(const StringName &p_name, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = ""); + void set_defaults(const StringName &p_name, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = "", Variant p_value = Variant()); void reset_defaults(); BlackboardPlanEditor(); diff --git a/editor/editor_property_variable_name.cpp b/editor/editor_property_variable_name.cpp index 176c236..529a2d9 100644 --- a/editor/editor_property_variable_name.cpp +++ b/editor/editor_property_variable_name.cpp @@ -105,7 +105,8 @@ void EditorPropertyVariableName::_update_status() { void EditorPropertyVariableName::_status_pressed() { ERR_FAIL_NULL(plan); if (!plan->has_var(name_edit->get_text())) { - BlackboardPlanEditor::get_singleton()->set_defaults(name_edit->get_text(), expected_type, expected_hint, expected_hint_string); + BlackboardPlanEditor::get_singleton()->set_defaults(name_edit->get_text(), + expected_type, default_hint, default_hint_string, default_value); } BlackboardPlanEditor::get_singleton()->edit_plan(plan); BlackboardPlanEditor::get_singleton()->popup_centered(); @@ -138,12 +139,13 @@ void EditorPropertyVariableName::_update_property() { _update_status(); } -void EditorPropertyVariableName::setup(const Ref &p_plan, bool p_allow_empty, Variant::Type p_type, PropertyHint p_hint, String p_hint_string) { +void EditorPropertyVariableName::setup(const Ref &p_plan, bool p_allow_empty, Variant::Type p_type, PropertyHint p_hint, String p_hint_string, Variant p_default_value) { plan = p_plan; allow_empty = p_allow_empty; expected_type = p_type; - expected_hint = p_hint; - expected_hint_string = p_hint_string; + default_hint = p_hint; + default_hint_string = p_hint_string; + default_value = p_default_value; _update_status(); } @@ -238,8 +240,9 @@ bool EditorInspectorPluginVariableName::_parse_property(Object *p_object, const Ref plan; Variant::Type expected_type = Variant::NIL; - PropertyHint expected_hint = PROPERTY_HINT_NONE; - String expected_hint_string; + PropertyHint default_hint = PROPERTY_HINT_NONE; + String default_hint_string; + Variant default_value; if (is_mapping) { plan.reference_ptr(Object::cast_to(p_object)); ERR_FAIL_NULL_V(plan, false); @@ -247,8 +250,9 @@ bool EditorInspectorPluginVariableName::_parse_property(Object *p_object, const if (plan->has_var(var_name)) { BBVariable variable = plan->get_var(var_name); expected_type = variable.get_type(); - expected_hint = variable.get_hint(); - expected_hint_string = variable.get_hint_string(); + default_hint = variable.get_hint(); + default_hint_string = variable.get_hint_string(); + default_value = variable.get_value(); } if (plan->get_parent_scope_plan_provider().is_valid()) { Ref parent_plan = plan->get_parent_scope_plan_provider().call(); @@ -258,11 +262,11 @@ bool EditorInspectorPluginVariableName::_parse_property(Object *p_object, const } ERR_FAIL_NULL_V(plan, false); } else { - plan = plan_getter.call(); + plan = editor_plan_provider.call(); } EditorPropertyVariableName *ed = memnew(EditorPropertyVariableName); - ed->setup(plan, is_mapping, expected_type, expected_hint, expected_hint_string); + ed->setup(plan, is_mapping, expected_type, default_hint, default_hint_string, default_value); add_property_editor(p_path, ed, expected_type); return true; diff --git a/editor/editor_property_variable_name.h b/editor/editor_property_variable_name.h index 8cf2df8..ad57b94 100644 --- a/editor/editor_property_variable_name.h +++ b/editor/editor_property_variable_name.h @@ -46,8 +46,9 @@ private: bool allow_empty = false; Variant::Type expected_type = Variant::NIL; - PropertyHint expected_hint = PROPERTY_HINT_NONE; - String expected_hint_string; + PropertyHint default_hint = PROPERTY_HINT_NONE; + String default_hint_string; + Variant default_value; LineEdit *name_edit; Button *drop_btn; @@ -76,7 +77,7 @@ public: virtual void _update_property() override; #endif - void setup(const Ref &p_plan, bool p_allow_empty, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = ""); + void setup(const Ref &p_plan, bool p_allow_empty, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = "", Variant p_default_value = Variant()); EditorPropertyVariableName(); }; @@ -84,7 +85,7 @@ class EditorInspectorPluginVariableName : public EditorInspectorPlugin { GDCLASS(EditorInspectorPluginVariableName, EditorInspectorPlugin); private: - Callable plan_getter; + Callable editor_plan_provider; protected: static void _bind_methods() {} @@ -98,7 +99,7 @@ public: virtual bool _parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField p_usage, const bool p_wide = false) override; #endif - void set_plan_getter(const Callable &p_getter) { plan_getter = p_getter; } + void set_editor_plan_provider(const Callable &p_getter) { editor_plan_provider = p_getter; } EditorInspectorPluginVariableName() = default; }; diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 82df889..09c91a0 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -1486,7 +1486,7 @@ void LimboAIEditorPlugin::_notification(int p_notification) { add_debugger_plugin(memnew(LimboDebuggerPlugin)); add_inspector_plugin(memnew(EditorInspectorPluginBBPlan)); EditorInspectorPluginVariableName *var_plugin = memnew(EditorInspectorPluginVariableName); - var_plugin->set_plan_getter(Callable(limbo_ai_editor, "get_edited_blackboard_plan")); + var_plugin->set_editor_plan_provider(Callable(limbo_ai_editor, "get_edited_blackboard_plan")); add_inspector_plugin(var_plugin); #ifdef LIMBOAI_MODULE // ! Only used in the module version.