KLFriendAddListItem.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ---@class KLFriendAddListItem:UIKmlLuaPanelBase
  2. ---@field view KLFriendAddListItemView
  3. local KLFriendAddListItem = class(UIKmlLuaPanelBase)
  4. local this =KLFriendAddListItem
  5. ---创建时调用一次
  6. function this:Init()
  7. self.isAddFriend = self.args and self.args.addFriend or false
  8. GUI:setVisible(self.view.BtnForbid, self.isAddFriend)
  9. GUI:setVisible(self.view.BtnRefuse, not self.isAddFriend)
  10. GUI:setVisible(self.view.BtnAgree, not self.isAddFriend)
  11. ---@type FriendProto.FriendInfo
  12. local data = self.args.data
  13. self.data = data
  14. GUI:Text_setString(self.view.friend_name, data.name)
  15. GUI:Text_setString(self.view.friend_level, "LV."..data.level)
  16. if self.isAddFriend then
  17. local isFriend = SL:CheckIsFriend(data.rid)
  18. GUI:setVisible(self.view.BtnAlreadyAdd, isFriend)
  19. GUI:setVisible(self.view.BtnAdd, not isFriend)
  20. else
  21. GUI:setVisible(self.view.BtnAlreadyAdd, false)
  22. GUI:setVisible(self.view.BtnAdd, false)
  23. end
  24. GUI:Image_loadTexture(self.view.Icon,"1" .. self.data.career,"Atlas/MUIcon.spriteatlas")
  25. end
  26. ---创建或者刷新界面数据时调用
  27. function this:Refresh()
  28. end
  29. ---注册UI事件和服务器消息
  30. function this:RegistEvents()
  31. GUI:AddOnClickEvent(self.view.BtnAgree, self, self.AgreeApply)
  32. GUI:AddOnClickEvent(self.view.BtnRefuse, self, self.RefuseApply)
  33. GUI:AddOnClickEvent(self.view.BtnForbid, self, self.Forbid)
  34. GUI:AddOnClickEvent(self.view.BtnAdd, self, self.AddFriend)
  35. GUI:AddOnClickEvent(self.view.BtnAlreadyAdd, self, self.AlreadyAddFriend)
  36. end
  37. function this:AgreeApply()
  38. SL:HandleAddFriendRequest(self.data.rid, 1)
  39. end
  40. function this:RefuseApply()
  41. SL:HandleAddFriendRequest(self.data.rid, 0)
  42. end
  43. function this:Forbid()
  44. SL.Friend:ReqAddFriendMessage(5, self.data.rid)
  45. end
  46. function this:AddFriend()
  47. SL:AddFriend(self.data.rid)
  48. local friends = SL:GetFriendData(EFriendRelation.Friend)
  49. ---@type cfg_global_column
  50. local tbl = SL:GetConfig("cfg_global", 45)
  51. local split = string.split(tbl.value, "#")
  52. local friendMax = tonumber(split[1])
  53. if table.count(friends) < friendMax then
  54. SL:FriendInfo_AddIdToAlreadySendFriendReq(self.data.rid)
  55. GUI:UIPanel_Close(nil, self)
  56. end
  57. end
  58. function this:AlreadyAddFriend()
  59. SL:TipMessage("对方已存在您的好友列表中!", 1, NoticeType.NoticeMid)
  60. end
  61. function this:Close()
  62. end
  63. return this