diff --git a/core/2d/ProgressTimer.cpp b/core/2d/ProgressTimer.cpp index 025a5571f2..1a3fddeb2d 100644 --- a/core/2d/ProgressTimer.cpp +++ b/core/2d/ProgressTimer.cpp @@ -231,8 +231,21 @@ void ProgressTimer::updateDisplayedOpacity(uint8_t parentOpacity) { Node::updateDisplayedOpacity(parentOpacity); - _sprite->updateDisplayedOpacity(_displayedOpacity); + _displayedOpacity = _realOpacity * parentOpacity / 0xFF; + + _sprite->setOpacity(_displayedOpacity); + updateColor(); updateProgress(); + + if (_cascadeOpacityEnabled) + { + _sprite->updateDisplayedOpacity(_displayedOpacity); + + for(const auto& child : _children) + { + child->updateDisplayedOpacity(_displayedOpacity); + } + } } void ProgressTimer::updateColor() @@ -242,7 +255,11 @@ void ProgressTimer::updateColor() if (!_vertexData.empty()) { - const auto& sc = _sprite->getQuad().tl.colors; + auto sc = _sprite->getQuad().tl.colors; + sc.r = sc.r * _sprite->getOpacity() / 255.0f; + sc.g = sc.g * _sprite->getOpacity() / 255.0f; + sc.b = sc.b * _sprite->getOpacity() / 255.0f; + sc.a = sc.a * _sprite->getOpacity() / 255.0f; for (auto& d : _vertexData) { d.colors = sc; @@ -288,8 +305,12 @@ const Color3B& ProgressTimer::getColor() const void ProgressTimer::setOpacity(uint8_t opacity) { - _sprite->setOpacity(opacity); + _displayedOpacity = _realOpacity = opacity; + + _sprite->setOpacity(_displayedOpacity); updateColor(); + + updateCascadeOpacity(); } uint8_t ProgressTimer::getOpacity() const @@ -297,6 +318,11 @@ uint8_t ProgressTimer::getOpacity() const return _sprite->getOpacity(); } +uint8_t ProgressTimer::getDisplayedOpacity() const +{ + return _sprite->getDisplayedOpacity(); +} + void ProgressTimer::setMidpoint(const Vec2& midPoint) { _midpoint = midPoint.getClampPoint(Vec2::ZERO, Vec2(1, 1)); @@ -596,8 +622,8 @@ Vec2 ProgressTimer::boundaryTexCoord(char index) return Vec2((kProgressTextureCoords >> ((index << 1) + 1)) & 1, (kProgressTextureCoords >> (index << 1)) & 1); } - else - return Vec2::ZERO; + + return Vec2::ZERO; } void ProgressTimer::draw(Renderer* renderer, const Mat4& transform, uint32_t flags) diff --git a/core/2d/ProgressTimer.h b/core/2d/ProgressTimer.h index 0cc02cc502..f81a258c64 100644 --- a/core/2d/ProgressTimer.h +++ b/core/2d/ProgressTimer.h @@ -156,6 +156,7 @@ public: virtual const Color3B& getColor() const override; virtual void setOpacity(uint8_t opacity) override; virtual uint8_t getOpacity() const override; + virtual uint8_t getDisplayedOpacity() const override; /** * @js ctor