mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into android_gles20
This commit is contained in:
commit
7ccb38556e
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||||
#include "cocoa/CCNS.h"
|
#include "cocoa/CCNS.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCScene.h"
|
#include "CCScene.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCScheduler.h"
|
#include "CCScheduler.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCTouchDispatcher.h"
|
#include "CCTouchDispatcher.h"
|
||||||
|
@ -96,7 +96,8 @@ bool CCDirector::init(void)
|
||||||
m_pNotificationNode = NULL;
|
m_pNotificationNode = NULL;
|
||||||
|
|
||||||
m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS;
|
m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS;
|
||||||
m_pobScenesStack = new CCMutableArray<CCScene*>();
|
m_pobScenesStack = CCArray::array();
|
||||||
|
m_pobScenesStack->retain();
|
||||||
|
|
||||||
// Set default projection (3D)
|
// Set default projection (3D)
|
||||||
m_eProjection = kCCDirectorProjectionDefault;
|
m_eProjection = kCCDirectorProjectionDefault;
|
||||||
|
@ -336,8 +337,9 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
|
||||||
{
|
{
|
||||||
// reset the viewport if 3d proj & retina display
|
// reset the viewport if 3d proj & retina display
|
||||||
if( CC_CONTENT_SCALE_FACTOR() != 1 )
|
if( CC_CONTENT_SCALE_FACTOR() != 1 )
|
||||||
|
{
|
||||||
glViewport(-size.width/2, -size.height/2, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
|
glViewport(-size.width/2, -size.height/2, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
|
||||||
|
}
|
||||||
float zeye = this->getZEye();
|
float zeye = this->getZEye();
|
||||||
|
|
||||||
kmMat4 matrixPerspective, matrixLookup;
|
kmMat4 matrixPerspective, matrixLookup;
|
||||||
|
@ -563,7 +565,7 @@ void CCDirector::popScene(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_bSendCleanupToScene = true;
|
m_bSendCleanupToScene = true;
|
||||||
m_pNextScene = m_pobScenesStack->getObjectAtIndex(c - 1);
|
m_pNextScene = (CCScene*)m_pobScenesStack->objectAtIndex(c - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,7 +326,7 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, CCObject *pTarget
|
||||||
pElement->currentTimerSalvaged = true;
|
pElement->currentTimerSalvaged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccArrayRemoveObjectAtIndex(pElement->timers, i );
|
ccArrayRemoveObjectAtIndex(pElement->timers, i, true);
|
||||||
|
|
||||||
// update timerIndex in case we are in tick:, looping over the actions
|
// update timerIndex in case we are in tick:, looping over the actions
|
||||||
if (pElement->timerIndex >= i)
|
if (pElement->timerIndex >= i)
|
||||||
|
|
|
@ -2055,10 +2055,13 @@ bool CCAnimate::initWithAnimation(CCAnimation *pAnimation)
|
||||||
float accumUnitsOfTime = 0;
|
float accumUnitsOfTime = 0;
|
||||||
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
|
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
|
||||||
|
|
||||||
CCMutableArray<CCAnimationFrame*>* pFrames = pAnimation->getFrames();
|
CCArray* pFrames = pAnimation->getFrames();
|
||||||
for (CCMutableArray<CCAnimationFrame*>::CCMutableArrayIterator iterFrame = pFrames->begin(); iterFrame != pFrames->end(); ++iterFrame)
|
CCARRAY_VERIFY_TYPE(pFrames, CCAnimationFrame*);
|
||||||
|
|
||||||
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(pFrames, pObj)
|
||||||
{
|
{
|
||||||
CCAnimationFrame *frame = *iterFrame;
|
CCAnimationFrame* frame = (CCAnimationFrame*)pObj;
|
||||||
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
||||||
accumUnitsOfTime += frame->getDelayUnits();
|
accumUnitsOfTime += frame->getDelayUnits();
|
||||||
m_pSplitTimes->push_back(value);
|
m_pSplitTimes->push_back(value);
|
||||||
|
@ -2151,7 +2154,7 @@ void CCAnimate::update(ccTime t)
|
||||||
t = fmodf(t, 1.0f);
|
t = fmodf(t, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCAnimationFrame*>* frames = m_pAnimation->getFrames();
|
CCArray* frames = m_pAnimation->getFrames();
|
||||||
unsigned int numberOfFrames = frames->count();
|
unsigned int numberOfFrames = frames->count();
|
||||||
CCSpriteFrame *frameToDisplay = NULL;
|
CCSpriteFrame *frameToDisplay = NULL;
|
||||||
|
|
||||||
|
@ -2159,11 +2162,11 @@ void CCAnimate::update(ccTime t)
|
||||||
float splitTime = m_pSplitTimes->at(i);
|
float splitTime = m_pSplitTimes->at(i);
|
||||||
|
|
||||||
if( splitTime <= t ) {
|
if( splitTime <= t ) {
|
||||||
CCAnimationFrame *frame = frames->getObjectAtIndex(i);
|
CCAnimationFrame* frame = (CCAnimationFrame*)frames->objectAtIndex(i);
|
||||||
frameToDisplay = frame->getSpriteFrame();
|
frameToDisplay = frame->getSpriteFrame();
|
||||||
((CCSprite*)m_pTarget)->setDisplayFrame(frameToDisplay);
|
((CCSprite*)m_pTarget)->setDisplayFrame(frameToDisplay);
|
||||||
|
|
||||||
CCObjectDictionary* dict = frame->getUserInfo();
|
CCDictionary* dict = frame->getUserInfo();
|
||||||
if( dict )
|
if( dict )
|
||||||
{
|
{
|
||||||
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
||||||
|
@ -2177,16 +2180,17 @@ void CCAnimate::update(ccTime t)
|
||||||
|
|
||||||
CCActionInterval* CCAnimate::reverse(void)
|
CCActionInterval* CCAnimate::reverse(void)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCAnimationFrame*>* pOldArray = m_pAnimation->getFrames();
|
CCArray* pOldArray = m_pAnimation->getFrames();
|
||||||
CCMutableArray<CCAnimationFrame*>* pNewArray = new CCMutableArray<CCAnimationFrame*>(pOldArray->count());
|
CCArray* pNewArray = CCArray::arrayWithCapacity(pOldArray->count());
|
||||||
|
|
||||||
|
CCARRAY_VERIFY_TYPE(pOldArray, CCAnimationFrame*);
|
||||||
|
|
||||||
if (pOldArray->count() > 0)
|
if (pOldArray->count() > 0)
|
||||||
{
|
{
|
||||||
CCAnimationFrame *pElement;
|
CCObject* pObj = NULL;
|
||||||
CCMutableArray<CCAnimationFrame*>::CCMutableArrayRevIterator iter;
|
CCARRAY_FOREACH_REVERSE(pOldArray, pObj)
|
||||||
for (iter = pOldArray->rbegin(); iter != pOldArray->rend(); iter++)
|
|
||||||
{
|
{
|
||||||
pElement = *iter;
|
CCAnimationFrame* pElement = (CCAnimationFrame*)pObj;
|
||||||
if (! pElement)
|
if (! pElement)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -95,7 +95,7 @@ void CCActionManager::removeActionAtIndex(unsigned int uIndex, tHashElement *pEl
|
||||||
pElement->currentActionSalvaged = true;
|
pElement->currentActionSalvaged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccArrayRemoveObjectAtIndex(pElement->actions, uIndex);
|
ccArrayRemoveObjectAtIndex(pElement->actions, uIndex, true);
|
||||||
|
|
||||||
// update actionIndex in case we are in tick. looping over the actions
|
// update actionIndex in case we are in tick. looping over the actions
|
||||||
if (pElement->actionIndex >= uIndex)
|
if (pElement->actionIndex >= uIndex)
|
||||||
|
|
|
@ -24,14 +24,14 @@ THE SOFTWARE.
|
||||||
#include "CCAutoreleasePool.h"
|
#include "CCAutoreleasePool.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
|
|
||||||
namespace cocos2d
|
NS_CC_BEGIN
|
||||||
{
|
|
||||||
|
|
||||||
CCPoolManager g_PoolManager;
|
CCPoolManager g_PoolManager;
|
||||||
|
|
||||||
CCAutoreleasePool::CCAutoreleasePool(void)
|
CCAutoreleasePool::CCAutoreleasePool(void)
|
||||||
{
|
{
|
||||||
m_pManagedObjectArray = new CCMutableArray<CCObject*>();
|
m_pManagedObjectArray = new CCArray();
|
||||||
|
m_pManagedObjectArray->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAutoreleasePool::~CCAutoreleasePool(void)
|
CCAutoreleasePool::~CCAutoreleasePool(void)
|
||||||
|
@ -61,13 +61,14 @@ void CCAutoreleasePool::clear()
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
int nIndex = m_pManagedObjectArray->count() - 1;
|
int nIndex = m_pManagedObjectArray->count() - 1;
|
||||||
#endif
|
#endif
|
||||||
CCMutableArray<CCObject*>::CCMutableArrayRevIterator it;
|
|
||||||
for(it = m_pManagedObjectArray->rbegin(); it != m_pManagedObjectArray->rend(); ++it)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH_REVERSE(m_pManagedObjectArray, pObj)
|
||||||
{
|
{
|
||||||
if(!*it)
|
if(!pObj)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
(*it)->m_bManaged = false;
|
pObj->m_bManaged = false;
|
||||||
//(*it)->release();
|
//(*it)->release();
|
||||||
//delete (*it);
|
//delete (*it);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -93,7 +94,8 @@ CCPoolManager* CCPoolManager::getInstance()
|
||||||
|
|
||||||
CCPoolManager::CCPoolManager()
|
CCPoolManager::CCPoolManager()
|
||||||
{
|
{
|
||||||
m_pReleasePoolStack = new CCMutableArray<CCAutoreleasePool*>();
|
m_pReleasePoolStack = new CCArray();
|
||||||
|
m_pReleasePoolStack->init();
|
||||||
m_pCurReleasePool = 0;
|
m_pCurReleasePool = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,13 +116,13 @@ void CCPoolManager::finalize()
|
||||||
if(m_pReleasePoolStack->count() > 0)
|
if(m_pReleasePoolStack->count() > 0)
|
||||||
{
|
{
|
||||||
//CCAutoreleasePool* pReleasePool;
|
//CCAutoreleasePool* pReleasePool;
|
||||||
CCMutableArray<CCAutoreleasePool*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for(it = m_pReleasePoolStack->begin(); it != m_pReleasePoolStack->end(); ++it)
|
CCARRAY_FOREACH(m_pReleasePoolStack, pObj)
|
||||||
{
|
{
|
||||||
if(!*it)
|
if(!pObj)
|
||||||
break;
|
break;
|
||||||
|
CCAutoreleasePool* pPool = (CCAutoreleasePool*)pObj;
|
||||||
(*it)->clear();
|
pPool->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,10 +154,10 @@ void CCPoolManager::pop()
|
||||||
|
|
||||||
// if(nCount > 1)
|
// if(nCount > 1)
|
||||||
// {
|
// {
|
||||||
// m_pCurReleasePool = m_pReleasePoolStack->getObjectAtIndex(nCount - 2);
|
// m_pCurReleasePool = m_pReleasePoolStack->objectAtIndex(nCount - 2);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
m_pCurReleasePool = m_pReleasePoolStack->getObjectAtIndex(nCount - 2);
|
m_pCurReleasePool = (CCAutoreleasePool*)m_pReleasePoolStack->objectAtIndex(nCount - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*m_pCurReleasePool = NULL;*/
|
/*m_pCurReleasePool = NULL;*/
|
||||||
|
@ -186,4 +188,4 @@ CCAutoreleasePool* CCPoolManager::getCurReleasePool()
|
||||||
return m_pCurReleasePool;
|
return m_pCurReleasePool;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
|
@ -0,0 +1,253 @@
|
||||||
|
#include "CCDictionary.h"
|
||||||
|
#include "CCString.h"
|
||||||
|
#include "CCInteger.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
CCDictionary::CCDictionary()
|
||||||
|
: m_pElements(NULL)
|
||||||
|
, m_eDictType(kCCDictUnknown)
|
||||||
|
, m_eOldDictType(kCCDictUnknown)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CCDictionary::~CCDictionary()
|
||||||
|
{
|
||||||
|
removeAllObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CCDictionary::count()
|
||||||
|
{
|
||||||
|
return HASH_COUNT(m_pElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCArray* CCDictionary::allKeys()
|
||||||
|
{
|
||||||
|
int iKeyCount = this->count();
|
||||||
|
if (iKeyCount <= 0) return NULL;
|
||||||
|
CCArray* pArray = CCArray::arrayWithCapacity(iKeyCount);
|
||||||
|
|
||||||
|
CCDictElement *pElement, *tmp;
|
||||||
|
if (m_eDictType == kCCDictStr)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
CCString* pOneKey = new CCString(pElement->m_szKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_eDictType == kCCDictInt)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
CCInteger* pOneKey = new CCInteger(pElement->m_iKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCArray* CCDictionary::allKeysForObject(CCObject* object)
|
||||||
|
{
|
||||||
|
int iKeyCount = this->count();
|
||||||
|
if (iKeyCount <= 0) return NULL;
|
||||||
|
CCArray* pArray = CCArray::array();
|
||||||
|
|
||||||
|
CCDictElement *pElement, *tmp;
|
||||||
|
|
||||||
|
if (m_eDictType == kCCDictStr)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
if (object == pElement->m_pObject)
|
||||||
|
{
|
||||||
|
CCString* pOneKey = new CCString(pElement->m_szKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_eDictType == kCCDictInt)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
if (object == pElement->m_pObject)
|
||||||
|
{
|
||||||
|
CCInteger* pOneKey = new CCInteger(pElement->m_iKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCObject* CCDictionary::objectForKey(const char* key)
|
||||||
|
{
|
||||||
|
if (m_eDictType == kCCDictUnknown && m_eDictType == kCCDictUnknown) return NULL;
|
||||||
|
CCAssert(m_eDictType == kCCDictStr, "this dictionary does not use string as key.");
|
||||||
|
|
||||||
|
CCObject* pRetObject = NULL;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_STR(m_pElements,key, pElement);
|
||||||
|
if (pElement != NULL)
|
||||||
|
{
|
||||||
|
pRetObject = pElement->m_pObject;
|
||||||
|
}
|
||||||
|
return pRetObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCObject* CCDictionary::objectForKey(int key)
|
||||||
|
{
|
||||||
|
if (m_eDictType == kCCDictUnknown && m_eDictType == kCCDictUnknown) return NULL;
|
||||||
|
CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as key.");
|
||||||
|
|
||||||
|
CCObject* pRetObject = NULL;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||||
|
if (pElement != NULL)
|
||||||
|
{
|
||||||
|
pRetObject = pElement->m_pObject;
|
||||||
|
}
|
||||||
|
return pRetObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCDictionary::setObject(CCObject* pObject, const char* key)
|
||||||
|
{
|
||||||
|
CCAssert(key != NULL && strlen(key) > 0 && pObject != NULL, "Invalid Argument!");
|
||||||
|
if (m_eOldDictType == kCCDictUnknown)
|
||||||
|
{
|
||||||
|
m_eOldDictType = kCCDictStr;
|
||||||
|
}
|
||||||
|
m_eDictType = kCCDictStr;
|
||||||
|
CCAssert(m_eDictType == m_eOldDictType, "this dictionary does not use string as key.");
|
||||||
|
|
||||||
|
bool bRet = false;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_STR(m_pElements, key, pElement);
|
||||||
|
if (pElement == NULL)
|
||||||
|
{
|
||||||
|
pObject->retain();
|
||||||
|
pElement = new CCDictElement(key, pObject);
|
||||||
|
HASH_ADD_STR(m_pElements, m_szKey, pElement);
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCObject* pTmpObj = pElement->m_pObject;
|
||||||
|
pTmpObj->retain();
|
||||||
|
removeObjectForKey(key);
|
||||||
|
setObject(pObject, key);
|
||||||
|
pTmpObj->release();
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCDictionary::setObject(CCObject* pObject, int key)
|
||||||
|
{
|
||||||
|
CCAssert(pObject != NULL, "Invalid Argument!");
|
||||||
|
if (m_eOldDictType == kCCDictUnknown)
|
||||||
|
{
|
||||||
|
m_eOldDictType = kCCDictInt;
|
||||||
|
}
|
||||||
|
m_eDictType = kCCDictInt;
|
||||||
|
CCAssert(m_eDictType == m_eOldDictType, "this dictionary does not use integer as key.");
|
||||||
|
|
||||||
|
bool bRet = false;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||||
|
if (pElement == NULL)
|
||||||
|
{
|
||||||
|
pObject->retain();
|
||||||
|
pElement = new CCDictElement(key, pObject);
|
||||||
|
HASH_ADD_INT(m_pElements, m_iKey, pElement);
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCObject* pTmpObj = pElement->m_pObject;
|
||||||
|
pTmpObj->retain();
|
||||||
|
removeObjectForKey(key);
|
||||||
|
setObject(pObject, key);
|
||||||
|
pTmpObj->release();
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCDictionary::removeObjectForKey(const char* key)
|
||||||
|
{
|
||||||
|
CCAssert(m_eDictType == kCCDictStr, "this dictionary does not use string as its key");
|
||||||
|
CCAssert(key != NULL && strlen(key) > 0, "Invalid Argument!");
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_STR(m_pElements, key, pElement);
|
||||||
|
if (pElement)
|
||||||
|
{
|
||||||
|
HASH_DEL(m_pElements, pElement);
|
||||||
|
pElement->m_pObject->release();
|
||||||
|
CC_SAFE_DELETE(pElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCDictionary::removeObjectForKey(int key)
|
||||||
|
{
|
||||||
|
CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as its key");
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||||
|
if (pElement != NULL)
|
||||||
|
{
|
||||||
|
HASH_DEL(m_pElements, pElement);
|
||||||
|
pElement->m_pObject->release();
|
||||||
|
CC_SAFE_DELETE(pElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCDictionary::removeAllObjects()
|
||||||
|
{
|
||||||
|
CCDictElement *pElement, *tmp;
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
HASH_DEL(m_pElements, pElement);
|
||||||
|
pElement->m_pObject->release();
|
||||||
|
CC_SAFE_DELETE(pElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CCObject* CCDictionary::copyWithZone(CCZone* pZone)
|
||||||
|
{
|
||||||
|
CCDictionary* pNewDict = new CCDictionary();
|
||||||
|
|
||||||
|
CCDictElement* pElement = NULL;
|
||||||
|
if (m_eDictType == kCCDictInt)
|
||||||
|
{
|
||||||
|
CCDICT_FOREACH(this, pElement)
|
||||||
|
{
|
||||||
|
pNewDict->setObject(pElement->getObject(), pElement->getIntKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_eDictType == kCCDictStr)
|
||||||
|
{
|
||||||
|
CCDICT_FOREACH(this, pElement)
|
||||||
|
{
|
||||||
|
pNewDict->setObject(pElement->getObject(), pElement->getStrKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pNewDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* need deep copy ?*/
|
||||||
|
|
||||||
|
CCDictionary* CCDictionary::dictionaryWithDictionary(CCDictionary* srcDict)
|
||||||
|
{
|
||||||
|
CCDictionary* pNewDict = (CCDictionary*)srcDict->copyWithZone(NULL);
|
||||||
|
pNewDict->autorelease();
|
||||||
|
return pNewDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -23,6 +23,8 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCNotificationCenter.h"
|
#include "CCNotificationCenter.h"
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,9 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include "CCAnimation.h"
|
#include "CCAnimation.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief An interval action is an action that takes place within a certain period of time.
|
@brief An interval action is an action that takes place within a certain period of time.
|
||||||
|
@ -717,8 +718,6 @@ private:
|
||||||
CCFiniteTimeAction* m_pAction;
|
CCFiniteTimeAction* m_pAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //__ACTION_CCINTERVAL_ACTION_H__
|
#endif //__ACTION_CCINTERVAL_ACTION_H__
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
#define __ACTION_CCACTION_MANAGER_H__
|
#define __ACTION_CCACTION_MANAGER_H__
|
||||||
|
|
||||||
#include "CCAction.h"
|
#include "CCAction.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
|
@ -28,8 +28,8 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCPlatformConfig.h"
|
#include "CCPlatformConfig.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -54,7 +54,7 @@ public:
|
||||||
virtual ~CCAnimationFrame();
|
virtual ~CCAnimationFrame();
|
||||||
virtual CCObject* copyWithZone(CCZone* pZone);
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
|
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
|
||||||
bool initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCObjectDictionary* userInfo);
|
bool initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCDictionary* userInfo);
|
||||||
|
|
||||||
/** CCSpriteFrameName to be used */
|
/** CCSpriteFrameName to be used */
|
||||||
CC_SYNTHESIZE_RETAIN(CCSpriteFrame*, m_pSpriteFrame, SpriteFrame)
|
CC_SYNTHESIZE_RETAIN(CCSpriteFrame*, m_pSpriteFrame, SpriteFrame)
|
||||||
|
@ -63,7 +63,7 @@ public:
|
||||||
CC_SYNTHESIZE(float, m_fDelayUnits, DelayUnits)
|
CC_SYNTHESIZE(float, m_fDelayUnits, DelayUnits)
|
||||||
|
|
||||||
/** A CCAnimationFrameDisplayedNotification notification will be broadcasted when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcasted. */
|
/** A CCAnimationFrameDisplayedNotification notification will be broadcasted when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcasted. */
|
||||||
CC_SYNTHESIZE_RETAIN(CCObjectDictionary*, m_pUserInfo, UserInfo)
|
CC_SYNTHESIZE_RETAIN(CCDictionary*, m_pUserInfo, UserInfo)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,18 +92,18 @@ public:
|
||||||
The frames will be created with one "delay unit".
|
The frames will be created with one "delay unit".
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *arrayOfSpriteFrameNames);
|
static CCAnimation* animationWithSpriteFrames(CCArray* arrayOfSpriteFrameNames);
|
||||||
|
|
||||||
/* Creates an animation with an array of CCSpriteFrame and a delay between frames in seconds.
|
/* Creates an animation with an array of CCSpriteFrame and a delay between frames in seconds.
|
||||||
The frames will be added with one "delay unit".
|
The frames will be added with one "delay unit".
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *arrayOfSpriteFrameNames, float delay);
|
static CCAnimation* animationWithSpriteFrames(CCArray* arrayOfSpriteFrameNames, float delay);
|
||||||
|
|
||||||
/* Creates an animation with an array of CCAnimationFrame, the delay per units in seconds and and how many times it should be executed.
|
/* Creates an animation with an array of CCAnimationFrame, the delay per units in seconds and and how many times it should be executed.
|
||||||
@since v2.0
|
@since v2.0
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animationWithAnimationFrames(CCMutableArray<CCAnimationFrame*> *arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops);
|
static CCAnimation* animationWithAnimationFrames(CCArray *arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops);
|
||||||
|
|
||||||
/** Adds a CCSpriteFrame to a CCAnimation.
|
/** Adds a CCSpriteFrame to a CCAnimation.
|
||||||
The frame will be added with one "delay unit".
|
The frame will be added with one "delay unit".
|
||||||
|
@ -126,17 +126,17 @@ public:
|
||||||
/** Initializes a CCAnimation with frames.
|
/** Initializes a CCAnimation with frames.
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
bool initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames);
|
bool initWithSpriteFrames(CCArray *pFrames);
|
||||||
|
|
||||||
/** Initializes a CCAnimation with frames and a delay between frames
|
/** Initializes a CCAnimation with frames and a delay between frames
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
bool initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames, float delay);
|
bool initWithSpriteFrames(CCArray *pFrames, float delay);
|
||||||
|
|
||||||
/** Initializes a CCAnimation with CCAnimationFrame
|
/** Initializes a CCAnimation with CCAnimationFrame
|
||||||
@since v2.0
|
@since v2.0
|
||||||
*/
|
*/
|
||||||
bool initWithAnimationFrames(CCMutableArray<CCAnimationFrame*>* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops);
|
bool initWithAnimationFrames(CCArray* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops);
|
||||||
|
|
||||||
virtual CCObject* copyWithZone(CCZone* pZone);
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ public:
|
||||||
CC_PROPERTY_READONLY(float, m_fDuration, Duration)
|
CC_PROPERTY_READONLY(float, m_fDuration, Duration)
|
||||||
|
|
||||||
/** array of CCAnimationFrames */
|
/** array of CCAnimationFrames */
|
||||||
CC_SYNTHESIZE_RETAIN(CCMutableArray<CCAnimationFrame*>*, m_pFrames, Frames)
|
CC_SYNTHESIZE_RETAIN(CCArray*, m_pFrames, Frames)
|
||||||
|
|
||||||
/** whether or not it shall restore the original frame when the animation finishes */
|
/** whether or not it shall restore the original frame when the animation finishes */
|
||||||
CC_SYNTHESIZE(bool, m_bRestoreOriginalFrame, RestoreOriginalFrame)
|
CC_SYNTHESIZE(bool, m_bRestoreOriginalFrame, RestoreOriginalFrame)
|
||||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||||
#define __CC_ANIMATION_CACHE_H__
|
#define __CC_ANIMATION_CACHE_H__
|
||||||
|
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public:
|
||||||
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
||||||
@since v1.1
|
@since v1.1
|
||||||
*/
|
*/
|
||||||
void addAnimationsWithDictionary(CCObjectDictionary* dictionary);
|
void addAnimationsWithDictionary(CCDictionary* dictionary);
|
||||||
|
|
||||||
/** Adds an animation from a plist file.
|
/** Adds an animation from a plist file.
|
||||||
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
||||||
|
@ -83,11 +83,11 @@ public:
|
||||||
bool init(void);
|
bool init(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseVersion1(CCObjectDictionary* animations);
|
void parseVersion1(CCDictionary* animations);
|
||||||
void parseVersion2(CCObjectDictionary* animations);
|
void parseVersion2(CCDictionary* animations);
|
||||||
const char * valueForKey(const char *key, CCObjectDictionary* dict);
|
const char * valueForKey(const char *key, CCDictionary* dict);
|
||||||
private:
|
private:
|
||||||
CCMutableDictionary<std::string, CCAnimation*>* m_pAnimations;
|
CCDictionary* m_pAnimations;
|
||||||
static CCAnimationCache* s_pSharedAnimationCache;
|
static CCAnimationCache* s_pSharedAnimationCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,25 @@ I found that it's not work in C++. So it keep what it's look like in version 1.0
|
||||||
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
|
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
|
||||||
arr++)
|
arr++)
|
||||||
|
|
||||||
namespace cocos2d
|
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
|
||||||
{
|
if (__array__ && __array__->data->num > 0) \
|
||||||
|
for(CCObject** arr = __array__->data->arr + __array__->data->num-1, **end = __array__->data->arr; \
|
||||||
|
arr >= end && ((__object__ = *arr) != NULL/* || true*/); \
|
||||||
|
arr--)
|
||||||
|
|
||||||
|
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||||
|
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
|
||||||
|
do { \
|
||||||
|
if (__array__ && __array__->data->num > 0) \
|
||||||
|
for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1; arr <= end; arr++) \
|
||||||
|
CCAssert(dynamic_cast<__type__>(*arr), "element type is wrong!"); \
|
||||||
|
} while(false)
|
||||||
|
#else
|
||||||
|
#define CCARRAY_VERIFY_TYPE(__array__, __type__) void(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CC_DLL CCArray : public CCObject
|
class CC_DLL CCArray : public CCObject
|
||||||
{
|
{
|
||||||
|
@ -99,11 +116,11 @@ public:
|
||||||
// Removing Objects
|
// Removing Objects
|
||||||
|
|
||||||
/** Remove last object */
|
/** Remove last object */
|
||||||
void removeLastObject();
|
void removeLastObject(bool bReleaseObj = true);
|
||||||
/** Remove a certain object */
|
/** Remove a certain object */
|
||||||
void removeObject(CCObject* object);
|
void removeObject(CCObject* object, bool bReleaseObj = true);
|
||||||
/** Remove an element with a certain index */
|
/** Remove an element with a certain index */
|
||||||
void removeObjectAtIndex(unsigned int index);
|
void removeObjectAtIndex(unsigned int index, bool bReleaseObj = true);
|
||||||
/** Remove all elements */
|
/** Remove all elements */
|
||||||
void removeObjectsInArray(CCArray* otherArray);
|
void removeObjectsInArray(CCArray* otherArray);
|
||||||
/** Remove all objects */
|
/** Remove all objects */
|
||||||
|
@ -124,13 +141,15 @@ public:
|
||||||
/* Shrinks the array so the memory footprint corresponds with the number of items */
|
/* Shrinks the array so the memory footprint corresponds with the number of items */
|
||||||
void reduceMemoryFootprint();
|
void reduceMemoryFootprint();
|
||||||
|
|
||||||
|
void replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool bReleaseObject = true);
|
||||||
|
|
||||||
|
/** TODO: deep copy array. */
|
||||||
|
virtual CCObject* copyWithZone(CCZone* pZone) {CCAssert(false, "");return NULL;}
|
||||||
public:
|
public:
|
||||||
ccArray* data;
|
ccArray* data;
|
||||||
|
|
||||||
private:
|
|
||||||
CCArray() : data(NULL) {};
|
CCArray() : data(NULL) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
||||||
#endif // __CCARRAY_H__
|
#endif // __CCARRAY_H__
|
||||||
|
|
|
@ -25,12 +25,13 @@ THE SOFTWARE.
|
||||||
#define __AUTORELEASEPOOL_H__
|
#define __AUTORELEASEPOOL_H__
|
||||||
|
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace cocos2d {
|
|
||||||
class CC_DLL CCAutoreleasePool : public CCObject
|
class CC_DLL CCAutoreleasePool : public CCObject
|
||||||
{
|
{
|
||||||
CCMutableArray<CCObject*>* m_pManagedObjectArray;
|
CCArray* m_pManagedObjectArray;
|
||||||
public:
|
public:
|
||||||
CCAutoreleasePool(void);
|
CCAutoreleasePool(void);
|
||||||
~CCAutoreleasePool(void);
|
~CCAutoreleasePool(void);
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
|
|
||||||
class CC_DLL CCPoolManager
|
class CC_DLL CCPoolManager
|
||||||
{
|
{
|
||||||
CCMutableArray<CCAutoreleasePool*>* m_pReleasePoolStack;
|
CCArray* m_pReleasePoolStack;
|
||||||
CCAutoreleasePool* m_pCurReleasePool;
|
CCAutoreleasePool* m_pCurReleasePool;
|
||||||
|
|
||||||
CCAutoreleasePool* getCurReleasePool();
|
CCAutoreleasePool* getCurReleasePool();
|
||||||
|
@ -62,6 +63,6 @@ public:
|
||||||
friend class CCAutoreleasePool;
|
friend class CCAutoreleasePool;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__AUTORELEASEPOOL_H__
|
#endif //__AUTORELEASEPOOL_H__
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __CCDICTIONARY_H__
|
||||||
|
#define __CCDICTIONARY_H__
|
||||||
|
|
||||||
|
#include "support/data_support/uthash.h"
|
||||||
|
#include "CCObject.h"
|
||||||
|
#include "CCArray.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class CCDictionary;
|
||||||
|
|
||||||
|
class CC_DLL CCDictElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCDictElement(const char* pszKey, CCObject* pObject)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
strncpy(m_szKey, pszKey, sizeof(m_szKey));
|
||||||
|
m_pObject = pObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCDictElement(int iKey, CCObject* pObject)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
m_iKey = iKey;
|
||||||
|
m_pObject = pObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char* getStrKey() const
|
||||||
|
{
|
||||||
|
return m_szKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int getIntKey() const
|
||||||
|
{
|
||||||
|
return m_iKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CCObject* getObject() const
|
||||||
|
{
|
||||||
|
return m_pObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline void init()
|
||||||
|
{
|
||||||
|
m_iKey = 0;
|
||||||
|
m_pObject = NULL;
|
||||||
|
memset(m_szKey, 0, sizeof(m_szKey));
|
||||||
|
memset(&hh, 0, sizeof(hh));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char m_szKey[256]; /* hash key of string type*/
|
||||||
|
int m_iKey; /* hash key of integer type */
|
||||||
|
CCObject* m_pObject;/* hash value */
|
||||||
|
public:
|
||||||
|
UT_hash_handle hh; /* makes this class hashable */
|
||||||
|
friend class CCDictionary;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// #define CCDICT_FOREACH(__dict__, pElement) \
|
||||||
|
// for (pElement = __dict__->m_pElements; pElement != NULL; \
|
||||||
|
// pElement = (CCDictElement*)pElement->hh.next)
|
||||||
|
|
||||||
|
#define CCDICT_FOREACH(__dict__, __el__) \
|
||||||
|
CCDictElement* ##__dict__##__el__##tmp = NULL; \
|
||||||
|
HASH_ITER(hh, (__dict__)->m_pElements, __el__, ##__dict__##__el__##tmp)
|
||||||
|
|
||||||
|
|
||||||
|
class CC_DLL CCDictionary : public CCObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCDictionary();
|
||||||
|
~CCDictionary();
|
||||||
|
|
||||||
|
/// return the number of items
|
||||||
|
unsigned int count();
|
||||||
|
|
||||||
|
/// return all the keys
|
||||||
|
CCArray* allKeys();
|
||||||
|
|
||||||
|
/** @warning : We use '==' to compare two objects*/
|
||||||
|
CCArray* allKeysForObject(CCObject* object);
|
||||||
|
|
||||||
|
CCObject* objectForKey(const char* key);
|
||||||
|
CCObject* objectForKey(int key);
|
||||||
|
|
||||||
|
bool setObject(CCObject* pObject, const char* key);
|
||||||
|
bool setObject(CCObject* pObject, int key);
|
||||||
|
|
||||||
|
void removeObjectForKey(const char* key);
|
||||||
|
void removeObjectForKey(int key);
|
||||||
|
|
||||||
|
void removeAllObjects();
|
||||||
|
|
||||||
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
|
static CCDictionary* dictionaryWithDictionary(CCDictionary* srcDict);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CCDictElement* m_pElements;
|
||||||
|
private:
|
||||||
|
enum CCDictType
|
||||||
|
{
|
||||||
|
kCCDictUnknown = 0,
|
||||||
|
kCCDictStr,
|
||||||
|
kCCDictInt
|
||||||
|
};
|
||||||
|
CCDictType m_eDictType;
|
||||||
|
CCDictType m_eOldDictType;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* __CCDICTIONARY_H__ */
|
|
@ -31,7 +31,7 @@ THE SOFTWARE.
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
|
@ -448,7 +448,7 @@ protected:
|
||||||
bool m_bSendCleanupToScene;
|
bool m_bSendCleanupToScene;
|
||||||
|
|
||||||
/* scheduled scenes */
|
/* scheduled scenes */
|
||||||
CCMutableArray<CCScene*> *m_pobScenesStack;
|
CCArray* m_pobScenesStack;
|
||||||
|
|
||||||
/* last time the main loop was updated */
|
/* last time the main loop was updated */
|
||||||
struct cc_timeval *m_pLastUpdate;
|
struct cc_timeval *m_pLastUpdate;
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef __CCINTEGER_H__
|
||||||
|
#define __CCINTEGER_H__
|
||||||
|
|
||||||
|
#include "CCObject.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class CC_DLL CCInteger : public CCObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCInteger(int v)
|
||||||
|
: value(v) {}
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* __CCINTEGER_H__ */
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
||||||
#define __CCKEYPAD_DISPATCHER_H__
|
#define __CCKEYPAD_DISPATCHER_H__
|
||||||
|
|
||||||
#include "CCKeypadDelegate.h"
|
#include "CCKeypadDelegate.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -84,9 +84,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
typedef CCMutableArray<CCKeypadHandler*> KeypadDelegateArray;
|
CCArray* m_pDelegates;
|
||||||
|
|
||||||
KeypadDelegateArray* m_pDelegates;
|
|
||||||
bool m_bLocked;
|
bool m_bLocked;
|
||||||
bool m_bToAdd;
|
bool m_bToAdd;
|
||||||
bool m_bToRemove;
|
bool m_bToRemove;
|
||||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
||||||
#include "CCTouchDelegateProtocol.h"
|
#include "CCTouchDelegateProtocol.h"
|
||||||
#include "CCAccelerometerDelegate.h"
|
#include "CCAccelerometerDelegate.h"
|
||||||
#include "CCKeypadDelegate.h"
|
#include "CCKeypadDelegate.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ class CC_DLL CCLayerMultiplex : public CCLayer
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
unsigned int m_nEnabledLayer;
|
unsigned int m_nEnabledLayer;
|
||||||
CCMutableArray<CCLayer *> * m_pLayers;
|
CCArray* m_pLayers;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CCLayerMultiplex();
|
CCLayerMultiplex();
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d{
|
namespace cocos2d{
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ namespace cocos2d{
|
||||||
/** CCMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
|
/** CCMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
*/
|
*/
|
||||||
CC_PROPERTY(CCMutableArray<CCMenuItem*>*, m_pSubItems, SubItems);
|
CC_PROPERTY(CCArray*, m_pSubItems, SubItems);
|
||||||
public:
|
public:
|
||||||
CCMenuItemToggle()
|
CCMenuItemToggle()
|
||||||
: m_cOpacity(0)
|
: m_cOpacity(0)
|
||||||
|
|
|
@ -1,363 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef __COCOA_CC_MUTABLE_ARRAY_H__
|
|
||||||
#define __COCOA_CC_MUTABLE_ARRAY_H__
|
|
||||||
|
|
||||||
#include "CCObject.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
#include <vector>
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
namespace cocos2d {
|
|
||||||
|
|
||||||
// the element should be pointer of CCObject or it's sub class
|
|
||||||
template<class T = CCObject*>
|
|
||||||
class CCMutableArray : public CCObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef std::vector<T> CCObjectArray;
|
|
||||||
typedef typename CCObjectArray::iterator CCMutableArrayIterator;
|
|
||||||
typedef typename CCObjectArray::reverse_iterator CCMutableArrayRevIterator;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CCMutableArray(unsigned int uSize = 0)
|
|
||||||
{
|
|
||||||
if (uSize != 0)
|
|
||||||
m_array.reserve(uSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~CCMutableArray(void)
|
|
||||||
{
|
|
||||||
removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline unsigned int count(void)
|
|
||||||
{
|
|
||||||
return (unsigned int)m_array.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool containsObject(T pObject)
|
|
||||||
{
|
|
||||||
if (m_array.empty() || (! pObject))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bRet = false;
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
for (iter = m_array.begin(); iter != m_array.end(); ++iter)
|
|
||||||
{
|
|
||||||
if (*iter == pObject)
|
|
||||||
{
|
|
||||||
bRet = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
T getLastObject(void)
|
|
||||||
{
|
|
||||||
CCMutableArrayRevIterator iter = rbegin();
|
|
||||||
|
|
||||||
if (iter != m_array.rend())
|
|
||||||
return *iter;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
T getObjectAtIndex(unsigned int uIndex)
|
|
||||||
{
|
|
||||||
CCAssert(uIndex < count(), "");
|
|
||||||
|
|
||||||
if (uIndex >= count())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_array[uIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adding objects
|
|
||||||
void addObject(T pObject)
|
|
||||||
{
|
|
||||||
// make sure the pointer is not null
|
|
||||||
if (pObject == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the refrence
|
|
||||||
pObject->retain();
|
|
||||||
|
|
||||||
m_array.push_back(pObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
void addObjectsFromArray(CCMutableArray<T> *pArray)
|
|
||||||
{
|
|
||||||
if (pArray && pArray->count() > 0)
|
|
||||||
{
|
|
||||||
m_array.reserve(count() + pArray->count());
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
|
||||||
{
|
|
||||||
if (*iter)
|
|
||||||
(*iter)->retain();
|
|
||||||
m_array.push_back(*iter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void insertObjectAtIndex(T pObject, unsigned int uIndex)
|
|
||||||
{
|
|
||||||
CCAssert(uIndex <= count(), "");
|
|
||||||
// make sure the object is not null
|
|
||||||
if (pObject == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the reference of the object
|
|
||||||
pObject->retain();
|
|
||||||
|
|
||||||
// resize the capacity if the index out of it
|
|
||||||
if (uIndex >= m_array.capacity())
|
|
||||||
{
|
|
||||||
m_array.reserve(uIndex + 1);
|
|
||||||
m_array.push_back(pObject);
|
|
||||||
}
|
|
||||||
else // insert the object
|
|
||||||
m_array.insert(m_array.begin() + uIndex, pObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removing objects
|
|
||||||
void removeLastObject(bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
CCMutableArrayRevIterator it = m_array.rbegin();
|
|
||||||
if (it != m_array.rend())
|
|
||||||
{
|
|
||||||
if (bDeleteObject)
|
|
||||||
(*it)->release();
|
|
||||||
m_array.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObject(T pObject, bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (m_array.empty() || (! pObject))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
int i;
|
|
||||||
for (iter = m_array.begin(), i = 0; iter != m_array.end(); ++iter, ++i)
|
|
||||||
{
|
|
||||||
if (*iter == pObject)
|
|
||||||
{
|
|
||||||
m_array.erase(iter);
|
|
||||||
|
|
||||||
if (bDeleteObject)
|
|
||||||
{
|
|
||||||
pObject->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObjectsInArray(CCMutableArray<T>* pDeleteArray)
|
|
||||||
{
|
|
||||||
if(pDeleteArray && pDeleteArray->count())
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator it;
|
|
||||||
for( it = pDeleteArray->m_array.begin(); it != pDeleteArray->m_array.end(); ++it)
|
|
||||||
{
|
|
||||||
removeObject(*it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObjectAtIndex(unsigned int uIndex, bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (m_array.empty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bDeleteObject)
|
|
||||||
{
|
|
||||||
T pObject = m_array.at(uIndex);
|
|
||||||
if (pObject)
|
|
||||||
{
|
|
||||||
pObject->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_array.erase(m_array.begin() + uIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeAllObjects(bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (bDeleteObject)
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
for (iter = m_array.begin(); iter != m_array.end(); ++iter)
|
|
||||||
(*iter)->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_array.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void replaceObjectAtIndex(unsigned int uIndex, T pObject, bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (bDeleteObject && m_array[uIndex])
|
|
||||||
{
|
|
||||||
m_array[uIndex]->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_array[uIndex] = pObject;
|
|
||||||
|
|
||||||
// add the ref
|
|
||||||
if (pObject)
|
|
||||||
{
|
|
||||||
pObject->retain();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayIterator begin(void)
|
|
||||||
{
|
|
||||||
return m_array.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayRevIterator rbegin(void)
|
|
||||||
{
|
|
||||||
return m_array.rbegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
CCMutableArrayIterator getLastValidIterator(void)
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
CCMutableArrayIterator ret;
|
|
||||||
for (iter = m_array.begin(); iter != m_array.end(); ++iter)
|
|
||||||
{
|
|
||||||
ret = iter;
|
|
||||||
if (! (*iter))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* end is a keyword of lua, so should use other name
|
|
||||||
* to export to lua
|
|
||||||
*/
|
|
||||||
inline CCMutableArrayIterator endToLua(void)
|
|
||||||
{
|
|
||||||
return m_array.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayIterator end(void)
|
|
||||||
{
|
|
||||||
return m_array.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayRevIterator rend(void)
|
|
||||||
{
|
|
||||||
return m_array.rend();
|
|
||||||
}
|
|
||||||
|
|
||||||
CCMutableArray<T>* copy(void)
|
|
||||||
{
|
|
||||||
CCMutableArray* pArray = new CCMutableArray();
|
|
||||||
|
|
||||||
pArray->m_array.assign(m_array.begin(), m_array.end());
|
|
||||||
|
|
||||||
if(pArray->count() > 0)
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator it;
|
|
||||||
for(it = pArray->begin(); it != pArray->end(); ++it)
|
|
||||||
{
|
|
||||||
if(*it)
|
|
||||||
{
|
|
||||||
(*it)->retain();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
static CCMutableArray<T>* arrayWithObjects(T pObject1, ...)
|
|
||||||
{
|
|
||||||
CCMutableArray<T> *pArray = new CCMutableArray<T>();
|
|
||||||
pArray->autorelease();
|
|
||||||
|
|
||||||
va_list params;
|
|
||||||
va_start(params, pObject1);
|
|
||||||
|
|
||||||
T pFirst = pObject1;
|
|
||||||
while (pFirst)
|
|
||||||
{
|
|
||||||
pArray->addObject(pFirst);
|
|
||||||
pFirst = va_arg(params, T);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(params);
|
|
||||||
|
|
||||||
return pArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
static CCMutableArray<T>* arrayWithArray(CCMutableArray<T> *pSrcArray)
|
|
||||||
{
|
|
||||||
CCMutableArray<T> *pDestArray = 0;
|
|
||||||
|
|
||||||
if (pSrcArray == 0)
|
|
||||||
{
|
|
||||||
pDestArray = new CCMutableArray<T>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pDestArray = pSrcArray->copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
pDestArray->autorelease();
|
|
||||||
|
|
||||||
return pDestArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<T> m_array;
|
|
||||||
};
|
|
||||||
|
|
||||||
}//namespace cocos2d
|
|
||||||
|
|
||||||
#endif // __COCOA_CC_MUTABLE_ARRAY_H__
|
|
|
@ -1,241 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
#ifndef __CCMUTABLE_DICTIONARY_H__
|
|
||||||
#define __CCMUTABLE_DICTIONARY_H__
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include "CCObject.h"
|
|
||||||
#include "CCMutableArray.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
namespace cocos2d {
|
|
||||||
class CCString;
|
|
||||||
|
|
||||||
template<class _KeyT, class _ValueT = CCObject*>
|
|
||||||
class CCMutableDictionary : public CCObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef std::map<_KeyT, _ValueT> CCObjectMap;
|
|
||||||
typedef typename CCObjectMap::iterator CCObjectMapIter;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
typedef pair<_KeyT, _ValueT> Int_Pair;
|
|
||||||
CCObjectMap m_Map;
|
|
||||||
bool m_bBegin;
|
|
||||||
CCObjectMapIter m_MapIter;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CCMutableDictionary(void)
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
~CCMutableDictionary(void)
|
|
||||||
{
|
|
||||||
removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// return the number of items
|
|
||||||
unsigned int count()
|
|
||||||
{
|
|
||||||
return m_Map.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// return all the keys
|
|
||||||
std::vector<_KeyT> allKeys()
|
|
||||||
{
|
|
||||||
std::vector<_KeyT> tRet;
|
|
||||||
if (m_Map.size() > 0)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
for( it = m_Map.begin(); it != m_Map.end(); ++it)
|
|
||||||
{
|
|
||||||
tRet.push_back(it->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @warning : We use '==' to compare two objects*/
|
|
||||||
std::vector<_KeyT> allKeysForObject(_ValueT object)
|
|
||||||
{
|
|
||||||
std::vector<_KeyT> tRet;
|
|
||||||
if (m_Map.size() > 0)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
for( it= m_Map.begin(); it != m_Map.end(); ++it)
|
|
||||||
{
|
|
||||||
if (it->second == object)
|
|
||||||
{
|
|
||||||
tRet.push_back(it->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ValueT objectForKey(const _KeyT& key) ///<
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
|
|
||||||
it = m_Map.find(key);
|
|
||||||
|
|
||||||
if(it == m_Map.end()) //no match case
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setObject(_ValueT pObject, const _KeyT& key)
|
|
||||||
{
|
|
||||||
pair<CCObjectMapIter, bool > pr;
|
|
||||||
|
|
||||||
pr = m_Map.insert( Int_Pair(key, pObject) );
|
|
||||||
|
|
||||||
if(pr.second == true)
|
|
||||||
{
|
|
||||||
pObject->retain();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObjectForKey(const _KeyT& key)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
|
|
||||||
it = m_Map.find(key);
|
|
||||||
|
|
||||||
if(it == m_Map.end()) //no match case
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(it->second )
|
|
||||||
{
|
|
||||||
it->second->release() ;
|
|
||||||
m_Map.erase(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool begin()
|
|
||||||
{
|
|
||||||
if(m_Map.size() == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_MapIter = m_Map.begin();
|
|
||||||
m_bBegin = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ValueT next(_KeyT* key = NULL)
|
|
||||||
{
|
|
||||||
if(!m_bBegin)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
_ValueT pObject = m_MapIter->second;
|
|
||||||
|
|
||||||
if(m_MapIter == m_Map.end())
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(key)
|
|
||||||
{
|
|
||||||
*key = m_MapIter->first;
|
|
||||||
}
|
|
||||||
|
|
||||||
++m_MapIter;
|
|
||||||
|
|
||||||
if(m_MapIter == m_Map.end())
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* end is a keyword of lua, so should use other name
|
|
||||||
* to export to lua
|
|
||||||
*/
|
|
||||||
void endToLua()
|
|
||||||
{
|
|
||||||
end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void end()
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeAllObjects()
|
|
||||||
{
|
|
||||||
if (m_Map.size() > 0)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
for( it = m_Map.begin(); it != m_Map.end(); ++it)
|
|
||||||
{
|
|
||||||
if (it->second)
|
|
||||||
{
|
|
||||||
it->second->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_Map.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
static CCMutableDictionary<_KeyT, _ValueT>* dictionaryWithDictionary(CCMutableDictionary<_KeyT, _ValueT>* srcDict)
|
|
||||||
{
|
|
||||||
CCMutableDictionary<_KeyT, _ValueT>* pNewDict = new CCMutableDictionary<_KeyT, _ValueT>();
|
|
||||||
|
|
||||||
srcDict->begin();
|
|
||||||
|
|
||||||
_KeyT key;
|
|
||||||
_ValueT value;
|
|
||||||
|
|
||||||
while( (value = srcDict->next(&key)) )
|
|
||||||
{
|
|
||||||
pNewDict->setObject(value, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
srcDict->end();
|
|
||||||
|
|
||||||
return pNewDict;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#define CCDictionary CCMutableDictionary
|
|
||||||
typedef CCDictionary<std::string, CCString*> CCStringToStringDictionary;
|
|
||||||
typedef CCDictionary<std::string, CCObject*> CCObjectDictionary;
|
|
||||||
|
|
||||||
}//namespace cocos2d
|
|
||||||
|
|
||||||
|
|
||||||
#endif //__CCMUTABLE_DICTIONARY_H__
|
|
|
@ -28,10 +28,10 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CCParticleBatchNode;
|
class CCParticleBatchNode;
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ public:
|
||||||
/** initializes a CCQuadParticleSystem from a CCDictionary.
|
/** initializes a CCQuadParticleSystem from a CCDictionary.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
bool initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary);
|
bool initWithDictionary(CCDictionary *dictionary);
|
||||||
|
|
||||||
//! Initializes a system with a fixed number of particles
|
//! Initializes a system with a fixed number of particles
|
||||||
virtual bool initWithTotalParticles(unsigned int numberOfParticles);
|
virtual bool initWithTotalParticles(unsigned int numberOfParticles);
|
||||||
|
@ -396,17 +396,17 @@ private:
|
||||||
/** Private method, return the string found by key in dict.
|
/** Private method, return the string found by key in dict.
|
||||||
@return "" if not found; return the string if found.
|
@return "" if not found; return the string if found.
|
||||||
*/
|
*/
|
||||||
inline const char * valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict)
|
inline const char * valueForKey(const char *key, CCDictionary *dict)
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
CCString *pString = (CCString*)dict->objectForKey(std::string(key));
|
CCString *pString = (CCString*)dict->objectForKey(key);
|
||||||
return pString ? pString->m_sString.c_str() : "";
|
return pString ? pString->m_sString.c_str() : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__CCPARTICLE_SYSTEM_H__
|
#endif //__CCPARTICLE_SYSTEM_H__
|
||||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||||
#ifndef __CCSHADERCACHE_H__
|
#ifndef __CCSHADERCACHE_H__
|
||||||
#define __CCSHADERCACHE_H__
|
#define __CCSHADERCACHE_H__
|
||||||
|
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
private:
|
private:
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
CCMutableDictionary<std::string, CCGLProgram*>* m_pPrograms;
|
CCDictionary* m_pPrograms;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCTextureAtlas.h"
|
#include "CCTextureAtlas.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCTextureAtlas.h"
|
#include "CCTextureAtlas.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d
|
namespace cocos2d
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,7 +38,7 @@ THE SOFTWARE.
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
class CCSprite;
|
class CCSprite;
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
|
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
|
||||||
*/
|
*/
|
||||||
void addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *pobDictionary, CCTexture2D *pobTexture);
|
void addSpriteFramesWithDictionary(CCDictionary* pobDictionary, CCTexture2D *pobTexture);
|
||||||
|
|
||||||
/** Adds multiple Sprite Frames from a plist file.
|
/** Adds multiple Sprite Frames from a plist file.
|
||||||
* A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
|
* A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
|
||||||
|
@ -103,7 +103,7 @@ public:
|
||||||
/** Removes multiple Sprite Frames from CCDictionary.
|
/** Removes multiple Sprite Frames from CCDictionary.
|
||||||
* @since v0.99.5
|
* @since v0.99.5
|
||||||
*/
|
*/
|
||||||
void removeSpriteFramesFromDictionary(CCDictionary<std::string, CCSpriteFrame*> *dictionary);
|
void removeSpriteFramesFromDictionary(CCDictionary* dictionary);
|
||||||
|
|
||||||
/** Removes all Sprite Frames associated with the specified textures.
|
/** Removes all Sprite Frames associated with the specified textures.
|
||||||
* It is convinient to call this method when a specific texture needs to be removed.
|
* It is convinient to call this method when a specific texture needs to be removed.
|
||||||
|
@ -126,11 +126,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCSpriteFrameCache(void) : m_pSpriteFrames(NULL), m_pSpriteFramesAliases(NULL){}
|
CCSpriteFrameCache(void) : m_pSpriteFrames(NULL), m_pSpriteFramesAliases(NULL){}
|
||||||
const char * valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict);
|
const char * valueForKey(const char* key, CCDictionary* dict);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CCDictionary<std::string, CCSpriteFrame*> *m_pSpriteFrames;
|
CCDictionary* m_pSpriteFrames;
|
||||||
CCDictionary<std::string, CCString*> *m_pSpriteFramesAliases;
|
CCDictionary* m_pSpriteFramesAliases;
|
||||||
};
|
};
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,11 @@ namespace cocos2d {
|
||||||
return m_sString;
|
return m_sString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* c_str()
|
||||||
|
{
|
||||||
|
return m_sString.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
bool isEmpty()
|
bool isEmpty()
|
||||||
{
|
{
|
||||||
return m_sString.empty();
|
return m_sString.empty();
|
||||||
|
|
|
@ -79,7 +79,7 @@ class CC_DLL CCTMXLayer : public CCSpriteBatchNode
|
||||||
/** Layer orientation, which is the same as the map orientation */
|
/** Layer orientation, which is the same as the map orientation */
|
||||||
CC_SYNTHESIZE(unsigned int, m_uLayerOrientation, LayerOrientation);
|
CC_SYNTHESIZE(unsigned int, m_uLayerOrientation, LayerOrientation);
|
||||||
/** properties from the layer. They can be added using Tiled */
|
/** properties from the layer. They can be added using Tiled */
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
CCTMXLayer();
|
CCTMXLayer();
|
||||||
virtual ~CCTMXLayer();
|
virtual ~CCTMXLayer();
|
||||||
|
|
|
@ -29,8 +29,8 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ namespace cocos2d {
|
||||||
/** offset position of child objects */
|
/** offset position of child objects */
|
||||||
CC_SYNTHESIZE_PASS_BY_REF(CCPoint, m_tPositionOffset, PositionOffset);
|
CC_SYNTHESIZE_PASS_BY_REF(CCPoint, m_tPositionOffset, PositionOffset);
|
||||||
/** list of properties stored in a dictionary */
|
/** list of properties stored in a dictionary */
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
/** array of the objects */
|
/** array of the objects */
|
||||||
CC_PROPERTY(CCMutableArray<CCStringToStringDictionary*>*, m_pObjects, Objects);
|
CC_PROPERTY(CCArray*, m_pObjects, Objects);
|
||||||
public:
|
public:
|
||||||
CCTMXObjectGroup();
|
CCTMXObjectGroup();
|
||||||
virtual ~CCTMXObjectGroup();
|
virtual ~CCTMXObjectGroup();
|
||||||
|
@ -58,7 +58,7 @@ namespace cocos2d {
|
||||||
/** return the dictionary for the specific object name.
|
/** return the dictionary for the specific object name.
|
||||||
It will return the 1st object found on the array for the given name.
|
It will return the 1st object found on the array for the given name.
|
||||||
*/
|
*/
|
||||||
CCStringToStringDictionary *objectNamed(const char *objectName);
|
CCDictionary* objectNamed(const char *objectName);
|
||||||
protected:
|
protected:
|
||||||
/** name of the group */
|
/** name of the group */
|
||||||
std::string m_sGroupName;
|
std::string m_sGroupName;
|
||||||
|
|
|
@ -28,17 +28,17 @@ THE SOFTWARE.
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCTMXObjectGroup.h"
|
#include "CCTMXObjectGroup.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CCTMXObjectGroup;
|
class CCTMXObjectGroup;
|
||||||
class CCTMXLayer;
|
class CCTMXLayer;
|
||||||
class CCTMXLayerInfo;
|
class CCTMXLayerInfo;
|
||||||
class CCTMXTilesetInfo;
|
class CCTMXTilesetInfo;
|
||||||
class CCTMXMapInfo;
|
class CCTMXMapInfo;
|
||||||
|
|
||||||
/** Possible oritentations of the TMX map */
|
/** Possible oritentations of the TMX map */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
/** Orthogonal orientation */
|
/** Orthogonal orientation */
|
||||||
CCTMXOrientationOrtho,
|
CCTMXOrientationOrtho,
|
||||||
|
|
||||||
|
@ -47,61 +47,61 @@ namespace cocos2d {
|
||||||
|
|
||||||
/** Isometric orientation */
|
/** Isometric orientation */
|
||||||
CCTMXOrientationIso,
|
CCTMXOrientationIso,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief CCTMXTiledMap knows how to parse and render a TMX map.
|
/** @brief CCTMXTiledMap knows how to parse and render a TMX map.
|
||||||
|
|
||||||
It adds support for the TMX tiled map format used by http://www.mapeditor.org
|
It adds support for the TMX tiled map format used by http://www.mapeditor.org
|
||||||
It supports isometric, hexagonal and orthogonal tiles.
|
It supports isometric, hexagonal and orthogonal tiles.
|
||||||
It also supports object groups, objects, and properties.
|
It also supports object groups, objects, and properties.
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
- Each tile will be treated as an CCSprite
|
- Each tile will be treated as an CCSprite
|
||||||
- The sprites are created on demand. They will be created only when you call "layer->tileAt(position)"
|
- The sprites are created on demand. They will be created only when you call "layer->tileAt(position)"
|
||||||
- Each tile can be rotated / moved / scaled / tinted / "opacitied", since each tile is a CCSprite
|
- Each tile can be rotated / moved / scaled / tinted / "opacitied", since each tile is a CCSprite
|
||||||
- Tiles can be added/removed in runtime
|
- Tiles can be added/removed in runtime
|
||||||
- The z-order of the tiles can be modified in runtime
|
- The z-order of the tiles can be modified in runtime
|
||||||
- Each tile has an anchorPoint of (0,0)
|
- Each tile has an anchorPoint of (0,0)
|
||||||
- The anchorPoint of the TMXTileMap is (0,0)
|
- The anchorPoint of the TMXTileMap is (0,0)
|
||||||
- The TMX layers will be added as a child
|
- The TMX layers will be added as a child
|
||||||
- The TMX layers will be aliased by default
|
- The TMX layers will be aliased by default
|
||||||
- The tileset image will be loaded using the CCTextureCache
|
- The tileset image will be loaded using the CCTextureCache
|
||||||
- Each tile will have a unique tag
|
- Each tile will have a unique tag
|
||||||
- Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z
|
- Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z
|
||||||
- Each object group will be treated as an CCMutableArray
|
- Each object group will be treated as an CCMutableArray
|
||||||
- Object class which will contain all the properties in a dictionary
|
- Object class which will contain all the properties in a dictionary
|
||||||
- Properties can be assigned to the Map, Layer, Object Group, and Object
|
- Properties can be assigned to the Map, Layer, Object Group, and Object
|
||||||
|
|
||||||
Limitations:
|
Limitations:
|
||||||
- It only supports one tileset per layer.
|
- It only supports one tileset per layer.
|
||||||
- Embeded images are not supported
|
- Embeded images are not supported
|
||||||
- It only supports the XML format (the JSON format is not supported)
|
- It only supports the XML format (the JSON format is not supported)
|
||||||
|
|
||||||
Technical description:
|
Technical description:
|
||||||
Each layer is created using an CCTMXLayer (subclass of CCSpriteBatchNode). If you have 5 layers, then 5 CCTMXLayer will be created,
|
Each layer is created using an CCTMXLayer (subclass of CCSpriteBatchNode). If you have 5 layers, then 5 CCTMXLayer will be created,
|
||||||
unless the layer visibility is off. In that case, the layer won't be created at all.
|
unless the layer visibility is off. In that case, the layer won't be created at all.
|
||||||
You can obtain the layers (CCTMXLayer objects) at runtime by:
|
You can obtain the layers (CCTMXLayer objects) at runtime by:
|
||||||
- map->getChildByTag(tag_number); // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...
|
- map->getChildByTag(tag_number); // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...
|
||||||
- map->layerNamed(name_of_the_layer);
|
- map->layerNamed(name_of_the_layer);
|
||||||
|
|
||||||
Each object group is created using a CCTMXObjectGroup which is a subclass of CCMutableArray.
|
Each object group is created using a CCTMXObjectGroup which is a subclass of CCMutableArray.
|
||||||
You can obtain the object groups at runtime by:
|
You can obtain the object groups at runtime by:
|
||||||
- map->objectGroupNamed(name_of_the_object_group);
|
- map->objectGroupNamed(name_of_the_object_group);
|
||||||
|
|
||||||
Each object is a CCTMXObject.
|
Each object is a CCTMXObject.
|
||||||
|
|
||||||
Each property is stored as a key-value pair in an CCMutableDictionary.
|
Each property is stored as a key-value pair in an CCMutableDictionary.
|
||||||
You can obtain the properties at runtime by:
|
You can obtain the properties at runtime by:
|
||||||
|
|
||||||
map->propertyNamed(name_of_the_property);
|
map->propertyNamed(name_of_the_property);
|
||||||
layer->propertyNamed(name_of_the_property);
|
layer->propertyNamed(name_of_the_property);
|
||||||
objectGroup->propertyNamed(name_of_the_property);
|
objectGroup->propertyNamed(name_of_the_property);
|
||||||
object->propertyNamed(name_of_the_property);
|
object->propertyNamed(name_of_the_property);
|
||||||
|
|
||||||
@since v0.8.1
|
@since v0.8.1
|
||||||
*/
|
*/
|
||||||
class CC_DLL CCTMXTiledMap : public CCNode
|
class CC_DLL CCTMXTiledMap : public CCNode
|
||||||
{
|
{
|
||||||
/** the map's size property measured in tiles */
|
/** the map's size property measured in tiles */
|
||||||
CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tMapSize, MapSize);
|
CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tMapSize, MapSize);
|
||||||
/** the tiles's size property measured in pixels */
|
/** the tiles's size property measured in pixels */
|
||||||
|
@ -109,10 +109,10 @@ namespace cocos2d {
|
||||||
/** map orientation */
|
/** map orientation */
|
||||||
CC_SYNTHESIZE(int, m_nMapOrientation, MapOrientation);
|
CC_SYNTHESIZE(int, m_nMapOrientation, MapOrientation);
|
||||||
/** object groups */
|
/** object groups */
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXObjectGroup*>*, m_pObjectGroups, ObjectGroups);
|
CC_PROPERTY(CCArray*, m_pObjectGroups, ObjectGroups);
|
||||||
/** properties */
|
/** properties */
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
CCTMXTiledMap();
|
CCTMXTiledMap();
|
||||||
virtual ~CCTMXTiledMap();
|
virtual ~CCTMXTiledMap();
|
||||||
|
|
||||||
|
@ -138,19 +138,20 @@ namespace cocos2d {
|
||||||
CCString *propertyNamed(const char *propertyName);
|
CCString *propertyNamed(const char *propertyName);
|
||||||
|
|
||||||
/** return properties dictionary for tile GID */
|
/** return properties dictionary for tile GID */
|
||||||
CCDictionary<std::string, CCString*> *propertiesForGID(int GID);
|
CCDictionary* propertiesForGID(int GID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
|
CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
|
||||||
CCTMXTilesetInfo * tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
|
CCTMXTilesetInfo * tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
|
||||||
void buildWithMapInfo(CCTMXMapInfo* mapInfo);
|
void buildWithMapInfo(CCTMXMapInfo* mapInfo);
|
||||||
protected:
|
protected:
|
||||||
//! tile properties
|
//! tile properties
|
||||||
CCDictionary<int, CCStringToStringDictionary*> *m_pTileProperties;
|
CCDictionary* m_pTileProperties;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
}// namespace cocos2d
|
|
||||||
#endif //__CCTMX_TILE_MAP_H__
|
#endif //__CCTMX_TILE_MAP_H__
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,62 +27,62 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#ifndef __CC_TM_XML_PARSER__
|
#ifndef __CC_TM_XML_PARSER__
|
||||||
#define __CC_TM_XML_PARSER__
|
#define __CC_TM_XML_PARSER__
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
|
|
||||||
#include "../platform/CCSAXParser.h"
|
#include "../platform/CCSAXParser.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CCTMXObjectGroup;
|
class CCTMXObjectGroup;
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
* Internal TMX parser
|
* Internal TMX parser
|
||||||
*
|
*
|
||||||
* IMPORTANT: These classed should not be documented using doxygen strings
|
* IMPORTANT: These classed should not be documented using doxygen strings
|
||||||
* since the user should not use them.
|
* since the user should not use them.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TMXLayerAttribNone = 1 << 0,
|
TMXLayerAttribNone = 1 << 0,
|
||||||
TMXLayerAttribBase64 = 1 << 1,
|
TMXLayerAttribBase64 = 1 << 1,
|
||||||
TMXLayerAttribGzip = 1 << 2,
|
TMXLayerAttribGzip = 1 << 2,
|
||||||
TMXLayerAttribZlib = 1 << 3,
|
TMXLayerAttribZlib = 1 << 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TMXPropertyNone,
|
TMXPropertyNone,
|
||||||
TMXPropertyMap,
|
TMXPropertyMap,
|
||||||
TMXPropertyLayer,
|
TMXPropertyLayer,
|
||||||
TMXPropertyObjectGroup,
|
TMXPropertyObjectGroup,
|
||||||
TMXPropertyObject,
|
TMXPropertyObject,
|
||||||
TMXPropertyTile
|
TMXPropertyTile
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum ccTMXTileFlags_ {
|
typedef enum ccTMXTileFlags_ {
|
||||||
kCCTMXTileHorizontalFlag = 0x80000000,
|
kCCTMXTileHorizontalFlag = 0x80000000,
|
||||||
kCCTMXTileVerticalFlag = 0x40000000,
|
kCCTMXTileVerticalFlag = 0x40000000,
|
||||||
kCCTMXTileDiagonalFlag = 0x20000000,
|
kCCTMXTileDiagonalFlag = 0x20000000,
|
||||||
kCCFlipedAll = (kCCTMXTileHorizontalFlag|kCCTMXTileVerticalFlag|kCCTMXTileDiagonalFlag),
|
kCCFlipedAll = (kCCTMXTileHorizontalFlag|kCCTMXTileVerticalFlag|kCCTMXTileDiagonalFlag),
|
||||||
kCCFlippedMask = ~(kCCFlipedAll)
|
kCCFlippedMask = ~(kCCFlipedAll)
|
||||||
} ccTMXTileFlags;
|
} ccTMXTileFlags;
|
||||||
|
|
||||||
// Bits on the far end of the 32-bit global tile ID (GID's) are used for tile flags
|
// Bits on the far end of the 32-bit global tile ID (GID's) are used for tile flags
|
||||||
|
|
||||||
/** @brief CCTMXLayerInfo contains the information about the layers like:
|
/** @brief CCTMXLayerInfo contains the information about the layers like:
|
||||||
- Layer name
|
- Layer name
|
||||||
- Layer size
|
- Layer size
|
||||||
- Layer opacity at creation time (it can be modified at runtime)
|
- Layer opacity at creation time (it can be modified at runtime)
|
||||||
- Whether the layer is visible (if it's not visible, then the CocosNode won't be created)
|
- Whether the layer is visible (if it's not visible, then the CocosNode won't be created)
|
||||||
|
|
||||||
This information is obtained from the TMX file.
|
This information is obtained from the TMX file.
|
||||||
*/
|
*/
|
||||||
class CC_DLL CCTMXLayerInfo : public CCObject
|
class CC_DLL CCTMXLayerInfo : public CCObject
|
||||||
{
|
{
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
std::string m_sName;
|
std::string m_sName;
|
||||||
CCSize m_tLayerSize;
|
CCSize m_tLayerSize;
|
||||||
unsigned int *m_pTiles;
|
unsigned int *m_pTiles;
|
||||||
|
@ -92,24 +92,24 @@ namespace cocos2d {
|
||||||
unsigned int m_uMinGID;
|
unsigned int m_uMinGID;
|
||||||
unsigned int m_uMaxGID;
|
unsigned int m_uMaxGID;
|
||||||
CCPoint m_tOffset;
|
CCPoint m_tOffset;
|
||||||
public:
|
public:
|
||||||
CCTMXLayerInfo();
|
CCTMXLayerInfo();
|
||||||
virtual ~CCTMXLayerInfo();
|
virtual ~CCTMXLayerInfo();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief CCTMXTilesetInfo contains the information about the tilesets like:
|
/** @brief CCTMXTilesetInfo contains the information about the tilesets like:
|
||||||
- Tileset name
|
- Tileset name
|
||||||
- Tilset spacing
|
- Tilset spacing
|
||||||
- Tileset margin
|
- Tileset margin
|
||||||
- size of the tiles
|
- size of the tiles
|
||||||
- Image used for the tiles
|
- Image used for the tiles
|
||||||
- Image size
|
- Image size
|
||||||
|
|
||||||
This information is obtained from the TMX file.
|
This information is obtained from the TMX file.
|
||||||
*/
|
*/
|
||||||
class CC_DLL CCTMXTilesetInfo : public CCObject
|
class CC_DLL CCTMXTilesetInfo : public CCObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string m_sName;
|
std::string m_sName;
|
||||||
unsigned int m_uFirstGid;
|
unsigned int m_uFirstGid;
|
||||||
CCSize m_tTileSize;
|
CCSize m_tTileSize;
|
||||||
|
@ -119,28 +119,28 @@ namespace cocos2d {
|
||||||
std::string m_sSourceImage;
|
std::string m_sSourceImage;
|
||||||
//! size in pixels of the image
|
//! size in pixels of the image
|
||||||
CCSize m_tImageSize;
|
CCSize m_tImageSize;
|
||||||
public:
|
public:
|
||||||
CCTMXTilesetInfo();
|
CCTMXTilesetInfo();
|
||||||
virtual ~CCTMXTilesetInfo();
|
virtual ~CCTMXTilesetInfo();
|
||||||
CCRect rectForGID(unsigned int gid);
|
CCRect rectForGID(unsigned int gid);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief CCTMXMapInfo contains the information about the map like:
|
/** @brief CCTMXMapInfo contains the information about the map like:
|
||||||
- Map orientation (hexagonal, isometric or orthogonal)
|
- Map orientation (hexagonal, isometric or orthogonal)
|
||||||
- Tile size
|
- Tile size
|
||||||
- Map size
|
- Map size
|
||||||
|
|
||||||
And it also contains:
|
And it also contains:
|
||||||
- Layers (an array of TMXLayerInfo objects)
|
- Layers (an array of TMXLayerInfo objects)
|
||||||
- Tilesets (an array of TMXTilesetInfo objects)
|
- Tilesets (an array of TMXTilesetInfo objects)
|
||||||
- ObjectGroups (an array of TMXObjectGroupInfo objects)
|
- ObjectGroups (an array of TMXObjectGroupInfo objects)
|
||||||
|
|
||||||
This information is obtained from the TMX file.
|
This information is obtained from the TMX file.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class CC_DLL CCTMXMapInfo : public CCObject, public CCSAXDelegator
|
class CC_DLL CCTMXMapInfo : public CCObject, public CCSAXDelegator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// map orientation
|
/// map orientation
|
||||||
CC_SYNTHESIZE(int, m_nOrientation, Orientation);
|
CC_SYNTHESIZE(int, m_nOrientation, Orientation);
|
||||||
/// map width & height
|
/// map width & height
|
||||||
|
@ -148,11 +148,11 @@ namespace cocos2d {
|
||||||
/// tiles width & height
|
/// tiles width & height
|
||||||
CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tTileSize, TileSize);
|
CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tTileSize, TileSize);
|
||||||
/// Layers
|
/// Layers
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXLayerInfo*>*, m_pLayers, Layers);
|
CC_PROPERTY(CCArray*, m_pLayers, Layers);
|
||||||
/// tilesets
|
/// tilesets
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXTilesetInfo*>*, m_pTilesets, Tilesets);
|
CC_PROPERTY(CCArray*, m_pTilesets, Tilesets);
|
||||||
/// ObjectGroups
|
/// ObjectGroups
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXObjectGroup*>*, m_pObjectGroups, ObjectGroups);
|
CC_PROPERTY(CCArray*, m_pObjectGroups, ObjectGroups);
|
||||||
/// parent element
|
/// parent element
|
||||||
CC_SYNTHESIZE(int, m_nParentElement, ParentElement);
|
CC_SYNTHESIZE(int, m_nParentElement, ParentElement);
|
||||||
/// parent GID
|
/// parent GID
|
||||||
|
@ -162,8 +162,8 @@ namespace cocos2d {
|
||||||
/// is stroing characters?
|
/// is stroing characters?
|
||||||
CC_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters);
|
CC_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters);
|
||||||
/// properties
|
/// properties
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
CCTMXMapInfo();
|
CCTMXMapInfo();
|
||||||
virtual ~CCTMXMapInfo();
|
virtual ~CCTMXMapInfo();
|
||||||
/** creates a TMX Format with a tmx file */
|
/** creates a TMX Format with a tmx file */
|
||||||
|
@ -181,8 +181,8 @@ namespace cocos2d {
|
||||||
/* handles the work of parsing for parseXMLFile: and parseXMLString: */
|
/* handles the work of parsing for parseXMLFile: and parseXMLString: */
|
||||||
bool parseXMLData(const char* data);
|
bool parseXMLData(const char* data);
|
||||||
|
|
||||||
CCDictionary<int, CCStringToStringDictionary*> * getTileProperties();
|
CCDictionary* getTileProperties();
|
||||||
void setTileProperties(CCDictionary<int, CCStringToStringDictionary*> * tileProperties);
|
void setTileProperties(CCDictionary* tileProperties);
|
||||||
|
|
||||||
// implement pure virtual methods of CCSAXDelegator
|
// implement pure virtual methods of CCSAXDelegator
|
||||||
void startElement(void *ctx, const char *name, const char **atts);
|
void startElement(void *ctx, const char *name, const char **atts);
|
||||||
|
@ -193,9 +193,9 @@ namespace cocos2d {
|
||||||
inline void setCurrentString(const char *currentString){ m_sCurrentString = currentString; }
|
inline void setCurrentString(const char *currentString){ m_sCurrentString = currentString; }
|
||||||
inline const char* getTMXFileName(){ return m_sTMXFileName.c_str(); }
|
inline const char* getTMXFileName(){ return m_sTMXFileName.c_str(); }
|
||||||
inline void setTMXFileName(const char *fileName){ m_sTMXFileName = fileName; }
|
inline void setTMXFileName(const char *fileName){ m_sTMXFileName = fileName; }
|
||||||
private:
|
private:
|
||||||
void internalInit(const char* tmxFileName, const char* resourcePath);
|
void internalInit(const char* tmxFileName, const char* resourcePath);
|
||||||
protected:
|
protected:
|
||||||
//! tmx filename
|
//! tmx filename
|
||||||
std::string m_sTMXFileName;
|
std::string m_sTMXFileName;
|
||||||
// tmx resource path
|
// tmx resource path
|
||||||
|
@ -203,10 +203,10 @@ namespace cocos2d {
|
||||||
//! current string
|
//! current string
|
||||||
std::string m_sCurrentString;
|
std::string m_sCurrentString;
|
||||||
//! tile properties
|
//! tile properties
|
||||||
CCDictionary<int, CCStringToStringDictionary*>* m_pTileProperties;
|
CCDictionary* m_pTileProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class CCImage;
|
||||||
class CC_DLL CCTextureCache : public CCObject
|
class CC_DLL CCTextureCache : public CCObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CCMutableDictionary<std::string, CCTexture2D*> * m_pTextures;
|
CCDictionary* m_pTextures;
|
||||||
//pthread_mutex_t *m_pDictLock;
|
//pthread_mutex_t *m_pDictLock;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCTouchDelegateProtocol.h"
|
#include "CCTouchDelegateProtocol.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -146,19 +146,19 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void forceRemoveDelegate(CCTouchDelegate *pDelegate);
|
void forceRemoveDelegate(CCTouchDelegate *pDelegate);
|
||||||
void forceAddHandler(CCTouchHandler *pHandler, CCMutableArray<CCTouchHandler*> *pArray);
|
void forceAddHandler(CCTouchHandler *pHandler, CCArray* pArray);
|
||||||
void forceRemoveAllDelegates(void);
|
void forceRemoveAllDelegates(void);
|
||||||
void rearrangeHandlers(CCMutableArray<CCTouchHandler*> *pArray);
|
void rearrangeHandlers(CCArray* pArray);
|
||||||
CCTouchHandler* findHandler(CCMutableArray<CCTouchHandler*> *pArray, CCTouchDelegate *pDelegate);
|
CCTouchHandler* findHandler(CCArray* pArray, CCTouchDelegate *pDelegate);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CCMutableArray<CCTouchHandler*> *m_pTargetedHandlers;
|
CCArray* m_pTargetedHandlers;
|
||||||
CCMutableArray<CCTouchHandler*> *m_pStandardHandlers;
|
CCArray* m_pStandardHandlers;
|
||||||
|
|
||||||
bool m_bLocked;
|
bool m_bLocked;
|
||||||
bool m_bToAdd;
|
bool m_bToAdd;
|
||||||
bool m_bToRemove;
|
bool m_bToRemove;
|
||||||
CCMutableArray<CCTouchHandler*> *m_pHandlersToAdd;
|
CCArray* m_pHandlersToAdd;
|
||||||
struct _ccCArray *m_pHandlersToRemove;
|
struct _ccCArray *m_pHandlersToRemove;
|
||||||
bool m_bToQuit;
|
bool m_bToQuit;
|
||||||
bool m_bDispatchEvents;
|
bool m_bDispatchEvents;
|
||||||
|
|
|
@ -97,8 +97,8 @@ THE SOFTWARE.
|
||||||
// cocoa includes
|
// cocoa includes
|
||||||
//
|
//
|
||||||
#include "CCSet.h"
|
#include "CCSet.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCZone.h"
|
#include "CCZone.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
|
|
|
@ -38,7 +38,8 @@ CCKeypadDispatcher::CCKeypadDispatcher()
|
||||||
, m_bToAdd(false)
|
, m_bToAdd(false)
|
||||||
, m_bToRemove(false)
|
, m_bToRemove(false)
|
||||||
{
|
{
|
||||||
m_pDelegates = new KeypadDelegateArray;
|
m_pDelegates = CCArray::array();
|
||||||
|
m_pDelegates->retain();
|
||||||
|
|
||||||
m_pHandlersToAdd = ccCArrayNew(8);
|
m_pHandlersToAdd = ccCArrayNew(8);
|
||||||
m_pHandlersToRemove = ccCArrayNew(8);
|
m_pHandlersToRemove = ccCArrayNew(8);
|
||||||
|
@ -124,12 +125,11 @@ void CCKeypadDispatcher::forceAddDelegate(CCKeypadDelegate* pDelegate)
|
||||||
|
|
||||||
void CCKeypadDispatcher::forceRemoveDelegate(CCKeypadDelegate* pDelegate)
|
void CCKeypadDispatcher::forceRemoveDelegate(CCKeypadDelegate* pDelegate)
|
||||||
{
|
{
|
||||||
CCKeypadHandler *pHandler;
|
CCKeypadHandler* pHandler = NULL;
|
||||||
CCMutableArray<CCKeypadHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pDelegates, pObj)
|
||||||
for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCKeypadHandler*)pObj;
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
m_pDelegates->removeObject(pHandler);
|
m_pDelegates->removeObject(pHandler);
|
||||||
|
@ -140,19 +140,19 @@ void CCKeypadDispatcher::forceRemoveDelegate(CCKeypadDelegate* pDelegate)
|
||||||
|
|
||||||
bool CCKeypadDispatcher::dispatchKeypadMSG(ccKeypadMSGType nMsgType)
|
bool CCKeypadDispatcher::dispatchKeypadMSG(ccKeypadMSGType nMsgType)
|
||||||
{
|
{
|
||||||
CCKeypadHandler *pHandler;
|
CCKeypadHandler* pHandler = NULL;
|
||||||
CCKeypadDelegate *pDelegate;
|
CCKeypadDelegate* pDelegate = NULL;
|
||||||
CCMutableArray<CCKeypadHandler*>::CCMutableArrayIterator iter;
|
|
||||||
|
|
||||||
m_bLocked = true;
|
m_bLocked = true;
|
||||||
|
|
||||||
if (m_pDelegates->count() > 0)
|
if (m_pDelegates->count() > 0)
|
||||||
{
|
{
|
||||||
for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pDelegates, pObj)
|
||||||
{
|
{
|
||||||
CC_BREAK_IF(!(*iter));
|
CC_BREAK_IF(!pObj);
|
||||||
|
|
||||||
pHandler = *iter;
|
pHandler = (CCKeypadHandler*)pObj;
|
||||||
pDelegate = pHandler->getDelegate();
|
pDelegate = pHandler->getDelegate();
|
||||||
|
|
||||||
switch (nMsgType)
|
switch (nMsgType)
|
||||||
|
|
|
@ -33,7 +33,7 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
||||||
#include "CCLabelBMFont.h"
|
#include "CCLabelBMFont.h"
|
||||||
|
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCConfiguration.h"
|
#include "CCConfiguration.h"
|
||||||
#include "CCDrawingPrimitives.h"
|
#include "CCDrawingPrimitives.h"
|
||||||
#include "CCSprite.h"
|
#include "CCSprite.h"
|
||||||
|
@ -42,55 +42,55 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "support/data_support/uthash.h"
|
#include "support/data_support/uthash.h"
|
||||||
|
|
||||||
namespace cocos2d{
|
NS_CC_BEGIN
|
||||||
|
|
||||||
//
|
//
|
||||||
//FNTConfig Cache - free functions
|
//FNTConfig Cache - free functions
|
||||||
//
|
//
|
||||||
CCMutableDictionary<std::string, CCBMFontConfiguration*> *configurations = NULL;
|
CCDictionary* configurations = NULL;
|
||||||
CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile)
|
CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile)
|
||||||
{
|
{
|
||||||
CCBMFontConfiguration *pRet = NULL;
|
CCBMFontConfiguration* pRet = NULL;
|
||||||
|
|
||||||
if( configurations == NULL )
|
if( configurations == NULL )
|
||||||
{
|
{
|
||||||
configurations = new CCMutableDictionary<std::string, CCBMFontConfiguration*>();
|
configurations = new CCDictionary();
|
||||||
}
|
}
|
||||||
std::string key(fntFile);
|
|
||||||
pRet = configurations->objectForKey(key);
|
pRet = (CCBMFontConfiguration*)configurations->objectForKey(fntFile);
|
||||||
if( pRet == NULL )
|
if( pRet == NULL )
|
||||||
{
|
{
|
||||||
pRet = CCBMFontConfiguration::configurationWithFNTFile(fntFile);
|
pRet = CCBMFontConfiguration::configurationWithFNTFile(fntFile);
|
||||||
configurations->setObject(pRet, key);
|
configurations->setObject(pRet, fntFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FNTConfigRemoveCache( void )
|
void FNTConfigRemoveCache( void )
|
||||||
{
|
{
|
||||||
if (configurations)
|
if (configurations)
|
||||||
{
|
{
|
||||||
configurations->removeAllObjects();
|
configurations->removeAllObjects();
|
||||||
CC_SAFE_RELEASE_NULL(configurations);
|
CC_SAFE_RELEASE_NULL(configurations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//Hash Element
|
//Hash Element
|
||||||
//
|
//
|
||||||
// Equal function for targetSet.
|
// Equal function for targetSet.
|
||||||
typedef struct _KerningHashElement
|
typedef struct _KerningHashElement
|
||||||
{
|
{
|
||||||
int key; // key for the hash. 16-bit for 1st element, 16-bit for 2nd element
|
int key; // key for the hash. 16-bit for 1st element, 16-bit for 2nd element
|
||||||
int amount;
|
int amount;
|
||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
} tKerningHashElement;
|
} tKerningHashElement;
|
||||||
//
|
//
|
||||||
//BitmapFontConfiguration
|
//BitmapFontConfiguration
|
||||||
//
|
//
|
||||||
|
|
||||||
CCBMFontConfiguration * CCBMFontConfiguration::configurationWithFNTFile(const char *FNTfile)
|
CCBMFontConfiguration * CCBMFontConfiguration::configurationWithFNTFile(const char *FNTfile)
|
||||||
{
|
{
|
||||||
CCBMFontConfiguration * pRet = new CCBMFontConfiguration();
|
CCBMFontConfiguration * pRet = new CCBMFontConfiguration();
|
||||||
if (pRet->initWithFNTfile(FNTfile))
|
if (pRet->initWithFNTfile(FNTfile))
|
||||||
{
|
{
|
||||||
|
@ -99,38 +99,39 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bool CCBMFontConfiguration::initWithFNTfile(const char *FNTfile)
|
|
||||||
{
|
bool CCBMFontConfiguration::initWithFNTfile(const char *FNTfile)
|
||||||
|
{
|
||||||
CCAssert(FNTfile != NULL && strlen(FNTfile)!=0, "");
|
CCAssert(FNTfile != NULL && strlen(FNTfile)!=0, "");
|
||||||
m_pKerningDictionary = NULL;
|
m_pKerningDictionary = NULL;
|
||||||
this->parseConfigFile(FNTfile);
|
this->parseConfigFile(FNTfile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCBMFontConfiguration::CCBMFontConfiguration()
|
CCBMFontConfiguration::CCBMFontConfiguration()
|
||||||
: m_pBitmapFontArray(new std::map<unsigned int, ccBMFontDef>)
|
: m_pBitmapFontArray(new std::map<unsigned int, ccBMFontDef>)
|
||||||
, m_uCommonHeight(0)
|
, m_uCommonHeight(0)
|
||||||
, m_pKerningDictionary(NULL)
|
, m_pKerningDictionary(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCBMFontConfiguration::~CCBMFontConfiguration()
|
CCBMFontConfiguration::~CCBMFontConfiguration()
|
||||||
{
|
{
|
||||||
CCLOGINFO( "cocos2d: deallocing CCBMFontConfiguration" );
|
CCLOGINFO( "cocos2d: deallocing CCBMFontConfiguration" );
|
||||||
CC_SAFE_DELETE(m_pBitmapFontArray);
|
CC_SAFE_DELETE(m_pBitmapFontArray);
|
||||||
this->purgeKerningDictionary();
|
this->purgeKerningDictionary();
|
||||||
m_sAtlasName.clear();
|
m_sAtlasName.clear();
|
||||||
}
|
}
|
||||||
char * CCBMFontConfiguration::description(void)
|
char * CCBMFontConfiguration::description(void)
|
||||||
{
|
{
|
||||||
char *ret = new char[100];
|
char *ret = new char[100];
|
||||||
sprintf(ret, "<CCBMFontConfiguration | Kernings:%d | Image = %s>", HASH_COUNT(m_pKerningDictionary), m_sAtlasName.c_str());
|
sprintf(ret, "<CCBMFontConfiguration | Kernings:%d | Image = %s>", HASH_COUNT(m_pKerningDictionary), m_sAtlasName.c_str());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::purgeKerningDictionary()
|
void CCBMFontConfiguration::purgeKerningDictionary()
|
||||||
{
|
{
|
||||||
tKerningHashElement *current;
|
tKerningHashElement *current;
|
||||||
while(m_pKerningDictionary)
|
while(m_pKerningDictionary)
|
||||||
{
|
{
|
||||||
|
@ -138,9 +139,9 @@ namespace cocos2d{
|
||||||
HASH_DEL(m_pKerningDictionary,current);
|
HASH_DEL(m_pKerningDictionary,current);
|
||||||
free(current);
|
free(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::parseConfigFile(const char *controlFile)
|
void CCBMFontConfiguration::parseConfigFile(const char *controlFile)
|
||||||
{
|
{
|
||||||
std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);
|
std::string fullpath = CCFileUtils::fullPathFromRelativePath(controlFile);
|
||||||
|
|
||||||
CCFileData data(fullpath.c_str(), "rb");
|
CCFileData data(fullpath.c_str(), "rb");
|
||||||
|
@ -212,9 +213,9 @@ namespace cocos2d{
|
||||||
this->parseKerningEntry(line);
|
this->parseKerningEntry(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::parseImageFileName(std::string line, const char *fntFile)
|
void CCBMFontConfiguration::parseImageFileName(std::string line, const char *fntFile)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// line to parse:
|
// line to parse:
|
||||||
// page id=0 file="bitmapFontTest.png"
|
// page id=0 file="bitmapFontTest.png"
|
||||||
|
@ -231,9 +232,9 @@ namespace cocos2d{
|
||||||
value = line.substr(index, index2-index);
|
value = line.substr(index, index2-index);
|
||||||
|
|
||||||
m_sAtlasName = CCFileUtils::fullPathFromRelativeFile(value.c_str(), fntFile);
|
m_sAtlasName = CCFileUtils::fullPathFromRelativeFile(value.c_str(), fntFile);
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::parseInfoArguments(std::string line)
|
void CCBMFontConfiguration::parseInfoArguments(std::string line)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// possible lines to parse:
|
// possible lines to parse:
|
||||||
// info face="Script" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,4,3,2 spacing=0,0 outline=0
|
// info face="Script" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,4,3,2 spacing=0,0 outline=0
|
||||||
|
@ -246,9 +247,9 @@ namespace cocos2d{
|
||||||
std::string value = line.substr(index, index2-index);
|
std::string value = line.substr(index, index2-index);
|
||||||
sscanf(value.c_str(), "padding=%d,%d,%d,%d", &m_tPadding.top, &m_tPadding.right, &m_tPadding.bottom, &m_tPadding.left);
|
sscanf(value.c_str(), "padding=%d,%d,%d,%d", &m_tPadding.top, &m_tPadding.right, &m_tPadding.bottom, &m_tPadding.left);
|
||||||
CCLOG("cocos2d: padding: %d,%d,%d,%d", m_tPadding.left, m_tPadding.top, m_tPadding.right, m_tPadding.bottom);
|
CCLOG("cocos2d: padding: %d,%d,%d,%d", m_tPadding.left, m_tPadding.top, m_tPadding.right, m_tPadding.bottom);
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::parseCommonArguments(std::string line)
|
void CCBMFontConfiguration::parseCommonArguments(std::string line)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// line to parse:
|
// line to parse:
|
||||||
// common lineHeight=104 base=26 scaleW=1024 scaleH=512 pages=1 packed=0
|
// common lineHeight=104 base=26 scaleW=1024 scaleH=512 pages=1 packed=0
|
||||||
|
@ -276,9 +277,9 @@ namespace cocos2d{
|
||||||
CCAssert(atoi(value.c_str()) == 1, "CCBitfontAtlas: only supports 1 page");
|
CCAssert(atoi(value.c_str()) == 1, "CCBitfontAtlas: only supports 1 page");
|
||||||
|
|
||||||
// packed (ignore) What does this mean ??
|
// packed (ignore) What does this mean ??
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::parseCharacterDefinition(std::string line, ccBMFontDef *characterDefinition)
|
void CCBMFontConfiguration::parseCharacterDefinition(std::string line, ccBMFontDef *characterDefinition)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// line to parse:
|
// line to parse:
|
||||||
// char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=44 xadvance=14 page=0 chnl=0
|
// char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=44 xadvance=14 page=0 chnl=0
|
||||||
|
@ -325,9 +326,9 @@ namespace cocos2d{
|
||||||
index2 = line.find(' ', index);
|
index2 = line.find(' ', index);
|
||||||
value = line.substr(index, index2-index);
|
value = line.substr(index, index2-index);
|
||||||
sscanf(value.c_str(), "xadvance=%d", &characterDefinition->xAdvance);
|
sscanf(value.c_str(), "xadvance=%d", &characterDefinition->xAdvance);
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::parseKerningCapacity(std::string line)
|
void CCBMFontConfiguration::parseKerningCapacity(std::string line)
|
||||||
{
|
{
|
||||||
// When using uthash there is not need to parse the capacity.
|
// When using uthash there is not need to parse the capacity.
|
||||||
|
|
||||||
// CCAssert(!kerningDictionary, @"dictionary already initialized");
|
// CCAssert(!kerningDictionary, @"dictionary already initialized");
|
||||||
|
@ -346,9 +347,9 @@ namespace cocos2d{
|
||||||
//
|
//
|
||||||
// if( capacity != -1 )
|
// if( capacity != -1 )
|
||||||
// kerningDictionary = ccHashSetNew(capacity, targetSetEql);
|
// kerningDictionary = ccHashSetNew(capacity, targetSetEql);
|
||||||
}
|
}
|
||||||
void CCBMFontConfiguration::parseKerningEntry(std::string line)
|
void CCBMFontConfiguration::parseKerningEntry(std::string line)
|
||||||
{
|
{
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// line to parse:
|
// line to parse:
|
||||||
// kerning first=121 second=44 amount=-7
|
// kerning first=121 second=44 amount=-7
|
||||||
|
@ -379,20 +380,20 @@ namespace cocos2d{
|
||||||
element->amount = amount;
|
element->amount = amount;
|
||||||
element->key = (first<<16) | (second&0xffff);
|
element->key = (first<<16) | (second&0xffff);
|
||||||
HASH_ADD_INT(m_pKerningDictionary,key, element);
|
HASH_ADD_INT(m_pKerningDictionary,key, element);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//CCLabelBMFont
|
//CCLabelBMFont
|
||||||
//
|
//
|
||||||
|
|
||||||
//LabelBMFont - Purge Cache
|
//LabelBMFont - Purge Cache
|
||||||
void CCLabelBMFont::purgeCachedData()
|
void CCLabelBMFont::purgeCachedData()
|
||||||
{
|
{
|
||||||
FNTConfigRemoveCache();
|
FNTConfigRemoveCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
//LabelBMFont - Creation & Init
|
//LabelBMFont - Creation & Init
|
||||||
CCLabelBMFont *CCLabelBMFont::labelWithString(const char *str, const char *fntFile)
|
CCLabelBMFont *CCLabelBMFont::labelWithString(const char *str, const char *fntFile)
|
||||||
{
|
{
|
||||||
CCLabelBMFont *pRet = new CCLabelBMFont();
|
CCLabelBMFont *pRet = new CCLabelBMFont();
|
||||||
if(pRet && pRet->initWithString(str, fntFile))
|
if(pRet && pRet->initWithString(str, fntFile))
|
||||||
{
|
{
|
||||||
|
@ -401,10 +402,10 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCLabelBMFont::initWithString(const char *theString, const char *fntFile)
|
bool CCLabelBMFont::initWithString(const char *theString, const char *fntFile)
|
||||||
{
|
{
|
||||||
CCAssert(theString != NULL, "");
|
CCAssert(theString != NULL, "");
|
||||||
CC_SAFE_RELEASE(m_pConfiguration);// allow re-init
|
CC_SAFE_RELEASE(m_pConfiguration);// allow re-init
|
||||||
m_pConfiguration = FNTConfigLoadFile(fntFile);
|
m_pConfiguration = FNTConfigLoadFile(fntFile);
|
||||||
|
@ -422,16 +423,16 @@ namespace cocos2d{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CCLabelBMFont::~CCLabelBMFont()
|
CCLabelBMFont::~CCLabelBMFont()
|
||||||
{
|
{
|
||||||
m_sString.clear();
|
m_sString.clear();
|
||||||
CC_SAFE_RELEASE(m_pConfiguration);
|
CC_SAFE_RELEASE(m_pConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelBMFont - Atlas generation
|
// LabelBMFont - Atlas generation
|
||||||
int CCLabelBMFont::kerningAmountForFirst(unsigned short first, unsigned short second)
|
int CCLabelBMFont::kerningAmountForFirst(unsigned short first, unsigned short second)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned int key = (first<<16) | (second & 0xffff);
|
unsigned int key = (first<<16) | (second & 0xffff);
|
||||||
|
|
||||||
|
@ -442,18 +443,18 @@ namespace cocos2d{
|
||||||
ret = element->amount;
|
ret = element->amount;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cc_wcslen(const unsigned short* str)
|
static int cc_wcslen(const unsigned short* str)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
while(*str++) i++;
|
while(*str++) i++;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Code from GLIB gutf8.c starts here. */
|
/* Code from GLIB gutf8.c starts here. */
|
||||||
|
|
||||||
#define UTF8_COMPUTE(Char, Mask, Len) \
|
#define UTF8_COMPUTE(Char, Mask, Len) \
|
||||||
if (Char < 128) \
|
if (Char < 128) \
|
||||||
{ \
|
{ \
|
||||||
Len = 1; \
|
Len = 1; \
|
||||||
|
@ -487,7 +488,7 @@ namespace cocos2d{
|
||||||
else \
|
else \
|
||||||
Len = -1;
|
Len = -1;
|
||||||
|
|
||||||
#define UTF8_LENGTH(Char) \
|
#define UTF8_LENGTH(Char) \
|
||||||
((Char) < 0x80 ? 1 : \
|
((Char) < 0x80 ? 1 : \
|
||||||
((Char) < 0x800 ? 2 : \
|
((Char) < 0x800 ? 2 : \
|
||||||
((Char) < 0x10000 ? 3 : \
|
((Char) < 0x10000 ? 3 : \
|
||||||
|
@ -495,7 +496,7 @@ namespace cocos2d{
|
||||||
((Char) < 0x4000000 ? 5 : 6)))))
|
((Char) < 0x4000000 ? 5 : 6)))))
|
||||||
|
|
||||||
|
|
||||||
#define UTF8_GET(Result, Chars, Count, Mask, Len) \
|
#define UTF8_GET(Result, Chars, Count, Mask, Len) \
|
||||||
(Result) = (Chars)[0] & (Mask); \
|
(Result) = (Chars)[0] & (Mask); \
|
||||||
for ((Count) = 1; (Count) < (Len); ++(Count)) \
|
for ((Count) = 1; (Count) < (Len); ++(Count)) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -508,14 +509,14 @@ namespace cocos2d{
|
||||||
(Result) |= ((Chars)[(Count)] & 0x3f); \
|
(Result) |= ((Chars)[(Count)] & 0x3f); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UNICODE_VALID(Char) \
|
#define UNICODE_VALID(Char) \
|
||||||
((Char) < 0x110000 && \
|
((Char) < 0x110000 && \
|
||||||
(((Char) & 0xFFFFF800) != 0xD800) && \
|
(((Char) & 0xFFFFF800) != 0xD800) && \
|
||||||
((Char) < 0xFDD0 || (Char) > 0xFDEF) && \
|
((Char) < 0xFDD0 || (Char) > 0xFDEF) && \
|
||||||
((Char) & 0xFFFE) != 0xFFFE)
|
((Char) & 0xFFFE) != 0xFFFE)
|
||||||
|
|
||||||
|
|
||||||
static const char utf8_skip_data[256] = {
|
static const char utf8_skip_data[256] = {
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
|
@ -532,13 +533,13 @@ namespace cocos2d{
|
||||||
2, 2, 2, 2, 2, 2, 2,
|
2, 2, 2, 2, 2, 2, 2,
|
||||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5,
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5,
|
||||||
5, 5, 5, 6, 6, 1, 1
|
5, 5, 5, 6, 6, 1, 1
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *const g_utf8_skip = utf8_skip_data;
|
static const char *const g_utf8_skip = utf8_skip_data;
|
||||||
|
|
||||||
#define cc_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(unsigned char *)(p)])
|
#define cc_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(unsigned char *)(p)])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* g_utf8_strlen:
|
* g_utf8_strlen:
|
||||||
* @p: pointer to the start of a UTF-8 encoded string.
|
* @p: pointer to the start of a UTF-8 encoded string.
|
||||||
* @max: the maximum number of bytes to examine. If @max
|
* @max: the maximum number of bytes to examine. If @max
|
||||||
|
@ -550,9 +551,9 @@ namespace cocos2d{
|
||||||
*
|
*
|
||||||
* Return value: the length of the string in characters
|
* Return value: the length of the string in characters
|
||||||
**/
|
**/
|
||||||
static long
|
static long
|
||||||
cc_utf8_strlen (const char * p, int max)
|
cc_utf8_strlen (const char * p, int max)
|
||||||
{
|
{
|
||||||
long len = 0;
|
long len = 0;
|
||||||
const char *start = p;
|
const char *start = p;
|
||||||
|
|
||||||
|
@ -590,9 +591,9 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* g_utf8_get_char:
|
* g_utf8_get_char:
|
||||||
* @p: a pointer to Unicode character encoded as UTF-8
|
* @p: a pointer to Unicode character encoded as UTF-8
|
||||||
*
|
*
|
||||||
|
@ -604,9 +605,9 @@ namespace cocos2d{
|
||||||
*
|
*
|
||||||
* Return value: the resulting character
|
* Return value: the resulting character
|
||||||
**/
|
**/
|
||||||
static unsigned int
|
static unsigned int
|
||||||
cc_utf8_get_char (const char * p)
|
cc_utf8_get_char (const char * p)
|
||||||
{
|
{
|
||||||
int i, mask = 0, len;
|
int i, mask = 0, len;
|
||||||
unsigned int result;
|
unsigned int result;
|
||||||
unsigned char c = (unsigned char) *p;
|
unsigned char c = (unsigned char) *p;
|
||||||
|
@ -617,11 +618,11 @@ namespace cocos2d{
|
||||||
UTF8_GET (result, p, i, mask, len);
|
UTF8_GET (result, p, i, mask, len);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CCLabelBMFont::createFontChars()
|
void CCLabelBMFont::createFontChars()
|
||||||
{
|
{
|
||||||
int nextFontPositionX = 0;
|
int nextFontPositionX = 0;
|
||||||
int nextFontPositionY = 0;
|
int nextFontPositionY = 0;
|
||||||
unsigned short prev = -1;
|
unsigned short prev = -1;
|
||||||
|
@ -744,11 +745,11 @@ namespace cocos2d{
|
||||||
this->setContentSize(tmpSize);
|
this->setContentSize(tmpSize);
|
||||||
|
|
||||||
CC_SAFE_DELETE_ARRAY(pUniStr);
|
CC_SAFE_DELETE_ARRAY(pUniStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//LabelBMFont - CCLabelProtocol protocol
|
//LabelBMFont - CCLabelProtocol protocol
|
||||||
void CCLabelBMFont::setString(const char *newString)
|
void CCLabelBMFont::setString(const char *newString)
|
||||||
{
|
{
|
||||||
m_sString.clear();
|
m_sString.clear();
|
||||||
m_sString = newString;
|
m_sString = newString;
|
||||||
|
|
||||||
|
@ -765,21 +766,21 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->createFontChars();
|
this->createFontChars();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CCLabelBMFont::getString(void)
|
const char* CCLabelBMFont::getString(void)
|
||||||
{
|
{
|
||||||
return m_sString.c_str();
|
return m_sString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCLabelBMFont::setCString(const char *label)
|
void CCLabelBMFont::setCString(const char *label)
|
||||||
{
|
{
|
||||||
setString(label);
|
setString(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
//LabelBMFont - CCRGBAProtocol protocol
|
//LabelBMFont - CCRGBAProtocol protocol
|
||||||
void CCLabelBMFont::setColor(const ccColor3B& var)
|
void CCLabelBMFont::setColor(const ccColor3B& var)
|
||||||
{
|
{
|
||||||
m_tColor = var;
|
m_tColor = var;
|
||||||
if (m_pChildren && m_pChildren->count() != 0)
|
if (m_pChildren && m_pChildren->count() != 0)
|
||||||
{
|
{
|
||||||
|
@ -793,13 +794,13 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const ccColor3B& CCLabelBMFont::getColor()
|
const ccColor3B& CCLabelBMFont::getColor()
|
||||||
{
|
{
|
||||||
return m_tColor;
|
return m_tColor;
|
||||||
}
|
}
|
||||||
void CCLabelBMFont::setOpacity(GLubyte var)
|
void CCLabelBMFont::setOpacity(GLubyte var)
|
||||||
{
|
{
|
||||||
m_cOpacity = var;
|
m_cOpacity = var;
|
||||||
|
|
||||||
if (m_pChildren && m_pChildren->count() != 0)
|
if (m_pChildren && m_pChildren->count() != 0)
|
||||||
|
@ -818,13 +819,13 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GLubyte CCLabelBMFont::getOpacity()
|
GLubyte CCLabelBMFont::getOpacity()
|
||||||
{
|
{
|
||||||
return m_cOpacity;
|
return m_cOpacity;
|
||||||
}
|
}
|
||||||
void CCLabelBMFont::setIsOpacityModifyRGB(bool var)
|
void CCLabelBMFont::setIsOpacityModifyRGB(bool var)
|
||||||
{
|
{
|
||||||
m_bIsOpacityModifyRGB = var;
|
m_bIsOpacityModifyRGB = var;
|
||||||
if (m_pChildren && m_pChildren->count() != 0)
|
if (m_pChildren && m_pChildren->count() != 0)
|
||||||
{
|
{
|
||||||
|
@ -842,26 +843,26 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool CCLabelBMFont::getIsOpacityModifyRGB()
|
bool CCLabelBMFont::getIsOpacityModifyRGB()
|
||||||
{
|
{
|
||||||
return m_bIsOpacityModifyRGB;
|
return m_bIsOpacityModifyRGB;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelBMFont - AnchorPoint
|
// LabelBMFont - AnchorPoint
|
||||||
void CCLabelBMFont::setAnchorPoint(const CCPoint& point)
|
void CCLabelBMFont::setAnchorPoint(const CCPoint& point)
|
||||||
{
|
{
|
||||||
if( ! CCPoint::CCPointEqualToPoint(point, m_tAnchorPoint) )
|
if( ! CCPoint::CCPointEqualToPoint(point, m_tAnchorPoint) )
|
||||||
{
|
{
|
||||||
CCSpriteBatchNode::setAnchorPoint(point);
|
CCSpriteBatchNode::setAnchorPoint(point);
|
||||||
this->createFontChars();
|
this->createFontChars();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//LabelBMFont - Debug draw
|
//LabelBMFont - Debug draw
|
||||||
#if CC_LABELBMFONT_DEBUG_DRAW
|
#if CC_LABELBMFONT_DEBUG_DRAW
|
||||||
void CCLabelBMFont::draw()
|
void CCLabelBMFont::draw()
|
||||||
{
|
{
|
||||||
CCSpriteBatchNode::draw();
|
CCSpriteBatchNode::draw();
|
||||||
const CCSize& s = this->getContentSize();
|
const CCSize& s = this->getContentSize();
|
||||||
CCPoint vertices[4]={
|
CCPoint vertices[4]={
|
||||||
|
@ -869,7 +870,7 @@ namespace cocos2d{
|
||||||
ccp(s.width,s.height),ccp(0,s.height),
|
ccp(s.width,s.height),ccp(0,s.height),
|
||||||
};
|
};
|
||||||
ccDrawPoly(vertices, 4, true);
|
ccDrawPoly(vertices, 4, true);
|
||||||
}
|
}
|
||||||
#endif // CC_LABELBMFONT_DEBUG_DRAW
|
#endif // CC_LABELBMFONT_DEBUG_DRAW
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
|
@ -745,7 +745,8 @@ void CCLayerMultiplex::addLayer(CCLayer* layer)
|
||||||
|
|
||||||
bool CCLayerMultiplex::initWithLayer(CCLayer* layer)
|
bool CCLayerMultiplex::initWithLayer(CCLayer* layer)
|
||||||
{
|
{
|
||||||
m_pLayers = new CCMutableArray<CCLayer*>(1);
|
m_pLayers = CCArray::array();
|
||||||
|
m_pLayers->retain();
|
||||||
m_pLayers->addObject(layer);
|
m_pLayers->addObject(layer);
|
||||||
m_nEnabledLayer = 0;
|
m_nEnabledLayer = 0;
|
||||||
this->addChild(layer);
|
this->addChild(layer);
|
||||||
|
@ -754,8 +755,8 @@ bool CCLayerMultiplex::initWithLayer(CCLayer* layer)
|
||||||
|
|
||||||
bool CCLayerMultiplex::initWithLayers(CCLayer *layer, va_list params)
|
bool CCLayerMultiplex::initWithLayers(CCLayer *layer, va_list params)
|
||||||
{
|
{
|
||||||
m_pLayers = new CCMutableArray<CCLayer*>(5);
|
m_pLayers = CCArray::arrayWithCapacity(5);
|
||||||
//m_pLayers->retain();
|
m_pLayers->retain();
|
||||||
|
|
||||||
m_pLayers->addObject(layer);
|
m_pLayers->addObject(layer);
|
||||||
|
|
||||||
|
@ -766,7 +767,7 @@ bool CCLayerMultiplex::initWithLayers(CCLayer *layer, va_list params)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nEnabledLayer = 0;
|
m_nEnabledLayer = 0;
|
||||||
this->addChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer));
|
this->addChild((CCNode*)m_pLayers->objectAtIndex(m_nEnabledLayer));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -776,24 +777,24 @@ void CCLayerMultiplex::switchTo(unsigned int n)
|
||||||
{
|
{
|
||||||
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
||||||
|
|
||||||
this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true);
|
this->removeChild((CCNode*)m_pLayers->objectAtIndex(m_nEnabledLayer), true);
|
||||||
|
|
||||||
m_nEnabledLayer = n;
|
m_nEnabledLayer = n;
|
||||||
|
|
||||||
this->addChild(m_pLayers->getObjectAtIndex(n));
|
this->addChild((CCNode*)m_pLayers->objectAtIndex(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCLayerMultiplex::switchToAndReleaseMe(unsigned int n)
|
void CCLayerMultiplex::switchToAndReleaseMe(unsigned int n)
|
||||||
{
|
{
|
||||||
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
||||||
|
|
||||||
this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true);
|
this->removeChild((CCNode*)m_pLayers->objectAtIndex(m_nEnabledLayer), true);
|
||||||
|
|
||||||
//[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]];
|
//[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]];
|
||||||
m_pLayers->replaceObjectAtIndex(m_nEnabledLayer, NULL);
|
m_pLayers->replaceObjectAtIndex(m_nEnabledLayer, NULL);
|
||||||
|
|
||||||
m_nEnabledLayer = n;
|
m_nEnabledLayer = n;
|
||||||
|
|
||||||
this->addChild(m_pLayers->getObjectAtIndex(n));
|
this->addChild((CCNode*)m_pLayers->objectAtIndex(n));
|
||||||
}
|
}
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
|
@ -33,72 +33,72 @@ THE SOFTWARE.
|
||||||
#include "CCScriptSupport.h"
|
#include "CCScriptSupport.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
namespace cocos2d{
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static unsigned int _fontSize = kCCItemSize;
|
static unsigned int _fontSize = kCCItemSize;
|
||||||
static std::string _fontName = "Marker Felt";
|
static std::string _fontName = "Marker Felt";
|
||||||
static bool _fontNameRelease = false;
|
static bool _fontNameRelease = false;
|
||||||
|
|
||||||
const unsigned int kCurrentItem = 0xc0c05001;
|
const unsigned int kCurrentItem = 0xc0c05001;
|
||||||
const unsigned int kZoomActionTag = 0xc0c05002;
|
const unsigned int kZoomActionTag = 0xc0c05002;
|
||||||
|
|
||||||
const unsigned int kNormalTag = 0x1;
|
const unsigned int kNormalTag = 0x1;
|
||||||
const unsigned int kSelectedTag = 0x2;
|
const unsigned int kSelectedTag = 0x2;
|
||||||
const unsigned int kDisableTag = 0x3;
|
const unsigned int kDisableTag = 0x3;
|
||||||
//
|
//
|
||||||
// CCMenuItem
|
// CCMenuItem
|
||||||
//
|
//
|
||||||
CCMenuItem * CCMenuItem::itemWithTarget(CCObject *rec, SEL_MenuHandler selector)
|
CCMenuItem * CCMenuItem::itemWithTarget(CCObject *rec, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCMenuItem *pRet = new CCMenuItem();
|
CCMenuItem *pRet = new CCMenuItem();
|
||||||
pRet->initWithTarget(rec, selector);
|
pRet->initWithTarget(rec, selector);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
bool CCMenuItem::initWithTarget(CCObject *rec, SEL_MenuHandler selector)
|
bool CCMenuItem::initWithTarget(CCObject *rec, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
setAnchorPoint(ccp(0.5f, 0.5f));
|
setAnchorPoint(ccp(0.5f, 0.5f));
|
||||||
m_pListener = rec;
|
m_pListener = rec;
|
||||||
m_pfnSelector = selector;
|
m_pfnSelector = selector;
|
||||||
m_bIsEnabled = true;
|
m_bIsEnabled = true;
|
||||||
m_bIsSelected = false;
|
m_bIsSelected = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItem::~CCMenuItem()
|
CCMenuItem::~CCMenuItem()
|
||||||
{
|
{
|
||||||
unregisterScriptHandler();
|
unregisterScriptHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItem::selected()
|
void CCMenuItem::selected()
|
||||||
{
|
{
|
||||||
m_bIsSelected = true;
|
m_bIsSelected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItem::unselected()
|
void CCMenuItem::unselected()
|
||||||
{
|
{
|
||||||
m_bIsSelected = false;
|
m_bIsSelected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItem::registerScriptHandler(int nHandler)
|
void CCMenuItem::registerScriptHandler(int nHandler)
|
||||||
{
|
{
|
||||||
unregisterScriptHandler();
|
unregisterScriptHandler();
|
||||||
m_nScriptHandler = nHandler;
|
m_nScriptHandler = nHandler;
|
||||||
LUALOG("[LUA] Add CCMenuItem script handler: %d", m_nScriptHandler);
|
LUALOG("[LUA] Add CCMenuItem script handler: %d", m_nScriptHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItem::unregisterScriptHandler(void)
|
void CCMenuItem::unregisterScriptHandler(void)
|
||||||
{
|
{
|
||||||
if (m_nScriptHandler)
|
if (m_nScriptHandler)
|
||||||
{
|
{
|
||||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nScriptHandler);
|
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeLuaHandler(m_nScriptHandler);
|
||||||
LUALOG("[LUA] Remove CCMenuItem script handler: %d", m_nScriptHandler);
|
LUALOG("[LUA] Remove CCMenuItem script handler: %d", m_nScriptHandler);
|
||||||
m_nScriptHandler = 0;
|
m_nScriptHandler = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItem::activate()
|
void CCMenuItem::activate()
|
||||||
{
|
{
|
||||||
if (m_bIsEnabled)
|
if (m_bIsEnabled)
|
||||||
{
|
{
|
||||||
if (m_pListener && m_pfnSelector)
|
if (m_pListener && m_pfnSelector)
|
||||||
|
@ -111,53 +111,53 @@ namespace cocos2d{
|
||||||
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, getTag());
|
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeFunctionWithIntegerData(m_nScriptHandler, getTag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItem::setIsEnabled(bool enabled)
|
void CCMenuItem::setIsEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
m_bIsEnabled = enabled;
|
m_bIsEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCMenuItem::getIsEnabled()
|
bool CCMenuItem::getIsEnabled()
|
||||||
{
|
{
|
||||||
return m_bIsEnabled;
|
return m_bIsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCRect CCMenuItem::rect()
|
CCRect CCMenuItem::rect()
|
||||||
{
|
{
|
||||||
return CCRectMake( m_tPosition.x - m_tContentSize.width * m_tAnchorPoint.x,
|
return CCRectMake( m_tPosition.x - m_tContentSize.width * m_tAnchorPoint.x,
|
||||||
m_tPosition.y - m_tContentSize.height * m_tAnchorPoint.y,
|
m_tPosition.y - m_tContentSize.height * m_tAnchorPoint.y,
|
||||||
m_tContentSize.width, m_tContentSize.height);
|
m_tContentSize.width, m_tContentSize.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCMenuItem::getIsSelected()
|
bool CCMenuItem::getIsSelected()
|
||||||
{
|
{
|
||||||
return m_bIsSelected;
|
return m_bIsSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItem::setTarget(CCObject *rec, SEL_MenuHandler selector)
|
void CCMenuItem::setTarget(CCObject *rec, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
m_pListener = rec;
|
m_pListener = rec;
|
||||||
m_pfnSelector = selector;
|
m_pfnSelector = selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//CCMenuItemLabel
|
//CCMenuItemLabel
|
||||||
//
|
//
|
||||||
const ccColor3B& CCMenuItemLabel::getDisabledColor()
|
const ccColor3B& CCMenuItemLabel::getDisabledColor()
|
||||||
{
|
{
|
||||||
return m_tDisabledColor;
|
return m_tDisabledColor;
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::setDisabledColor(const ccColor3B& var)
|
void CCMenuItemLabel::setDisabledColor(const ccColor3B& var)
|
||||||
{
|
{
|
||||||
m_tDisabledColor = var;
|
m_tDisabledColor = var;
|
||||||
}
|
}
|
||||||
CCNode *CCMenuItemLabel::getLabel()
|
CCNode *CCMenuItemLabel::getLabel()
|
||||||
{
|
{
|
||||||
return m_pLabel;
|
return m_pLabel;
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::setLabel(CCNode* var)
|
void CCMenuItemLabel::setLabel(CCNode* var)
|
||||||
{
|
{
|
||||||
if (var)
|
if (var)
|
||||||
{
|
{
|
||||||
addChild(var);
|
addChild(var);
|
||||||
|
@ -171,49 +171,49 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pLabel = var;
|
m_pLabel = var;
|
||||||
}
|
}
|
||||||
CCMenuItemLabel * CCMenuItemLabel::itemWithLabel(CCNode*label, CCObject* target, SEL_MenuHandler selector)
|
CCMenuItemLabel * CCMenuItemLabel::itemWithLabel(CCNode*label, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCMenuItemLabel *pRet = new CCMenuItemLabel();
|
CCMenuItemLabel *pRet = new CCMenuItemLabel();
|
||||||
pRet->initWithLabel(label, target, selector);
|
pRet->initWithLabel(label, target, selector);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
CCMenuItemLabel* CCMenuItemLabel::itemWithLabel(CCNode *label)
|
CCMenuItemLabel* CCMenuItemLabel::itemWithLabel(CCNode *label)
|
||||||
{
|
{
|
||||||
CCMenuItemLabel *pRet = new CCMenuItemLabel();
|
CCMenuItemLabel *pRet = new CCMenuItemLabel();
|
||||||
pRet->initWithLabel(label, NULL, NULL);
|
pRet->initWithLabel(label, NULL, NULL);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
bool CCMenuItemLabel::initWithLabel(CCNode* label, CCObject* target, SEL_MenuHandler selector)
|
bool CCMenuItemLabel::initWithLabel(CCNode* label, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCMenuItem::initWithTarget(target, selector);
|
CCMenuItem::initWithTarget(target, selector);
|
||||||
m_fOriginalScale = 1.0f;
|
m_fOriginalScale = 1.0f;
|
||||||
m_tColorBackup = ccWHITE;
|
m_tColorBackup = ccWHITE;
|
||||||
m_tDisabledColor = ccc3(126,126,126);
|
m_tDisabledColor = ccc3(126,126,126);
|
||||||
this->setLabel(label);
|
this->setLabel(label);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CCMenuItemLabel::~CCMenuItemLabel()
|
CCMenuItemLabel::~CCMenuItemLabel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::setString(const char * label)
|
void CCMenuItemLabel::setString(const char * label)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCLabelProtocol*>(m_pLabel)->setString(label);
|
dynamic_cast<CCLabelProtocol*>(m_pLabel)->setString(label);
|
||||||
this->setContentSize(m_pLabel->getContentSize());
|
this->setContentSize(m_pLabel->getContentSize());
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::activate()
|
void CCMenuItemLabel::activate()
|
||||||
{
|
{
|
||||||
if(m_bIsEnabled)
|
if(m_bIsEnabled)
|
||||||
{
|
{
|
||||||
this->stopAllActions();
|
this->stopAllActions();
|
||||||
this->setScale( m_fOriginalScale );
|
this->setScale( m_fOriginalScale );
|
||||||
CCMenuItem::activate();
|
CCMenuItem::activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::selected()
|
void CCMenuItemLabel::selected()
|
||||||
{
|
{
|
||||||
// subclass to change the default action
|
// subclass to change the default action
|
||||||
if(m_bIsEnabled)
|
if(m_bIsEnabled)
|
||||||
{
|
{
|
||||||
|
@ -233,9 +233,9 @@ namespace cocos2d{
|
||||||
zoomAction->setTag(kZoomActionTag);
|
zoomAction->setTag(kZoomActionTag);
|
||||||
this->runAction(zoomAction);
|
this->runAction(zoomAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::unselected()
|
void CCMenuItemLabel::unselected()
|
||||||
{
|
{
|
||||||
// subclass to change the default action
|
// subclass to change the default action
|
||||||
if(m_bIsEnabled)
|
if(m_bIsEnabled)
|
||||||
{
|
{
|
||||||
|
@ -245,9 +245,9 @@ namespace cocos2d{
|
||||||
zoomAction->setTag(kZoomActionTag);
|
zoomAction->setTag(kZoomActionTag);
|
||||||
this->runAction(zoomAction);
|
this->runAction(zoomAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::setIsEnabled(bool enabled)
|
void CCMenuItemLabel::setIsEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if( m_bIsEnabled != enabled )
|
if( m_bIsEnabled != enabled )
|
||||||
{
|
{
|
||||||
if(enabled == false)
|
if(enabled == false)
|
||||||
|
@ -261,41 +261,41 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CCMenuItem::setIsEnabled(enabled);
|
CCMenuItem::setIsEnabled(enabled);
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::setOpacity(GLubyte opacity)
|
void CCMenuItemLabel::setOpacity(GLubyte opacity)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(m_pLabel)->setOpacity(opacity);
|
dynamic_cast<CCRGBAProtocol*>(m_pLabel)->setOpacity(opacity);
|
||||||
}
|
}
|
||||||
GLubyte CCMenuItemLabel::getOpacity()
|
GLubyte CCMenuItemLabel::getOpacity()
|
||||||
{
|
{
|
||||||
return dynamic_cast<CCRGBAProtocol*>(m_pLabel)->getOpacity();
|
return dynamic_cast<CCRGBAProtocol*>(m_pLabel)->getOpacity();
|
||||||
}
|
}
|
||||||
void CCMenuItemLabel::setColor(const ccColor3B& color)
|
void CCMenuItemLabel::setColor(const ccColor3B& color)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(m_pLabel)->setColor(color);
|
dynamic_cast<CCRGBAProtocol*>(m_pLabel)->setColor(color);
|
||||||
}
|
}
|
||||||
const ccColor3B& CCMenuItemLabel::getColor()
|
const ccColor3B& CCMenuItemLabel::getColor()
|
||||||
{
|
{
|
||||||
return dynamic_cast<CCRGBAProtocol*>(m_pLabel)->getColor();
|
return dynamic_cast<CCRGBAProtocol*>(m_pLabel)->getColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//CCMenuItemAtlasFont
|
//CCMenuItemAtlasFont
|
||||||
//
|
//
|
||||||
CCMenuItemAtlasFont * CCMenuItemAtlasFont::itemWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap)
|
CCMenuItemAtlasFont * CCMenuItemAtlasFont::itemWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap)
|
||||||
{
|
{
|
||||||
return CCMenuItemAtlasFont::itemWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, NULL, NULL);
|
return CCMenuItemAtlasFont::itemWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItemAtlasFont * CCMenuItemAtlasFont::itemWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, CCObject* target, SEL_MenuHandler selector)
|
CCMenuItemAtlasFont * CCMenuItemAtlasFont::itemWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCMenuItemAtlasFont *pRet = new CCMenuItemAtlasFont();
|
CCMenuItemAtlasFont *pRet = new CCMenuItemAtlasFont();
|
||||||
pRet->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
pRet->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
bool CCMenuItemAtlasFont::initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, CCObject* target, SEL_MenuHandler selector)
|
bool CCMenuItemAtlasFont::initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCAssert( value != NULL && strlen(value) != 0, "value length must be greater than 0");
|
CCAssert( value != NULL && strlen(value) != 0, "value length must be greater than 0");
|
||||||
CCLabelAtlas *label = new CCLabelAtlas();
|
CCLabelAtlas *label = new CCLabelAtlas();
|
||||||
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
|
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
|
||||||
|
@ -305,47 +305,47 @@ namespace cocos2d{
|
||||||
// do something ?
|
// do something ?
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//CCMenuItemFont
|
//CCMenuItemFont
|
||||||
//
|
//
|
||||||
void CCMenuItemFont::setFontSize(unsigned int s)
|
void CCMenuItemFont::setFontSize(unsigned int s)
|
||||||
{
|
{
|
||||||
_fontSize = s;
|
_fontSize = s;
|
||||||
}
|
}
|
||||||
unsigned int CCMenuItemFont::fontSize()
|
unsigned int CCMenuItemFont::fontSize()
|
||||||
{
|
{
|
||||||
return _fontSize;
|
return _fontSize;
|
||||||
}
|
}
|
||||||
void CCMenuItemFont::setFontName(const char *name)
|
void CCMenuItemFont::setFontName(const char *name)
|
||||||
{
|
{
|
||||||
if( _fontNameRelease )
|
if( _fontNameRelease )
|
||||||
{
|
{
|
||||||
_fontName.clear();
|
_fontName.clear();
|
||||||
}
|
}
|
||||||
_fontName = name;
|
_fontName = name;
|
||||||
_fontNameRelease = true;
|
_fontNameRelease = true;
|
||||||
}
|
}
|
||||||
const char * CCMenuItemFont::fontName()
|
const char * CCMenuItemFont::fontName()
|
||||||
{
|
{
|
||||||
return _fontName.c_str();
|
return _fontName.c_str();
|
||||||
}
|
}
|
||||||
CCMenuItemFont * CCMenuItemFont::itemWithString(const char *value, CCObject* target, SEL_MenuHandler selector)
|
CCMenuItemFont * CCMenuItemFont::itemWithString(const char *value, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCMenuItemFont *pRet = new CCMenuItemFont();
|
CCMenuItemFont *pRet = new CCMenuItemFont();
|
||||||
pRet->initWithString(value, target, selector);
|
pRet->initWithString(value, target, selector);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
CCMenuItemFont * CCMenuItemFont::itemWithString(const char *value)
|
CCMenuItemFont * CCMenuItemFont::itemWithString(const char *value)
|
||||||
{
|
{
|
||||||
CCMenuItemFont *pRet = new CCMenuItemFont();
|
CCMenuItemFont *pRet = new CCMenuItemFont();
|
||||||
pRet->initWithString(value, NULL, NULL);
|
pRet->initWithString(value, NULL, NULL);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
bool CCMenuItemFont::initWithString(const char *value, CCObject* target, SEL_MenuHandler selector)
|
bool CCMenuItemFont::initWithString(const char *value, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCAssert( value != NULL && strlen(value) != 0, "Value length must be greater than 0");
|
CCAssert( value != NULL && strlen(value) != 0, "Value length must be greater than 0");
|
||||||
|
|
||||||
m_strFontName = _fontName;
|
m_strFontName = _fontName;
|
||||||
|
@ -357,46 +357,46 @@ namespace cocos2d{
|
||||||
// do something ?
|
// do something ?
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemFont::recreateLabel()
|
void CCMenuItemFont::recreateLabel()
|
||||||
{
|
{
|
||||||
CCLabelTTF *label = CCLabelTTF::labelWithString(dynamic_cast<CCLabelProtocol*>(m_pLabel)->getString(),
|
CCLabelTTF *label = CCLabelTTF::labelWithString(dynamic_cast<CCLabelProtocol*>(m_pLabel)->getString(),
|
||||||
m_strFontName.c_str(), (float)m_uFontSize);
|
m_strFontName.c_str(), (float)m_uFontSize);
|
||||||
this->setLabel(label);
|
this->setLabel(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemFont::setFontSizeObj(unsigned int s)
|
void CCMenuItemFont::setFontSizeObj(unsigned int s)
|
||||||
{
|
{
|
||||||
m_uFontSize = s;
|
m_uFontSize = s;
|
||||||
recreateLabel();
|
recreateLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CCMenuItemFont::fontSizeObj()
|
unsigned int CCMenuItemFont::fontSizeObj()
|
||||||
{
|
{
|
||||||
return m_uFontSize;
|
return m_uFontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemFont::setFontNameObj(const char* name)
|
void CCMenuItemFont::setFontNameObj(const char* name)
|
||||||
{
|
{
|
||||||
m_strFontName = name;
|
m_strFontName = name;
|
||||||
recreateLabel();
|
recreateLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CCMenuItemFont::fontNameObj()
|
const char* CCMenuItemFont::fontNameObj()
|
||||||
{
|
{
|
||||||
return m_strFontName.c_str();
|
return m_strFontName.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//CCMenuItemSprite
|
//CCMenuItemSprite
|
||||||
//
|
//
|
||||||
CCNode * CCMenuItemSprite::getNormalImage()
|
CCNode * CCMenuItemSprite::getNormalImage()
|
||||||
{
|
{
|
||||||
return m_pNormalImage;
|
return m_pNormalImage;
|
||||||
}
|
}
|
||||||
void CCMenuItemSprite::setNormalImage(CCNode* var)
|
void CCMenuItemSprite::setNormalImage(CCNode* var)
|
||||||
{
|
{
|
||||||
if (var)
|
if (var)
|
||||||
{
|
{
|
||||||
addChild(var, 0, kNormalTag);
|
addChild(var, 0, kNormalTag);
|
||||||
|
@ -411,13 +411,13 @@ namespace cocos2d{
|
||||||
|
|
||||||
m_pNormalImage = var;
|
m_pNormalImage = var;
|
||||||
this->setContentSize(m_pNormalImage->getContentSize());
|
this->setContentSize(m_pNormalImage->getContentSize());
|
||||||
}
|
}
|
||||||
CCNode * CCMenuItemSprite::getSelectedImage()
|
CCNode * CCMenuItemSprite::getSelectedImage()
|
||||||
{
|
{
|
||||||
return m_pSelectedImage;
|
return m_pSelectedImage;
|
||||||
}
|
}
|
||||||
void CCMenuItemSprite::setSelectedImage(CCNode* var)
|
void CCMenuItemSprite::setSelectedImage(CCNode* var)
|
||||||
{
|
{
|
||||||
if (var)
|
if (var)
|
||||||
{
|
{
|
||||||
addChild(var, 0, kSelectedTag);
|
addChild(var, 0, kSelectedTag);
|
||||||
|
@ -431,13 +431,13 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pSelectedImage = var;
|
m_pSelectedImage = var;
|
||||||
}
|
}
|
||||||
CCNode * CCMenuItemSprite::getDisabledImage()
|
CCNode * CCMenuItemSprite::getDisabledImage()
|
||||||
{
|
{
|
||||||
return m_pDisabledImage;
|
return m_pDisabledImage;
|
||||||
}
|
}
|
||||||
void CCMenuItemSprite::setDisabledImage(CCNode* var)
|
void CCMenuItemSprite::setDisabledImage(CCNode* var)
|
||||||
{
|
{
|
||||||
if (var)
|
if (var)
|
||||||
{
|
{
|
||||||
addChild(var, 0, kDisableTag);
|
addChild(var, 0, kDisableTag);
|
||||||
|
@ -451,12 +451,12 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pDisabledImage = var;
|
m_pDisabledImage = var;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//CCMenuItemSprite - CCRGBAProtocol protocol
|
//CCMenuItemSprite - CCRGBAProtocol protocol
|
||||||
//
|
//
|
||||||
void CCMenuItemSprite::setOpacity(GLubyte opacity)
|
void CCMenuItemSprite::setOpacity(GLubyte opacity)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->setOpacity(opacity);
|
dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->setOpacity(opacity);
|
||||||
|
|
||||||
if (m_pSelectedImage)
|
if (m_pSelectedImage)
|
||||||
|
@ -468,9 +468,9 @@ namespace cocos2d{
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(m_pDisabledImage)->setOpacity(opacity);
|
dynamic_cast<CCRGBAProtocol*>(m_pDisabledImage)->setOpacity(opacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CCMenuItemSprite::setColor(const ccColor3B& color)
|
void CCMenuItemSprite::setColor(const ccColor3B& color)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->setColor(color);
|
dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->setColor(color);
|
||||||
|
|
||||||
if (m_pSelectedImage)
|
if (m_pSelectedImage)
|
||||||
|
@ -482,32 +482,32 @@ namespace cocos2d{
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(m_pDisabledImage)->setColor(color);
|
dynamic_cast<CCRGBAProtocol*>(m_pDisabledImage)->setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GLubyte CCMenuItemSprite::getOpacity()
|
GLubyte CCMenuItemSprite::getOpacity()
|
||||||
{
|
{
|
||||||
return dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->getOpacity();
|
return dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->getOpacity();
|
||||||
}
|
}
|
||||||
const ccColor3B& CCMenuItemSprite::getColor()
|
const ccColor3B& CCMenuItemSprite::getColor()
|
||||||
{
|
{
|
||||||
return dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->getColor();
|
return dynamic_cast<CCRGBAProtocol*>(m_pNormalImage)->getColor();
|
||||||
}
|
}
|
||||||
CCMenuItemSprite * CCMenuItemSprite::itemWithNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite)
|
CCMenuItemSprite * CCMenuItemSprite::itemWithNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite)
|
||||||
{
|
{
|
||||||
return CCMenuItemSprite::itemWithNormalSprite(normalSprite, selectedSprite, disabledSprite, NULL, NULL);
|
return CCMenuItemSprite::itemWithNormalSprite(normalSprite, selectedSprite, disabledSprite, NULL, NULL);
|
||||||
}
|
}
|
||||||
CCMenuItemSprite * CCMenuItemSprite::itemWithNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCObject* target, SEL_MenuHandler selector)
|
CCMenuItemSprite * CCMenuItemSprite::itemWithNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
return CCMenuItemSprite::itemWithNormalSprite(normalSprite, selectedSprite, NULL, target, selector);
|
return CCMenuItemSprite::itemWithNormalSprite(normalSprite, selectedSprite, NULL, target, selector);
|
||||||
}
|
}
|
||||||
CCMenuItemSprite * CCMenuItemSprite::itemWithNormalSprite(CCNode *normalSprite, CCNode *selectedSprite, CCNode *disabledSprite, CCObject *target, SEL_MenuHandler selector)
|
CCMenuItemSprite * CCMenuItemSprite::itemWithNormalSprite(CCNode *normalSprite, CCNode *selectedSprite, CCNode *disabledSprite, CCObject *target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCMenuItemSprite *pRet = new CCMenuItemSprite();
|
CCMenuItemSprite *pRet = new CCMenuItemSprite();
|
||||||
pRet->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
pRet->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
bool CCMenuItemSprite::initWithNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, CCObject* target, SEL_MenuHandler selector)
|
bool CCMenuItemSprite::initWithNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCAssert(normalSprite != NULL, "");
|
CCAssert(normalSprite != NULL, "");
|
||||||
CCMenuItem::initWithTarget(target, selector);
|
CCMenuItem::initWithTarget(target, selector);
|
||||||
setNormalImage(normalSprite);
|
setNormalImage(normalSprite);
|
||||||
|
@ -516,13 +516,13 @@ namespace cocos2d{
|
||||||
|
|
||||||
this->setContentSize(m_pNormalImage->getContentSize());
|
this->setContentSize(m_pNormalImage->getContentSize());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
void CCMenuItemSprite::selected()
|
void CCMenuItemSprite::selected()
|
||||||
{
|
{
|
||||||
CCMenuItem::selected();
|
CCMenuItem::selected();
|
||||||
|
|
||||||
if (m_pDisabledImage)
|
if (m_pDisabledImage)
|
||||||
|
@ -539,10 +539,10 @@ namespace cocos2d{
|
||||||
{
|
{
|
||||||
m_pNormalImage->setIsVisible(true);
|
m_pNormalImage->setIsVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemSprite::unselected()
|
void CCMenuItemSprite::unselected()
|
||||||
{
|
{
|
||||||
CCMenuItem::unselected();
|
CCMenuItem::unselected();
|
||||||
|
|
||||||
m_pNormalImage->setIsVisible(true);
|
m_pNormalImage->setIsVisible(true);
|
||||||
|
@ -556,10 +556,10 @@ namespace cocos2d{
|
||||||
{
|
{
|
||||||
m_pDisabledImage->setIsVisible(false);
|
m_pDisabledImage->setIsVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemSprite::setIsEnabled(bool bEnabled)
|
void CCMenuItemSprite::setIsEnabled(bool bEnabled)
|
||||||
{
|
{
|
||||||
CCMenuItem::setIsEnabled(bEnabled);
|
CCMenuItem::setIsEnabled(bEnabled);
|
||||||
|
|
||||||
if (m_pSelectedImage)
|
if (m_pSelectedImage)
|
||||||
|
@ -588,18 +588,18 @@ namespace cocos2d{
|
||||||
m_pNormalImage->setIsVisible(true);
|
m_pNormalImage->setIsVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage)
|
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage)
|
||||||
{
|
{
|
||||||
return CCMenuItemImage::itemWithNormalImage(normalImage, selectedImage, NULL, NULL, NULL);
|
return CCMenuItemImage::itemWithNormalImage(normalImage, selectedImage, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector)
|
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
return CCMenuItemImage::itemWithNormalImage(normalImage, selectedImage, NULL, target, selector);
|
return CCMenuItemImage::itemWithNormalImage(normalImage, selectedImage, NULL, target, selector);
|
||||||
}
|
}
|
||||||
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector)
|
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCMenuItemImage *pRet = new CCMenuItemImage();
|
CCMenuItemImage *pRet = new CCMenuItemImage();
|
||||||
if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
|
if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
|
||||||
{
|
{
|
||||||
|
@ -608,9 +608,9 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage)
|
CCMenuItemImage * CCMenuItemImage::itemWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage)
|
||||||
{
|
{
|
||||||
CCMenuItemImage *pRet = new CCMenuItemImage();
|
CCMenuItemImage *pRet = new CCMenuItemImage();
|
||||||
if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, NULL, NULL))
|
if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, NULL, NULL))
|
||||||
{
|
{
|
||||||
|
@ -619,9 +619,9 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bool CCMenuItemImage::initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector)
|
bool CCMenuItemImage::initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector)
|
||||||
{
|
{
|
||||||
CCNode *normalSprite = CCSprite::spriteWithFile(normalImage);
|
CCNode *normalSprite = CCSprite::spriteWithFile(normalImage);
|
||||||
CCNode *selectedSprite = NULL;
|
CCNode *selectedSprite = NULL;
|
||||||
CCNode *disabledSprite = NULL;
|
CCNode *disabledSprite = NULL;
|
||||||
|
@ -636,40 +636,41 @@ namespace cocos2d{
|
||||||
disabledSprite = CCSprite::spriteWithFile(disabledImage);
|
disabledSprite = CCSprite::spriteWithFile(disabledImage);
|
||||||
}
|
}
|
||||||
return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// Setter of sprite frames
|
// Setter of sprite frames
|
||||||
//
|
//
|
||||||
void CCMenuItemImage::setNormalSpriteFrame(CCSpriteFrame * frame)
|
void CCMenuItemImage::setNormalSpriteFrame(CCSpriteFrame * frame)
|
||||||
{
|
{
|
||||||
setNormalImage(CCSprite::spriteWithSpriteFrame(frame));
|
setNormalImage(CCSprite::spriteWithSpriteFrame(frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemImage::setSelectedSpriteFrame(CCSpriteFrame * frame)
|
void CCMenuItemImage::setSelectedSpriteFrame(CCSpriteFrame * frame)
|
||||||
{
|
{
|
||||||
setSelectedImage(CCSprite::spriteWithSpriteFrame(frame));
|
setSelectedImage(CCSprite::spriteWithSpriteFrame(frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemImage::setDisabledSpriteFrame(CCSpriteFrame * frame)
|
void CCMenuItemImage::setDisabledSpriteFrame(CCSpriteFrame * frame)
|
||||||
{
|
{
|
||||||
setDisabledImage(CCSprite::spriteWithSpriteFrame(frame));
|
setDisabledImage(CCSprite::spriteWithSpriteFrame(frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// MenuItemToggle
|
// MenuItemToggle
|
||||||
//
|
//
|
||||||
void CCMenuItemToggle::setSubItems(CCMutableArray<CCMenuItem*>* var)
|
void CCMenuItemToggle::setSubItems(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pSubItems);
|
CC_SAFE_RELEASE(m_pSubItems);
|
||||||
m_pSubItems = var;
|
m_pSubItems = var;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCMenuItem*> *CCMenuItemToggle::getSubItems()
|
|
||||||
{
|
CCArray* CCMenuItemToggle::getSubItems()
|
||||||
|
{
|
||||||
return m_pSubItems;
|
return m_pSubItems;
|
||||||
}
|
}
|
||||||
CCMenuItemToggle * CCMenuItemToggle::itemWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...)
|
CCMenuItemToggle * CCMenuItemToggle::itemWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, item);
|
va_start(args, item);
|
||||||
CCMenuItemToggle *pRet = new CCMenuItemToggle();
|
CCMenuItemToggle *pRet = new CCMenuItemToggle();
|
||||||
|
@ -677,11 +678,13 @@ namespace cocos2d{
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
bool CCMenuItemToggle::initWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, va_list args)
|
|
||||||
{
|
bool CCMenuItemToggle::initWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, va_list args)
|
||||||
|
{
|
||||||
CCMenuItem::initWithTarget(target, selector);
|
CCMenuItem::initWithTarget(target, selector);
|
||||||
this->m_pSubItems = new CCMutableArray<CCMenuItem*>();
|
this->m_pSubItems = CCArray::array();
|
||||||
|
this->m_pSubItems->retain();
|
||||||
int z = 0;
|
int z = 0;
|
||||||
CCMenuItem *i = item;
|
CCMenuItem *i = item;
|
||||||
while(i)
|
while(i)
|
||||||
|
@ -693,37 +696,38 @@ namespace cocos2d{
|
||||||
m_uSelectedIndex = UINT_MAX;
|
m_uSelectedIndex = UINT_MAX;
|
||||||
this->setSelectedIndex(0);
|
this->setSelectedIndex(0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItemToggle* CCMenuItemToggle::itemWithItem(CCMenuItem *item)
|
CCMenuItemToggle* CCMenuItemToggle::itemWithItem(CCMenuItem *item)
|
||||||
{
|
{
|
||||||
CCMenuItemToggle *pRet = new CCMenuItemToggle();
|
CCMenuItemToggle *pRet = new CCMenuItemToggle();
|
||||||
pRet->initWithItem(item);
|
pRet->initWithItem(item);
|
||||||
pRet->autorelease();
|
pRet->autorelease();
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCMenuItemToggle::initWithItem(CCMenuItem *item)
|
bool CCMenuItemToggle::initWithItem(CCMenuItem *item)
|
||||||
{
|
{
|
||||||
CCMenuItem::initWithTarget(NULL, NULL);
|
CCMenuItem::initWithTarget(NULL, NULL);
|
||||||
this->m_pSubItems = new CCMutableArray<CCMenuItem*>();
|
this->m_pSubItems = CCArray::array();
|
||||||
|
this->m_pSubItems->retain();
|
||||||
m_pSubItems->addObject(item);
|
m_pSubItems->addObject(item);
|
||||||
m_uSelectedIndex = UINT_MAX;
|
m_uSelectedIndex = UINT_MAX;
|
||||||
this->setSelectedIndex(0);
|
this->setSelectedIndex(0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCMenuItemToggle::addSubItem(CCMenuItem *item)
|
void CCMenuItemToggle::addSubItem(CCMenuItem *item)
|
||||||
{
|
{
|
||||||
m_pSubItems->addObject(item);
|
m_pSubItems->addObject(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItemToggle::~CCMenuItemToggle()
|
CCMenuItemToggle::~CCMenuItemToggle()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(m_pSubItems);
|
CC_SAFE_RELEASE(m_pSubItems);
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::setSelectedIndex(unsigned int index)
|
void CCMenuItemToggle::setSelectedIndex(unsigned int index)
|
||||||
{
|
{
|
||||||
if( index != m_uSelectedIndex )
|
if( index != m_uSelectedIndex )
|
||||||
{
|
{
|
||||||
m_uSelectedIndex = index;
|
m_uSelectedIndex = index;
|
||||||
|
@ -733,29 +737,29 @@ namespace cocos2d{
|
||||||
currentItem->removeFromParentAndCleanup(false);
|
currentItem->removeFromParentAndCleanup(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItem *item = m_pSubItems->getObjectAtIndex(m_uSelectedIndex);
|
CCMenuItem* item = (CCMenuItem*)m_pSubItems->objectAtIndex(m_uSelectedIndex);
|
||||||
this->addChild(item, 0, kCurrentItem);
|
this->addChild(item, 0, kCurrentItem);
|
||||||
const CCSize& s = item->getContentSize();
|
const CCSize& s = item->getContentSize();
|
||||||
this->setContentSize(s);
|
this->setContentSize(s);
|
||||||
item->setPosition( ccp( s.width/2, s.height/2 ) );
|
item->setPosition( ccp( s.width/2, s.height/2 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsigned int CCMenuItemToggle::getSelectedIndex()
|
unsigned int CCMenuItemToggle::getSelectedIndex()
|
||||||
{
|
{
|
||||||
return m_uSelectedIndex;
|
return m_uSelectedIndex;
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::selected()
|
void CCMenuItemToggle::selected()
|
||||||
{
|
{
|
||||||
CCMenuItem::selected();
|
CCMenuItem::selected();
|
||||||
m_pSubItems->getObjectAtIndex(m_uSelectedIndex)->selected();
|
((CCMenuItem*)(m_pSubItems->objectAtIndex(m_uSelectedIndex)))->selected();
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::unselected()
|
void CCMenuItemToggle::unselected()
|
||||||
{
|
{
|
||||||
CCMenuItem::unselected();
|
CCMenuItem::unselected();
|
||||||
m_pSubItems->getObjectAtIndex(m_uSelectedIndex)->unselected();
|
((CCMenuItem*)(m_pSubItems->objectAtIndex(m_uSelectedIndex)))->unselected();
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::activate()
|
void CCMenuItemToggle::activate()
|
||||||
{
|
{
|
||||||
// update index
|
// update index
|
||||||
if( m_bIsEnabled )
|
if( m_bIsEnabled )
|
||||||
{
|
{
|
||||||
|
@ -763,58 +767,62 @@ namespace cocos2d{
|
||||||
this->setSelectedIndex(newIndex);
|
this->setSelectedIndex(newIndex);
|
||||||
}
|
}
|
||||||
CCMenuItem::activate();
|
CCMenuItem::activate();
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::setIsEnabled(bool enabled)
|
void CCMenuItemToggle::setIsEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
CCMenuItem::setIsEnabled(enabled);
|
CCMenuItem::setIsEnabled(enabled);
|
||||||
|
|
||||||
if(m_pSubItems && m_pSubItems->count() > 0)
|
if(m_pSubItems && m_pSubItems->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCMenuItem*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it)
|
CCARRAY_FOREACH(m_pSubItems, pObj)
|
||||||
{
|
{
|
||||||
(*it)->setIsEnabled(enabled);
|
CCMenuItem* pItem = (CCMenuItem*)pObj;
|
||||||
|
pItem->setIsEnabled(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CCMenuItem * CCMenuItemToggle::selectedItem()
|
|
||||||
{
|
CCMenuItem* CCMenuItemToggle::selectedItem()
|
||||||
return m_pSubItems->getObjectAtIndex(m_uSelectedIndex);
|
{
|
||||||
}
|
return (CCMenuItem*)m_pSubItems->objectAtIndex(m_uSelectedIndex);
|
||||||
//
|
}
|
||||||
//CCMenuItemToggle - CCRGBAProtocol protocol
|
//
|
||||||
//
|
//CCMenuItemToggle - CCRGBAProtocol protocol
|
||||||
GLubyte CCMenuItemToggle::getOpacity()
|
//
|
||||||
{
|
GLubyte CCMenuItemToggle::getOpacity()
|
||||||
|
{
|
||||||
return m_cOpacity;
|
return m_cOpacity;
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::setOpacity(GLubyte opacity)
|
void CCMenuItemToggle::setOpacity(GLubyte opacity)
|
||||||
{
|
{
|
||||||
m_cOpacity = opacity;
|
m_cOpacity = opacity;
|
||||||
if(m_pSubItems && m_pSubItems->count() > 0)
|
if(m_pSubItems && m_pSubItems->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCMenuItem*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it)
|
CCARRAY_FOREACH(m_pSubItems, pObj)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(*it)->setOpacity(opacity);
|
CCMenuItem* pItem = (CCMenuItem*)pObj;
|
||||||
|
dynamic_cast<CCRGBAProtocol*>(pItem)->setOpacity(opacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const ccColor3B& CCMenuItemToggle::getColor()
|
const ccColor3B& CCMenuItemToggle::getColor()
|
||||||
{
|
{
|
||||||
return m_tColor;
|
return m_tColor;
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::setColor(const ccColor3B& color)
|
void CCMenuItemToggle::setColor(const ccColor3B& color)
|
||||||
{
|
{
|
||||||
m_tColor = color;
|
m_tColor = color;
|
||||||
if(m_pSubItems && m_pSubItems->count() > 0)
|
if(m_pSubItems && m_pSubItems->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCMenuItem*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it)
|
CCARRAY_FOREACH(m_pSubItems, pObj)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(*it)->setColor(color);
|
CCMenuItem* pItem = (CCMenuItem*)pObj;
|
||||||
}
|
dynamic_cast<CCRGBAProtocol*>(pItem)->setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace cocos2d
|
NS_CC_END
|
||||||
|
|
|
@ -150,7 +150,7 @@ bool CCParticleSystem::initWithFile(const char *plistFile)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
m_sPlistFile = CCFileUtils::fullPathFromRelativePath(plistFile);
|
m_sPlistFile = CCFileUtils::fullPathFromRelativePath(plistFile);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(m_sPlistFile.c_str());
|
CCDictionary *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(m_sPlistFile.c_str());
|
||||||
|
|
||||||
CCAssert( dict != NULL, "Particles: file not found");
|
CCAssert( dict != NULL, "Particles: file not found");
|
||||||
bRet = this->initWithDictionary(dict);
|
bRet = this->initWithDictionary(dict);
|
||||||
|
@ -159,7 +159,7 @@ bool CCParticleSystem::initWithFile(const char *plistFile)
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary)
|
bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = NULL;
|
||||||
|
|
|
@ -52,14 +52,14 @@ typedef enum
|
||||||
class CCDictMaker : public CCSAXDelegator
|
class CCDictMaker : public CCSAXDelegator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCDictionary<std::string, CCObject*> *m_pRootDict;
|
CCDictionary *m_pRootDict;
|
||||||
CCDictionary<std::string, CCObject*> *m_pCurDict;
|
CCDictionary *m_pCurDict;
|
||||||
std::stack<CCDictionary<std::string, CCObject*>*> m_tDictStack;
|
std::stack<CCDictionary*> m_tDictStack;
|
||||||
std::string m_sCurKey;///< parsed key
|
std::string m_sCurKey;///< parsed key
|
||||||
CCSAXState m_tState;
|
CCSAXState m_tState;
|
||||||
CCMutableArray<CCObject*> *m_pArray;
|
CCArray* m_pArray;
|
||||||
|
|
||||||
std::stack<CCMutableArray<CCObject*>*> m_tArrayStack;
|
std::stack<CCArray*> m_tArrayStack;
|
||||||
std::stack<CCSAXState> m_tStateStack;
|
std::stack<CCSAXState> m_tStateStack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary* dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCSAXParser parser;
|
CCSAXParser parser;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public:
|
||||||
std::string sName((char*)name);
|
std::string sName((char*)name);
|
||||||
if( sName == "dict" )
|
if( sName == "dict" )
|
||||||
{
|
{
|
||||||
m_pCurDict = new CCDictionary<std::string, CCObject*>();
|
m_pCurDict = new CCDictionary();
|
||||||
if(! m_pRootDict)
|
if(! m_pRootDict)
|
||||||
{
|
{
|
||||||
// Because it will call m_pCurDict->release() later, so retain here.
|
// Because it will call m_pCurDict->release() later, so retain here.
|
||||||
|
@ -120,8 +120,8 @@ public:
|
||||||
{
|
{
|
||||||
// add the dictionary into the pre dictionary
|
// add the dictionary into the pre dictionary
|
||||||
CCAssert(! m_tDictStack.empty(), "The state is wrong!");
|
CCAssert(! m_tDictStack.empty(), "The state is wrong!");
|
||||||
CCDictionary<std::string, CCObject*>* pPreDict = m_tDictStack.top();
|
CCDictionary* pPreDict = m_tDictStack.top();
|
||||||
pPreDict->setObject(m_pCurDict, m_sCurKey);
|
pPreDict->setObject(m_pCurDict, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pCurDict->release();
|
m_pCurDict->release();
|
||||||
|
@ -149,17 +149,18 @@ public:
|
||||||
else if (sName == "array")
|
else if (sName == "array")
|
||||||
{
|
{
|
||||||
m_tState = SAX_ARRAY;
|
m_tState = SAX_ARRAY;
|
||||||
m_pArray = new CCMutableArray<CCObject*>();
|
m_pArray = CCArray::array();
|
||||||
|
m_pArray->retain();
|
||||||
|
|
||||||
CCSAXState preState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
|
CCSAXState preState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
|
||||||
if (preState == SAX_DICT)
|
if (preState == SAX_DICT)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(m_pArray, m_sCurKey);
|
m_pCurDict->setObject(m_pArray, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
else if (preState == SAX_ARRAY)
|
else if (preState == SAX_ARRAY)
|
||||||
{
|
{
|
||||||
CCAssert(! m_tArrayStack.empty(), "The state is worng!");
|
CCAssert(! m_tArrayStack.empty(), "The state is worng!");
|
||||||
CCMutableArray<CCObject*>* pPreArray = m_tArrayStack.top();
|
CCArray* pPreArray = m_tArrayStack.top();
|
||||||
pPreArray->addObject(m_pArray);
|
pPreArray->addObject(m_pArray);
|
||||||
}
|
}
|
||||||
m_pArray->release();
|
m_pArray->release();
|
||||||
|
@ -205,7 +206,7 @@ public:
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(str, m_sCurKey);
|
m_pCurDict->setObject(str, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
str->release();
|
str->release();
|
||||||
}
|
}
|
||||||
|
@ -218,7 +219,7 @@ public:
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(str, m_sCurKey);
|
m_pCurDict->setObject(str, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
str->release();
|
str->release();
|
||||||
}
|
}
|
||||||
|
@ -254,7 +255,7 @@ public:
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(pText, m_sCurKey);
|
m_pCurDict->setObject(pText, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -287,15 +288,15 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary* CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCDictionary<std::string, CCObject*> *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
CCDictionary* ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
||||||
ret->autorelease();
|
ret->autorelease();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
CCDictionary* CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCDictMaker tMaker;
|
CCDictMaker tMaker;
|
||||||
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
||||||
#define __CC_FILEUTILS_PLATFORM_H__
|
#define __CC_FILEUTILS_PLATFORM_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
@ -87,13 +87,13 @@ public:
|
||||||
@param pFileName The file name of *.plist file
|
@param pFileName The file name of *.plist file
|
||||||
@return The CCDictionary pointer generated from the file
|
@return The CCDictionary pointer generated from the file
|
||||||
*/
|
*/
|
||||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
|
static CCDictionary* dictionaryWithContentsOfFile(const char *pFileName);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@brief The same meaning as dictionaryWithContentsOfFile(), but it doesn't call autorelease, so the
|
@brief The same meaning as dictionaryWithContentsOfFile(), but it doesn't call autorelease, so the
|
||||||
invoker should call release().
|
invoker should call release().
|
||||||
*/
|
*/
|
||||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFileThreadSafe(const char *pFileName);
|
static CCDictionary* dictionaryWithContentsOfFileThreadSafe(const char *pFileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get the writeable path
|
@brief Get the writeable path
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCSAXParser.h"
|
#include "CCSAXParser.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/xmlmemory.h>
|
#include <libxml/xmlmemory.h>
|
||||||
|
|
|
@ -211,6 +211,10 @@
|
||||||
RelativePath="..\cocoa\CCData.cpp"
|
RelativePath="..\cocoa\CCData.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\cocoa\CCDictionary.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\cocoa\CCGeometry.cpp"
|
RelativePath="..\cocoa\CCGeometry.cpp"
|
||||||
>
|
>
|
||||||
|
@ -399,6 +403,10 @@
|
||||||
RelativePath="..\include\CCData.h"
|
RelativePath="..\include\CCData.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\include\CCDictionary.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\include\CCDirector.h"
|
RelativePath="..\include\CCDirector.h"
|
||||||
>
|
>
|
||||||
|
@ -435,6 +443,10 @@
|
||||||
RelativePath="..\include\CCIMEDispatcher.h"
|
RelativePath="..\include\CCIMEDispatcher.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\include\CCInteger.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\include\CCKeypadDelegate.h"
|
RelativePath="..\include\CCKeypadDelegate.h"
|
||||||
>
|
>
|
||||||
|
@ -1100,22 +1112,6 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
|
||||||
Name="gles2"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath="..\gles2\CCGLProgram.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\gles2\ccGLStateCache.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\gles2\CCShaderCache.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="kazmath"
|
Name="kazmath"
|
||||||
>
|
>
|
||||||
|
@ -1251,6 +1247,18 @@
|
||||||
<Filter
|
<Filter
|
||||||
Name="shaders"
|
Name="shaders"
|
||||||
>
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\shaders\CCGLProgram.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\shaders\ccGLStateCache.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\shaders\CCShaderCache.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\shaders\ccShaders.cpp"
|
RelativePath="..\shaders\ccShaders.cpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -64,7 +64,7 @@ CCShaderCache::~CCShaderCache()
|
||||||
|
|
||||||
bool CCShaderCache::init()
|
bool CCShaderCache::init()
|
||||||
{
|
{
|
||||||
m_pPrograms = new CCMutableDictionary<std::string, CCGLProgram*>();
|
m_pPrograms = new CCDictionary();
|
||||||
loadDefaultShaders();
|
loadDefaultShaders();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ void CCShaderCache::loadDefaultShaders()
|
||||||
|
|
||||||
CCGLProgram* CCShaderCache::programForKey(const char* key)
|
CCGLProgram* CCShaderCache::programForKey(const char* key)
|
||||||
{
|
{
|
||||||
return m_pPrograms->objectForKey(key);
|
return (CCGLProgram*)m_pPrograms->objectForKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCShaderCache::addProgram(CCGLProgram* program, const char* key)
|
void CCShaderCache::addProgram(CCGLProgram* program, const char* key)
|
|
@ -40,7 +40,7 @@ CCAnimationFrame::CCAnimationFrame()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimationFrame::initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCObjectDictionary* userInfo)
|
bool CCAnimationFrame::initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCDictionary* userInfo)
|
||||||
{
|
{
|
||||||
setSpriteFrame(spriteFrame);
|
setSpriteFrame(spriteFrame);
|
||||||
setDelayUnits(delayUnits);
|
setDelayUnits(delayUnits);
|
||||||
|
@ -73,7 +73,7 @@ CCObject* CCAnimationFrame::copyWithZone(CCZone* pZone)
|
||||||
}
|
}
|
||||||
|
|
||||||
pCopy->initWithSpriteFrame((CCSpriteFrame*)m_pSpriteFrame->copy()->autorelease(),
|
pCopy->initWithSpriteFrame((CCSpriteFrame*)m_pSpriteFrame->copy()->autorelease(),
|
||||||
m_fDelayUnits, (CCObjectDictionary*)m_pUserInfo->copy()->autorelease());
|
m_fDelayUnits, m_pUserInfo != NULL ? (CCDictionary*)m_pUserInfo->copy()->autorelease() : NULL);
|
||||||
|
|
||||||
CC_SAFE_DELETE(pNewZone);
|
CC_SAFE_DELETE(pNewZone);
|
||||||
return pCopy;
|
return pCopy;
|
||||||
|
@ -90,7 +90,7 @@ CCAnimation* CCAnimation::animation(void)
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *frames)
|
CCAnimation* CCAnimation::animationWithSpriteFrames(CCArray *frames)
|
||||||
{
|
{
|
||||||
CCAnimation *pAnimation = new CCAnimation();
|
CCAnimation *pAnimation = new CCAnimation();
|
||||||
pAnimation->initWithSpriteFrames(frames);
|
pAnimation->initWithSpriteFrames(frames);
|
||||||
|
@ -99,7 +99,7 @@ CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *frames, float delay)
|
CCAnimation* CCAnimation::animationWithSpriteFrames(CCArray *frames, float delay)
|
||||||
{
|
{
|
||||||
CCAnimation *pAnimation = new CCAnimation();
|
CCAnimation *pAnimation = new CCAnimation();
|
||||||
pAnimation->initWithSpriteFrames(frames, delay);
|
pAnimation->initWithSpriteFrames(frames, delay);
|
||||||
|
@ -108,7 +108,7 @@ CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimation::animationWithAnimationFrames(CCMutableArray<CCAnimationFrame*>* arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops)
|
CCAnimation* CCAnimation::animationWithAnimationFrames(CCArray* arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops)
|
||||||
{
|
{
|
||||||
CCAnimation *pAnimation = new CCAnimation();
|
CCAnimation *pAnimation = new CCAnimation();
|
||||||
pAnimation->initWithAnimationFrames(arrayOfSpriteFrameNames, delayPerUnit, loops);
|
pAnimation->initWithAnimationFrames(arrayOfSpriteFrameNames, delayPerUnit, loops);
|
||||||
|
@ -121,24 +121,26 @@ bool CCAnimation::init()
|
||||||
return initWithSpriteFrames(NULL, 0.0f);
|
return initWithSpriteFrames(NULL, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimation::initWithSpriteFrames(CCMutableArray<CCSpriteFrame*>* pFrames)
|
bool CCAnimation::initWithSpriteFrames(CCArray* pFrames)
|
||||||
{
|
{
|
||||||
return initWithSpriteFrames(pFrames, 0.0f);
|
return initWithSpriteFrames(pFrames, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimation::initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames, float delay)
|
bool CCAnimation::initWithSpriteFrames(CCArray *pFrames, float delay)
|
||||||
{
|
{
|
||||||
|
CCARRAY_VERIFY_TYPE(pFrames, CCSpriteFrame*);
|
||||||
|
|
||||||
m_uLoops = 1;
|
m_uLoops = 1;
|
||||||
m_fDelayPerUnit = delay;
|
m_fDelayPerUnit = delay;
|
||||||
CCMutableArray<CCAnimationFrame*>* pTmpFrames = new CCMutableArray<CCAnimationFrame*>();
|
CCArray* pTmpFrames = CCArray::array();
|
||||||
pTmpFrames->autorelease();
|
|
||||||
setFrames(pTmpFrames);
|
setFrames(pTmpFrames);
|
||||||
|
|
||||||
if (pFrames != NULL)
|
if (pFrames != NULL)
|
||||||
{
|
{
|
||||||
for(CCMutableArray<CCSpriteFrame*>::CCMutableArrayIterator it = pFrames->begin(); it != pFrames->end(); ++it)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(pFrames, pObj)
|
||||||
{
|
{
|
||||||
CCSpriteFrame* frame = *it;
|
CCSpriteFrame* frame = (CCSpriteFrame*)pObj;
|
||||||
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
||||||
animFrame->initWithSpriteFrame(frame, 1, NULL);
|
animFrame->initWithSpriteFrame(frame, 1, NULL);
|
||||||
m_pFrames->addObject(animFrame);
|
m_pFrames->addObject(animFrame);
|
||||||
|
@ -151,16 +153,19 @@ bool CCAnimation::initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimation::initWithAnimationFrames(CCMutableArray<CCAnimationFrame*>* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops)
|
bool CCAnimation::initWithAnimationFrames(CCArray* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops)
|
||||||
{
|
{
|
||||||
|
CCARRAY_VERIFY_TYPE(arrayOfAnimationFrames, CCAnimationFrame*);
|
||||||
|
|
||||||
m_fDelayPerUnit = delayPerUnit;
|
m_fDelayPerUnit = delayPerUnit;
|
||||||
m_uLoops = loops;
|
m_uLoops = loops;
|
||||||
|
|
||||||
setFrames(CCMutableArray<CCAnimationFrame*>::arrayWithArray(arrayOfAnimationFrames));
|
setFrames(CCArray::arrayWithArray(arrayOfAnimationFrames));
|
||||||
|
|
||||||
for( CCMutableArray<CCAnimationFrame*>::CCMutableArrayIterator it = m_pFrames->begin(); it != m_pFrames->end(); ++it )
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pFrames, pObj)
|
||||||
{
|
{
|
||||||
CCAnimationFrame *animFrame = *it;
|
CCAnimationFrame* animFrame = (CCAnimationFrame*)pObj;
|
||||||
m_fTotalDelayUnits += animFrame->getDelayUnits();
|
m_fTotalDelayUnits += animFrame->getDelayUnits();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -54,7 +54,7 @@ void CCAnimationCache::purgeSharedAnimationCache(void)
|
||||||
|
|
||||||
bool CCAnimationCache::init()
|
bool CCAnimationCache::init()
|
||||||
{
|
{
|
||||||
m_pAnimations = new CCMutableDictionary<std::string, CCAnimation*>();
|
m_pAnimations = new CCDictionary();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ CCAnimationCache::~CCAnimationCache()
|
||||||
|
|
||||||
void CCAnimationCache::addAnimation(CCAnimation *animation, const char * name)
|
void CCAnimationCache::addAnimation(CCAnimation *animation, const char * name)
|
||||||
{
|
{
|
||||||
m_pAnimations->setObject(animation, std::string(name));
|
m_pAnimations->setObject(animation, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::removeAnimationByName(const char* name)
|
void CCAnimationCache::removeAnimationByName(const char* name)
|
||||||
|
@ -81,41 +81,43 @@ void CCAnimationCache::removeAnimationByName(const char* name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pAnimations->removeObjectForKey(std::string(name));
|
m_pAnimations->removeObjectForKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimationCache::animationByName(const char* name)
|
CCAnimation* CCAnimationCache::animationByName(const char* name)
|
||||||
{
|
{
|
||||||
return m_pAnimations->objectForKey(std::string(name));
|
return (CCAnimation*)m_pAnimations->objectForKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::parseVersion1(CCObjectDictionary* animations)
|
void CCAnimationCache::parseVersion1(CCDictionary* animations)
|
||||||
{
|
{
|
||||||
vector<std::string> animationNames = animations->allKeys();
|
|
||||||
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
||||||
|
|
||||||
for (vector<std::string>::iterator iterName = animationNames.begin(); iterName != animationNames.end(); ++iterName)
|
CCDictElement* pElement = NULL;
|
||||||
|
CCDICT_FOREACH(animations, pElement)
|
||||||
{
|
{
|
||||||
string name = *iterName;
|
CCDictionary* animationDict = (CCDictionary*)pElement->getObject();
|
||||||
CCObjectDictionary* animationDict = (CCObjectDictionary*)animations->objectForKey(name);
|
CCArray* frameNames = (CCArray*)animationDict->objectForKey("frames");
|
||||||
CCMutableArray<CCObject*>* frameNames = (CCMutableArray<CCObject*>*)animationDict->objectForKey("frames");
|
|
||||||
float delay = (float)atof(valueForKey("delay", animationDict));
|
float delay = (float)atof(valueForKey("delay", animationDict));
|
||||||
CCAnimation* animation = NULL;
|
CCAnimation* animation = NULL;
|
||||||
|
|
||||||
if ( frameNames == NULL ) {
|
if ( frameNames == NULL )
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name.c_str());
|
{
|
||||||
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", pElement->getStrKey());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCAnimationFrame*>* frames = new CCMutableArray<CCAnimationFrame*>(frameNames->count());
|
CCArray* frames = CCArray::arrayWithCapacity(frameNames->count());
|
||||||
|
frames->retain();
|
||||||
|
|
||||||
for (CCMutableArray<CCObject*>::CCMutableArrayIterator iterFrameName = frameNames->begin(); iterFrameName != frameNames->end(); ++iterFrameName)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(frameNames, pObj)
|
||||||
{
|
{
|
||||||
const char* frameName = ((CCString*)(*iterFrameName))->toStdString().c_str();
|
const char* frameName = ((CCString*)pObj)->c_str();
|
||||||
CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(frameName);
|
CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(frameName);
|
||||||
|
|
||||||
if ( ! spriteFrame ) {
|
if ( ! spriteFrame ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", name.c_str(), frameName);
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", pElement->getStrKey(), frameName);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -127,57 +129,59 @@ void CCAnimationCache::parseVersion1(CCObjectDictionary* animations)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( frames->count() == 0 ) {
|
if ( frames->count() == 0 ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: None of the frames for animation '%s' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", name.c_str());
|
CCLOG("cocos2d: CCAnimationCache: None of the frames for animation '%s' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", pElement->getStrKey());
|
||||||
continue;
|
continue;
|
||||||
} else if ( frames->count() != frameNames->count() ) {
|
} else if ( frames->count() != frameNames->count() ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", name.c_str());
|
CCLOG("cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", pElement->getStrKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
animation = CCAnimation::animationWithAnimationFrames(frames, delay, 1);
|
animation = CCAnimation::animationWithAnimationFrames(frames, delay, 1);
|
||||||
|
|
||||||
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, name.c_str());
|
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, pElement->getStrKey());
|
||||||
frames->release();
|
frames->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::parseVersion2(CCObjectDictionary* animations)
|
void CCAnimationCache::parseVersion2(CCDictionary* animations)
|
||||||
{
|
{
|
||||||
vector<std::string> animationNames = animations->allKeys();
|
|
||||||
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
||||||
|
|
||||||
for (vector<std::string>::iterator iterName = animationNames.begin(); iterName != animationNames.end(); ++iterName)
|
CCDictElement* pElement = NULL;
|
||||||
|
CCDICT_FOREACH(animations, pElement)
|
||||||
{
|
{
|
||||||
string name = *iterName;
|
const char* name = pElement->getStrKey();
|
||||||
CCObjectDictionary* animationDict = (CCObjectDictionary*)animations->objectForKey(name);
|
CCDictionary* animationDict = (CCDictionary*)pElement->getObject();
|
||||||
|
|
||||||
int loops = atoi(valueForKey("loops", animationDict));
|
int loops = atoi(valueForKey("loops", animationDict));
|
||||||
bool restoreOriginalFrame = atoi(valueForKey("restoreOriginalFrame", animationDict)) == 0 ? false : true;
|
bool restoreOriginalFrame = atoi(valueForKey("restoreOriginalFrame", animationDict)) == 0 ? false : true;
|
||||||
|
|
||||||
CCMutableArray<CCObject*>* frameArray = (CCMutableArray<CCObject*>*)animationDict->objectForKey("frames");
|
CCArray* frameArray = (CCArray*)animationDict->objectForKey("frames");
|
||||||
|
|
||||||
if ( frameArray == NULL ) {
|
if ( frameArray == NULL ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name.c_str());
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array of AnimationFrames
|
// Array of AnimationFrames
|
||||||
CCMutableArray<CCAnimationFrame*>* array = new CCMutableArray<CCAnimationFrame*>(frameArray->count());
|
CCArray* array = CCArray::arrayWithCapacity(frameArray->count());
|
||||||
|
array->retain();
|
||||||
|
|
||||||
for (CCMutableArray<CCObject*>::CCMutableArrayIterator iterFrameName = frameArray->begin(); iterFrameName != frameArray->end(); ++iterFrameName)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(frameArray, pObj)
|
||||||
{
|
{
|
||||||
CCObjectDictionary* entry = (CCObjectDictionary*)(*iterFrameName);
|
CCDictionary* entry = (CCDictionary*)(pObj);
|
||||||
|
|
||||||
const char* spriteFrameName = valueForKey("spriteframe", entry);
|
const char* spriteFrameName = valueForKey("spriteframe", entry);
|
||||||
CCSpriteFrame *spriteFrame = frameCache->spriteFrameByName(spriteFrameName);
|
CCSpriteFrame *spriteFrame = frameCache->spriteFrameByName(spriteFrameName);
|
||||||
|
|
||||||
if( ! spriteFrame ) {
|
if( ! spriteFrame ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", name.c_str(), spriteFrameName);
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", name, spriteFrameName);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float delayUnits = (float)atof(valueForKey("delayUnits", entry));
|
float delayUnits = (float)atof(valueForKey("delayUnits", entry));
|
||||||
CCObjectDictionary* userInfo = (CCObjectDictionary*)entry->objectForKey("notification");
|
CCDictionary* userInfo = (CCDictionary*)entry->objectForKey("notification");
|
||||||
|
|
||||||
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
||||||
animFrame->initWithSpriteFrame(spriteFrame, delayUnits, userInfo);
|
animFrame->initWithSpriteFrame(spriteFrame, delayUnits, userInfo);
|
||||||
|
@ -193,14 +197,14 @@ void CCAnimationCache::parseVersion2(CCObjectDictionary* animations)
|
||||||
|
|
||||||
animation->setRestoreOriginalFrame(restoreOriginalFrame);
|
animation->setRestoreOriginalFrame(restoreOriginalFrame);
|
||||||
|
|
||||||
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, name.c_str());
|
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, name);
|
||||||
animation->release();
|
animation->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::addAnimationsWithDictionary(CCObjectDictionary* dictionary)
|
void CCAnimationCache::addAnimationsWithDictionary(CCDictionary* dictionary)
|
||||||
{
|
{
|
||||||
CCObjectDictionary* animations = (CCObjectDictionary*)dictionary->objectForKey("animations");
|
CCDictionary* animations = (CCDictionary*)dictionary->objectForKey("animations");
|
||||||
|
|
||||||
if ( animations == NULL ) {
|
if ( animations == NULL ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: No animations were found in provided dictionary.");
|
CCLOG("cocos2d: CCAnimationCache: No animations were found in provided dictionary.");
|
||||||
|
@ -208,18 +212,19 @@ void CCAnimationCache::addAnimationsWithDictionary(CCObjectDictionary* dictionar
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int version = 1;
|
unsigned int version = 1;
|
||||||
CCObjectDictionary* properties = (CCObjectDictionary*)dictionary->objectForKey("properties");
|
CCDictionary* properties = (CCDictionary*)dictionary->objectForKey("properties");
|
||||||
if( properties )
|
if( properties )
|
||||||
{
|
{
|
||||||
version = atoi(valueForKey("format", properties));
|
version = atoi(valueForKey("format", properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCObject*>* spritesheets = (CCMutableArray<CCObject*>*)properties->objectForKey("spritesheets");
|
CCArray* spritesheets = (CCArray*)properties->objectForKey("spritesheets");
|
||||||
|
|
||||||
for( CCMutableArray<CCObject*>::CCMutableArrayIterator iterName = spritesheets->begin(); iterName != spritesheets->end(); ++iterName)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(spritesheets, pObj)
|
||||||
{
|
{
|
||||||
CCString* name = (CCString*)(*iterName);
|
CCString* name = (CCString*)(pObj);
|
||||||
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->toStdString().c_str());
|
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (version) {
|
switch (version) {
|
||||||
|
@ -234,11 +239,11 @@ void CCAnimationCache::addAnimationsWithDictionary(CCObjectDictionary* dictionar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * CCAnimationCache::valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict)
|
const char * CCAnimationCache::valueForKey(const char *key, CCDictionary *dict)
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
CCString *pString = (CCString*)dict->objectForKey(std::string(key));
|
CCString *pString = (CCString*)dict->objectForKey(key);
|
||||||
return pString ? pString->m_sString.c_str() : "";
|
return pString ? pString->m_sString.c_str() : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
@ -250,7 +255,7 @@ void CCAnimationCache::addAnimationsWithFile(const char* plist)
|
||||||
CCAssert( plist, "Invalid texture file name");
|
CCAssert( plist, "Invalid texture file name");
|
||||||
|
|
||||||
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
||||||
CCObjectDictionary* dict = CCFileUtils::dictionaryWithContentsOfFile(path);
|
CCDictionary* dict = CCFileUtils::dictionaryWithContentsOfFile(path);
|
||||||
|
|
||||||
CCAssert( dict, "CCAnimationCache: File could not be found");
|
CCAssert( dict, "CCAnimationCache: File could not be found");
|
||||||
|
|
||||||
|
|
|
@ -960,7 +960,7 @@ void CCSprite::setDisplayFrameWithAnimationName(const char *animationName, int f
|
||||||
|
|
||||||
CCAssert(a, "CCSprite#setDisplayFrameWithAnimationName: Frame not found");
|
CCAssert(a, "CCSprite#setDisplayFrameWithAnimationName: Frame not found");
|
||||||
|
|
||||||
CCAnimationFrame *frame = a->getFrames()->getObjectAtIndex(frameIndex);
|
CCAnimationFrame* frame = (CCAnimationFrame*)a->getFrames()->objectAtIndex(frameIndex);
|
||||||
|
|
||||||
CCAssert(frame, "CCSprite#setDisplayFrame. Invalid frame");
|
CCAssert(frame, "CCSprite#setDisplayFrame. Invalid frame");
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,12 @@ THE SOFTWARE.
|
||||||
#include "support/TransformUtils.h"
|
#include "support/TransformUtils.h"
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
|
#include "CCArray.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace cocos2d {
|
using namespace std;
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static CCSpriteFrameCache *pSharedSpriteFrameCache = NULL;
|
static CCSpriteFrameCache *pSharedSpriteFrameCache = NULL;
|
||||||
|
|
||||||
|
@ -58,8 +62,8 @@ void CCSpriteFrameCache::purgeSharedSpriteFrameCache(void)
|
||||||
|
|
||||||
bool CCSpriteFrameCache::init(void)
|
bool CCSpriteFrameCache::init(void)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames= new CCDictionary<std::string, CCSpriteFrame*>();
|
m_pSpriteFrames= new CCDictionary();
|
||||||
m_pSpriteFramesAliases = new CCDictionary<std::string, CCString*>();
|
m_pSpriteFramesAliases = new CCDictionary();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +73,7 @@ CCSpriteFrameCache::~CCSpriteFrameCache(void)
|
||||||
CC_SAFE_RELEASE(m_pSpriteFramesAliases);
|
CC_SAFE_RELEASE(m_pSpriteFramesAliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
|
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary* dictionary, CCTexture2D *pobTexture)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Supported Zwoptex Formats:
|
Supported Zwoptex Formats:
|
||||||
|
@ -80,8 +84,8 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
|
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *metadataDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
|
CCDictionary *metadataDict = (CCDictionary*)dictionary->objectForKey("metadata");
|
||||||
CCDictionary<std::string, CCObject*> *framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
|
CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames");
|
||||||
int format = 0;
|
int format = 0;
|
||||||
|
|
||||||
// get the format
|
// get the format
|
||||||
|
@ -93,12 +97,11 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
// check the format
|
// check the format
|
||||||
CCAssert(format >=0 && format <= 3, "");
|
CCAssert(format >=0 && format <= 3, "");
|
||||||
|
|
||||||
framesDict->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(framesDict, pElement)
|
||||||
CCDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
||||||
while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
|
|
||||||
{
|
{
|
||||||
CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
|
CCDictionary* frameDict = (CCDictionary*)pElement->getObject();
|
||||||
|
CCSpriteFrame* spriteFrame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(pElement->getStrKey());
|
||||||
if (spriteFrame)
|
if (spriteFrame)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -164,19 +167,19 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
|
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
|
||||||
|
|
||||||
// get aliases
|
// get aliases
|
||||||
CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
|
CCArray* aliases = (CCArray*) (frameDict->objectForKey("aliases"));
|
||||||
CCMutableArray<CCString*>::CCMutableArrayIterator iter;
|
CCString * frameKey = new CCString(pElement->getStrKey());
|
||||||
|
|
||||||
CCString * frameKey = new CCString(key.c_str());
|
CCObject* pObj = NULL;
|
||||||
for (iter = aliases->begin(); iter != aliases->end(); ++iter)
|
CCARRAY_FOREACH(aliases, pObj)
|
||||||
{
|
{
|
||||||
std::string oneAlias = ((CCString*) (*iter))->m_sString;
|
std::string oneAlias = ((CCString*)pObj)->m_sString;
|
||||||
if (m_pSpriteFramesAliases->objectForKey(oneAlias))
|
if (m_pSpriteFramesAliases->objectForKey(oneAlias.c_str()))
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pSpriteFramesAliases->setObject(frameKey, oneAlias);
|
m_pSpriteFramesAliases->setObject(frameKey, oneAlias.c_str());
|
||||||
}
|
}
|
||||||
frameKey->release();
|
frameKey->release();
|
||||||
// create frame
|
// create frame
|
||||||
|
@ -189,7 +192,7 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// add sprite frame
|
// add sprite frame
|
||||||
m_pSpriteFrames->setObject(spriteFrame, key);
|
m_pSpriteFrames->setObject(spriteFrame, pElement->getStrKey());
|
||||||
spriteFrame->release();
|
spriteFrame->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +200,7 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
||||||
{
|
{
|
||||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
CCDictionary *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||||
|
|
||||||
addSpriteFramesWithDictionary(dict, pobTexture);
|
addSpriteFramesWithDictionary(dict, pobTexture);
|
||||||
|
|
||||||
|
@ -222,11 +225,11 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char*
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||||
{
|
{
|
||||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
CCDictionary *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||||
|
|
||||||
string texturePath("");
|
string texturePath("");
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*>* metadataDict = (CCDictionary<std::string, CCObject*>*)dict->objectForKey(string("metadata"));
|
CCDictionary* metadataDict = (CCDictionary*)dict->objectForKey("metadata");
|
||||||
if (metadataDict)
|
if (metadataDict)
|
||||||
{
|
{
|
||||||
// try to read texture file name from meta data
|
// try to read texture file name from meta data
|
||||||
|
@ -269,7 +272,7 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||||
|
|
||||||
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->setObject(pobFrame, std::string(pszFrameName));
|
m_pSpriteFrames->setObject(pobFrame, pszFrameName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeSpriteFrames(void)
|
void CCSpriteFrameCache::removeSpriteFrames(void)
|
||||||
|
@ -280,18 +283,16 @@ void CCSpriteFrameCache::removeSpriteFrames(void)
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeUnusedSpriteFrames(void)
|
void CCSpriteFrameCache::removeUnusedSpriteFrames(void)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(m_pSpriteFrames, pElement)
|
||||||
CCSpriteFrame *spriteFrame = NULL;
|
|
||||||
while( (spriteFrame = m_pSpriteFrames->next(&key)) )
|
|
||||||
{
|
{
|
||||||
|
CCSpriteFrame* spriteFrame = (CCSpriteFrame*)pElement->getObject();
|
||||||
if( spriteFrame->retainCount() == 1 )
|
if( spriteFrame->retainCount() == 1 )
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCSpriteFrameCache: removing unused frame: %s", key.c_str());
|
CCLOG("cocos2d: CCSpriteFrameCache: removing unused frame: %s", pElement->getStrKey());
|
||||||
m_pSpriteFrames->removeObjectForKey(key);
|
m_pSpriteFrames->removeObjectForKey(pElement->getStrKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_pSpriteFrames->end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,50 +305,47 @@ void CCSpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is this an alias ?
|
// Is this an alias ?
|
||||||
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(string(pszName));
|
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(pszName);
|
||||||
|
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(key->m_sString);
|
m_pSpriteFrames->removeObjectForKey(key->c_str());
|
||||||
m_pSpriteFramesAliases->removeObjectForKey(key->m_sString);
|
m_pSpriteFramesAliases->removeObjectForKey(key->c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(std::string(pszName));
|
m_pSpriteFrames->removeObjectForKey(pszName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
||||||
{
|
{
|
||||||
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
||||||
CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(path);
|
CCDictionary* dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(path);
|
||||||
|
|
||||||
removeSpriteFramesFromDictionary((CCDictionary<std::string, CCSpriteFrame*>*)dict);
|
removeSpriteFramesFromDictionary((CCDictionary*)dict);
|
||||||
|
|
||||||
dict->release();
|
dict->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary<std::string, CCSpriteFrame*> *dictionary)
|
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary* dictionary)
|
||||||
{
|
{
|
||||||
CCDictionary<std::string, CCObject*>* framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(string("frames"));
|
CCDictionary* framesDict = (CCDictionary*)dictionary->objectForKey("frames");
|
||||||
vector<string> keysToRemove;
|
vector<string> keysToRemove;
|
||||||
|
|
||||||
framesDict->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(framesDict, pElement)
|
||||||
CCDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
||||||
while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
|
|
||||||
{
|
{
|
||||||
if (m_pSpriteFrames->objectForKey(key))
|
if (m_pSpriteFrames->objectForKey(pElement->getStrKey()))
|
||||||
{
|
{
|
||||||
keysToRemove.push_back(key);
|
keysToRemove.push_back(pElement->getStrKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
framesDict->end();
|
|
||||||
|
|
||||||
vector<string>::iterator iter;
|
vector<string>::iterator iter;
|
||||||
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(*iter);
|
m_pSpriteFrames->removeObjectForKey((*iter).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,36 +353,34 @@ void CCSpriteFrameCache::removeSpriteFramesFromTexture(CCTexture2D* texture)
|
||||||
{
|
{
|
||||||
vector<string> keysToRemove;
|
vector<string> keysToRemove;
|
||||||
|
|
||||||
m_pSpriteFrames->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(m_pSpriteFrames, pElement)
|
||||||
CCDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
||||||
while( (frameDict = (CCDictionary<std::string, CCObject*>*)m_pSpriteFrames->next(&key)) )
|
|
||||||
{
|
{
|
||||||
CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(key);
|
string key = pElement->getStrKey();
|
||||||
|
CCSpriteFrame* frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(key.c_str());
|
||||||
if (frame && (frame->getTexture() == texture))
|
if (frame && (frame->getTexture() == texture))
|
||||||
{
|
{
|
||||||
keysToRemove.push_back(key);
|
keysToRemove.push_back(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_pSpriteFrames->end();
|
|
||||||
|
|
||||||
vector<string>::iterator iter;
|
vector<string>::iterator iter;
|
||||||
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(*iter);
|
m_pSpriteFrames->removeObjectForKey((*iter).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
||||||
{
|
{
|
||||||
CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(std::string(pszName));
|
CCSpriteFrame* frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(pszName);
|
||||||
if (! frame)
|
if (!frame)
|
||||||
{
|
{
|
||||||
// try alias dictionary
|
// try alias dictionary
|
||||||
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(string(pszName));
|
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(pszName);
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
frame = m_pSpriteFrames->objectForKey(key->m_sString);
|
frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(key->c_str());
|
||||||
if (! frame)
|
if (! frame)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCSpriteFrameCahce: Frame '%s' not found", pszName);
|
CCLOG("cocos2d: CCSpriteFrameCahce: Frame '%s' not found", pszName);
|
||||||
|
@ -394,13 +390,14 @@ CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * CCSpriteFrameCache::valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict)
|
const char * CCSpriteFrameCache::valueForKey(const char *key, CCDictionary *dict)
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
CCString *pString = (CCString*)dict->objectForKey(std::string(key));
|
CCString *pString = (CCString*)dict->objectForKey(key);
|
||||||
return pString ? pString->m_sString.c_str() : "";
|
return pString ? pString->m_sString.c_str() : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}//namespace cocos2d
|
|
||||||
|
NS_CC_END
|
||||||
|
|
|
@ -25,8 +25,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d
|
NS_CC_BEGIN
|
||||||
{
|
|
||||||
|
|
||||||
CCArray* CCArray::array()
|
CCArray* CCArray::array()
|
||||||
{
|
{
|
||||||
|
@ -158,20 +157,20 @@ void CCArray::insertObject(CCObject* object, unsigned int index)
|
||||||
ccArrayInsertObjectAtIndex(data, object, index);
|
ccArrayInsertObjectAtIndex(data, object, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeLastObject()
|
void CCArray::removeLastObject(bool bReleaseObj)
|
||||||
{
|
{
|
||||||
CCAssert(data->num, "no objects added");
|
CCAssert(data->num, "no objects added");
|
||||||
ccArrayRemoveObjectAtIndex(data, data->num-1);
|
ccArrayRemoveObjectAtIndex(data, data->num-1, bReleaseObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeObject(CCObject* object)
|
void CCArray::removeObject(CCObject* object, bool bReleaseObj/* = true*/)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObject(data, object);
|
ccArrayRemoveObject(data, object, bReleaseObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeObjectAtIndex(unsigned int index)
|
void CCArray::removeObjectAtIndex(unsigned int index, bool bReleaseObj)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObjectAtIndex(data, index);
|
ccArrayRemoveObjectAtIndex(data, index, bReleaseObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeObjectsInArray(CCArray* otherArray)
|
void CCArray::removeObjectsInArray(CCArray* otherArray)
|
||||||
|
@ -242,4 +241,20 @@ CCArray::~CCArray()
|
||||||
ccArrayFree(data);
|
ccArrayFree(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCArray::replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool bReleaseObject/* = true*/)
|
||||||
|
{
|
||||||
|
if (bReleaseObject && uIndex < data->num && data->arr[uIndex] != NULL)
|
||||||
|
{
|
||||||
|
data->arr[uIndex]->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
data->arr[uIndex] = pObject;
|
||||||
|
|
||||||
|
// add the ref
|
||||||
|
if (pObject)
|
||||||
|
{
|
||||||
|
pObject->retain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
|
@ -71,7 +71,7 @@ void CCProfiler::releaseAllTimers()
|
||||||
|
|
||||||
bool CCProfiler::init()
|
bool CCProfiler::init()
|
||||||
{
|
{
|
||||||
m_pActiveTimers = new CCMutableDictionary<std::string, CCProfilingTimer*>();
|
m_pActiveTimers = new CCDictionary();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +82,10 @@ CCProfiler::~CCProfiler(void)
|
||||||
|
|
||||||
void CCProfiler::displayTimers()
|
void CCProfiler::displayTimers()
|
||||||
{
|
{
|
||||||
vector<string> allKeys = m_pActiveTimers->allKeys();
|
CCDictElement* pElement = NULL;
|
||||||
for (vector<string>::iterator it = allKeys.begin(); it != allKeys.end(); ++it)
|
CCDICT_FOREACH(m_pActiveTimers, pElement)
|
||||||
{
|
{
|
||||||
CCProfilingTimer* timer = m_pActiveTimers->objectForKey(*it);
|
CCProfilingTimer* timer = (CCProfilingTimer*)pElement->getObject();
|
||||||
CCLog(timer->description());
|
CCLog(timer->description());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ void CCProfilingTimer::reset()
|
||||||
void CCProfilingBeginTimingBlock(const char *timerName)
|
void CCProfilingBeginTimingBlock(const char *timerName)
|
||||||
{
|
{
|
||||||
CCProfiler* p = CCProfiler::sharedProfiler();
|
CCProfiler* p = CCProfiler::sharedProfiler();
|
||||||
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
|
CCProfilingTimer* timer = (CCProfilingTimer*)p->m_pActiveTimers->objectForKey(timerName);
|
||||||
if( ! timer )
|
if( ! timer )
|
||||||
{
|
{
|
||||||
timer = p->createAndAddTimerWithName(timerName);
|
timer = p->createAndAddTimerWithName(timerName);
|
||||||
|
@ -144,7 +144,7 @@ void CCProfilingBeginTimingBlock(const char *timerName)
|
||||||
void CCProfilingEndTimingBlock(const char *timerName)
|
void CCProfilingEndTimingBlock(const char *timerName)
|
||||||
{
|
{
|
||||||
CCProfiler* p = CCProfiler::sharedProfiler();
|
CCProfiler* p = CCProfiler::sharedProfiler();
|
||||||
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
|
CCProfilingTimer* timer = (CCProfilingTimer*)p->m_pActiveTimers->objectForKey(timerName);
|
||||||
|
|
||||||
CCAssert(timer, "CCProfilingTimer not found");
|
CCAssert(timer, "CCProfilingTimer not found");
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ void CCProfilingEndTimingBlock(const char *timerName)
|
||||||
void CCProfilingResetTimingBlock(const char *timerName)
|
void CCProfilingResetTimingBlock(const char *timerName)
|
||||||
{
|
{
|
||||||
CCProfiler* p = CCProfiler::sharedProfiler();
|
CCProfiler* p = CCProfiler::sharedProfiler();
|
||||||
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
|
CCProfilingTimer *timer = (CCProfilingTimer*)p->m_pActiveTimers->objectForKey(timerName);
|
||||||
|
|
||||||
CCAssert(timer, "CCProfilingTimer not found");
|
CCAssert(timer, "CCProfilingTimer not found");
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
/** releases all timers */
|
/** releases all timers */
|
||||||
void releaseAllTimers();
|
void releaseAllTimers();
|
||||||
|
|
||||||
CCMutableDictionary<std::string, CCProfilingTimer*>* m_pActiveTimers;
|
CCDictionary* m_pActiveTimers;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CCProfilingTimer : public CCObject
|
class CCProfilingTimer : public CCObject
|
||||||
|
|
|
@ -45,7 +45,7 @@ THE SOFTWARE.
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
// Easy integration
|
// Easy integration
|
||||||
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
||||||
|
@ -86,9 +86,7 @@ static inline void ccArrayFree(ccArray *arr)
|
||||||
|
|
||||||
ccArrayRemoveAllObjects(arr);
|
ccArrayRemoveAllObjects(arr);
|
||||||
|
|
||||||
//delete arr->m_pObjectArray;
|
|
||||||
free(arr->arr);
|
free(arr->arr);
|
||||||
|
|
||||||
free(arr);
|
free(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,9 +223,13 @@ static inline void ccArrayRemoveAllObjects(ccArray *arr)
|
||||||
|
|
||||||
/** Removes object at specified index and pushes back all subsequent objects.
|
/** Removes object at specified index and pushes back all subsequent objects.
|
||||||
Behaviour undefined if index outside [0, num-1]. */
|
Behaviour undefined if index outside [0, num-1]. */
|
||||||
static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index)
|
static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj)
|
||||||
{
|
{
|
||||||
|
if (bReleaseObj)
|
||||||
|
{
|
||||||
arr->arr[index]->release();
|
arr->arr[index]->release();
|
||||||
|
}
|
||||||
|
|
||||||
arr->num--;
|
arr->num--;
|
||||||
|
|
||||||
unsigned int remaining = arr->num - index;
|
unsigned int remaining = arr->num - index;
|
||||||
|
@ -252,18 +254,20 @@ static inline void ccArrayFastRemoveObject(ccArray *arr, CCObject* object)
|
||||||
{
|
{
|
||||||
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
||||||
if (index != UINT_MAX)
|
if (index != UINT_MAX)
|
||||||
|
{
|
||||||
ccArrayFastRemoveObjectAtIndex(arr, index);
|
ccArrayFastRemoveObjectAtIndex(arr, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Searches for the first occurance of object and removes it. If object is not
|
/** Searches for the first occurance of object and removes it. If object is not
|
||||||
found the function has no effect. */
|
found the function has no effect. */
|
||||||
static inline void ccArrayRemoveObject(ccArray *arr, CCObject* object)
|
static inline void ccArrayRemoveObject(ccArray *arr, CCObject* object, bool bReleaseObj)
|
||||||
{
|
{
|
||||||
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
||||||
|
|
||||||
if (index != UINT_MAX)
|
if (index != UINT_MAX)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObjectAtIndex(arr, index);
|
ccArrayRemoveObjectAtIndex(arr, index, bReleaseObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +277,7 @@ static inline void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
for( unsigned int i = 0; i < minusArr->num; i++)
|
for( unsigned int i = 0; i < minusArr->num; i++)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
ccArrayRemoveObject(arr, minusArr->arr[i], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +291,7 @@ static inline void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
if( ccArrayContainsObject(minusArr, arr->arr[i]) )
|
if( ccArrayContainsObject(minusArr, arr->arr[i]) )
|
||||||
{
|
{
|
||||||
delete arr->arr[i];
|
arr->arr[i]->release();
|
||||||
back++;
|
back++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -496,6 +500,6 @@ static inline void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||||
arr->num -= back;
|
arr->num -= back;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
||||||
#endif // CC_ARRAY_H
|
#endif // CC_ARRAY_H
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
/****************************************************************************
|
/*
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2003-2010, Troy D. Hanson http://uthash.sourceforge.net
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistributions of source code must retain the above copyright
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
notice, this list of conditions and the following disclaimer.
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||||
all copies or substantial portions of the Software.
|
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
THE SOFTWARE.
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
****************************************************************************/
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
#ifndef __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
||||||
#define __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
#define __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
||||||
|
|
|
@ -41,8 +41,11 @@ THE SOFTWARE.
|
||||||
#include "pthread.h"
|
#include "pthread.h"
|
||||||
#include "CCThread.h"
|
#include "CCThread.h"
|
||||||
#include "semaphore.h"
|
#include "semaphore.h"
|
||||||
|
#include "CCString.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
using namespace std;
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
typedef struct _AsyncStruct
|
typedef struct _AsyncStruct
|
||||||
{
|
{
|
||||||
|
@ -169,7 +172,7 @@ CCTextureCache::CCTextureCache()
|
||||||
{
|
{
|
||||||
CCAssert(g_sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
|
CCAssert(g_sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
|
||||||
|
|
||||||
m_pTextures = new CCMutableDictionary<std::string, CCTexture2D*>();
|
m_pTextures = new CCDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTextureCache::~CCTextureCache()
|
CCTextureCache::~CCTextureCache()
|
||||||
|
@ -205,7 +208,7 @@ void CCTextureCache::addImageAsync(const char *path, CCObject *target, SEL_CallF
|
||||||
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
||||||
|
|
||||||
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
||||||
texture = m_pTextures->objectForKey(pathKey);
|
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
|
||||||
|
|
||||||
std::string fullpath = pathKey;
|
std::string fullpath = pathKey;
|
||||||
if (texture != NULL)
|
if (texture != NULL)
|
||||||
|
@ -326,7 +329,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
||||||
|
|
||||||
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
||||||
texture = m_pTextures->objectForKey(pathKey);
|
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
|
||||||
|
|
||||||
std::string fullpath = pathKey; // (CCFileUtils::fullPathFromRelativePath(path));
|
std::string fullpath = pathKey; // (CCFileUtils::fullPathFromRelativePath(path));
|
||||||
if( ! texture )
|
if( ! texture )
|
||||||
|
@ -362,7 +365,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtJpg);
|
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtJpg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_pTextures->setObject(texture, pathKey);
|
m_pTextures->setObject(texture, pathKey.c_str());
|
||||||
// autorelease prevents possible crash in multithreaded environments
|
// autorelease prevents possible crash in multithreaded environments
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
}
|
}
|
||||||
|
@ -390,7 +393,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtPng);
|
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtPng);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_pTextures->setObject(texture, pathKey);
|
m_pTextures->setObject(texture, pathKey.c_str());
|
||||||
// autorelease prevents possible crash in multithreaded environments
|
// autorelease prevents possible crash in multithreaded environments
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
}
|
}
|
||||||
|
@ -454,7 +457,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
|
||||||
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
||||||
CCFileUtils::ccRemoveHDSuffixFromFile(key);
|
CCFileUtils::ccRemoveHDSuffixFromFile(key);
|
||||||
|
|
||||||
if( (tex = m_pTextures->objectForKey(key)) )
|
if( (tex = (CCTexture2D*)m_pTextures->objectForKey(key.c_str())) )
|
||||||
{
|
{
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +471,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
|
||||||
// cache the texture file name
|
// cache the texture file name
|
||||||
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
|
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
|
||||||
#endif
|
#endif
|
||||||
m_pTextures->setObject(tex, key);
|
m_pTextures->setObject(tex, key.c_str());
|
||||||
tex->autorelease();
|
tex->autorelease();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -497,7 +500,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// If key is nil, then create a new texture each time
|
// If key is nil, then create a new texture each time
|
||||||
if(key && (texture = m_pTextures->objectForKey(forKey)))
|
if(key && (texture = (CCTexture2D *)m_pTextures->objectForKey(forKey.c_str())))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -508,7 +511,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
||||||
|
|
||||||
if(key && texture)
|
if(key && texture)
|
||||||
{
|
{
|
||||||
m_pTextures->setObject(texture, forKey);
|
m_pTextures->setObject(texture, forKey.c_str());
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -530,15 +533,15 @@ void CCTextureCache::removeAllTextures()
|
||||||
|
|
||||||
void CCTextureCache::removeUnusedTextures()
|
void CCTextureCache::removeUnusedTextures()
|
||||||
{
|
{
|
||||||
std::vector<std::string> keys = m_pTextures->allKeys();
|
CCDictElement* pElement = NULL;
|
||||||
std::vector<std::string>::iterator it;
|
CCDICT_FOREACH(m_pTextures, pElement)
|
||||||
for (it = keys.begin(); it != keys.end(); ++it)
|
|
||||||
{
|
{
|
||||||
CCTexture2D *value = m_pTextures->objectForKey(*it);
|
CCLOG("cocos2d: CCTextureCache: texture: %s", pElement->getStrKey());
|
||||||
|
CCTexture2D *value = (CCTexture2D*)pElement->getObject();
|
||||||
if (value->retainCount() == 1)
|
if (value->retainCount() == 1)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", (*it).c_str());
|
CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", pElement->getStrKey());
|
||||||
m_pTextures->removeObjectForKey(*it);
|
m_pTextures->removeObjectForKey(pElement->getStrKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,11 +551,12 @@ void CCTextureCache::removeTexture(CCTexture2D* texture)
|
||||||
if( ! texture )
|
if( ! texture )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<std::string> keys = m_pTextures->allKeysForObject(texture);
|
CCArray* keys = m_pTextures->allKeysForObject(texture);
|
||||||
|
CCObject* pObj;
|
||||||
for (unsigned int i = 0; i < keys.size(); i++)
|
CCARRAY_FOREACH(keys, pObj)
|
||||||
{
|
{
|
||||||
m_pTextures->removeObjectForKey(keys[i]);
|
CCString* pKey = (CCString*)pObj;
|
||||||
|
m_pTextures->removeObjectForKey(pKey->c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,13 +568,12 @@ void CCTextureCache::removeTextureForKey(const char *textureKeyName)
|
||||||
}
|
}
|
||||||
|
|
||||||
string fullPath = CCFileUtils::fullPathFromRelativePath(textureKeyName);
|
string fullPath = CCFileUtils::fullPathFromRelativePath(textureKeyName);
|
||||||
m_pTextures->removeObjectForKey(fullPath);
|
m_pTextures->removeObjectForKey(fullPath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTexture2D* CCTextureCache::textureForKey(const char* key)
|
CCTexture2D* CCTextureCache::textureForKey(const char* key)
|
||||||
{
|
{
|
||||||
std::string strKey = CCFileUtils::fullPathFromRelativePath(key);
|
return (CCTexture2D*)m_pTextures->objectForKey(CCFileUtils::fullPathFromRelativePath(key));
|
||||||
return m_pTextures->objectForKey(strKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureCache::reloadAllTextures()
|
void CCTextureCache::reloadAllTextures()
|
||||||
|
@ -585,18 +588,17 @@ void CCTextureCache::dumpCachedTextureInfo()
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
unsigned int totalBytes = 0;
|
unsigned int totalBytes = 0;
|
||||||
|
|
||||||
vector<string> keys = m_pTextures->allKeys();
|
CCDictElement* pElement = NULL;
|
||||||
vector<string>::iterator iter;
|
CCDICT_FOREACH(m_pTextures, pElement)
|
||||||
for (iter = keys.begin(); iter != keys.end(); iter++)
|
|
||||||
{
|
{
|
||||||
CCTexture2D *tex = m_pTextures->objectForKey(*iter);
|
CCTexture2D* tex = (CCTexture2D*)pElement->getObject();
|
||||||
unsigned int bpp = tex->bitsPerPixelForFormat();
|
unsigned int bpp = tex->bitsPerPixelForFormat();
|
||||||
// Each texture takes up width * height * bytesPerPixel bytes.
|
// Each texture takes up width * height * bytesPerPixel bytes.
|
||||||
unsigned int bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8;
|
unsigned int bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8;
|
||||||
totalBytes += bytes;
|
totalBytes += bytes;
|
||||||
count++;
|
count++;
|
||||||
CCLOG("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
CCLOG("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
||||||
(*iter).c_str(),
|
pElement->getStrKey(),
|
||||||
(long)tex->retainCount(),
|
(long)tex->retainCount(),
|
||||||
(long)tex->getName(),
|
(long)tex->getName(),
|
||||||
(long)tex->getPixelsWide(),
|
(long)tex->getPixelsWide(),
|
||||||
|
@ -797,5 +799,5 @@ void VolatileTexture::reloadAllTextures()
|
||||||
|
|
||||||
#endif // CC_ENABLE_CACHE_TEXTTURE_DATA
|
#endif // CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||||
|
|
||||||
}//namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ namespace cocos2d {
|
||||||
CCPointObject *point = (CCPointObject*)m_pParallaxArray->arr[i];
|
CCPointObject *point = (CCPointObject*)m_pParallaxArray->arr[i];
|
||||||
if( point->getChild()->isEqual(child))
|
if( point->getChild()->isEqual(child))
|
||||||
{
|
{
|
||||||
ccArrayRemoveObjectAtIndex(m_pParallaxArray, i);
|
ccArrayRemoveObjectAtIndex(m_pParallaxArray, i, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ bool CCTMXLayer::initWithTilesetInfo(CCTMXTilesetInfo *tilesetInfo, CCTMXLayerIn
|
||||||
m_uMinGID = layerInfo->m_uMinGID;
|
m_uMinGID = layerInfo->m_uMinGID;
|
||||||
m_uMaxGID = layerInfo->m_uMaxGID;
|
m_uMaxGID = layerInfo->m_uMaxGID;
|
||||||
m_cOpacity = layerInfo->m_cOpacity;
|
m_cOpacity = layerInfo->m_cOpacity;
|
||||||
m_pProperties = CCStringToStringDictionary::dictionaryWithDictionary(layerInfo->getProperties());
|
setProperties(CCDictionary::dictionaryWithDictionary(layerInfo->getProperties()));
|
||||||
m_fContentScaleFactor = CCDirector::sharedDirector()->getContentScaleFactor();
|
m_fContentScaleFactor = CCDirector::sharedDirector()->getContentScaleFactor();
|
||||||
|
|
||||||
// tilesetInfo
|
// tilesetInfo
|
||||||
|
@ -194,10 +194,11 @@ void CCTMXLayer::setupTiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CCTMXLayer - Properties
|
// CCTMXLayer - Properties
|
||||||
CCString *CCTMXLayer::propertyNamed(const char *propertyName)
|
CCString* CCTMXLayer::propertyNamed(const char *propertyName)
|
||||||
{
|
{
|
||||||
return m_pProperties->objectForKey(std::string(propertyName));
|
return (CCString*)m_pProperties->objectForKey(propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXLayer::parseInternalProperties()
|
void CCTMXLayer::parseInternalProperties()
|
||||||
{
|
{
|
||||||
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
||||||
|
@ -674,11 +675,11 @@ int CCTMXLayer::vertexZForPos(const CCPoint& pos)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCStringToStringDictionary * CCTMXLayer::getProperties()
|
CCDictionary * CCTMXLayer::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXLayer::setProperties(CCStringToStringDictionary* var)
|
void CCTMXLayer::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
|
|
|
@ -26,64 +26,67 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "CCTMXObjectGroup.h"
|
#include "CCTMXObjectGroup.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
namespace cocos2d {
|
|
||||||
|
|
||||||
//implementation CCTMXObjectGroup
|
NS_CC_BEGIN
|
||||||
|
|
||||||
CCTMXObjectGroup::CCTMXObjectGroup()
|
//implementation CCTMXObjectGroup
|
||||||
|
|
||||||
|
CCTMXObjectGroup::CCTMXObjectGroup()
|
||||||
:m_tPositionOffset(CCPointZero)
|
:m_tPositionOffset(CCPointZero)
|
||||||
,m_sGroupName("")
|
,m_sGroupName("")
|
||||||
{
|
{
|
||||||
m_pObjects = new CCMutableArray<CCStringToStringDictionary*>();
|
m_pObjects = CCArray::array();
|
||||||
m_pProperties = new CCStringToStringDictionary();
|
m_pObjects->retain();
|
||||||
}
|
m_pProperties = new CCDictionary();
|
||||||
CCTMXObjectGroup::~CCTMXObjectGroup()
|
}
|
||||||
{
|
CCTMXObjectGroup::~CCTMXObjectGroup()
|
||||||
|
{
|
||||||
CCLOGINFO( "cocos2d: deallocing.");
|
CCLOGINFO( "cocos2d: deallocing.");
|
||||||
CC_SAFE_RELEASE(m_pObjects);
|
CC_SAFE_RELEASE(m_pObjects);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
}
|
}
|
||||||
CCStringToStringDictionary * CCTMXObjectGroup::objectNamed(const char *objectName)
|
CCDictionary* CCTMXObjectGroup::objectNamed(const char *objectName)
|
||||||
{
|
{
|
||||||
if (m_pObjects && m_pObjects->count() > 0)
|
if (m_pObjects && m_pObjects->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for (it = m_pObjects->begin(); it != m_pObjects->end(); ++it)
|
CCARRAY_FOREACH(m_pObjects, pObj)
|
||||||
{
|
{
|
||||||
CCString *name = (*it)->objectForKey(std::string("name"));
|
CCDictionary* pDict = (CCDictionary*)pObj;
|
||||||
|
CCString *name = (CCString*)pDict->objectForKey("name");
|
||||||
if (name && name->m_sString == objectName)
|
if (name && name->m_sString == objectName)
|
||||||
{
|
{
|
||||||
return *it;
|
return pDict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// object not found
|
// object not found
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
CCString *CCTMXObjectGroup::propertyNamed(const char* propertyName)
|
CCString* CCTMXObjectGroup::propertyNamed(const char* propertyName)
|
||||||
{
|
{
|
||||||
return m_pProperties->objectForKey(std::string(propertyName));
|
return (CCString*)m_pProperties->objectForKey(propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCStringToStringDictionary * CCTMXObjectGroup::getProperties()
|
CCDictionary* CCTMXObjectGroup::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXObjectGroup::setProperties(CCStringToStringDictionary * properties)
|
void CCTMXObjectGroup::setProperties(CCDictionary * properties)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(properties);
|
CC_SAFE_RETAIN(properties);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
m_pProperties = properties;
|
m_pProperties = properties;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCStringToStringDictionary*> *CCTMXObjectGroup::getObjects()
|
CCArray* CCTMXObjectGroup::getObjects()
|
||||||
{
|
{
|
||||||
return m_pObjects;
|
return m_pObjects;
|
||||||
}
|
}
|
||||||
void CCTMXObjectGroup::setObjects(CCMutableArray<CCStringToStringDictionary*> * objects)
|
void CCTMXObjectGroup::setObjects(CCArray* objects)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(objects);
|
CC_SAFE_RETAIN(objects);
|
||||||
CC_SAFE_RELEASE(m_pObjects);
|
CC_SAFE_RELEASE(m_pObjects);
|
||||||
m_pObjects = objects;
|
m_pObjects = objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace cocos2d
|
NS_CC_END
|
||||||
|
|
|
@ -101,24 +101,24 @@ CCTMXTiledMap::~CCTMXTiledMap()
|
||||||
CC_SAFE_RELEASE(m_pTileProperties);
|
CC_SAFE_RELEASE(m_pTileProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCTMXObjectGroup*> * CCTMXTiledMap::getObjectGroups()
|
CCArray* CCTMXTiledMap::getObjectGroups()
|
||||||
{
|
{
|
||||||
return m_pObjectGroups;
|
return m_pObjectGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXTiledMap::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
|
void CCTMXTiledMap::setObjectGroups(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pObjectGroups);
|
CC_SAFE_RELEASE(m_pObjectGroups);
|
||||||
m_pObjectGroups = var;
|
m_pObjectGroups = var;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCStringToStringDictionary * CCTMXTiledMap::getProperties()
|
CCDictionary * CCTMXTiledMap::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXTiledMap::setProperties(CCStringToStringDictionary* var)
|
void CCTMXTiledMap::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
|
@ -141,14 +141,14 @@ CCTMXLayer * CCTMXTiledMap::parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *
|
||||||
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
|
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
|
||||||
{
|
{
|
||||||
CCSize size = layerInfo->m_tLayerSize;
|
CCSize size = layerInfo->m_tLayerSize;
|
||||||
CCMutableArray<CCTMXTilesetInfo*>* tilesets = mapInfo->getTilesets();
|
CCArray* tilesets = mapInfo->getTilesets();
|
||||||
if (tilesets && tilesets->count()>0)
|
if (tilesets && tilesets->count()>0)
|
||||||
{
|
{
|
||||||
CCTMXTilesetInfo *tileset = NULL;
|
CCTMXTilesetInfo* tileset = NULL;
|
||||||
CCMutableArray<CCTMXTilesetInfo*>::CCMutableArrayRevIterator rit;
|
CCObject* pObj = NULL;
|
||||||
for (rit = tilesets->rbegin(); rit != tilesets->rend(); ++rit)
|
CCARRAY_FOREACH_REVERSE(tilesets, pObj);
|
||||||
{
|
{
|
||||||
tileset = *rit;
|
tileset = (CCTMXTilesetInfo*)pObj;
|
||||||
if (tileset)
|
if (tileset)
|
||||||
{
|
{
|
||||||
for( unsigned int y=0; y < size.height; y++ )
|
for( unsigned int y=0; y < size.height; y++ )
|
||||||
|
@ -179,7 +179,7 @@ CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCT
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all the tiles are 0, return empty tileset
|
// If all the tiles are 0, return empty tileset
|
||||||
CCLOG("cocos2d: Warning: TMX Layer '%@' has no tiles", layerInfo->m_sName.c_str());
|
CCLOG("cocos2d: Warning: TMX Layer '%s' has no tiles", layerInfo->m_sName.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,14 +203,14 @@ void CCTMXTiledMap::buildWithMapInfo(CCTMXMapInfo* mapInfo)
|
||||||
|
|
||||||
int idx=0;
|
int idx=0;
|
||||||
|
|
||||||
CCMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
|
CCArray* layers = mapInfo->getLayers();
|
||||||
if (layers && layers->count()>0)
|
if (layers && layers->count()>0)
|
||||||
{
|
{
|
||||||
CCTMXLayerInfo *layerInfo = NULL;
|
CCTMXLayerInfo* layerInfo = NULL;
|
||||||
CCMutableArray<CCTMXLayerInfo*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for (it = layers->begin(); it != layers->end(); ++it)
|
CCARRAY_FOREACH(layers, pObj)
|
||||||
{
|
{
|
||||||
layerInfo = *it;
|
layerInfo = (CCTMXLayerInfo*)pObj;
|
||||||
if (layerInfo && layerInfo->m_bVisible)
|
if (layerInfo && layerInfo->m_bVisible)
|
||||||
{
|
{
|
||||||
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
|
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||||
|
@ -257,11 +257,11 @@ CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName)
|
||||||
std::string sGroupName = groupName;
|
std::string sGroupName = groupName;
|
||||||
if (m_pObjectGroups && m_pObjectGroups->count()>0)
|
if (m_pObjectGroups && m_pObjectGroups->count()>0)
|
||||||
{
|
{
|
||||||
CCTMXObjectGroup *objectGroup;
|
CCTMXObjectGroup* objectGroup = NULL;
|
||||||
CCMutableArray<CCTMXObjectGroup*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for (it = m_pObjectGroups->begin(); it != m_pObjectGroups->end(); ++it)
|
CCARRAY_FOREACH(m_pObjectGroups, pObj)
|
||||||
{
|
{
|
||||||
objectGroup = (CCTMXObjectGroup*)(*it);
|
objectGroup = (CCTMXObjectGroup*)(pObj);
|
||||||
if (objectGroup && objectGroup->getGroupName() == sGroupName)
|
if (objectGroup && objectGroup->getGroupName() == sGroupName)
|
||||||
{
|
{
|
||||||
return objectGroup;
|
return objectGroup;
|
||||||
|
@ -273,13 +273,14 @@ CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCString * CCTMXTiledMap::propertyNamed(const char *propertyName)
|
CCString* CCTMXTiledMap::propertyNamed(const char *propertyName)
|
||||||
{
|
{
|
||||||
return m_pProperties->objectForKey(std::string(propertyName));
|
return (CCString*)m_pProperties->objectForKey(propertyName);
|
||||||
}
|
}
|
||||||
CCDictionary<std::string, CCString*> * CCTMXTiledMap::propertiesForGID(int GID)
|
|
||||||
|
CCDictionary* CCTMXTiledMap::propertiesForGID(int GID)
|
||||||
{
|
{
|
||||||
return m_pTileProperties->objectForKey(GID);
|
return (CCDictionary*)m_pTileProperties->objectForKey(GID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ THE SOFTWARE.
|
||||||
#include "support/base64.h"
|
#include "support/base64.h"
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
/*
|
/*
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
||||||
#include "expat.h"
|
#include "expat.h"
|
||||||
|
@ -46,36 +47,36 @@ THE SOFTWARE.
|
||||||
#endf
|
#endf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void tmx_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
void tmx_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
||||||
void tmx_endElement(void *ctx, const xmlChar *name);
|
void tmx_endElement(void *ctx, const xmlChar *name);
|
||||||
void tmx_characters(void *ctx, const xmlChar *ch, int len);
|
void tmx_characters(void *ctx, const xmlChar *ch, int len);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char* valueForKey(const char *key, std::map<std::string, std::string>* dict)
|
static const char* valueForKey(const char *key, std::map<std::string, std::string>* dict)
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string>::iterator it = dict->find(key);
|
std::map<std::string, std::string>::iterator it = dict->find(key);
|
||||||
return it!=dict->end() ? it->second.c_str() : "";
|
return it!=dict->end() ? it->second.c_str() : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// implementation CCTMXLayerInfo
|
// implementation CCTMXLayerInfo
|
||||||
CCTMXLayerInfo::CCTMXLayerInfo()
|
CCTMXLayerInfo::CCTMXLayerInfo()
|
||||||
: m_sName("")
|
: m_sName("")
|
||||||
, m_pTiles(NULL)
|
, m_pTiles(NULL)
|
||||||
, m_bOwnTiles(true)
|
, m_bOwnTiles(true)
|
||||||
, m_uMinGID(100000)
|
, m_uMinGID(100000)
|
||||||
, m_uMaxGID(0)
|
, m_uMaxGID(0)
|
||||||
, m_tOffset(CCPointZero)
|
, m_tOffset(CCPointZero)
|
||||||
{
|
{
|
||||||
m_pProperties= new CCStringToStringDictionary();;
|
m_pProperties= new CCDictionary();;
|
||||||
}
|
}
|
||||||
CCTMXLayerInfo::~CCTMXLayerInfo()
|
CCTMXLayerInfo::~CCTMXLayerInfo()
|
||||||
{
|
{
|
||||||
CCLOGINFO("cocos2d: deallocing.");
|
CCLOGINFO("cocos2d: deallocing.");
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
if( m_bOwnTiles && m_pTiles )
|
if( m_bOwnTiles && m_pTiles )
|
||||||
|
@ -83,33 +84,33 @@ namespace cocos2d {
|
||||||
delete [] m_pTiles;
|
delete [] m_pTiles;
|
||||||
m_pTiles = NULL;
|
m_pTiles = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CCStringToStringDictionary * CCTMXLayerInfo::getProperties()
|
CCDictionary * CCTMXLayerInfo::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXLayerInfo::setProperties(CCStringToStringDictionary* var)
|
void CCTMXLayerInfo::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
m_pProperties = var;
|
m_pProperties = var;
|
||||||
}
|
}
|
||||||
|
|
||||||
// implementation CCTMXTilesetInfo
|
// implementation CCTMXTilesetInfo
|
||||||
CCTMXTilesetInfo::CCTMXTilesetInfo()
|
CCTMXTilesetInfo::CCTMXTilesetInfo()
|
||||||
:m_uFirstGid(0)
|
:m_uFirstGid(0)
|
||||||
,m_tTileSize(CCSizeZero)
|
,m_tTileSize(CCSizeZero)
|
||||||
,m_uSpacing(0)
|
,m_uSpacing(0)
|
||||||
,m_uMargin(0)
|
,m_uMargin(0)
|
||||||
,m_tImageSize(CCSizeZero)
|
,m_tImageSize(CCSizeZero)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
CCTMXTilesetInfo::~CCTMXTilesetInfo()
|
CCTMXTilesetInfo::~CCTMXTilesetInfo()
|
||||||
{
|
{
|
||||||
CCLOGINFO("cocos2d: deallocing.");
|
CCLOGINFO("cocos2d: deallocing.");
|
||||||
}
|
}
|
||||||
CCRect CCTMXTilesetInfo::rectForGID(unsigned int gid)
|
CCRect CCTMXTilesetInfo::rectForGID(unsigned int gid)
|
||||||
{
|
{
|
||||||
CCRect rect;
|
CCRect rect;
|
||||||
rect.size = m_tTileSize;
|
rect.size = m_tTileSize;
|
||||||
gid &= kCCFlippedMask;
|
gid &= kCCFlippedMask;
|
||||||
|
@ -119,12 +120,12 @@ namespace cocos2d {
|
||||||
rect.origin.x = (gid % max_x) * (m_tTileSize.width + m_uSpacing) + m_uMargin;
|
rect.origin.x = (gid % max_x) * (m_tTileSize.width + m_uSpacing) + m_uMargin;
|
||||||
rect.origin.y = (gid / max_x) * (m_tTileSize.height + m_uSpacing) + m_uMargin;
|
rect.origin.y = (gid / max_x) * (m_tTileSize.height + m_uSpacing) + m_uMargin;
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
// implementation CCTMXMapInfo
|
// implementation CCTMXMapInfo
|
||||||
|
|
||||||
CCTMXMapInfo * CCTMXMapInfo::formatWithTMXFile(const char *tmxFile)
|
CCTMXMapInfo * CCTMXMapInfo::formatWithTMXFile(const char *tmxFile)
|
||||||
{
|
{
|
||||||
CCTMXMapInfo *pRet = new CCTMXMapInfo();
|
CCTMXMapInfo *pRet = new CCTMXMapInfo();
|
||||||
if(pRet->initWithTMXFile(tmxFile))
|
if(pRet->initWithTMXFile(tmxFile))
|
||||||
{
|
{
|
||||||
|
@ -133,10 +134,10 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTMXMapInfo * CCTMXMapInfo::formatWithXML(const char* tmxString, const char* resourcePath)
|
CCTMXMapInfo * CCTMXMapInfo::formatWithXML(const char* tmxString, const char* resourcePath)
|
||||||
{
|
{
|
||||||
CCTMXMapInfo *pRet = new CCTMXMapInfo();
|
CCTMXMapInfo *pRet = new CCTMXMapInfo();
|
||||||
if(pRet->initWithXML(tmxString, resourcePath))
|
if(pRet->initWithXML(tmxString, resourcePath))
|
||||||
{
|
{
|
||||||
|
@ -145,37 +146,43 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCTMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePath)
|
||||||
|
{
|
||||||
|
m_pTilesets = CCArray::array();
|
||||||
|
m_pTilesets->retain();
|
||||||
|
|
||||||
|
m_pLayers = CCArray::array();
|
||||||
|
m_pLayers->retain();
|
||||||
|
|
||||||
void CCTMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePath)
|
|
||||||
{
|
|
||||||
m_pTilesets = new CCMutableArray<CCTMXTilesetInfo*>();
|
|
||||||
m_pLayers = new CCMutableArray<CCTMXLayerInfo*>();
|
|
||||||
m_sTMXFileName = CCFileUtils::fullPathFromRelativePath(tmxFileName);
|
m_sTMXFileName = CCFileUtils::fullPathFromRelativePath(tmxFileName);
|
||||||
m_sResources = resourcePath;
|
m_sResources = resourcePath;
|
||||||
m_pObjectGroups = new CCMutableArray<CCTMXObjectGroup*>();
|
m_pObjectGroups = CCArray::array();
|
||||||
m_pProperties = new CCStringToStringDictionary();
|
m_pObjectGroups->retain();
|
||||||
m_pTileProperties = new CCDictionary<int, CCStringToStringDictionary*>();
|
|
||||||
|
m_pProperties = new CCDictionary();
|
||||||
|
m_pTileProperties = new CCDictionary();
|
||||||
|
|
||||||
// tmp vars
|
// tmp vars
|
||||||
m_sCurrentString = "";
|
m_sCurrentString = "";
|
||||||
m_bStoringCharacters = false;
|
m_bStoringCharacters = false;
|
||||||
m_nLayerAttribs = TMXLayerAttribNone;
|
m_nLayerAttribs = TMXLayerAttribNone;
|
||||||
m_nParentElement = TMXPropertyNone;
|
m_nParentElement = TMXPropertyNone;
|
||||||
}
|
}
|
||||||
bool CCTMXMapInfo::initWithXML(const char* tmxString, const char* resourcePath)
|
bool CCTMXMapInfo::initWithXML(const char* tmxString, const char* resourcePath)
|
||||||
{
|
{
|
||||||
internalInit("", resourcePath);
|
internalInit("", resourcePath);
|
||||||
return parseXMLString(tmxString);
|
return parseXMLString(tmxString);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCTMXMapInfo::initWithTMXFile(const char *tmxFile)
|
bool CCTMXMapInfo::initWithTMXFile(const char *tmxFile)
|
||||||
{
|
{
|
||||||
internalInit(tmxFile, "");
|
internalInit(tmxFile, "");
|
||||||
return parseXMLFile(m_sTMXFileName.c_str());
|
return parseXMLFile(m_sTMXFileName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTMXMapInfo::CCTMXMapInfo()
|
CCTMXMapInfo::CCTMXMapInfo()
|
||||||
:m_tMapSize(CCSizeZero)
|
:m_tMapSize(CCSizeZero)
|
||||||
,m_tTileSize(CCSizeZero)
|
,m_tTileSize(CCSizeZero)
|
||||||
,m_pLayers(NULL)
|
,m_pLayers(NULL)
|
||||||
|
@ -185,82 +192,84 @@ namespace cocos2d {
|
||||||
,m_bStoringCharacters(false)
|
,m_bStoringCharacters(false)
|
||||||
,m_pProperties(NULL)
|
,m_pProperties(NULL)
|
||||||
,m_pTileProperties(NULL)
|
,m_pTileProperties(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
CCTMXMapInfo::~CCTMXMapInfo()
|
CCTMXMapInfo::~CCTMXMapInfo()
|
||||||
{
|
{
|
||||||
CCLOGINFO("cocos2d: deallocing.");
|
CCLOGINFO("cocos2d: deallocing.");
|
||||||
CC_SAFE_RELEASE(m_pTilesets);
|
CC_SAFE_RELEASE(m_pTilesets);
|
||||||
CC_SAFE_RELEASE(m_pLayers);
|
CC_SAFE_RELEASE(m_pLayers);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
CC_SAFE_RELEASE(m_pTileProperties);
|
CC_SAFE_RELEASE(m_pTileProperties);
|
||||||
CC_SAFE_RELEASE(m_pObjectGroups);
|
CC_SAFE_RELEASE(m_pObjectGroups);
|
||||||
}
|
}
|
||||||
CCMutableArray<CCTMXLayerInfo*> * CCTMXMapInfo::getLayers()
|
CCArray* CCTMXMapInfo::getLayers()
|
||||||
{
|
{
|
||||||
return m_pLayers;
|
return m_pLayers;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setLayers(CCMutableArray<CCTMXLayerInfo*>* var)
|
void CCTMXMapInfo::setLayers(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pLayers);
|
CC_SAFE_RELEASE(m_pLayers);
|
||||||
m_pLayers = var;
|
m_pLayers = var;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCTMXTilesetInfo*> * CCTMXMapInfo::getTilesets()
|
CCArray* CCTMXMapInfo::getTilesets()
|
||||||
{
|
{
|
||||||
return m_pTilesets;
|
return m_pTilesets;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setTilesets(CCMutableArray<CCTMXTilesetInfo*>* var)
|
void CCTMXMapInfo::setTilesets(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pTilesets);
|
CC_SAFE_RELEASE(m_pTilesets);
|
||||||
m_pTilesets = var;
|
m_pTilesets = var;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCTMXObjectGroup*> * CCTMXMapInfo::getObjectGroups()
|
CCArray* CCTMXMapInfo::getObjectGroups()
|
||||||
{
|
{
|
||||||
return m_pObjectGroups;
|
return m_pObjectGroups;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
|
void CCTMXMapInfo::setObjectGroups(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pObjectGroups);
|
CC_SAFE_RELEASE(m_pObjectGroups);
|
||||||
m_pObjectGroups = var;
|
m_pObjectGroups = var;
|
||||||
}
|
}
|
||||||
CCStringToStringDictionary * CCTMXMapInfo::getProperties()
|
CCDictionary * CCTMXMapInfo::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setProperties(CCStringToStringDictionary* var)
|
void CCTMXMapInfo::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
m_pProperties = var;
|
m_pProperties = var;
|
||||||
}
|
}
|
||||||
CCDictionary<int, CCStringToStringDictionary*> * CCTMXMapInfo::getTileProperties()
|
|
||||||
{
|
CCDictionary* CCTMXMapInfo::getTileProperties()
|
||||||
|
{
|
||||||
return m_pTileProperties;
|
return m_pTileProperties;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setTileProperties(CCDictionary<int, CCStringToStringDictionary*> * tileProperties)
|
|
||||||
{
|
void CCTMXMapInfo::setTileProperties(CCDictionary* tileProperties)
|
||||||
|
{
|
||||||
CC_SAFE_RETAIN(tileProperties);
|
CC_SAFE_RETAIN(tileProperties);
|
||||||
CC_SAFE_RELEASE(m_pTileProperties);
|
CC_SAFE_RELEASE(m_pTileProperties);
|
||||||
m_pTileProperties = tileProperties;
|
m_pTileProperties = tileProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCTMXMapInfo::parseXMLString(const char *xmlString)
|
bool CCTMXMapInfo::parseXMLString(const char *xmlString)
|
||||||
{
|
{
|
||||||
// TODO:
|
// TODO:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCTMXMapInfo::parseXMLData(const char* data)
|
bool CCTMXMapInfo::parseXMLData(const char* data)
|
||||||
{
|
{
|
||||||
// TODO:
|
// TODO:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCTMXMapInfo::parseXMLFile(const char *xmlFilename)
|
bool CCTMXMapInfo::parseXMLFile(const char *xmlFilename)
|
||||||
{
|
{
|
||||||
CCSAXParser parser;
|
CCSAXParser parser;
|
||||||
|
|
||||||
if (false == parser.init("UTF-8") )
|
if (false == parser.init("UTF-8") )
|
||||||
|
@ -271,12 +280,12 @@ namespace cocos2d {
|
||||||
parser.setDelegator(this);
|
parser.setDelegator(this);
|
||||||
|
|
||||||
return parser.parse(xmlFilename);;
|
return parser.parse(xmlFilename);;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// the XML parser calls here with all the elements
|
// the XML parser calls here with all the elements
|
||||||
void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(ctx);
|
CC_UNUSED_PARAM(ctx);
|
||||||
CCTMXMapInfo *pTMXMapInfo = this;
|
CCTMXMapInfo *pTMXMapInfo = this;
|
||||||
std::string elementName = (char*)name;
|
std::string elementName = (char*)name;
|
||||||
|
@ -346,8 +355,8 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
else if(elementName == "tile")
|
else if(elementName == "tile")
|
||||||
{
|
{
|
||||||
CCTMXTilesetInfo* info = pTMXMapInfo->getTilesets()->getLastObject();
|
CCTMXTilesetInfo* info = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();
|
||||||
CCStringToStringDictionary *dict = new CCStringToStringDictionary();
|
CCDictionary *dict = new CCDictionary();
|
||||||
pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict)));
|
pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict)));
|
||||||
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
|
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
|
||||||
CC_SAFE_RELEASE(dict);
|
CC_SAFE_RELEASE(dict);
|
||||||
|
@ -407,7 +416,7 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
else if(elementName == "image")
|
else if(elementName == "image")
|
||||||
{
|
{
|
||||||
CCTMXTilesetInfo *tileset = pTMXMapInfo->getTilesets()->getLastObject();
|
CCTMXTilesetInfo* tileset = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();
|
||||||
|
|
||||||
// build full path
|
// build full path
|
||||||
std::string imagename = valueForKey("source", attributeDict);
|
std::string imagename = valueForKey("source", attributeDict);
|
||||||
|
@ -442,30 +451,30 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
else if(elementName == "object")
|
else if(elementName == "object")
|
||||||
{
|
{
|
||||||
char buffer[32];
|
char buffer[32] = {0};
|
||||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
|
||||||
|
|
||||||
// The value for "type" was blank or not a valid class name
|
// The value for "type" was blank or not a valid class name
|
||||||
// Create an instance of TMXObjectInfo to store the object and its properties
|
// Create an instance of TMXObjectInfo to store the object and its properties
|
||||||
CCStringToStringDictionary *dict = new CCStringToStringDictionary();
|
CCDictionary *dict = new CCDictionary();
|
||||||
|
|
||||||
// Set the name of the object to the value for "name"
|
// Set the name of the object to the value for "name"
|
||||||
std::string key = "name";
|
std::string key = "name";
|
||||||
CCString *value = new CCString(valueForKey("name", attributeDict));
|
CCString *value = new CCString(valueForKey("name", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
// Assign all the attributes as key/name pairs in the properties dictionary
|
// Assign all the attributes as key/name pairs in the properties dictionary
|
||||||
key = "type";
|
key = "type";
|
||||||
value = new CCString(valueForKey("type", attributeDict));
|
value = new CCString(valueForKey("type", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
int x = atoi(valueForKey("x", attributeDict)) + (int)objectGroup->getPositionOffset().x;
|
int x = atoi(valueForKey("x", attributeDict)) + (int)objectGroup->getPositionOffset().x;
|
||||||
key = "x";
|
key = "x";
|
||||||
sprintf(buffer, "%d", x);
|
sprintf(buffer, "%d", x);
|
||||||
value = new CCString(buffer);
|
value = new CCString(buffer);
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
int y = atoi(valueForKey("y", attributeDict)) + (int)objectGroup->getPositionOffset().y;
|
int y = atoi(valueForKey("y", attributeDict)) + (int)objectGroup->getPositionOffset().y;
|
||||||
|
@ -474,17 +483,17 @@ namespace cocos2d {
|
||||||
key = "y";
|
key = "y";
|
||||||
sprintf(buffer, "%d", y);
|
sprintf(buffer, "%d", y);
|
||||||
value = new CCString(buffer);
|
value = new CCString(buffer);
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
key = "width";
|
key = "width";
|
||||||
value = new CCString(valueForKey("width", attributeDict));
|
value = new CCString(valueForKey("width", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
key = "height";
|
key = "height";
|
||||||
value = new CCString(valueForKey("height", attributeDict));
|
value = new CCString(valueForKey("height", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
// Add the object to the objectGroup
|
// Add the object to the objectGroup
|
||||||
|
@ -507,27 +516,27 @@ namespace cocos2d {
|
||||||
// The parent element is the map
|
// The parent element is the map
|
||||||
CCString *value = new CCString(valueForKey("value", attributeDict));
|
CCString *value = new CCString(valueForKey("value", attributeDict));
|
||||||
std::string key = valueForKey("name", attributeDict);
|
std::string key = valueForKey("name", attributeDict);
|
||||||
pTMXMapInfo->getProperties()->setObject(value, key);
|
pTMXMapInfo->getProperties()->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
||||||
{
|
{
|
||||||
// The parent element is the last layer
|
// The parent element is the last layer
|
||||||
CCTMXLayerInfo *layer = pTMXMapInfo->getLayers()->getLastObject();
|
CCTMXLayerInfo* layer = (CCTMXLayerInfo*)pTMXMapInfo->getLayers()->lastObject();
|
||||||
CCString *value = new CCString(valueForKey("value", attributeDict));
|
CCString *value = new CCString(valueForKey("value", attributeDict));
|
||||||
std::string key = valueForKey("name", attributeDict);
|
std::string key = valueForKey("name", attributeDict);
|
||||||
// Add the property to the layer
|
// Add the property to the layer
|
||||||
layer->getProperties()->setObject(value, key);
|
layer->getProperties()->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
||||||
{
|
{
|
||||||
// The parent element is the last object group
|
// The parent element is the last object group
|
||||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
|
||||||
CCString *value = new CCString(valueForKey("value", attributeDict));
|
CCString *value = new CCString(valueForKey("value", attributeDict));
|
||||||
std::string key = valueForKey("name", attributeDict);
|
const char* key = valueForKey("name", attributeDict);
|
||||||
objectGroup->getProperties()->setObject(value, key);
|
objectGroup->getProperties()->setObject(value, key);
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
|
@ -535,20 +544,19 @@ namespace cocos2d {
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
||||||
{
|
{
|
||||||
// The parent element is the last object
|
// The parent element is the last object
|
||||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
|
||||||
CCStringToStringDictionary *dict = objectGroup->getObjects()->getLastObject();
|
CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();
|
||||||
|
|
||||||
std::string propertyName = valueForKey("name", attributeDict);
|
const char* propertyName = valueForKey("name", attributeDict);
|
||||||
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
||||||
dict->setObject(propertyValue, propertyName);
|
dict->setObject(propertyValue, propertyName);
|
||||||
propertyValue->release();
|
propertyValue->release();
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile )
|
||||||
{
|
{
|
||||||
CCStringToStringDictionary *dict;
|
CCDictionary* dict = (CCDictionary*)pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID());
|
||||||
dict = pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID());
|
|
||||||
|
|
||||||
std::string propertyName = valueForKey("name", attributeDict);
|
const char* propertyName = valueForKey("name", attributeDict);
|
||||||
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
||||||
dict->setObject(propertyValue, propertyName);
|
dict->setObject(propertyValue, propertyName);
|
||||||
propertyValue->release();
|
propertyValue->release();
|
||||||
|
@ -559,10 +567,10 @@ namespace cocos2d {
|
||||||
attributeDict->clear();
|
attributeDict->clear();
|
||||||
delete attributeDict;
|
delete attributeDict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXMapInfo::endElement(void *ctx, const char *name)
|
void CCTMXMapInfo::endElement(void *ctx, const char *name)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(ctx);
|
CC_UNUSED_PARAM(ctx);
|
||||||
CCTMXMapInfo *pTMXMapInfo = this;
|
CCTMXMapInfo *pTMXMapInfo = this;
|
||||||
std::string elementName = (char*)name;
|
std::string elementName = (char*)name;
|
||||||
|
@ -573,7 +581,7 @@ namespace cocos2d {
|
||||||
{
|
{
|
||||||
pTMXMapInfo->setStoringCharacters(false);
|
pTMXMapInfo->setStoringCharacters(false);
|
||||||
|
|
||||||
CCTMXLayerInfo *layer = pTMXMapInfo->getLayers()->getLastObject();
|
CCTMXLayerInfo* layer = (CCTMXLayerInfo*)pTMXMapInfo->getLayers()->lastObject();
|
||||||
|
|
||||||
std::string currentString = pTMXMapInfo->getCurrentString();
|
std::string currentString = pTMXMapInfo->getCurrentString();
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
|
@ -635,10 +643,10 @@ namespace cocos2d {
|
||||||
// The object element has ended
|
// The object element has ended
|
||||||
pTMXMapInfo->setParentElement(TMXPropertyNone);
|
pTMXMapInfo->setParentElement(TMXPropertyNone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXMapInfo::textHandler(void *ctx, const char *ch, int len)
|
void CCTMXMapInfo::textHandler(void *ctx, const char *ch, int len)
|
||||||
{
|
{
|
||||||
CC_UNUSED_PARAM(ctx);
|
CC_UNUSED_PARAM(ctx);
|
||||||
CCTMXMapInfo *pTMXMapInfo = this;
|
CCTMXMapInfo *pTMXMapInfo = this;
|
||||||
std::string pText((char*)ch,0,len);
|
std::string pText((char*)ch,0,len);
|
||||||
|
@ -649,6 +657,7 @@ namespace cocos2d {
|
||||||
currentString += pText;
|
currentString += pText;
|
||||||
pTMXMapInfo->setCurrentString(currentString.c_str());
|
pTMXMapInfo->setCurrentString(currentString.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
}//namespace cocos2d
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCTouchDispatcher.h"
|
#include "CCTouchDispatcher.h"
|
||||||
#include "CCTouchHandler.h"
|
#include "CCTouchHandler.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCSet.h"
|
#include "CCSet.h"
|
||||||
#include "CCTouch.h"
|
#include "CCTouch.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
|
@ -36,9 +36,9 @@ THE SOFTWARE.
|
||||||
/**
|
/**
|
||||||
* Used for sort
|
* Used for sort
|
||||||
*/
|
*/
|
||||||
static bool less(const cocos2d::CCTouchHandler *p1, const cocos2d::CCTouchHandler *p2)
|
static int less(const void* p1, const void* p2)
|
||||||
{
|
{
|
||||||
return ((cocos2d::CCTouchHandler*)p1)->getPriority() < ((cocos2d::CCTouchHandler*)p2)->getPriority();
|
return ((cocos2d::CCTouchHandler*)p1)->getPriority() < ((cocos2d::CCTouchHandler*)p2)->getPriority() ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
@ -81,10 +81,12 @@ CCTouchDispatcher* CCTouchDispatcher::sharedDispatcher(void)
|
||||||
bool CCTouchDispatcher::init(void)
|
bool CCTouchDispatcher::init(void)
|
||||||
{
|
{
|
||||||
m_bDispatchEvents = true;
|
m_bDispatchEvents = true;
|
||||||
m_pTargetedHandlers = new CCMutableArray<CCTouchHandler*>(8);
|
m_pTargetedHandlers = CCArray::arrayWithCapacity(8);
|
||||||
m_pStandardHandlers = new CCMutableArray<CCTouchHandler*>(4);
|
m_pTargetedHandlers->retain();
|
||||||
|
m_pStandardHandlers = CCArray::arrayWithCapacity(4);
|
||||||
|
m_pStandardHandlers->retain();
|
||||||
|
|
||||||
m_pHandlersToAdd = new CCMutableArray<CCTouchHandler*>(8);
|
m_pHandlersToAdd = CCArray::arrayWithCapacity(8);
|
||||||
m_pHandlersToRemove = ccCArrayNew(8);
|
m_pHandlersToRemove = ccCArrayNew(8);
|
||||||
|
|
||||||
m_bToRemove = false;
|
m_bToRemove = false;
|
||||||
|
@ -113,14 +115,14 @@ CCTouchDispatcher::~CCTouchDispatcher(void)
|
||||||
//
|
//
|
||||||
// handlers management
|
// handlers management
|
||||||
//
|
//
|
||||||
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCMutableArray<CCTouchHandler*> *pArray)
|
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCArray *pArray)
|
||||||
{
|
{
|
||||||
unsigned int u = 0;
|
unsigned int u = 0;
|
||||||
|
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
CCARRAY_FOREACH(pArray, pObj)
|
||||||
{
|
{
|
||||||
CCTouchHandler *h = *iter;
|
CCTouchHandler *h = (CCTouchHandler *)pObj;
|
||||||
if (h)
|
if (h)
|
||||||
{
|
{
|
||||||
if (h->getPriority() < pHandler->getPriority())
|
if (h->getPriority() < pHandler->getPriority())
|
||||||
|
@ -136,7 +138,7 @@ void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCMutableArray
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray->insertObjectAtIndex(pHandler, u);
|
pArray->insertObject(pHandler, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||||
|
@ -188,14 +190,14 @@ void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPri
|
||||||
void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
||||||
{
|
{
|
||||||
CCTouchHandler *pHandler;
|
CCTouchHandler *pHandler;
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
|
||||||
|
|
||||||
// XXX: remove it from both handlers ???
|
// XXX: remove it from both handlers ???
|
||||||
|
|
||||||
// remove handler from m_pStandardHandlers
|
// remove handler from m_pStandardHandlers
|
||||||
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pStandardHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCTouchHandler*)pObj;
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
m_pStandardHandlers->removeObject(pHandler);
|
m_pStandardHandlers->removeObject(pHandler);
|
||||||
|
@ -204,9 +206,9 @@ void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove handler from m_pTargetedHandlers
|
// remove handler from m_pTargetedHandlers
|
||||||
for (iter = m_pTargetedHandlers->begin(); iter != m_pTargetedHandlers->end(); ++iter)
|
CCARRAY_FOREACH(m_pTargetedHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCTouchHandler*)pObj;
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
m_pTargetedHandlers->removeObject(pHandler);
|
m_pTargetedHandlers->removeObject(pHandler);
|
||||||
|
@ -263,47 +265,49 @@ void CCTouchDispatcher::removeAllDelegates(void)
|
||||||
|
|
||||||
CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate)
|
CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pTargetedHandlers, pObj)
|
||||||
for (iter = m_pTargetedHandlers->begin(); iter != m_pTargetedHandlers->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if ((*iter)->getDelegate() == pDelegate)
|
CCTouchHandler* pHandler = (CCTouchHandler*)pObj;
|
||||||
|
if (pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
return *iter;
|
return pHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
CCARRAY_FOREACH(m_pStandardHandlers, pObj)
|
||||||
{
|
{
|
||||||
if ((*iter)->getDelegate() == pDelegate)
|
CCTouchHandler* pHandler = (CCTouchHandler*)pObj;
|
||||||
|
if (pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
return *iter;
|
return pHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTouchHandler* CCTouchDispatcher::findHandler(CCMutableArray<CCTouchHandler*> *pArray, CCTouchDelegate *pDelegate)
|
CCTouchHandler* CCTouchDispatcher::findHandler(CCArray* pArray, CCTouchDelegate *pDelegate)
|
||||||
{
|
{
|
||||||
CCAssert(pArray != NULL && pDelegate != NULL, "");
|
CCAssert(pArray != NULL && pDelegate != NULL, "");
|
||||||
|
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(pArray, pObj)
|
||||||
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if ((*iter)->getDelegate() == pDelegate)
|
CCTouchHandler* pHandle = (CCTouchHandler*)pObj;
|
||||||
|
if (pHandle->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
return *iter;
|
return pHandle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchDispatcher::rearrangeHandlers(CCMutableArray<CCTouchHandler*> *pArray)
|
void CCTouchDispatcher::rearrangeHandlers(CCArray *pArray)
|
||||||
{
|
{
|
||||||
std::sort(pArray->begin(), pArray->end(), less);
|
// FIXME: qsort is not supported in bada1.0, so we must implement it ourselves.
|
||||||
|
qsort(pArray->data->arr, pArray->data->num, sizeof(pArray->data->arr[0]), less);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
|
void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
|
||||||
|
@ -350,12 +354,12 @@ void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int u
|
||||||
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
|
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
|
||||||
{
|
{
|
||||||
pTouch = (CCTouch *)(*setIter);
|
pTouch = (CCTouch *)(*setIter);
|
||||||
CCTargetedTouchHandler *pHandler;
|
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator arrayIter;
|
CCTargetedTouchHandler *pHandler = NULL;
|
||||||
for (arrayIter = m_pTargetedHandlers->begin(); arrayIter != m_pTargetedHandlers->end(); ++arrayIter)
|
CCObject* pObj = NULL;
|
||||||
/*for (unsigned int i = 0; i < m_pTargetedHandlers->num; ++i)*/
|
CCARRAY_FOREACH(m_pTargetedHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = (CCTargetedTouchHandler *)(*arrayIter);
|
pHandler = (CCTargetedTouchHandler *)(pObj);
|
||||||
|
|
||||||
if (! pHandler)
|
if (! pHandler)
|
||||||
{
|
{
|
||||||
|
@ -411,11 +415,11 @@ void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int u
|
||||||
//
|
//
|
||||||
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCStandardTouchHandler *pHandler = NULL;
|
||||||
CCStandardTouchHandler *pHandler;
|
CCObject* pObj = NULL;
|
||||||
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
CCARRAY_FOREACH(m_pStandardHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = (CCStandardTouchHandler*)(*iter);
|
pHandler = (CCStandardTouchHandler*)(pObj);
|
||||||
|
|
||||||
if (! pHandler)
|
if (! pHandler)
|
||||||
{
|
{
|
||||||
|
@ -463,11 +467,11 @@ void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int u
|
||||||
if (m_bToAdd)
|
if (m_bToAdd)
|
||||||
{
|
{
|
||||||
m_bToAdd = false;
|
m_bToAdd = false;
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCTouchHandler* pHandler = NULL;
|
||||||
CCTouchHandler *pHandler;
|
CCObject* pObj = NULL;
|
||||||
for (iter = m_pHandlersToAdd->begin(); iter != m_pHandlersToAdd->end(); ++iter)
|
CCARRAY_FOREACH(m_pHandlersToAdd, pObj)
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCTouchHandler*)pObj;
|
||||||
if (! pHandler)
|
if (! pHandler)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ACTION_MANUAL_LAYER = 0,
|
ACTION_MANUAL_LAYER = 0,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
7593bccdf37e94e6af9b7bfec82d6931c746f428
|
6b30e04685cc62b5daa0628f9bb038bc42bae923
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
#include "../testBasic.h"
|
#include "../testBasic.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class SpriteTestDemo : public CCLayer
|
class SpriteTestDemo : public CCLayer
|
||||||
{
|
{
|
||||||
|
|
|
@ -615,13 +615,13 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest()
|
||||||
|
|
||||||
////----UXLOG("----> Iterating over all the group objets");
|
////----UXLOG("----> Iterating over all the group objets");
|
||||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
|
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict = NULL;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
{
|
{
|
||||||
dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
|
@ -639,24 +639,23 @@ void TMXOrthoObjectsTest::draw()
|
||||||
CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||||
|
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict = NULL;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
|
||||||
{
|
{
|
||||||
dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
std::string key = "x";
|
const char* key = "x";
|
||||||
int x = dict->objectForKey(key)->toInt();
|
int x = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "y";
|
key = "y";
|
||||||
int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
int y = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||||
key = "width";
|
key = "width";
|
||||||
int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
int width = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||||
key = "height";
|
key = "height";
|
||||||
int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
int height = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||||
|
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
|
@ -697,15 +696,13 @@ TMXIsoObjectsTest::TMXIsoObjectsTest()
|
||||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||||
|
|
||||||
//UxMutableArray* objects = group->objects();
|
//UxMutableArray* objects = group->objects();
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
//UxMutableDictionary<std::string>* dict;
|
//UxMutableDictionary<std::string>* dict;
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict;
|
||||||
//CCMutableArray<CCObject*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
|
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
|
||||||
{
|
{
|
||||||
dict = (*it);
|
dict = (CCDictionary*)pObj;
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
|
@ -719,24 +716,23 @@ void TMXIsoObjectsTest::draw()
|
||||||
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||||
CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");
|
||||||
|
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
|
||||||
{
|
{
|
||||||
dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
std::string key = "x";
|
const char* key = "x";
|
||||||
int x = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
|
int x = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
|
||||||
key = "y";
|
key = "y";
|
||||||
int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
int y = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||||
key = "width";
|
key = "width";
|
||||||
int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
int width = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||||
key = "height";
|
key = "height";
|
||||||
int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
int height = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||||
|
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
|
@ -1412,26 +1408,25 @@ void TMXGIDObjectsTest::draw()
|
||||||
CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
||||||
CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
|
CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
|
||||||
|
|
||||||
CCMutableArray<CCStringToStringDictionary*> *array = group->getObjects();
|
CCArray *array = group->getObjects();
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator iter;
|
CCDictionary* dict;
|
||||||
CCStringToStringDictionary *dict;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(array, pObj)
|
||||||
for (iter = array->begin(); iter != array->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
dict = *iter;
|
dict = (CCDictionary*)pObj;
|
||||||
if(!dict)
|
if(!dict)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string key = "x";
|
const char* key = "x";
|
||||||
int x = dict->objectForKey(key)->toInt();
|
int x = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "y";
|
key = "y";
|
||||||
int y = dict->objectForKey(key)->toInt();
|
int y = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "width";
|
key = "width";
|
||||||
int width = dict->objectForKey(key)->toInt();
|
int width = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "height";
|
key = "height";
|
||||||
int height = dict->objectForKey(key)->toInt();
|
int height = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
|
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ PongLayer::PongLayer()
|
||||||
|
|
||||||
CCTexture2D* paddleTexture = CCTextureCache::sharedTextureCache()->addImage(s_Paddle);
|
CCTexture2D* paddleTexture = CCTextureCache::sharedTextureCache()->addImage(s_Paddle);
|
||||||
|
|
||||||
CCMutableArray<CCObject *> *paddlesM = new CCMutableArray<CCObject *>(4);
|
CCArray *paddlesM = CCArray::arrayWithCapacity(4);
|
||||||
|
|
||||||
Paddle* paddle = Paddle::paddleWithTexture(paddleTexture);
|
Paddle* paddle = Paddle::paddleWithTexture(paddleTexture);
|
||||||
paddle->setPosition( CCPointMake(160, 15) );
|
paddle->setPosition( CCPointMake(160, 15) );
|
||||||
|
@ -72,12 +72,12 @@ PongLayer::PongLayer()
|
||||||
paddle->setPosition( CCPointMake(160, 480 - kStatusBarHeight - 100) );
|
paddle->setPosition( CCPointMake(160, 480 - kStatusBarHeight - 100) );
|
||||||
paddlesM->addObject( paddle );
|
paddlesM->addObject( paddle );
|
||||||
|
|
||||||
m_paddles = paddlesM->copy();
|
m_paddles = (CCArray*)paddlesM->copy();
|
||||||
|
|
||||||
CCMutableArray<CCObject *>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for(it = m_paddles->begin(); it != m_paddles->end(); it++)
|
CCARRAY_FOREACH(m_paddles, pObj)
|
||||||
{
|
{
|
||||||
paddle = (Paddle*)(*it);
|
paddle = (Paddle*)(pObj);
|
||||||
|
|
||||||
if(!paddle)
|
if(!paddle)
|
||||||
break;
|
break;
|
||||||
|
@ -85,8 +85,6 @@ PongLayer::PongLayer()
|
||||||
addChild(paddle);
|
addChild(paddle);
|
||||||
}
|
}
|
||||||
|
|
||||||
paddlesM->release();
|
|
||||||
|
|
||||||
schedule( schedule_selector(PongLayer::doStep) );
|
schedule( schedule_selector(PongLayer::doStep) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,11 +107,11 @@ void PongLayer::doStep(ccTime delta)
|
||||||
{
|
{
|
||||||
m_ball->move(delta);
|
m_ball->move(delta);
|
||||||
|
|
||||||
Paddle* paddle;
|
Paddle* paddle = NULL;
|
||||||
CCMutableArray<CCObject *>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for(it = m_paddles->begin(); it != m_paddles->end(); it++)
|
CCARRAY_FOREACH(m_paddles, pObj)
|
||||||
{
|
{
|
||||||
paddle = (Paddle*)(*it);
|
paddle = (Paddle*)(pObj);
|
||||||
|
|
||||||
if(!paddle)
|
if(!paddle)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Ball;
|
||||||
class PongLayer : public CCLayer
|
class PongLayer : public CCLayer
|
||||||
{
|
{
|
||||||
Ball* m_ball;
|
Ball* m_ball;
|
||||||
CCMutableArray<CCObject *> *m_paddles;
|
CCArray* m_paddles;
|
||||||
CCPoint m_ballStartingVelocity;
|
CCPoint m_ballStartingVelocity;
|
||||||
public:
|
public:
|
||||||
PongLayer();
|
PongLayer();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class TestScene : public CCScene
|
class TestScene : public CCScene
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue