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
"use strict";
cc._RF.push(module, '70f383+TA9FNYsybDVLsVk6', 'playerhead');
// Scripts/common/playerhead.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      圆形头像
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var PlayerHead = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("mainui", "head_item");
  },
  initPanel: function initPanel() {
    // 头像部分
    this.container = this.root_wnd.getChildByName("container");
    this.icon = this.container.getChildByName("icon").getComponent(cc.Sprite); // 头像框
 
    this.frame = this.root_wnd.getChildByName("frame").getComponent(cc.Sprite); // 等级部分
 
    this.lev_container = this.root_wnd.getChildByName("lev_container");
    this.lev_container.active = false;
    this.lev = this.lev_container.getChildByName("lev").getComponent(cc.Label);
    this.click_icon = this.root_wnd.getChildByName("click");
 
    if (this.lev_value != null) {
      this.lev.string = this.lev_value;
      this.lev_container.active = true;
    }
 
    if (this.head_res) {
      this.loadHeadRes(this.head_res);
    }
 
    if (this.frame_res != null) {
      this.loadFrameRes(this.frame_res, this.frame_scale);
    }
 
    if (this.scale_value != null) {
      this.setScale(this.scale_value);
    }
 
    if (this.grey_bool != null) {
      this.setLockStatus(this.grey_bool);
    }
  },
  registerEvent: function registerEvent() {
    if (this.call_back) {
      this.click_icon.on(cc.Node.EventType.TOUCH_END, function () {
        this.call_back(this);
      }, this);
    }
  },
  onShow: function onShow() {},
  onHide: function onHide() {},
  // 点击事件
  addCallBack: function addCallBack(call_back) {
    this.call_back = call_back;
  },
  // 设置头像资源
  setHeadRes: function setHeadRes(res) {
    if (this.root_wnd) {
      this.loadHeadRes(res);
    } else {
      this.head_res = res;
    }
  },
  // 设置头像框资源
  setFrameRes: function setFrameRes(res, scale) {
    if (this.root_wnd) {
      this.loadFrameRes(res, scale);
    } else {
      this.frame_res = res;
      this.frame_scale = scale;
    }
  },
  // 设置等级显示
  setLev: function setLev(lev) {
    if (this.root_wnd) {
      this.lev.string = lev;
      this.lev_container.active = true;
    } else {
      this.lev_value = lev;
    }
  },
  // 设置锁定状态
  setLockStatus: function setLockStatus(bool) {
    this.grey_bool = bool;
    if (this.root_wnd == null) return;
 
    if (bool) {
      this.icon.setState(cc.Sprite.State.NORMAL);
      this.frame.setState(cc.Sprite.State.NORMAL);
    } else {
      this.icon.setState(cc.Sprite.State.GRAY);
      this.frame.setState(cc.Sprite.State.GRAY);
    }
  },
  // 加载资源,这里可能需要判断一下加载回来的是不是我需要的资源,私有方法 不能外部调用,外部滴啊用请用 setHeadRes
  loadHeadRes: function loadHeadRes(res_id) {
    var res_path = PathTool.getHeadRes(res_id);
    this.loadRes(res_path, function (resObject) {
      this.icon.spriteFrame = resObject;
    }.bind(this));
  },
  // 加载资源,这里可能需要判断一下加载回来的是不是我需要的资源,私有方法 不能外部调用,外部滴啊用请用 setFrameRes
  //scale默认比例是大部分需要缩放所以用了100/117,其他情况结合自己界面修改scale值
  loadFrameRes: function loadFrameRes(bid, scale) {
    if (scale == null) {
      scale = 100 / 117;
    }
 
    if (typeof bid == "number") {
      var config = Config.avatar_data.data_avatar[bid];
 
      if (!config) {
        return;
      }
 
      var res_path = PathTool.getHeadcircle(config.res_id);
      this.loadRes(res_path, function (resObject) {
        this.frame.spriteFrame = resObject;
      }.bind(this));
      this.frame.node.scale = scale;
 
      if (bid == 1000) {
        this.frame.node.y = 0;
      } else {
        this.frame.node.y = 5;
      }
    } else {
      this.loadRes(bid, function (resObject) {
        this.frame.spriteFrame = resObject;
      }.bind(this));
      this.frame.node.scale = scale;
    }
  },
  setScale: function setScale(value) {
    this.scale_value = value;
    if (this.root_wnd) this.root_wnd.scale = value;
  },
  //背景框
  showBg: function showBg(res, scale) {
    this.setFrameRes(res, scale);
  },
  setSex: function setSex(sex, pos) {
    if (sex == null || typeof sex != "number") return;
    if (sex >= 2) return;
 
    if (this.sex_icon_sp == null) {
      this.sex_icon_sp = Utils.createImage(this.root_wnd, null, 0, 0, cc.v2(0, 0));
    }
 
    this.loadRes(PathTool.getUIIconPath("common", "common_sex" + sex), function (sp) {
      this.sex_icon_sp.spriteFrame = sp;
    }.bind(this));
 
    if (pos != null && this.sex_icon_sp != null) {
      this.sex_icon_sp.node.setPosition(pos);
    }
  },
  onDelete: function onDelete() {// this.container.off(cc.Node.EventType.TOUCH_END, function () {}, this);
  },
  clearHead: function clearHead() {
    this.icon.spriteFrame = null;
  }
});
 
cc._RF.pop();