Skip to content

Commit 119c99a

Browse files
committed
Merge pull request #100193 from raulsntos/gdextension/set_class_icon
GDExtension: Add method to set the class icon
2 parents a11364d + 69f1cc1 commit 119c99a

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

core/extension/gdextension.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ void GDExtension::_register_extension_class(GDExtensionClassLibraryPtr p_library
245245
p_extension_funcs->is_abstract, // GDExtensionBool is_abstract;
246246
true, // GDExtensionBool is_exposed;
247247
false, // GDExtensionBool is_runtime;
248+
nullptr, // GDExtensionConstStringPtr icon_path;
248249
p_extension_funcs->set_func, // GDExtensionClassSet set_func;
249250
p_extension_funcs->get_func, // GDExtensionClassGet get_func;
250251
p_extension_funcs->get_property_list_func, // GDExtensionClassGetPropertyList get_property_list_func;
@@ -280,6 +281,7 @@ void GDExtension::_register_extension_class2(GDExtensionClassLibraryPtr p_librar
280281
p_extension_funcs->is_abstract, // GDExtensionBool is_abstract;
281282
p_extension_funcs->is_exposed, // GDExtensionBool is_exposed;
282283
false, // GDExtensionBool is_runtime;
284+
nullptr, // GDExtensionConstStringPtr icon_path;
283285
p_extension_funcs->set_func, // GDExtensionClassSet set_func;
284286
p_extension_funcs->get_func, // GDExtensionClassGet get_func;
285287
p_extension_funcs->get_property_list_func, // GDExtensionClassGetPropertyList get_property_list_func;
@@ -315,6 +317,7 @@ void GDExtension::_register_extension_class3(GDExtensionClassLibraryPtr p_librar
315317
p_extension_funcs->is_abstract, // GDExtensionBool is_abstract;
316318
p_extension_funcs->is_exposed, // GDExtensionBool is_exposed;
317319
p_extension_funcs->is_runtime, // GDExtensionBool is_runtime;
320+
nullptr, // GDExtensionConstStringPtr icon_path;
318321
p_extension_funcs->set_func, // GDExtensionClassSet set_func;
319322
p_extension_funcs->get_func, // GDExtensionClassGet get_func;
320323
p_extension_funcs->get_property_list_func, // GDExtensionClassGetPropertyList get_property_list_func;
@@ -456,6 +459,13 @@ void GDExtension::_register_extension_class_internal(GDExtensionClassLibraryPtr
456459
#endif
457460

458461
ClassDB::register_extension_class(&extension->gdextension);
462+
463+
if (p_extension_funcs->icon_path != nullptr) {
464+
const String icon_path = *reinterpret_cast<const String *>(p_extension_funcs->icon_path);
465+
if (!icon_path.is_empty()) {
466+
self->class_icon_paths[class_name] = icon_path;
467+
}
468+
}
459469
}
460470

461471
void GDExtension::_register_extension_class_method(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassMethodInfo *p_method_info) {

core/extension/gdextension_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ typedef struct {
368368
GDExtensionBool is_abstract;
369369
GDExtensionBool is_exposed;
370370
GDExtensionBool is_runtime;
371+
GDExtensionConstStringPtr icon_path;
371372
GDExtensionClassSet set_func;
372373
GDExtensionClassGet get_func;
373374
GDExtensionClassGetPropertyList get_property_list_func;

core/extension/gdextension_manager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ void GDExtensionManager::initialize_extensions(GDExtension::InitializationLevel
210210
ERR_FAIL_COND(int32_t(p_level) - 1 != level);
211211
for (KeyValue<String, Ref<GDExtension>> &E : gdextension_map) {
212212
E.value->initialize_library(p_level);
213+
214+
if (p_level == GDExtension::INITIALIZATION_LEVEL_EDITOR) {
215+
for (const KeyValue<String, String> &kv : E.value->class_icon_paths) {
216+
gdextension_class_icon_paths[kv.key] = kv.value;
217+
}
218+
}
213219
}
214220
level = p_level;
215221
}

0 commit comments

Comments
 (0)