2010-11-13 11:34:49 +08:00
|
|
|
/****************************************************************************
|
2011-09-05 10:12:14 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2011-03-19 10:34:26 +08:00
|
|
|
|
2011-09-05 10:12:14 +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-11-13 11:34:49 +08:00
|
|
|
|
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-06-20 17:31:38 +08:00
|
|
|
#include "CCScriptSupport.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
|
2010-11-13 11:34:49 +08:00
|
|
|
namespace cocos2d {
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// InstantAction
|
|
|
|
//
|
|
|
|
CCActionInstant::CCActionInstant() {
|
|
|
|
}
|
|
|
|
|
|
|
|
CCObject * CCActionInstant::copyWithZone(CCZone *pZone) {
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCActionInstant *pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCActionInstant*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCActionInstant();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCFiniteTimeAction::copyWithZone(pZone);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCActionInstant::isDone() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCActionInstant::step(ccTime dt) {
|
|
|
|
CC_UNUSED_PARAM(dt);
|
|
|
|
update(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCActionInstant::update(ccTime time) {
|
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction * CCActionInstant::reverse() {
|
|
|
|
return (CCFiniteTimeAction*) (copy()->autorelease());
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Show
|
|
|
|
//
|
|
|
|
CCShow* CCShow::action() {
|
|
|
|
CCShow* pRet = new CCShow();
|
|
|
|
|
|
|
|
if (pRet) {
|
|
|
|
pRet->autorelease();
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCShow::startWithTarget(CCNode *pTarget) {
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
pTarget->setIsVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction* CCShow::reverse() {
|
|
|
|
return (CCFiniteTimeAction*) (CCHide::action());
|
|
|
|
}
|
|
|
|
|
|
|
|
CCObject* CCShow::copyWithZone(CCZone *pZone) {
|
|
|
|
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCShow *pRet = NULL;
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCShow*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCShow();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction::copyWithZone(pZone);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Hide
|
|
|
|
//
|
|
|
|
CCHide * CCHide::action() {
|
|
|
|
CCHide *pRet = new CCHide();
|
|
|
|
|
|
|
|
if (pRet) {
|
|
|
|
pRet->autorelease();
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCHide::startWithTarget(CCNode *pTarget) {
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
pTarget->setIsVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction *CCHide::reverse() {
|
|
|
|
return (CCFiniteTimeAction*) (CCShow::action());
|
|
|
|
}
|
|
|
|
|
|
|
|
CCObject* CCHide::copyWithZone(CCZone *pZone) {
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCHide *pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCHide*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCHide();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCFiniteTimeAction::copyWithZone(pZone);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ToggleVisibility
|
|
|
|
//
|
|
|
|
CCToggleVisibility * CCToggleVisibility::action() {
|
|
|
|
CCToggleVisibility *pRet = new CCToggleVisibility();
|
|
|
|
|
|
|
|
if (pRet) {
|
|
|
|
pRet->autorelease();
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCToggleVisibility::startWithTarget(CCNode *pTarget) {
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
pTarget->setIsVisible(!pTarget->getIsVisible());
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FlipX
|
|
|
|
//
|
|
|
|
CCFlipX *CCFlipX::actionWithFlipX(bool x) {
|
|
|
|
CCFlipX *pRet = new CCFlipX();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (pRet && pRet->initWithFlipX(x)) {
|
|
|
|
pRet->autorelease();
|
2010-08-12 16:19:09 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCFlipX::initWithFlipX(bool x) {
|
|
|
|
m_bFlipX = x;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCFlipX::startWithTarget(CCNode *pTarget) {
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
((CCSprite*) (pTarget))->setFlipX(m_bFlipX);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction* CCFlipX::reverse() {
|
|
|
|
return CCFlipX::actionWithFlipX(!m_bFlipX);
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCFlipX::copyWithZone(CCZone *pZone) {
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCFlipX *pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCFlipX*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCFlipX();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-25 19:04:29 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
pRet->initWithFlipX(m_bFlipX);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// FlipY
|
|
|
|
//
|
|
|
|
CCFlipY * CCFlipY::actionWithFlipY(bool y) {
|
|
|
|
CCFlipY *pRet = new CCFlipY();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (pRet && pRet->initWithFlipY(y)) {
|
|
|
|
pRet->autorelease();
|
2011-08-25 19:04:29 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
bool CCFlipY::initWithFlipY(bool y) {
|
|
|
|
m_bFlipY = y;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCFlipY::startWithTarget(CCNode *pTarget) {
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
((CCSprite*) (pTarget))->setFlipY(m_bFlipY);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCFiniteTimeAction* CCFlipY::reverse() {
|
|
|
|
return CCFlipY::actionWithFlipY(!m_bFlipY);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCObject* CCFlipY::copyWithZone(CCZone *pZone) {
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCFlipY *pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCFlipY*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCFlipY();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-08-12 16:19:09 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
pRet->initWithFlipY(m_bFlipY);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Place
|
|
|
|
//
|
|
|
|
CCPlace* CCPlace::actionWithPosition(const CCPoint& pos) {
|
|
|
|
CCPlace *pRet = new CCPlace();
|
|
|
|
|
|
|
|
if (pRet && pRet->initWithPosition(pos)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCPlace::initWithPosition(const CCPoint& pos) {
|
|
|
|
m_tPosition = pos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCObject * CCPlace::copyWithZone(CCZone *pZone) {
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCPlace *pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCPlace*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCPlace();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
pRet->initWithPosition(m_tPosition);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
void CCPlace::startWithTarget(CCNode *pTarget) {
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
m_pTarget->setPosition(m_tPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CallFunc
|
|
|
|
//
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFunc * CCCallFunc::actionWithTarget(SelectorProtocol* pSelectorTarget,
|
|
|
|
SEL_CallFunc selector) {
|
|
|
|
CCCallFunc *pRet = new CCCallFunc();
|
|
|
|
|
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget)) {
|
|
|
|
pRet->m_pCallFunc = selector;
|
|
|
|
pRet->autorelease();
|
2011-08-25 19:04:29 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFunc* CCCallFunc::actionWithScriptFuncName(const char* pszFuncName) {
|
|
|
|
CCCallFunc *pRet = new CCCallFunc();
|
|
|
|
|
|
|
|
if (pRet && pRet->initWithScriptFuncName(pszFuncName)) {
|
|
|
|
pRet->autorelease();
|
2010-08-12 16:19:09 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCCallFunc::initWithScriptFuncName(const char *pszFuncName) {
|
|
|
|
this->m_scriptFuncName = string(pszFuncName);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCCallFunc::initWithTarget(SelectorProtocol* pSelectorTarget) {
|
2011-12-15 10:26:31 +08:00
|
|
|
if (pSelectorTarget)
|
|
|
|
{
|
|
|
|
dynamic_cast<CCObject*>(pSelectorTarget)->retain();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2011-12-15 10:26:31 +08:00
|
|
|
if (m_pSelectorTarget)
|
|
|
|
{
|
|
|
|
dynamic_cast<CCObject*>(m_pSelectorTarget)->release();
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
m_pSelectorTarget = pSelectorTarget;
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCCallFunc::copyWithZone(CCZone *pZone) {
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCallFunc* pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
//in case of being called at sub class
|
|
|
|
pRet = (CCCallFunc*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCCallFunc();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget);
|
|
|
|
pRet->m_pCallFunc = m_pCallFunc;
|
|
|
|
pRet->m_scriptFuncName = m_scriptFuncName;
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCCallFunc::startWithTarget(CCNode *pTarget) {
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
this->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCCallFunc::execute() {
|
|
|
|
if (m_pCallFunc) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFunc)();
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()) {
|
|
|
|
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFunc(
|
|
|
|
m_scriptFuncName.c_str());
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// CallFuncN
|
|
|
|
//
|
|
|
|
void CCCallFuncN::execute() {
|
|
|
|
if (m_pCallFuncN) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFuncN)(m_pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()) {
|
|
|
|
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncN(
|
|
|
|
m_scriptFuncName.c_str(), m_pTarget);
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFuncN * CCCallFuncN::actionWithTarget(SelectorProtocol* pSelectorTarget,
|
|
|
|
SEL_CallFuncN selector) {
|
|
|
|
CCCallFuncN *pRet = new CCCallFuncN();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget, selector)) {
|
|
|
|
pRet->autorelease();
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCCallFuncN* CCCallFuncN::actionWithScriptFuncName(const char *pszFuncName) {
|
|
|
|
CCCallFuncN *pRet = new CCCallFuncN();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (pRet && pRet->initWithScriptFuncName(pszFuncName)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCCallFuncN::initWithTarget(SelectorProtocol* pSelectorTarget,
|
|
|
|
SEL_CallFuncN selector) {
|
|
|
|
if (CCCallFunc::initWithTarget(pSelectorTarget)) {
|
|
|
|
m_pCallFuncN = selector;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCCallFuncN::copyWithZone(CCZone* zone) {
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
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();
|
|
|
|
zone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncN);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// CallFuncND
|
|
|
|
//
|
|
|
|
CCCallFuncND * CCCallFuncND::actionWithTarget(SelectorProtocol* pSelectorTarget,
|
|
|
|
SEL_CallFuncND selector, void* d) {
|
|
|
|
CCCallFuncND* pRet = new CCCallFuncND();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget, selector, d)) {
|
|
|
|
pRet->autorelease();
|
2010-08-05 17:22:47 +08:00
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFuncND* CCCallFuncND::actionWithScriptFuncName(const char* pszFuncName,
|
|
|
|
void *d) {
|
|
|
|
CCCallFuncND* pRet = new CCCallFuncND();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (pRet && pRet->initWithScriptFuncName(pszFuncName)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
pRet->m_pData = d;
|
|
|
|
return pRet;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCCallFuncND::initWithTarget(SelectorProtocol* pSelectorTarget,
|
|
|
|
SEL_CallFuncND selector, void* d) {
|
|
|
|
if (CCCallFunc::initWithTarget(pSelectorTarget)) {
|
|
|
|
m_pData = d;
|
|
|
|
m_pCallFuncND = selector;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCObject * CCCallFuncND::copyWithZone(CCZone* zone) {
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCallFuncND* pRet = NULL;
|
|
|
|
|
|
|
|
if (zone && zone->m_pCopyObject) {
|
|
|
|
//in case of being called at sub class
|
|
|
|
pRet = (CCCallFuncND*) (zone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCCallFuncND();
|
|
|
|
zone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncND, m_pData);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCCallFuncND::execute() {
|
|
|
|
if (m_pCallFuncND) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFuncND)(m_pTarget, m_pData);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()) {
|
|
|
|
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncND(
|
|
|
|
m_scriptFuncName.c_str(), m_pTarget, m_pData);
|
|
|
|
}
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// CCCallFuncO
|
|
|
|
//
|
|
|
|
CCCallFuncO::CCCallFuncO() :
|
|
|
|
m_pObject(NULL) {
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFuncO::~CCCallFuncO() {
|
|
|
|
CC_SAFE_RELEASE(m_pObject);
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
void CCCallFuncO::execute() {
|
|
|
|
if (m_pCallFuncO) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFuncO)(m_pObject);
|
2011-05-31 14:04:14 +08:00
|
|
|
}
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()) {
|
|
|
|
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFunc0(
|
|
|
|
m_scriptFuncName.c_str(), m_pObject);
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFuncO * CCCallFuncO::actionWithTarget(SelectorProtocol* pSelectorTarget,
|
|
|
|
SEL_CallFuncO selector, CCObject* pObject) {
|
|
|
|
CCCallFuncO *pRet = new CCCallFuncO();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget, selector, pObject)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
2011-05-31 14:04:14 +08:00
|
|
|
}
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCCallFuncO* CCCallFuncO::actionWithScriptFuncName(const char *pszFuncName) {
|
|
|
|
CCCallFuncO *pRet = new CCCallFuncO();
|
|
|
|
|
|
|
|
if (pRet && pRet->initWithScriptFuncName(pszFuncName)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
2011-06-20 17:31:38 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
bool CCCallFuncO::initWithTarget(SelectorProtocol* pSelectorTarget,
|
|
|
|
SEL_CallFuncO selector, CCObject* pObject) {
|
|
|
|
if (CCCallFunc::initWithTarget(pSelectorTarget)) {
|
|
|
|
m_pObject = pObject;
|
|
|
|
CC_SAFE_RETAIN(m_pObject)
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
m_pCallFuncO = selector;
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCCallFuncO::copyWithZone(CCZone* zone) {
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCallFuncO* pRet = NULL;
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
if (zone && zone->m_pCopyObject) {
|
|
|
|
//in case of being called at sub class
|
|
|
|
pRet = (CCCallFuncO*) (zone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCCallFuncO();
|
|
|
|
zone = pNewZone = new CCZone(pRet);
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncO, m_pObject);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
2010-11-13 11:34:49 +08:00
|
|
|
}
|