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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
"use strict";
cc._RF.push(module, '3e4f97ctNZFJY2Akocnka5f', 'mall_son_panel');
// Scripts/mod/mall/view/mall_son_panel.js
 
"use strict";
 
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
 
// --------------------------------------------------------------------
// @author: @syg.com(必填, 创建模块的人员)
// @description:
//      竖版商城子商城
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var MallController = require("mall_controller");
 
var RoleController = require("role_controller");
 
var MallConst = require("mall_const");
 
var MallEvent = require("mall_event");
 
var MallItem = require("mall_item");
 
var CommonScrollView = require("common_scrollview");
 
var BackpackController = require("backpack_controller");
 
var TimeTool = require("timetool");
 
var treasure_type = 16; //针对探宝的
 
var MallSonPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("mall", "mall_son_panel");
    this.ctrl = MallController.getInstance();
    this.role_vo = RoleController.getInstance().getRoleVo();
    this.tab_list = [];
    this.cur_index = null;
    this.cur_tab = null;
    this.data_list = [];
  },
  initPanel: function initPanel() {
    this.main_container = this.root_wnd.getChildByName("main_container");
    this.tab_container = this.main_container.getChildByName("tab_container");
 
    for (var i = 1; i < 5; i++) {
      var tab_btn = this.tab_container.getChildByName(cc.js.formatStr("tab_btn_%s", i));
      tab_btn.label = tab_btn.getChildByName("title").getComponent(cc.Label);
      tab_btn.label.node.color = new cc.Color(0xcf, 0xb5, 0x93, 0xff); // tab_btn.bright = false;
 
      tab_btn.btn = tab_btn.getComponent(cc.Button);
      tab_btn.btn.interactable = false;
      tab_btn.index = i;
      tab_btn.is_first = true;
      this.tab_list[i] = tab_btn;
    }
 
    this.refresh_panel = this.main_container.getChildByName("refresh_panel");
    this.refresh_panel.active = false;
    this.btn_refresh = this.refresh_panel.getChildByName("btn_refresh");
    this.refresh_time = this.refresh_panel.getChildByName("refresh_time").getComponent(cc.Label);
    this.refresh_time.string = "";
    var config = gdata("exchange_data", "data_shop_list", [treasure_type]);
    var Sprit_1 = this.btn_refresh.getChildByName("Sprite_1").getComponent(cc.Sprite);
    Sprit_1.node.setScale(0.5, 0.5);
    var item_res_path = PathTool.getItemRes(Utils.getItemConfig(config.item_bid).icon);
 
    if (item_res_path) {
      this.loadRes(item_res_path, function (res_object) {
        Sprit_1.spriteFrame = res_object;
      }.bind(this));
    }
 
    var Text_1 = this.btn_refresh.getChildByName("Text_1").getComponent(cc.Label);
    Text_1.string = config.cost_list[0][1] + "刷新";
    this.scrollCon = this.main_container.getChildByName("scrollCon");
    this.coin = this.main_container.getChildByName("coin").getComponent(cc.Sprite);
    this.count = this.main_container.getChildByName("count").getComponent(cc.Label);
    this.add_btn = this.main_container.getChildByName("add_btn");
    this.add_btn.active = false;
    var scroll_view_size = cc.size(622, 648);
    var setting = {
      item_class: MallItem,
      // 单元类
      start_x: 4,
      // 第一个单元的X起点
      space_x: 0,
      // x方向的间隔
      start_y: 3,
      // 第一个单元的Y起点
      space_y: 2,
      // y方向的间隔
      item_width: 306,
      // 单元的尺寸width
      item_height: 143,
      // 单元的尺寸height
      row: 0,
      // 行数,作用于水平滚动类型
      col: 2,
      // 列数,作用于垂直滚动类型
      need_dynamic: true
    };
    this.item_scrollview = new CommonScrollView();
    this.item_scrollview.createScroll(this.scrollCon, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting, cc.v2(0.5, 0.5));
  },
  registerEvent: function registerEvent() {
    // for (var k in this.tab_list){
    //     var tab_btn = this.tab_list[k];
    //     var func = function(btn){
    //         if(btn.type != null){
    //             if(btn.btn.interactable == false){
    //                 message(Utils.TI18N(btn.notice));
    //             }else{
    //                 this.changeTabView(btn.index);
    //             }
    //         }
    //     }.bind(this)
    //     tab_btn.on(cc.Node.EventType.TOUCH_END,func(tab_btn))
    // }
    this.add_btn.on(cc.Node.EventType.TOUCH_END, function () {
      var item_bid = gdata("exchange_data", "data_shop_list", [this.cur_tab.type]).item_bid;
      var data = Utils.getItemConfig(item_bid);
      BackpackController.getInstance().openTipsSource(true, data);
    }, this);
    this.addGlobalEvent(MallEvent.Open_View_Event, function (data) {
      if (this.cur_index != 4) {
        var list = this.getConfig(this.cur_tab.type, data);
        this.data_list[this.cur_index] = Utils.deepCopy(list);
        this.item_scrollview.setData(this.data_list[this.cur_index], function (cell) {
          this.ctrl.openMallBuyWindow(true, cell);
        }.bind(this));
      }
    }.bind(this));
 
    if (this.role_vo) {
      if (this.role_update_lev_event == null) {
        this.role_update_lev_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) {
          // if (this.cur_index == null || this.cur_index == MallConst.MallType.ScoreShop)
          //     return
          if (key == "lev") {
            for (var k in this.tab_list) {
              if (k == this.cur_index) {
                continue;
              }
 
              this.setTabBtnTouchStatus(this.checkBtnIsOpen(k), k);
            }
          } else if (key == "gsrv_id" || key == "gid") {
            this.setTabBtnTouchStatus(this.checkBtnIsOpen(5), 1);
          } else if (key == "gold" || key == "arena_cent" || key == "guild" || key == "hero_soul" || key == "friend_point" || key == "arena_guesscent" || key == "star_point" || key == "expedition_medal") {
            var item_bid = gdata("exchange_data", "data_shop_list", [this.cur_tab.type]).item_bid;
 
            if (gdata("item_data", "data_assets_id2label", [item_bid]) == key) {
              var item_res_path = PathTool.getItemRes(Utils.getItemConfig(item_bid).icon);
 
              if (item_res_path) {
                this.loadRes(item_res_path, function (res_object) {
                  this.coin.spriteFrame = res_object;
                }.bind(this));
              }
 
              if (this.cur_index == 4) {
                this.count.string = this.role_vo.star_point;
              } else {
                if (this.cur_index == 1) {
                  this.count.string = this.role_vo.expedition_medal;
                } else {
                  this.count.string = this.role_vo[gdata("item_data", "data_assets_id2label", [item_bid])];
                }
              }
            }
          }
        }, this);
      }
    } //除神秘神格商城以外的购买成功
 
 
    this.addGlobalEvent(MallEvent.Buy_Success_Event, function (data) {
      if (this.cur_index && this.data_list && this.data_list[this.cur_index]) {
        for (var k in this.data_list[this.cur_index]) {
          var v = this.data_list[this.cur_index][k];
 
          if (typeof v == "number") {
            if (v != null && v.id != null && v.has_buy != null) {
              if (v.id == data.eid && Utils.next(data.ext || {}) != null) v.has_buy = data.ext[0].val;
            }
          }
        }
      }
    }.bind(this));
    this.btn_refresh.on(cc.Node.EventType.TOUCH_END, function () {
      var list = gdata("exchange_data", "data_shop_list", [treasure_type]).cost_list;
 
      if (this.role_vo.star_point >= list[0][1]) {
        this.ctrl.sender13405(treasure_type);
      } else {
        message(Utils.TI18N("探宝积分不足"));
        BackpackController.getInstance().openTipsSource(true, 18);
      }
    }, this);
    this.addGlobalEvent(MallEvent.Get_Buy_list, function (data) {
      if (data.type == treasure_type) {
        this.setLessTime(data.refresh_time - gcore.SmartSocket.getTime());
 
        for (var k in data.item_list) {
          data.item_list[k].shop_type = treasure_type;
        }
 
        this.data_list[this.cur_index] = Utils.deepCopy(data);
        this.item_scrollview.setData(this.data_list[this.cur_index].item_list, function (cell) {
          this.ctrl.openMallBuyWindow(true, cell);
        }.bind(this));
      }
    }.bind(this));
  },
  //设置倒计时
  setLessTime: function setLessTime(less_time) {
    if (this.refresh_time == null) return;
    this.refresh_time.node.stopAllActions();
 
    if (less_time > 0) {
      this.setTimeFormatString(less_time);
      var callfun = cc.callFunc(function () {
        less_time = less_time - 1;
 
        if (less_time < 0) {
          this.refresh_time.node.stopAllActions();
        } else {
          this.setTimeFormatString(less_time);
        }
      }.bind(this));
      this.refresh_time.node.runAction(cc.repeatForever(cc.sequence(cc.delayTime(1), callfun)));
    } else {
      this.setTimeFormatString(less_time);
    }
  },
  setTimeFormatString: function setTimeFormatString(time) {
    if (time > 0) {
      this.refresh_time.string = TimeTool.getTimeFormat(time);
    } else {
      this.refresh_time.string = "00:00:00";
    }
  },
  setData: function setData(data) {
    if (data == null) return;
    this.data = data;
    if (this.root_wnd) this.onShow();
  },
  onShow: function onShow() {
    this.setList(this.list);
    this.openById(this.id);
  },
  setCallFun: function setCallFun(call_fun) {
    this.call_fun = call_fun;
  },
  setVisibleStatus: function setVisibleStatus(bool) {
    if (this.root_wnd == null) return;
    this.root_wnd.active = bool;
  },
  onDelete: function onDelete() {
    if (this.item_scrollview) this.item_scrollview.deleteMe();
    this.item_scrollview = null;
 
    if (this.role_update_lev_event) {
      if (this.role_vo) {
        this.role_vo.unbind(this.role_update_lev_event);
        this.role_update_lev_event = null;
        this.role_vo = null;
      }
    }
 
    if (this.refresh_time) {
      this.refresh_time.node.stopAllActions();
      this.refresh_time = null;
    }
  },
  changeTabView: function changeTabView(index) {
    if (this.cur_index == index) return;
 
    if (this.cur_tab != null) {
      this.cur_tab.label.node.color = new cc.Color(0xcf, 0xb5, 0x93, 0xff);
      this.cur_tab.btn.interactable = true;
    }
 
    this.cur_index = index;
    this.cur_tab = this.tab_list[this.cur_index];
 
    if (this.cur_tab) {
      this.cur_tab.label.node.color = new cc.Color(0xff, 0xed, 0xd6, 0xff);
      this.cur_tab.btn.interactable = false;
    }
 
    this.refresh_panel.active = this.cur_index == 4;
 
    if (this.cur_tab.is_first) {
      this.ctrl.sender13401(this.cur_tab.type);
      this.cur_tab.is_first = false;
    } else {
      if (this.cur_index != 4) {
        this.item_scrollview.setData(this.data_list[this.cur_index], function (cell) {
          this.ctrl.openMallBuyWindow(true, cell);
        }.bind(this));
      }
    }
 
    if (this.cur_index == 4) {
      this.item_scrollview.setData([]);
      this.ctrl.sender13403(treasure_type);
    }
 
    var item_bid = gdata("exchange_data", "data_shop_list", [this.cur_tab.type]).item_bid;
 
    if (item_bid) {
      if (this.cur_index == 4) {
        var item_bid = gdata("exchange_data", "data_shop_list", [treasure_type]).item_bid;
        var item_res_path = PathTool.getItemRes(Utils.getItemConfig(item_bid).icon);
 
        if (item_res_path) {
          this.loadRes(item_res_path, function (res_object) {
            this.coin.spriteFrame = res_object;
          }.bind(this));
          this.count.string = this.role_vo.star_point;
        }
      } else {
        var item_res_path = PathTool.getItemRes(Utils.getItemConfig(item_bid).icon);
 
        if (item_res_path) {
          this.loadRes(item_res_path, function (res_object) {
            this.coin.spriteFrame = res_object;
          }.bind(this));
          this.count.string = this.role_vo.star_point;
        }
 
        if (this.cur_index == 1) this.count.string = this.role_vo.expedition_medal;else this.count.string = Utils.getMoneyString(this.role_vo[gdata("item_data", "data_assets_id2label", [item_bid])]);
      }
    }
  },
  openById: function openById(id) {
    this.id = id;
    if (this.root_wnd == null) return;
 
    for (var k in this.tab_list) {
      var v = this.tab_list[k];
 
      if (v.type == id) {
        this.cur_index = null;
        this.changeTabView(v.index);
      }
    }
  },
  getConfig: function getConfig(index, data) {
    var config = [];
 
    if (index == 5) {
      config = Utils.deepCopy(Config.exchange_data.data_shop_exchage_guild);
    } else if (index == 6) {
      config = Utils.deepCopy(Config.exchange_data.data_shop_exchage_arena);
    } else if (index == 7) {
      config = Utils.deepCopy(Config.exchange_data.data_shop_exchage_boss);
    } else if (index == 8) {
      config = Utils.deepCopy(Config.exchange_data.data_shop_exchage_expediton);
    } else if (index == 16) {
      //探宝
      config = Utils.deepCopy(Config.exchange_data.data_shop_exchage_guess);
    }
 
    var list = Utils.deepCopy(data.item_list);
    var show_list = [];
 
    for (var a in config) {
      var j = config[a];
 
      if (j.type == this.cur_tab.type) {
        if (list && Utils.next(list)) {
          //已经买过的限购物品
          for (var k in list) {
            var v = list[k];
 
            if (j.id == v.item_id) {
              if (v.ext[0] && v.ext[0].val != null) {
                //不管是什么限购 赋值已购买次数就好了
                j.has_buy = v.ext[0].val;
                list.splice(k, 1);
              }
 
              break;
            } else j.has_buy = 0;
          }
        } else j.has_buy = 0;
 
        show_list.push(j);
      }
    }
 
    return show_list;
  },
  checkBtnIsOpen: function checkBtnIsOpen(type) {
    if (type == 5) {
      //工会
      if (this.role_vo.lev >= gdata("exchange_data", "data_shop_exchage_cost", "open_guild_lev").val && this.role_vo.isHasGuild()) return true;else return false;
    } else if (type == 6 || type == 16) {
      //竞技
      var SceneConst = require("scene_const");
 
      var build_vo = require("mainscene_controller").getInstance().getBuildVo(SceneConst.CenterSceneBuild.arena);
 
      if (build_vo && build_vo.is_lock) return false;else return true;
    } else if (type == 7) {
      if (this.role_vo.lev >= gdata("exchange_data", "data_shop_exchage_cost", "open_god_point_lev").val) return true;else return false;
    }
 
    return true;
  },
  setTabBtnTouchStatus: function setTabBtnTouchStatus(status, index) {
    var tab_btn = this.tab_list[index];
 
    if (tab_btn) {
      if (!status) tab_btn.getComponent(cc.Sprite).setState(cc.Sprite.State.GRAY);else {
        tab_btn.getComponent(cc.Sprite).setState(cc.Sprite.State.NORMAL);
        tab_btn.getComponent(cc.Button).interactable = status;
        tab_btn.getComponent(cc.Button).enableAutoGrayEffect = !status;
      }
      tab_btn.can_touch = status;
    }
  },
  setList: function setList(list) {
    var _notice_list;
 
    this.list = list;
    if (this.root_wnd == null) return;
    var notice_list = (_notice_list = {}, _defineProperty(_notice_list, 5, gdata("exchange_data", "data_shop_exchage_cost", "open_guild_lev").desc), _defineProperty(_notice_list, 16, gdata("exchange_data", "data_shop_exchage_cost", "open_arena_cent_lev").desc), _defineProperty(_notice_list, 6, gdata("exchange_data", "data_shop_exchage_cost", "open_arena_cent_lev").desc), _notice_list);
 
    for (var k in this.tab_list) {
      var v = this.tab_list[k];
 
      if (list[k - 1] != null) {
        v.active = true;
        v.label.string = gdata("exchange_data", "data_shop_list", [list[k - 1]]).name;
        v.type = list[k - 1];
        v.notice = notice_list[v.type];
        this.setTabBtnTouchStatus(this.checkBtnIsOpen(v.type), k);
      } else {
        v.active = false;
      }
    }
 
    if (this.btn_event == null) {
      for (var k in this.tab_list) {
        var tab_btn = this.tab_list[k];
 
        if (tab_btn != null) {
          tab_btn.on(cc.Node.EventType.TOUCH_END, function (event) {
            var btn = event.currentTarget;
 
            if (btn.type != null) {
              if (btn.can_touch == false) message(Utils.TI18N(btn.notice));else this.changeTabView(btn.index);
            }
          }, this);
        }
      }
 
      this.btn_event = true;
    } // var select_index = 1;
    // for(var i = 0;i < list.length; i ++){
    //     if (list[i] != null){
    //         if (this.checkBtnIsOpen(this.tab_list[i]).type){
    //             select_index = i;
    //             break
    //         }
    //     }
    // }
 
  }
});
module.exports = MallSonPanel;
 
cc._RF.pop();