Update name of parameter in editor

This commit is contained in:
Serhii Snitsaruk 2022-10-20 22:53:09 +02:00
parent 34ef7d96ea
commit 54addba8a3
4 changed files with 29 additions and 15 deletions

View File

@ -8,6 +8,25 @@
VARIANT_ENUM_CAST(BBParam::ValueSource); VARIANT_ENUM_CAST(BBParam::ValueSource);
void BBParam::set_value_source(ValueSource p_value) {
value_source = p_value;
property_list_changed_notify();
_update_name();
emit_changed();
}
void BBParam::set_saved_value(Variant p_value) {
saved_value = p_value;
_update_name();
emit_changed();
}
void BBParam::set_variable(const String &p_value) {
variable = p_value;
_update_name();
emit_changed();
}
Variant BBParam::get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default) { Variant BBParam::get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default) {
ERR_FAIL_COND_V(p_blackboard.is_valid(), p_default); ERR_FAIL_COND_V(p_blackboard.is_valid(), p_default);
@ -34,7 +53,7 @@ void BBParam::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_variable", "p_variable_name"), &BBParam::set_variable); ClassDB::bind_method(D_METHOD("set_variable", "p_variable_name"), &BBParam::set_variable);
ClassDB::bind_method(D_METHOD("get_variable"), &BBParam::get_variable); ClassDB::bind_method(D_METHOD("get_variable"), &BBParam::get_variable);
ClassDB::bind_method(D_METHOD("get_type"), &BBParam::get_type); ClassDB::bind_method(D_METHOD("get_type"), &BBParam::get_type);
ClassDB::bind_method(D_METHOD("get_value"), &BBParam::get_value); ClassDB::bind_method(D_METHOD("get_value", "p_agent", "p_blackboard", "p_default"), &BBParam::get_value, Variant());
ADD_PROPERTY(PropertyInfo(Variant::INT, "value_source", PROPERTY_HINT_ENUM, "Saved Value, Blackboard Var"), "set_value_source", "get_value_source"); ADD_PROPERTY(PropertyInfo(Variant::INT, "value_source", PROPERTY_HINT_ENUM, "Saved Value, Blackboard Var"), "set_value_source", "get_value_source");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable", PROPERTY_HINT_NONE, "", 0), "set_variable", "get_variable"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable", PROPERTY_HINT_NONE, "", 0), "set_variable", "get_variable");

View File

@ -5,8 +5,10 @@
#include "core/object.h" #include "core/object.h"
#include "core/resource.h" #include "core/resource.h"
#include "core/typedefs.h"
#include "core/variant.h" #include "core/variant.h"
#include "modules/limboai/blackboard.h" #include "modules/limboai/blackboard.h"
#include "modules/limboai/limbo_utility.h"
class BBParam : public Resource { class BBParam : public Resource {
GDCLASS(BBParam, Resource); GDCLASS(BBParam, Resource);
@ -22,6 +24,10 @@ private:
Variant saved_value; Variant saved_value;
String variable; String variable;
_FORCE_INLINE_ void _update_name() {
set_name((value_source == SAVED_VALUE) ? String(saved_value) : LimboUtility::get_singleton()->decorate_var(variable));
}
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -30,23 +36,13 @@ protected:
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
public: public:
void set_value_source(ValueSource p_value) { void set_value_source(ValueSource p_value);
value_source = p_value;
property_list_changed_notify();
emit_changed();
}
ValueSource get_value_source() const { return value_source; } ValueSource get_value_source() const { return value_source; }
void set_saved_value(Variant p_value) { void set_saved_value(Variant p_value);
saved_value = p_value;
emit_changed();
}
Variant get_saved_value() const { return saved_value; } Variant get_saved_value() const { return saved_value; }
void set_variable(const String &p_value) { void set_variable(const String &p_value);
variable = p_value;
emit_changed();
}
String get_variable() const { return variable; } String get_variable() const { return variable; }
virtual Variant get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant()); virtual Variant get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant());

View File

Before

Width:  |  Height:  |  Size: 510 B

After

Width:  |  Height:  |  Size: 510 B

View File

@ -122,7 +122,6 @@ void register_limboai_types() {
ClassDB::register_class<BTCondition>(); ClassDB::register_class<BTCondition>();
// ClassDB::register_class<BBParam>();
ClassDB::register_virtual_class<BBParam>(); ClassDB::register_virtual_class<BBParam>();
ClassDB::register_class<BBInt>(); ClassDB::register_class<BBInt>();
ClassDB::register_class<BBBool>(); ClassDB::register_class<BBBool>();