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
"use strict";
cc._RF.push(module, '09ce7eDPQhM8KRslRou8T7R', 'stone_dungeon_window');
// Scripts/mod/stone_dungeon/view/stone_dungeon_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-01-08 12:01:56
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var StoneDungeonController = require("stone_dungeon_controller");
 
var CommonScrollView = require("common_scrollview");
 
var StoneDungeonEvent = require("stone_dungeon_event");
 
var RoleController = require("role_controller");
 
var MainuiController = require("mainui_controller");
 
var Stone_dungeonWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("stonedungeon", "stone_dungeon_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.role_vo = RoleController.getInstance().getRoleVo();
    this.first_come_in = true;
    this.cur_index = 1;
    this.tab_list = [];
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.root_wnd.getChildByName("background");
    this.background.scale = FIT_SCALE;
    this.main_container = this.root_wnd.getChildByName("main_container");
    this.background_img = this.main_container.getChildByName("background").getComponent(cc.Sprite);
    this.loadRes(PathTool.getCommonIcomPath("common_1003"), function (resObject) {
      this.background_img.spriteFrame = resObject;
    }.bind(this));
    this.Image_2_0 = this.main_container.getChildByName("Image_2_0").getComponent(cc.Sprite);
    this.Image_2 = this.main_container.getChildByName("Image_2").getComponent(cc.Sprite);
    this.loadRes(PathTool.getCommonIcomPath("common_1013"), function (resObject) {
      this.Image_2_0.spriteFrame = resObject;
      this.Image_2.spriteFrame = resObject;
    }.bind(this));
    this.Image_3 = this.main_container.getChildByName("Image_3").getComponent(cc.Sprite);
    this.loadRes(PathTool.getUIIconPath("activity", "activity_8"), function (resObject) {
      this.Image_3.spriteFrame = resObject;
    }.bind(this));
    this.Image_1 = this.main_container.getChildByName("Image_1").getComponent(cc.Sprite);
    this.loadRes(PathTool.getCommonIcomPath("common_1002"), function (resObject) {
      this.Image_1.spriteFrame = resObject;
    }.bind(this));
    this.textCount = this.main_container.getChildByName("textCount").getComponent(cc.Label);
    this.banner_node = this.main_container.getChildByName("banner");
    this.banner_node.scale = 2;
    this.banner = this.banner_node.getComponent(cc.Sprite);
    this.close_btn = this.main_container.getChildByName("close_btn");
    this.btnRule = this.main_container.getChildByName("btnRule");
    this.scoreView = this.main_container.getChildByName("scoreView");
    this.scoreView_img = this.scoreView.getChildByName("background").getComponent(cc.Sprite);
    this.loadRes(PathTool.getCommonIcomPath("common_1034"), function (resObject) {
      this.scoreView_img.spriteFrame = resObject;
    }.bind(this));
    this.tab_container = this.main_container.getChildByName("tab_container");
 
    var StoneDungeonTab = require("stone_dungeon_tab");
 
    var setting = {
      item_class: StoneDungeonTab,
      // 单元类
      start_x: 0,
      // 第一个单元的X起点
      space_x: 32,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 0,
      // y方向的间隔
      item_width: 120,
      // 单元的尺寸width
      item_height: 136,
      // 单元的尺寸height
      row: 1,
      // 行数,作用于水平滚动类型
      col: 0 // 列数,作用于垂直滚动类型
 
    };
    var scroll_view_size = this.tab_container.getContentSize();
    this.tabScrollview = new CommonScrollView();
    this.tabScrollview.createScroll(this.tab_container, cc.v2(0, 0), ScrollViewDir.horizontal, ScrollViewStartPos.top, scroll_view_size, setting);
 
    var StoneDungeonItem = require("stone_dungeon_item");
 
    var setting = {
      item_class: StoneDungeonItem,
      // 单元类
      start_x: 0,
      // 第一个单元的X起点
      space_x: 0,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 0,
      // y方向的间隔
      item_width: 616,
      // 单元的尺寸width
      item_height: 125,
      // 单元的尺寸height
      row: 0,
      // 行数,作用于水平滚动类型
      col: 1,
      // 列数,作用于垂直滚动类型
      once_num: 5
    };
    var scroll_view_size = cc.size(616, 490);
    this.itemScrollview = new CommonScrollView();
    this.itemScrollview.createScroll(this.scoreView, cc.v2(0, -255), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting, cc.v2(0.5, 0.5));
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.close_btn.on(cc.Node.EventType.TOUCH_END, function (event) {
      StoneDungeonController.getInstance().openStoneDungeonView(false);
    }, this);
    this.addGlobalEvent(StoneDungeonEvent.Update_StoneDungeon_Data, function (data) {
      this.changeDungeonData(this.cur_index, 1);
      this.first_come_in = false;
      this.redPointStatus();
    }.bind(this));
    this.btnRule.on(cc.Node.EventType.TOUCH_END, function (event) {
      var config = Config.dungeon_stone_data.data_const.desc_rule;
      Utils.playButtonSound(1);
      var pos = event.touch.getLocation();
 
      require("tips_controller").getInstance().showCommonTips(config.desc, pos);
    }, this);
  },
  // 红点
  redPointStatus: function redPointStatus() {
    var status = [];
    var length = Config.dungeon_stone_data.data_type_open_length;
    var list = Config.dungeon_stone_data.data_const.dungeon_type.val;
 
    for (var i = 0; i < length; i++) {
      var count = this.model.getChangeSweepCount(list[i]);
      status[list[i]] = false;
      var bool = MainuiController.getInstance().checkIsOpenByActivate(Config.dungeon_stone_data.data_type_open[list[i]].activate);
 
      if (count < 2 && bool == true) {
        status[list[i]] = true;
      }
 
      var item = this.tab_list[i];
 
      if (item) {
        item.setSelectRedPoint(status[list[i]] || false);
      }
    }
 
    var bool = false;
 
    for (var i = 1; i <= length; i++) {
      bool = bool || status[i] || false;
    }
 
    return bool;
  },
  changeDungeonData: function changeDungeonData(index, flag) {
    index = Config.dungeon_stone_data.data_type_open[index].id || 1;
    var change_count = this.model.getChangeSweepCount(index);
    var str = "";
    var free_count = 1; //1:还有次数
 
    if (change_count >= 2) {
      free_count = 0;
 
      if (change_count >= Config.dungeon_stone_data.data_buy[index].length) {
        str = cc.js.formatStr(Utils.TI18N("今日已无次数"));
      } else {
        var vip_count = 1;
 
        for (var i in Config.dungeon_stone_data.data_buy[index]) {
          if (Config.dungeon_stone_data.data_buy[index][i].vip <= this.role_vo.vip_lev) {
            vip_count = i;
          }
        }
 
        var remain_num = vip_count - change_count;
 
        if (remain_num <= 0) {
          remain_num = 0;
        }
 
        str = cc.js.formatStr(Utils.TI18N("今日剩余次数: %d"), remain_num);
      }
    } else {
      str = cc.js.formatStr(Utils.TI18N("今日免费次数: %d"), Config.dungeon_stone_data.data_const.free_num.val - change_count);
    }
 
    this.textCount.string = str;
 
    if (this.itemScrollview) {
      var data_info = [];
 
      for (var i in Config.dungeon_stone_data.data_award_list) {
        if (Config.dungeon_stone_data.data_award_list[i].dun_type == index) {
          data_info.push(Config.dungeon_stone_data.data_award_list[i]);
        }
      }
 
      data_info.sort(function (a, b) {
        return a.id - b.id;
      });
      var title_pos = this.getPoerTitle(data_info);
      change_count = change_count + 1;
      var temp_arr = Object.keys(Config.dungeon_stone_data.data_buy[index]);
 
      if (change_count >= temp_arr.length) {
        change_count = temp_arr.length;
      }
 
      var tab = {
        title_pos: title_pos,
        //推荐位置
        count: free_count,
        //免费次数
        expend: Config.dungeon_stone_data.data_buy[index][change_count].cost //消耗钻石
 
      };
      var list_item = this.itemScrollview.getItemList();
 
      if (flag == 1 && this.first_come_in == false) {
        for (var i in list_item) {
          list_item[i].setExtendData(tab);
          list_item[i].setChangeData(data_info[i]);
        }
      } else {
        this.itemScrollview.setData(data_info, null, tab);
        this.itemScrollview.jumpToMove(cc.v2(0, 125 * (title_pos - 1)), 0.2);
      }
    }
  },
  // 获取推荐角标
  getPoerTitle: function getPoerTitle(data) {
    var num = -1;
    var totle = data.length;
 
    for (var i in data) {
      var clearance = this.model.getPassClearanceID(data[i].id);
 
      if (this.role_vo.max_power >= data[i].power) {
        if (clearance && clearance.status == 1) {
          num = parseInt(i);
        }
      }
    }
 
    if (num + 1 >= totle) {
      num = totle;
    } else {
      if (data[num + 1] && this.role_vo.max_power >= data[num + 1].power && this.role_vo.lev >= data[num + 1].lev_limit) {
        num = num + 2;
      } else {
        return num + 1;
      }
    }
 
    return num;
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(params) {
    this.ctrl.send13030();
    var list = Config.dungeon_stone_data.data_const.dungeon_type.val;
    var tab = [];
 
    for (var i = 0; i < list.length; i++) {
      tab.push({
        id: list[i]
      });
    }
 
    var res = PathTool.getIconPath("activity/activity_big", "activity_banner_1", false, false);
    this.loadRes(res, function (resObject) {
      this.banner.spriteFrame = resObject;
    }.bind(this));
 
    var click_callback = function (cell) {
      var bool = MainuiController.getInstance().checkIsOpenByActivate(Config.dungeon_stone_data.data_type_open[cell.getData().id].activate);
 
      if (bool == false) {
        message(Config.dungeon_stone_data.data_type_open[cell.getData().id].desc);
        return;
      }
 
      if (this.cur_index == cell.getData().id) return;
      var list_item = this.tabScrollview.getItemList();
 
      for (var i in list_item) {
        if (list_item[i].getData().id == cell.getData().id) {
          list_item[i].setSelect(true);
        } else {
          list_item[i].setSelect(false);
        }
      }
 
      this.cur_index = cell.getData().id;
      this.changeDungeonData(cell.getData().id);
      var res = PathTool.getIconPath("activity/activity_big", "activity_banner_" + Config.dungeon_stone_data.data_type_open[cell.getData().id].id, false, false);
      this.loadRes(res, function (resObject) {
        this.banner.spriteFrame = resObject;
      }.bind(this));
    }.bind(this);
 
    this.tabScrollview.setData(tab, click_callback);
 
    if (this.tabScrollview) {
      this.tabScrollview.addEndCallBack(function () {
        var list_item = this.tabScrollview.getItemList();
 
        for (var i in list_item) {
          this.tab_list.push(list_item[i]);
        }
 
        this.redPointStatus();
      }.bind(this));
    }
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    StoneDungeonController.getInstance().openStoneDungeonView(false);
 
    if (this.tabScrollview) {
      this.tabScrollview.DeleteMe();
      this.tabScrollview = null;
    }
 
    if (this.itemScrollview) {
      this.itemScrollview.DeleteMe();
      this.itemScrollview = null;
    }
 
    for (var i in this.tab_list) {
      if (this.tab_list[i].deleteMe) {
        this.tab_list[i].deleteMe();
        this.tab_list[i] = null;
      }
    }
 
    this.tab_list = [];
  }
});
 
cc._RF.pop();