mirror of
https://github.com/godotengine/godot-cpp.git
synced 2026-01-03 18:09:13 +03:00
Add support for _notification, _set, _get, _get_property_list, _property_can_revert, _property_get_revert, and _to_string methods.
This commit is contained in:
@@ -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