From eb8611c55b3f48c8111ce2bde1e1cc58b2684230 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Thu, 8 Jun 2017 17:11:20 +0800 Subject: [PATCH 1/2] improve progressbar, make error msg explicitly --- cocos2d/core/components/CCProgressBar.js | 46 ++++++++++++++++-------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/cocos2d/core/components/CCProgressBar.js b/cocos2d/core/components/CCProgressBar.js index 8a12678d96..a8ef8b01cc 100644 --- a/cocos2d/core/components/CCProgressBar.js +++ b/cocos2d/core/components/CCProgressBar.js @@ -154,25 +154,34 @@ var ProgressBar = cc.Class({ totalWidth = entitySize.width; totalHeight = this.totalLength; break; - case Mode.FILLED: + } + + //handling filled mode + if (this.mode === Mode.FILLED) { + if (this.barSprite.type !== cc.Sprite.Type.FILLED) { + cc.warn('ProgressBar FILLED mode only works when barSprite\'s Type is FILLED!'); + } else { if (this.reverse) { actualLenth = actualLenth * -1; } this.barSprite.fillRange = actualLenth; - break; + } + } else { + if (this.barSprite.type !== cc.Sprite.Type.FILLED) { + + var anchorOffsetX = anchorPoint.x - entityAnchorPoint.x; + var anchorOffsetY = anchorPoint.y - entityAnchorPoint.y; + var finalPosition = cc.p(totalWidth * anchorOffsetX, totalHeight * anchorOffsetY); + + entity.setPosition(cc.pAdd(entityPosition, finalPosition)); + + entity.setAnchorPoint(anchorPoint); + entity.setContentSize(finalContentSize); + } else { + cc.warn('ProgressBar non-FILLED mode only works when barSprite\'s Type is non-FILLED!'); + } } - if (this.barSprite.type !== cc.Sprite.Type.FILLED) { - - var anchorOffsetX = anchorPoint.x - entityAnchorPoint.x; - var anchorOffsetY = anchorPoint.y - entityAnchorPoint.y; - var finalPosition = cc.p(totalWidth * anchorOffsetX, totalHeight * anchorOffsetY); - - entity.setPosition(cc.pAdd(entityPosition, finalPosition)); - - entity.setAnchorPoint(anchorPoint); - entity.setContentSize(finalContentSize); - } } @@ -221,16 +230,23 @@ var ProgressBar = cc.Class({ animatable: false }, + _totalLength: 1, /** * !#en The total width or height of the bar sprite. * !#zh 进度条实际的总长度 * @property {Number} totalLength */ totalLength: { - default: 1, range: [0, Number.MAX_VALUE], tooltip: CC_DEV && 'i18n:COMPONENT.progress.total_length', - notify: function(value) { + get: function () { + return this._totalLength; + }, + set: function(value) { + if (this.mode === Mode.FILLED) { + value = cc.clamp01(value); + } + this._totalLength = value; this._updateBarStatus(); } }, From 41896dbc012ed9691ee449f423c5534cd636dfa1 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Thu, 8 Jun 2017 17:19:43 +0800 Subject: [PATCH 2/2] improve project data back compatibility --- cocos2d/core/components/CCProgressBar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/components/CCProgressBar.js b/cocos2d/core/components/CCProgressBar.js index a8ef8b01cc..fd9aefd381 100644 --- a/cocos2d/core/components/CCProgressBar.js +++ b/cocos2d/core/components/CCProgressBar.js @@ -230,7 +230,7 @@ var ProgressBar = cc.Class({ animatable: false }, - _totalLength: 1, + _N$totalLength: 1, /** * !#en The total width or height of the bar sprite. * !#zh 进度条实际的总长度 @@ -240,13 +240,13 @@ var ProgressBar = cc.Class({ range: [0, Number.MAX_VALUE], tooltip: CC_DEV && 'i18n:COMPONENT.progress.total_length', get: function () { - return this._totalLength; + return this._N$totalLength; }, set: function(value) { if (this.mode === Mode.FILLED) { value = cc.clamp01(value); } - this._totalLength = value; + this._N$totalLength = value; this._updateBarStatus(); } },