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

修复Laya下图文混排不支持动画表情的问题 #83

Open
CoderMzx opened this issue Apr 27, 2023 · 0 comments
Open

修复Laya下图文混排不支持动画表情的问题 #83

CoderMzx opened this issue Apr 27, 2023 · 0 comments

Comments

@CoderMzx
Copy link

CoderMzx commented Apr 27, 2023

无法Fork2.13的分支,只能在这里提了,3.0的修复方法理论一样

新建 ChatAni.ts 类

export class ChatAni extends Laya.HTMLImageElement {
    private _srcc: string;
    private frames: Array<fairygui.Frame> = [];
    constructor() {
        super();
        this.width = 72;
    }
    public set emoji(id: string) {
        this._srcc = id;
        this.frames = []
        let movie = fgui.UIPackage.createObjectFromURL(id).asMovieClip;
        let clip: fgui.MovieClip = movie.displayObject as fgui.MovieClip
        for (let i: number = 0; i < clip.frames.length; i++) {
            this.frames.push(clip.frames[i])
        }
        this.onloadHandler();
    }
    public get emoji() {
        return this._srcc;
    }
    private onloadHandler() {
        if (this.frames) {
            Laya.timer.loop(120, this, this.loopHandler);
            this.loopHandler();
        } else {
            Laya.timer.clear(this, this.loopHandler);
        }
    }
    private _count: number = 0;
    private loopHandler() {
        let frames = this.frames;
        let _count = this._count;
        let frame = frames[_count];
        this.width = frame.texture.width;
        this.height = frame.texture.height;
        this["_tex"] = frame.texture
        this.repaint()
        _count++;
        if (_count > frames.length - 1) {
            _count = 0;
        }
        this._count = _count;
    }
    public destroy() {
        super.destroy();
        Laya.timer.clear(this, this.loopHandler);
    }
    private isListener: boolean;
    public renderSelfToGraphic(graphic: Laya.Graphics, gX: number, gY: number, recList: any[]): void {
        let isListener = this.isListener;
        if (!isListener) {
            let _sp: Laya.Node = graphic["_sp"];
            if (_sp) {
                _sp.on(Laya.Event.DISPLAY, this, this.onDisplay);
                _sp.on(Laya.Event.UNDISPLAY, this, this.onUnDisplay);

                this.isListener = isListener = true;
            }
        }
        super.renderSelfToGraphic(graphic, gX, gY, recList);
    }
    private onDisplay(): void {
        this.onloadHandler();
    }
    private onUnDisplay(): void {
        Laya.timer.clear(this, this.loopHandler);
    }
}

在Main.ts的onConfigLoaded函数中添加
Laya.ClassUtils.regClass("femoji", ChatAni);

EmojiParser.ts 类中 onTag_Emoji 方法修改为

private onTag_Emoji(tagName: string, end: boolean, attr: string): string {
        return `<femoji emoji="${fgui.UIPackage.getItemURL("Chat", tagName.substring(1).toLowerCase())}"></femoji>`;
    }
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

No branches or pull requests

1 participant