repair child node render data synchronization update bug (#3963)

This commit is contained in:
JoneLau
2019-03-05 14:25:40 +08:00
committed by Weiliang Wang
parent 4edd55349f
commit 1f21da8d3c
8 changed files with 68 additions and 32 deletions
+1 -1
View File
@@ -440,7 +440,7 @@ export class ButtonComponent extends Component {
return this._target;
}
set target (value: Node) {
set target (value: Node | null) {
if (this._target === value) {
return;
}
+4 -4
View File
@@ -595,12 +595,12 @@ export class LabelComponent extends UIRenderComponent {
}
public updateAssembler (render: UI) {
if (!this._canRender() || !this._texture) {
return;
if (super.updateAssembler(render) && this._texture) {
render.commitComp(this, this._texture, this._assembler!);
return true;
}
this._checkAndUpdateRenderData();
render.commitComp(this, this._texture, this._assembler!);
return false;
}
protected _updateColor () {
+5 -5
View File
@@ -26,6 +26,7 @@
// import {SpriteFrame} from '../../../assets/CCSpriteFrame';
import { ccclass/*, executeInEditMode*/, executionOrder,
menu/*, property*/ } from '../../../core/data/class-decorator';
import { UI } from '../../../renderer/ui/ui';
// import { ccenum } from '../../../core/value-types/enum';
// import { clamp } from '../../../core/vmath';
import { EventType } from '../../../scene-graph/node-event-enum';
@@ -37,7 +38,6 @@ import quad from '../../primitive/quad';
import { scale, translate } from '../../primitive/transform';
import { UIRenderComponent } from './ui-render-component';
import { UITransformComponent } from './ui-transfrom-component';
import { UI } from '../../../renderer/ui/ui';
// /**
// * !#en the type for mask.
@@ -241,12 +241,12 @@ export class MaskComponent extends UIRenderComponent {
}
public updateAssembler (render: UI) {
if (!this._canRender()) {
return;
if (super.updateAssembler(render)) {
render.commitComp(this, null, this._assembler!);
return true;
}
this._checkAndUpdateRenderData();
render.commitComp(this, null, this._assembler!);
return false;
}
public postUpdateAssembler (render: UI) {
+4 -4
View File
@@ -410,12 +410,12 @@ export class SpriteComponent extends UIRenderComponent {
}
public updateAssembler (render: UI) {
if (!this._canRender() || !this._spriteFrame) {
return;
if (super.updateAssembler(render) && this._spriteFrame) {
render.commitComp(this, this._spriteFrame, this._assembler!);
return true;
}
this._checkAndUpdateRenderData();
render.commitComp(this, this._spriteFrame, this._assembler!);
return false;
}
public onDestroy () {
@@ -307,6 +307,16 @@ export class UIRenderComponent extends Component {
}
public updateAssembler (render: UI) {
if (!this._canRender()) {
return false;
}
if (this.node.hasChanged && !this._renderDataDirty) {
this.markForUpdateRenderData();
}
this._checkAndUpdateRenderData();
return true;
}
public postUpdateAssembler (render: UI) {
+11 -8
View File
@@ -26,9 +26,9 @@
import { Component} from '../../../components/component';
import { ccclass, executeInEditMode, executionOrder, menu, property, requireComponent } from '../../../core/data/class-decorator';
import { Node } from '../../../scene-graph/index';
import { UITransformComponent } from './ui-transfrom-component';
import { ccenum } from '../../../core/value-types/enum';
import { Node } from '../../../scene-graph/node';
import { UITransformComponent } from './ui-transfrom-component';
/**
* !#en Enum for Widget's alignment mode, indicating when the widget should refresh.
* !#zh Widget 的对齐模式,表示 Widget 应该何时刷新。
@@ -101,7 +101,6 @@ export class WidgetComponent extends Component {
* The default value is null, and when null, indicates the current parent.
* !#zh 指定一个对齐目标,只能是当前节点的其中一个父节点,默认为空,为空时表示当前父节点。
* @property {Node} target
* @default null
*/
@property({
type: Node,
@@ -110,7 +109,11 @@ export class WidgetComponent extends Component {
return this._target;
}
set target (value) {
set target (value: Node | null) {
if (this._target === value){
return;
}
this._target = value;
if (CC_EDITOR /*&& !cc.engine._isPlaying*/ && this.node.parent) {
// adjust the offsets to keep the size and position unchanged after target chagned
@@ -493,11 +496,11 @@ export class WidgetComponent extends Component {
* @private
*/
@property
get alignFlags() {
get alignFlags () {
return this._alignFlags;
}
set alignFlags(value) {
set alignFlags (value) {
if (this._alignFlags === value) {
return;
}
@@ -510,7 +513,7 @@ export class WidgetComponent extends Component {
@property
private _alignFlags = 0;
private _wasAlignOnce = false;
// @property
@property
private _target: Node | null = null;
@property
private _left = 0;
@@ -572,7 +575,7 @@ export class WidgetComponent extends Component {
// this._wasAlignOnce = false;
// }
if(this._alignMode === AlignMode.ONCE){
if (this._alignMode === AlignMode.ONCE){
this._wasAlignOnce = true;
}
}
+19 -7
View File
@@ -448,7 +448,7 @@ function updateAlignment (node: Node) {
}
// node._widget will be null when widget is disabled
const widget = node.uiWidgetComp || node.getComponent(WidgetComponent);
const widget = node.uiWidgetComp;
if (widget && parent) {
align(node, widget);
}
@@ -514,8 +514,8 @@ export const widgetManager = cc._widgetManager = {
},
refreshWidgetOnResized (node: Node) {
if (Node.isNode(node)){
// const widget = node.getComponent(WidgetComponent);
const widget: WidgetComponent | null = null;
const widget = node.uiWidgetComp;
// const widget: WidgetComponent | null = null;
if (widget) {
if (widget!.alignMode === AlignMode.ON_WINDOW_RESIZE) {
widget!.enabled = true;
@@ -560,7 +560,10 @@ export const widgetManager = cc._widgetManager = {
l += zero.x;
l *= one.x;
temp = pos.x - myAP.x * widgetNode.width! * widgetNodeScale.x - l;
widget.isAbsoluteLeft || (temp /= matchSize.width);
if (widget.isAbsoluteLeft) {
temp /= matchSize.width;
}
temp /= one.x;
widget.left = i(widget.left, temp);
}
@@ -569,7 +572,10 @@ export const widgetManager = cc._widgetManager = {
let r = (1 - parentAP.x) * matchSize.width;
r += zero.x;
temp = (r *= one.x) - (pos.x + (1 - myAP.x) * widgetNode.width! * widgetNodeScale.x);
widget.isAbsoluteRight || (temp /= matchSize.width);
if (widget.isAbsoluteRight) {
temp /= matchSize.width;
}
temp /= one.x;
widget.right = i(widget.right, temp);
}
@@ -578,7 +584,10 @@ export const widgetManager = cc._widgetManager = {
let t = (1 - parentAP.y) * matchSize.height;
t += zero.y;
temp = (t *= one.y) - (pos.y + (1 - myAP.y) * widgetNode.height! * widgetNodeScale.y);
widget.isAbsoluteTop || (temp /= matchSize.height);
if (!widget.isAbsoluteTop){
temp /= matchSize.height;
}
temp /= one.y;
widget.top = i(widget.top, temp);
}
@@ -588,7 +597,10 @@ export const widgetManager = cc._widgetManager = {
b += zero.y;
b *= one.y;
temp = pos.y - myAP.y * widgetNode.height! * widgetNodeScale.y - b;
widget.isAbsoluteBottom || (temp /= matchSize.height);
if (!widget.isAbsoluteBottom){
temp /= matchSize.height;
}
temp /= one.y;
widget.bottom = i(widget.bottom, temp);
}
+14 -3
View File
@@ -28,8 +28,6 @@ class Node extends BaseNode {
return obj instanceof Node && (obj.constructor === Node || !(obj instanceof cc.Scene));
}
public uiWidgetComp: WidgetComponent | null = null;
// local transform
@property({
// default: cc.v3(0, 0, 0),
@@ -62,6 +60,7 @@ class Node extends BaseNode {
protected _eventProcessor;
private _uiTransfromComp: UITransformComponent | null = null;
private _uiWidgetComp: WidgetComponent | null = null;
@property({
type: Vec3,
@@ -98,10 +97,22 @@ class Node extends BaseNode {
}
// NOTE: don't set it manually
set uiTransfromComp (value) {
set uiTransfromComp (value: UITransformComponent | null) {
this._uiTransfromComp = value;
}
get uiWidgetComp () {
if (!this._uiWidgetComp) {
this._uiWidgetComp = this.getComponent(WidgetComponent);
}
return this._uiWidgetComp;
}
set uiWidgetComp (value: WidgetComponent | null) {
this._uiWidgetComp = value;
}
get width () {
return this.uiTransfromComp!.width;
}