From 76b8ae027a0b241c5ced597389839441af19f82c Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 8 Aug 2017 16:54:57 +0800 Subject: [PATCH 01/14] adjustment CCLayout code fix fireball/issues/6218 --- cocos2d/core/components/CCLayout.js | 53 ++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 0edf2e526e..49079edf1d 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -402,7 +402,9 @@ var Layout = cc.Class({ this._N$padding = 0; }, - __preload: function() { + onEnable: function() { + this._addEventListeners(); + if(cc.sizeEqualToSize(this.node.getContentSize(), cc.size(0, 0))) { this.node.setContentSize(this._layoutSize); } @@ -411,23 +413,40 @@ var Layout = cc.Class({ this._migratePaddingData(); } - this.node.on('size-changed', this._resized, this); + this._doLayoutDirty(); + }, + onDisable: function () { + this._removeEventListeners(); + }, + + _doLayoutDirty : function () { + this._layoutDirty = true; + }, + + _addEventListeners: function () { + cc.director.on(cc.Director.EVENT_BEFORE_VISIT, this._updateLayout, this); + this.node.on('size-changed', this._resized, this); this.node.on('anchor-changed', this._doLayoutDirty, this); this.node.on('child-added', this._childAdded, this); this.node.on('child-removed', this._childRemoved, this); this.node.on('child-reorder', this._doLayoutDirty, this); - - this._updateChildrenEventListener(); + this._addChildrenEventListeners(); }, - _doLayoutDirty : function() { - this._layoutDirty = true; + _removeEventListeners: function () { + cc.director.off(cc.Director.EVENT_BEFORE_VISIT, this._updateLayout, this); + this.node.off('size-changed', this._resized, this); + this.node.off('anchor-changed', this._doLayoutDirty, this); + this.node.off('child-added', this._childAdded, this); + this.node.off('child-removed', this._childRemoved, this); + this.node.off('child-reorder', this._doLayoutDirty, this); + this._removeChildrenEventListeners(); }, - _updateChildrenEventListener: function() { + _addChildrenEventListeners: function() { var children = this.node.children; - children.forEach(function(child) { + children.forEach(function (child) { child.on('size-changed', this._doLayoutDirty, this); child.on('position-changed', this._doLayoutDirty, this); child.on('anchor-changed', this._doLayoutDirty, this); @@ -435,6 +454,16 @@ var Layout = cc.Class({ }.bind(this)); }, + _removeChildrenEventListeners: function () { + var children = this.node.children; + children.forEach(function (child) { + child.off('size-changed', this._doLayoutDirty, this); + child.off('position-changed', this._doLayoutDirty, this); + child.off('anchor-changed', this._doLayoutDirty, this); + child.off('active-in-hierarchy-changed', this._doLayoutDirty, this); + }.bind(this)); + }, + _childAdded: function(event) { var child = event.detail; child.on('size-changed', this._doLayoutDirty, this); @@ -894,14 +923,6 @@ var Layout = cc.Class({ } }, - onEnable: function () { - cc.director.on(cc.Director.EVENT_BEFORE_VISIT, this._updateLayout, this); - }, - - onDisable: function () { - cc.director.off(cc.Director.EVENT_BEFORE_VISIT, this._updateLayout, this); - }, - _updateLayout: function() { if (this._layoutDirty && this.node.children.length > 0) { this._doLayout(); From 363aed3e2fd97e7f334ed37a81ed8da6fcbda26e Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Sat, 12 Aug 2017 10:28:53 +0800 Subject: [PATCH 02/14] update doc --- extensions/spine/Skeleton.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index c31b13791f..91f1d1a726 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -672,8 +672,12 @@ sp.Skeleton = cc.Class({ }, /** - * !#en Sets skeleton data to sp.Skeleton. - * !#zh 设置 Skeleton 中的 Skeleton Data。 + * !#en + * Sets runtime skeleton data to sp.Skeleton.
+ * This method is different from the `skeletonData` property. This method is passed in the raw data provided by the Spine runtime, and the skeletonData type is the asset type provided by Creator. + * !#zh + * 设置底层运行时用到的 SkeletonData。
+ * 这个接口有别于 `skeletonData` 属性,这个接口传入的是 Spine runtime 提供的原始数据,而 skeletonData 的类型是 Creator 提供的资源类型。 * @method setSkeletonData * @param {sp.spine.SkeletonData} skeletonData * @param {sp.spine.SkeletonData} ownsSkeletonData From dc703aa96bce68cb6f1de4cf9197948014516116 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 15 Aug 2017 18:15:38 +0800 Subject: [PATCH 03/14] Repair outline bug for fireball/issues/6254 and fireball/issues/6258 --- jsb/jsb-label.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/jsb/jsb-label.js b/jsb/jsb-label.js index c5fe42b5c5..f59df1ef41 100644 --- a/jsb/jsb-label.js +++ b/jsb/jsb-label.js @@ -60,7 +60,7 @@ jsbLabel.prototype.getOverflow = function() { jsbLabel.prototype._enableBold = jsbLabel.prototype.enableBold; jsbLabel.prototype.enableBold = function(enabled) { - if(enabled) { + if (enabled) { this._enableBold(); } else { this.disableEffect(5); @@ -69,7 +69,7 @@ jsbLabel.prototype.enableBold = function(enabled) { jsbLabel.prototype._enableItalics = jsbLabel.prototype.enableItalics; jsbLabel.prototype.enableItalics = function(enabled) { - if(enabled) { + if (enabled) { this._enableItalics(); } else { this.disableEffect(4); @@ -78,7 +78,7 @@ jsbLabel.prototype.enableItalics = function(enabled) { jsbLabel.prototype._enableUnderline = jsbLabel.prototype.enableUnderline; jsbLabel.prototype.enableUnderline = function(enabled) { - if(enabled) { + if (enabled) { this._enableUnderline(); } else { this.disableEffect(6); @@ -117,7 +117,7 @@ jsbLabel.prototype.setLineHeight = function (height) { jsbLabel.prototype._setColor = jsbLabel.prototype.setColor; jsbLabel.prototype.setColor = function(color) { - if(this._labelType === _ccsg.Label.Type.BMFont) { + if (this._labelType === _ccsg.Label.Type.BMFont) { this._setColor(color); } else { this.setTextColor(color); @@ -141,7 +141,7 @@ jsbLabel.prototype.setContentSize = function (size, height) { var newWidth = (typeof size.width === 'number') ? size.width : size; var newHeight = (typeof size.height === 'number') ? size.height : height; - if(this.getOverflow() === cc.Label.Overflow.NONE) { + if (this.getOverflow() === cc.Label.Overflow.NONE) { newWidth = 0; newHeight = 0; } else { @@ -161,18 +161,22 @@ jsbLabel.prototype.setFontAsset = function (fontAsset) { var extName = cc.path.extname(fontHandle); if (extName === '.ttf') { - if(!this._ttfConfig) { + var outlineWidth = this.isOutlined() ? this.getOutlineWidth() : 0; + if (!this._ttfConfig) { this._ttfConfig = { fontFilePath: fontHandle, fontSize: this._fontSize, - outlineSize: 0, + outlineSize: outlineWidth, glyphs: 0, customGlyphs: "", distanceFieldEnable: false }; } + else { + this._ttfConfig.outlineSize = outlineWidth; + this._ttfConfig.fontFilePath = fontHandle; + } this._labelType = _ccsg.Label.Type.TTF; - this._ttfConfig.fontFilePath = fontHandle; this.setTTFConfig(this._ttfConfig); } else if (fontAsset.spriteFrame) { this._labelType = _ccsg.Label.Type.BMFont; @@ -194,7 +198,7 @@ jsbLabel.prototype.setFontFamily = function (fontFamily) { jsbLabel.prototype.setOutlined = function(value) { this._outlined = !!value; - if(this._outlined) { + if (this._outlined) { this.enableOutline(this.getOutlineColor(), this.getOutlineWidth()); } else { //1 equals cpp outline effect @@ -204,14 +208,24 @@ jsbLabel.prototype.setOutlined = function(value) { jsbLabel.prototype.setOutlineWidth = function(value) { this._outlineWidth = value; - if(this._outlined) { - this.enableOutline(this.getOutlineColor(), this.getOutlineWidth()); + if (this._outlined) { + var outlineWidth = this.getOutlineWidth(); + if (this._labelType === _ccsg.Label.Type.TTF) { + var ttfConfig = this.getTTFConfig(); + if (ttfConfig.outlineSize !== outlineWidth) { + ttfConfig.outlineSize = outlineWidth; + this.setTTFConfig(ttfConfig); + } + } + else { + this.enableOutline(this.getOutlineColor(), outlineWidth); + } } }; jsbLabel.prototype.setOutlineColor = function(value) { this._outlineColor = cc.color(value); - if(this._outlined) { + if (this._outlined) { this.enableOutline(this.getOutlineColor(), this.getOutlineWidth()); } }; From eed3cc2d0ffea32f06cc69ac856ea6ef55215038 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 15 Aug 2017 22:08:53 +0800 Subject: [PATCH 04/14] fix deserialization about TypeScript --- cocos2d/core/CCDirector.js | 8 +++++--- cocos2d/core/platform/deserialize.js | 7 +++++-- test/qunit/unit/test-class.js | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index b78153185f..71647a6fac 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -878,9 +878,11 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ /** * !#en - * set color for clear screen.
- * Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js - * !#zh 设置场景的默认擦除颜色(支持白色全透明,但不支持透明度为中间值)。 + * Set color for clear screen.
+ * (Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js) + * !#zh + * 设置场景的默认擦除颜色。
+ * 支持全透明,但不支持透明度为中间值。要支持全透明需手工开启 cc.macro.ENABLE_TRANSPARENT_CANVAS。 * @method setClearColor * @param {Color} clearColor */ diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index 47a52aa999..423072062b 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -582,8 +582,11 @@ var _Deserializer = (function () { } function _deserializeFireClass (self, obj, serialized, klass, target) { - var deserialize = klass.__deserialize__; - if (!deserialize) { + var deserialize; + if (klass.hasOwnProperty('__deserialize__')) { + deserialize = klass.__deserialize__; + } + else { deserialize = compileDeserialize(self, klass); // if (CC_TEST && !isPhantomJS) { // cc.log(deserialize); diff --git a/test/qunit/unit/test-class.js b/test/qunit/unit/test-class.js index 9c6e7b1d6c..e631cbc078 100644 --- a/test/qunit/unit/test-class.js +++ b/test/qunit/unit/test-class.js @@ -843,4 +843,26 @@ largeModule('Class ES6'); // } // expect(0); // }); + + if (TestEditorExtends) { + test('deserialization of child class', function () { + @ccclass('cc.Animal') + class Animal {} + + @ccclass('cc.Dog') + class Dog extends Animal { + @property + name = '3'; + } + + var ani = new Animal(); + cc.deserialize(Editor.serialize(ani)); + var dog = new Dog(); + dog.name = 'a'; + var cloneDog = cc.deserialize(Editor.serialize(dog)); + strictEqual(dog.name, cloneDog.name, 'property should be deserializable if super class also have been deserialized'); + + cc.js.unregisterClass(Animal, Dog); + }); + } })(); From 6fd37c87d231d1430849c8d0fa056df756a2f221 Mon Sep 17 00:00:00 2001 From: RazgrizHsu Date: Wed, 16 Aug 2017 10:14:29 +0800 Subject: [PATCH 05/14] Extend the RichText tag's attributes to support height and width follow the original principle: the image line height must not exceed the RichText line height --- cocos2d/core/components/CCRichText.js | 28 ++++++++--- cocos2d/core/label/CCHtmlTextParser.js | 64 +++++++++++++------------- 2 files changed, 55 insertions(+), 37 deletions(-) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index bd79283366..bbc4570335 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -505,23 +505,39 @@ var RichText = cc.Class({ var spriteRect = spriteFrame.getRect(); var scaleFactor = 1; - if(spriteRect.height > this.lineHeight) { - scaleFactor = this.lineHeight / spriteRect.height; + var spriteWidth = spriteRect.width; + var spriteHeight = spriteRect.height; + var expectWidht = richTextElement.style.imageWidth; + var expectHeight = richTextElement.style.imageHeight; + + //follow the original rule, the image height must less then lineHeight + if(expectHeight && expectHeight > 0 && expectHeight < this.lineHeight ) + { + scaleFactor = expectHeight / spriteRect.height; + spriteWidth = spriteWidth * scaleFactor; + spriteHeight = spriteHeight * scaleFactor; } + else if(spriteRect.height > this.lineHeight) { + scaleFactor = this.lineHeight / spriteRect.height; + spriteWidth = spriteWidth * scaleFactor; + spriteHeight = spriteHeight * scaleFactor; + } + if(expectWidht && expectWidht > 0) spriteWidth = expectWidht; + if(this.maxWidth > 0) { - if(this._lineOffsetX + spriteRect.width * scaleFactor > this.maxWidth) { + if(this._lineOffsetX + spriteWidth > this.maxWidth) { this._updateLineInfo(); } - this._lineOffsetX += spriteRect.width * scaleFactor; + this._lineOffsetX += spriteWidth; } else { - this._lineOffsetX += spriteRect.width * scaleFactor; + this._lineOffsetX += spriteWidth; if(this._lineOffsetX > this._labelWidth) { this._labelWidth = this._lineOffsetX; } } this._applySpriteFrame(spriteFrame); - sprite.setContentSize(spriteRect.width * scaleFactor, spriteRect.height * scaleFactor); + sprite.setContentSize(spriteWidth, spriteHeight); sprite._lineCount = this._lineCount; if(richTextElement.style.event) { diff --git a/cocos2d/core/label/CCHtmlTextParser.js b/cocos2d/core/label/CCHtmlTextParser.js index 7d34a08fe9..3fba61dada 100644 --- a/cocos2d/core/label/CCHtmlTextParser.js +++ b/cocos2d/core/label/CCHtmlTextParser.js @@ -123,38 +123,40 @@ cc.HtmlTextParser.prototype = { if(header && header[0].length > 0) { tagName = header[0].trim(); if(tagName.startsWith("img") && tagName[tagName.length-1] === "/") { - var srcBegin = tagName.indexOf('='); - var remainingArgument = tagName.substring(srcBegin+1).trim(); - var imageSrc; - var endQuotIndex = -1; - var isValidImageTag = false; - switch(remainingArgument[0]){ - case "'": - endQuotIndex = remainingArgument.indexOf("'", 1); - if(endQuotIndex > -1) { - imageSrc = remainingArgument.substring(1, endQuotIndex); - isValidImageTag = true; - } - break; - case "\"": - endQuotIndex = remainingArgument.indexOf("\"", 1); - if(endQuotIndex > -1) { - imageSrc = remainingArgument.substring(1, endQuotIndex); - isValidImageTag = true; - } - break; - default: - //invalid tag - break; - } - if(isValidImageTag) { - obj.isImage = true; - obj.src = imageSrc; - eventHanlderString = remainingArgument.substring(endQuotIndex+1).trim(); - if(eventHanlderString.match(eventRegx)){ - eventObj = this._processEventHandler(eventHanlderString); - obj.event = eventObj; + var imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*click(\s)*=/; + header = attribute.match(imageAttrReg); + var tagValue; + var remainingArgument; + while (header) { + //skip the invalid tags at first + attribute = attribute.substring(attribute.indexOf(header[0])); + tagName = attribute.substr(0, header[0].length); + //remove space and = character + remainingArgument = attribute.substring(tagName.length).trim(); + nextSpace = remainingArgument.indexOf(' '); + + tagValue = (nextSpace > -1) ? remainingArgument.substr(0, nextSpace) : remainingArgument; + tagName = tagName.replace(/[^a-zA-Z]/g, "").trim(); + tagName = tagName.toLocaleLowerCase(); + + attribute = remainingArgument.substring(nextSpace).trim(); + if (tagName === "src") { + obj.isImage = true + if( tagValue.indexOf('\'')===0 ) tagValue = tagValue.substring( 1, tagValue.length - 1 ); + if( tagValue.indexOf('\"')===0 ) tagValue = tagValue.substring( 1, tagValue.length - 1 ); + obj.src = tagValue; + } else if (tagName === "height") { + obj.imageHeight = parseInt(tagValue); + } else if (tagName === "width") { + obj.imageWidth = parseInt(tagValue); + } else if (tagName === "click") { + obj.event = this._processEventHandler(tagName + "=" + tagValue); } + header = attribute.match(imageAttrReg); + } + + if( obj.isImage ) + { this._resultObjectArray.push({text: "", style: obj}); } From 7ce5abe2a71ce663dac12af1aa23c8f536ea24ff Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 16 Aug 2017 17:36:22 +0800 Subject: [PATCH 06/14] add setJavascriptInterfaceScheme and setOnJSCallback to webview for fireball/issues/6251 --- cocos2d/core/components/CCWebView.js | 32 ++++++++++++++++++++++++++++ cocos2d/core/webview/CCSGWebView.js | 1 + 2 files changed, 33 insertions(+) diff --git a/cocos2d/core/components/CCWebView.js b/cocos2d/core/components/CCWebView.js index 8b52f806fb..239a7772bd 100644 --- a/cocos2d/core/components/CCWebView.js +++ b/cocos2d/core/components/CCWebView.js @@ -151,7 +151,39 @@ var WebView = cc.Class({ _onWebViewLoadError: function () { cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.ERROR); this.node.emit('error', this); + }, + + /** + * !#en + * Set javascript interface scheme. + * Note: only available on Android and iOS at the moment. + * !#zh + * 设置 javascript 接口方案。 + * 注意:目前只能在 Android 和 iOS 上使用。 + * @method setJavascriptInterfaceScheme + * @param {String} scheme + */ + setJavascriptInterfaceScheme: function (scheme) { + if (this._sgNode) { + this._sgNode.setJavascriptInterfaceScheme(scheme); + } + }, + /** + * !#en + * This callback called when load URL that start with javascript interface scheme. + * Note: only available on Android and iOS at the moment. + * !#zh + * 当加载 URL 以 JavaScript 接口方案开始时调用这个回调函数。 + * 注意:目前只能在 Android 和 iOS 上使用。 + * @method setOnJSCallback + * @param {Function} callback + */ + setOnJSCallback: function (callback) { + if (this._sgNode) { + this._sgNode.setOnJSCallback(callback); + } } + }); cc.WebView = module.exports = WebView; diff --git a/cocos2d/core/webview/CCSGWebView.js b/cocos2d/core/webview/CCSGWebView.js index 3be92317ff..9602b44e24 100644 --- a/cocos2d/core/webview/CCSGWebView.js +++ b/cocos2d/core/webview/CCSGWebView.js @@ -34,6 +34,7 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ } }, + setOnJSCallback: function(callback){}, setJavascriptInterfaceScheme: function(scheme){}, loadData: function(data, MIMEType, encoding, baseURL){}, loadHTMLString: function(string, baseURL){}, From cdff8574430e466e689fc053b812637b63620702 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 16 Aug 2017 17:47:54 +0800 Subject: [PATCH 07/14] open DepthTest to TMXLayer for fireball/issues/6270 --- cocos2d/tilemap/CCSGTMXLayer.js | 5 +++++ cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 2e96dab320..1e63ca8a92 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -294,6 +294,11 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ } else { renderer.pushRenderCommand(cmd); } + + if(cc._renderType === cc.game.RENDER_TYPE_WEBGL) { + renderer.pushRenderCommand(this._renderCmd._depthTestVisitCmd); + } + cmd._dirtyFlag = 0; }, diff --git a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js index f1c2486e42..063d167ee7 100644 --- a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js +++ b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js @@ -54,12 +54,22 @@ _ccsg.TMXLayer.WebGLRenderCmd = function(renderableObject){ StaggerAxis = cc.TiledMap.StaggerAxis; StaggerIndex = cc.TiledMap.StaggerIndex; } + + // close DepthTest, local use DepthTest; + this._depthTestVisitCmd = new cc.CustomRenderCmd(this, _closeDepthTest); }; +function _closeDepthTest () { + cc.renderer.setDepthTest(false); +} + var proto = _ccsg.TMXLayer.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype); proto.constructor = _ccsg.TMXLayer.WebGLRenderCmd; proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) { + // open Depth Test + cc.renderer.setDepthTest(true); + var node = this._node, hasRotation = (node._rotationX || node._rotationY), layerOrientation = node.layerOrientation, tiles = node.tiles; @@ -167,6 +177,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) { z = colOffset + col; // Skip sprite tiles if (spTiles[z]) { + spTiles[z]._vertexZ = node._vertexZ + cc.renderer.assignedZStep * z / tiles.length; continue; } From 53cead8fdb4615ec76c00421d66de6e45ab7e577 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 16 Aug 2017 18:28:34 +0800 Subject: [PATCH 08/14] Failed to refresh the size in time for fireball/issues/6263 --- cocos2d/core/components/CCLabel.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 484b794dde..49840c6f7e 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -501,6 +501,11 @@ var Label = cc.Class({ }, + onEnable: function () { + this._super(); + this._updateNodeSize(); + }, + _createSgNode: function () { return null; }, From 601aa097416818b3814e17b764cde4bd573b2f0b Mon Sep 17 00:00:00 2001 From: RazgrizHsu Date: Thu, 17 Aug 2017 06:04:44 +0800 Subject: [PATCH 09/14] fix unit test cases, follow original rule --- cocos2d/core/label/CCHtmlTextParser.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/label/CCHtmlTextParser.js b/cocos2d/core/label/CCHtmlTextParser.js index 3fba61dada..e05b1cb667 100644 --- a/cocos2d/core/label/CCHtmlTextParser.js +++ b/cocos2d/core/label/CCHtmlTextParser.js @@ -127,6 +127,7 @@ cc.HtmlTextParser.prototype = { header = attribute.match(imageAttrReg); var tagValue; var remainingArgument; + var isValidImageTag = false; while (header) { //skip the invalid tags at first attribute = attribute.substring(attribute.indexOf(header[0])); @@ -142,8 +143,14 @@ cc.HtmlTextParser.prototype = { attribute = remainingArgument.substring(nextSpace).trim(); if (tagName === "src") { obj.isImage = true - if( tagValue.indexOf('\'')===0 ) tagValue = tagValue.substring( 1, tagValue.length - 1 ); - if( tagValue.indexOf('\"')===0 ) tagValue = tagValue.substring( 1, tagValue.length - 1 ); + if( tagValue.endsWith( '\/' ) ) tagValue = tagValue.substring( 0, tagValue.length - 1 ); + if( tagValue.indexOf('\'')===0 ) { + isValidImageTag = true; + tagValue = tagValue.substring( 1, tagValue.length - 1 ); + } else if( tagValue.indexOf('"')===0 ) { + isValidImageTag = true; + tagValue = tagValue.substring( 1, tagValue.length - 1 ); + } obj.src = tagValue; } else if (tagName === "height") { obj.imageHeight = parseInt(tagValue); @@ -155,7 +162,7 @@ cc.HtmlTextParser.prototype = { header = attribute.match(imageAttrReg); } - if( obj.isImage ) + if( isValidImageTag && obj.isImage ) { this._resultObjectArray.push({text: "", style: obj}); } From cdc564a536c64761e4aa36a515c108bf2028ef0c Mon Sep 17 00:00:00 2001 From: RazgrizHsu Date: Thu, 17 Aug 2017 12:23:55 +0800 Subject: [PATCH 10/14] according to the discussion - correct wrong word of Width - include case when image height less then lineHeight - promote image attribute regex to global cache in file --- cocos2d/core/components/CCRichText.js | 21 ++++++++++----------- cocos2d/core/label/CCHtmlTextParser.js | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index bbc4570335..05c8592d78 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -507,22 +507,21 @@ var RichText = cc.Class({ var scaleFactor = 1; var spriteWidth = spriteRect.width; var spriteHeight = spriteRect.height; - var expectWidht = richTextElement.style.imageWidth; + var expectWidth = richTextElement.style.imageWidth; var expectHeight = richTextElement.style.imageHeight; - //follow the original rule, the image height must less then lineHeight - if(expectHeight && expectHeight > 0 && expectHeight < this.lineHeight ) - { - scaleFactor = expectHeight / spriteRect.height; + //follow the original rule, expectHeight must less then lineHeight + if(expectHeight > 0 && expectHeight < this.lineHeight ) { + scaleFactor = expectHeight / spriteHeight; + spriteWidth = spriteWidth * scaleFactor; + spriteHeight = spriteHeight * scaleFactor; + } else { + scaleFactor = this.lineHeight / spriteHeight; spriteWidth = spriteWidth * scaleFactor; spriteHeight = spriteHeight * scaleFactor; } - else if(spriteRect.height > this.lineHeight) { - scaleFactor = this.lineHeight / spriteRect.height; - spriteWidth = spriteWidth * scaleFactor; - spriteHeight = spriteHeight * scaleFactor; - } - if(expectWidht && expectWidht > 0) spriteWidth = expectWidht; + + if(expectWidth > 0) spriteWidth = expectWidth; if(this.maxWidth > 0) { if(this._lineOffsetX + spriteWidth > this.maxWidth) { diff --git a/cocos2d/core/label/CCHtmlTextParser.js b/cocos2d/core/label/CCHtmlTextParser.js index e05b1cb667..758d828077 100644 --- a/cocos2d/core/label/CCHtmlTextParser.js +++ b/cocos2d/core/label/CCHtmlTextParser.js @@ -23,6 +23,7 @@ ****************************************************************************/ var eventRegx = /^(click)(\s)*=/; +var imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*click(\s)*=/; /** * A utils class for parsing HTML texts. The parsed results will be an object array. */ @@ -123,7 +124,6 @@ cc.HtmlTextParser.prototype = { if(header && header[0].length > 0) { tagName = header[0].trim(); if(tagName.startsWith("img") && tagName[tagName.length-1] === "/") { - var imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*click(\s)*=/; header = attribute.match(imageAttrReg); var tagValue; var remainingArgument; From c3c69a588dfe448cd111fcda284bd4936ac3c7cc Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 17 Aug 2017 13:42:10 +0800 Subject: [PATCH 11/14] refine code --- cocos2d/tilemap/CCSGTMXLayer.js | 2 +- cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 1e63ca8a92..eb4f4f3d26 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -296,7 +296,7 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ } if(cc._renderType === cc.game.RENDER_TYPE_WEBGL) { - renderer.pushRenderCommand(this._renderCmd._depthTestVisitCmd); + renderer.pushRenderCommand(this._renderCmd._disableDepthTestCmd); } cmd._dirtyFlag = 0; diff --git a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js index 063d167ee7..7253514b75 100644 --- a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js +++ b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js @@ -55,11 +55,11 @@ _ccsg.TMXLayer.WebGLRenderCmd = function(renderableObject){ StaggerIndex = cc.TiledMap.StaggerIndex; } - // close DepthTest, local use DepthTest; - this._depthTestVisitCmd = new cc.CustomRenderCmd(this, _closeDepthTest); + // disable DepthTest, local use DepthTest; + this._disableDepthTestCmd = new cc.CustomRenderCmd(this, _disableDepthTest); }; -function _closeDepthTest () { +function _disableDepthTest () { cc.renderer.setDepthTest(false); } @@ -67,7 +67,7 @@ var proto = _ccsg.TMXLayer.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.W proto.constructor = _ccsg.TMXLayer.WebGLRenderCmd; proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) { - // open Depth Test + // enable Depth Test cc.renderer.setDepthTest(true); var node = this._node, hasRotation = (node._rotationX || node._rotationY), From 565c42ff7f6fa5670fece6faaf07af4d34b105c4 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 17 Aug 2017 14:19:57 +0800 Subject: [PATCH 12/14] remove redundant code --- cocos2d/core/components/CCLabel.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 49840c6f7e..250de3da11 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -489,11 +489,6 @@ var Label = cc.Class({ __preload: function () { this._super(); - var sgSizeInitialized = this._sgNode._isUseSystemFont; - if (sgSizeInitialized) { - this._updateNodeSize(); - } - // node should be resize whenever font changed, needed only on web if (!CC_JSB) { this._sgNode.on('load', this._updateNodeSize, this); From e90ba4313f5fa6286a1f61b0458b219c521dfaf3 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 17 Aug 2017 17:32:11 +0800 Subject: [PATCH 13/14] Modify the _updateNodeSize timing for fireball/issues/6263 --- cocos2d/core/components/CCLabel.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 250de3da11..7da167c676 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -494,10 +494,6 @@ var Label = cc.Class({ this._sgNode.on('load', this._updateNodeSize, this); } - }, - - onEnable: function () { - this._super(); this._updateNodeSize(); }, From 17597bfa96572f11c9e0a83e8271ed362b6e0e85 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 18 Aug 2017 09:59:37 +0800 Subject: [PATCH 14/14] fix repeatedly creating a Label will cause the Label to be incorrect for fireball/issues/6282 --- cocos2d/core/label/CCSGLabel.js | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 2c74926e81..e0b270badc 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -1307,7 +1307,6 @@ _ccsg.Label.pool.get = function (string, fontAsset) { label.enableBold(false); label.enableItalics(false); label.enableUnderline(false); - label.setBlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA); return label; }