UISign.ts
5.45 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
179
180
181
// 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 { UserSkill } from "../../kernel/battle/BattleConst";
import { SignTable, TableName } from "../../kernel/table/TableDefine";
import SignItem from "../../prefabs/SignItem";
import { UIBase } from "../UIBase";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass
export default class UISign extends UIBase {
// private _itemList: SignItem[] = [];
@property(cc.Node)
btn_ad: cc.Node = null;
@property(cc.Node)
adNode: cc.Node = null;
@property(cc.Node)
btn_start: cc.Node = null;
@property(cc.Node)
btn_bonus: cc.Node = null;
openCount: number = 0;
protected onLoad(): void {
// SaveDataManager.ins.runtimeData.loginRewardData.freshTime = 0;
}
onEnable() {
this.refresh();
this.btn_ad.active = true;
// this.adNode.getComponent(CustomNativeAdView).showNativeAd((result) => {
// if (result) {
// this.btn_ad.active = true;
// } else {
// this.btn_ad.active = false;
// }
// });
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 {
let tip = cc.find('main/tips', this.node);
cc.Tween.stopAllByTarget(tip);
tip.active = false;
}
hide_btn_ad() {
this.btn_ad.active = false;
}
private refresh() {
let num = cc.find('main/container', this.node).children.length;
let now = SaveDataManager.ins.getNowTime();
let valid = (now >= SaveDataManager.ins.runtimeData.loginRewardData.freshTime);
// valid = true;
if (valid && SaveDataManager.ins.runtimeData.loginRewardData.step >= 7) {
SaveDataManager.ins.runtimeData.loginRewardData.step = 0;
SaveDataManager.ins.saveData();
}
for (let i = 0; i < num; ++i) {
let item = (cc.find('main/container/SignItem' + (i + 1).toString(), this.node).getComponent(SignItem));
item.setDay(i + 1);
item.setLock(i + 1 <= SaveDataManager.ins.runtimeData.loginRewardData.step);
item.setCurrent(i - SaveDataManager.ins.runtimeData.loginRewardData.step == 0);
}
// cc.find('main/btnDouble', this.node).getComponent(cc.Button).interactable = valid;
// cc.find('main/btnGet', this.node).getComponent(cc.Button).interactable = valid;
}
onCloseClick() {
UIManager.ins.closeWindow(WindowName.SIGN);
}
onDoubleClick() {
let now = SaveDataManager.ins.getNowTime();
let valid = (now >= SaveDataManager.ins.runtimeData.loginRewardData.freshTime);
if (valid) {
//AD 放完广告调 get(2)
// HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
if (true) {
this.get(2);
} else {
console.log('视频播放失败');
}
// });
}
else {
this.showTip();
}
}
onAdClick() {
//AD 纯放广告
}
onGetClick() {
let now = SaveDataManager.ins.getNowTime();
let valid = (now >= SaveDataManager.ins.runtimeData.loginRewardData.freshTime);
if (valid) {
this.get(1);
}
else {
this.showTip();
}
}
private get(rate: number = 1) {
let cur = SaveDataManager.ins.runtimeData.loginRewardData.step;
let config = tMgr.getConfig(TableName.SIGN, cur + 1) as SignTable;
if (config.Type == 1) {
SaveDataManager.ins.adjustDiamond(config.Num * rate, true);
}
else if (config.Type == 2) {
SaveDataManager.ins.setUserSkillNumDelta(UserSkill.BOMB, config.Num * rate);
}
else if (config.Type == 3) {
// SaveDataManager.ins.setUserSkillNumDelta(UserSkill.SHURIKEN, config.Num * rate);
SaveDataManager.ins.unlockBallSkin(2);
}
SaveDataManager.ins.runtimeData.loginRewardData.step++;
let endTime = new Date();
endTime.setHours(23, 59, 59);
SaveDataManager.ins.runtimeData.loginRewardData.freshTime = endTime.getTime();
SaveDataManager.ins.saveData();
this.refresh();
}
private showTip() {
let tip = cc.find('main/tips', this.node);
tip.active = true;
tip.scale = 0;
cc.Tween.stopAllByTarget(tip);
cc.tween(tip).to(0.3, { scale: 1 }, { easing: 'backOut' }).delay(2).to(0.3, { scale: 0 }, { easing: 'backIn' }).call(() => { tip.active = false; }).start();
}
}