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
"use strict";
cc._RF.push(module, '37b56evyCRFxZsAYx14HZce', 'forge_equip_panel');
// Scripts/mod/forgehouse/view/forge_equip_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     装备锻造界面
// <br/>Create: 2019-03-29 17:20:37
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var ForgeHouseController = require("forgehouse_controller");
 
var CommonScrollView = require("common_scrollview");
 
var ForgehouseItemPanel = require("forgehouse_item_panel");
 
var BackPackController = require("backpack_controller");
 
var BackPackConst = require("backpack_const");
 
var RoleController = require("role_controller");
 
var Forge_Equip_Panel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("forgehouse", "forge_equip_panel");
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.tab_list = {};
    this.cur_index = null;
    this.composite_number = 0; // 当前选择合成数量
 
    this.composite_max = 0; // 最大可合成数量
 
    this.composite_price = 0; // 合成单价
 
    this.normal_color = new cc.Color(0xd3, 0xb4, 0x9b, 0xff);
    this.normal_outlinecolor = new cc.Color(0x40, 0x22, 0x15, 0xff);
    this.select_color = new cc.Color(0xff, 0xff, 0xff, 0xff);
    this.select_outlinecolor = new cc.Color(0x6d, 0x35, 0x07, 0xff);
    this.role_vo = RoleController.getInstance().getRoleVo();
    this.ctrl = ForgeHouseController.getInstance();
    this.partner_const = Config.partner_eqm_data.data_partner_const;
    this.eqm_comp_list = Config.partner_eqm_data.data_eqm_compose_id;
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.main_container = this.seekChild("main_container");
    this.bg_1 = this.seekChild("bg_1", cc.Sprite);
    this.loadRes(PathTool.getBigBg("bigbg_80"), function (sp) {
      this.bg_1.spriteFrame = sp;
    }.bind(this));
    var title_list = [Utils.TI18N("武器"), Utils.TI18N("衣服"), Utils.TI18N("头盔"), Utils.TI18N("鞋子")];
    var type_list = [BackPackConst.item_type.WEAPON, BackPackConst.item_type.CLOTHES, BackPackConst.item_type.HAT, BackPackConst.item_type.SHOE];
    var tab_container = this.seekChild("tab_container");
 
    for (var index = 0; index < 4; index++) {
      var object = {};
      var new_index = index + 1;
      object.btn = tab_container.getChildByName("tab_btn_" + new_index); //获取主节点
 
      object.normal = object.btn.getChildByName("normal"); //普通状态
 
      object.select = object.btn.getChildByName("select"); //选中状态
 
      object.red_point = object.btn.getChildByName("redpoint"); //红点
 
      object.title = object.btn.getChildByName("title"); //label对象
 
      object.title_label = object.title.getComponent(cc.Label); //label
 
      object.title_outline = object.title.getComponent(cc.LabelOutline); //描边
 
      object.title_label.string = title_list[index];
      object.index = new_index;
      object.type = type_list[index];
      this.tab_list[new_index] = object;
    }
 
    this.btn_composite = this.seekChild("btn_composite"); // 熔炼按钮
 
    this.seekChild(this.btn_composite, "Text_1", cc.Label).string = Utils.TI18N("合成");
    this.all_composite = this.seekChild("btn_all_composite");
    this.all_composite_btn = this.seekChild("btn_all_composite", cc.Button);
    this.all_composite_lo = this.seekChild(this.all_composite, "Text_1", cc.LabelOutline);
 
    if (this.role_vo.vip_lev < this.partner_const.synthesis_vip_lev.val && this.role_vo.lev < this.partner_const.synthesis_character_lev.val) {
      Utils.setGreyButton(this.all_composite_btn, true);
      this.all_composite_lo.enabled = false;
    }
 
    this.btn_add = this.seekChild("btn_add"); // 加
 
    this.btn_redu = this.seekChild("btn_redu"); // 减
 
    this.gold_num = this.seekChild("gold_num", cc.Label); // 消耗金币数量
 
    this.spriteGold = this.seekChild("spriteGold").getComponent(cc.Sprite); // 消耗资产图标
 
    this.loadRes(PathTool.getItemRes(1), function (sp) {
      this.spriteGold.spriteFrame = sp;
    }.bind(this));
    this.composite_num = this.seekChild("composite_num", cc.Label); // 合成数量
 
    this.composite_num.string = 9999;
    this.bar = this.seekChild("bar", cc.ProgressBar); // 合成进度条
 
    this.bar_num = this.seekChild("bar_num", cc.Label); // 合成进度数字
 
    this.btn_comp_nd = this.seekChild("btn_comp"); //合成记录
 
    this.last_item = ItemsPool.getInstance().getItem("backpack_item");
    this.last_item.setPosition(-156, 912);
    this.last_item.setParent(this.main_container);
    this.last_item.initConfig(true, 1, false, true);
    this.last_item.show();
    this.cur_item = ItemsPool.getInstance().getItem("backpack_item");
    this.cur_item.setPosition(156, 912);
    this.cur_item.setParent(this.main_container);
    this.cur_item.initConfig(true, 1, false, true);
    this.cur_item.show();
    var goods_con = this.seekChild("goods_con");
    var setting = {
      item_class: ForgehouseItemPanel,
      // 单元类
      start_x: 4,
      // 第一个单元的X起点
      space_x: 8,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 10,
      // y方向的间隔
      item_width: 120,
      // 单元的尺寸width
      item_height: 120,
      // 单元的尺寸height
      row: 5,
      // 行数,作用于水平滚动类型
      col: 5,
      // 列数,作用于垂直滚动类型
      once_num: 5,
      need_dynamic: true
    };
    this.item_scrollview = new CommonScrollView();
    this.item_scrollview.createScroll(goods_con, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, cc.size(goods_con.width, goods_con.height), setting, cc.v2(0, 0));
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    var _this = this;
 
    var _loop = function _loop() {
      var element = _this.tab_list[key];
 
      if (element.btn) {
        element.btn.on(cc.Node.EventType.TOUCH_END, function (event) {
          this.changeTabView(element.index);
        }.bind(_this));
      }
    };
 
    for (var key in this.tab_list) {
      _loop();
    }
 
    this.btn_add.on(cc.Node.EventType.TOUCH_END, function () {
      Utils.playButtonSound(1);
 
      if (this.composite_number < this.composite_max) {
        this.setCompositeVal(this.composite_number + 1);
      }
    }.bind(this));
    this.btn_redu.on(cc.Node.EventType.TOUCH_END, function () {
      Utils.playButtonSound(1);
 
      if (this.composite_number > 1) {
        this.setCompositeVal(this.composite_number - 1);
      }
    }.bind(this));
    this.btn_composite.on(cc.Node.EventType.TOUCH_END, function (event) {
      Utils.playButtonSound(1);
      if (this.cur_tab == null || this.select_data == null) return;
 
      if (this.composite_number <= 0) {
        message(Utils.TI18N("合成数量材料不足"));
        return;
      }
 
      ForgeHouseController.getInstance().send11080(this.select_data.id, this.composite_number);
    }.bind(this));
    Utils.onTouchEnd(this.all_composite, function () {
      if (this.role_vo.vip_lev < this.partner_const.synthesis_vip_lev.val && this.role_vo.lev < this.partner_const.synthesis_character_lev.val) {
        var str = cc.js.formatStr(Utils.TI18N("人物%s级或VIP达到%s级开启"), this.partner_const.synthesis_character_lev.val, this.partner_const.synthesis_vip_lev.val);
        message(str);
        return;
      }
 
      var base_id = this.eqm_comp_list[this.cur_index][Object.keys(this.eqm_comp_list[this.cur_index]).length].id;
 
      if (base_id) {
        this.ctrl.getModel().setCompSendID(base_id);
        this.ctrl.send11079(base_id);
      }
    }.bind(this), 1);
    Utils.onTouchEnd(this.btn_comp_nd, function () {
      this.ctrl.openEquipmentCompRecordWindow(true);
    }.bind(this), 1); // 合成成功之后
 
    this.addGlobalEvent(EventId.COMPOSITE_RESULT, function () {
      this.compositeResult();
    }.bind(this));
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(index) {
    var index = index || 1;
    this.changeTabView(index); // 优先设置红点状态
 
    for (var key in this.tab_list) {
      var tab_object = this.tab_list[key];
 
      if (tab_object) {
        this.checkTabCanComposite(tab_object.index);
      }
    }
  },
  changeTabView: function changeTabView(index) {
    if (this.cur_index == index) {
      return;
    }
 
    if (this.cur_tab) {
      this.cur_tab.select.active = false;
      this.cur_tab.title.color = this.normal_color;
      this.cur_tab.title_outline.color = this.normal_outlinecolor;
    }
 
    this.cur_tab = this.tab_list[index];
    this.cur_index = index;
 
    if (this.cur_tab) {
      this.cur_tab.select.active = true;
      this.cur_tab.title.color = this.select_color;
      this.cur_tab.title_outline.color = this.select_outlinecolor;
    }
 
    this.setThePanelData();
  },
  // 合成成功,直接刷新界面吧
  compositeResult: function compositeResult() {
    this.setThePanelData(true); // 后续补充红点处理
  },
 
  /**
   * 设置标签数据,
   * @param {*} force 如果为true就标识不需要改变选中 
   */
  setThePanelData: function setThePanelData(force) {
    if (this.cur_tab == null) {
      return;
    }
 
    var type = this.cur_tab.index;
    var list = ForgeHouseController.getInstance().getModel().getBackEquipsData(type);
 
    if (list == null || list.length == 0) {
      return;
    } // 对数据充足
 
 
    var temp_ary = [];
    var had_select = false;
 
    for (var index = 0; index < list.length; index++) {
      var element = list[index];
      var is_select = false;
 
      if (force == true) {
        if (this.select_data && this.select_data.id == element.id) {
          is_select = true;
          had_select = true;
        }
      }
 
      var is_red = this.checkCanComposite(element.expend);
      temp_ary.push({
        data: element,
        is_select: is_select,
        is_red: is_red
      });
    } // 如果没有默认选中的,则选中第一个
 
 
    if (had_select == false) {
      temp_ary[0].is_select = true;
    }
 
    var clickback = function (cell) {
      this.selectItemCell(cell);
    }.bind(this);
 
    this.item_scrollview.setData(temp_ary, clickback, {
      is_other: false,
      scale: 1,
      effect: false,
      is_show_tips: true
    }); // 这个时候表示当前标签有合成成功,所以才做判断
 
    if (force == true) {
      this.checkTabCanComposite(this.cur_tab.index);
    }
  },
  // 判断一个装备是否有可合成数据
  checkCanComposite: function checkCanComposite(expend) {
    var can_composite = false;
    var coin_stauts = false;
 
    if (expend && expend.length >= 2 && expend[0].length >= 2) {
      var need_bid = expend[0][0];
      var need_num = expend[0][1];
      var max_num = BackPackController.getInstance().getModel().getPackItemNumByBid(BackPackConst.Bag_Code.EQUIPS, need_bid);
      can_composite = max_num >= need_num;
      var need_coin = expend[1][1];
      coin_stauts = need_coin <= this.role_vo.coin;
    }
 
    return can_composite && coin_stauts;
  },
  // 判断标签页是否可以显示红点,这个时候需要遍历这个标签页中 只要有可显示的就好了
  checkTabCanComposite: function checkTabCanComposite(index) {
    var tab_object = this.tab_list[index];
    if (tab_object == null) return;
    var type = tab_object.index;
    var list = ForgeHouseController.getInstance().getModel().getBackEquipsData(type);
 
    if (list && list.length > 0) {
      var is_red = false;
 
      for (var _index = 0; _index < list.length; _index++) {
        var element = list[_index];
        is_red = is_red || this.checkCanComposite(element.expend);
 
        if (is_red == true) {
          break;
        }
      }
    }
 
    tab_object.red_point.active = is_red;
  },
  // 选中处理
  selectItemCell: function selectItemCell(cell) {
    if (this.select_item) {
      this.select_item.setSelectStatus(false);
      this.select_item = null;
    }
 
    this.select_item = cell;
    this.select_item.setSelectStatus(true); // 然后对选中的做一些特殊设置
 
    this.updateChooseItem();
  },
  updateChooseItem: function updateChooseItem() {
    if (this.select_item == null || this.select_item.data == null) return; // 选中物品的数据
 
    this.select_data = this.select_item.data; // 设置右边目标物品
 
    this.cur_item.setData(this.select_data.id); // 设置左边需求物品
 
    var expend = this.select_data.expend;
 
    if (expend && expend.length >= 2) {
      // 第一个表示需求物品,第二个表示需求资产
      var need_bid = expend[0][0];
      var need_num = expend[0][1];
      this.last_item.setData(need_bid); // 设置显示进度
 
      var max_num = BackPackController.getInstance().getModel().getPackItemNumByBid(BackPackConst.Bag_Code.EQUIPS, need_bid); // 取出最大数量
 
      this.bar_num.string = max_num + "/" + need_num;
      var per = Math.min(1, Math.max(max_num / need_num));
      this.bar.progress = per; // 最大合成数量
 
      this.composite_max = Math.floor(max_num / need_num); // 资产显示
 
      var need_asset_num = expend[1][1]; // 保存单价
 
      this.composite_price = need_asset_num; // 默认合成最多个数
 
      this.setCompositeVal(this.composite_max);
    }
  },
  // 设置合成数量
  setCompositeVal: function setCompositeVal(val) {
    this.composite_number = val;
 
    if (val == 0) {} else {} // 当前合成数量
 
 
    this.composite_num.string = val; // 合成价格
 
    this.gold_num.string = val * this.composite_price;
  },
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.item_scrollview) {
      this.item_scrollview.DeleteMe();
    }
 
    this.item_scrollview = null;
 
    if (this.last_item) {
      this.last_item.onDelete();
    }
 
    this.last_item = null;
 
    if (this.cur_item) {
      this.cur_item.onDelete();
    }
 
    this.cur_item = null;
  }
});
 
cc._RF.pop();