2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (C) 2010 Lam Pham
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "CCActionProgressTimer.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "misc_nodes/CCProgressTimer.h"
|
|
|
|
#include "cocoa/CCZone.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
#define kProgressTimerCast CCProgressTimer*
|
|
|
|
|
|
|
|
// implementation of CCProgressTo
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCProgressTo* CCProgressTo::create(float duration, float fPercent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCProgressTo *pProgressTo = new CCProgressTo();
|
|
|
|
pProgressTo->initWithDuration(duration, fPercent);
|
|
|
|
pProgressTo->autorelease();
|
|
|
|
|
|
|
|
return pProgressTo;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
bool CCProgressTo::initWithDuration(float duration, float fPercent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_to = fPercent;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCProgressTo* CCProgressTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCProgressTo();
|
|
|
|
a->initWithDuration(_duration, _to);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCProgressTo* CCProgressTo::reverse() const
|
|
|
|
{
|
|
|
|
CCAssert(false, "reverse() not supported in CCProgressTo");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCObject* CCProgressTo::copyWithZone(CCZone *pZone)
|
|
|
|
{
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCProgressTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
pCopy = (CCProgressTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCopy = new CCProgressTo();
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
pCopy->initWithDuration(_duration, _to);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pCopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCProgressTo::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
_from = ((kProgressTimerCast)(pTarget))->getPercentage();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// XXX: Is this correct ?
|
|
|
|
// Adding it to support CCRepeat
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_from == 100)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_from = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCProgressTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of CCProgressFromTo
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCProgressFromTo* CCProgressFromTo::create(float duration, float fFromPercentage, float fToPercentage)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCProgressFromTo *pProgressFromTo = new CCProgressFromTo();
|
|
|
|
pProgressFromTo->initWithDuration(duration, fFromPercentage, fToPercentage);
|
|
|
|
pProgressFromTo->autorelease();
|
|
|
|
|
|
|
|
return pProgressFromTo;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
bool CCProgressFromTo::initWithDuration(float duration, float fFromPercentage, float fToPercentage)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_to = fToPercentage;
|
|
|
|
_from = fFromPercentage;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCProgressFromTo* CCProgressFromTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCProgressFromTo();
|
|
|
|
a->initWithDuration(_duration, _from, _to);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCObject* CCProgressFromTo::copyWithZone(CCZone *pZone)
|
|
|
|
{
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCProgressFromTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
pCopy = (CCProgressFromTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCopy = new CCProgressFromTo();
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
pCopy->initWithDuration(_duration, _from, _to);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pCopy;
|
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCProgressFromTo* CCProgressFromTo::reverse(void) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return CCProgressFromTo::create(_duration, _to, _from);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCProgressFromTo::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCProgressFromTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|