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
"use strict";
cc._RF.push(module, '5a834XHoONCcLnoC0HBA/ZW', 'limitexercise_change_item_panel');
// Scripts/mod/limitexercise/view/limitexercise_change_item_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-09-10 11:44:13
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var LimitexerciseController = require("limitexercise_controller");
 
var ExhibitionItem = require("limitexercise_hero_item_panel");
 
var LimitExerciseChangeItem = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("limitexercise", "limitexercise_change_item");
    this.HeightItem = 568;
    this.model = LimitexerciseController.getInstance().getModel();
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.btn_master = {};
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    var _this = this;
 
    var main_container = this.root_wnd.getChildByName("main_container");
    this.touch_kuang = main_container.getChildByName("touch_kuang");
 
    var _loop = function _loop(i) {
      var tab = {};
      tab.btn = main_container.getChildByName("btn_master_" + i);
      tab.hero_item = new ExhibitionItem(0.9); //ItemsPool.getInstance().getItem("hero_exhibition_item")
      // tab.hero_item.effect = false
      // tab.hero_item.setExtendData({scale:0.9,can_click:true})
 
      tab.hero_item.addCallBack(function () {
        this.onClickHeroItem(i);
      }.bind(_this));
      tab.hero_item.setParent(tab.btn);
      tab.hero_item.setPosition(-26, -4.5);
      tab.hero_item.show();
      tab.name = tab.btn.getChildByName("name").getComponent(cc.Label);
      tab.name.string = "";
      tab.bar = tab.btn.getChildByName("bar").getComponent(cc.ProgressBar);
      tab.bar_num = tab.btn.getChildByName("bar_num").getComponent(cc.Label);
      tab.bar_num.string = "";
      tab.kill_spr = tab.btn.getChildByName("kill_spr");
      tab.kill_spr.zIndex = 10;
      tab.kill_spr.active = false;
      tab.lock_spr = tab.btn.getChildByName("lock_spr");
      tab.lock_spr.zIndex = 10;
      tab.lock_spr.active = false;
 
      if (i == 5) {
        var boss_spr = tab.btn.getChildByName("boss_spr");
        boss_spr.zIndex = 10;
      }
 
      tab.index = i;
      _this.btn_master[i] = tab;
    };
 
    for (var i = 1; i <= 5; ++i) {
      _loop(i);
    }
 
    if (this.data) {
      this.setData(this.data);
      this.setItemIndex();
    }
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {},
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(params) {},
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  setData: function setData(data) {
    this.data = data;
    if (!data || !this.root_wnd) return;
    this.setGuardData(data);
  },
  setGuardData: function setGuardData(data) {
    var _this2 = this;
 
    var list = [];
 
    for (var i in data) {
      list.push(data[i]);
    }
 
    list.sort(function (a, b) {
      return a.sort_id - b.sort_id;
    });
    this.data = data;
 
    var _loop2 = function _loop2(_i) {
      if (_this2.btn_master[_i + 1]) {
        var boss = _this2.getHeroHp(list[_i].order_id);
 
        var hp = boss[0];
        var level_status = boss[1];
 
        if (_this2.btn_master[_i + 1].hero_item.root_wnd) {
          _this2.btn_master[_i + 1].hero_item.setHeadImg(list[_i].head_id);
 
          _this2.btn_master[_i + 1].hero_item.setQualityImg(list[_i].star);
 
          _this2.btn_master[_i + 1].hero_item.setLev(list[_i].master_lev); // this.btn_master[i+1].hero_item.setRootScale(0.9)
 
 
          Utils.setChildUnEnabled(_this2.btn_master[_i + 1].hero_item.root_wnd, hp == 0);
        } else {
          _this2.btn_master[_i + 1].hero_item.getRootWnd(function () {
            this.btn_master[_i + 1].hero_item.setHeadImg(list[_i].head_id);
 
            this.btn_master[_i + 1].hero_item.setQualityImg(list[_i].star);
 
            this.btn_master[_i + 1].hero_item.setLev(list[_i].master_lev); // this.btn_master[i+1].hero_item.setRootScale(0.9)
 
 
            Utils.setChildUnEnabled(this.btn_master[_i + 1].hero_item.root_wnd, hp == 0);
          }.bind(_this2));
        }
 
        _this2.btn_master[_i + 1].name.string = list[_i].name;
        _this2.btn_master[_i + 1].bar_num.string = hp + "%";
        _this2.btn_master[_i + 1].bar.progress = hp;
 
        if (level_status == true) {
          _this2.btn_master[_i + 1].lock_spr.active = false;
        } else {
          _this2.btn_master[_i + 1].lock_spr.active = hp == 100;
        }
 
        _this2.btn_master[_i + 1].kill_spr.active = hp == 0; // setChildUnEnabled(hp==0, this.btn_master[i].hero_item)
      }
    };
 
    for (var _i = 0; _i < list.length; ++_i) {
      _loop2(_i);
    }
  },
  getHeroHp: function getHeroHp(order_id) {
    var cur_level = this.model.getCurrentChangeID();
    var cur_hp = this.model.getCurrentBossHp();
    if (!cur_level || !cur_hp) return 0;
    var hp_num = 0;
    var level_status = false;
 
    if (order_id < cur_level) {
      hp_num = 0;
    } else if (order_id == cur_level) {
      hp_num = cur_hp * 0.001;
      level_status = true;
    } else if (order_id > cur_level) {
      hp_num = 100;
    }
 
    return [hp_num, level_status];
  },
  addCallBack: function addCallBack(callback) {
    this.callback = callback;
  },
  onClickHeroItem: function onClickHeroItem(pos) {
    this.funcCallBack(this.data, pos);
  },
  funcCallBack: function funcCallBack(data, index) {
    if (!data) return;
 
    if (this.callback) {
      var order_type, order_id;
 
      for (var i in data) {
        var item = data[i];
 
        if (item.sort_id == index) {
          order_type = item.order_type;
          order_id = item.order_id;
          break;
        }
      }
 
      if (order_type && order_id) {
        this.item_index = index;
        this.callback(this, order_type, order_id, index);
      }
    }
  },
  getBtnMaster: function getBtnMaster(index) {
    if (this.btn_master[index]) {
      return this.btn_master[index].btn;
    }
  },
  setItemIndex: function setItemIndex() {
    if (!this.data) return;
    var cur_change = this.model.getCurrentChangeID();
    var init_index;
    var data = this.model.getLimitExerciseData();
 
    if (data.order > data.round * 15) {
      cur_change = data.round_boss;
    }
 
    for (var i in this.data) {
      var v = this.data[i];
 
      if (v.order_id == cur_change) {
        init_index = v.sort_id;
        break;
      }
    }
 
    if (init_index) {
      this.onClickHeroItem(init_index);
    }
  },
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    for (var i in this.btn_master) {
      if (this.btn_master[i].hero_item) {
        this.btn_master[i].hero_item.deleteMe();
        this.btn_master[i].hero_item = null;
      }
    }
  }
});
 
cc._RF.pop();