MessageEntryItem.ts 2.15 KB
import { MessageEntryItemProps } from "../type/MessageView";
import { DummyLabel, DummyNode, DummyRichText, DummySprite } from "../../../../common/CCDummyObjects";
import { ListItemImpl } from "../../baseview/impl/ListItemImpl";
import { ResUtils } from "simba-cc-resutils";

const { ccclass, property } = cc._decorator;

@ccclass
export class MessageEntryItemImpl extends ListItemImpl<MessageEntryItemProps> {

    @property({ type: cc.RichText })
    protected lastMsgLabel: cc.RichText = DummyRichText;

    @property(cc.Sprite)
    protected iconSprite: cc.Sprite = DummySprite;

    @property(cc.Sprite)
    protected nameSprite: cc.Sprite = DummySprite;

    @property(cc.Node)
    private addGraceBtnNode: cc.Node = DummyNode;

    @property(cc.Node)
    private addNode: cc.Node = DummyNode;

    @property(cc.Label)
    private graceLevel: cc.Label = DummyLabel;

    @property(cc.Node)
    redDotNode: cc.Node = DummyNode;


    onLoad() {
        this.bindProp("nameSpr", async (value) => {
            if (value && "" !== value.trim()) {
                this.nameSprite.spriteFrame = await ResUtils.loadRes(value, cc.SpriteFrame);
            }
        });
        this.bindProp("lastMsg", this.lastMsgLabel, "string");
        this.bindProp("redDot", this.redDotNode, "active");
        this.bindProp("icons", async (value) => {
            if (value.length == 1) {
                this.iconSprite.spriteFrame = await ResUtils.loadRes(value[0], cc.SpriteFrame);
            }
        });

        this.bindProp("level", (v) => {
            this.graceLevel.string = v + "";
        });
        this.bindProp("isShowAddGrace", async (value) => {
            this.addNode.active = value;
            if (value) {
                cc.tween(this.addGraceBtnNode)
                    .repeatForever(cc.tween()
                        .to(0.8, { scale: 1.15 }, { easing: 'sineInOut' })
                        .to(0.8, { scale: 1 }, { easing: 'sineInOut' }))
                    .start();
            }
        });
        this.bindProp("isShowGrace", this.addGraceBtnNode, "active");
    }

    onAddGraceClickCallBack() {
        this._props.addGraceClickCallBack(this._props.roleId);
    }
}