From 54addba8a3ecd1dc107518afadc753eea9e07e4a Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 20 Oct 2022 22:53:09 +0200 Subject: [PATCH] Update name of parameter in editor --- bb_param/bb_param.cpp | 21 +++++++++++++++++- bb_param/bb_param.h | 22 ++++++++----------- ...cons_blackboard.svg => icon_b_b_param.svg} | 0 register_types.cpp | 1 - 4 files changed, 29 insertions(+), 15 deletions(-) rename icons/unused/{icons_blackboard.svg => icon_b_b_param.svg} (100%) diff --git a/bb_param/bb_param.cpp b/bb_param/bb_param.cpp index a2f7a23..53cf273 100644 --- a/bb_param/bb_param.cpp +++ b/bb_param/bb_param.cpp @@ -8,6 +8,25 @@ 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 &p_blackboard, const Variant &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("get_variable"), &BBParam::get_variable); 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::STRING, "variable", PROPERTY_HINT_NONE, "", 0), "set_variable", "get_variable"); diff --git a/bb_param/bb_param.h b/bb_param/bb_param.h index cbe2241..16bd16a 100644 --- a/bb_param/bb_param.h +++ b/bb_param/bb_param.h @@ -5,8 +5,10 @@ #include "core/object.h" #include "core/resource.h" +#include "core/typedefs.h" #include "core/variant.h" #include "modules/limboai/blackboard.h" +#include "modules/limboai/limbo_utility.h" class BBParam : public Resource { GDCLASS(BBParam, Resource); @@ -22,6 +24,10 @@ private: Variant saved_value; String variable; + _FORCE_INLINE_ void _update_name() { + set_name((value_source == SAVED_VALUE) ? String(saved_value) : LimboUtility::get_singleton()->decorate_var(variable)); + } + protected: static void _bind_methods(); @@ -30,23 +36,13 @@ protected: void _get_property_list(List *p_list) const; public: - void set_value_source(ValueSource p_value) { - value_source = p_value; - property_list_changed_notify(); - emit_changed(); - } + void set_value_source(ValueSource p_value); ValueSource get_value_source() const { return value_source; } - void set_saved_value(Variant p_value) { - saved_value = p_value; - emit_changed(); - } + void set_saved_value(Variant p_value); Variant get_saved_value() const { return saved_value; } - void set_variable(const String &p_value) { - variable = p_value; - emit_changed(); - } + void set_variable(const String &p_value); String get_variable() const { return variable; } virtual Variant get_value(Object *p_agent, const Ref &p_blackboard, const Variant &p_default = Variant()); diff --git a/icons/unused/icons_blackboard.svg b/icons/unused/icon_b_b_param.svg similarity index 100% rename from icons/unused/icons_blackboard.svg rename to icons/unused/icon_b_b_param.svg diff --git a/register_types.cpp b/register_types.cpp index e3409de..b206474 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -122,7 +122,6 @@ void register_limboai_types() { ClassDB::register_class(); - // ClassDB::register_class(); ClassDB::register_virtual_class(); ClassDB::register_class(); ClassDB::register_class();