示例#1
0
    UIControlBase* NiStream::parseControls(cocos2d::CCNode* parent, mutableDic* dic) 
    {
        if (dic == NULL) 
            return NULL;
        _ParentNode = parent;        
        m_pCurrentLinkedDic = dic;
        
        cocos2d::CCString* ccType = static_cast<cocos2d::CCString*>(dic->objectForKey("type"));
        std::string type = ccType->toStdString();
        
        delete m_pControl;
        m_pControl = NULL;
        
        // create current type creator ,and create control 
        createFunction pfnCreate = NULL;
        std::map<string, createFunction>::iterator itor = ms_kLoaders.find(type);
        if (itor != ms_kLoaders.end())
        {
            pfnCreate = (*itor).second;
        }
        
        if (pfnCreate == NULL)
        {
            CCLog("Error!, NiStream::parseControls() ! type £½ %s", type.c_str());
            return NULL;
        }

        m_pControl = (UIControlBase*)(*pfnCreate)();
        m_pControl->LoadBinary(*this);

        if (m_pControl != NULL && _controlsDic.find(m_pControl->getTag()) == _controlsDic.end()) {
            _controlsDic[m_pControl->getTag()] = m_pControl;
//            CCLog("Add control id:%i into controls dic.", m_pControl->getTag());
        }
        
        mutableArray* children = static_cast<mutableArray*>(dic->objectForKey("children"));
        if (children == NULL)
        {
            m_pControl->BindNode(_ParentNode);
			//m_pControl->setRoot(m_pControl);
            return m_pControl;
        }

        //create control from control data 
        internalCreateControl(&m_pControl, children);   
        
        m_pControl->BindNode(_ParentNode);
		//m_pControl->setRoot(m_pControl);
        
        return m_pControl;
    }
示例#2
0
Control* GearControl::createControl(ControlPanel* parent)
{
  _control = internalCreateControl(parent);
  return _control;
}
示例#3
0
    void NiStream::internalCreateControl(UIControlBase** pControl, CCObject* pData)
    {
        mutableArray* children = static_cast<mutableArray*>(pData);
        if (children == NULL)
            return;
        
        UIControlBase* pParent = *pControl;
        
        for (size_t i = 0; i < children->count(); i++) 
        {
            mutableDic* dic = (mutableDic*)(children->objectAtIndex(i));           
            
            m_pCurrentLinkedDic = dic;
            
            cocos2d::CCString* ccType = static_cast<cocos2d::CCString*>(dic->objectForKey("type"));
            std::string type = ccType->toStdString();

            // create current type creator ,and create control 
            createFunction pfnCreate = NULL;
            std::map<string, createFunction>::iterator itor = ms_kLoaders.find(type);
            if (itor != ms_kLoaders.end())
            {
                pfnCreate = (*itor).second;
            }
            
            if (pfnCreate == NULL)
            {
                CCLog("Error!, NiStream::parseControls() ! child type = %s", type.c_str());
                continue ;
            }
            
            UIControlBase* pChildControl = (UIControlBase*)(*pfnCreate)();

			// set parent first
            pChildControl->setParent(pParent);    
			
            pChildControl->LoadBinary(*this);
            
            // get the transform
            //CCPoint ptWorld = pChildControl->GetWorldPosition();
            
            // need to transform world position to relative position 
            // call subclass's function and transform world position to local
            //pChildControl->SetWorldPosition(ptWorld);
            
            if (pChildControl != NULL && _controlsDic.find(pChildControl->getTag()) == _controlsDic.end())
            {
                _controlsDic[pChildControl->getTag()] = pChildControl;
//                CCLog("Add control id:%i into controls dic.", pChildControl->getTag());
            }
            
            // parse chilren node
            mutableArray* children = static_cast<mutableArray*>(dic->objectForKey("children"));
           
            //create control from control data
			if(children != NULL)
			{
				internalCreateControl(&pChildControl, children);
			}
        }
        
        return;
    }