コード例 #1
0
ファイル: UIHUD3D.cpp プロジェクト: TerraDevs/Terra
void CUIHUD3D::Reload()
{
    if (gEnv->IsEditor())
    {
        RemoveHudEntities();
    }
}
コード例 #2
0
ファイル: UIHUD3D.cpp プロジェクト: aronarts/FireNET
void CUIHUD3D::OnSystemEvent( ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam )
{
	switch ( event )
	{
	case ESYSTEM_EVENT_LEVEL_GAMEPLAY_START:
		SpawnHudEntities();
		break;
	case ESYSTEM_EVENT_LEVEL_LOAD_RESUME_GAME:
	case ESYSTEM_EVENT_LEVEL_UNLOAD:
		RemoveHudEntities();
		break;
	}
}
コード例 #3
0
ファイル: UIHUD3D.cpp プロジェクト: TerraDevs/Terra
void CUIHUD3D::SpawnHudEntities()
{
    RemoveHudEntities();

    if (gEnv->IsEditor() && gEnv->IsEditing())
        return;

    const char* hudprefab = NULL;
    IGameRules* pGameRules = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->GetCurrentGameRules();
    if (pGameRules)
    {
        IScriptTable* pTable = pGameRules->GetEntity()->GetScriptTable();
        if (pTable)
        {
            if (!pTable->GetValue("hud_prefab", hudprefab))
                hudprefab = NULL;
        }
    }
    hudprefab = hudprefab ? hudprefab : HUD3D_PREFAB_LIB;

    XmlNodeRef node = gEnv->pSystem->LoadXmlFromFile(hudprefab);
    if (node)
    {
        // get the prefab with the name defined in HUD3D_PREFAB_NAME
        XmlNodeRef prefab = NULL;
        for (int i = 0; i < node->getChildCount(); ++i)
        {
            const char* name = node->getChild(i)->getAttr("Name");
            if (name && strcmp(name, HUD3D_PREFAB_NAME) == 0)
            {
                prefab = node->getChild(i);
                prefab = prefab ? prefab->findChild("Objects") : XmlNodeRef();
                break;
            }
        }

        if (prefab)
        {
            // get the PIVOT entity and collect childs
            XmlNodeRef pivotNode = NULL;
            std::vector<XmlNodeRef> childs;
            const int count = prefab->getChildCount();
            childs.reserve(count-1);

            for (int i = 0; i < count; ++i)
            {
                const char* name = prefab->getChild(i)->getAttr("Name");
                if (strcmp("PIVOT", name) == 0)
                {
                    assert(pivotNode == NULL);
                    pivotNode = prefab->getChild(i);
                }
                else
                {
                    childs.push_back(prefab->getChild(i));
                }
            }

            if (pivotNode)
            {
                // spawn pivot entity
                IEntityClass* pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( pivotNode->getAttr("EntityClass") );
                if (pEntClass)
                {
                    SEntitySpawnParams params;
                    params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
                    params.pClass = pEntClass;
                    m_pHUDRootEntity = gEnv->pEntitySystem->SpawnEntity(params);
                }

                if (!m_pHUDRootEntity) return;

                m_HUDRootEntityId = m_pHUDRootEntity->GetId();

                // spawn the childs and link to the pivot enity
                for (std::vector<XmlNodeRef>::iterator it = childs.begin(); it != childs.end(); ++it)
                {
                    XmlNodeRef child = *it;
                    pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( child->getAttr("EntityClass") );
                    if (pEntClass)
                    {
                        const char* material = child->getAttr("Material");
                        Vec3 pos;
                        Vec3 scale;
                        Quat rot;
                        child->getAttr("Pos", pos);
                        child->getAttr("Rotate", rot);
                        child->getAttr("Scale", scale);

                        SEntitySpawnParams params;
                        params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
                        params.pClass = pEntClass;
                        params.vPosition = pos;
                        params.qRotation = rot;
                        params.vScale = scale;
                        IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(params);
                        if (pEntity)
                        {
                            IScriptTable* pScriptTable = pEntity->GetScriptTable();
                            if (pScriptTable)
                            {
                                SmartScriptTable probs;
                                pScriptTable->GetValue("Properties", probs);

                                XmlNodeRef properties = child->findChild("Properties");
                                if (probs && properties)
                                {
                                    for (int k = 0; k < properties->getNumAttributes(); ++k)
                                    {
                                        const char* sKey;
                                        const char* sVal;
                                        properties->getAttributeByIndex(k, &sKey, &sVal);
                                        probs->SetValue(sKey, sVal);
                                    }
                                }
                                Script::CallMethod(pScriptTable,"OnPropertyChange");
                            }

                            if (material)
                            {
                                IMaterial* pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(material);
                                if (pMat)
                                    pEntity->SetMaterial(pMat);
                            }
                            m_pHUDRootEntity->AttachChild(pEntity);
                            m_HUDEnties.push_back( pEntity->GetId() );
                        }
                    }
                }
            }
        }
    }

    OnVisCVarChange( NULL );
}