KLFriendAddSubItem.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ---@class KLFriendAddSubItem:UIKmlLuaPanelBase
  2. ---@field view KLFriendAddSubItemView
  3. local KLFriendAddSubItem = class(UIKmlLuaPanelBase)
  4. local this =KLFriendAddSubItem
  5. ---创建时调用一次
  6. function this:Init()
  7. if SL:FriendInfo_GetRecommendFriends() then
  8. self:UpdateData(SL:FriendInfo_GetRecommendFriends(), false)
  9. GUI:Text_setString(self.view.tui_jian_text, "系统推荐")
  10. else
  11. SL.Friend:ReqRecommendFriendsMessage()
  12. end
  13. end
  14. ---创建或者刷新界面数据时调用
  15. function this:Refresh()
  16. self:StartTimeDown()
  17. end
  18. ---注册UI事件和服务器消息
  19. function this:RegistEvents()
  20. GUI:AddOnClickEvent(self.view.shua_xin_img, self, self.ReqRefreshAddFriends)
  21. SL:RegisterLuaNetMsg(MessageDef.ResRecommendFriendsMessage, self.ResRecommendFriendsMessage, self)
  22. GUI:AddOnClickEvent(self.view.BtnSearch, self, self.SearchFriend)
  23. SL:RegisterLuaNetMsg(MessageDef.ResSearchFriendMessage, self.ResSearchFriendMessage, self)
  24. SL:RegisterLUAEvent(LUA_EVENT_FRIEND_LIST_CHANGE, self.OnFriendChange, self)
  25. end
  26. function this:OnFriendChange(_, type)
  27. if type == 5 and not self.isSearch and self.dataList then
  28. local list= SL:GetFriendData(5)
  29. if not table.isNullOrEmpty(list) then
  30. local checkList = {}
  31. for _, v in pairs(list) do
  32. table.insert(checkList, v.rid)
  33. end
  34. --屏蔽好友推荐
  35. for i = #self.dataList, 1 , -1 do
  36. if table.contains(checkList, self.dataList[i].rid) then
  37. table.remove(self.dataList, i)
  38. end
  39. end
  40. self:UpdateData(self.dataList, false)
  41. end
  42. end
  43. end
  44. function this:ReqRefreshAddFriends()
  45. if self.canRefresh then
  46. SL:FriendInfo_SetNextTime(SL:GetMetaValue(EMetaVarGetKey.UID))
  47. SL.Friend:ReqRecommendFriendsMessage()
  48. self:StartTimeDown()
  49. else
  50. end
  51. end
  52. ---@param message FriendProto.RecommendFriendsRes
  53. function this:ResRecommendFriendsMessage(id, message)
  54. self:UpdateData(message.friendInfo)
  55. GUI:Text_setString(self.view.tui_jian_text, "系统推荐", false)
  56. end
  57. ---查找
  58. function this:SearchFriend()
  59. local str = GUI:Text_getString(self.view.IptSearch)
  60. if not string.isNullOrEmpty(str) then
  61. SL.Friend:ReqSearchFriendMessage(str)
  62. else
  63. if SL:FriendInfo_GetRecommendFriends() then
  64. self:UpdateData(SL:FriendInfo_GetRecommendFriends(), false)
  65. GUI:Text_setString(self.view.tui_jian_text, "系统推荐")
  66. else
  67. SL.Friend:ReqRecommendFriendsMessage()
  68. end
  69. end
  70. end
  71. ---@param message FriendProto.SearchFriendRes
  72. function this:ResSearchFriendMessage(id, message)
  73. self:UpdateData(message.friendInfo, true)
  74. GUI:Text_setString(self.view.tui_jian_text, "搜索 '好友' 符合条件的结果")
  75. end
  76. ---@param dataList FriendProto.FriendInfo[]
  77. function this:UpdateData(dataList, isSearch)
  78. self.dataList = dataList
  79. self.isSearch = isSearch
  80. local filePath = "dev/ui/FriendSys/Item/KLFriendAddList/KLFriendAddListItem"
  81. GUI:UIPanel_Close(filePath)
  82. for _, v in pairs(dataList) do
  83. GUI:UIPanel_Open(filePath, self.view.ListContent,
  84. self, {addFriend = true, data = v}, true)
  85. end
  86. end
  87. function this:Close()
  88. GUI:UIPanel_Close("dev/ui/FriendSys/Item/KLFriendAddList/KLFriendAddListItem")
  89. if self.co_timer then
  90. Coroutine.Stop(self.co_timer)
  91. end
  92. end
  93. function this:StartTimeDown()
  94. if self.co_timer then
  95. Coroutine.Stop(self.co_timer)
  96. self.co_timer = nil
  97. end
  98. self.co_timer = Coroutine.Start(function()
  99. local nextTime = SL:FriendInfo_GetNextTime(SL:GetMetaValue(EMetaVarGetKey.UID))
  100. if not nextTime then
  101. nextTime = os.time() - 1
  102. end
  103. local left = nextTime - os.time()
  104. self.canRefresh = left <= 0
  105. if left > 0 then
  106. GUI:setVisible(self.view.TxtCdCountdown, true)
  107. GUI:setVisible(self.view.shua_xin_text, false)
  108. GUI:Button_setGrey(self.view.shua_xin_img, true)
  109. end
  110. while left > 0 do
  111. local minute = math.modf(left / 60)
  112. local second = left % 60
  113. local fmtTime = string.format("%02s:%02s", minute, second)
  114. GUI:Text_setString(self.view.TxtCdCountdown, fmtTime)
  115. Coroutine.Wait(1)
  116. left = left - 1
  117. end
  118. self.canRefresh = true
  119. GUI:setVisible(self.view.TxtCdCountdown, false)
  120. GUI:setVisible(self.view.shua_xin_text, true)
  121. GUI:Button_setGrey(self.view.shua_xin_img, false)
  122. end)
  123. end
  124. return this