2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (C) 2010 Lam Pham
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionProgressTimer.h"
|
|
|
|
#include "2d/CCProgressTimer.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
#define kProgressTimerCast ProgressTimer*
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of ProgressTo
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
ProgressTo* ProgressTo::create(float duration, float percent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ProgressTo* progressTo = new ProgressTo();
|
2021-12-08 00:11:53 +08:00
|
|
|
if (progressTo->initWithDuration(duration, percent))
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
|
|
|
progressTo->autorelease();
|
|
|
|
return progressTo;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete progressTo;
|
|
|
|
return nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ProgressTo::initWithDuration(float duration, float percent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
_to = percent;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ProgressTo* ProgressTo::clone() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
|
|
|
return ProgressTo::create(_duration, _to);
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ProgressTo* ProgressTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(false, "reverse() not supported in ProgressTo");
|
2015-01-08 10:22:45 +08:00
|
|
|
return nullptr;
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ProgressTo::startWithTarget(Node* target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_from = ((kProgressTimerCast)(target))->getPercentage();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ProgressTo::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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of ProgressFromTo
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
ProgressFromTo* ProgressFromTo::create(float duration, float fromPercentage, float toPercentage)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ProgressFromTo* progressFromTo = new ProgressFromTo();
|
|
|
|
if (progressFromTo->initWithDuration(duration, fromPercentage, toPercentage))
|
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
progressFromTo->autorelease();
|
|
|
|
return progressFromTo;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete progressFromTo;
|
|
|
|
return nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ProgressFromTo::initWithDuration(float duration, float fromPercentage, float toPercentage)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_to = toPercentage;
|
2013-12-18 17:47:20 +08:00
|
|
|
_from = fromPercentage;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ProgressFromTo* ProgressFromTo::clone() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
|
|
|
return ProgressFromTo::create(_duration, _from, _to);
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
ProgressFromTo* ProgressFromTo::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return ProgressFromTo::create(_duration, _to, _from);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ProgressFromTo::startWithTarget(Node* target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ProgressFromTo::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
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|