Skip to content

Commit aac2a0b

Browse files
committed
ProgressTo supports ui::Widgets with setPercent now
1 parent 8fa2c96 commit aac2a0b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

cocos/2d/CCActionProgressTimer.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ THE SOFTWARE.
2525
****************************************************************************/
2626
#include "2d/CCActionProgressTimer.h"
2727
#include "2d/CCProgressTimer.h"
28+
#include "ui/UILoadingBar.h"
2829

2930
NS_CC_BEGIN
3031

31-
#define kProgressTimerCast ProgressTimer*
32-
3332
// implementation of ProgressTo
34-
3533
ProgressTo* ProgressTo::create(float duration, float percent)
3634
{
3735
ProgressTo *progressTo = new (std::nothrow) ProgressTo();
@@ -71,12 +69,23 @@ ProgressTo* ProgressTo::reverse() const
7169
void ProgressTo::startWithTarget(Node *target)
7270
{
7371
ActionInterval::startWithTarget(target);
74-
_from = ((kProgressTimerCast)(target))->getPercentage();
72+
73+
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(target);
74+
if (loading_bar){
75+
_from = loading_bar->getPercent();
76+
} else {
77+
_from = static_cast<ProgressTimer*>(target)->getPercentage();
78+
};
7579
}
7680

7781
void ProgressTo::update(float time)
7882
{
79-
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
83+
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(_target);
84+
if (loading_bar){
85+
loading_bar->setPercent(_from + (_to - _from) * time);
86+
} else {
87+
static_cast<ProgressTimer*>(_target)->setPercentage(_from + (_to - _from) * time);
88+
};
8089
}
8190

8291
// implementation of ProgressFromTo
@@ -125,7 +134,12 @@ void ProgressFromTo::startWithTarget(Node *target)
125134

126135
void ProgressFromTo::update(float time)
127136
{
128-
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
137+
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(_target);
138+
if (loading_bar){
139+
loading_bar->setPercent(_from + (_to - _from) * time);
140+
} else {
141+
static_cast<ProgressTimer*>(_target)->setPercentage(_from + (_to - _from) * time);
142+
};
129143
}
130144

131145
NS_CC_END

0 commit comments

Comments
 (0)