Skip to content

Commit

Permalink
name change & use assert
Browse files Browse the repository at this point in the history
  • Loading branch information
LinYunMo committed Sep 14, 2023
1 parent cc3aae0 commit 2ec6076
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 85 deletions.
4 changes: 2 additions & 2 deletions cocos/2d/assembler/label/ttfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const ttfUtils = {
style.underlineHeight = comp.underlineHeight;

// outline// both
const isOutlined = comp.outlineUsed && comp.outlineWidth > 0;
const isOutlined = comp.enableOutline && comp.outlineWidth > 0;
if (isOutlined) {
style.isOutlined = true;
style.outlineColor.set(comp.outlineColor);
Expand All @@ -78,7 +78,7 @@ export const ttfUtils = {
}

// shadow// both
const isShadow = comp.shadowUsed;
const isShadow = comp.enableShadow && (comp.shadowBlur > 0 || comp.shadowOffset.x !== 0 || comp.shadowOffset.y !== 0);
if (isShadow) {
style.hasShadow = true;
style.shadowColor.set(comp.shadowColor);
Expand Down
44 changes: 17 additions & 27 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, warn } from '../../core';
import { Color, assertIsTrue, cclegacy } from '../../core';
import { Label } from './label';

/**
Expand Down Expand Up @@ -59,21 +59,16 @@ export class LabelOutline extends Component {
* @deprecated since v3.8.2, please use [[Label.outlineColor]] instead.
*/
@tooltip('i18n:labelOutline.color')
// @constget
get color (): Readonly<Color> {
const label = this.node.getComponent(Label);
if (!label) {
warn('Required Label component to work, please add Label component.');
return this._color;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
return label.outlineColor;
}

set color (value) {
const label = this.node.getComponent(Label);
if (label) {
label.outlineColor = value;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.outlineColor = value;
}

/**
Expand All @@ -88,47 +83,42 @@ export class LabelOutline extends Component {
@tooltip('i18n:labelOutline.width')
get width (): number {
const label = this.node.getComponent(Label);
if (!label) {
warn('Required Label component to work, please add Label component.');
return this._width;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
return label.outlineWidth;
}

set width (value) {
const label = this.node.getComponent(Label);
if (label) {
label.outlineWidth = value;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.outlineWidth = value;
}

/**
* @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead.
* @deprecated since v3.8.2, please use [[Label.enableOutline]] instead.
*/
public onEnable (): void {
const label = this.node.getComponent(Label);
if (label) {
label.outlineUsed = true;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.enableOutline = true;
}

/**
* @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead.
* @deprecated since v3.8.2, please use [[Label.enableOutline]] instead.
*/
public onDisable (): void {
const label = this.node.getComponent(Label);
if (label) {
label.outlineUsed = false;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.enableOutline = false;
}

/**
* @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead.
* @deprecated since v3.8.2, please use [[Label.enableOutline]] instead.
*/
public onLoad (): void {
const label = this.node.getComponent(Label);
if (label && this.enabledInHierarchy) {
label.outlineUsed = true;
assertIsTrue(label, 'Required Label component to work, please add Label component.');
if (this.enabledInHierarchy) {
label.enableOutline = true;
}
}
}
Expand Down
53 changes: 20 additions & 33 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, warn } from '../../core';
import { Color, Vec2, assertIsTrue } from '../../core';
import { Label } from './label';

/**
Expand Down Expand Up @@ -60,18 +60,14 @@ export class LabelShadow extends Component {
@tooltip('i18n:labelShadow.color')
get color (): Readonly<Color> {
const label = this.node.getComponent(Label);
if (!label) {
warn('Required Label component to work, please add Label component.');
return this._color;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
return label.shadowColor;
}

set color (value) {
const label = this.node.getComponent(Label);
if (label) {
label.shadowColor = value;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.shadowColor = value;
}

/**
Expand All @@ -86,18 +82,14 @@ export class LabelShadow extends Component {
@tooltip('i18n:labelShadow.offset')
get offset (): Vec2 {
const label = this.node.getComponent(Label);
if (!label) {
warn('Required Label component to work, please add Label component.');
return this._offset;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
return label.shadowOffset;
}

set offset (value) {
const label = this.node.getComponent(Label);
if (label) {
label.shadowOffset = value;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.shadowOffset = value;
}

/**
Expand All @@ -112,47 +104,42 @@ export class LabelShadow extends Component {
@tooltip('i18n:labelShadow.blur')
get blur (): number {
const label = this.node.getComponent(Label);
if (!label) {
warn('Required Label component to work, please add Label component.');
return this._blur;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
return label.shadowBlur;
}

set blur (value) {
const label = this.node.getComponent(Label);
if (label) {
label.shadowBlur = value;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.shadowBlur = value;
}

/**
* @deprecated since v3.8.2, please use [[Label.shadowUsed]] instead.
* @deprecated since v3.8.2, please use [[Label.enableShadow]] instead.
*/
public onEnable (): void {
const label = this.node.getComponent(Label);
if (label) {
label.shadowUsed = true;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.enableShadow = true;
}

/**
* @deprecated since v3.8.2, please use [[Label.shadowUsed]] instead.
* @deprecated since v3.8.2, please use [[Label.enableShadow]] instead.
*/
public onDisable (): void {
const label = this.node.getComponent(Label);
if (label) {
label.shadowUsed = false;
}
assertIsTrue(label, 'Required Label component to work, please add Label component.');
label.enableShadow = false;
}

/**
* @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead.
* @deprecated since v3.8.2, please use [[Label.enableShadow]] instead.
*/
public onLoad (): void {
const label = this.node.getComponent(Label);
if (label && this.enabledInHierarchy) {
label.shadowUsed = true;
assertIsTrue(label, 'Required Label component to work, please add Label component.');
if (this.enabledInHierarchy) {
label.enableShadow = true;
}
}
}
38 changes: 19 additions & 19 deletions cocos/2d/components/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,13 @@ export class Label extends UIRenderer {
**/
@editable
@displayOrder(19)
@tooltip('i18n:label.outline_used')
get outlineUsed (): boolean {
return this._isOutline;
@tooltip('i18n:label.outline_enable')
get enableOutline (): boolean {
return this._enableOutline;
}
set outlineUsed (value) {
if (this._isOutline === value) return;
this._isOutline = value;
set enableOutline (value) {
if (this._enableOutline === value) return;
this._enableOutline = value;
this.markForUpdateRenderData();
}

Expand All @@ -630,7 +630,7 @@ export class Label extends UIRenderer {
* 改变描边的颜色。
*/
@editable
@visible(function (this: Label) { return this._isOutline; })
@visible(function (this: Label) { return this._enableOutline; })

Check warning on line 633 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(20)
@tooltip('i18n:label.outline_color')
get outlineColor (): Color {
Expand All @@ -650,7 +650,7 @@ export class Label extends UIRenderer {
* 改变描边的宽度。
*/
@editable
@visible(function (this: Label) { return this._isOutline; })
@visible(function (this: Label) { return this._enableOutline; })

Check warning on line 653 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(21)
@tooltip('i18n:label.outline_width')
get outlineWidth (): number {
Expand All @@ -668,13 +668,13 @@ export class Label extends UIRenderer {
*/
@editable
@displayOrder(22)
@tooltip('i18n:label.shadow_used')
get shadowUsed (): boolean {
return this._isShadow;
@tooltip('i18n:label.shadow_enable')
get enableShadow (): boolean {
return this._enableShadow;
}
set shadowUsed (value) {
if (this._isShadow === value) return;
this._isShadow = value;
set enableShadow (value) {
if (this._enableShadow === value) return;
this._enableShadow = value;
this.markForUpdateRenderData();
}

Expand All @@ -686,7 +686,7 @@ export class Label extends UIRenderer {
* 阴影的颜色。
*/
@editable
@visible(function (this: Label) { return this._isShadow; })
@visible(function (this: Label) { return this._enableShadow; })

Check warning on line 689 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(23)
@tooltip('i18n:label.shadow_color')
get shadowColor (): Color {
Expand All @@ -706,7 +706,7 @@ export class Label extends UIRenderer {
* 字体与阴影的偏移。
*/
@editable
@visible(function (this: Label) { return this._isShadow; })
@visible(function (this: Label) { return this._enableShadow; })

Check warning on line 709 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(24)
@tooltip('i18n:label.shadow_offset')
get shadowOffset (): Vec2 {
Expand All @@ -726,7 +726,7 @@ export class Label extends UIRenderer {
* 阴影的模糊程度。
*/
@editable
@visible(function (this: Label) { return this._isShadow; })
@visible(function (this: Label) { return this._enableShadow; })

Check warning on line 729 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(25)
@tooltip('i18n:label.shadow_blur')
get shadowBlur (): number {
Expand Down Expand Up @@ -841,13 +841,13 @@ export class Label extends UIRenderer {
@serializable
protected _cacheMode = CacheMode.NONE;
@serializable
protected _isOutline = false;
protected _enableOutline = false;
@serializable
protected _outlineColor = new Color(0, 0, 0, 255);
@serializable
protected _outlineWidth = 2;
@serializable
protected _isShadow = false;
protected _enableShadow = false;
@serializable
protected _shadowColor = new Color(0, 0, 0, 255);
@serializable
Expand Down
4 changes: 2 additions & 2 deletions editor/i18n/en/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ module.exports = link(mixin({
font_underline: 'Font underlined',
spacing_x: 'The spacing between text characters, only available in BMFont',
underline_height: 'The height of underline',
outline_used: 'Whether outline is enabled',
outline_enable: 'Whether outline is enabled',
outline_width: 'The width of outline',
outline_color: 'The color of outline',
shadow_used: 'Whether shadow is enabled',
shadow_enable: 'Whether shadow is enabled',
shadow_color: 'The color of shadow',
shadow_offset: 'Offset between font and shadow',
shadow_blur: 'A non-negative float specifying the level of shadow blur',
Expand Down
4 changes: 2 additions & 2 deletions editor/i18n/zh/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ module.exports = link(mixin({
font_underline: '字体加下划线',
spacing_x: '文本字符之间的间距。仅在使用 BMFont 位图字体时生效',
underline_height: '下划线高度',
outline_used: '是否启用描边',
outline_enable: '是否启用描边',
outline_width: '描边宽度',
outline_color: '描边颜色',
shadow_used: '是否启用阴影',
shadow_enable: '是否启用阴影',
shadow_color: '阴影颜色',
shadow_offset: '阴影偏移量',
shadow_blur: '阴影模糊程度',
Expand Down

0 comments on commit 2ec6076

Please sign in to comment.