difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
"use strict";
cc._RF.push(module, 'e7e11Sjh5FGaaMKEg8kuLGU', 'ladder_main_window');
// Scripts/mod/ladder/view/ladder_main_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     跨服天梯mainview
// <br/>Create: 2019-07-24 16:56:38
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var RoleController = require("role_controller");
 
var LadderController = require("ladder_controller");
 
var LadderRoleItem = require("ladder_role_item");
 
var TimeTool = require("timetool");
 
var MainuiController = require("mainui_controller");
 
var CommonAlert = require("commonalert");
 
var LadderConst = require("ladder_const");
 
var LadderEvent = require("ladder_event");
 
var Ladder_mainWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("ladder", "ladder_main_window"); // this.viewTag = SCENE_TAG.ui;                //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
    // this.win_type = WinType.Full;               //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {
    this.role_vo = RoleController.getInstance().getRoleVo();
    this.role_panels = {};
    this.role_items = {};
    this.ctrl = LadderController.getInstance();
    this.model = this.ctrl.getModel();
    this.white_color = new cc.Color(255, 255, 255, 255);
    this.color_1 = new cc.Color(71, 132, 37, 255);
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    var background = this.seekChild("background");
    background.scale = FIT_SCALE;
    this.loadRes(PathTool.getBigBg("bigbg_58"), function (sp) {
      background.getComponent(cc.Sprite).spriteFrame = sp;
    }.bind(this));
    this.main_container = this.seekChild("main_container");
    this.top_panel = this.seekChild(this.main_container, "top_panel");
    var win_title = this.seekChild(this.top_panel, "win_title", cc.Label);
    win_title.string = Utils.TI18N("天梯争霸");
    this.btn_rule = this.seekChild(this.top_panel, "btn_rule");
    this.btn_role = this.seekChild(this.top_panel, "btn_role");
    this.btn_log = this.seekChild(this.top_panel, "btn_log");
    this.btn_rank = this.seekChild(this.top_panel, "btn_rank");
    this.btn_award = this.seekChild(this.top_panel, "btn_award");
    this.btn_shop = this.seekChild(this.top_panel, "btn_shop");
    this.bottom_panel = this.seekChild(this.main_container, "bottom_panel");
    var black_bg = this.seekChild(this.bottom_panel, "black_bg");
    var count_title = this.seekChild(this.bottom_panel, "count_title", cc.Label);
    count_title.string = Utils.TI18N("挑战次数:");
    this.count_label_lb = this.seekChild(this.bottom_panel, "count_label", cc.Label);
    var tips_label = this.seekChild(this.main_container, "tips_label", cc.Label);
    tips_label.string = Utils.TI18N("快速挑战排名不变");
    this.time_title_lb = this.seekChild(this.bottom_panel, "time_title", cc.Label);
    this.time_title_lb.string = Utils.TI18N("距离结束:");
    this.time_label_lb = this.seekChild(this.bottom_panel, "time_label", cc.Label);
    var score_bg = this.seekChild(this.main_container, "score_bg");
    this.score_label_lb = this.seekChild(score_bg, "score_label", cc.Label);
    this.score_label_lb.string = this.role_vo.sky_coin;
    var rank_bg = this.seekChild(this.main_container, "rank_bg");
    var rank_title = this.seekChild(rank_bg, "rank_title", cc.Label);
    rank_title.string = Utils.TI18N("排名:");
    this.rank_label_lb = this.seekChild(rank_bg, "rank_label", cc.Label);
    this.close_btn = this.seekChild(this.main_container, "close_btn");
    this.refresh_btn = this.seekChild(this.main_container, "refresh_btn");
    this.refresh_btn._can_touch = true;
    this.refresh_btn_label_lb = this.seekChild(this.refresh_btn, "label", cc.Label);
    this.refresh_btn_label_lo = this.seekChild(this.refresh_btn, "label", cc.LabelOutline);
    this.refresh_btn_label_lb.string = Utils.TI18N("刷新");
    this.challenge_btn = this.seekChild(this.main_container, "challenge_btn");
    this.challenge_btn_label_lb = this.seekChild(this.challenge_btn, "label", cc.Label);
    this.challenge_btn_label_lb.string = Utils.TI18N("一键挑战");
    this.add_btn = this.seekChild(this.bottom_panel, "add_btn");
 
    for (var i = 1; i <= 5; i++) {
      var role_panel = this.seekChild(this.main_container, "role_pos_" + i);
      this.role_panels[i] = role_panel;
    }
 
    this.role_panel_size = this.role_panels[1].getContentSize();
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.close_btn, function () {
      this.ctrl.openMainWindow(false);
    }.bind(this), 1);
    Utils.onTouchEnd(this.btn_rule, function () {
      MainuiController.getInstance().openCommonExplainView(true, Config.sky_ladder_data.data_explain);
    }.bind(this), 1);
    Utils.onTouchEnd(this.btn_role, function () {
      this.ctrl.openLadderTopThreeWindow(true);
    }.bind(this), 1);
    Utils.onTouchEnd(this.btn_log, function () {
      this.ctrl.openLadderLogWindow(true);
    }.bind(this), 1);
    Utils.onTouchEnd(this.btn_rank, function () {
      this.ctrl.openLadderRankWindow(true);
    }.bind(this), 1);
    Utils.onTouchEnd(this.btn_award, function () {
      this.ctrl.openLadderAwardWindow(true);
    }.bind(this), 1);
    Utils.onTouchEnd(this.btn_shop, function () {
      this.ctrl.openLadderShopWindow(true);
    }.bind(this), 1); //添加挑战次数
 
    Utils.onTouchEnd(this.add_btn, function () {
      var is_open = this.model.getLadderIsOpen();
 
      if (!is_open) {
        var txt_cfg = Config.sky_ladder_data.data_const["close_text"];
 
        if (txt_cfg) {
          message(cc.js.formatStr(Utils.TI18N("每%s天梯争霸"), txt_cfg.desc));
        }
      }
 
      if (this.myBaseInfo) {
        var buy_combat_num = this.myBaseInfo.buy_combat_num || 0;
        var cost_config = Config.sky_ladder_data.data_buy_num[buy_combat_num + 1];
 
        if (cost_config) {
          if (this.role_vo.vip_lev >= cost_config.vip) {
            var res = PathTool.getItemRes(Config.ItemData.data_assets_label2id.gold);
            var msg = cc.js.formatStr(Utils.TI18N("确定消耗<img src='%s'/>%s增加一次挑战次数吗?"), Config.ItemData.data_assets_label2id.gold, cost_config.cost);
            CommonAlert.show(msg, Utils.TI18N("确定"), function () {
              this.ctrl.requestBuyChallengeCount();
            }.bind(this), Utils.TI18N("取消"), null, 2, null, {
              resArr: [res]
            });
          } else {
            message(Utils.TI18N("提升VIP等级可增加购买次数"));
          }
        } else {
          message(Utils.TI18N("当前已经购买达到上限"));
        }
      }
    }.bind(this), 1);
    Utils.onTouchEnd(this.refresh_btn, function () {
      var is_open = this.model.getLadderIsOpen();
 
      if (is_open) {
        this.ctrl.requestRefreshEnemyList();
      } else {
        var txt_cfg = Config.sky_ladder_data.data_const["clost_text"];
 
        if (txt_cfg) {
          message(cc.js.formatStr(Utils.TI18N("每%s天梯争霸"), txt_cfg.desc));
        }
      }
    }.bind(this), 1);
    Utils.onTouchEnd(this.challenge_btn, function () {
      var is_open = this.model.getLadderIsOpen();
 
      if (!is_open) {
        var txt_cfg = Config.sky_ladder_data.data_const["close_text"];
 
        if (txt_cfg) {
          message(cc.js.formatStr(Utils.TI18N("每%s天梯争霸"), txt_cfg.desc));
        }
 
        return;
      }
 
      var fun = function () {
        this.ctrl.checkJoinLadderBattle(null, null, true);
      }.bind(this);
 
      var str = Utils.TI18N("一键挑战将直接获得奖励,是否继续?\n\n\n                          <size=22>(消耗一次挑战次数)</size>");
      CommonAlert.show(str, Utils.TI18N("确定"), fun, Utils.TI18N("取消"), null, 2, null);
    }.bind(this), 1); //个人数据更新
 
    this.addGlobalEvent(LadderEvent.UpdateLadderMyBaseInfo, function () {
      this.refreshMyBaseInfo();
    }, this); //更新所有对手列表
 
    this.addGlobalEvent(LadderEvent.UpdateAllLadderEnemyList, function () {
      this.refreshRoleList();
    }, this); //积分更新
 
    if (this.role_vo != null) {
      if (this.role_assets_event == null) {
        this.role_assets_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) {
          if (key == "sky_coin") {
            this.score_label_lb.string = value;
          }
        }.bind(this));
      }
    } //活动开启/关闭
 
 
    this.addGlobalEvent(LadderEvent.UpdateLadderOpenStatus, function () {
      this.refreshMyBaseInfo();
    }, this); //红点
 
    this.addGlobalEvent(LadderEvent.UpdateLadderRedStatus, function () {
      this.refrehsBtnRedStatus(bid, status);
    }, this);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(params) {
    this.ctrl.requestLadderMyBaseInfo();
    this.ctrl.requestLadderEnemyListData();
    this.refrehsBtnRedStatus();
  },
  refreshRoleList: function refreshRoleList() {
    var enemy_datas = this.model.getLadderEnemyListData();
    cc.log("enemy_datas==", enemy_datas);
 
    var sortFunc = function sortFunc(objA, objB) {
      if (objA.rank != 0 && objB.rank != 0) {
        return objA.rank - objB.rank;
      } else if (objA.rank == 0 && objB.rank != 0) {
        return 1;
      } else if (objA.rank != 0 && objB.rank == 0) {
        return -1;
      } else {
        return 1;
      }
    }; // enemy_datas.sort(sortFunc);
    //循环
 
 
    this.list_index = 1;
    this.startUpdate(5, function () {
      var index = this.list_index;
      var role_item = this.role_items[index];
 
      if (!role_item) {
        role_item = new LadderRoleItem();
        var role_panel = this.role_panels[index];
        role_item.setPosition(cc.v2(this.role_panel_size.width / 2, this.role_panel_size.height - 140));
        role_item.setParent(role_panel);
        this.role_items[index] = role_item;
      }
 
      var enemy_data = enemy_datas[index];
 
      if (enemy_data && Utils.next(enemy_data) != null) {
        role_item.setData(enemy_data);
        role_item.setVisible(true);
      } else {
        role_item.setVisible(false);
      }
 
      this.list_index += 1;
    }.bind(this), 1000 / 5);
  },
  //刷新个人信息数据
  refreshMyBaseInfo: function refreshMyBaseInfo() {
    this.myBaseInfo = this.model.getLadderMyBaseInfo();
    var is_open = this.model.getLadderIsOpen();
    this.count_label_lb.string = this.myBaseInfo.can_combat_num || 0; //今日剩余购买次数
 
    if (!this.left_buy_count) {
      this.left_buy_count = Utils.createRichLabel(20, this.white_color, cc.v2(0.5, 0.5), cc.v2(590, 10));
      this.left_buy_count.setParent(this.bottom_panel);
    }
 
    var left_count = this.model.getTodayLeftBuyCount();
    this.left_buy_count.string = cc.js.formatStr(Utils.TI18N("<color=#fff8bf><outline=2 color=#000000>(剩余购买次数:</outline></c><color=#39e522><outline=2 color=#000000>%d</outline></c><color=#fff8bf><outline=2 color=#000000>)</outline></c>", left_count));
 
    if (!is_open || !this.myBaseInfo.rank || this.myBaseInfo.rank == 0) {
      this.rank_label_lb.string = Utils.TI18N("暂无");
    } else {
      this.rank_label_lb.string = this.myBaseInfo.rank;
    }
 
    this.ref_time = this.myBaseInfo.ref_time || 0; //下次可刷新时间
 
    this.combat_time = this.myBaseInfo.combat_time || 0; //结束时间
 
    var cur_time = gcore.SmartSocket.getTime();
    var com_left_time = this.combat_time - cur_time;
 
    if (com_left_time < 0) {
      com_left_time = 0;
    } //活动开启显示剩余时间、活动未开启显示参赛条件
 
 
    if (!is_open) {
      this.time_label_lb.node.active = false;
      this.time_title_lb.node.active = false;
 
      if (!this.join_text) {
        this.join_text = Utils.createRichLabel(22, this.white_color, cc.v2(0.5, 0.5), cc.v2(346, 38.5));
        this.join_text.setParent(this.bottom_panel);
      }
 
      this.join_text.node.active = true;
      var rank_cfg = Config.sky_ladder_data.data_const["arena_rank"];
 
      if (rank_cfg) {
        this.join_text.string = cc.js.formatStr(Utils.TI18N("color=#fff8bf><outline=2 color=#000000>参赛条件:竞技场排名前</outline></c>color=#39e522><outline=2 color=#000000>%d</outline></c>color=#fff8bf><outline=2 color=#000000>名</outline></c>", rank_cfg.val));
      }
    } else {
      this.time_label_lb.node.active = true;
      this.time_title_lb.node.active = true;
      this.time_label_lb.string = TimeTool.getTimeFormat(com_left_time);
 
      if (this.join_text) {
        this.join_text.node.active = false;
      }
 
      this.openLadderTimer(true);
    }
 
    var ref_left_time = this.ref_time - cur_time;
 
    if (ref_left_time <= 0 && this.refresh_btn._can_touch == false) {
      // setChildUnEnabled(true, self.refresh_btn)
      this.refresh_btn._can_touch = true;
      this.refresh_btn_label_lb.string = Utils.TI18N("刷新"); // this.refresh_btn_label_lo.color = this.color_1;
 
      this.refresh_btn_label_lo.enabled = true;
    } else if (ref_left_time > 0 && this.refresh_btn._can_touch == true) {
      // setChildUnEnabled(true, self.refresh_btn)
      this.refresh_btn._can_touch = false;
      this.refresh_btn_label_lb.string = cc.js.formatStr(Utils.TI18N("%s秒"), ref_left_time);
      this.refresh_btn_label_lo.enabled = false;
    }
  },
  //计时器
  openLadderTimer: function openLadderTimer(status) {
    if (status == true) {
      if (this.ladder_timer == null) {
        this.ladder_timer = gcore.Timer.set(function () {
          var cur_time = gcore.SmartSocket.getTime();
          var com_left_time = this.combat_time - cur_time;
          var ref_left_time = this.ref_time - cur_time;
 
          if (com_left_time <= 0 && ref_left_time <= 0) {
            gcore.Timer.del(this.ladder_timer);
            this.ladder_timer = null;
          }
 
          if (com_left_time < 0) {
            com_left_time = 0;
          }
 
          if (com_left_time <= 0) {
            this.time_label_lb.node.active = false;
            this.time_title_lb.node.active = false;
 
            if (this.join_text) {
              this.join_text.node.active = true;
            }
          } else {
            this.time_label_lb.node.active = true;
            this.time_title_lb.node.active = true;
            this.time_label_lb.string = TimeTool.getTimeFormat(com_left_time);
          }
 
          if (ref_left_time <= 0) {
            if (this.refresh_btn._can_touch == false) {
              this.refresh_btn._can_touch = true; // this.refresh_btn_label_lo.color = this.color_1;
              // setChildUnEnabled(true, self.refresh_btn)
            }
 
            this.refresh_btn_label_lb.string = Utils.TI18N("刷新");
          } else if (ref_left_time > 0) {
            if (this.refresh_btn._can_touch == true) {
              // setChildUnEnabled(true, self.refresh_btn)
              this.refresh_btn._can_touch = false;
              this.refresh_btn_label_lo.enabled = false;
            }
 
            this.refresh_btn_label_lb.string = cc.js.formatStr(Utils.TI18N("%s秒"), ref_left_time);
          }
        }.bind(this), 1000, 1);
      }
    } else {
      if (this.ladder_timer != null) {
        gcore.Timer.del(this.ladder_timer);
        this.ladder_timer = null;
      }
    }
  },
  //红点
  refrehsBtnRedStatus: function refrehsBtnRedStatus(bid, status) {
    if (bid == LadderConst.RedType.TopThree) {
      Utils.addRedPointToNodeByStatus(this.btn_role, status);
    } else if (bid == LadderConst.RedType.BattleLog) {
      Utils.addRedPointToNodeByStatus(this.btn_log, status);
    } else {
      var top_three_status = this.model.checkRedIsShowByRedType(LadderConst.RedType.TopThree);
      Utils.addRedPointToNodeByStatus(this.btn_role, top_three_status);
      var log_status = this.model.checkRedIsShowByRedType(LadderConst.RedType.BattleLog);
      Utils.addRedPointToNodeByStatus(this.btn_log, log_status);
    }
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    if (this.role_vo) {
      if (this.role_assets_event) {
        this.role_vo.unbind(this.role_assets_event);
        this.role_assets_event = null;
      }
 
      this.role_vo = null;
    }
 
    for (var k in this.role_items) {
      var item = this.role_items[k];
 
      if (item) {
        item.deleteMe();
        item = null;
      }
    }
 
    this.role_items = null;
    this.openLadderTimer(false);
    this.ctrl.openMainWindow(false);
  }
});
 
cc._RF.pop();