Skip to content

Commit e5b77ad

Browse files
tankorsmashdrelaptop
authored andcommitted
add ui::LoadingBar support to Progress actions (#18748)
Just checked for the loading bar target and cast appropriately. I made this edit in Github, but the source edit was from my old fork that I can't get to merge in tankorsmash/cocos2dx-mytracker@aac2a0b
1 parent 4315f56 commit e5b77ad

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

cocos/2d/CCActionProgressTimer.cpp

+22-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ THE SOFTWARE.
2626
****************************************************************************/
2727
#include "2d/CCActionProgressTimer.h"
2828
#include "2d/CCProgressTimer.h"
29+
#include "ui/UILoadingBar.h"
2930

3031
NS_CC_BEGIN
3132

3233
#define kProgressTimerCast ProgressTimer*
3334

3435
// implementation of ProgressTo
35-
3636
ProgressTo* ProgressTo::create(float duration, float percent)
3737
{
3838
ProgressTo *progressTo = new (std::nothrow) ProgressTo();
@@ -41,7 +41,6 @@ ProgressTo* ProgressTo::create(float duration, float percent)
4141
progressTo->autorelease();
4242
return progressTo;
4343
}
44-
4544
delete progressTo;
4645
return nullptr;
4746
}
@@ -73,12 +72,23 @@ ProgressTo* ProgressTo::reverse() const
7372
void ProgressTo::startWithTarget(Node *target)
7473
{
7574
ActionInterval::startWithTarget(target);
76-
_from = ((kProgressTimerCast)(target))->getPercentage();
75+
76+
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(target);
77+
if (loading_bar){
78+
_from = loading_bar->getPercent();
79+
} else {
80+
_from = static_cast<ProgressTimer*>(target)->getPercentage();
81+
};
7782
}
7883

7984
void ProgressTo::update(float time)
8085
{
81-
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
86+
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(_target);
87+
if (loading_bar){
88+
loading_bar->setPercent(_from + (_to - _from) * time);
89+
} else {
90+
static_cast<ProgressTimer*>(_target)->setPercentage(_from + (_to - _from) * time);
91+
};
8292
}
8393

8494
// implementation of ProgressFromTo
@@ -90,14 +100,14 @@ ProgressFromTo* ProgressFromTo::create(float duration, float fromPercentage, flo
90100
progressFromTo->autorelease();
91101
return progressFromTo;
92102
}
93-
103+
94104
delete progressFromTo;
95105
return nullptr;
96106
}
97107

98108
bool ProgressFromTo::initWithDuration(float duration, float fromPercentage, float toPercentage)
99109
{
100-
if (ActionInterval::initWithDuration(duration))
110+
if (ActionInterval::initWithDuration(duration))
101111
{
102112
_to = toPercentage;
103113
_from = fromPercentage;
@@ -127,7 +137,12 @@ void ProgressFromTo::startWithTarget(Node *target)
127137

128138
void ProgressFromTo::update(float time)
129139
{
130-
((kProgressTimerCast)(_target))->setPercentage(_from + (_to - _from) * time);
140+
ui::LoadingBar* loading_bar = dynamic_cast<ui::LoadingBar*>(_target);
141+
if (loading_bar){
142+
loading_bar->setPercent(_from + (_to - _from) * time);
143+
} else {
144+
static_cast<ProgressTimer*>(_target)->setPercentage(_from + (_to - _from) * time);
145+
};
131146
}
132147

133148
NS_CC_END

0 commit comments

Comments
 (0)