UILevelPreview.ts
6 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
182
183
184
185
186
187
188
189
190
191
// 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 { GuideManager } from "../../component/GuideManager";
import { SaveDataManager } from "../../component/SaveDataManager";
import { ADID, tMgr, WindowName } from "../../Global";
import { MapData } from "../../kernel/battle/map/MapData";
import { MapManager } from "../../kernel/battle/map/MapManager";
import { GamePlayTable, TableName } from "../../kernel/table/TableDefine";
import { UIBase } from "../UIBase";
import { UIManager } from "../UIManager";
import { UITitleData } from "./UITitleData";
const { ccclass, property } = cc._decorator;
@ccclass
export default class UILevelPreview extends UIBase {
private _txtLevel: cc.Label;
@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() {
this._txtLevel = this.node.getChildByName('titleNode').getComponentInChildren(cc.Label);
}
// start() {
// }
// update (dt) {}
protected onEnable(): void {
let container = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content');
container.destroyAllChildren();
let levelId = this.enableParam as number;
this._txtLevel.string = (levelId).toString();
let mapUrl = levelId == 0 ? 'test1' : 'map-' + levelId.toString();
MapManager.ins.loadMap(mapUrl, this.onMapLoaded, this);
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 onPopUpEffectFinish(): void {
let levelId = this.enableParam as number;
if (levelId == 1 && SaveDataManager.ins.runtimeData.guideStep == 1) {
let wpos = this.node.getChildByName('btnStart').convertToWorldSpaceAR(cc.v2(0, -60));
GuideManager.ins.showHand(wpos, false);
wpos = this.node.getChildByName('btnStart').convertToWorldSpaceAR(cc.v2(0, 80));
GuideManager.ins.showTalk(wpos, (tMgr.getConfig(TableName.GAME_PLAY, 27) as GamePlayTable).Comment);
}
}
protected onDisable(): void {
let container = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content');
container.destroyAllChildren();
GuideManager.ins.hideHand();
GuideManager.ins.hideTalk();
}
//#endregion
//#region public method
//#endregion
//#region event
onBtnCloseClick() {
this._useCloseEffect = true;
this.leave();
}
onStartBattleClick() {
this._useCloseEffect = false; //当进入战斗时,不使用关闭特效,否则异步后才会调用此界面的销毁接口,而此时地图正在创建,容易造成animation出错
this.go();
}
onBonusClick() {
this._useCloseEffect = false; //当进入战斗时,不使用关闭特效,否则异步后才会调用此界面的销毁接口,而此时地图正在创建,容易造成animation出错
//AD 放广告 放完后调go(true)
// HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
if (true) {
this.go(true);
} else {
console.log('视频播放失败');
}
// })
}
onAdClick() {
//AD 纯放广告
}
//#endregion
//#region private method
onMapLoaded(data: MapData) {
if (data.levelId == this.enableParam) {
let view = MapManager.ins.renderMap(data, this.node.getChildByName('battlePrefab'), true);
let content = this.node.getChildByName('containerBack').getChildByName('container').getChildByName('view').getChildByName('content');
let scaleX = content.width / view.width;
view.setScale(scaleX, scaleX);
let contentHeight = (data.maxContentY + 1) * data.gridSize.y;
let blankHeight = (data.mapGridSize.y - data.maxContentY - 1) * data.gridSize.y;
view.setPosition(0, (-blankHeight + data.gridSize.y) * scaleX / 2);
// view.setPosition(0,)
// content.height = contentHeight * scaleX;
content.setContentSize(content.width, contentHeight * scaleX);
content.addChild(view);
this.node.getChildByName('containerBack').getChildByName('container').getComponent(cc.ScrollView).scrollTo(cc.v2(0.5, 0));
}
}
private leave() {
UIManager.ins.closeWindow(WindowName.PREVIEW);
}
private go(bonus: boolean = false) {
this.leave();
let levelId = this.enableParam as number;
if (SaveDataManager.ins.runtimeData.guideStep == 1) {
//忽略关卡数,否则老玩家会卡住
SaveDataManager.ins.runtimeData.guideStep++;
SaveDataManager.ins.saveData();
}
UITitleData.isBattleBonus = bonus;
// let levelId = this.enableParam as number;
// let introConfig = IntroTableMgr.ins.getTableByLevel(levelId);
// if (introConfig) {
// //需要弹提示
// UIManager.ins.openWindow(WindowName.INTRO, levelId);
// }
// else {
UIManager.ins.openScene('Battle');
// }
}
//#endregion
}