Add support for _notification, _set, _get, _get_property_list, _property_can_revert, _property_get_revert, and _to_string methods.
This commit is contained in:
@@ -7,10 +7,20 @@ func _ready():
|
||||
|
||||
prints("")
|
||||
|
||||
# To string.
|
||||
prints("To string")
|
||||
prints(" Example --> ", $Example.to_string())
|
||||
prints(" ExampleMin --> ", $Example/ExampleMin.to_string())
|
||||
|
||||
# Call static methods.
|
||||
prints("Static method calls")
|
||||
prints(" static (109)", Example.test_static(9, 100));
|
||||
Example.test_static2();
|
||||
|
||||
# Property list.
|
||||
prints("Property list")
|
||||
$Example.property_from_list = Vector3(100, 200, 300)
|
||||
prints(" property value ", $Example.property_from_list)
|
||||
|
||||
# Call methods.
|
||||
prints("Instance method calls")
|
||||
|
||||
@@ -7,6 +7,8 @@ script = ExtResource( "1_c326s" )
|
||||
|
||||
[node name="Example" type="Example" parent="."]
|
||||
|
||||
[node name="ExampleMin" type="ExampleMin" parent="Example"]
|
||||
|
||||
[node name="Label" type="Label" parent="Example"]
|
||||
offset_left = 194.0
|
||||
offset_top = -2.0
|
||||
|
||||
@@ -58,6 +58,51 @@ int Example::def_args(int p_a, int p_b) {
|
||||
return p_a + p_b;
|
||||
}
|
||||
|
||||
void Example::_notification(int p_what) {
|
||||
UtilityFunctions::print("Notification: ", String::num(p_what));
|
||||
}
|
||||
|
||||
bool Example::_set(const StringName &p_name, const Variant &p_value) {
|
||||
if (p_name == StringName("property_from_list")) {
|
||||
property_from_list = p_value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Example::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
if (p_name == StringName("property_from_list")) {
|
||||
r_ret = property_from_list;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String Example::_to_string() const {
|
||||
return "[ GDExtension::Example <--> Instance ID:" + itos(get_instance_id()) + " ]";
|
||||
}
|
||||
|
||||
void Example::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR3, "property_from_list"));
|
||||
}
|
||||
|
||||
bool Example::_property_can_revert(const StringName &p_name) const {
|
||||
if (p_name == StringName("property_from_list") && property_from_list != Vector3(42, 42, 42)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
bool Example::_property_get_revert(const StringName &p_name, Variant &r_property) const {
|
||||
if (p_name == StringName("property_from_list")) {
|
||||
r_property = Vector3(42, 42, 42);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void Example::_bind_methods() {
|
||||
// Methods.
|
||||
ClassDB::bind_method(D_METHOD("simple_func"), &Example::simple_func);
|
||||
|
||||
@@ -56,14 +56,31 @@ public:
|
||||
~ExampleRef();
|
||||
};
|
||||
|
||||
class ExampleMin : public Control {
|
||||
GDCLASS(ExampleMin, Control);
|
||||
|
||||
protected:
|
||||
static void _bind_methods(){};
|
||||
};
|
||||
|
||||
class Example : public Control {
|
||||
GDCLASS(Example, Control);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void _notification(int p_what);
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
bool _property_can_revert(const StringName &p_name) const;
|
||||
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
|
||||
|
||||
String _to_string() const;
|
||||
|
||||
private:
|
||||
Vector2 custom_position;
|
||||
Vector3 property_from_list;
|
||||
|
||||
public:
|
||||
// Constants.
|
||||
|
||||
@@ -46,6 +46,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
|
||||
}
|
||||
|
||||
ClassDB::register_class<ExampleRef>();
|
||||
ClassDB::register_class<ExampleMin>();
|
||||
ClassDB::register_class<Example>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user