Skip to content

Commit

Permalink
change getter/setter
Browse files Browse the repository at this point in the history
  • Loading branch information
LinYunMo committed Sep 8, 2023
1 parent 8a532e8 commit cc3aae0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
30 changes: 15 additions & 15 deletions cocos/2d/components/label-outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -61,18 +61,18 @@ export class LabelOutline extends Component {
@tooltip('i18n:labelOutline.color')
// @constget
get color (): Readonly<Color> {
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;
}
}

Expand All @@ -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;
}
}

Expand Down
36 changes: 22 additions & 14 deletions cocos/2d/components/label-shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -59,18 +59,18 @@ export class LabelShadow extends Component {
*/
@tooltip('i18n:labelShadow.color')
get color (): Readonly<Color> {
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;
}
}

Expand All @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down

0 comments on commit cc3aae0

Please sign in to comment.