From cc3aae0a9ef1f73c7817f7bcba04397e9760f28e Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Fri, 8 Sep 2023 16:34:58 +0800 Subject: [PATCH] change getter/setter --- cocos/2d/components/label-outline.ts | 30 +++++++++++------------ cocos/2d/components/label-shadow.ts | 36 +++++++++++++++++----------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/cocos/2d/components/label-outline.ts b/cocos/2d/components/label-outline.ts index 7386b351f6d..cd4115b3a4c 100644 --- a/cocos/2d/components/label-outline.ts +++ b/cocos/2d/components/label-outline.ts @@ -25,7 +25,7 @@ import { ccclass, help, executionOrder, menu, tooltip, requireComponent, executeInEditMode, serializable } from 'cc.decorator'; import { Component } from '../../scene-graph/component'; -import { Color, cclegacy } from '../../core'; +import { Color, cclegacy, warn } from '../../core'; import { Label } from './label'; /** @@ -61,18 +61,18 @@ export class LabelOutline extends Component { @tooltip('i18n:labelOutline.color') // @constget get color (): Readonly { - return this._color; + const label = this.node.getComponent(Label); + if (!label) { + warn('Required Label component to work, please add Label component.'); + return this._color; + } + return label.outlineColor; } set color (value) { - if (this._color === value) { - return; - } - - this._color.set(value); const label = this.node.getComponent(Label); if (label) { - label.outlineColor = this._color; + label.outlineColor = value; } } @@ -87,18 +87,18 @@ export class LabelOutline extends Component { */ @tooltip('i18n:labelOutline.width') get width (): number { - return this._width; + const label = this.node.getComponent(Label); + if (!label) { + warn('Required Label component to work, please add Label component.'); + return this._width; + } + return label.outlineWidth; } set width (value) { - if (this._width === value) { - return; - } - - this._width = value; const label = this.node.getComponent(Label); if (label) { - label.outlineWidth = this._width; + label.outlineWidth = value; } } diff --git a/cocos/2d/components/label-shadow.ts b/cocos/2d/components/label-shadow.ts index c65ea7aa155..886b308f348 100644 --- a/cocos/2d/components/label-shadow.ts +++ b/cocos/2d/components/label-shadow.ts @@ -25,7 +25,7 @@ import { ccclass, help, executionOrder, menu, tooltip, requireComponent, executeInEditMode, serializable } from 'cc.decorator'; import { Component } from '../../scene-graph/component'; -import { Color, Vec2 } from '../../core'; +import { Color, Vec2, warn } from '../../core'; import { Label } from './label'; /** @@ -59,18 +59,18 @@ export class LabelShadow extends Component { */ @tooltip('i18n:labelShadow.color') get color (): Readonly { - return this._color; + const label = this.node.getComponent(Label); + if (!label) { + warn('Required Label component to work, please add Label component.'); + return this._color; + } + return label.shadowColor; } set color (value) { - if (this._color === value) { - return; - } - - this._color.set(value); const label = this.node.getComponent(Label); if (label) { - label.shadowColor = this._color; + label.shadowColor = value; } } @@ -85,14 +85,18 @@ export class LabelShadow extends Component { */ @tooltip('i18n:labelShadow.offset') get offset (): Vec2 { - return this._offset; + const label = this.node.getComponent(Label); + if (!label) { + warn('Required Label component to work, please add Label component.'); + return this._offset; + } + return label.shadowOffset; } set offset (value) { - this._offset = value; const label = this.node.getComponent(Label); if (label) { - label.shadowOffset = this._offset; + label.shadowOffset = value; } } @@ -107,14 +111,18 @@ export class LabelShadow extends Component { */ @tooltip('i18n:labelShadow.blur') get blur (): number { - return this._blur; + const label = this.node.getComponent(Label); + if (!label) { + warn('Required Label component to work, please add Label component.'); + return this._blur; + } + return label.shadowBlur; } set blur (value) { - this._blur = value; const label = this.node.getComponent(Label); if (label) { - label.shadowBlur = this._blur; + label.shadowBlur = value; } }