From 02dfcbbd7391b9b5b5ad3679ec644790a080e343 Mon Sep 17 00:00:00 2001 From: spe <853517173@qq.com> Date: Tue, 28 May 2024 19:07:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B1=82=E7=BA=A7=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=86=85=E5=AD=90=E8=8A=82=E7=82=B9=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E4=BF=AE=E6=94=B9=E9=80=8F=E6=98=8E=E5=BA=A6?= =?UTF-8?q?=E6=B2=A1=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/demo/CCCExtension.ts | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/assets/demo/CCCExtension.ts b/assets/demo/CCCExtension.ts index 27a8b38..07232be 100644 --- a/assets/demo/CCCExtension.ts +++ b/assets/demo/CCCExtension.ts @@ -1,3 +1,5 @@ +import { View } from "cc"; +import { EditBox } from "cc"; import { EPSILON, Node, RenderData, StencilManager, UIRenderer, approx, cclegacy, clamp, gfx, log } from "cc"; enum Stage { // Stencil disabled @@ -19,6 +21,7 @@ enum Stage { export default class CCCExtension { static init() { this._extendRender3_x(); + this._extendEditBoxTemp(); } private static _extendRender3_x() { @@ -53,21 +56,21 @@ export default class CCCExtension { const uiProps = node._uiProps; const render = uiProps.uiComp as UIRenderer; // Save opacity - let parentOpacity = 1; + let parentOpacity = this._pOpacity === undefined ? 1 : this._pOpacity; if (node.parent) { parentOpacity = node.parent._uiProps.opacity; } let opacity = parentOpacity; // TODO Always cascade ui property's local opacity before remove it const selfOpacity = render && render.color ? render.color.a / 255 : 1; + this._pOpacity = opacity = opacity * selfOpacity * uiProps.localOpacity; - opacity *= selfOpacity * uiProps.localOpacity; // TODO Set opacity to ui property's opacity before remove it + if (uiProps[`setOpacity`]) { uiProps[`setOpacity`](opacity); - } else { - uiProps[`_opacity`] = opacity; } + uiProps[`_opacity`] = opacity; if (!approx(opacity, 0, EPSILON)) { if (uiProps.colorDirty) { // Cascade color dirty state @@ -94,6 +97,8 @@ export default class CCCExtension { __renderQueue = []; for (let i = 0; i < children.length; ++i) { const child = children[i]; + if (node.parent) + child._uiProps.colorDirty = child._uiProps.colorDirty || node.parent._uiProps.colorDirty; const enableLevelRender = node[`__enableLevelRender`]; if (!enableLevelRender) { this.walk(child, level); @@ -101,15 +106,14 @@ export default class CCCExtension { levelSplit(child, 0, i); } } - while (__renderQueue.length > 0) { - const list = __renderQueue.shift(); - if (list.length > 0) { - while (list.length > 0) { - const n = list.shift(); - this.walk(n, level); - } + for (let i = 0; i < __renderQueue.length; ++i) { + const list = __renderQueue[i]; + for (let j = 0; j < list.length; ++j) { + const n = list[j]; + this.walk(n, level); } } + __renderQueue = []; } } @@ -121,7 +125,7 @@ export default class CCCExtension { } } // Restore opacity - // this._pOpacity = parentOpacity; + this._pOpacity = parentOpacity; // Post render assembler update logic // ATTENTION: Will also reset colorDirty inside postUpdateAssembler @@ -138,6 +142,15 @@ export default class CCCExtension { } }); } + + private static _extendEditBoxTemp() { + EditBox.prototype.onDestroy = function () { + if (this._impl) { + View.instance.targetOff(this._impl); + this._impl.clear(); + } + } + } } export function updateOpacity(renderData: RenderData, opacity: number) {