a7b633b7-40e9-44d5-a542-79cf1ff20fa7.js
7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"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();