a7b633b7-40e9-44d5-a542-79cf1ff20fa7.js 7.52 KB
"use strict";
cc._RF.push(module, 'a7b63O3QOlE1aVCec8f8g+n', 'CCCooperationItem');
// script/cooperation/script/CCCooperationItem.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CCCooperationItem = void 0;
const simba_cc_resutils_1 = require("simba-cc-resutils");
const CCDummyObjects_1 = require("../../common/CCDummyObjects");
const EventCenter_1 = require("../event/EventCenter");
const CooperationClassBase_1 = require("./CooperationClassBase");
const CooperationDataCenter_1 = require("./CooperationDataCenter");
const CooperationDotMgr_1 = require("./CooperationDotMgr");
/**cocos合作item组件 */
const { ccclass, property } = cc._decorator;
let CCCooperationItem = /** @class */ (() => {
    let CCCooperationItem = class CCCooperationItem extends cc.Component {
        constructor() {
            super(...arguments);
            this.iconSprite = CCDummyObjects_1.DummySprite;
            this.nameLabel = CCDummyObjects_1.DummyLabel;
            this.playingUserLabel = CCDummyObjects_1.DummyLabel;
            this.location = CooperationDataCenter_1.SubGameLocation.GameCenter;
            this.ossPath = CooperationClassBase_1.CooperationClassBase.COO_OSS_PATH_DEV;
            this.diyColor = CCDummyObjects_1.DummyColor;
            this.useDIYColor = false;
            this._localSFPath = "textures/cooperationItems/";
            this._localSFArr = [
                "dlmhsj",
                "fakeprince2",
                "feidao",
                "huanyuanshi",
                "jiawangzi",
                "jiujiu",
                "lianaiyujing",
                "mrqm",
                "shanyoufusu",
                "shenmiriji",
                "sxjsl",
                "wodedadao",
                "wolianzeida",
                "yybs"
            ];
        }
        /***设置release还是dev */
        setRelease(release = false) {
            this.ossPath = release ? CooperationClassBase_1.CooperationClassBase.COO_OSS_PATH_RELEASE : CooperationClassBase_1.CooperationClassBase.COO_OSS_PATH_DEV;
        }
        /**设置当前模型所处的位置标识 */
        setLocation(location) {
            this.location = location;
        }
        /**绑定数据 */
        bindData(data) {
            if (!data) {
                return;
            }
            this.dataModel = data;
            this.refreshItem(data);
        }
        /**刷新模型 */
        refreshItem(data) {
            if (!data && !this.dataModel) {
                return;
            }
            if (data) {
                this.refreshIcon(data.icon);
                this.refreshName(data.appName);
                this.refreshPlayingUser();
                this.refreshNameColor();
            }
            else {
                console.error('data is null');
            }
        }
        /**刷新icon */
        refreshIcon(icon) {
            let spr = this.iconSprite;
            let iconName = icon.split(".")[0];
            let isLocal = this._localSFArr.findIndex((v) => v === iconName) !== (-1);
            let loaclPath = this._localSFPath + iconName;
            return new Promise((resolve, reject) => {
                if (isLocal) {
                    simba_cc_resutils_1.ResUtils.loadRes(loaclPath, cc.SpriteFrame).then((sf) => {
                        spr.spriteFrame = sf;
                        resolve(true);
                    });
                }
                else {
                    let path = this.ossPath + CooperationDataCenter_1.default.getInstance().getCurGameID() + CooperationClassBase_1.CooperationClassBase.IMG_PATH + icon;
                    cc.assetManager.loadRemote(path, (err, sprite) => {
                        if (err) {
                            reject(err);
                        }
                        else {
                            spr.spriteFrame = new cc.SpriteFrame(sprite);
                            resolve(true);
                        }
                    });
                }
            });
        }
        /**刷新name */
        refreshName(name) {
            if (!name || !this.nameLabel) {
                return;
            }
            this.nameLabel.node.active = !!this.dataModel.showAppName;
            this.nameLabel.string = name;
        }
        /**设置name的字体颜色 */
        refreshNameColor() {
            if (!this.nameLabel) {
                return;
            }
            let c = cc.color(255, 255, 255);
            if (this.useDIYColor && this.diyColor) {
                c = this.diyColor;
            }
            this.nameLabel.node.color = c;
            if (!this.playingUserLabel) {
                return;
            }
            this.playingUserLabel.node.color = c;
        }
        /**刷新正在玩的玩家数量 */
        refreshPlayingUser() {
            if (!this.playingUserLabel) {
                return;
            }
            this.playingUserLabel.node.active = !!this.dataModel.showPlayingUser;
            if (!this.dataModel.userMin)
                this.dataModel.userMin = 0;
            let min = this.dataModel.userMin > 0 ? this.dataModel.userMin : 0;
            if (!this.dataModel.userMax)
                this.dataModel.userMax = 0;
            let max = this.dataModel.userMax > 0 && this.dataModel.userMax > min ? this.dataModel.userMax : min + 100;
            let num = Math.ceil(Math.random() * (max - min) + min);
            this.playingUserLabel.string = num.toString() + "在玩";
        }
        /**Item点击回调 */
        onItemClick() {
            CooperationDotMgr_1.default.getInstance().dotClickSubGame(this.dataModel.appId, this.dataModel.appName, this.dataModel.index, this.location);
            EventCenter_1.EventCenter.OPEN_SUBGAME_BY_APPID.emit(this.dataModel.appId);
        }
    };
    __decorate([
        property({ type: cc.Sprite, visible: true, displayName: "iconSprite", tooltip: "小游戏icon精灵" })
    ], CCCooperationItem.prototype, "iconSprite", void 0);
    __decorate([
        property({ type: cc.Label, visible: true, displayName: "nameLabel", tooltip: "小游戏name标签" })
    ], CCCooperationItem.prototype, "nameLabel", void 0);
    __decorate([
        property({ type: cc.Label, visible: true, displayName: "playingUserLabel", tooltip: "小游戏多少人正在玩标签" })
    ], CCCooperationItem.prototype, "playingUserLabel", void 0);
    __decorate([
        property({ tooltip: "当前游戏所处的位置:主界面(mainUI)、游戏中心列表(gameCenter)、朋友圈列表(momentCenter)" })
    ], CCCooperationItem.prototype, "location", void 0);
    __decorate([
        property({ type: cc.Color, tooltip: "个性化定制字体颜色", displayName: "diyLabelColor" })
    ], CCCooperationItem.prototype, "diyColor", void 0);
    __decorate([
        property
    ], CCCooperationItem.prototype, "useDIYColor", void 0);
    CCCooperationItem = __decorate([
        ccclass
    ], CCCooperationItem);
    return CCCooperationItem;
})();
exports.CCCooperationItem = CCCooperationItem;

cc._RF.pop();