From ade6bb5362dc0ecec651bf44f73d225e6f9563f0 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 13 Jan 2016 15:26:58 +0800 Subject: [PATCH] check component conflict --- cocos2d/ToMerge/wrappers/ui/layout.js | 110 --------------------- cocos2d/ToMerge/wrappers/ui/scroll-view.js | 99 ------------------- cocos2d/core/CCNode.js | 6 ++ cocos2d/core/utils/base-node.js | 4 + 4 files changed, 10 insertions(+), 209 deletions(-) delete mode 100644 cocos2d/ToMerge/wrappers/ui/layout.js delete mode 100644 cocos2d/ToMerge/wrappers/ui/scroll-view.js diff --git a/cocos2d/ToMerge/wrappers/ui/layout.js b/cocos2d/ToMerge/wrappers/ui/layout.js deleted file mode 100644 index 7a7c20b270..0000000000 --- a/cocos2d/ToMerge/wrappers/ui/layout.js +++ /dev/null @@ -1,110 +0,0 @@ -var NodeWrapper = require('../node'); -var WidgetWrapper = require('./widget'); - -var LayoutWrapper = cc.Class({ - name: 'cc.LayoutWrapper', - extends: WidgetWrapper, - - properties: { - clippingEnabled: { - get: function () { - return this.targetN.clippingEnabled; - }, - set: function (value) { - if (typeof value === 'boolean') { - this.targetN.clippingEnabled = value; - - cc.renderer.childrenOrderDirty = true; - if (CC_EDITOR) { - cc.engine.repaintInEditMode(); - } - } - else { - cc.error('The new clippingEnabled must be boolean'); - } - } - }, - - layoutType: { - get: function () { - return this.targetN.layoutType; - }, - set: function (value) { - if (typeof value === 'number' && !isNaN(value)) { - this.targetN.layoutType = value; - this.updateChildLayoutType(); - - this.doLayout(); - } - else { - cc.error('The new layoutType must be number'); - } - }, - type: ccui.Layout.Type - }, - - _layoutType: { - default: 0 - }, - - _clippingEnabled: { - default: null - } - }, - - updateChildLayoutType: function () { - var layoutType = this.layoutType; - this.children.forEach( function (child) { - child.widgetLayoutType = layoutType; - }); - }, - - addChildN: function (child) { - var wrapper = cc.getWrapper(child); - wrapper.widgetLayoutType = this.layoutType; - NodeWrapper.prototype.addChildN.call(this, child); - }, - - canAddChildN: function (child) { - if ( !(child instanceof ccui.Widget) ) { - cc.error('Layout can only add ccui.Widget as a child'); - return false; - } - - return true; - }, - - onChildSiblingIndexChanged: function () { - this.doLayout(); - }, - - doLayout: function () { - this.targetN.requestDoLayout(); - cc.renderer.childrenOrderDirty = true; - if (CC_EDITOR) { - cc.engine.repaintInEditMode(); - } - }, - - onBeforeSerialize: function () { - WidgetWrapper.prototype.onBeforeSerialize.call(this); - - this._layoutType = this.layoutType; - this._clippingEnabled = this.clippingEnabled; - }, - - createNode: function (node) { - node = node || new ccui.Layout(); - - WidgetWrapper.prototype.createNode.call(this, node); - - node.layoutType = this._layoutType; - - if (this._clippingEnabled !== null) - node.clippingEnabled = this._clippingEnabled; - - return node; - } -}); - -cc.LayoutWrapper = module.exports = LayoutWrapper; diff --git a/cocos2d/ToMerge/wrappers/ui/scroll-view.js b/cocos2d/ToMerge/wrappers/ui/scroll-view.js deleted file mode 100644 index b89fb8d24e..0000000000 --- a/cocos2d/ToMerge/wrappers/ui/scroll-view.js +++ /dev/null @@ -1,99 +0,0 @@ - -var LayoutWrapper = require('./layout'); - -var ScrollViewWrapper = cc.Class({ - name: 'cc.ScrollViewWrapper', - extends: LayoutWrapper, - - properties: { - direction: { - get: function () { - return this.targetN.getDirection(); - }, - set: function (value) { - if (typeof value === 'number' && !isNaN(value)) { - this.targetN.setDirection(value); - - this.doLayout(); - } - else { - cc.error('The new direction must be number'); - } - }, - type: ccui.ScrollView.Dir - }, - - bounce: { - get: function () { - return this.targetN.isBounceEnabled(); - }, - set: function (value) { - if (typeof value === 'boolean') { - this.targetN.setBounceEnabled(value); - } - else { - cc.error('The new bounce must be boolean'); - } - } - }, - - innerSize: { - get: function () { - var size = this.targetN.getInnerContainerSize(); - return new cc.Vec2(size.width, size.height); - }, - set: function (value) { - if ( value instanceof cc.Vec2 ) { - this.targetN.setInnerContainerSize( cc.size(value.x, value.y) ); - - this.doLayout(); - } - else { - cc.error('The new innerSize must be cc.Vec2'); - } - } - }, - - _direction: { - default: ccui.ScrollView.Dir.NONE, - type: ccui.ScrollView.Dir - }, - - _bounce: { - default: false - }, - - _innerSize: { - default: null - } - }, - - doLayout: function () { - this.targetN._innerContainer.requestDoLayout(); - LayoutWrapper.prototype.doLayout.call(this); - }, - - onBeforeSerialize: function () { - LayoutWrapper.prototype.onBeforeSerialize.call(this); - - this._direction = this.direction; - this._bounce = this.bounce; - this._innerSize = [this.innerSize.x, this.innerSize.y]; - }, - - createNode: function (node) { - node = node || new ccui.ScrollView(); - - LayoutWrapper.prototype.createNode.call(this, node); - - node.setDirection( this._direction ); - node.setBounceEnabled( this._bounce ); - - var innerSize = this._innerSize; - if (innerSize) node.setInnerContainerSize( cc.size(innerSize[0], innerSize[1]) ); - - return node; - } -}); - -cc.ScrollViewWrapper = module.exports = ScrollViewWrapper; diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 0cb540a607..48683d23df 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -551,6 +551,12 @@ var Node = cc.Class({ } } + // check conflict + + if (CC_EDITOR && !_Scene.DetectConflict.beforeAddComponent(this, constructor)) { + return null; + } + // var component = new constructor(); diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index b9f61ae231..2e806d5c2b 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -144,6 +144,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ oldParent._children.splice(removeAt, 1); oldParent.emit(CHILD_REMOVED, removeAt); this._onHierarchyChanged(oldParent); + + if (CC_EDITOR) { + _Scene.DetectConflict.afterAddChild(this); + } } } else if (value) {