void CCDisplayManager::addDisplay(CCNode *display, int index) { CCDecorativeDisplay *decoDisplay = NULL; if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) { decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); } else { decoDisplay = CCDecorativeDisplay::create(); m_pDecoDisplayList->addObject(decoDisplay); } CCDisplayData *displayData = NULL; if (CCSkin *skin = dynamic_cast<CCSkin *>(display)) { skin->setBone(m_pBone); displayData = CCSpriteDisplayData::create(); CCDisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); if (CCSpriteDisplayData *spriteDisplayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); } else { CCBaseData baseData; skin->setSkinData(baseData); } } else if (dynamic_cast<CCParticleSystemQuad *>(display)) { displayData = CCParticleDisplayData::create(); } else if(CCArmature *armature = dynamic_cast<CCArmature *>(display)) { displayData = CCArmatureDisplayData::create(); armature->setParentBone(m_pBone); } else { displayData = CCDisplayData::create(); } decoDisplay->setDisplay(display); decoDisplay->setDisplayData(displayData); //! if changed display index is current display index, then change current display to the new display if(index == m_iDisplayIndex) { m_iDisplayIndex = -1; changeDisplayByIndex(index, false); } }
void CCDisplayManager::addDisplay(CCNode *display, int index) { CCDecorativeDisplay *decoDisplay = NULL; if(index >= 0 && (unsigned int)index < m_pDecoDisplayList->count()) { decoDisplay = (CCDecorativeDisplay *)m_pDecoDisplayList->objectAtIndex(index); } else { decoDisplay = CCDecorativeDisplay::create(); m_pDecoDisplayList->addObject(decoDisplay); } CCDisplayData *displayData = NULL; if (CCSkin *skin = dynamic_cast<CCSkin *>(display)) { skin->setBone(m_pBone); displayData = CCSpriteDisplayData::create(); displayData->displayName = skin->getDisplayName(); CCDisplayFactory::initSpriteDisplay(m_pBone, decoDisplay, skin->getDisplayName().c_str(), skin); if (CCSpriteDisplayData *spriteDisplayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData()) { skin->setSkinData(spriteDisplayData->skinData); ((CCSpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData; } else { bool find = false; for (int i = m_pDecoDisplayList->count()-2; i>=0; i--) { CCDecorativeDisplay *dd = static_cast<CCDecorativeDisplay*>(m_pDecoDisplayList->objectAtIndex(i)); CCSpriteDisplayData *sdd = static_cast<CCSpriteDisplayData *>(dd->getDisplayData()); if (sdd) { find = true; skin->setSkinData(sdd->skinData); (static_cast<CCSpriteDisplayData *>(displayData))->skinData = sdd->skinData; break; } } if (!find) { CCBaseData baseData; skin->setSkinData(baseData); } } } else if (dynamic_cast<CCParticleSystemQuad *>(display)) { displayData = CCParticleDisplayData::create(); display->removeFromParent(); CCArmature *armature = m_pBone->getArmature(); if (armature) { display->setParent(armature); } } else if(CCArmature *armature = dynamic_cast<CCArmature *>(display)) { displayData = CCArmatureDisplayData::create(); displayData->displayName = armature->getName(); armature->setParentBone(m_pBone); } else { displayData = CCDisplayData::create(); } decoDisplay->setDisplay(display); decoDisplay->setDisplayData(displayData); //! if changed display index is current display index, then change current display to the new display if(index == m_iDisplayIndex) { m_iDisplayIndex = -1; changeDisplayWithIndex(index, false); } }