Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of outline and shadow to label #16106

Merged
merged 13 commits into from
Sep 20, 2023
Merged

Conversation

LinYunMo
Copy link
Contributor

@LinYunMo LinYunMo commented Aug 25, 2023

Re: https://github.com/cocos/3d-tasks/issues/10661
depend: https://github.com/cocos/engine-extensions/pull/345

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@github-actions
Copy link

github-actions bot commented Aug 25, 2023

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -2468,33 +2468,19 @@
      *
      * @zh
      * 描边效果组件,用于字体描边,只能用于系统字体。
      *
-     * @example
-     * ```ts
-     * import { Node, Label, LabelOutline } from 'cc';
-     * // Create a new node and add label components.
-     * const node = new Node("New Label");
-     * const label = node.addComponent(Label);
-     * const outline = node.addComponent(LabelOutline);
-     * node.parent = this.node;
-     * ```
+     * @deprecated since v3.8.2, please use [[Label.enableOutline]] instead.
      */
     export class LabelOutline extends Component {
-        protected _color: math.Color;
-        protected _width: number;
         /**
          * @en
          * Outline color.
          *
          * @zh
          * 改变描边的颜色。
          *
-         * @example
-         * ```ts
-         * import { Color } from 'cc';
-         * outline.color = new Color(0.5, 0.3, 0.7, 1.0);
-         * ```
+         * @deprecated since v3.8.2, please use [[Label.outlineColor]] instead.
          */
         get color(): Readonly<math.Color>;
         set color(value: Readonly<math.Color>);
         /**
@@ -2503,18 +2489,20 @@
          *
          * @zh
          * 改变描边的宽度。
          *
-         * @example
-         * ```ts
-         * outline.width = 3;
-         * ```
+         * @deprecated since v3.8.2, please use [[Label.outlineWidth]] instead.
          */
         get width(): number;
         set width(value: number);
+        /**
+         * @deprecated since v3.8.2, please use [[Label.enableOutline]] instead.
+         */
         onEnable(): void;
+        /**
+         * @deprecated since v3.8.2, please use [[Label.enableOutline]] instead.
+         */
         onDisable(): void;
-        protected _updateRenderData(): void;
     }
     /**
      * @en
      * Graphics component.
@@ -2869,32 +2857,20 @@
     }
     /**
      * @en Shadow effect for Label component, only for system fonts or TTF fonts.
      * @zh 用于给 Label 组件添加阴影效果,只能用于系统字体或 ttf 字体。
-     * @example
-     * import { Node, Label, LabelShadow } from 'cc';
-     * // Create a new node and add label components.
-     * const node = new Node("New Label");
-     * const label = node.addComponent(Label);
-     * const shadow = node.addComponent(LabelShadow);
-     * node.parent = this.node;
+     *
+     * @deprecated since v3.8.2, please use [[Label.enableShadow]] instead.
      */
     export class LabelShadow extends Component {
-        protected _color: math.Color;
-        protected _offset: math.Vec2;
-        protected _blur: number;
         /**
          * @en
          * Shadow color.
          *
          * @zh
          * 阴影的颜色。
          *
-         * @example
-         * ```ts
-         * import { Color } from 'cc';
-         * labelShadow.color = new Color(0.5, 0.3, 0.7, 1.0);
-         * ```
+         * @deprecated since v3.8.2, please use [[Label.shadowColor]] instead.
          */
         get color(): Readonly<math.Color>;
         set color(value: Readonly<math.Color>);
         /**
@@ -2903,13 +2879,9 @@
          *
          * @zh
          * 字体与阴影的偏移。
          *
-         * @example
-         * ```ts
-         * import { Vec2 } from 'cc';
-         * labelShadow.offset = new Vec2(2, 2);
-         * ```
+         * @deprecated since v3.8.2, please use [[Label.shadowOffset]] instead.
          */
         get offset(): math.Vec2;
         set offset(value: math.Vec2);
         /**
@@ -2918,18 +2890,20 @@
          *
          * @zh
          * 阴影的模糊程度。
          *
-         * @example
-         * ```ts
-         * labelShadow.blur = 2;
-         * ```
+         * @deprecated since v3.8.2, please use [[Label.shadowBlur]] instead.
          */
         get blur(): number;
         set blur(value: number);
+        /**
+         * @deprecated since v3.8.2, please use [[Label.enableShadow]] instead.
+         */
         onEnable(): void;
+        /**
+         * @deprecated since v3.8.2, please use [[Label.enableShadow]] instead.
+         */
         onDisable(): void;
-        protected _updateRenderData(): void;
     }
     /**
      * @en
      * Set the UI transparency component.
@@ -3250,8 +3224,68 @@
          */
         get underlineHeight(): number;
         set underlineHeight(value: number);
         /**
+         ** @en
+         ** Outline effect used to change the display, only for system fonts or TTF fonts.
+         **
+         ** @zh
+         ** 描边效果组件,用于字体描边,只能用于系统字体或 ttf 字体。
+         **/
+        get enableOutline(): boolean;
+        set enableOutline(value: boolean);
+        /**
+         * @en
+         * Outline color.
+         *
+         * @zh
+         * 改变描边的颜色。
+         */
+        get outlineColor(): math.Color;
+        set outlineColor(value: math.Color);
+        /**
+         * @en
+         * Change the outline width.
+         *
+         * @zh
+         * 改变描边的宽度。
+         */
+        get outlineWidth(): number;
+        set outlineWidth(value: number);
+        /**
+         * @en Shadow effect for Label component, only for system fonts or TTF fonts. Disabled when cache mode is char.
+         * @zh 用于给 Label 组件添加阴影效果,只能用于系统字体或 ttf 字体。在缓存模式为 char 时不可用。
+         */
+        get enableShadow(): boolean;
+        set enableShadow(value: boolean);
+        /**
+         * @en
+         * Shadow color.
+         *
+         * @zh
+         * 阴影的颜色。
+         */
+        get shadowColor(): math.Color;
+        set shadowColor(value: math.Color);
+        /**
+         * @en
+         * Offset between font and shadow.
+         *
+         * @zh
+         * 字体与阴影的偏移。
+         */
+        get shadowOffset(): math.Vec2;
+        set shadowOffset(value: math.Vec2);
+        /**
+         * @en
+         * A non-negative float specifying the level of shadow blur.
+         *
+         * @zh
+         * 阴影的模糊程度。
+         */
+        get shadowBlur(): number;
+        set shadowBlur(value: number);
+        /**
          * @deprecated since v3.7.0, this is an engine private interface that will be removed in the future.
          */
         get spriteFrame(): SpriteFrame | __private._cocos_2d_assembler_label_font_utils__LetterRenderTexture | null;
         /**
@@ -3287,8 +3321,15 @@
         protected _isBold: boolean;
         protected _isUnderline: boolean;
         protected _underlineHeight: number;
         protected _cacheMode: CacheMode;
+        protected _enableOutline: boolean;
+        protected _outlineColor: math.Color;
+        protected _outlineWidth: number;
+        protected _enableShadow: boolean;
+        protected _shadowColor: math.Color;
+        protected _shadowOffset: math.Vec2;
+        protected _shadowBlur: number;
         protected _N$file: Font | null;
         protected _texture: SpriteFrame | __private._cocos_2d_assembler_label_font_utils__LetterRenderTexture | null;
         protected _ttfSpriteFrame: SpriteFrame | null;
         protected _userDefinedFont: Font | null;

@@ -77,7 +68,10 @@ export class LabelShadow extends Component {
}

this._color.set(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No needs to cache color anymore, just set label's property directly

@@ -100,7 +90,10 @@ export class LabelShadow extends Component {

set offset (value) {
this._offset = value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No needs to cache color anymore, just set label's property directly

@@ -82,7 +70,10 @@ export class LabelOutline extends Component {
}

this._color.set(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No needs to cache color anymore, just set label's property directly

@editable
@displayOrder(19)
@tooltip('i18n:label.outline_used')
get outlineUsed (): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the names in other software

Copy link
Contributor Author

@LinYunMo LinYunMo Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UE: Outlined enableShadow
Godot: outline_size shadow_outline_size
UGUI:皆为单独组件

@LinYunMo
Copy link
Contributor Author

@cocos-robot run test cases

@LinYunMo
Copy link
Contributor Author

@cocos-robot run test cases

let shadowComp = LabelShadow && comp.getComponent(LabelShadow);
shadowComp = (shadowComp && shadowComp.enabled) ? shadowComp : null;
if (shadowComp) {
const isShadow = comp.enableShadow && (comp.shadowBlur > 0 || comp.shadowOffset.x !== 0 || comp.shadowOffset.y !== 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use approx instead!

/**
* @deprecated since v3.8.2, please use [[Label.enableOutline]] instead.
*/
public onLoad (): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems not needs onLoad anymore.

** Outline effect used to change the display, only for system fonts or TTF fonts.
**
** @zh
** 描边效果组件,用于字体描边,只能用于系统字体。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description is not correct. And should hide it when font is BMFont?

@PPpro PPpro mentioned this pull request Sep 18, 2023
6 tasks
@LinYunMo LinYunMo closed this Sep 20, 2023
@LinYunMo LinYunMo reopened this Sep 20, 2023
@SantyWang SantyWang merged commit d2d7623 into cocos:v3.8.2 Sep 20, 2023
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants