mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 01:12:42 +08:00
@@ -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;
|
||||
@@ -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;
|
||||
@@ -551,6 +551,12 @@ var Node = cc.Class({
|
||||
}
|
||||
}
|
||||
|
||||
// check conflict
|
||||
|
||||
if (CC_EDITOR && !_Scene.DetectConflict.beforeAddComponent(this, constructor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var component = new constructor();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user