SinInDayitemImpl.ts 1.84 KB
import { DummyLabel, DummySprite, DummyNode } from "../../../../common/CCDummyObjects";
import { SininDayItemProps } from "../type/SininSevenDayView";
import { ResUtils } from "../../../../common/utils/ResUtils";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SininDayItemImpl extends cc.Component {

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    private _viewProps: SininDayItemProps =
        {
            key: "",
            titlecontent: "",
            itemicon: "",
            number: "",
            itemmask: true
        };

    @property(cc.Label)
    item_title: cc.Label = DummyLabel;

    @property(cc.Sprite)
    item_icon: cc.Sprite = DummySprite;

    @property(cc.Label)
    number: cc.Label = DummyLabel;

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

    setSininDayItem(item: SininDayItemProps) {
        if (this._viewProps.key != item.key) {
            this._viewProps.key = item.key;
        }


        if (this._viewProps.titlecontent != item.titlecontent) {
            this._viewProps.titlecontent = item.titlecontent;
            this.item_title.string = item.titlecontent;
        }


        if (this._viewProps.itemicon != item.itemicon) {
            ResUtils.loadRes<cc.SpriteFrame>(item.itemicon, cc.SpriteFrame).then((value) => {
                this.item_icon.spriteFrame = value;
            });

            this._viewProps.itemicon = item.itemicon;
        }

        if (this._viewProps.number != item.number) {
            this.number.string = item.number;
            this._viewProps.number = item.number;
        }

        if (this._viewProps.itemmask != item.itemmask) {
            this.item_mask.active = item.itemmask;
            this._viewProps.itemmask = item.itemmask;
        }

    }

    // update (dt) {}
}