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
"use strict";
cc._RF.push(module, '91cf6N/J3pL3o29EawKrEAC', 'newfirstcharge_window');
// Scripts/mod/newfirstcharge/view/newfirstcharge_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-03-22 11:02:42
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var VipController = require("vip_controller");
 
var NewFirstChargeEvent = require("newfirstcharge_event");
 
var NewfirstchargeWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("newfirstcharge", "newfirstcharge_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.cur_index = null;
    this.item_list = [];
    this.item_reward_list = [];
 
    for (var i = 1; i <= 3; i++) {
      this.item_reward_list[i] = {};
    }
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.root_wnd.getChildByName("background");
    this.background.scale = FIT_SCALE;
    this.main_container = this.root_wnd.getChildByName("main_container");
    var container = this.main_container.getChildByName("container");
    var bg_node = container.getChildByName("bg");
    var bg = bg_node.getComponent(cc.Sprite);
    this.loadRes(PathTool.getBigBg("txt_cn_action_bigbg_3", null, "action"), function (resObject) {
      bg.spriteFrame = resObject;
    }.bind(this));
    this.close_btn = container.getChildByName("close_btn");
    this.title_img = container.getChildByName("title_img");
    this.remain_charge = container.getChildByName("remain_charge").getComponent(cc.Label);
    this.remain_charge.string = Utils.TI18N("已累充: ");
    this.btn_recharge = container.getChildByName("btn");
    this.btn_label = this.btn_recharge.getChildByName("label").getComponent(cc.Label);
    this.btn_label.string = Utils.TI18N("前往充值");
    this.Sprite_2 = container.getChildByName("Sprite_2").getComponent(cc.Sprite);
    this.Sprite_2_0 = container.getChildByName("Sprite_2_0").getComponent(cc.Sprite);
    this.Sprite_2_1 = container.getChildByName("Sprite_2_1").getComponent(cc.Sprite);
    var icon_path = PathTool.getItemRes(3);
    this.loadRes(icon_path, function (res_object) {
      this.Sprite_2.spriteFrame = res_object;
      this.Sprite_2_0.spriteFrame = res_object;
      this.Sprite_2_1.spriteFrame = res_object;
    }.bind(this));
    this.model.setFirstRechargeData();
 
    for (var i = 1; i <= 3; i++) {
      var item = container.getChildByName("item_" + i);
 
      if (item) {
        var object = {};
        object.scroll = item.getChildByName("scroll").getChildByName("content");
        object.finish_icon = item.getChildByName("finish_icon");
        object.finish_icon.active = false;
        object.title = item.getChildByName("title").getComponent(cc.Label);
        object.title.string = Utils.TI18N("第") + i + Utils.TI18N("天免费领");
        object.list = {};
        this.item_list[i] = object;
      }
    }
 
    this.tab_view = [];
 
    for (var i = 1; i <= 2; i++) {
      var tab = {};
      tab.btn = container.getChildByName("btn_grade_" + i);
      tab.normal = tab.btn.getChildByName("normal");
      tab.select = tab.btn.getChildByName("select");
      tab.select.active = false;
      tab.title = tab.btn.getChildByName("title");
      tab.title.color = new cc.Color(0xff, 0xff, 0xff, 0xff);
      tab.titleOutLine = tab.btn.getChildByName("title").getComponent(cc.LabelOutline);
      tab.titleOutLine.color = new cc.Color(0x71, 0x00, 0x42, 0xff);
      tab.title_barner = container.getChildByName("title_img_" + i);
      tab.title_barner.scale = 2;
      tab.title_barner.active = false;
      this.loadRes(PathTool.getUIIconPath("newfirstcharge", "txt_cn_newfirstcharge_" + i), function (title_barner, resObject) {
        title_barner.getComponent(cc.Sprite).spriteFrame = resObject;
      }.bind(this, tab.title_barner));
      tab.index = i;
      this.tab_view[i] = tab;
    }
 
    this.tab_get_hero = {};
 
    for (var i = 1; i <= 3; i++) {
      var tab = {};
      tab.btn = container.getChildByName("btn_" + i);
      tab.title = tab.btn.getChildByName("Text_1");
      tab.get = container.getChildByName("get_" + i);
      tab.get.active = false;
      tab.index = i;
      this.tab_get_hero[i] = tab;
    }
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.close_btn, function () {
      this.ctrl.openNewFirstChargeView(false);
    }.bind(this), 2);
    Utils.onTouchEnd(this.btn_recharge, function () {
      var first_data = this.model.getFirstRechargeData(this.cur_index);
 
      if (this.get_gift_id == 0) {
        this.ctrl.openNewFirstChargeView(false); //临时
 
        VipController.getInstance().openVipMainWindow(true, VIPTABCONST.DAILY_GIFT);
      } else if (this.get_gift_id == 1) {
        if (first_data[this.gift_index]) {
          this.ctrl.sender21013(first_data[this.gift_index].id);
        }
      } else {
        this.ctrl.openNewFirstChargeView(false);
      }
    }.bind(this), 1);
 
    for (var i in this.tab_view) {
      Utils.onTouchEnd(this.tab_view[i].btn, function (v) {
        this.changeTabView(v.index);
      }.bind(this, this.tab_view[i]), 1);
    }
 
    for (var j in this.tab_get_hero) {
      Utils.onTouchEnd(this.tab_get_hero[j].btn, function (v) {
        if (v.index && this.updata_charge_data) {
          if (this.updata_charge_data.choosen_status == 1) {
            var list = [20501, 30506, 10505];
            var role_data = Config.partner_data.data_partner_base[list[v.index - 1]];
 
            if (role_data) {
              var str = cc.js.formatStr(Utils.TI18N("<color=#643223>是否确定选择</color> <color=#bc3f0e fontsize=26>%s</color> <color=#643223>作为奖励?\n</color> <color=#643223>  确定后其它英雄将不可领取</color>"), role_data.name);
 
              var CommonAlert = require("commonalert");
 
              CommonAlert.show(str, Utils.TI18N("确定"), function () {
                this.ctrl.sender21014(v.index);
              }.bind(this), Utils.TI18N("取消"));
            }
          } else {
            this.ctrl.sender21014(v.index);
          }
        }
      }.bind(this, this.tab_get_hero[j]), 1);
    }
 
    this.addGlobalEvent(NewFirstChargeEvent.New_First_Charge_Event, function (data) {
      this.updata_charge_data = data;
 
      if (data.choosen_status != null && data.has_choosen_id != null) {
        this.getChooseHeroStatus(data.choosen_status, data.has_choosen_id);
      }
 
      var RoleController = require("role_controller");
 
      var role_vo = RoleController.getInstance().getRoleVo();
      var totle_str = cc.js.formatStr(Utils.TI18N("已累充: %d"), Math.floor(role_vo.vip_exp * 0.1));
      this.remain_charge.string = totle_str;
      this.setRedPointTab();
      this.updateData(data);
    }.bind(this));
  },
  // 红点
  setRedPointTab: function setRedPointTab() {
    var status_1 = false;
 
    for (var i = 1; i <= 3; i++) {
      var get_data = this.model.getFirstBtnStatus(i);
 
      if (get_data) {
        if (get_data == 1) {
          status_1 = true;
          break;
        }
      }
    }
 
    Utils.addRedPointToNodeByStatus(this.tab_view[1].btn, status_1);
    var status_2 = false;
 
    for (var i = 4; i <= 6; i++) {
      var get_data = this.model.getFirstBtnStatus(i);
 
      if (get_data) {
        if (get_data == 1) {
          status_2 = true;
          break;
        }
      }
    }
 
    Utils.addRedPointToNodeByStatus(this.tab_view[2].btn, status_2);
  },
  changeTabView: function changeTabView(index) {
    index = index || 0;
    if (this.cur_index == index) return;
 
    if (this.tab_index != null) {
      this.tab_index.normal.active = true;
      this.tab_index.select.active = false;
      this.tab_index.titleOutLine.color = new cc.Color(0x71, 0x00, 0x42, 0xff);
      this.tab_index.title_barner.active = false;
    }
 
    this.tab_index = this.tab_view[index];
 
    if (this.tab_index != null) {
      this.tab_index.normal.active = false;
      this.tab_index.select.active = true;
      this.tab_index.titleOutLine.color = new cc.Color(0xc4, 0x5a, 0x14, 0xff);
      this.tab_index.title_barner.active = true;
    }
 
    this.cur_index = index;
    var first_data = this.model.getFirstRechargeData(index);
    this.fillItemList(first_data);
 
    if (this.updata_charge_data) {
      this.updateData(this.updata_charge_data);
    }
  },
  fillItemList: function fillItemList(list) {
    var scale = 0.8;
    var size = 119 * scale;
    var create_index = 1;
 
    for (var i = 0; i < list.length; i++) {
      var object = this.item_list[i + 1];
      var num = list[i].item_list.length;
      object.scroll.setContentSize(cc.size(size * num, object.scroll.getContentSize().height));
 
      for (var k = 0; k < num; k++) {
        var _x = size * (k + 1) - size * 0.5;
 
        var _y = size * 0.5;
 
        if (!this.item_reward_list[i + 1][k]) {
          this.item_reward_list[i + 1][k] = ItemsPool.getInstance().getItem("backpack_item");
          this.item_reward_list[i + 1][k].setParent(object.scroll);
          this.item_reward_list[i + 1][k].setExtendData({
            scale: scale,
            is_show_tips: true
          });
          this.item_reward_list[i + 1][k].show();
        }
 
        if (this.item_reward_list[i + 1][k]) {
          this.item_reward_list[i + 1][k].setPosition(_x, _y);
          this.item_reward_list[i + 1][k].setData({
            bid: list[i].item_list[k][0],
            num: list[i].item_list[k][1]
          });
          cc.log(list[i], "list[i]");
        }
 
        create_index = create_index + 1;
      }
    }
  },
  // 选择英雄按钮
  getChooseHeroStatus: function getChooseHeroStatus(status, choose_id) {
    for (var i = 1; i <= 3; i++) {
      if (status == 0) {
        this.tab_get_hero[i].get.active = false;
        this.tab_get_hero[i].btn.active = true;
        this.tab_get_hero[i].btn.getComponent(cc.Button).interactable = false;
        this.tab_get_hero[i].btn.getComponent(cc.Button).enableAutoGrayEffect = true;
        this.tab_get_hero[i].title.color = new cc.Color(0xff, 0xff, 0xff, 0xff);
      } else if (status == 1) {
        this.tab_get_hero[i].get.active = false;
        this.tab_get_hero[i].btn.active = true;
        this.tab_get_hero[i].btn.getComponent(cc.Button).interactable = true;
        this.tab_get_hero[i].btn.getComponent(cc.Button).enableAutoGrayEffect = false;
        this.tab_get_hero[i].title.color = new cc.Color(0x25, 0x55, 0x05, 0xff);
      } else if (status == 2) {
        this.tab_get_hero[i].btn.active = false;
 
        if (i == choose_id) {
          this.tab_get_hero[i].get.active = true;
        }
      }
    }
  },
  updateData: function updateData(data) {
    if (data == null) return;
    var status_list = [[1, 2, 3], [4, 5, 6]];
    var charge_list = [];
 
    for (var i in status_list[this.cur_index - 1]) {
      var status = this.model.getFirstBtnStatus(status_list[this.cur_index - 1][i]);
      charge_list[i] = status;
      this.item_list[parseInt(i) + 1].finish_icon.active = status == 2;
    }
 
    this.gift_index = 0; //领取的位置
 
    var totle = 0;
    this.get_gift_id = 10;
 
    for (var i in charge_list) {
      totle = totle + charge_list[i];
 
      if (charge_list[i] == 1) {
        this.get_gift_id = 1;
        this.gift_index = i;
      }
    }
 
    if (totle == 0) {
      this.get_gift_id = 0;
      this.btn_label.string = Utils.TI18N("前往充值");
    } else if (totle == 1 || totle == 3 || totle == 5) {
      this.btn_label.string = Utils.TI18N("领取奖励");
    } else if (totle == 2 || totle == 4) {
      this.btn_label.string = Utils.TI18N("明日再来");
    } else if (totle == 6) {
      this.btn_label.string = Utils.TI18N("领取完毕");
    }
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(index) {
    index = index || 1;
    this.changeTabView(index);
    this.ctrl.sender21012();
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    for (var i = 1; i <= 3; i++) {
      for (var j in this.item_reward_list[i]) {
        this.item_reward_list[i][j].deleteMe();
      }
 
      this.item_reward_list[i] = null;
    }
 
    this.item_reward_list = [];
    this.ctrl.openNewFirstChargeView(false);
  }
});
 
cc._RF.pop();