2010-11-13 11:34:49 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:34:26 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
|
2010-11-13 11:34:49 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-12-22 15:15:04 +08:00
|
|
|
#include "CCActionInstant.h"
|
2010-11-13 11:34:49 +08:00
|
|
|
#include "CCNode.h"
|
|
|
|
#include "CCSprite.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
|
2010-11-13 11:34:49 +08:00
|
|
|
namespace cocos2d {
|
2010-08-05 17:22:47 +08:00
|
|
|
//
|
|
|
|
// InstantAction
|
|
|
|
//
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::CCActionInstant()
|
2011-04-01 16:06:53 +08:00
|
|
|
{}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCActionInstant::copyWithZone(cocos2d::CCZone *pZone)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant *pRet = NULL;
|
2010-11-13 11:34:49 +08:00
|
|
|
if (pZone && pZone->m_pCopyObject)
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
pRet = (CCActionInstant*)(pZone->m_pCopyObject);
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
pRet = new CCActionInstant();
|
2011-03-07 17:11:57 +08:00
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|
|
|
|
CCFiniteTimeAction::copyWithZone(pZone);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
bool CCActionInstant::isDone()
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
void CCActionInstant::step(ccTime dt)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-06-10 17:51:37 +08:00
|
|
|
CC_UNUSED_PARAM(dt);
|
2010-08-05 17:22:47 +08:00
|
|
|
update(1);
|
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
void CCActionInstant::update(ccTime time)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-06-10 17:51:37 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2010-08-05 17:22:47 +08:00
|
|
|
// ignore
|
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
CCFiniteTimeAction * CCActionInstant::reverse()
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
return (CCFiniteTimeAction*)(copy()->autorelease());
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Show
|
|
|
|
//
|
2010-08-12 16:19:09 +08:00
|
|
|
CCShow* CCShow::action()
|
|
|
|
{
|
|
|
|
CCShow* pRet = new CCShow();
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCShow::startWithTarget(CCNode *pTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
pTarget->setIsVisible(true);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
CCFiniteTimeAction *CCShow::reverse()
|
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
return (CCFiniteTimeAction*)(CCHide::action());
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// Hide
|
|
|
|
//
|
2010-08-12 16:19:09 +08:00
|
|
|
CCHide * CCHide::action()
|
|
|
|
{
|
|
|
|
CCHide *pRet = new CCHide();
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCHide::startWithTarget(CCNode *pTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
pTarget->setIsVisible(false);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction *CCHide::reverse()
|
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
return (CCFiniteTimeAction*)(CCShow::action());
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ToggleVisibility
|
|
|
|
//
|
2010-08-12 16:19:09 +08:00
|
|
|
CCToggleVisibility * CCToggleVisibility::action()
|
|
|
|
{
|
|
|
|
CCToggleVisibility *pRet = new CCToggleVisibility();
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCToggleVisibility::startWithTarget(CCNode *pTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
pTarget->setIsVisible(! pTarget->getIsVisible());
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// FlipX
|
|
|
|
//
|
|
|
|
CCFlipX *CCFlipX::actionWithFlipX(bool x)
|
|
|
|
{
|
|
|
|
CCFlipX *pRet = new CCFlipX();
|
2010-11-13 11:34:49 +08:00
|
|
|
pRet->initWithFlipX(x);
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCFlipX::initWithFlipX(bool x)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
m_bFlipX = x;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCFlipX::startWithTarget(CCNode *pTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
((CCSprite*)(pTarget))->setFlipX(m_bFlipX);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction* CCFlipX::reverse()
|
|
|
|
{
|
|
|
|
return CCFlipX::actionWithFlipX(!m_bFlipX);
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCFlipX::copyWithZone(CCZone *pZone)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
2010-11-13 11:34:49 +08:00
|
|
|
CCFlipX *pRet = NULL;
|
|
|
|
if (pZone && pZone->m_pCopyObject)
|
|
|
|
{
|
|
|
|
pRet = (CCFlipX*)(pZone->m_pCopyObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCFlipX();
|
2011-03-07 17:11:57 +08:00
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
2010-11-13 11:34:49 +08:00
|
|
|
pRet->initWithFlipX(m_bFlipX);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FlipY
|
|
|
|
//
|
|
|
|
CCFlipY * CCFlipY::actionWithFlipY(bool y)
|
|
|
|
{
|
|
|
|
CCFlipY *pRet = new CCFlipY();
|
|
|
|
pRet->initWithFlipY(y);
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCFlipY::initWithFlipY(bool y)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
m_bFlipY = y;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCFlipY::startWithTarget(CCNode *pTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
((CCSprite*)(pTarget))->setFlipY(m_bFlipY);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction* CCFlipY::reverse()
|
|
|
|
{
|
|
|
|
return CCFlipY::actionWithFlipY(!m_bFlipY);
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCFlipY::copyWithZone(CCZone *pZone)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
2010-11-13 11:34:49 +08:00
|
|
|
CCFlipY *pRet = NULL;
|
|
|
|
if (pZone && pZone->m_pCopyObject)
|
|
|
|
{
|
|
|
|
pRet = (CCFlipY*)(pZone->m_pCopyObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCFlipY();
|
2011-03-07 17:11:57 +08:00
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
2010-11-13 11:34:49 +08:00
|
|
|
pRet->initWithFlipY(m_bFlipY);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Place
|
|
|
|
//
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPlace * CCPlace::actionWithPosition(CCPoint pos)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
CCPlace *pRet = new CCPlace();
|
|
|
|
pRet->initWithPosition(pos);
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
bool CCPlace::initWithPosition(CCPoint pos)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
m_tPosition = pos;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCPlace::copyWithZone(CCZone *pZone)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
2010-11-13 11:34:49 +08:00
|
|
|
CCPlace *pRet = NULL;
|
|
|
|
if (pZone && pZone->m_pCopyObject)
|
|
|
|
{
|
|
|
|
pRet = (CCPlace*)(pZone->m_pCopyObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCPlace();
|
2011-03-07 17:11:57 +08:00
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
2010-11-13 11:34:49 +08:00
|
|
|
pRet->initWithPosition(m_tPosition);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCPlace::startWithTarget(CCNode *pTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
m_pTarget->setPosition(m_tPosition);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CallFunc
|
|
|
|
//
|
|
|
|
|
|
|
|
CCCallFunc * CCCallFunc::actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFunc selector)
|
|
|
|
{
|
|
|
|
CCCallFunc* pCallFunc = new CCCallFunc();
|
|
|
|
pCallFunc->autorelease();
|
|
|
|
|
|
|
|
pCallFunc->initWithTarget(pSelectorTarget);
|
|
|
|
pCallFunc->m_pCallFunc = selector;
|
|
|
|
|
|
|
|
return pCallFunc;
|
|
|
|
}
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
CCCallFunc * CCCallFunc::actionWithLua(const char * pszfunc)
|
|
|
|
{
|
|
|
|
if (pszfunc)
|
|
|
|
{
|
|
|
|
|
|
|
|
CCCallFunc* pCallFunc = new CCCallFunc();
|
|
|
|
pCallFunc->initWithLua(pszfunc);
|
|
|
|
pCallFunc->autorelease();
|
|
|
|
return pCallFunc;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bool CCCallFunc::initWithLua(const char* pszfn)
|
|
|
|
{
|
|
|
|
if (pszfn)
|
|
|
|
{
|
|
|
|
m_pLuaCallFun = pszfn;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCCallFunc::initWithTarget(SelectorProtocol* pSelectorTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-11-13 11:34:49 +08:00
|
|
|
if (pSelectorTarget)
|
|
|
|
{
|
2010-09-30 11:57:31 +08:00
|
|
|
pSelectorTarget->selectorProtocolRetain();
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|
|
|
|
if (m_pSelectorTarget)
|
|
|
|
{
|
2010-09-30 11:57:31 +08:00
|
|
|
m_pSelectorTarget->selectorProtocolRelease();
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
m_pSelectorTarget = pSelectorTarget;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCCallFunc::copyWithZone(cocos2d::CCZone *pZone)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
2010-08-05 17:22:47 +08:00
|
|
|
CCCallFunc* pRet = NULL;
|
|
|
|
if(pZone && pZone->m_pCopyObject) //in case of being called at sub class
|
2010-08-30 15:06:08 +08:00
|
|
|
pRet = (CCCallFunc*)(pZone->m_pCopyObject);
|
2010-08-05 17:22:47 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCCallFunc();
|
2011-03-07 17:11:57 +08:00
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
pRet->initWithTarget(m_pSelectorTarget);
|
|
|
|
pRet->m_pCallFunc = m_pCallFunc;
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCCallFunc::startWithTarget(CCNode *pTarget)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
this->execute();
|
|
|
|
}
|
|
|
|
void CCCallFunc::execute()
|
|
|
|
{
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
schedule_CallFunc(m_pSelectorTarget, m_pCallFunc, m_pLuaCallFun);
|
|
|
|
#else
|
2010-08-05 17:22:47 +08:00
|
|
|
if(m_pCallFunc)
|
|
|
|
{
|
|
|
|
(m_pSelectorTarget->*m_pCallFunc)();
|
|
|
|
}
|
2011-05-31 14:04:14 +08:00
|
|
|
#endif
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// CallFuncN
|
|
|
|
//
|
|
|
|
void CCCallFuncN::execute()
|
|
|
|
{
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
schedule_CallFuncN(m_pSelectorTarget, m_pCallFuncN, m_pTarget, m_pLuaCallFun);
|
|
|
|
#else
|
2010-08-05 17:22:47 +08:00
|
|
|
if(m_pCallFuncN)
|
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
(m_pSelectorTarget->*m_pCallFuncN)(m_pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-05-31 14:04:14 +08:00
|
|
|
#endif
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
CCCallFuncN * CCCallFuncN::actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncN selector)
|
|
|
|
{
|
|
|
|
CCCallFuncN *pRet = new CCCallFuncN();
|
2010-09-07 15:13:25 +08:00
|
|
|
if(pRet->initWithTarget(pSelectorTarget, selector))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
2010-09-07 15:13:25 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
CCCallFuncN * CCCallFuncN::actionWithLua(const char * pszfunc)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (pszfunc)
|
|
|
|
{
|
|
|
|
CCCallFuncN *pRet = new CCCallFuncN();
|
|
|
|
pRet->initWithLua(pszfunc);
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-07 15:13:25 +08:00
|
|
|
bool CCCallFuncN::initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncN selector)
|
|
|
|
{
|
|
|
|
if( CCCallFunc::initWithTarget(pSelectorTarget) )
|
|
|
|
{
|
|
|
|
m_pCallFuncN = selector;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-31 14:04:14 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCCallFuncN::copyWithZone(CCZone* zone)
|
2010-09-07 15:13:25 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
2010-09-07 15:13:25 +08:00
|
|
|
CCCallFuncN* pRet = NULL;
|
|
|
|
if(zone && zone->m_pCopyObject) //in case of being called at sub class
|
|
|
|
pRet = (CCCallFuncN*)(zone->m_pCopyObject);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCCallFuncN();
|
2011-03-07 17:11:57 +08:00
|
|
|
zone = pNewZone = new CCZone(pRet);
|
2010-09-07 15:13:25 +08:00
|
|
|
}
|
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncN);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// CallFuncND
|
|
|
|
//
|
|
|
|
CCCallFuncND * CCCallFuncND::actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d)
|
|
|
|
{
|
|
|
|
CCCallFuncND* pRet = new CCCallFuncND();
|
2010-11-13 11:34:49 +08:00
|
|
|
if (pRet->initWithTarget(pSelectorTarget, selector, d))
|
|
|
|
{
|
2010-09-04 12:02:52 +08:00
|
|
|
pRet->autorelease();
|
2010-11-13 11:34:49 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
2010-09-04 12:02:52 +08:00
|
|
|
return NULL;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
CCCallFuncND * CCCallFuncND::actionWithLua(const char * pszfunc)
|
|
|
|
{
|
|
|
|
if (pszfunc)
|
|
|
|
{
|
|
|
|
CCCallFuncND* pRet = new CCCallFuncND();
|
|
|
|
pRet->autorelease();
|
|
|
|
pRet->initWithLua(pszfunc);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCCallFuncND::initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2010-09-02 14:54:42 +08:00
|
|
|
if( CCCallFunc::initWithTarget(pSelectorTarget) )
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
m_pData = d;
|
|
|
|
m_pCallFuncND = selector;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2010-09-04 12:02:52 +08:00
|
|
|
return false;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCCallFuncND::copyWithZone(CCZone* zone)
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
2010-08-05 17:22:47 +08:00
|
|
|
CCCallFuncND* pRet = NULL;
|
|
|
|
if(zone && zone->m_pCopyObject) //in case of being called at sub class
|
2010-08-30 15:06:08 +08:00
|
|
|
pRet = (CCCallFuncND*)(zone->m_pCopyObject);
|
2010-08-05 17:22:47 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCCallFuncND();
|
2011-03-07 17:11:57 +08:00
|
|
|
zone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2010-09-02 14:54:42 +08:00
|
|
|
CCCallFunc::copyWithZone(zone);
|
2010-08-05 17:22:47 +08:00
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncND, m_pData);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCCallFuncND::execute()
|
|
|
|
{
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
schedule_CallFuncND(m_pSelectorTarget,m_pCallFuncND, m_pTarget, m_pData, m_pLuaCallFun);
|
|
|
|
#else
|
2010-08-05 17:22:47 +08:00
|
|
|
if(m_pCallFuncND)
|
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
(m_pSelectorTarget->*m_pCallFuncND)(m_pTarget, m_pData);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-05-31 14:04:14 +08:00
|
|
|
#endif
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 16:47:29 +08:00
|
|
|
//
|
|
|
|
// CCCallFuncO
|
|
|
|
//
|
|
|
|
CCCallFuncO::CCCallFuncO()
|
2011-04-01 16:06:53 +08:00
|
|
|
: m_pObject(NULL)
|
2010-12-23 16:47:29 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CCCallFuncO::~CCCallFuncO()
|
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
CC_SAFE_RELEASE(m_pObject);
|
2010-12-23 16:47:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCCallFuncO::execute()
|
|
|
|
{
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
schedule_CallFuncO(m_pSelectorTarget, m_pCallFuncO, m_pObject, m_pLuaCallFun);
|
|
|
|
#else
|
2010-12-23 16:47:29 +08:00
|
|
|
if(m_pCallFuncO)
|
|
|
|
{
|
2011-04-13 11:53:25 +08:00
|
|
|
(m_pSelectorTarget->*m_pCallFuncO)(m_pObject);
|
2010-12-23 16:47:29 +08:00
|
|
|
}
|
2011-05-31 14:04:14 +08:00
|
|
|
#endif
|
2010-12-23 16:47:29 +08:00
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
CCCallFuncO * CCCallFuncO::actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncO selector, CCObject* pObject)
|
2010-12-23 16:47:29 +08:00
|
|
|
{
|
|
|
|
CCCallFuncO *pRet = new CCCallFuncO();
|
|
|
|
if(pRet->initWithTarget(pSelectorTarget, selector, pObject))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
2010-12-23 16:47:29 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-01 17:51:08 +08:00
|
|
|
#ifdef ENABLE_LUA
|
2011-05-31 14:04:14 +08:00
|
|
|
CCCallFuncO * CCCallFuncO::actionWithLua(const char * pszfunc)
|
|
|
|
{
|
|
|
|
if (pszfunc)
|
|
|
|
{
|
|
|
|
CCCallFuncO *pRet = new CCCallFuncO();
|
|
|
|
pRet->autorelease();
|
|
|
|
pRet->initWithLua(pszfunc);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
2011-03-07 17:11:57 +08:00
|
|
|
bool CCCallFuncO::initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncO selector, CCObject* pObject)
|
2010-12-23 16:47:29 +08:00
|
|
|
{
|
|
|
|
if( CCCallFunc::initWithTarget(pSelectorTarget) )
|
|
|
|
{
|
|
|
|
m_pObject = pObject;
|
|
|
|
m_pObject->retain();
|
|
|
|
|
|
|
|
m_pCallFuncO = selector;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject * CCCallFuncO::copyWithZone(CCZone* zone)
|
2010-12-23 16:47:29 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
2010-12-23 16:47:29 +08:00
|
|
|
CCCallFuncO* pRet = NULL;
|
|
|
|
if(zone && zone->m_pCopyObject) //in case of being called at sub class
|
|
|
|
pRet = (CCCallFuncO*)(zone->m_pCopyObject);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCCallFuncO();
|
2011-03-07 17:11:57 +08:00
|
|
|
zone = pNewZone = new CCZone(pRet);
|
2010-12-23 16:47:29 +08:00
|
|
|
}
|
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncO, m_pObject);
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-12-23 16:47:29 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2010-08-05 17:22:47 +08:00
|
|
|
|
|
|
|
#if NS_BLOCKS_AVAILABLE
|
|
|
|
|
|
|
|
#pragma mark CCCallBlock
|
|
|
|
|
|
|
|
@implementation CCCallBlock
|
|
|
|
|
|
|
|
+(id) actionWithBlock:(void(^)())block {
|
|
|
|
return [[[self alloc] initWithBlock:block] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(id) initWithBlock:(void(^)())block {
|
|
|
|
if ((self = [super init])) {
|
|
|
|
|
|
|
|
block_ = [block retain];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
-(id) copyWithZone: (CCZone*) zone {
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithBlock:block_];
|
2010-08-05 17:22:47 +08:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) startWithTarget:(id)aTarget {
|
|
|
|
[super startWithTarget:aTarget];
|
|
|
|
[self execute];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) execute {
|
|
|
|
block_();
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) dealloc {
|
|
|
|
[block_ release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark CCCallBlockN
|
|
|
|
|
|
|
|
@implementation CCCallBlockN
|
|
|
|
|
|
|
|
+(id) actionWithBlock:(void(^)(CCNode *node))block {
|
|
|
|
return [[[self alloc] initWithBlock:block] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(id) initWithBlock:(void(^)(CCNode *node))block {
|
|
|
|
if ((self = [super init])) {
|
|
|
|
|
|
|
|
block_ = [block retain];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
-(id) copyWithZone: (CCZone*) zone {
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithBlock:block_];
|
2010-08-05 17:22:47 +08:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) startWithTarget:(id)aTarget {
|
|
|
|
[super startWithTarget:aTarget];
|
|
|
|
[self execute];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) execute {
|
|
|
|
block_(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) dealloc {
|
|
|
|
[block_ release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
#endif // NS_BLOCKS_AVAILABLE
|
2010-11-13 11:34:49 +08:00
|
|
|
|
|
|
|
}
|