Skip to content

Commit

Permalink
merged v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nantas committed May 11, 2016
2 parents aeb5b65 + 00325b9 commit 3e396e3
Show file tree
Hide file tree
Showing 26 changed files with 1,667 additions and 618 deletions.
10 changes: 8 additions & 2 deletions cocos2d/compression/ZipUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ cc.Codec.unzip = function () {
* @returns {String} Unpacked byte string
*/
cc.Codec.unzipBase64 = function () {
var tmpInput = cc.Codec.Base64.decode.apply(cc.Codec.Base64, arguments);
return cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, [tmpInput]);
var buffer = cc.Codec.Base64.decode.apply(cc.Codec.Base64, arguments);
try {
return cc.Codec.GZip.gunzip.call(cc.Codec.GZip, buffer);
}
catch(e) {
// if not zipped, just skip
return buffer.slice(7); // get image data
}
};

/**
Expand Down
20 changes: 20 additions & 0 deletions cocos2d/core/components/CCButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,17 @@ var Button = cc.Class({
if (!this.target) {
this.target = this.node;
}
},

onEnable: function () {
if (!CC_EDITOR) {
this._registerEvent();
} else {
this.node.on('spriteframe-changed', function(event) {
if (this.transition === Transition.SPRITE) {
this.normalSprite = event.detail.spriteFrame;
}
}.bind(this));
}
},

Expand Down Expand Up @@ -446,6 +454,18 @@ var Button = cc.Class({
onDisable: function() {
this._hovered = false;
this._pressed = false;

if (!CC_EDITOR) {
this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this);
this.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this);
this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);

this.node.off(cc.Node.EventType.MOUSE_ENTER, this._onMouseMoveIn, this);
this.node.off(cc.Node.EventType.MOUSE_LEAVE, this._onMouseMoveOut, this);
} else {
this.node.off('spriteframe-changed');
}
},

_applyTransition: function (color, sprite) {
Expand Down
16 changes: 8 additions & 8 deletions cocos2d/core/components/CCLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ var Layout = cc.Class({
var row = 0;
var containerResizeBoundary;

var maxHeightChildAnchor;
var maxHeightChildAnchorY = 0;

var newChildWidth = this.cellSize.width;
if (this.type !== Type.GRID && this.resizeMode === ResizeMode.CHILDREN) {
Expand Down Expand Up @@ -436,7 +436,7 @@ var Layout = cc.Class({
if (child.height >= tempMaxHeight) {
secondMaxHeight = tempMaxHeight;
tempMaxHeight = child.height;
maxHeightChildAnchor = child.getAnchorPoint();
maxHeightChildAnchorY = child.getAnchorPoint().y;
}

if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) {
Expand Down Expand Up @@ -483,14 +483,14 @@ var Layout = cc.Class({
if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) {
containerResizeBoundary = containerResizeBoundary || this.node._contentSize.height;
signX = -1;
tempFinalPositionY = finalPositionY + signX * (topMarign * maxHeightChildAnchor.y + this.padding);
tempFinalPositionY = finalPositionY + signX * (topMarign * maxHeightChildAnchorY + this.padding);
if (tempFinalPositionY < containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionY;
}
}
else {
containerResizeBoundary = containerResizeBoundary || -this.node._contentSize.height;
tempFinalPositionY = finalPositionY + signX * (topMarign * maxHeightChildAnchor.y + this.padding);
tempFinalPositionY = finalPositionY + signX * (topMarign * maxHeightChildAnchorY + this.padding);
if (tempFinalPositionY > containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionY;
}
Expand Down Expand Up @@ -534,7 +534,7 @@ var Layout = cc.Class({
var secondMaxWidth = 0;
var column = 0;
var containerResizeBoundary;
var maxWidthChildAnchor;
var maxWidthChildAnchorX = 0;

var newChildHeight = this.cellSize.height;
if (this.type !== Type.GRID && this.resizeMode === ResizeMode.CHILDREN) {
Expand Down Expand Up @@ -563,7 +563,7 @@ var Layout = cc.Class({
if (child.width >= tempMaxWidth) {
secondMaxWidth = tempMaxWidth;
tempMaxWidth = child.width;
maxWidthChildAnchor = child.getAnchorPoint();
maxWidthChildAnchorX = child.getAnchorPoint().x;
}

if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) {
Expand Down Expand Up @@ -610,14 +610,14 @@ var Layout = cc.Class({
if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) {
signX = -1;
containerResizeBoundary = containerResizeBoundary || this.node._contentSize.width;
tempFinalPositionX = finalPositionX + signX * (rightMarign * maxWidthChildAnchor.x + this.padding);
tempFinalPositionX = finalPositionX + signX * (rightMarign * maxWidthChildAnchorX + this.padding);
if (tempFinalPositionX < containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionX;
}
}
else {
containerResizeBoundary = containerResizeBoundary || -this.node._contentSize.width;
tempFinalPositionX = finalPositionX + signX * (rightMarign * maxWidthChildAnchor.x + this.padding);
tempFinalPositionX = finalPositionX + signX * (rightMarign * maxWidthChildAnchorX + this.padding);
if (tempFinalPositionX > containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionX;
}
Expand Down
2 changes: 2 additions & 0 deletions cocos2d/core/components/CCScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ var ScrollView = cc.Class({
var anchor = options.anchor;
var applyToHorizontal = options.applyToHorizontal;
var applyToVertical = options.applyToVertical;
this._calculateBoundary();

anchor = cc.pClamp(anchor, cc.p(0, 0), cc.p(1, 1));

Expand Down Expand Up @@ -694,6 +695,7 @@ var ScrollView = cc.Class({

_handlePressLogic: function() {
this._autoScrolling = false;
this._calculateBoundary();

this._touchMovePreviousTimestamp = getTimeInMilliseconds();
this._touchMoveDisplacements = [];
Expand Down
6 changes: 6 additions & 0 deletions cocos2d/core/components/CCSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,15 @@ var Sprite = cc.Class({
return this._spriteFrame;
},
set: function (value, force) {
if (this._spriteFrame === value) {
return;
}
var lastSprite = this._spriteFrame;
this._spriteFrame = value;
this._applySpriteFrame(lastSprite);
if (CC_EDITOR) {
this.node.emit('spriteframe-changed', this);
}
},
type: cc.SpriteFrame,
},
Expand Down
75 changes: 59 additions & 16 deletions cocos2d/core/load-pipeline/CCLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,17 @@ JS.mixin(cc.loader, {
},

_resources: resources,
_getResUuid: function (url) {
var uuid = resources.getUuid(url);
_getResUuid: function (url, type) {
var uuid = resources.getUuid(url, type);
if ( !uuid ) {
var extname = cc.path.extname(url);
if (extname) {
//cc.warn('Don\'t add extension for "%s".', url);
// strip extname
url = url.slice(0, - extname.length);
uuid = resources.getUuid(url);
uuid = resources.getUuid(url, type);
if (uuid) {
cc.warn('loadRes: should not specify the extname in ' + url + extname);
}
}
}
return uuid;
Expand All @@ -261,23 +263,37 @@ JS.mixin(cc.loader, {
* @method loadRes
* @param {String} url - Url of the target resource.
* The url is relative to the "resources" folder, extensions must be omitted.
* @param {Function} [type] - Only asset of type will be loaded if this argument is supplied.
* @param {Function} completeCallback - Callback invoked when the resource loaded.
* @param {Error} completeCallback.error - The error info or null if loaded successfully.
* @param {Object} completeCallback.resource - The loaded resource if it can be found otherwise returns null.
*
* @example
*
* // load the prefab (project/assets/resources/misc/character/cocos) from resources folder
* cc.loader.loadRes('misc/character/cocos', function (err, prefab) {
* if (err) {
* cc.error(err.message || err);
* return;
* }
* cc.log('Result should be a prefab: ' + (prefab instanceof cc.Prefab));
* });
*
* // load the sprite frame (project/assets/resources/imgs/cocos.png/cocos) from resources folder
* cc.loader.loadRes('imgs/cocos.png/cocos', function (err, spriteFrame) {
* cc.loader.loadRes('imgs/cocos', cc.SpriteFrame, function (err, spriteFrame) {
* if (err) {
* cc.error(err.message || err);
* return;
* }
* cc.log('Result should be a sprite frame: ' + ( spriteFrame instanceof cc.SpriteFrame));
* cc.log('Result should be a sprite frame: ' + (spriteFrame instanceof cc.SpriteFrame));
* });
*/
loadRes: function (url, completeCallback) {
var uuid = this._getResUuid(url);
loadRes: function (url, type, completeCallback) {
if (!completeCallback && type && !cc.isChildClassOf(type, cc.RawAsset)) {
completeCallback = type;
type = null;
}
var uuid = this._getResUuid(url, type);
if (uuid) {
this.load(
{
Expand All @@ -290,7 +306,14 @@ JS.mixin(cc.loader, {
}
else {
callInNextTick(function () {
completeCallback.call(null, new Error('Resources url "' + url + '" does not exist.'), null);
var info;
if (type) {
info = cc.js.getClassName(type) + ' in "' + url + '" does not exist.';
}
else {
info = 'Resources url "' + url + '" does not exist.';
}
completeCallback(new Error(info), null);
});
}
},
Expand All @@ -302,25 +325,40 @@ JS.mixin(cc.loader, {
*
* @method loadResAll
* @param {String} url - Url of the target folder.
* The url is relative to the "resources" folder.
* The url is relative to the "resources" folder, extensions must be omitted.
* @param {Function} [type] - Only asset of type will be loaded if this argument is supplied.
* @param {Function} completeCallback - A callback which is called when all assets have been loaded, or an error occurs.
* @param {Error} completeCallback.error - If one of the asset failed, the complete callback is immediately called with the error. If all assets are loaded successfully, error will be null.
* @param {Object[]} completeCallback.assets - An array of all loaded assets. If nothing to load, assets will be an empty array. If error occurs, assets will be null.
*
* @example
*
* // load the sprite frame (project/assets/resources/imgs/cocos.png/cocos) from resources folder
* cc.loader.loadResAll('imgs/cocos.png', function (err, assets) {
* // load the texture (resources/imgs/cocos.png) and sprite frame (resources/imgs/cocos.png/cocos)
* cc.loader.loadResAll('imgs/cocos', function (err, assets) {
* if (err) {
* cc.error(err);
* return;
* }
* var texture = assets[0];
* var spriteFrame = assets[1];
* });
*
* // load all textures in "resources/imgs/"
* cc.loader.loadResAll('imgs', cc.Texture2D, function (err, textures) {
* if (err) {
* cc.error(err);
* return;
* }
* var texture1 = textures[0];
* var texture2 = textures[1];
* });
*/
loadResAll: function (url, completeCallback) {
var uuids = resources.getUuidArray(url);
loadResAll: function (url, type, completeCallback) {
if (!completeCallback && type && !cc.isChildClassOf(type, cc.RawAsset)) {
completeCallback = type;
type = null;
}
var uuids = resources.getUuidArray(url, type);
var remain = uuids.length;
if (remain > 0) {
var results = [];
Expand Down Expand Up @@ -354,7 +392,7 @@ JS.mixin(cc.loader, {
}
else {
callInNextTick(function () {
completeCallback.call(null, null, []);
completeCallback(null, []);
});
}
},
Expand All @@ -370,7 +408,12 @@ JS.mixin(cc.loader, {
* @returns {*}
*/
getRes: function (url) {
return this._items.getContent(url);
var item = this._items.getContent(url);
if (!item) {
var uuid = this._getResUuid(url);
item = this._items.getContent(uuid);
}
return item;
},

/**
Expand Down
Loading

0 comments on commit 3e396e3

Please sign in to comment.