Editor: Check if variable is of correct type for BBParam subtypes

This commit is contained in:
Serhii Snitsaruk 2024-05-18 13:37:24 +02:00
parent ff61d55c44
commit 064d00fdfa
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
6 changed files with 9 additions and 7 deletions

View File

@ -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<Blackboard> &p_blackboard, const Variant &p_default = Variant()) override;
};

View File

@ -49,8 +49,6 @@ protected:
void _get_property_list(List<PropertyInfo> *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 @@ public:
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<Blackboard> &p_blackboard, const Variant &p_default = Variant());
BBParam();

View File

@ -27,6 +27,8 @@ public:
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();
};

View File

@ -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<BlackboardPlan> &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);
}

View File

@ -36,6 +36,7 @@ private:
bool initialized = false;
Ref<BlackboardPlan> plan;
StringName param_type;
PropertyHint property_hint = PROPERTY_HINT_NONE;

View File

@ -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))));
}