From 064d00fdfabcb92281ca6c0d09e90e1df9ef688e Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sat, 18 May 2024 13:37:24 +0200 Subject: [PATCH] Editor: Check if variable is of correct type for BBParam subtypes --- blackboard/bb_param/bb_node.h | 4 +--- blackboard/bb_param/bb_param.h | 4 ++-- blackboard/bb_param/bb_variant.h | 2 ++ editor/editor_property_bb_param.cpp | 3 ++- editor/editor_property_bb_param.h | 1 + editor/editor_property_variable_name.cpp | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/blackboard/bb_param/bb_node.h b/blackboard/bb_param/bb_node.h index ce6c0eed..51ecad32 100644 --- a/blackboard/bb_param/bb_node.h +++ b/blackboard/bb_param/bb_node.h @@ -17,10 +17,8 @@ class BBNode : public BBParam { GDCLASS(BBNode, BBParam); -protected: - virtual Variant::Type get_type() const override { return Variant::NODE_PATH; } - public: + virtual Variant::Type get_type() const override { return Variant::NODE_PATH; } virtual Variant get_value(Node *p_scene_root, const Ref &p_blackboard, const Variant &p_default = Variant()) override; }; diff --git a/blackboard/bb_param/bb_param.h b/blackboard/bb_param/bb_param.h index 98a96cbe..262db5f4 100644 --- a/blackboard/bb_param/bb_param.h +++ b/blackboard/bb_param/bb_param.h @@ -49,8 +49,6 @@ class BBParam : public Resource { void _get_property_list(List *p_list) const; public: - virtual Variant::Type get_type() const { return Variant::NIL; } - void set_value_source(ValueSource p_value); ValueSource get_value_source() const { return value_source; } @@ -66,6 +64,8 @@ class BBParam : public Resource { virtual String _to_string(); #endif + virtual Variant::Type get_type() const { return Variant::NIL; } + virtual Variant::Type get_variable_expected_type() const { return get_type(); } virtual Variant get_value(Node *p_scene_root, const Ref &p_blackboard, const Variant &p_default = Variant()); BBParam(); diff --git a/blackboard/bb_param/bb_variant.h b/blackboard/bb_param/bb_variant.h index f996987e..6f5a382f 100644 --- a/blackboard/bb_param/bb_variant.h +++ b/blackboard/bb_param/bb_variant.h @@ -27,6 +27,8 @@ class BBVariant : public BBParam { virtual Variant::Type get_type() const override; void set_type(Variant::Type p_type); + virtual Variant::Type get_variable_expected_type() const override { return Variant::NIL; } + BBVariant(const Variant &p_value); BBVariant(); }; diff --git a/editor/editor_property_bb_param.cpp b/editor/editor_property_bb_param.cpp index 707fdbb1..5969baa1 100644 --- a/editor/editor_property_bb_param.cpp +++ b/editor/editor_property_bb_param.cpp @@ -283,6 +283,7 @@ void EditorPropertyBBParam::update_property() { if (param->get_value_source() == BBParam::BLACKBOARD_VAR) { _remove_value_editor(); variable_editor->set_object_and_property(param.ptr(), SNAME("variable")); + variable_editor->setup(plan, false, param->get_variable_expected_type()); variable_editor->update_property(); variable_editor->show(); bottom_container->hide(); @@ -300,7 +301,7 @@ void EditorPropertyBBParam::update_property() { void EditorPropertyBBParam::setup(PropertyHint p_hint, const String &p_hint_text, const Ref &p_plan) { param_type = p_hint_text; property_hint = p_hint; - variable_editor->setup(p_plan, false); + plan = p_plan; variable_editor->set_name_split_ratio(0.0); } diff --git a/editor/editor_property_bb_param.h b/editor/editor_property_bb_param.h index 5c78f715..f9a84992 100644 --- a/editor/editor_property_bb_param.h +++ b/editor/editor_property_bb_param.h @@ -36,6 +36,7 @@ class EditorPropertyBBParam : public EditorProperty { bool initialized = false; + Ref plan; StringName param_type; PropertyHint property_hint = PROPERTY_HINT_NONE; diff --git a/editor/editor_property_variable_name.cpp b/editor/editor_property_variable_name.cpp index 0c402930..ad3cb69f 100644 --- a/editor/editor_property_variable_name.cpp +++ b/editor/editor_property_variable_name.cpp @@ -96,7 +96,7 @@ void EditorPropertyVariableName::_update_status() { } else { BUTTON_SET_ICON(status_btn, theme_cache.var_error_icon); status_btn->set_tooltip_text(TTR(vformat( - "The %s variable in the blackboard plan is not of the same type as this variable (expected %s).\nClick to open the blackboard plan and fix the variable type.", + "The %s variable in the blackboard plan should be of type %s.\nClick to open the blackboard plan.", LimboUtility::get_singleton()->decorate_var(var_name), Variant::get_type_name(expected_type)))); }