Skip to content

Commit e839199

Browse files
committed
Add support for property groups
1 parent 02802b1 commit e839199

File tree

8 files changed

+39
-11
lines changed

8 files changed

+39
-11
lines changed

godot-headers-temp/godot/gdnative_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ typedef struct {
438438
void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info);
439439
void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value);
440440
void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter);
441+
void (*classdb_register_extension_class_property_group)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix);
442+
void (*classdb_register_extension_class_property_subgroup)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix);
441443
void (*classdb_register_extension_class_signal)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count);
442444
void (*classdb_unregister_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */
443445
} GDNativeInterface;

include/godot_cpp/core/class_db.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class ClassDB {
108108
static MethodBind *bind_method(N p_method_name, M p_method);
109109
template <class M>
110110
static MethodBind *bind_vararg_method(uint32_t p_flags, const char *p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const std::vector<Variant> &p_default_args = std::vector<Variant>{}, bool p_return_nil_is_variant = true);
111+
static void add_property_group(const char *p_class, const char *p_name, const char *p_prefix);
112+
static void add_property_subgroup(const char *p_class, const char *p_name, const char *p_prefix);
111113
static void add_property(const char *p_class, const PropertyInfo &p_pinfo, const char *p_setter, const char *p_getter, int p_index = -1);
112114
static void add_signal(const char *p_class, const MethodInfo &p_signal);
113115
static void bind_integer_constant(const char *p_class, const char *p_enum, const char *p_name, GDNativeInt p_constant);

include/godot_cpp/core/object.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include <vector>
4444

4545
#define ADD_SIGNAL(m_signal) ClassDB::add_signal(get_class_static(), m_signal)
46+
#define ADD_GROUP(m_name, m_prefix) ::ClassDB::add_property_group(get_class_static(), m_name, m_prefix)
47+
#define ADD_SUBGROUP(m_name, m_prefix) ::ClassDB::add_property_subgroup(get_class_static(), m_name, m_prefix)
4648
#define ADD_PROPERTY(m_property, m_setter, m_getter) ClassDB::add_property(get_class_static(), m_property, m_setter, m_getter)
4749

4850
namespace godot {

src/core/class_db.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) {
5252
return method;
5353
}
5454

55+
void ClassDB::add_property_group(const char *p_class, const char *p_name, const char *p_prefix) {
56+
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), "Trying to add property to non-existing class.");
57+
58+
ClassInfo &info = classes[p_class];
59+
60+
info.property_list.push_back(PropertyInfo(Variant::NIL, p_name, PROPERTY_HINT_NONE, p_prefix, PROPERTY_USAGE_GROUP));
61+
}
62+
63+
void ClassDB::add_property_subgroup(const char *p_class, const char *p_name, const char *p_prefix) {
64+
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), "Trying to add property to non-existing class.");
65+
66+
ClassInfo &info = classes[p_class];
67+
68+
info.property_list.push_back(PropertyInfo(Variant::NIL, p_name, PROPERTY_HINT_NONE, p_prefix, PROPERTY_USAGE_SUBGROUP));
69+
}
70+
5571
void ClassDB::add_property(const char *p_class, const PropertyInfo &p_pinfo, const char *p_setter, const char *p_getter, int p_index) {
5672
ERR_FAIL_COND_MSG(classes.find(p_class) == classes.end(), "Trying to add property to non-existing class.");
5773

@@ -262,9 +278,15 @@ void ClassDB::initialize(GDNativeInitializationLevel p_level) {
262278
property.usage, // DEFAULT //uint32_t usage;
263279
};
264280

265-
const PropertySetGet &setget = cl.property_setget.find(property.name)->second;
281+
if (info.usage == PROPERTY_USAGE_GROUP) {
282+
internal::interface->classdb_register_extension_class_property_group(internal::library, cl.name, info.name, info.hint_string);
283+
} else if (info.usage == PROPERTY_USAGE_SUBGROUP) {
284+
internal::interface->classdb_register_extension_class_property_subgroup(internal::library, cl.name, info.name, info.hint_string);
285+
} else {
286+
const PropertySetGet &setget = cl.property_setget.find(property.name)->second;
266287

267-
internal::interface->classdb_register_extension_class_property(internal::library, cl.name, &info, setget.setter, setget.getter);
288+
internal::interface->classdb_register_extension_class_property(internal::library, cl.name, &info, setget.setter, setget.getter);
289+
}
268290
}
269291

270292
for (const std::pair<std::string, MethodInfo> pair : cl.signal_map) {

test/demo/example.gdextension

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ entry_symbol = "example_library_init"
44

55
[libraries]
66

7-
Linux.64 = "bin/x11/libgdexample.so"
8-
Windows.64 = "bin/win64/libgdexample.dll"
7+
linux.64 = "bin/x11/libgdexample.so"
8+
windows.64 = "bin/win64/libgdexample.dll"

test/demo/main.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ func _ready():
1313
prints("vararg args", $Example.varargs_func("some", "arguments", "to", "test"))
1414

1515
# Use properties.
16-
prints("custom postion is", $Example.custom_position)
17-
$Example.custom_position = Vector2(50, 50)
18-
prints("custom postion now is", $Example.custom_position)
16+
prints("custom position is", $Example.group_subgroup_custom_position)
17+
$Example.group_subgroup_custom_position = Vector2(50, 50)
18+
prints("custom position now is", $Example.group_subgroup_custom_position)
1919

2020
# Get constants
2121
prints("FIRST", $Example.FIRST)

test/demo/main.tscn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ script = ExtResource( "1_c326s" )
77

88
[node name="Example" type="Example" parent="."]
99
script = null
10-
__meta__ = {
11-
"_edit_use_anchors_": false
12-
}
1310

1411
[node name="Label" type="Label" parent="Example"]
1512
offset_left = 194.0

test/src/example.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ void Example::_bind_methods() {
5353
}
5454

5555
// Properties.
56+
ADD_GROUP("Test group","group_");
57+
ADD_SUBGROUP("Test subgroup","group_subgroup_");
58+
5659
ClassDB::bind_method(D_METHOD("get_custom_position"), &Example::get_custom_position);
5760
ClassDB::bind_method(D_METHOD("set_custom_position", "position"), &Example::set_custom_position);
58-
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "custom_position"), "set_custom_position", "get_custom_position");
61+
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "group_subgroup_custom_position"), "set_custom_position", "get_custom_position");
5962

6063
// Signals.
6164
ADD_SIGNAL(MethodInfo("custom_signal", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::INT, "value")));

0 commit comments

Comments
 (0)