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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
"use strict";
cc._RF.push(module, 'b9241pLxv5L0px4HAgdPkeb', 'adventure_form_window');
// Scripts/mod/adventure/view/adventure_form_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     冒险布阵界面
// <br/>Create: 2019-05-14 11:34:59
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var HeroConst = require("hero_const");
 
var CommonAlert = require("commonalert");
 
var HeroController = require("hero_controller");
 
var CommonScrollView = require("common_scrollview");
 
var Adventure_formWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("adventure", "adventure_form_window");
    this.viewTag = SCENE_TAG.dialogue; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
 
    this.win_type = WinType.Big; //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
 
    this.ctrl = arguments[0];
    this.model = this.ctrl.getModel();
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {
    this.five_hero_vo = []; // 已经选择的伙伴列表
 
    this.hero_item_list = []; // 英雄对象
 
    this.select_list = []; // 上面选中的实例对象
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.root_wnd.getChildByName("background");
    this.background.scale = FIT_SCALE;
    var main_container = this.root_wnd.getChildByName("main_container");
    var win_title = main_container.getChildByName("win_title").getComponent(cc.Label);
    win_title.string = Utils.TI18N("冒险出战");
    var top_panel = main_container.getChildByName("top_panel");
    this.lay_scrollview = top_panel.getChildByName("lay_scrollview");
    this.no_vedio_image = top_panel.getChildByName("no_vedio_image");
    var no_label = this.no_vedio_image.getChildByName("label").getComponent(cc.Label);
    no_label.string = Utils.TI18N("暂无该类型英雄"); // 阵营
 
    var camp_node = top_panel.getChildByName("camp_node");
    this.camp_btn_list = [];
    this.camp_btn_list[0] = camp_node.getChildByName("camp_btn0");
    this.camp_btn_list[HeroConst.CampType.eWater] = camp_node.getChildByName("camp_btn1");
    this.camp_btn_list[HeroConst.CampType.eFire] = camp_node.getChildByName("camp_btn2");
    this.camp_btn_list[HeroConst.CampType.eWind] = camp_node.getChildByName("camp_btn3");
    this.camp_btn_list[HeroConst.CampType.eLight] = camp_node.getChildByName("camp_btn4");
    this.camp_btn_list[HeroConst.CampType.eDark] = camp_node.getChildByName("camp_btn5");
    this.img_select = camp_node.getChildByName("img_select");
    var x = this.camp_btn_list[0].x;
    var y = this.camp_btn_list[0].y;
    this.img_select.setPosition(x - 0.5, y + 1);
    var bottom_panel = main_container.getChildByName("bottom_panel");
 
    for (var i = 1; i <= 5; i++) {
      var item = ItemsPool.getInstance().getItem("hero_exhibition_item");
      ;
      item.setRootScale(0.9);
      item.setButtonEffect(false);
      item.setRootPosition(cc.v2(104 + (i - 1) * 128, 229));
      item.setParent(bottom_panel);
      item.addTouchCb(function (i) {
        this.onClickHeroItemEnd(i);
      }.bind(this, i));
      item.show();
      this.hero_item_list[i] = item;
    }
 
    var pos_tips = bottom_panel.getChildByName("pos_tips").getComponent(cc.Label);
    pos_tips.string = Utils.TI18N("从列表中选择英雄");
    this.fight_btn = bottom_panel.getChildByName("fight_btn");
    this.key_up_btn = bottom_panel.getChildByName("key_up_btn");
    var fight_lab = this.fight_btn.getChildByName("label").getComponent(cc.Label);
    fight_lab.string = Utils.TI18N("进入冒险");
    var kep_lab = this.key_up_btn.getChildByName("label").getComponent(cc.Label);
    kep_lab.string = Utils.TI18N("一键布阵");
    this.power_click = bottom_panel.getChildByName("power_click"); // 战力
 
    this.power_val_nd = this.seekChild("power_val");
    this.fight_label = this.power_val_nd.getComponent("CusRichText");
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.background, function () {
      this.ctrl.openAdventureFormWindow(false);
    }.bind(this), 2);
 
    for (var i in this.camp_btn_list) {
      Utils.onTouchEnd(this.camp_btn_list[i], function (i) {
        this.onClickBtnShowByIndex(i);
      }.bind(this, i), 1);
    }
 
    Utils.onTouchEnd(this.key_up_btn, function () {
      this.onClickKeyUpBtn();
    }.bind(this), 1);
    Utils.onTouchEnd(this.fight_btn, function () {
      this.onClickSaveBtn();
    }.bind(this), 1);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(params) {
    this.onClickBtnShowByIndex(0);
  },
  // 显示根据类型 0表示全部
  onClickBtnShowByIndex: function onClickBtnShowByIndex(select_camp) {
    if (this.img_select && this.camp_btn_list[select_camp]) {
      var x = this.camp_btn_list[select_camp].x;
      var y = this.camp_btn_list[select_camp].y;
      this.img_select.setPosition(x - 0.5, y + 1);
    }
 
    this.updateHeroList(select_camp);
  },
  // ==============================--
  // desc:创建英雄列表
  // @select_camp:
  // @return 
  // ==============================--
  updateHeroList: function updateHeroList(select_camp) {
    var select_camp = select_camp || 0;
    if (select_camp == this.select_camp) return;
 
    if (!this.list_view) {
      var scroll_view_size = this.lay_scrollview.getContentSize();
      var setting = {
        item_class: "hero_exhibition_item",
        // 单元类
        start_x: 0,
        // 第一个单元的X起点
        space_x: 8,
        // x方向的间隔
        start_y: 0,
        // 第一个单元的Y起点
        space_y: 10,
        // y方向的间隔
        item_width: 119,
        // 单元的尺寸width
        item_height: 119,
        // 单元的尺寸height
        row: 5,
        // 行数,作用于水平滚动类型
        col: 5,
        // 列数,作用于垂直滚动类型
        once_num: 5,
        need_dynamic: true
      };
      this.list_view = new CommonScrollView();
      this.list_view.createScroll(this.lay_scrollview, cc.v2(-scroll_view_size.width / 2, -scroll_view_size.height / 2), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting);
    }
 
    this.select_camp = select_camp;
 
    var clickback = function (cell) {
      this.selectHero(cell);
    }.bind(this);
 
    if (this.hero_array == null) {
      this.hero_array = Utils.deepCopy(HeroController.getInstance().getModel().getAllHeroArray());
    }
 
    var show_list = [];
 
    for (var j = 1; j <= this.hero_array.length; j++) {
      var hero_vo = this.hero_array[j - 1];
 
      if (select_camp == 0 || select_camp == hero_vo.camp_type) {
        show_list.push(hero_vo);
      }
    }
 
    if (show_list.length > 0) {
      show_list.sort(Utils.tableUpperSorter(["star", "power", "lev", "sort_order"]));
      this.list_view.setData(show_list, clickback, {
        scale: 0.9,
        from_type: HeroConst.ExhibitionItemType.eHeroSelect,
        can_click: true
      });
      this.no_vedio_image.active = false;
    } else {
      this.list_view.setData({});
      this.no_vedio_image.active = true;
    }
 
    this.show_list = show_list;
  },
  // ==============================--
  // desc:一键上阵
  // @return 
  // ==============================--
  onClickKeyUpBtn: function onClickKeyUpBtn() {
    var count = 0;
 
    for (var i in this.five_hero_vo) {
      if (this.five_hero_vo[i]) {
        count++;
      }
    }
 
    if (count >= 5) {
      message(Utils.TI18N("上阵人数已满"));
      return;
    }
 
    if (this.show_list == null || Utils.next(this.show_list) == null) {
      message(Utils.TI18N("当前列表没有可上阵的英雄"));
      return;
    }
 
    for (var i = 1; i <= 5; i++) {
      if (this.five_hero_vo[i] == null) {
        var hero_vo = this.getFreeHero();
 
        if (hero_vo) {
          hero_vo.is_ui_select = true;
          this.five_hero_vo[i] = hero_vo;
          this.hero_item_list[i].setData(hero_vo); //  在上面列表中找到这个对象,并且设置选中
 
          this.setTopSelect(hero_vo, i);
        }
      }
    }
 
    this.updateFightPower();
  },
  setTopSelect: function setTopSelect(hero_vo, index) {
    if (this.list_view == null) return;
    if (this.select_list[index]) return;
    var item_list = this.list_view.getItemList();
 
    for (var i in item_list) {
      var v = item_list[i];
      var data = v.getData();
 
      if (data && data.partner_id == hero_vo.partner_id) {
        data.is_ui_select = hero_vo.is_ui_select;
        v.setSelected(hero_vo.is_ui_select);
        this.select_list[index] = v;
        break;
      }
    }
  },
  // ==============================--
  // desc:获取当前不在阵上的英雄
  // @return 
  // ==============================--
  getFreeHero: function getFreeHero() {
    for (var i in this.show_list) {
      var hero_vo = this.show_list[i];
      var is_free = true;
 
      for (var k in this.five_hero_vo) {
        if (this.five_hero_vo[k]) {
          var data = this.five_hero_vo[k];
 
          if (hero_vo.partner_id == data.partner_id || hero_vo.bid == data.bid) {
            is_free = false;
            break;
          }
        }
      }
 
      if (is_free == true) {
        return hero_vo;
      }
    }
  },
  // ==============================--
  // desc:点击上面选中的单位
  // @item:
  // @hero_vo:
  // @return 
  // ==============================--
  selectHero: function selectHero(item) {
    if (item == null) return;
    var hero_vo = this.show_list[item.tmp_index];
    if (hero_vo == null) return;
    var index = -1;
    var partner_id = hero_vo.partner_id;
 
    for (var k in this.five_hero_vo) {
      if (this.five_hero_vo[k] && partner_id == this.five_hero_vo[k].partner_id) {
        index = k;
        break;
      }
    }
 
    if (index != -1) {
      //下阵
      hero_vo.is_ui_select = false;
      var data = item.getData();
      data.is_ui_select = hero_vo.is_ui_select;
      item.setSelected(hero_vo.is_ui_select);
      this.hero_item_list[index].setData(null);
      this.five_hero_vo[index] = null;
      this.select_list[index] = null;
    } else {
      var count = 0;
 
      for (var i in this.five_hero_vo) {
        if (this.five_hero_vo[i]) {
          if (this.five_hero_vo[i].bid == hero_vo.bid) {
            message(Utils.TI18N("不能同时上阵2个相同英雄"));
            return;
          }
 
          count = count + 1;
        }
      }
 
      if (count >= 5) {
        message(Utils.TI18N("上阵人数已满"));
        return;
      }
 
      var new_index = 0;
 
      for (var i = 1; i <= 5; i++) {
        if (this.five_hero_vo[i] == null) {
          new_index = i;
          break;
        }
      }
 
      if (new_index == 0) {
        message(Utils.TI18N("没有上阵位置"));
        return;
      }
 
      this.five_hero_vo[new_index] = hero_vo;
      this.hero_item_list[new_index].setData(hero_vo);
      this.select_list[new_index] = item;
      hero_vo.is_ui_select = true;
      var data = item.getData();
      data.is_ui_select = hero_vo.is_ui_select;
      item.setSelected(hero_vo.is_ui_select);
    }
 
    this.updateFightPower();
  },
  // ==============================--
  // desc:计算战斗力
  // @return 
  // ==============================--
  updateFightPower: function updateFightPower() {
    var power = 0;
 
    for (var k in this.five_hero_vo) {
      if (this.five_hero_vo[k]) {
        power = power + this.five_hero_vo[k].power;
      }
    }
 
    this.fight_label.setNum(power);
  },
  // ==============================--
  // desc:点击下面5个英雄
  // @index:
  // @sender:
  // @return 
  // ==============================--
  onClickHeroItemEnd: function onClickHeroItemEnd(index, sender) {
    var hero_vo = this.five_hero_vo[index];
    if (hero_vo == null) return;
    hero_vo.is_ui_select = false;
    var list = this.list_view.getItemList();
 
    for (var i in list) {
      var item = list[i];
      var data = item.getData();
 
      if (data.partner_id == hero_vo.partner_id) {
        data.is_ui_select = hero_vo.is_ui_select;
        item.setSelected(hero_vo.is_ui_select);
        break;
      }
    }
 
    this.five_hero_vo[index] = null;
    this.select_list[index] = null;
    this.hero_item_list[index].setData(null);
    this.updateFightPower();
  },
  // ==============================--
  // desc:请求进入冒险
  // @return 
  // ==============================--
  onClickSaveBtn: function onClickSaveBtn() {
    var plist = [];
    var count = 0;
 
    for (var k in this.five_hero_vo) {
      if (this.five_hero_vo[k]) {
        plist.push({
          id: this.five_hero_vo[k].partner_id
        });
        count = count + 1;
      }
    }
 
    if (count == 0) {
      message(Utils.TI18N("请设置出战英雄"));
      return;
    }
 
    var hero_array = HeroController.getInstance().getModel().getAllHeroArray();
    var size = hero_array.length;
 
    if (count < 5 && count < size) {
      //当前还有可上的英雄但是没设置上
      var msg = Utils.TI18N("当前上阵英雄不足5个,是否确认以此阵容进入冒险?");
      CommonAlert.show(msg, Utils.TI18N("确定"), function (plist) {
        this.ctrl.requestSetForm(plist);
      }.bind(this, plist), Utils.TI18N("取消"));
    } else {
      this.ctrl.requestSetForm(plist);
    }
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    if (this.list_view) {
      this.list_view.deleteMe();
      this.list_view = null;
    }
 
    if (this.hero_item_list) {
      for (var i in this.hero_item_list) {
        this.hero_item_list[i].deleteMe();
      }
 
      this.hero_item_list = null;
    }
 
    this.hero_array = null;
    this.ctrl.openAdventureFormWindow(false);
  }
});
 
cc._RF.pop();