UIUserSkillInfo.ts
3.19 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
// 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 { ADID, tMgr, WindowName } from "../../Global";
import { TableName, UserSkillTable } from "../../kernel/table/TableDefine";
import { UIBase } from "../UIBase";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass
export default class UIUserSkillInfo extends UIBase {
private _config: UserSkillTable;
//#region LIFE-CYCLE CALLBACKS:
// onLoad () {}
@property(cc.Node)
btn_ad: cc.Node = null;
@property(cc.Node)
btn_start: cc.Node = null;
@property(cc.Node)
btn_bonus: cc.Node = null;
openCount: number = 0;
protected onEnable(): void {
let skillId = this.enableParam;
this._config = tMgr.getConfig(TableName.USER_SKILL, skillId) as UserSkillTable;
this.node.getChildByName('txtDesc').getComponent(cc.Label).string = this._config.Desc;
cc.resources.load('ui/battle/' + this._config.Icon, cc.SpriteFrame, (error, asset) => {
if (!error) {
this.node.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = asset as cc.SpriteFrame;
}
});
this.node.getChildByName('btnDiamond').getComponentInChildren(cc.Label).string = this._config.Cost.toString();
this.node.getChildByName('icon').getComponentInChildren(cc.Label).string = this._config.BuyNum.toString();
this.btn_ad.getChildByName('Background').getChildByName('UI_General_Btn_yellow_ckgg').active = true;
this.btn_ad.getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false;
this.openCount++;
if (this.openCount > 1) {
this.BtnPos_Change();
}
}
//按钮位置轮换
BtnPos_Change() {
let tempPos = this.btn_start.position;
this.btn_start.position = this.btn_bonus.position;
this.btn_bonus.position = this.btn_ad.position;
this.btn_ad.position = tempPos;
}
// update (dt) {}
//#endregion
//#region event
onBtnCloseClick() {
UIManager.ins.closeWindow(WindowName.USER_SKILL_INFO);
}
onBtnAdClick() {
//AD 放广告,放完后调用 doAddNum()
// HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
if (true) {
this.doAddNum();
} else {
console.log('视频播放失败');
}
// });
this.onBtnCloseClick();
}
onBtnBuyClick() {
if (SaveDataManager.ins.adjustDiamond(-this._config.Cost)) {
//扣钱成功
this.doAddNum();
this.onBtnCloseClick();
}
else {
console.log('diamond donot enough')
}
}
//#endregion
//#region private method
private doAddNum() {
SaveDataManager.ins.setUserSkillNumDelta(this._config.ID, this._config.BuyNum);
}
//#endregion
}