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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
"use strict";
cc._RF.push(module, '55eddYixShPf7Odm68JCgez', 'friend_list_item');
// Scripts/mod/friend/view/friend_list_item.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: @syg.com(必填, 创建模块的人员)
// @description:
//      竖版好友列表子项
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var FriendController = require("friend_controller");
 
var FriendConst = require("friend_const");
 
var PlayerHead = require("playerhead");
 
var FriendVo = require("friend_vo");
 
var TimeTool = require("timetool");
 
var FriendListItem = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("friend", "friend_item");
    this.ctrl = FriendController.getInstance();
    this.size = cc.size(610, 114);
    this.width = 610;
    this.height = 114;
    this.is_del = false;
    this.item_list = {};
    this.vo = null;
    this.open_type = arguments[0] && arguments[0].open_type || FriendConst.Type.MyFriend;
  },
  initPanel: function initPanel() {
    this.root_wnd.setContentSize(this.size);
    this.main_panel = this.root_wnd.getChildByName("main_panel"); //名字
 
    this.role_name = this.main_panel.getChildByName("role_name").getComponent(cc.Label);
    this.role_power = this.main_panel.getChildByName("role_power").getComponent(cc.Label);
    this.is_online = this.main_panel.getChildByName("is_online").getComponent(cc.Label);
    this.img_btn = this.main_panel.getChildByName("img");
    this.img = this.main_panel.getChildByName("img").getComponent(cc.Sprite);
    this.button = this.main_panel.getChildByName("add_btn");
    this.btn_label = this.button.getChildByName("Label").getComponent(cc.Label);
    this.btn_label_lo = this.button.getChildByName("Label").getComponent(cc.LabelOutline);
    this.del_btn = this.main_panel.getChildByName("del_btn");
    this.del_btn.active = false; //头像
 
    this.head_con = this.main_panel.getChildByName("head_con");
    this.play_head = new PlayerHead();
    this.play_head.setParent(this.head_con);
    this.play_head.show();
    this.play_head.addCallBack(function () {
      this.ctrl.openFriendCheckPanel(true, this.vo);
    }.bind(this));
  },
  setExtendData: function setExtendData(open_type) {
    this.open_type = open_type;
  },
  clickHandler: function clickHandler() {
    if (this.call_fun) this.call_fun(this.vo);
  },
  setTouchFuncL: function setTouchFuncL(value) {
    this.call_fun = value;
  },
  addCallBackL: function addCallBackL(value) {
    this.call_fun = value;
  },
  registerEvent: function registerEvent() {
    this.button.on(cc.Node.EventType.TOUCH_END, function () {
      if (!this.vo) return;
      if (!this.button.getComponent(cc.Button).interactable) return;
 
      if (this.my_friend) {
        //私聊
        var ChatController = require("chat_controller");
 
        var ChatConst = require("chat_const");
 
        var vo = {
          avatar_bid: this.vo.avatar_bid,
          career: this.vo.career,
          dun_id: this.vo.dun_id,
          face_id: this.vo.face_id,
          gid: this.vo.gid,
          gift_status: this.vo.gift_status,
          gname: this.vo.gname,
          group_id: this.vo.group_id,
          gsrv_id: this.vo.gsrv_id,
          intimacy: this.vo.intimacy,
          is_awake: this.vo.is_awake,
          is_cross: this.vo.is_cross,
          is_draw: this.vo.is_draw,
          is_moshengren: this.vo.is_moshengren,
          is_online: this.vo.is_online,
          is_present: this.vo.is_present,
          is_used: this.vo.is_used,
          is_vip: this.vo.is_vip,
          lev: this.vo.lev,
          login_out_time: this.vo.login_out_time,
          login_time: this.vo.login_time,
          main_partner_id: this.vo.main_partner_id,
          name: this.vo.name,
          partner_bid: this.vo.partner_bid,
          partner_lev: this.vo.partner_lev,
          partner_star: this.vo.partner_star,
          power: this.vo.power,
          rid: this.vo.rid,
          sex: this.vo.sex,
          srv_id: this.vo.srv_id,
          talk_time: this.vo.talk_time
        };
        ChatController.getInstance().openChatPanel(ChatConst.Channel.Friend, "friend", vo);
      }
 
      if (this.award_panel) {
        this.ctrl.sender_13316(0, this.vo.rid, this.vo.srv_id);
      }
 
      if (this.apply_panel) {
        this.ctrl.accept(this.vo.srv_id, this.vo.rid, 1);
      }
 
      if (this.black_panel) {
        this.ctrl.deleteBlackList(this.vo.rid, this.vo.srv_id);
      }
 
      if (this.del_friend_btn) {//删除好友
      }
 
      if (this.recommend_panel) {
        this.ctrl.addOther(this.vo.srv_id, this.vo.rid);
        this.btn_label.string = Utils.TI18N("等待同意");
        this.button.getComponent(cc.Button).interactable = false;
        this.button.getComponent(cc.Button).enableAutoGrayEffect = true;
        this.btn_label_lo.color = new cc.Color(0x79, 0x79, 0x79, 0xff);
      }
 
      if (this.is_del) {
        //删除好友
        this.ctrl.delOther(this.vo.srv_id, this.vo.rid);
      }
    }, this);
    this.del_btn.on(cc.Node.EventType.TOUCH_END, function () {
      if (!this.vo) return;
      this.ctrl.accept(this.vo.srv_id, this.vo.rid, 0);
    }, this);
    this.img_btn.on(cc.Node.EventType.TOUCH_END, function () {
      if (!this.vo) return;
      if (!this.img_btn.getComponent(cc.Button).interactable) return;
 
      if (this.my_friend) {
        this.ctrl.sender_13316(0, this.vo.rid, this.vo.srv_id);
      }
 
      if (this.award_panel) {
        this.ctrl.sender_13316(1, this.vo.rid, this.vo.srv_id);
      }
    }, this);
  },
  setData: function setData(data) {
    if (data == null) return;
    this.unBindEvent();
    this.vo = data;
    if (this.root_wnd != null) this.onShow();
  },
  onShow: function onShow() {
    if (this.vo == null) return;
    var data = this.vo;
    gcore.Timer.set(function () {
      this.updateMessage();
    }.bind(this), 60, 1);
    if (data.face_id) this.play_head.setHeadRes(data.face_id);
 
    if (data.lev != null) {
      this.play_head.setLev(data.lev);
    }
 
    if (data.name != null) {
      this.role_name.string = data.name || "";
    }
 
    if (data.power != null) {
      var power = data.power || 0;
      this.role_power.string = Utils.TI18N("战力:") + power;
    }
 
    this.updateOnlineTime();
    this.addVoBindEvent();
  },
  // 更新在线时间
  updateOnlineTime: function updateOnlineTime() {
    if (!this.vo || !this.is_online) return;
    var str = "";
 
    if (this.vo.is_online != null && this.vo.is_online == 0) {
      var time = 0;
 
      if (this.vo.login_out_time == 0) {
        time = TimeTool.day2s() * 4;
      } else {
        var srv_time = gcore.SmartSocket.getTime();
        time = srv_time - this.vo.login_out_time;
      }
 
      str = TimeTool.getTimeFormatFriendShowTime(time);
    } else {
      str = Utils.TI18N("在线");
    }
 
    this.is_online.string = str;
  },
  addVoBindEvent: function addVoBindEvent() {
    // 直接用数据去监听这样避免了刷新的频繁
    if (this.vo && this.vo != null && this.vo.bind) {
      if (this.item_update_event == null) {
        this.item_update_event = this.vo.bind(FriendVo.UPDATE_FRIEND_ATTR_LOGIN_OUT_TIME, function (vo) {
          this.updateOnlineTime();
        }, this);
      }
    }
  },
  unBindEvent: function unBindEvent() {
    if (this.vo) {
      if (this.item_update_event != null) {
        this.vo.unbind(this.item_update_event);
        this.item_update_event = null;
      }
 
      this.vo = null;
    }
  },
  //根据类型创建显隐相关控件
  updateMessage: function updateMessage() {
    this.hideAllPanel();
 
    if (this.open_type == FriendConst.Type.MyFriend) {
      this.is_del = this.vo.del_status;
      this.updateMyFriend();
    } else if (this.open_type == FriendConst.Type.Award) {
      this.is_del = false;
      this.updateAwardPanel();
    } else if (this.open_type == FriendConst.Type.ApplyList) {
      this.is_del = false;
      this.updateApplyPanel();
    } else if (this.open_type == FriendConst.Type.BlackList) {
      this.is_del = false;
      this.updateBlackPanel();
    } else if (this.open_type == 5) {
      this.is_del = false;
      this.updateRecommendPanel();
    }
  },
  hideAllPanel: function hideAllPanel() {
    if (this.my_friend) this.my_friend = false;
    if (this.award_panel) this.award_panel = false;
    if (this.apply_panel) this.apply_panel = false;
    if (this.black_panel) this.black_panel = false;
    if (this.del_friend_btn) this.del_friend_btn = false;
    if (this.recommend_panel) this.recommend_panel = false;
  },
  //更新好友列表的控件
  updateMyFriend: function updateMyFriend() {
    if (!this.my_friend) {
      //赠送按钮
      this.loadRes(PathTool.getUIIconPath("friend", "friend_" + 5), function (sf_obj) {
        this.img.spriteFrame = sf_obj;
      }.bind(this));
      this.btn_label.string = Utils.TI18N("私聊");
      this.button.width = 96;
      this.del_btn.active = false;
      this.my_friend = true;
    }
 
    this.img.node.active = true;
    this.button.getComponent(cc.Button).interactable = true;
    this.button.getComponent(cc.Button).enableAutoGrayEffect = false;
    if (this.vo == null) return;
 
    if (this.vo.is_present != null && this.vo.is_present == 1) {
      this.img_btn.getComponent(cc.Button).interactable = false;
      this.img_btn.getComponent(cc.Button).enableAutoGrayEffect = true;
    } else {
      this.img_btn.getComponent(cc.Button).interactable = true;
      this.img_btn.getComponent(cc.Button).enableAutoGrayEffect = false;
    }
 
    if (this.is_del) this.setDelStatus(this.is_del);
  },
  //更新赠送的控件
  updateAwardPanel: function updateAwardPanel() {
    if (!this.award_panel) {
      //友情点标志
      if (this.path == null) {
        this.loadRes(PathTool.getUIIconPath("friend", "friend_" + 2), function (sf_obj) {
          this.img.spriteFrame = sf_obj;
        }.bind(this));
      } else {
        this.img.spriteFrame = this.res_object.getSpriteFrame("friend_" + 2);
      }
 
      this.btn_label.string = Utils.TI18N("回礼");
      this.award_panel = true;
    }
 
    this.img_btn.active = true;
    this.del_btn.active = false;
    this.img_btn.getComponent(cc.Button).interactable = true;
    this.img_btn.getComponent(cc.Button).enableAutoGrayEffect = false;
    this.btn_label_lo.color = new cc.Color(173, 100, 67, 0xff);
    if (!this.vo) return;
 
    if (this.vo.is_present != null && this.vo.is_present == 1) {
      this.button.getComponent(cc.Button).interactable = false;
      this.button.getComponent(cc.Button).enableAutoGrayEffect = true;
      this.btn_label_lo.color = new cc.Color(121, 121, 121, 0xff);
    }
 
    if (this.vo.is_draw != null && this.vo.is_draw == 0) {
      this.img_btn.getComponent(cc.Button).interactable = false;
      this.img_btn.getComponent(cc.Button).enableAutoGrayEffect = true;
    }
  },
  //更新申请列表的控件
  updateApplyPanel: function updateApplyPanel() {
    if (!this.apply_panel) {
      this.img.node.active = false;
      this.del_btn.active = true;
      this.apply_panel = true;
      this.btn_label.string = Utils.TI18N("接受");
      this.button.setContentSize(cc.size(96, 53));
      this.button.getComponent(cc.Button).interactable = true;
    }
  },
  //更新黑名单的控件
  updateBlackPanel: function updateBlackPanel() {
    if (!this.black_panel) {
      this.img.node.active = false;
      this.del_btn.active = false;
      this.btn_label.string = Utils.TI18N("移除");
      this.black_panel = true;
      this.button.getComponent(cc.Button).interactable = true;
    }
  },
  //更新推荐好友的控件
  updateRecommendPanel: function updateRecommendPanel() {
    if (!this.recommend_panel) {
      this.button.getComponent(cc.Button).interactable = true;
      this.img.node.active = false;
      this.del_btn.active = false;
      this.button.setContentSize(cc.size(127, 53));
      this.recommend_panel = true;
      this.btn_label.string = Utils.TI18N("加为好友");
    }
  },
  isHaveData: function isHaveData() {
    if (this.vo) return true;else return false;
  },
  setDelStatus: function setDelStatus(bool) {
    if (bool == true) this.hideAllPanel();
    this.is_del = bool;
    if (!this.button && bool == false) return;
 
    if (this.button) {
      if (bool) {
        this.button.setContentSize(cc.size(127, 53));
        this.btn_label.string = Utils.TI18N("删除好友");
        this.img.node.active = false;
      } else {
        this.button.setContentSize(cc.size(96, 53));
      }
    }
 
    if (bool == false) this.updateMyFriend();
  },
  getData: function getData() {
    return this.vo;
  },
  OnDelete: function OnDelete() {
    this.unBindEvent();
    this.vo = null;
    if (this.play_head) this.play_head.deleteMe();
    this.play_head = null;
  },
  setCallFun: function setCallFun(call_fun) {
    this.call_fun = call_fun;
  },
  setVisibleStatus: function setVisibleStatus(bool) {
    if (this.root_wnd == null) return;
    this.root_wnd.active = bool;
  }
});
module.exports = FriendListItem;
 
cc._RF.pop();