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
"use strict";
cc._RF.push(module, 'd7a7bRpTxFIrbOoakTyczPl', 'battle_buff_info_item_panel');
// Scripts/mod/battle/view/battle_buff_info_item_panel.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-07-24 15:54:31
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var BattleController = require("battle_controller");
 
var HeroVo = require("hero_vo");
 
var Dir_Type = {
  Left: 1,
  // 左边英雄
  Right: 2 // 右边英雄
 
};
var BattleBuffInfoItem = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("battle", "battle_buff_info_item");
    this.role_dir = arguments[0] || Dir_Type.Left;
    this.ctrl = BattleController.getInstance();
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.buff_list_item = [];
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.size = this.root_wnd.getContentSize();
    var container = this.root_wnd.getChildByName("container");
    this.container = container;
    this.touch_layout = container.getChildByName("touch_layout");
    this.arrow_sp = container.getChildByName("Sprite_1");
    this.hero_head = ItemsPool.getInstance().getItem("hero_exhibition_item");
    this.hero_head.setExtendData({
      scale: 0.7,
      can_click: true
    });
    this.hero_head.addCallBack(this._onClickHeroCallBack.bind(this));
    this.hero_head.setParent(container);
    this.hero_head.show();
 
    if (this.role_dir == Dir_Type.Left) {
      this.hero_head.setPosition(50, this.size.height / 2);
      this.touch_layout.setPosition(cc.v2(this.size.width, 0));
      this.arrow_sp.setPosition(cc.v2(282, 15));
      this.arrow_sp.scaleX = 1;
    } else {
      this.hero_head.setPosition(this.size.width - 50, this.size.height / 2);
      this.touch_layout.setPosition(this.size.width - 120 * 0.7 - 18, 0);
      this.arrow_sp.setPosition(cc.v2(18, 15));
      this.arrow_sp.scaleX = -1;
    }
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.touch_layout.on("touchend", function () {
      if (this.buff_list_data && Utils.next(this.buff_list_data) != null) {
        this.ctrl.openBattleBuffListView(true, this.buff_list_data, this.data.group, this.data.object_bid);
      }
    }, this);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(params) {
    if (this.data) {
      this.setData(this.data);
    }
  },
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.hero_head) {
      this.hero_head.deleteMe();
      this.hero_head = null;
    }
  },
  setData: function setData(data) {
    var _this = this;
 
    this.data = data || {};
 
    if (!this.root_wnd) {
      return;
    }
 
    var info = data.role_data; // -- 头像
 
    var hero_vo = new HeroVo();
 
    if (Config.partner_data.data_partner_base[info.object_bid]) {
      hero_vo.bid = info.object_bid;
      hero_vo.star = info.star;
    } else {
      var config = function config(id) {
        return gdata("unit_data", "data_unit1", id) || gdata("unit_data", "data_unit2", id) || gdata("unit_data", "data_unit3", id);
      };
 
      var unit_config = config(data.role_data.object_bid);
 
      if (unit_config) {
        hero_vo.bid = Number(unit_config.head_icon);
 
        if (unit_config.star && unit_config.star > 0) {
          hero_vo.star = unit_config.star;
        } else {
          var base_config = Config.partner_data.data_partner_base[hero_vo.bid];
 
          if (base_config) {
            hero_vo.star = base_config.init_star;
          }
        }
 
        hero_vo.master_head_id = hero_vo.bid;
      }
    }
 
    hero_vo.camp_type = info.camp_type;
    hero_vo.lev = info.lev;
    hero_vo.use_skin = info.fashion;
    this.hero_head.setData(hero_vo);
 
    if (info.hp > 0) {
      this.hero_head.showStrTips(false);
    } else {
      this.hero_head.showStrTips(true, Utils.TI18N("已阵亡"));
    } // -- buff 图标
 
 
    var temp_list = {};
    var temp_group_list = {};
 
    for (var i in this.data.buff_list) {
      var v = this.data.buff_list[i];
 
      if (v == null) {
        continue;
      }
 
      var buff_config = v.config;
      var buff = v.buff;
      var res_id = buff_config.icon; // -- 根据配置表判断一下,如果角色死亡,buff是否为需要清除的
 
      if (res_id != null && res_id != 0 && (info.hp > 0 || buff_config.clean_when_dead != null && buff_config.clean_when_dead == "false")) {
        if (temp_list[res_id] == null) {
          temp_list[res_id] = {
            res_id: res_id,
            num: 0,
            name: buff_config.name,
            remain_round: buff.remain_round,
            desc: buff_config.desc,
            buff_infos: []
          };
        }
 
        if (temp_list[res_id].num == 0 || buff_config.join_type && buff_config.join_type != 3) {
          temp_list[res_id].num = temp_list[res_id].num + 1;
          temp_list[res_id].buff_infos.push({
            buff_id: buff_config.bid,
            remain_round: buff.remain_round
          }); // _table_insert(temp_list[res_id].buff_infos, {buff_id=v.bid, remain_round=v.remain_round})
 
          if (buff_config.group) {
            temp_group_list[buff_config.group] = true;
          }
        } else if (buff_config.join_type && buff_config.join_type == 3 && buff_config.group && !temp_group_list[buff_config.group]) {
          temp_group_list[buff_config.group] = true;
          temp_list[res_id].num = temp_list[res_id].num + 1;
          temp_list[res_id].buff_infos.push({
            buff_id: buff_config.bid,
            remain_round: buff.remain_round
          }); // _table_insert(temp_list[res_id].buff_infos, {buff_id=v.bid, remain_round=v.remain_round})
        }
      }
    }
 
    this.buff_list_data = [];
 
    for (var k in temp_list) {
      var _v = temp_list[k];
      this.buff_list_data.push(_v);
    }
 
    this.buff_list_data.sort(function (a, b) {
      return a.res_id - b.res_id;
    });
    this.ctrl.updateBattleBuffListView(this.buff_list_data, info.group, info.object_bid);
 
    for (var _k = 0; _k < this.buff_list_item.length; ++_k) {
      var buff_object = this.buff_list_item[_k];
 
      if (buff_object.icon) {
        buff_object.icon.node.active = false;
      }
    }
 
    var start_x = 110;
    var start_y = 85;
 
    if (this.role_dir == Dir_Type.Right) {
      start_x = this.size.width - start_x;
    }
 
    var space_x = 5; // let space_y = 5
 
    var buff_icon_size = cc.size(33, 32);
 
    for (var _i = 0; _i < this.buff_list_data.length; ++_i) {
      var bData = this.buff_list_data[_i];
      var num = _i + 1;
 
      if (num <= 8) {
        (function () {
          //-- 最多显示8个
          var buff_object = _this.buff_list_item[_i];
 
          if (buff_object == null) {
            buff_object = _this.createBuffItem();
            _this.buff_list_item[_i] = buff_object;
          }
 
          buff_object.icon.node.active = true;
          buff_object.label.string = bData.num; //   -- 位置
 
          var row = Math.ceil(num / 4);
          var index = num % 4;
 
          if (index == 0) {
            index = 4;
          }
 
          var pos_x = start_x + (index - 1) * (buff_icon_size.width + space_x) + buff_icon_size.width / 2;
 
          if (_this.role_dir == Dir_Type.Right) {
            pos_x = start_x - (index - 1) * (buff_icon_size.width + space_x) - buff_icon_size.width / 2;
          }
 
          var pos_y = start_y - (row - 1) * (buff_icon_size.height + space_x) - buff_icon_size.height / 2;
          buff_object.icon.node.setPosition(cc.v2(pos_x, pos_y));
          var buff_icon_id = bData.res_id;
          var buff_path = PathTool.getBigBuffRes(buff_icon_id);
 
          if (buff_object.path != buff_path) {
            buff_object.path = buff_path;
 
            _this.loadRes(buff_path, function (res) {
              buff_object.icon.spriteFrame = res;
            }.bind(_this));
          }
        })();
      }
    }
  },
  _onClickHeroCallBack: function _onClickHeroCallBack() {
    if (this.data && this.data.role_data && this.data.role_data.owner_id != 0 && this.data.role_data.owner_srv_id != "" && this.data.role_data.object_id) {
      var RoleController = require("role_controller");
 
      var role_vo = RoleController.getInstance().getRoleVo();
 
      var HeroController = require("hero_controller");
 
      if (role_vo.rid == this.data.role_data.owner_id && role_vo.srv_id == this.data.role_data.owner_srv_id) {
        var hero_vo = HeroController.getInstance().getModel().getHeroById(this.data.role_data.object_id);
 
        if (hero_vo && Utils.next(hero_vo) != null) {
          HeroController.getInstance().openHeroTipsPanel(true, hero_vo);
        } else {
          message(Utils.TI18N("该英雄来自异域,无法查看"));
        }
      } else {
        var LookController = require("look_controller");
 
        LookController.getInstance().sender11061(this.data.role_data.owner_id, this.data.role_data.owner_srv_id, this.data.role_data.object_id);
      }
    } else {
      message(Utils.TI18N("该英雄来自异域,无法查看"));
    }
  },
  createBuffItem: function createBuffItem() {
    var object = {};
    var icon = Utils.createImage(this.container, null, 0, 0, cc.v2(0.5, 0.5));
    var node = new cc.Node();
    node.setAnchorPoint(cc.v2(1, 0));
    node.setPosition(15, -15);
    var label = node.addComponent(cc.Label);
    icon.node.addChild(node);
    label.fontSize = 14;
    label.lineHeight = 18;
    label.horizontalAlign = cc.macro.TextAlignment.CENTER;
    label.verticalAlign = cc.macro.TextAlignment.CENTER;
    node.color = new cc.Color(0xff, 0xff, 0xff, 0xff);
    var line = node.addComponent(cc.LabelOutline);
    line.color = new cc.Color(0, 0, 0);
    line.width = 1;
    object.icon = icon;
    object.label = label;
    object.path = "";
    return object;
  }
});
 
cc._RF.pop();