mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge pull request #341 from zilongshanren/improveProgressBar
add radial mode to progressbar
This commit is contained in:
@@ -36,7 +36,11 @@ var Mode = cc.Enum({
|
||||
/**
|
||||
* @property {Number} VERTICAL
|
||||
*/
|
||||
VERTICAL: 1
|
||||
VERTICAL: 1,
|
||||
/**
|
||||
* @property {Number} RADIAL
|
||||
*/
|
||||
RADIAL: 2,
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -55,6 +59,7 @@ var ProgressBar = cc.Class({
|
||||
_initBarSprite: function() {
|
||||
if (this.barSprite) {
|
||||
var entity = this.barSprite.node;
|
||||
if (!entity) return;
|
||||
|
||||
var nodeSize = this.node.getContentSize();
|
||||
var nodeAnchor = this.node.getAnchorPoint();
|
||||
@@ -65,12 +70,20 @@ var ProgressBar = cc.Class({
|
||||
this.node.setContentSize(entitySize);
|
||||
}
|
||||
|
||||
if (this.barSprite.fillType === cc.Sprite.FillType.RADIAL) {
|
||||
this.mode = Mode.RADIAL;
|
||||
}
|
||||
|
||||
var barSpriteSize = entity.getContentSize();
|
||||
if (this.mode === Mode.HORIZONTAL) {
|
||||
this.totalLength = barSpriteSize.width;
|
||||
} else {
|
||||
}
|
||||
else if(this.mode === Mode.VERTICAL) {
|
||||
this.totalLength = barSpriteSize.height;
|
||||
}
|
||||
else {
|
||||
this.totalLength = this.barSprite.fillRange;
|
||||
}
|
||||
|
||||
if(entity.parent === this.node){
|
||||
var x = - nodeSize.width * nodeAnchor.x;
|
||||
@@ -83,6 +96,9 @@ var ProgressBar = cc.Class({
|
||||
_updateBarStatus: function() {
|
||||
if (this.barSprite) {
|
||||
var entity = this.barSprite.node;
|
||||
|
||||
if (!entity) return;
|
||||
|
||||
var entityAnchorPoint = entity.getAnchorPoint();
|
||||
var entitySize = entity.getContentSize();
|
||||
var entityPosition = entity.getPosition();
|
||||
@@ -110,17 +126,24 @@ var ProgressBar = cc.Class({
|
||||
finalContentSize = cc.size(entitySize.width, actualLenth);
|
||||
totalWidth = entitySize.width;
|
||||
totalHeight = this.totalLength;
|
||||
break;
|
||||
case Mode.RADIAL:
|
||||
this.barSprite.fillRange = actualLenth;
|
||||
break;
|
||||
}
|
||||
|
||||
var anchorOffsetX = anchorPoint.x - entityAnchorPoint.x;
|
||||
var anchorOffsetY = anchorPoint.y - entityAnchorPoint.y;
|
||||
if (this.barSprite.type !== cc.Sprite.Type.FILLED) {
|
||||
|
||||
var finalPosition = cc.p(totalWidth * anchorOffsetX, totalHeight * anchorOffsetY);
|
||||
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.setPosition(cc.pAdd(entityPosition, finalPosition));
|
||||
|
||||
entity.setAnchorPoint(anchorPoint);
|
||||
entity.setContentSize(finalContentSize);
|
||||
}
|
||||
|
||||
entity.setAnchorPoint(anchorPoint);
|
||||
entity.setContentSize(finalContentSize);
|
||||
|
||||
}
|
||||
},
|
||||
@@ -151,11 +174,15 @@ var ProgressBar = cc.Class({
|
||||
notify: function() {
|
||||
if (this.barSprite) {
|
||||
var entity = this.barSprite.node;
|
||||
if (!entity) return;
|
||||
|
||||
var entitySize = entity.getContentSize();
|
||||
if (this.mode === Mode.HORIZONTAL) {
|
||||
this.totalLength = entitySize.width;
|
||||
} else if (this.mode === Mode.VERTICAL) {
|
||||
this.totalLength = entitySize.height;
|
||||
} else if (this.mode === Mode.RADIAL) {
|
||||
this.totalLength = this.barSprite.fillRange;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -170,7 +170,7 @@ var Sprite = cc.Class({
|
||||
return this._fillStart;
|
||||
},
|
||||
set: function(value) {
|
||||
this._fillStart = value;
|
||||
this._fillStart = cc.clamp01(value);
|
||||
this._sgNode && this._sgNode.setFillStart(value);
|
||||
},
|
||||
},
|
||||
@@ -180,7 +180,7 @@ var Sprite = cc.Class({
|
||||
return this._fillRange;
|
||||
},
|
||||
set: function(value) {
|
||||
this._fillRange = value;
|
||||
this._fillRange = cc.clamp01(value);
|
||||
this._sgNode && this._sgNode.setFillRange(value);
|
||||
},
|
||||
},
|
||||
@@ -236,6 +236,12 @@ var Sprite = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
statics: {
|
||||
FillType: FillType,
|
||||
Type: SpriteType,
|
||||
SizeMode: SizeMode,
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets whether the sprite is visible or not.
|
||||
* @method setVisible
|
||||
|
||||
Reference in New Issue
Block a user