From faf885c30b44147b485c8de5681f1f73945c4949 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 12 Sep 2023 11:05:01 +0800 Subject: [PATCH 1/2] replace NodeEventType.SIBLING_ORDER_CHANGED with NodeEventType.CHILDREN_ORDER_CHANGED --- cocos/input/types/event-enum.ts | 2 +- cocos/scene-graph/node-event.ts | 12 ++++++++++-- cocos/scene-graph/node.jsb.ts | 4 ++-- cocos/scene-graph/node.ts | 2 +- cocos/ui/layout.ts | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cocos/input/types/event-enum.ts b/cocos/input/types/event-enum.ts index c8c2a8d4e82..96d3844f8d4 100644 --- a/cocos/input/types/event-enum.ts +++ b/cocos/input/types/event-enum.ts @@ -265,7 +265,7 @@ export enum SystemEventType { * @en The event type for node's sibling order changed. * @zh 当节点在兄弟节点中的顺序发生变化时触发的事件。 * - * @deprecated since v3.3, please use Node.EventType.SIBLING_ORDER_CHANGED instead + * @deprecated since v3.3, please use Node.EventType.CHILDREN_ORDER_CHANGED instead */ SIBLING_ORDER_CHANGED = 'sibling-order-changed', } diff --git a/cocos/scene-graph/node-event.ts b/cocos/scene-graph/node-event.ts index 9d18185c689..55944153672 100644 --- a/cocos/scene-graph/node-event.ts +++ b/cocos/scene-graph/node-event.ts @@ -245,11 +245,19 @@ export enum NodeEventType { LAYER_CHANGED = 'layer-changed', /** - * @en The event type for node's sibling order changed. - * @zh 当节点在兄弟节点中的顺序发生变化时触发的事件。 + * @en This event indicates that the order of child nodes has been changed." + * @zh 该事件表示子节点的排序发生了改变。 + * @deprecated since v3.8.2 @en Please use `CHILDREN_ORDER_CHANGED`. @zh 请使用 `CHILDREN_ORDER_CHANGED`。 */ SIBLING_ORDER_CHANGED = 'sibling-order-changed', + /** + * @en This event indicates that the order of child nodes has been changed." + * @zh 该事件表示子节点的排序发生了改变。 + */ + // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values + CHILDREN_ORDER_CHANGED = 'sibling-order-changed', + /** * @en * Note: This event is only emitted from the top most node whose active value did changed, diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index ed2e4274521..a9e05315986 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -280,7 +280,7 @@ nodeProto.on = function (type, callback, target, useCapture: any = false) { this._registeredNodeEventTypeMask |= REGISTERED_EVENT_MASK_LAYER_CHANGED; } break; - case NodeEventType.SIBLING_ORDER_CHANGED: + case NodeEventType.CHILDREN_ORDER_CHANGED: if (!(this._registeredNodeEventTypeMask & REGISTERED_EVENT_MASK_SIBLING_ORDER_CHANGED)) { this._registerOnSiblingOrderChanged(); this._registeredNodeEventTypeMask |= REGISTERED_EVENT_MASK_SIBLING_ORDER_CHANGED; @@ -492,7 +492,7 @@ nodeProto.destroyAllChildren = function destroyAllChildren() { }; nodeProto._onSiblingOrderChanged = function () { - this.emit(NodeEventType.SIBLING_ORDER_CHANGED); + this.emit(NodeEventType.CHILDREN_ORDER_CHANGED); }; nodeProto._onActivateNode = function (shouldActiveNow) { diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index c1724a27da3..294c8d242fa 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -1309,7 +1309,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { this._children[i]._siblingIndex = i; } - this.emit(NodeEventType.SIBLING_ORDER_CHANGED); + this.emit(NodeEventType.CHILDREN_ORDER_CHANGED); } protected _instantiate (cloned, isSyncedNode): any { diff --git a/cocos/ui/layout.ts b/cocos/ui/layout.ts index 88c64aec0c1..11bc4cf7b8a 100644 --- a/cocos/ui/layout.ts +++ b/cocos/ui/layout.ts @@ -736,7 +736,7 @@ export class Layout extends Component { this.node.on(NodeEventType.ANCHOR_CHANGED, this._doLayoutDirty, this); this.node.on(NodeEventType.CHILD_ADDED, this._childAdded, this); this.node.on(NodeEventType.CHILD_REMOVED, this._childRemoved, this); - this.node.on(NodeEventType.SIBLING_ORDER_CHANGED, this._childrenChanged, this); + this.node.on(NodeEventType.CHILDREN_ORDER_CHANGED, this._childrenChanged, this); this.node.on('childrenSiblingOrderChanged', this.updateLayout, this); this._addChildrenEventListeners(); } @@ -747,7 +747,7 @@ export class Layout extends Component { this.node.off(NodeEventType.ANCHOR_CHANGED, this._doLayoutDirty, this); this.node.off(NodeEventType.CHILD_ADDED, this._childAdded, this); this.node.off(NodeEventType.CHILD_REMOVED, this._childRemoved, this); - this.node.off(NodeEventType.SIBLING_ORDER_CHANGED, this._childrenChanged, this); + this.node.off(NodeEventType.CHILDREN_ORDER_CHANGED, this._childrenChanged, this); this.node.off('childrenSiblingOrderChanged', this.updateLayout, this); this._removeChildrenEventListeners(); } From 7a6d1b1556780758dac478b3ae2604c62c9bfce6 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 12 Sep 2023 11:15:13 +0800 Subject: [PATCH 2/2] remove unneeded code --- cocos/scene-graph/node-event.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/scene-graph/node-event.ts b/cocos/scene-graph/node-event.ts index 55944153672..901862c301c 100644 --- a/cocos/scene-graph/node-event.ts +++ b/cocos/scene-graph/node-event.ts @@ -245,14 +245,14 @@ export enum NodeEventType { LAYER_CHANGED = 'layer-changed', /** - * @en This event indicates that the order of child nodes has been changed." + * @en This event indicates that the order of child nodes has been changed. * @zh 该事件表示子节点的排序发生了改变。 * @deprecated since v3.8.2 @en Please use `CHILDREN_ORDER_CHANGED`. @zh 请使用 `CHILDREN_ORDER_CHANGED`。 */ SIBLING_ORDER_CHANGED = 'sibling-order-changed', /** - * @en This event indicates that the order of child nodes has been changed." + * @en This event indicates that the order of child nodes has been changed. * @zh 该事件表示子节点的排序发生了改变。 */ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values