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() {
if (saved_value.get_type() != get_type()) {
Callable::CallError err;
Variant::construct(get_type(), saved_value, nullptr, 0, err);
}
return saved_value;
}
@ -50,7 +46,21 @@ void BBParam::set_variable(const String &p_value) {
String BBParam::to_string() {
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 {
return LimboUtility::get_singleton()->decorate_var(variable);
}
@ -95,5 +105,6 @@ void BBParam::_bind_methods() {
BBParam::BBParam() {
value_source = SAVED_VALUE;
variable = "";
saved_value = Variant();
_assign_default_value();
}

View File

@ -43,6 +43,11 @@ protected:
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;
public:

View File

@ -14,9 +14,18 @@
#include "core/variant/variant.h"
void BBVariant::set_type(Variant::Type p_type) {
type = p_type;
notify_property_list_changed();
emit_changed();
if (type != p_type) {
type = p_type;
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() {
@ -33,5 +42,4 @@ void BBVariant::_bind_methods() {
}
BBVariant::BBVariant() {
type = Variant::NIL;
}

View File

@ -20,12 +20,12 @@ class BBVariant : public BBParam {
GDCLASS(BBVariant, BBParam);
private:
Variant::Type type;
Variant::Type type = Variant::NIL;
protected:
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);
public: