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
"use strict";
cc._RF.push(module, 'e7868ORLHxHcJBUuji6H9EI', 'equip_cloth_item');
// Scripts/mod/hero/equip/equip_cloth_item.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-03-26 19:39:32
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var EquipClothItem = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("hero", "equip_cloth_item");
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.icon_list = {
      "atk": 21,
      "hp_max": 22,
      "def": 23,
      "speed": 37,
      "atk_per": 21
    };
    this.attr_data_key = Config.attr_data.data_id_to_key;
    this.attr_data_name = Config.attr_data.data_id_to_name;
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.item_con_nd = this.seekChild("item_con");
    this.equip_btn_nd = this.seekChild("equip_btn");
    this.equip_name_lb = this.seekChild("equip_name", cc.Label);
    this.equip_lev_lb = this.seekChild("equip_lev", cc.Label);
    this.equip_score_lb = this.seekChild("equip_score", cc.Label);
    this.attr_icon_sp = this.seekChild("attr_icon", cc.Sprite);
    this.attr_name_lb = this.seekChild("attr_name", cc.Label);
    this.attr_val_lb = this.seekChild("attr_val", cc.Label);
    this.backpack_item = ItemsPool.getInstance().getItem("backpack_item");
    this.backpack_item.setParent(this.item_con_nd);
    this.backpack_item.setExtendData({
      effect: false,
      scale: 0.9
    });
    this.backpack_item.show();
    this.equip_btn_nd.on(cc.Node.EventType.TOUCH_END, this.onClickEquipBtn, this);
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {},
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow(params) {
    this.updateWidgets();
  },
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.backpack_item) {
      this.backpack_item.deleteMe();
      this.backpack_item = null;
    }
  },
  setData: function setData(data) {
    this.equip_data = data;
    if (this.root_wnd) this.updateWidgets();
  },
  updateWidgets: function updateWidgets() {
    this.equip_name_lb.string = this.equip_data.config.name;
    this.equip_lev_lb.string = this.equip_data.lev;
    this.equip_score_lb.string = this.equip_data.score; // main_attr
 
    var main_attr = this.equip_data.main_attr[0];
 
    if (main_attr) {
      var attr_key = this.attr_data_key[main_attr.attr_id];
      var attr_res = this.icon_list[attr_key];
      var attr_icon_path = PathTool.getUIIconPath("common", "common_900" + attr_res);
      this.loadRes(attr_icon_path, function (attr_sf) {
        this.attr_icon_sp.spriteFrame = attr_sf;
      }.bind(this));
      var attr_name = this.attr_data_name[main_attr.attr_id];
      this.attr_name_lb.string = attr_name + ":";
      this.attr_val_lb.string = main_attr.attr_val;
    }
 
    this.backpack_item.setData(this.equip_data); // this.backpack_item.setItemNum();
  },
  addCallBack: function addCallBack(callback) {
    this.select_cb = callback;
  },
  onClickEquipBtn: function onClickEquipBtn() {
    if (this.select_cb) this.select_cb(this.equip_data);
  }
});
 
cc._RF.pop();