MCPcopy Create free account
hub / github.com/defold/defold / CompGuiTypeCreate

Function CompGuiTypeCreate

engine/gamesys/src/gamesys/components/comp_gui.cpp:3440–3512  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3438 }
3439
3440 static dmGameObject::Result CompGuiTypeCreate(const dmGameObject::ComponentTypeCreateCtx* ctx, dmGameObject::ComponentType* type)
3441 {
3442 g_CompGuiPropertySetters.SetCapacity(4, 8);
3443 g_CompGuiPropertyGetters.SetCapacity(4, 8);
3444
3445 CompGuiContext* gui_context = new CompGuiContext;
3446 gui_context->m_Factory = ctx->m_Factory;
3447 gui_context->m_RenderContext = *(dmRender::HRenderContext*)ctx->m_Contexts.Get(dmHashString64("render"));
3448 gui_context->m_GuiContext = *(dmGui::HContext*)ctx->m_Contexts.Get(dmHashString64("guic"));
3449 gui_context->m_ScriptContext = *(dmScript::HContext*)ctx->m_Contexts.Get(dmHashString64("gui_scriptc"));
3450
3451 gui_context->m_MaxGuiComponents = dmConfigFile::GetInt(ctx->m_Config, "gui.max_count", 64);
3452 gui_context->m_MaxParticleFXCount = dmConfigFile::GetInt(ctx->m_Config, "gui.max_particlefx_count", 64);
3453 gui_context->m_MaxParticleCount = dmConfigFile::GetInt(ctx->m_Config, "gui.max_particle_count", 1024);
3454 gui_context->m_MaxAnimationCount = dmConfigFile::GetInt(ctx->m_Config, "gui.max_animation_count", 1024);
3455 gui_context->m_MaxParticleBufferCount = dmConfigFile::GetInt(ctx->m_Config, "gui.max_particle_buffer_count", 1024);
3456
3457 // TODO: it seems like this is a hidden game.project property which should be gui.world_count like it is in physics
3458 int32_t max_world_count = dmConfigFile::GetInt(ctx->m_Config, "gui.max_instance_count", 128);
3459 if (max_world_count > 128)
3460 {
3461 dmLogError("`gui.max_instance_count` has a maximum value of 128, but it is set to %d. Decrease the value in `game.project`", max_world_count);
3462 return dmGameObject::RESULT_UNKNOWN_ERROR;
3463 }
3464 gui_context->m_Worlds.SetCapacity(max_world_count);
3465
3466 dmGui::InitializeScript(gui_context->m_ScriptContext);
3467
3468 ComponentTypeSetPrio(type, 300);
3469
3470 ComponentTypeSetContext(type, gui_context);
3471 ComponentTypeSetHasUserData(type, true);
3472 ComponentTypeSetReadsTransforms(type, false);
3473
3474 ComponentTypeSetNewWorldFn(type, CompGuiNewWorld);
3475 ComponentTypeSetDeleteWorldFn(type, CompGuiDeleteWorld);
3476 ComponentTypeSetCreateFn(type, CompGuiCreate);
3477 ComponentTypeSetDestroyFn(type, CompGuiDestroy);
3478 ComponentTypeSetInitFn(type, CompGuiInit);
3479 ComponentTypeSetFinalFn(type, CompGuiFinal);
3480 ComponentTypeSetAddToUpdateFn(type, CompGuiAddToUpdate);
3481 ComponentTypeSetUpdateFn(type, CompGuiUpdate);
3482 ComponentTypeSetRenderFn(type, CompGuiRender);
3483 ComponentTypeSetOnMessageFn(type, CompGuiOnMessage);
3484 ComponentTypeSetOnInputFn(type, CompGuiOnInput);
3485 ComponentTypeSetOnReloadFn(type, CompGuiOnReload);
3486 ComponentTypeSetGetPropertyFn(type, CompGuiGetProperty);
3487 ComponentTypeSetSetPropertyFn(type, CompGuiSetProperty);
3488
3489 ComponentTypeSetChildIteratorFn(type, CompGuiIterChildren);
3490 ComponentTypeSetPropertyIteratorFn(type, CompGuiIterProperties);
3491 ComponentTypeSetGetFn(type, CompGuiGetComponent);
3492
3493
3494 // Now register the node types with the gui
3495 CompGuiNodeTypeCtx gui_node_ctx;
3496 gui_node_ctx.m_Config = ctx->m_Config;
3497 gui_node_ctx.m_Render = gui_context->m_RenderContext;

Callers

nothing calls this directly

Tested by

no test coverage detected