Merge pull request #2414 from jareguo/master

fix widget warning
This commit is contained in:
Jare Guo
2018-03-09 09:37:55 +08:00
committed by GitHub
3 changed files with 59 additions and 45 deletions
+6 -3
View File
@@ -35,7 +35,7 @@ var VERTICAL = TOP | MID | BOT;
var AlignMode = cc.Enum({
ONCE: 0,
ON_WINDOW_RESIZED: 1,
ON_WINDOW_RESIZE: 1,
ALWAYS: 2,
});
@@ -299,7 +299,10 @@ function refreshScene () {
for (i = activeWidgets.length - 1; i >= 0; i--) {
widget = activeWidgets[i];
var node = widget.node;
if (widget.isAlignOnce && animationState.animatedSinceLastFrame && node.isChildOf(editingNode)) {
if (widget.alignMode !== AlignMode.ALWAYS &&
animationState.animatedSinceLastFrame &&
node.isChildOf(editingNode)
) {
// widget contains in activeWidgets should aligned at least once
widget.enabled = false;
}
@@ -482,7 +485,7 @@ var widgetManager = cc._widgetManager = module.exports = {
refreshWidgetOnResized (node) {
var widget = cc.Node.isNode(node) && node.getComponent(cc.Widget);
if (widget) {
if (widget.alignMode === AlignMode.ON_WINDOW_RESIZED) {
if (widget.alignMode === AlignMode.ON_WINDOW_RESIZE) {
widget.enabled = true;
}
}
+37 -38
View File
@@ -45,7 +45,7 @@ var WidgetManager = require('../base-ui/CCWidgetManager');
/**
* !#en Align first from the beginning as ONCE, and then realign it every time the window is resized.
* !#zh 一开始会像 ONCE 一样对齐一次,之后每当窗口大小改变时还会重新对齐。
* @property {Number} ON_WINDOW_RESIZED
* @property {Number} ON_WINDOW_RESIZE
*/
/**
* !#en Keep aligning all the way.
@@ -506,56 +506,26 @@ var Widget = cc.Class({
animatable: false
},
/**
* !#en
* When turned on, it will only be aligned once at the end of the onEnable frame,
* then immediately disables the current component.
* This will allow the script or animation to continue controlling the current node.
* Note: It will still be aligned at the frame when onEnable is called.
* !#zh
* 开启后仅会在 onEnable 的当帧结束时对齐一次,然后立刻禁用当前组件。
* 这样便于脚本或动画继续控制当前节点。
* 注意:onEnable 时所在的那一帧仍然会进行对齐。
* @property isAlignOnce
* @type {Boolean}
* @default false
* @deprecated
*/
isAlignOnce: {
get: function () {
if (CC_DEV) {
cc.warn('cc.Widget.isAlignOnce is deprecated, use alignMode instead please.');
}
return this.alignMode === AlignMode.ONCE;
},
set: function (value) {
if (CC_DEV) {
cc.warn('cc.Widget.isAlignOnce is deprecated, use alignMode instead please.');
}
this.alignMode = value ? AlignMode.ONCE : AlignMode.ALWAYS;
},
visible: false,
},
_wasAlignOnce: {
default: undefined,
formerlySerializedAs: 'isAlignOnce',
},
/**
* !#en Specifies the alignment mode of the Widget, which determines when the widget should refresh.
* !#zh 指定 Widget 的对齐模式,用于决定 Widget 应该何时刷新。
* @property {Widget.AlignMode} alignMode
* @example
* widget.alignMode = cc.Widget.AlignMode.ON_WINDOW_RESIZED;
* widget.alignMode = cc.Widget.AlignMode.ON_WINDOW_RESIZE;
*/
alignMode: {
default: AlignMode.ON_WINDOW_RESIZED,
default: AlignMode.ON_WINDOW_RESIZE,
type: AlignMode,
tooltip: CC_DEV && 'i18n:COMPONENT.widget.align_mode',
},
//
_wasAlignOnce: {
default: undefined,
formerlySerializedAs: 'isAlignOnce',
},
_target: null,
/**
@@ -682,5 +652,34 @@ var Widget = cc.Class({
},
});
/**
* !#en
* When turned on, it will only be aligned once at the end of the onEnable frame,
* then immediately disables the current component.
* This will allow the script or animation to continue controlling the current node.
* Note: It will still be aligned at the frame when onEnable is called.
* !#zh
* 开启后仅会在 onEnable 的当帧结束时对齐一次,然后立刻禁用当前组件。
* 这样便于脚本或动画继续控制当前节点。
* 注意:onEnable 时所在的那一帧仍然会进行对齐。
* @property {Boolean} isAlignOnce
* @default false
* @deprecated
*/
Object.defineProperty(Widget.prototype, 'isAlignOnce', {
get () {
if (CC_DEBUG) {
cc.warn('`widget.isAlignOnce` is deprecated, use `widget.alignMode === cc.Widget.AlignMode.ONCE` instead please.');
}
return this.alignMode === AlignMode.ONCE;
},
set (value) {
if (CC_DEBUG) {
cc.warn('`widget.isAlignOnce` is deprecated, use `widget.alignMode = cc.Widget.AlignMode.*` instead please.');
}
this.alignMode = value ? AlignMode.ONCE : AlignMode.ALWAYS;
}
});
cc.Widget = module.exports = Widget;
+16 -4
View File
@@ -580,6 +580,7 @@ var _Deserializer = (function () {
}
return Function('s', 'o', 'd', 'k', 't', sources.join(''));
} : function (self, klass) {
var TYPE = Attr.DELIMETER + 'type';
var EDITOR_ONLY = Attr.DELIMETER + 'editorOnly';
var SERIALIZABLE = Attr.DELIMETER + 'serializable';
var DEFAULT = Attr.DELIMETER + 'default';
@@ -616,10 +617,21 @@ var _Deserializer = (function () {
// function undefined object(null) string boolean number
var defaultValue = CCClass.getDefault(attrs[propName + DEFAULT]);
if (fastMode) {
var defaultType = typeof defaultValue;
var isPrimitiveType = (defaultType === 'string' && !stillUseUrl) ||
defaultType === 'number' ||
defaultType === 'boolean';
var isPrimitiveType;
var userType = attrs[propName + TYPE];
if (defaultValue === undefined && userType) {
isPrimitiveType = userType === cc.String ||
userType === cc.Integer ||
userType === cc.Float ||
userType === cc.Boolean;
}
else {
var defaultType = typeof defaultValue;
isPrimitiveType = (defaultType === 'string' && !stillUseUrl) ||
defaultType === 'number' ||
defaultType === 'boolean';
}
if (isPrimitiveType) {
o[propName] = prop;
}