Fix BBVariant inspector oddities

This commit is contained in:
Serhii Snitsaruk 2023-08-07 14:29:58 +02:00
parent 258437c340
commit b662c10513
4 changed files with 36 additions and 12 deletions

View File

@ -29,10 +29,6 @@ void BBParam::set_value_source(ValueSource p_value) {
} }
Variant BBParam::get_saved_value() { Variant BBParam::get_saved_value() {
if (saved_value.get_type() != get_type()) {
Callable::CallError err;
Variant::construct(get_type(), saved_value, nullptr, 0, err);
}
return saved_value; return saved_value;
} }
@ -50,7 +46,21 @@ void BBParam::set_variable(const String &p_value) {
String BBParam::to_string() { String BBParam::to_string() {
if (value_source == SAVED_VALUE) { if (value_source == SAVED_VALUE) {
return String(saved_value); String s = saved_value.stringify();
switch (get_type()) {
case Variant::STRING: {
s = s.c_escape().quote();
} break;
case Variant::STRING_NAME: {
s = "&" + s.c_escape().quote();
} break;
case Variant::NODE_PATH: {
s = "^" + s.c_escape().quote();
} break;
default: {
} break;
}
return s;
} else { } else {
return LimboUtility::get_singleton()->decorate_var(variable); return LimboUtility::get_singleton()->decorate_var(variable);
} }
@ -95,5 +105,6 @@ void BBParam::_bind_methods() {
BBParam::BBParam() { BBParam::BBParam() {
value_source = SAVED_VALUE; value_source = SAVED_VALUE;
variable = ""; variable = "";
saved_value = Variant();
_assign_default_value();
} }

View File

@ -43,6 +43,11 @@ protected:
virtual Variant::Type get_type() const { return Variant::NIL; } virtual Variant::Type get_type() const { return Variant::NIL; }
_FORCE_INLINE_ void _assign_default_value() {
Callable::CallError err;
Variant::construct(get_type(), saved_value, nullptr, 0, err);
}
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
public: public:

View File

@ -14,9 +14,18 @@
#include "core/variant/variant.h" #include "core/variant/variant.h"
void BBVariant::set_type(Variant::Type p_type) { void BBVariant::set_type(Variant::Type p_type) {
type = p_type; if (type != p_type) {
notify_property_list_changed(); type = p_type;
emit_changed(); if (get_saved_value().get_type() != p_type) {
_assign_default_value();
}
emit_changed();
notify_property_list_changed();
}
}
Variant::Type BBVariant::get_type() const {
return type;
} }
void BBVariant::_bind_methods() { void BBVariant::_bind_methods() {
@ -33,5 +42,4 @@ void BBVariant::_bind_methods() {
} }
BBVariant::BBVariant() { BBVariant::BBVariant() {
type = Variant::NIL;
} }

View File

@ -20,12 +20,12 @@ class BBVariant : public BBParam {
GDCLASS(BBVariant, BBParam); GDCLASS(BBVariant, BBParam);
private: private:
Variant::Type type; Variant::Type type = Variant::NIL;
protected: protected:
static void _bind_methods(); static void _bind_methods();
virtual Variant::Type get_type() const override { return type; } virtual Variant::Type get_type() const override;
void set_type(Variant::Type p_type); void set_type(Variant::Type p_type);
public: public: