Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ui::LoadingBar support to Progress actions #18748

Merged
merged 1 commit into from
Nov 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions cocos/2d/CCActionProgressTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ THE SOFTWARE.
****************************************************************************/
#include "2d/CCActionProgressTimer.h"
#include "2d/CCProgressTimer.h"
#include "ui/UILoadingBar.h"

NS_CC_BEGIN

#define kProgressTimerCast ProgressTimer*

// implementation of ProgressTo

ProgressTo* ProgressTo::create(float duration, float percent)
{
ProgressTo *progressTo = new (std::nothrow) ProgressTo();
Expand All @@ -41,7 +41,6 @@ ProgressTo* ProgressTo::create(float duration, float percent)
progressTo->autorelease();
return progressTo;
}

delete progressTo;
return nullptr;
}
Expand Down Expand Up @@ -73,12 +72,23 @@ ProgressTo* ProgressTo::reverse() const
void ProgressTo::startWithTarget(Node *target)
{
ActionInterval::startWithTarget(target);
_from = ((kProgressTimerCast)(target))->getPercentage();

ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(target);
if (loading_bar){
_from = loading_bar->getPercent();
} else {
_from = static_cast<ProgressTimer*>(target)->getPercentage();
};
}

void ProgressTo::update(float time)
{
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(_target);
if (loading_bar){
loading_bar->setPercent(_from + (_to - _from) * time);
} else {
static_cast<ProgressTimer*>(_target)->setPercentage(_from + (_to - _from) * time);
};
}

// implementation of ProgressFromTo
Expand All @@ -90,14 +100,14 @@ ProgressFromTo* ProgressFromTo::create(float duration, float fromPercentage, flo
progressFromTo->autorelease();
return progressFromTo;
}

delete progressFromTo;
return nullptr;
}

bool ProgressFromTo::initWithDuration(float duration, float fromPercentage, float toPercentage)
{
if (ActionInterval::initWithDuration(duration))
if (ActionInterval::initWithDuration(duration))
{
_to = toPercentage;
_from = fromPercentage;
Expand Down Expand Up @@ -127,7 +137,12 @@ void ProgressFromTo::startWithTarget(Node *target)

void ProgressFromTo::update(float time)
{
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(_target);
if (loading_bar){
loading_bar->setPercent(_from + (_to - _from) * time);
} else {
static_cast<ProgressTimer*>(_target)->setPercentage(_from + (_to - _from) * time);
};
}

NS_CC_END