BallSkinItem.ts
5.09 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
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { SaveDataManager } from "../component/SaveDataManager";
import { GlobalEvent, tMgr, WindowName } from "../Global";
import { getGlobalNode } from "../kernel/battle/BattleConst";
import { BallSkinTable, TableName } from "../kernel/table/TableDefine";
import { UIManager } from "../ui/UIManager";
const { ccclass, property } = cc._decorator;
@ccclass
export default class BallSkinItem extends cc.Component {
protected onLoad(): void {
getGlobalNode().on(GlobalEvent.BALL_SKIN_UNLOCK, this.refreshState, this);
getGlobalNode().on(GlobalEvent.BALL_SKIN_USE, this.refreshState, this);
}
protected onDestroy(): void {
getGlobalNode().targetOff(this);
}
private _config: BallSkinTable = null;
setBallSkinItem(id: number) {
if (id > 0) {
let config = tMgr.getConfig(TableName.BALL_SKIN, id) as BallSkinTable;
if (config) {
this._config = config;
this.node.getChildByName('icon').active = true;
cc.resources.load('battle/' + config.Img, cc.SpriteFrame, (error, asset) => {
if (!error) {
this.node.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = asset as cc.SpriteFrame;
}
})
}
}
else {
this.node.getChildByName('icon').active = false;
this._config = null;
}
this.refreshState();
}
private refreshState() {
let isAd = (this._config == null);
let isUnlocked = !isAd && SaveDataManager.ins.runtimeData.ballSkinUnlocked.includes(this._config.ID);
let isUsing = !isAd && (SaveDataManager.ins.runtimeData.ballSkinCurrent == this._config.ID);
this.node.getChildByName('txtName').getComponent(cc.Label).string = (isAd ? "" : this._config.Name);
//#region 显示尺寸
this.node.getChildByName('imgSize1').active = (!isAd && this._config.Size == 1);
this.node.getChildByName('imgSize2').active = (!isAd && this._config.Size == 2);
this.node.getChildByName('imgSize3').active = (!isAd && this._config.Size == 3);
//#endregion
this.node.getChildByName('btnBuy').active = !isAd && !isUnlocked;
this.node.getChildByName('btnSign').active = !isAd && !isUnlocked;
this.node.getChildByName('btnWheel').active = !isAd && !isUnlocked;
this.node.getChildByName('btnUse').active = !isAd && isUnlocked;
this.node.getChildByName('btnUsing').active = !isAd && isUnlocked;
this.node.getChildByName('btnAd').active = isAd;
if (!isAd) {
if (isUnlocked) {
//已经解锁了
this.node.getChildByName('btnUse').active = !isUsing;
this.node.getChildByName('btnUsing').active = isUsing;
}
else {
//未解锁
this.node.getChildByName('btnBuy').active = (this._config.Price > 0);
this.node.getChildByName('btnSign').active = (this._config.Price == -1);
this.node.getChildByName('btnWheel').active = (this._config.Price == -2);
if (this._config.Price > 0) {
this.node.getChildByName('btnBuy').getComponentInChildren(cc.Label).string = this._config.Price.toString();
}
}
} else {
this.node.getChildByName('btnAd').getChildByName('Background').getChildByName('UI_Skin_btn_cjhd').active = true;
this.node.getChildByName('btnAd').getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false;
// this.node.getChildByName('nodeAd').getComponent(CustomNativeAdView).showNativeAd((result) => {
// if (result) {
// this.node.getChildByName('btnAd').active = true;
// } else {
// this.node.getChildByName('btnAd').active = false;
// }
// });
}
}
onBtnBuyClick() {
if (this._config) {
// let wpos = this.node.getChildByName('btnBuy').convertToWorldSpaceAR(cc.v3(0, 0, 0));
// if (SaveDataManager.ins.adjustDiamond(-this._config.Price, true, wpos)) {
// SaveDataManager.ins.unlockBallSkin(this._config.ID);
// }
UIManager.ins.openWindow(WindowName.BALL_SKIN_PREVIEW, this._config.ID);
}
}
onHideAdBtn() {
this.node.getChildByName('btnAd').active = false;
}
onBtnWheelClick() {
UIManager.ins.openWindow(WindowName.WHEEL);
}
onBtnSignClick() {
UIManager.ins.openWindow(WindowName.SIGN);
}
onBtnAdClick() {
//AD 纯放广告
}
onBtnUseClick() {
if (this._config) {
SaveDataManager.ins.useBallSkin(this._config.ID);
}
}
}