UIRevive.ts
4.81 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
// 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 { SoundManager } from "../../component/SoundManager";
import { ADID, SoundName, WindowName } from "../../Global";
import { BattleManager } from "../../kernel/battle/BattleManager";
import { UserSkillShuriken } from "../../kernel/battle/userSkill/UserSkillShuriken";
import { UIBase } from "../UIBase";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass
export default class UIRevive extends UIBase {
private _reviveCount: number = 0;
private _diamondCount: number = 0;
private _countDown: number = 5;
private _countDownNodeList: cc.Node[] = [];
@property(cc.Node)
btn_ad: cc.Node = null;
@property(cc.Node)
btn_start: cc.Node = null;
@property(cc.Node)
btn_bonus: cc.Node = null;
//#region LIFE-CYCLE CALLBACKS:
openCount: number = 0;
onLoad() {
for (let i = 0; i < 6; ++i) {
this._countDownNodeList.push(this.node.getChildByName('countdownNode').getChildByName('imgCount' + i.toString()))
}
}
protected onEnable(): void {
this._reviveCount = BattleManager.ins.curBattle.reviveCount;
this._diamondCount = (this._reviveCount + 1) * 100;
this.node.getChildByName('btnDelete3').getComponentInChildren(cc.Label).string = this._diamondCount.toString();
this.node.getChildByName('btnDelete3').getComponent(cc.Button).interactable = (SaveDataManager.ins.runtimeData.diamond >= this._diamondCount);
this._countDown = 5;
this.startCountDown();
this.onCountDown();
SoundManager.ins.playEffect(SoundName.CONTINUE);
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;
}
protected onDisable(): void {
this.unschedule(this.onCountDown);
}
// update (dt) {}
//#endregion
//#region public method
//#endregion
//#region event
onDelete3Click() {
if (SaveDataManager.ins.adjustDiamond(-this._diamondCount)) {
//删除3行
for (let i = 0; i < 3; ++i) {
new UserSkillShuriken(BattleManager.ins.curBattle).doSkillRevive();
}
BattleManager.ins.curBattle.reviveCount++;
BattleManager.ins.shootTouchEnable = true; //弹出此界面表示已经输了,操作被锁定,用技能后解锁
this.leave();
}
else {
//钻石不足
}
}
onReviveClick() {
this.unschedule(this.onCountDown);//暂停倒计时
//AD 放广告, 然后调用 doRevive
// HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
if (true) {
this.doRevive();
} else {
console.log('视频播放失败');
}
// });
}
onAdClick() {
this.unschedule(this.onCountDown);//暂停倒计时
//AD 放广告 放完后调 this.startCountDown
}
onCloseClick() {
this.leave();
// UIManager.ins.openWindow(WindowName.BATTLE_RESULT, false);//弹出失败窗口
BattleManager.ins.curBattle.finishBattle(false, false);
}
private onCountDown() {
if (this._countDown <= 0) {
this.unschedule(this.onCountDown);
this.onCloseClick();
}
this._countDown--;
this.updateCountDown(this._countDown);
}
//#endregion
//#region private method
private startCountDown() {
this.schedule(this.onCountDown, 1, 5);
}
private doRevive() {
new UserSkillShuriken(BattleManager.ins.curBattle).doSkillRevive();
BattleManager.ins.shootTouchEnable = true; //弹出此界面表示已经输了,操作被锁定,用技能后解锁
this.leave();
}
private leave() {
UIManager.ins.closeWindow(WindowName.REVIVE);
}
private updateCountDown(num: number) {
for (let i = 0; i < this._countDownNodeList.length; ++i) {
this._countDownNodeList[i].active = (i == num);
}
}
//#endregion
}